akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int offset=100010;
#define lowb(x) x&-x
int n,a[offset],s[offset*10],bit[offset*10];
void add(int x)
{
    for(int i=x;i<=2*offset;i+=lowb(i))
		bit[i]++;
}
long long query(int x)
{
    long long sum=0;
    for(int i=x;i>=1;i-=lowb(i))
		sum+=bit[i];
    return sum;
}
bool check(int x)
{
    for(int i=1;i<=2*offset;i++)
		bit[i]=0;
    s[0]=0;
    for(int i=1;i<=n;i++)
        s[i]=s[i-1]+(a[i]>=x?1:-1);
    long long sum=0;
    for(int i=0;i<=n;i++)
	{
        sum+=query(s[i]+offset);
        add(s[i]+offset);
    }
    return sum>=1ll*n*(n+1)/4;
}
int main()
{
    cin>>n;
    int l=0,r=0;
    for(int i=1;i<=n;i++)
	{
        cin>>a[i];
        r=max(r,a[i]);
    }
    while(l<=r)
	{
        int mid=(l+r)/2;
        if(check(mid))
			l=mid+1;
        else
			r=mid-1;
    }
    cout<<r<<endl;
    return 0;
}


Measured memory_bytes: 7168
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <valarray>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <tuple>

using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

struct UnionFind
{
  /*
  * par[i]: 根のときは負の値で木のサイズ管理
  *       : それ以外の時は正の値で親の値を保持
  * 
  * 
  **/
  vector<int> par;
  UnionFind(int n) : par(n, -1) {}
  void init(int n)
  {
    par.assign(n, -1);
  }
  int root(int x)
  {
    if (par[x] < 0)
      return x;
    else
      return par[x] = root(par[x]);
  }
  bool unite(int x, int y)
  {
    x = root(x);
    y = root(y);
    if (x == y)
      return false;
    if (par[x] > par[y])
      swap(x, y);
    par[x] += par[y];
    par[y] = x; // xの方がサイズが小さいので小さい方にくっつける？
    return true;
  }
  bool issame(int x, int y)
  {
    return root(x) == root(y);
  }
  int size(int x)
  {
    return -par[root(x)];
  }
};

int main()
{
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  vector<ll> a(m), b(m);
  for (int i = 0; i < m; ++i)
  {
    cin >> a[i] >> b[i];
    a[i]--, b[i]--;
  }
  reverse(a.begin(), a.end());
  reverse(b.begin(), b.end());
  vector<ll> ans;
  ll cur = n * (n - 1LL) / 2LL;
  for (int i = 0; i < m; ++i)
  {
    ans.push_back(cur);
    ll aa = uf.size(a[i]), bb = uf.size(b[i]);
    if (uf.issame(a[i], b[i]))
      continue;
    cur -= aa * bb;
    uf.unite(a[i], b[i]);
  }
  reverse(ans.begin(), ans.end());
  for (int i = 0; i < ans.size(); ++i)
  {
    cout << ans[i] << endl;
  }

  return 0;
}


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

// #define endl '\n'

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

//     string s;
//     cin >> s;
//     int n = s.size();
//     bool ok = false;

//     for(char c : s) {
//         if(c != '0') {
//             ok = true;
//         }
//     }
//     if(!ok) {
//         cout << n;
//         return 0;
//     } 

    
//     for(int i = (n + 1) / 2; i < n; i++) {
//         if(s[i] != s[n - i - 1] || s[i] != s[n - i]) {
//             cout << i;
//             return 0;
//         }
//     }

//     return 0;
// }
#include<cstdio>
#include<cstring>
#include<cctype>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<vector>
#include<algorithm>
#define ll long long
#define lowbit(x) x&-x
using namespace std;
int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
int min(int a,int b){return a<b?a:b;}
int max(int a,int b){return a<b?b:a;}
int ab(int x){return x>0?x:-x;}
//int MO(int x){return x>=MOD?x-MOD:x;}
//void insert(int u,int v){tot++;e[tot].v=v;e[tot].from=first[u];first[u]=tot;}
/*------------------------------------------------------------*/
const int inf=0x3f3f3f3f,maxn=100010;
int n;
char s[maxn];
int main(){
    scanf("%s",s);
    n=strlen(s);
    bool ok=0;
    for(int i=1;i<=n;i++)if(s[i]!='0')ok=1;
    if(!ok){printf("%d",n);return 0;}
    for(int i=(n>>1)+(n&1);i<n;i++)if(s[i]!=s[n-i-1]||s[i]!=s[i-1]){printf("%d",i);return 0;}
    printf("%d",n);
    return 0;
}

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

long long gcd(int a, int b) {
  if (b == 0) {
    return a;
  }
  return gcd(b, a % b);
}
int main() {
  int n, k;
  cin>>n>>k;
  int a[n];
  for (int i=0; i<n; i++) cin>>a[i];
  sort(a, a + n);
  if (k > a[n-1]) {
    cout<<"IMPOSSIBLE"<<endl;
    return 0;
  }
  long long c = a[0];
  for (int i=1; i<n; i++) c = gcd(c, a[i]);
  if (c == gcd(c, k)) {
    cout<<"POSSIBLE"<<endl;
  } else {
    cout<<"IMPOSSIBLE"<<endl;
  }
}

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

int main(){
  int n;
  cin >> n;
  vector<int> vec(n);
  rep(i,n) cin >> vec.at(i);
  int sub_min = 1000000;
  rep(i,n){
    int a=0;
    int b=0;
    rep(j,i+1) a+= vec.at(j);
    for(int j=i+1;j<n;j++) b+= vec.at(j);
    int sub;
    sub = abs(a-b);
    if (sub<sub_min) sub_min = sub;
  }
  cout << sub_min << endl;
}
    

Measured memory_bytes: 256
counts = [0] * 4
for _ in range(3):
    a, b = map(int, input().split())
    counts[a - 1] += 1
    counts[b - 1] += 1

even = 0
for count in counts:
    if count % 2 == 0: even += 1

print('YES' if even == 2 else 'NO')

Measured memory_bytes: 3060
// ABEY SAALE
// QUESTION KHUD KR SOLUTION KYU DEKH RHA H
 
 
 
 
 
 
 
 
//MAAF KIJIYEGA ME GUSSE ME IDHAR UDHAR NIKAL JATA HU
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define senky_bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;

ll fac[2000005];
void pre(){ fac[0]=1; fac[1]=1; for(int i=2;i<200005;i++) fac[i]=(i*fac[i-1])%mod;}
ll power(ll a,ll b){ll res=1;while(b){if(b&1) res=(res*a)%mod;a=(a*a)%mod;b=b/2;}return res%mod;}
ll ncr(ll n,ll r){return ((fac[n]*power(fac[r],mod-2))%mod*power(fac[n-r],mod-2))%mod;}
// DEKHIYE JI  WALID JO THE ABBA HAMARE WO YEH function CHHOD KR GYE THE

signed main()
{   



      
      senky_bansal
      IIIT_ALLAHABAD
      
      // pre();
      ll t;
      // cin>>t;
      t=1;
      while(t--)
      { 
         
         ll n;
         cin>>n;
         ll a[n];
         for(int i=0;i<n;i++)
          cin>>a[i];
        ll ans =1;
        ll mx = a[0];
        for(int i=1;i<n;i++)
        {
          
          if(a[i]<=mx) ans++;
          mx = min(mx,a[i]);
        }
        cout<<ans<<endl;
         

      }
        
      






}



























Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long int
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 10000000000000;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
int main()
{
    fastio;
    ll n=0,k=0;
    cin>>k>>n;
    ll ar[n]={0};
    for(ll i=0;i<n;++i){
       cin>>ar[i]; 
    } 
    ll ans=ar[n-1]-ar[0];
    for(ll i=1;i<n-1;++i){
        ans=min(ans,k-ar[i+1]+ar[i]);
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>

int main(){
  int i,n,cnt=0;
  scanf("%d", &n);

  int a[n];

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

  for(;;){
    for(i=0; i<n; i++){
      if(a[i]%2!=0){
        printf("%d", cnt);
        return 0;
      }
      else{
        a[i]=a[i]/2;
      }
    }cnt++;
  }


  return 0;
}


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

int main(){
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    int left = A+B;
    int right = C+D;

    if(left > right){
        cout << "Left" << endl;
    } else if (left < right){
        cout << "Right" << endl;
    } else {
        cout << "Balanced" << endl;
    }
}

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

typedef unsigned long long ULL;
typedef long long LL;

using namespace std;

int main(){
    int N,i;
    ULL bef;
    ULL A;
    ULL step;
    ULL sum = 0;
    
    cin >> N;
    cin >> bef;
    for(i=1;i<N;i++){
        cin >> A;
        if( bef > A){
            step = bef - A;
        }else{
            step = 0;
        }
        bef = A + step;
        sum += step;
    }

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3592
#include <iostream>
using namespace std;
int main(){
  string str,day[7]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
  cin >> str;
  for(int ans=0;ans<7;ans++){
    if(day[ans]==str)cout << 7-ans << endl;
  }
  return 0;
}

Measured memory_bytes: 256
n=int(input())
a,b=map(int,input().split())
p=[int(i) for i in input().split()]
cnta=0
cntb=0
cntc=0
for i in p:
  if i<=a:
    cnta+=1
  elif i<=b:
    cntb+=1
  else:
    cntc+=1
print(min(cnta,cntb,cntc))


Measured memory_bytes: 38384
#include <iostream>
#include <random>
using namespace std;

int main(){
  int N,max = 0,cnt = 0;
  int H[100] = {0};
    cin >> N;
  for(int i = 0;i<N;i++){
    cin >> H[i];
  }
  
  for(int i = 0;i < N;i++){
  if(max<=H[i]){
    max = H[i];
    cnt++;
  }
  }

  cout << cnt << endl;

}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        long N = GetInputLong();

        Console.Write(N*N*N);

        Console.ReadKey();
    }


    public static int GetInputInt()
    {
        return int.Parse(Console.ReadLine());
    }
    public static int[] GetInputsInt()
    {
        return Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    }
    public static List<int> GetInputsIntList()
    {
        return Console.ReadLine().Split(' ').Select(int.Parse).ToList();
    }
    public static List<float> GetInputsFloatList()
    {
        return Console.ReadLine().Split(' ').Select(float.Parse).ToList();
    }

    public static long GetInputLong()
    {
        return long.Parse(Console.ReadLine());
    }
    public static long[] GetInputsLong()
    {
        return Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
    }

}


Measured memory_bytes: 13140
# E Knapsack 2

from collections import deque

MAX_V = 10**5+1
n, w = map(int,input().split())
wv_list = deque([[int(x) for x in input().split()] for y in range(n)])

dp = [[float("Inf")] * (MAX_V) for _ in range(n+1)]
for i in range(n+1):
    dp[i][0] = 0

for i in range(n):
    _w,_v = wv_list.popleft()
    for j in range(MAX_V):
        if j-_v < 0:
            dp[i+1][j] = dp[i][j]
        else:
            dp[i+1][j] = min(dp[i][j], dp[i][j-_v]+_w)

ans = 0
for i in range(MAX_V):
    if dp[n][i] <= w:
        ans = i
print(ans)

Measured memory_bytes: 399032
#include<stdio.h>
#include<algorithm>
using namespace std;
long long h[100000];
int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int i;
    for(i=0;i<n;i++)
    {
        scanf("%lld",&h[i]);
    }
    long long ans=9223372036854775807;
    sort(h,h+n);
    for(i=0;i+k-1<n;i++)
    {
        ans=ans<(h[i+k-1]-h[i])?ans:(h[i+k-1]-h[i]);
    }
    printf("%lld\n",ans);
    return 0;
}

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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
typedef complex<ld> Point;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 1e5 + 5;
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

int main() {
    ll n, a, b, c, d, e;
    cin >> n >> a >> b >> c >> d >> e;
    ll m = min({a, b, c, d, e});
    out((n + m - 1) / m + 4);
}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

int n;

map<ll, int> cnt;
priority_queue<ll> que;

int main(void) {
  // Here your code !
  scanf("%d", &n);

  for (int i = 0; i < n; ++i) {
    ll tmp;
    scanf("%lld", &tmp);

    cnt[tmp] += 1;
  }

  for (auto itr = cnt.begin(); itr != cnt.end(); ++itr) {
    for (int i = 0; i < itr->second / 2; ++i) {
      que.push(itr->first);
    }
  }

  if (que.empty()) {
    printf("%lld\n", 0);
    return 0;
  }

  ll first = que.top();
  que.pop();

  if (que.empty()) {
    printf("%lld\n", 0);
    return 0;
  }

  ll second = que.top();
  que.pop();

  printf("%lld\n", first * second);

  return 0;
}


Measured memory_bytes: 6528
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();    
    if (a > b) {
      System.out.println(a - 1);
    } else {
      System.out.println(a);
    }
  }
}

Measured memory_bytes: 22868
object Main extends App {
	val pw = new java.io.PrintWriter(System.out)

	@scala.annotation.tailrec
	def loop(start: Int, end: Int)(f: Int => Unit): Unit =
		if (start < end) {
			f(start)
			loop(start + 1, end)(f)
		}

	@scala.annotation.tailrec
	def f(x: BigDecimal, i: Int = 1, a: BigDecimal = 101): Int = if (x <= a) return i else f(x, i+1, (a * 1.01).setScale(0, scala.math.BigDecimal.RoundingMode.FLOOR))

	pw.println(f(BigDecimal(Scanner.next)))
	pw.flush()
}

object Scanner {
	private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0

	@inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
	@inline private def hasNextByte(): Boolean = if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else true
	@inline private def hasNext(): Boolean = {
		while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
		hasNextByte()
	}
	@inline private def readByte(): Byte = if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else -1

	def next(): String = {
		if(!hasNext()) ???
		val sb = new StringBuilder; var b = readByte()
		while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
		sb.toString
	}

	def nextInt(): Int = {
		val n = nextLong()
		if (n < Int.MinValue || Int.MaxValue < n) ???
		n.toInt
	}

	def nextLong(): Long = {
		if(!hasNext()) ???
		var minus = false; var b = readByte()
		if (b == '-') { minus = true; b = readByte() }

		@scala.annotation.tailrec
		def go (b: Byte, n: Long = 0): Long = if ('0' <= b && b <= '9') go(readByte(), n * 10 + b - '0') else if (minus) -n else n

		go(b)
	}

	def nextDouble(): Double = next().toDouble
}


Measured memory_bytes: 55096
import numpy as np
from numba import jit
@jit(cache = True)
def solve(n,k,A):
    l,r=0,0
    for i in range(k):
        B=np.zeros(n+1,dtype=np.int64)
        for x,y in enumerate(list(A)):
            l=max(0,x-y)
            r=min(n,x+y+1)
            B[l]+=1
            B[r]-=1
        A=np.cumsum(B[:-1])
        if A[A==n].size==n:
            break
    return A
n,k=map(int,input().split())
a=list(map(int,input().split()))
A=np.array(a)
X=solve(n,k,A)
print(*X,sep=' ')


Measured memory_bytes: 135532
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 100000000
#define INF 1000000000000000000
#define MOD 1000000007
#define mod 1000000007
#define REP(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define REPE(i, a, n) for (ll i = a; i <= (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair<int,int>Pin;
typedef pair<ll,ll>Pll;
template<class T> using V=vector<T>;
long long GCD(long long a, long long b) {return b?GCD(b,a%b):a;}
long long LCM(long long a, long long b) {return a/GCD(a,b)*b;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
int ddx[8]={-1,0,1,0,1,1,-1,-1};
int ddy[8]={0,-1,0,1,1,-1,1,-1};
ll cmp(pair<ll,ll>a,pair<ll,ll> b){
        if(a.se!=b.se)
        return a.se<b.se;
        else
        return a.fi<b.fi;
}
//----------------------------------------------------------------------

//----------------------------------------------------------------------
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------  
    //ll begin_time=clock();
    //-------------------------------
    set<ll>s;
    int q;cin>>q;
    while(q--){
        ll a,x;cin>>a>>x;
        if(a==0){
            s.insert(x);
            cout<<s.size()<<endl;
        }
        else{
            cout<<(x==*s.lower_bound(x))<<endl;
        }
    }
    //-------------------------------  
    //ll end_time=clock();cout<<"time="<<end_time-begin_time<<"ms"<<endl;
    //-------------------------------
    return 0;
}
//----------------------------------------------------------------------





































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

int main(){
    int a, b;
    cin >> a >> b;
    
    string ans;
    if (a == b) {
        ans = "Draw";
    } else if (a == 1) {
        ans = "Alice";
    } else if (b == 1) {
        ans = "Bob";
    } else if (a > b) {
        ans = "Alice";
    } else {
        ans = "Bob";
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines[0]);
    var ans = 0;

    // mで割った余りがrなので　m > r
    // N = m * r + r > r^2
    // (N-r)/r = m > r

    for (var r = 1; r * r <= N; r++) {
        if ((N - r) % r === 0 && (N - r) / r > r) { ans += (N - r) / r }
    }
    console.log(ans)
});

Measured memory_bytes: 8012
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define int long long
const int MOD=1e9+7;
const int N=3e5+10;
int32_t main()
{
	int nn;
    cin>>nn;
    int ans=0;
    for(int i=1;i<=nn;i++)
    {
        int f=0,f1=0;
       int n=i;
        while(n%3==0)
        {
            n/=3;
            f=1;
        }
        while(n%5==0)
        {
            n/=5;
            f1=1;
        }
        if(!f&&!f1)
            ans+=i;
    }   
    cout<<ans<<endl;



}

Measured memory_bytes: 3628
n, m, c = map(int, input().split())
b = list(map(int, input().split())) 

ans = 0

for _ in range(n):
    a = list(map(int, input().split())) 

    tmp = 0

    for i in range(m):
        tmp += a[i]*b[i]
    
    tmp += c

    if tmp > 0:
        ans += 1

print(ans)

Measured memory_bytes: 38384
k=int(input())
a=[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]
print(a[k-1])

Measured memory_bytes: 9192
#!/usr/local/bin python
# -*- coding: utf-8 -*-
#
# ~/PycharmProjects/atcoder/B-BinaryHackEasy.py
#
s = input()
ans = []

for i in range(len(s)):
    # print("tmp {}".format(s[0]))
    tmp = s[0]
    s = s[1:]
    if tmp == "B" and ans:
        ans.pop()
    elif tmp !="B":
        ans.append(tmp)
        # print(ans)

print("".join([str(n) for n in ans]))


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

using namespace std;
using ll =long long;
using db = double;
using vll = vector<long long>;

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; }
#define che(a,string) cout<<"//"<<string <<"=="<<(a)<<"//" <<endl;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define leftunique(a) {SORT(a);(a).erase(unique((a).begin(),(a).end()),(a).end());}
//leftuniqueは配列から同じ要素のものを取り除く 例 4 6 2 1 3 4 1 2 なら 1 2 3 4 6 になる
bool IsInt(double a){int b = a/1;if(a==b){return true;}else {return false;}}
bool coY() {cout <<"Yes"<<endl;}
bool coN(){cout <<"No"<<endl;}
const int mod = 1e9 + 7;
const ll INF = 1LL << 60;

//ここから書き始める

int main()
{
	cout << setprecision(10);
	ll n , m ;cin >> n >> m;
	ll x = 1900 * m + (n - m )* 100;
	ll ans = x * pow(2,m);
	cout << ans << endl;	
}


Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

const long p = 1_000_000_000 + 7;

bool test(ref long[] h, long a, long b, long n) {
    long m = 0;
    foreach(hi; h) {
        auto r = max(0, (hi - b*n));
        m += (r+(a-b)-1)/(a-b);
    }
    return m <= n;
}

void main(){
    long n, a, b;
    readlnTo(n, a, b);
    long[] h;
    foreach(i; iota(n)) {
        h ~= readLong();
    }
    long u = int.max/2;
    long l = 0;
    while(l+1 < u) {
        auto m = (u+l)/2;
        if(test(h, a, b, m)) {
            u = m;
        } else {
            l = m;
        }
    }
    writeln(u);
}



Measured memory_bytes: 4092
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;

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



int main(){
    IOS;
    priority_queue<int> pque;
    while(1){
        string s; cin >> s;
        if(s == "insert"){
            int x; cin >> x;
            pque.emplace(x);
        }
        else if(s == "extract"){
            cout << pque.top() << "\n";
            pque.pop();
        }else break;
    }
    return 0;
}



Measured memory_bytes: 6956
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let s:Vec<char> = read::<String>().chars().collect();

    let mut cnt1:u32 = 0;
    let mut cnt2:u32 = 0;
    let mut f:bool = true;
    for &ch in s.iter() {
        if ch == '0' {
            if f {
                cnt1 += 1;
            } else {
                cnt2 += 1;
            }
        } else {
            if f {
                cnt2 += 1;
            } else {
                cnt1 += 1;
            }
        }
        f = !f;
    }

    println!("{}", min(cnt1,cnt2));
    
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
priority_queue<double ,vector<double>,greater<double> >pq;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		double k;
		cin>>k;
		pq.push(k);
	}
	while(pq.size()>1){
		double a=pq.top();
		pq.pop();
		double b=pq.top();
		pq.pop();
		double c=(a+b)/2.0;
		pq.push(c);
	}
	printf("%lf",pq.top());
	return 0;
}

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

int main(void) {
    int n, aniki[5] = {};
    long long billy = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        if (s[0] == 'M') aniki[0]++;
        if (s[0] == 'A') aniki[1]++;
        if (s[0] == 'R') aniki[2]++;
        if (s[0] == 'C') aniki[3]++;
        if (s[0] == 'H') aniki[4]++;
    }
    for (int i = 0; i < 5; i++) {
        for (int j = i + 1; j < 5; j++) {
            for (int k = j + 1; k < 5; k++) {
                billy += (long long)aniki[i] * aniki[j] * aniki[k];
            }
        }
    }
    cout << billy << endl;
}


Measured memory_bytes: 256
main(){
	int n,a,b,c,t;	scanf("%d",&n);
	while(n--){
		scanf("%d%d%d",&a,&b,&c);
		if(a>c)	t=a,a=c,c=t;
		if(b>c)	t=b,b=c,c=t;
		if(a*a+b*b==c*c)	puts("YES");
		else				puts("NO");
	}
	exit(0);
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int a,b,c,i,j,n,s;
int main()
{
    scanf("%d%d%d%d",&a,&b,&c,&n);
    for (i=0;i<=a;i++)
    for (j=0;j<=b;j++)
    if ((n-i*500-j*100>=0)&&(n-i*500-j*100<=c*50)) s++;
    printf("%d\n",s);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
using namespace std;

#define N 10000
#define INF 200000000

int main()
{
    int n;
    vector<double> x(3), y(3), x2(3), y2(3);
    cin >> n;

    for(int p=0; p<n; p++)
    {
        cin >> x[0] >> y[0] >> x[1] >> y[1] >> x[2] >> y[2];
        for(int i=0; i<3; i++) { x2[i] = x[i]*x[i]; y2[i] = y[i]*y[i]; }

        double a, b, c, a2, b2, c2;
        a2 = abs((x[2]-x[1])*(x[2]-x[1]) + (y[2]-y[1])*(y[2]-y[1]));
        b2 = abs((x[0]-x[2])*(x[0]-x[2]) + (y[0]-y[2])*(y[0]-y[2]));
        c2 = abs((x[1]-x[0])*(x[1]-x[0]) + (y[1]-y[0])*(y[1]-y[0]));
        a = sqrt(a2); b = sqrt(b2); c = sqrt(c2);

        double s, S2;
        s = (a + b + c) / 2;
        S2 = s * (s-a) * (s-b) * (s-c);

        double cx, cy;
        cx = (a2*(b2+c2-a2)*x[0] + b2*(c2+a2-b2)*x[1] + c2*(a2+b2-c2)*x[2]) / (16 * S2);
        cy = (a2*(b2+c2-a2)*y[0] + b2*(c2+a2-b2)*y[1] + c2*(a2+b2-c2)*y[2]) / (16 * S2);

        cout << setprecision(3) << fixed <<
            cx << " " << cy << " " << sqrt(abs((cx-x[0])*(cx-x[0])+(cy-y[0])*(cy-y[0]))) << endl;
    }
}

Measured memory_bytes: 0
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

bool isKaibun(string S)
{
	rep(i, S.size())
	{
		if (S[i] != S[S.size() - 1 - i])
		{
			return false;
		}
	}

	return true;
}

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

	
	if(!isKaibun(S))
	{
		cout << "No" << endl;
		return 0;
	}

	if (!isKaibun(S.substr(0, (S.size() - 1) / 2)))
	{
		cout << "No" << endl;
		return 0;
	}

	if (!isKaibun(S.substr((S.size() + 3) / 2 - 1)))
	{
		cout << "No" << endl;
		return 0;
	}

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

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
    	int array[] = new int[n];
    	long sum = 0;
    	for(int i = 0; i < n; i ++) {
    		array[i] = sc.nextInt();
    		sum = sum + array[i];
    	}
    	Arrays.sort(array);
    	System.out.printf("%d %d %d\n", array[0], array[n-1], sum);
    }
}


Measured memory_bytes: 42256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define kaj_start int main()
#define kaj_shesh return 0

kaj_start{
    string s;
    cin >> s;

    set<char> st;
    for(int i = 0; i < 4; i++){
        st.insert(s[i]);
    }

    if(st.size() == 2){
        cout << "Yes";
    }else{
        cout << "No";
    }
    kaj_shesh;
}


Measured memory_bytes: 256
S=list(input())
BE=[int(S[0]),int(S[1])]
AF=[int(S[2]),int(S[3])]
b_flag=0
a_flag=0
if BE[0] == 0 and BE[1]>=1:
    b_flag=1
if BE[0] == 1 and BE[1] <=2:
    b_flag=1
if AF[0] == 0 and AF[1]>=1:
    a_flag=1
if AF[0] == 1 and AF[1] <=2:
    a_flag=1
if a_flag ==1 and b_flag==1:
    print('AMBIGUOUS')
elif a_flag ==1:
    print('YYMM')
elif b_flag==1:
    print('MMYY')
else:
    print('NA')


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char a[110];
    int n=0;
    scanf("%s",a);
    for(int i=0;i<strlen(a);i++)
    {
        if(a[i]=='C')
        {
            n=1;
        }
        if(a[i]=='F' && n==1)
        {
            n=2;
        }
    }
    if(n==2)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 256
MOD = 998244353

def solve

  n = gets.to_i
  dists = gets.split.map(&:to_i)

  orig = dists[0]
  dists.sort!


  if dists.count(0) != 1 || orig != 0
    puts "0"
    return
  end

  current_dist = 0
  current_dist_num = 0
  parent_dist_num = 1
  combs = []


  dists.each do |d|
    if current_dist != d
      # is divided?
      if d - current_dist > 1
        puts "0"
        return
      end
      combs << parent_dist_num ** current_dist_num
      parent_dist_num = current_dist_num
      current_dist_num = 0
      # puts "dist: #{d - 1}: #{parent_dist_num} nodes"
      current_dist = d 
    end
    # puts "current: #{current_dist}"
    current_dist_num += 1
  end

  combs << parent_dist_num ** current_dist_num


  # p combs
  puts combs.inject(:*) % MOD
end

solve()

Measured memory_bytes: 72412
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseFloat(x::SubString{String}) = parse(Float64, x)
parseFloat(x::Char) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    s = chomp(readline())
    answer = "AKIHABARA"
    for i = 1:9
        l = length(s)
        if i > l
            s = join([s, 'A'])
        end
        if answer[i] == 'A' != s[i]
            s = join([s[1:i-1], 'A', s[i:end]])
        end
    end
    if s == answer
        println("YES")
    else
        println("NO")
    end
end
main()

Measured memory_bytes: 130948
#include <bits/stdc++.h>
#define inf 1000000007
#define mod 1000000007
//#pragma GCC optimize(2)
//#define int long long
using namespace std;
template <typename T> void read(T &x){
	x=0;char ch=getchar();int fh=1;
	while (ch<'0'||ch>'9'){if (ch=='-')fh=-1;ch=getchar();}
	while (ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
	x*=fh;
}
template <typename T> void write(T x) {
	if (x<0) x=-x,putchar('-');
	if (x>9) write(x/10);
	putchar(x%10+'0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
signed main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,a[105];
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	bool flag=true;
	for(int i=1;i<=n;i++)
		if(a[i]%2==0&&a[i]%3!=0&&a[i]%5!=0)
			flag=false;
	cout<<(flag?"APPROVED":"DENIED")<<endl;
	return 0;
}


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

int main() {
    int K;
    cin >> K;
    queue<long long> que;
    for(int i=1;i<10;i++){
        que.push(i);
    }
    int cnt=0;
    long long x;
    while(cnt<K){
        x=que.front();
        que.pop();
        int y=x%10;
        if(y!=0) que.push(10*x+(y-1));
        que.push(10*x+y);
        if(y!=9) que.push(10*x+(y+1));
        cnt++;
    }
    cout << x << endl;
}

Measured memory_bytes: 1792
import math

n,m = map(int,input().split())

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


if n <= 1 and m <= 1:
  print(0)
elif n <= 1 and m >= 2:
  print(combinations_count(m,2))
elif n >= 2 and m <= 1:
  print(combinations_count(n,2))
else:
  print(combinations_count(n,2)+combinations_count(m,2))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define brep(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<n;i++)
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
#define ll long long


int main(void){
    string n;
    ll ans = 0;
    cin >> n;
    ll ct = 0;
    brep(i,(int)n.size()){
        if(n[i]=='W')ct++;
        if(n[i]=='B')ans+=ct;
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#!/usr/bin/env python3
# atcoder 
# Türkçe konuşyorum
# Türkler var mı
# memnün oldum

K = int(input())
S = input()



if(len(S) <= K):
    print(S)
else:
    print(S[:K] + '.' * 3)
    #for i in range(3):
    #    change = change.replace(change[i], '.')
    #print(S[:K] + change[:3])



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

int main(){
	int a;
  	cin >> a;
  
  	cout << a + a * a + a * a * a << endl;
}

Measured memory_bytes: 3628
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int L,n;
	cin>>L>>n;
	vi in(L);
	rep(i,n){
		int a,b;
		cin>>a>>b;
		in[a-1]++;
		in[b-1]--;
	}
	rep(i,L-1)in[i+1]+=in[i];
	int out=L+1;
	rep(i,L)if(in[i])out+=2;
	cout<<out<<endl;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
using namespace std;
int main(){	
    string X;
    cin >> X;
    int ans=X.length();
    int cnt=0,i;
    for(auto i:X){
        if (i=='S'){
            ++cnt;
        } 
        else{
            if (cnt>0){
                --cnt;
                ans-=2;
            }
            else{
                cnt=0;
            }
        }
    }	
    cout<<ans<<endl;
    return 0;
}

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

int main(){
    int n; cin>>n;
    int ans=0;

    for(int i=1;i<n;i++){
        if(n%i==0) ans+=(n/i)-1;
        else ans+=n/i;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3640
n = int(input())
t,a = map(int, input().split())
h = list(map(int, input().split()))
tem = []
for i in range(n):
    tem1 = t-h[i]*0.006
    tem1 = abs(tem1-a)
    tem.append([tem1, i+1])
tem.sort()
print(tem[0][1])



Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main(){
  vector<vector<char>> data(2,vector<char>(3));
  for(int i=0;i<2;i++){
    for(int j=0;j<3;j++){
      cin>>data.at(i).at(j);
    }
  }
  if(data.at(0).at(0)==data.at(1).at(2)&&data.at(0).at(1)==data.at(1).at(1)&&data.at(0).at(2)==data.at(1).at(0)){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
      
}

Measured memory_bytes: 256
/*
    NEVER GIVE UP!
    THE EXPERT IN ANYTHING WAS ONCE A BEGINNER
*/
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i,a,b) for(ll i=a; i<=b; i++)
#define fi(i,a,b) for(ll i=a; i>=b; i--)
#define fa(x,b) for(auto x:b)
#define TC ll test_case; cin>>test_case; for(ll number=1 ; number <= test_case ; number ++ )
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define endl "\n"

const ld pi = acos(-1);
const ll M=1e9+7,N=1e7+5,INF=1e18;

ll n,m,a,b,c,mx;
vector<string> sv;
vector<vector<pair<ll,ll>>> t;

void pc(string p)
{
    if(sz(p) == n)
        sv.pb(p);

    if(sz(p)>=n)
        return;
    
    pc(p+"0");
    pc(p+"1");
}

void solve()
{    
    cin >> n;
    t.resize(n);
    mx=0;

    f(i,0,n-1)
    {
        cin >> m;
        t[i].resize(m);
        f(j,0,m-1)
        {
            cin >> a >> b;
            a--;
            t[i][j].ff = a;
            t[i][j].ss = b;
        }
    }

    pc("");

    fa(s,sv)
    {
        bool is=true;
        c=0;

        f(i,0,sz(s)-1)
        {
            if(s[i]=='1')
            {
                fa(it,t[i])
                {
                    if( s[it.ff]-'0' !=it.ss)
                    {
                        is=false;
                    }
                }
                c++;
            }            
        }
        // cout << s << " " << c << endl;
        if(is)
            mx=max(mx,c);
    }
    cout << mx << endl;
}

int32_t main()
{
    FIO
    solve();
    return 0;
}

Measured memory_bytes: 2556
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <limits.h>
using namespace std;

/*
std::vector<std::string> v;
void rep(const int n, const int i, int* s)
{
    if(i == n){
        int sum = 0;
        std::string tmp;
        for(int j=0; j<n; j++){
            //cout << s[j];
            tmp += std::to_string(s[j]);
        }
        v.push_back(tmp);
        //cout << endl;
        return;
    }
    s[i] = 0;
    rep(n, i+1, s); 
    s[i] = 1;
    rep(n, i+1, s);
}
*/
bool solve(const int n, const int i, const int m, int* a)
{
    //cout << "solve:" << i << ", " << m << ", " << a[i] << endl;
    if(m == 0){
        //cout << "true!" << endl;
        return true;
    }else if(i >= n){
        //cout << "false!" << endl;
        return false;
    }

    bool res1 = solve(n, i+1, m, a);
    bool res2 = solve(n, i+1, m-a[i], a);
    return (res1 == true || res2 == true);
}
int main()
{
    int n, m;
    cin >> n;
    int a[n];
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    cin >> m;
    int q[m];
    for(int i=0; i<m; i++){
        cin >> q[i];
    }
    
    for(int i=0; i<m; i++){
        bool res = solve(n, 0, q[i], a);
        if(res == true) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    
    /*
    int s[n];
    rep(n, 0, s);
    std::vector<std::string>::iterator itr;
    for(int i=0; i<m; i++){
        itr = v.begin();
        bool eq = false;
        while(itr != v.end()){
            std::string tmp = *itr;
            //cout << tmp << ":";
            int sum = 0;
            for(int j=0; j<n; j++){
                int flag = tmp[n-1-j] - '0';
                sum += a[j]*flag;
                //cout << a[j] << "*" << flag << " ";
            }
            //cout << sum << endl;
            if(sum == q[i]){
                eq = true; break;
            }
            ++itr;
        }
        if(eq == true) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    */
}


Measured memory_bytes: 3108
object Main extends App {
  import scala.io.StdIn._
  val Array(x, a, b) = readLine.trim.split(' ').map(_.toInt)
  val n = readInt()
  println(
    Array.fill(n){readLine.trim}.foldLeft(x){
      case (current, "nobiro") ⇒ math.max(0, current + a)
      case (current, "tidime") ⇒ math.max(0, current + b)
      case (_, "karero") ⇒ 0
      case _ ⇒ ???
    }
  )
}


Measured memory_bytes: 44248
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
#define fi first
#define se second
#define sz(x) int(x.size())
using namespace std;
using ll = long long;
using P = pair<int ,int>;
const int INF = 1001001001;
const int MOD = 1000000007;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

#ifdef _DEBUG
#include "debug.h"
#else
#define debug(...)
#define print(...)
#endif

int main() {
    int n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(a.rbegin(), a.rend());
    ll ans = a[0];
    int k = n-2;
    FOR(i, 1, n-1) {
        if (k>=2) {
            ans += a[i]*2;
            k -= 2;
        } else if (k==1) {
            ans += a[i];
            k -= 1;
        }
        if (k==0) break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4048
#Union Findで連結を判定
N,M = map(int,input().split())
*P, = map(int,input().split())
XY = [list(map(int,input().split())) for _ in range(M)]

class UnionFind:
    def __init__(self,N):
        self.Parent = [-1]*N
    def get_Parent(self,n):
        if self.Parent[n] == -1:return n
        p = self.get_Parent(self.Parent[n])
        self.Parent[n] = p
        return p
    def merge(self,x,y):
        x = self.get_Parent(x)
        y = self.get_Parent(y)
        if x!=y: self.Parent[y] = x
        return
    def is_united(self,x,y):
        return self.get_Parent(x)==self.get_Parent(y)

U = UnionFind(N)
for x,y in XY:
    x-=1
    y-=1
    U.merge(x,y)
print(sum(U.is_united(i,p-1) for i,p in enumerate(P)))

Measured memory_bytes: 127596
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

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

    int N;
    cin >> N;

    vll A;
    rep(i, N)
    {
        ll a;
        cin >> a;

        if (A.empty() || a != A.back()) A.push_back(a);
    }

    if (A.size() <= 1)
    {
        cout << 1000 << endl;
        return 0;
    }

    ll money = 1000;
    ll stock = 0;

    set<int> us, ls;
    us.insert(A.size() - 1);
    reple(i, 1, A.size() - 2)
    {
        if (A[i] > A[i - 1] && A[i] > A[i + 1])
        {
            us.insert(i);
        }
        else if (A[i] < A[i - 1] && A[i] < A[i + 1])
        {
            ls.insert(i);
        }
    }

    bool flg = false;
    rep(i, A.size())
    {
        if (us.count(i) == 1)
        {
            if (!flg)
            {
                stock += money / A[0];
                money %= A[0];
                flg = true;
            }

            money += A[i] * stock;
            stock = 0;
        }
        else if (ls.count(i) == 1)
        {
            auto itr = us.upper_bound(i);
            if (itr != us.end())
            {
                stock += money / A[i];
                money %= A[i];

                flg = true;
            }
        }
    }

    cout << max(money, 1000LL) << endl;

    return 0;
}

Measured memory_bytes: 3528
#include<stdio.h>
int main(){
   int a,b,c,d,ans;

   scanf("%d %d %d %d",&a,&b,&c,&d);

   if(a>c){
       c=a;
   }
   if(b<d){
       d=b;
   }

   ans=d-c;
   if(ans>0){
       printf("%d",ans);
   }
   else if(ans<=0){
       printf("0");
   }

   return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

#define abs(a) ((a)<0 ? -(a) : (a))
#define chmin(a,b) ((a)<(b) ? (a) : (b))

#define MaxNum 100200

int main()
{
  int a[MaxNum];
  int N,K;
  
  scanf("%d %d",&N,&K);
  
  for(int i=0;i<N;i++)
    scanf("%d",&a[i]);
  
  int dp[MaxNum];
  
  //極大値で初期化
  for(int i=0;i<MaxNum;i++)
    dp[i]=2147483640;
  
  dp[0]=0;
    
  for(int i=0;i<N;i++)
    for(int j=1;j<=K;j++)
      dp[i+j]=chmin(dp[i+j],dp[i]+abs(a[i+j]-a[i]));
  
  printf("%d",dp[N-1]);
}

Measured memory_bytes: 896