akhauriyash/Code-Regression huggingface dataset:
n, m = map(int, input().split())
k_s = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))

s = bin(0)[2:].zfill(n)
ans = 0

for i in range(2 ** n):
    cnt = 0
    for j in range(m):
        on = 0
        for k in range(1, k_s[j][0] + 1):
            if s[k_s[j][k] - 1] == '1':
                on += 1
            if k == k_s[j][0]:
                if on % 2 == p[j]:
                    cnt += 1
    if cnt == m:
        ans += 1
    s = bin(int(s, 2) + 1)[2:].zfill(n)
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define int long long 
using namespace std;

int32_t main(){

    int l ,r;   cin >> l >> r;

    int ans = 0;

    while(l <= r)
        l*= 2 , ans++;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
using namespace std;
int main(){
    int x1,x2,x3,x4,y1,y2,y3,y4;
    cin >> x1 >> y1 >> x2>> y2;
    int l1,l2;
    l1=x2-x1;
    l2=y2-y1;
    x3=x2-l2;
    y3=y2+l1;
    x4=x1-l2;
    y4=y1+l1;
    cout << x3 << ' ' ;
    cout << y3 << ' ' ;
    cout << x4 << ' ' ;
    cout << y4 << endl; 
}

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

using namespace std;

int main(){
  int N, M, i, count;
  cin >> N >> M;
  int X[M], dif[M-1];
  for(i=0; i<M; i++) cin >> X[i];
  sort(X, X+M);
  for(i=0; i<M-1; i++){
    dif[i] = X[i+1]-X[i];
  }
  sort(dif, dif+M-1);
  if(N>=M) cout << "0\n";
  else{
    count = X[M-1] - X[0];
    for(i=0; i<N-1; i++){
      count -= dif[M-2-i];
    }
    cout << count << "\n";
  }
  return 0;
}


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

#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>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, d;
  cin >> n >> d;
  int a = 2 * d + 1;
  cout << (n + a - 1) / a << endl;
  return 0;
}
//templete by private_yusuke

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

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

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; }
template<class T>
T GCD(T a, T b) { if (b == 0) return a; else return GCD(b, a % b); }
template<class T>
T LCM(T a, T b) { return a / GCD(a, b) * b; }

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

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

	vi a(n);
	rep(i, n) cin >> a[i];

	vi s, ord(n + 1, -1);
	int c = 1, l = 0;

	{
		int v = 1;
		while (ord[v] == -1) {
			ord[v] = s.size();
			s.push_back(v);
			v = a[v - 1];
		}

		c = s.size() - ord[v];
		l = ord[v];
	}

	if (k < l) cout << s[k] << endl;
	else {
		k -= l;
		k %= c;
		cout << s[l + k] << endl;
	}
}

Measured memory_bytes: 5816
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int asc(const void *a, const void *b)
{
    return *(long int *)a - *(long int *)b;
}
int dis(const void *a, const void *b)
{
    return *(long int *)b - *(long int *)a;
}
int main()
{
    int n, k;
    int p[200010];
    int ans;
    int t = 0;
    int i = 0;
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &p[i]);
    }
    for (; i < k; i++)
    {
        t += p[i];
    }
    ans = t;
    for (; i < n; i++)
    {
        t -= p[i - k];
        t += p[i];
        ans = (ans > t) ? ans : t;
    }
    printf("%lf", (double)(ans + k) / 2);
    return 0;
}

Measured memory_bytes: 896
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int x = sc.nextInt();
    int[] l = new int[n];
    int sum = 0;
    int count = 0;
    for(int i=0;i<n;i++){
      l[i]=sc.nextInt();
    }
    for(int j=0;j<n;j++){
      sum += l[j];
      if(sum > x){
        break;
      }
      count++;
    }
    System.out.println(count+1);
  }
}

Measured memory_bytes: 25172
//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <set>
#include <stack>
#include <sstream>
#include <list>
//#include <array>
#include <vector>
#include <queue>
#include <map>
#include <memory>
#include <iterator>
#include <climits>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define FAST_IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned int UINT;
typedef unsigned long long ull;
typedef pair<int, int> pdi;
typedef pair<ll, int> pli;

int const maxn = 2e5 + 10;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
inline int lc(int x)  {return x << 1;}
inline int rc(int x)  {return x << 1 | 1;}
int const MOD = 1e9 + 7;

ll a[maxn];

int main(void) {
    FAST_IO;
    
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    sort(a + 1, a + 1 + n);
    ll ans = 1;
    int l = 1, r = n;
    int flag = 1;
    if (k & 1) {
        ans = ans * a[r];
        ans %= MOD;
        k--;
        r--;
        if (ans < 0) flag = -1;
    }
    while (k != 0) {
        ll x1 = a[l] * a[l + 1];
        ll x2 = a[r] * a[r - 1];
        if (x1 * flag > x2 * flag) {
            ans = ((ans % MOD) * (x1 % MOD) + MOD ) % MOD;
            l += 2;
        } else {
            ans = ((ans % MOD) * (x2 % MOD) + MOD ) % MOD;
            r -= 2;
        }
        k -= 2;
    }
    cout << (ans + MOD) % MOD << endl;

    return 0;
}

Measured memory_bytes: 5160
// import std = require('tstl')

{
  type Print = void | string | number | string[] | number[]
  let outs: Print[] = []

  const main = (): Print => {
    const r = _io()
    const [X, K, D] = r.nn()
    const xp = Math.abs(X)

    const plusMin = xp % D
    const minusMin = Math.abs((xp % D) - D)
    const steps = (xp - plusMin) / D

    const t = xp - K * D

    if (t >= 0) {
      return t
    }
    // console.log(sueps)
    // console.log(steps % 2)

    return Math.abs([plusMin, minusMin][(K - steps) % 2])
  }

  const _io = (i = 0) => {
    const str: string = require('fs').readFileSync('/dev/stdin', 'utf8')
    const lines = str.trim().split('\n')
    const s = () => lines[i++] || ''
    const n = () => Number(s())

    const mn = (v: string[]) => v.map(Number)
    const sp = (v: string) => v.split(' ')

    const ss = () => sp(s())
    const nn = () => mn(ss())
    const nls = () => mn(lines.slice(i))
    const nnls = () => lines.slice(i).map((v) => mn(sp(v)))

    return { lines, s, n, ss, nn, nls, nnls }
  }

  outs.push(main())

  console.log(
    outs
      .map((line) => (typeof line === 'object' ? line.join(' ') : String(line)))
      .join('\n')
  )
}


Measured memory_bytes: 29632
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define ll long long
//#define cccgift
#define lowbit(x) ((x)&-(x))
#define rep(i,l,r) for(res i=l,_r=r;i<=_r;++i)
#define per(i,r,l) for(res i=r,_l=l;i>=_l;--i)
#define mkp make_pair
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem0n(a,n) memset(a,0,(n)*sizeof(a[0]))
#define iter(x,v) for(res v,_p=head[x];v=ver[_p],_p;_p=nxt[_p])
#ifdef cccgift //by lqh
#define SHOW(x) cerr<<#x"="<<(x)<<endl
#else
#define SHOW(x) 0
#endif
//#define getchar()(ip1==ip2&&(ip2=(ip1=ibuf)+fread(ibuf,1,1<<21,stdin),ip1==ip2)?EOF:*ip1++)
//char ibuf[1<<21],*ip1=ibuf,*ip2=ibuf;
template<typename T>
inline void read(T &x)
{
    static char ch;bool f=1;
    for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
    for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
    if (x<0) x=-x,putchar('-');
    if (x>9) print(x/10);
    putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}
int n,k,a[200001],tot[200010];
inline void add(int l,int r) {
	chkmax(l,1),chkmin(r,n);
	++tot[l],--tot[r+1];
}
int main()
{
	read(n),read(k);
	rep(i,1,n) read(a[i]);
	rep(i,1,k) {
		mem0n(tot,n+1);
		rep(j,1,n) add(j-a[j],j+a[j]);
		rep(j,1,n) a[j]=(tot[j]+=tot[j-1]);
		bool flag=true;
		rep(j,1,n) flag&=(a[j]==n);
		if(flag) break;
	}
	rep(i,1,n) print(a[i],' ');puts("");
	return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do something instead of nothing and stay organized
*/

Measured memory_bytes: 5192
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

vector<int> G[200001];
ll ans[200001];
ll score[200001];

void dfs(int n, ll sc){
  ans[n] = sc + score[n];
  for(int i = 0; i < G[n].size(); i++){
    dfs(G[n][i], ans[n]);
  }
  return;
}

int main(){
  int N, Q;
  cin >> N >> Q;
  for(int i = 0; i < N - 1; i++){
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
  }

  for(int i = 0; i < Q; i++){
    int p;
    ll x;
    cin >> p >> x;
    p--;
    score[p] += x;
  }

  dfs(0, 0);

  for(int i = 0; i < N; i++){
    cout << ans[i] << " ";
  }

  cout << endl;

  return 0;

}


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

using namespace std;

typedef long long ll;

int getfa(int x, vector<int>& fa) {
	return fa[x] == x ? x : fa[x] = getfa(fa[x], fa);
}

int main() {
	int n, m, x, y, fx, fy;
	scanf("%d %d", &n, &m);
	vector<pair<int, int>> links;
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &x, &y);
		links.push_back(make_pair(x, y));
	}
	vector<int> fa(n + 1), cnt(n + 1);
	for (int i = 1; i <= n; i++) {
		fa[i] = i;
		cnt[i] = 1;
	}
	vector<ll> res;
	ll tot = 1LL * n * (n - 1) / 2;
	for (int i = links.size() - 1; i >= 0; i--) {
		x = links[i].first;
		y = links[i].second;
		fx = getfa(x, fa);
		fy = getfa(y, fa);
		res.push_back(tot);
		if (fx != fy) {
			fa[fx] = fy;
			tot -= 1LL * cnt[fx] * cnt[fy];
			cnt[fy] += cnt[fx];
		}
	}
	for (int i = res.size() - 1; i >= 0; i--) {
		printf("%lld\n", res[i]);
	}
	return 0;
}

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  
  int N;
  cin >> N;
  vector<int> aa(3 * N);
  for ( int i = 0; i < 3 * N ; i++) cin >> aa.at(i);
  
  sort(aa.begin(), aa.end());

  ll s = 0;
  for ( int i = N ; i < 3 * N ; i+=2){
    s += aa.at(i);
  }
  cout << s << endl;
}
  


Measured memory_bytes: 1408
#include <cstdio>
const int Maxn=100;
char s[Maxn+5];
int n;
int main(){
	scanf("%s",s+1);
	while(s[++n]!='\0');
	n--;
	if(n&1){
		puts("No");
		return 0;
	}
	for(int i=1;i<n;i+=2){
		if(s[i]=='h'&&s[i+1]=='i'){
		}
		else{
			puts("No");
			return 0;
		}
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

#define mod 1000000007

int main(){
	int n,i,j,k,l,m;
	const int a=0,g=1,c=2,t=3;
	long long ans=0;
	long long dp[101][4][4][4]={0};
	scanf("%d",&n);
	for(i=0;i<4;i++){
		for(j=0;j<4;j++){
			for(k=0;k<4;k++){
				if(i==a&&j==g&&k==c)continue;
				if(i==a&&j==c&&k==g)continue;
				if(i==g&&j==a&&k==c)continue;					
				dp[3][i][j][k]=1;
			}
		}
	}
	for(i=3;i<n;i++){
		for(j=0;j<4;j++){
			for(k=0;k<4;k++){
				for(l=0;l<4;l++){
					for(m=0;m<4;m++){
						if(k==a&&l==g&&m==c)continue;
						if(k==a&&l==c&&m==g)continue;
						if(k==g&&l==a&&m==c)continue;
						if(j==a&&l==g&&m==c)continue;
						if(j==a&&k==g&&m==c)continue;
						dp[i+1][k][l][m]+=dp[i][j][k][l];
						dp[i+1][k][l][m]%=mod;
					}
				}
			}
		}
	}
	for(i=0;i<4;i++){
		for(j=0;j<4;j++){
			for(k=0;k<4;k++){
				ans+=dp[n][i][j][k];
			}
		}
	}
	printf("%lld\n",ans%mod);
	return 0;
}

Measured memory_bytes: 256
n= input()
if n[-1]== "2" or n[-1]=='4' or n[-1]== '5' or n[-1]=='7' or n[-1]=='9':
    print("hon")
elif n[-1] == '0' or n[-1]=='1' or n[-1]== '6' or n[-1]== '8':
    print("pon")
else:
    print("bon")



Measured memory_bytes: 9052
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace ABC176
{
    class Program
    {
        static void Main(string[] args)
        {
            //var NXT = Console.ReadLine().Split().Select(double.Parse).ToArray();
            // var A = Console.ReadLine().Split().Select(long.Parse).OrderBy(x => x).ToArray();
            // var CA = Enumerable.Repeat(0, (int)N).Select(_ => Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray();
            var S = Console.ReadLine();
            //var L = Console.ReadLine().Split().Select(long.Parse).OrderBy(x => x).ToArray();
            var count = 0;
            for (int i = 0; i < S.Length; i++)
            {
                count += int.Parse(S[i].ToString());
            }
            if (count % 9 == 0) Console.WriteLine("Yes");
            else Console.WriteLine("No");

        }
    }
}


Measured memory_bytes: 32632
#include <bits/stdc++.h>
using namespace std;
const int MAX_N=16005;
vector <int> arms;
int x,y;
bool dp[2][MAX_N][MAX_N];
vector <int> a[2];
int main()
{
	string s;
	cin>>s;
	cin>>x>>y;
	x+=8000;
	y+=8000;
	arms.push_back(0);
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='F')arms.back()++;
		else arms.push_back(0);
	}
	a[1].push_back(0);
	for(int i=0;i<arms.size();i++)
	{
		a[i&1].push_back(arms[i]);
	}
	for(int k=0;k<=1;k++)
	{
		dp[k][0][8000+a[k][0]]=true;
		for(int i=1;i<a[k].size();i++)
		{
			for(int j=0;j<=16000;j++)
			{
				if(j-a[k][i]>=0)dp[k][i][j]|=dp[k][i-1][j-a[k][i]];
				if(j+a[k][i]<=16000)dp[k][i][j]|=dp[k][i-1][j+a[k][i]];
			}
		}
	}
	int _0=a[0].size()-1;
	int _1=a[1].size()-1;
	puts((dp[0][_0][x] && dp[1][_1][y])?"Yes":"No");
	return 0;
}


Measured memory_bytes: 127232
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<deque>

#define fi first
#define se second

using namespace std ;

template<class T> class myQueue{
  deque<T> v;
  public:
  myQueue(){};
  void push(const T & n_){
    v.push_back(n_) ;
  }
  void pop(){
    v.erase(v.begin()) ;
  }
  bool empty(){
    return v.empty() ;
  }
  T front(){
    return v[0] ;
  }
  T back(){
    return v[v.size()-1] ;
  }
  size_t size(){
    return v.size() ;
  }
};

int main(){
  myQueue<pair<string,int>> mq;
  vector<pair<string,int>> vsi ;
  int n,q,n2,time = 0 ;
  string s;
  pair<string,int> psi;
  cin >> n >> q ;
  for(int i = 0; i < n; ++i){
    cin >> s >> n2 ;
    mq.push(make_pair(s,n2)) ;
  }
  while(!mq.empty()){
    psi = mq.front() ;
    n2 = psi.se - q ;
    if(n2 <= 0){
      time += psi.se ;
      vsi.push_back(make_pair(psi.fi,time)) ;
    }
    else{
      time += q ;
      psi.se = n2 ;
      mq.push(psi) ;
    }
    mq.pop() ;
  }
  for(auto n3: vsi){
    cout << n3.fi << " " << n3.se << endl;
  }

  return 0 ;
}

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

int	main() {
	string S;
	cin >>S;
	reverse(S.begin(), S.end());
	int i=0;
	int N=S.size();
	while(i<N) {
		if (('r'==S.at(i))&&('e'==S.at(i+1))) {
			if((N>i+6)
					&&('m'==S.at(i+2))
					&&('a'==S.at(i+3))
					&&('e'==S.at(i+4))
					&&('r'==S.at(i+5))
					&&('d'==S.at(i+6)))
				i+=7;
			else if((N>i+5)
					&&('s'==S.at(i+2))
					&&('a'==S.at(i+3))
					&&('r'==S.at(i+4))
					&&('e'==S.at(i+5)))
				i+=6;
			else {
				cout <<"NO" <<endl;
				return 0;
			}
		} else if ((N>i+4)
				&&('m'==S.at(i))
				&&('a'==S.at(i+1))
				&&('e'==S.at(i+2))
				&&('r'==S.at(i+3))
				&&('d'==S.at(i+4)))
			i+=5;
		else if ((N>i+4)
				&&('e'==S.at(i))
				&&('s'==S.at(i+1))
				&&('a'==S.at(i+2))
				&&('r'==S.at(i+3))
				&&('e'==S.at(i+4)))
			i+=5;
		else {
			cout <<"NO" <<endl;
			return 0;
		}
	}
	cout <<"YES" <<endl;
	return 0;
};


Measured memory_bytes: 512
n, m = gets.chomp.split(' ').map(&:to_i)
keys = Array.new(m)
(0...m).each do |i|
  a, b = gets.chomp.split(' ').map(&:to_i)
  open = gets.chomp.split(' ').map(&:to_i)
  bit = 0
  (0...b).each do |j|
    bit += 1 << (open[j] - 1)
  end
  keys[i] = [a, bit]
end
dp = Array.new(1 << n, 1000000001)
dp[0] = 0
(0...m).each do |i|
  key = keys[i]
  (0...(1 << n)).each do |j|
    k = j | key[1]
    dp[k] = [dp[j] + key[0], dp[k]].min
  end
end
puts dp.last == 1000000001 ? '-1' : dp.last


Measured memory_bytes: 2300
#include "bits/stdc++.h"
 
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll,ll>;
using str = string;
using vpl4 = vector<pair<ll,ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define vllin(x,n) vll (x)(n);FOR(i,0,n-1){cin >>(x)[i];}
#define vllin2(a,b,n) vll (a)(n);vll (b)(n);FOR(i,0,n-1){cin >>(a)[i]>>b[i];}
#define vpl4in(x,n) vpl4 (x)((n),mp(0,0));FOR(i,0,n-1){cin >>x[i].fi>>x[i].se;}
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define says(x) cout<<(x)<<(' ');
#define sas cout<<(' ');
#define sayR(x) cout<<fixed<<setprecision(10)<<(x);
#define salR(x) cout<<fixed<<setprecision(10)<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define pow(a,b) ll(pow(a,b))

ll MOD=1000000007;

signed main(){
	llin(n);
	vllin(b,n);
	ll l=0;
	vll c(n,0);
	rFOR(i,0,n-1){
		rFOR(j,0,i){
			if(b[j]==j+1){
				l=1;
				b.erase(b.be+j);
				c[i]=j+1;
				break;
			} 
		}
		if(l==0){
			sal(-1);
			return 0;
		}
		l=0;
	}
	FOR(i,0,n-1){
		sal(c[i]);
	}
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  ll N = nextLong();
  ll L = nextLong();
  ll T = nextLong();

  vector<ll> X(N), W(N);
  REP(i, N) {
    X[i] = nextLong();
    W[i] = nextLong();
  }

  vector<ll> Y(N);
  REP(i, N) {
    if (W[i] == 1) Y[i] = (X[i] + T) % L;
    if (W[i] == 2) Y[i] = ((X[i] - T) % L + L) % L;
  }

  ll Y0 = Y[0];
  sort(ALL(Y));

  ll d = 0;
  for (int i = 1; i < N; i++) {
    if (W[0] == 1 && W[i] == 2) {
      ll t = 2 * T;
      if (t >= abs(X[i] - X[0])) {
        d++;
        t -= abs(X[i] - X[0]);
      }
      d += max(0LL, t / L);
    }
    if (W[0] == 2 && W[i] == 1) {
      ll t = 2 * T;
      if (t >= L - abs(X[i] - X[0])) {
        d++;
        t -= L - abs(X[i] - X[0]);
      }
      d += max(0LL, t / L);
    }
  }
  // cout << "d=" << d << endl;
  d %= N;

  vector<ll> ans(N);

  if (W[0] == 1) {
    int y0 = prev(upper_bound(ALL(Y), Y0)) - Y.begin();
    REP(i, N) ans[(d + i) % N] = Y[(y0 + i) % N];
  } else {
    int y0 = (lower_bound(ALL(Y), Y0)) - Y.begin();
    REP(i, N) ans[(N - d + i) % N] = Y[(y0 + i) % N];
  }

  REP(i, N) {
    cout << ans[i] << '\n';
  }
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll MOD = 1e9+7;

ll N, K;

const int MAX_N = 100000;

ll fact[MAX_N+100];
ll frev[MAX_N+100];

ll rev(ll a, ll p){
    if(p == 0) return 1;
    ll tmp = rev(a, p/2);
    tmp = tmp * tmp % MOD;
    if(p % 2 == 1) tmp = tmp * a % MOD;
    return tmp;
}


void calc_fact(){
    fact[0] = frev[0] = 1;
    for(int i = 1; i <= MAX_N; i++){
        fact[i] = (fact[i-1] * i) % MOD;
        frev[i] = rev(fact[i], MOD-2);
    }
}


ll comb(int n, int k){
    if(n < 0 || k < 0 || n < k) return 0;
    if(n == 0 || k == 0) return 1;
    return fact[n] * frev[k] % MOD * frev[n-k] % MOD;
}

ll solve(vector<ll> X){
    ll rem = N;
    ll ret = 0;
    REP(i,N){
        rem--;
        ret += X[i] * comb(rem, K-1);
        ret += MOD;
        ret %= MOD;
    }
    return ret;
}

int main(){
    cin >> N >> K;
    vector<ll> A(N);
    REP(i,N){
        ll a;
        cin >> a;
        A[i] = a;
    }

    //in main function
    fact[0] = frev[0] = 1;
    for(int i = 1; i <= MAX_N; i++){
        fact[i] = (fact[i-1] * i) % MOD;
        frev[i] = rev(fact[i], MOD-2);
    }

    ll ans = 0;
    sort(A.rbegin(), A.rend());
    ans += solve(A);

    reverse(A.begin(), A.end());
    ll sub = solve(A);
    ans += MOD - sub;
    ans %= MOD;

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3440
from collections import Counter
def check():
  H, W = map(int, input().split())
  A = ''
  for i in range(H):
    A += input()
  c = Counter(A)
  if H%2==0:
    if W%2==0:
      for v in c.values():
        if v%4!=0:
          return 'No'
      return 'Yes'
    cnt = 0
    for v in c.values():
      if v%2==1:
        return 'No'
      if v%4==2:
        cnt += 1
        if cnt>H//2:
          return 'No'
    return 'Yes'
  if W%2==0:
    cnt = 0
    for v in c.values():
      if v%2==1:
        return 'No'
      if v%4==2:
        cnt += 1
        if cnt>W//2:
          return 'No'
    return 'Yes'
  one,two = 0,0
  for v in c.values():
    if v%2==1:
      one += 1
    if v%4==2:
      two += 1
    if one>1 or two>W//2+H//2:
      return 'No'
  return 'Yes'
print(check())

Measured memory_bytes: 9500
#include <bits/stdc++.h>
using namespace std;
long long mod = 1000000007;
long long h[500000];
long long pow_mod(long long a, long long b) {
    if (b == 0) return 1;
    long long k = pow_mod(a, b/2);
    long long kk = (k*k) % mod;
    if (b % 2 == 0) return kk;
    return (kk * a) % mod;
}
long long nCr(long long n, long long r) {
    long long res = h[n];
    res *= pow_mod(h[r], mod-2);
    res %= mod;
    res *= pow_mod(h[n-r], mod-2);
    res %= mod;
    return res;
}
int main () {
    h[0] = h[1] = 1;
    for (int i = 2; i < 500000; i++) {
        h[i] = (h[i-1] * i) % mod;
    }
    int n, k;
    cin >> n >> k;
    if (n-1 < k) k = n-1;
    long long ans = 0;
    for (int i = 0; i <= k; i++) {
        ans += (nCr(n, n-i) * nCr(i+(n-i-1), i)) % mod;
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4096
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <time.h>
#include <vector>

using namespace std;
typedef long long ll;
template <class T = ll>
T in() {
    T x;
    cin >> x;
    return (x);
}
template <class T>
void print(T x) {
    cout << x << "\n";
}
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define reps(x, c) for (auto x : c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a)
#define mp(a, b) make_pair((a), (b))
#define pl pair<ll, ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cerr << #x "=" << (x) << "\n"
#define dbgv(x) \
    cerr << #x << "\n"; \
    reps(y, x) { cerr << y << " "; } \
    cerr << "\n"

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

    rep(i, n) {
        if (s[i] != s[k - 1]) {
            s[i] = '*';
        }
    }
    cout << s << endl;
}

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

using namespace std;
double a[200005],b[200005];
int main()
{
    int n,k;
    double x,s=0,max1;
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        a[i]=(x+1)/2;
    }
    for(int i=0;i<k;i++)
    {
        s+=a[i];
    }
    max1=s;
    for(int i=k;i<n;i++)
    {
        s-=a[i-k];
        s+=a[i];
        max1=max(s,max1);
    }
    printf("%.12lf",max1);
    return 0;
}


Measured memory_bytes: 1920
k, t = map(int, input().split())
A = list(map(int, input().split()))
if t == 1:
    print(k-1)
else:
    maxi = 0
    for i in range(t):
        maxi = max(maxi, i, key=lambda x:A[x])
    maxa = A.pop(maxi)
    sa = sum(A)
    print(max(0, maxa-1 - sa))
    

Measured memory_bytes: 9088
#include<iostream>
#include<string>
#include<cstring>
#include<iomanip>
using namespace std;
char a[100005], b[100005];
int main()
{
	cin >> a;
	int len = strlen(a),jian=0;
	for (int i = 0; i < len; i++)
	{
		b[i] = a[len - i-1];
		if (b[i] == 'd')b[i] = 'b';
		else if (b[i] == 'b')b[i] = 'd';
		else if (b[i] == 'p')b[i] = 'q';
		else if (b[i] == 'q')b[i] = 'p';
		if (b[i] != a[i]) { jian = 1; break; }
	}
	if (jian == 0)cout << "Yes";
	else cout << "No";
	return 0;
}



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




int main (){
  
  
   int x; cin >> x;
   int ans = 0;
   while(x >= 5){
    if(x >= 500){
        ans += ((x/500) * 1000);
        x = x % 500;
    } else if(x >= 5){
        ans += ((x/5) * 5);
        x = x % 5;
    }
   }
   
    cout << ans << "\n";
  
   
   return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int[] c = new int[n-1];

        int res = 0;
        for(int i=0; i<n; i++) {
            a[i] = sc.nextInt() - 1;
        }
        for(int i=0; i<n; i++) {
            b[i] = sc.nextInt();
            res += b[i];
        }
        for(int i=0; i<n-1; i++) {
            c[i] = sc.nextInt();
        }
        for(int i=0; i<n-1; i++) {
            if(a[i] + 1 == a[i+1]) {
                res += c[a[i]];
            }
        }



        System.out.println(res);

    }


}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define mod 1000000007
#define mod998 998244353
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
typedef long long ll;
using namespace std;

int A,B;

int main(){
	cin>>A>>B;
	if(B==1){
		cout<<0<<endl;
		return 0;
	}
	cout<<(B-1-1)/(A-1)+1<<endl;
}


Measured memory_bytes: 256
//  ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿>
//  ⣿         
//  ⣿ Author - midu_01C
//  ⣿         
//  ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿>

import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;

public class Main
{
    static Scanner cin = new Scanner(System.in);
    static PrintStream cout = new PrintStream
    (new FileOutputStream(FileDescriptor.out));
    
    public static void main(String args[])
    {
        int t,n,m,a,b,c,d,e,i,j,k,x,y,z,cnt=0;
        boolean flag = false; Vector v = new Vector();
        
        String s;
        s=cin.next();
        char[] ch=s.toCharArray();
        x=0;
        cnt=0;
        for(char c1:ch)
        {
            if(c1=='R') cnt++;
            else cnt=0;
            x=Math.max(x,cnt);
        }
        cout.println(x);
    }
}


Measured memory_bytes: 35656
#include <cmath>
#include <cstdio>

#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(), x.end()

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  ll n;
  cin >> n;

  ll a;
  ll cnt4=0, cnt0=0;
  rep(i, n){
    cin >> a;
    if(a%4==0) ++cnt4;
    if(a%2==1) ++cnt0;
  }
  if((cnt4 + cnt0 == n and cnt4 + 1>= cnt0)or cnt4>=cnt0) cout << "Yes" << endl;
  else cout << "No" << endl;


  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
#define endl "\n"
using namespace std;
const ll N=100010;

ll power(ll x,ll n)
{
    if(n==0){return 1;}
    if(n==1){return x%M;}
    if(n%2==0){
        return power((x*x)%M,n/2);
    }
    else{
        return (x*power((x*x)%M,n/2))%M;
    }
}


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

    ll n;
    cin>>n;
    vector<pi> ar(n);
    for(ll i=0;i<n;++i){
        cin>>ar[i].first>>ar[i].second;
    }
    sort(ar.begin(),ar.end());
    ll plusmin=ar[0].first+ar[0].second,minusmin=ar[0].first-ar[0].second;
    ll ans=0;
    for(ll i=1;i<n;++i){
        ll plus=ar[i].first+ar[i].second;
        ll minus=ar[i].first-ar[i].second;
        ans=max(ans,max(plus-plusmin,minus-minusmin));
        plusmin=min(plusmin,plus);
        minusmin=min(minusmin,minus);
    }
    cout<<ans;
    

    return (0);
}


Measured memory_bytes: 6364
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0;i < (int)(n);i++)
#define RREP(i,n) for(int i = (int)n-1;i >= 0;i--)
#define FOR(i,s,n) for(int i = s;i < (int)n;i++)
#define RFOR(i,s,n) for(int i = (int)n-1;i >= s;i--)
#define ALL(a) a.begin(),a.end()
#define IN(a, x, b) (a<=x && x<b)
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a = b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a = b;return true;}return false;}
template<class T>istream&operator >>(istream&is,vector<T>&vec){for(T&x:vec)is>>x;return is;}
template<class T>inline void OUT(T t){cout<<t<<"\n";}
template<class T,class... Ts>inline void OUT(T t,Ts... ts){cout<<t<<" ";OUT(ts...);}
template<typename T=int>vector<T>mv(size_t a){return vector<T>(a);}
template<typename T=int,typename... Ts>auto mv(size_t a,Ts... ts){return vector<decltype(mv<T>(ts...))>(a,mv<T>(ts...));}
template<typename T,typename V>typename enable_if<is_class<T>::value==0>::type FILL(T&t,const V&v){t=v;}
template<typename T,typename V>typename enable_if<is_class<T>::value!=0>::type FILL(T&t,const V&v){for(auto &e:t)FILL(e,v);}
constexpr long long INF = 1e18;

signed main(){
	int N,M;
	cin>>N>>M;
	OUT(N*M);
}


Measured memory_bytes: 3100
N=input()
C_0=0
C_1=0
C_2=0
C_3=0
for i in range(int(N)):
    S_i=input()
    if S_i=='AC':
        C_0=C_0+1
    elif S_i=='WA':
        C_1=C_1+1
    elif S_i=='TLE':
        C_2=C_2+1
    else:
        C_3=C_3+1
print('AC x '+str(C_0))
print('WA x '+str(C_1))   
print('TLE x '+str(C_2))   
print('RE x '+str(C_3))    

Measured memory_bytes: 9224
def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    from collections import defaultdict
    count = defaultdict(int)
    ans = 0
    for i, a in enumerate(A):
        if i - a in count:
            ans += count[i-a]
        count[i+a] += 1
    print(ans)
 
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 40668
a,b,c,d = map(int,input().split())
dx = c-a
dy = d-b
print('U'*dy+'R'*dx+'D'*dy+'L'*(dx+1)+'U'*(dy+1)+'R'*(dx+1)+'D'+'R'+'D'*(dy+1)+'L'*(dx+1)+'U')

Measured memory_bytes: 3060
#include <stdio.h>

#define DICE 6
#define CMD 128

typedef struct {
  int side[DICE];
} dice_t;

dice_t rotateN(dice_t d);
dice_t rotateS(dice_t d);
dice_t rotateW(dice_t d);
dice_t rotateE(dice_t d);
dice_t rotateR(dice_t d);
dice_t rotateL(dice_t d);

int main(void){
  int i, j, isEqual;
  dice_t d1, d2, d2copy;

  for (i = 0; i < DICE; i++)
    scanf("%d", &d1.side[i]);
  for (i = 0; i < DICE; i++)
    scanf("%d", &d2.side[i]);
  d2copy = d2;

  // search for top side and fix
  for (j = 0; j < DICE; j++) {
    isEqual = 1;
    d2 = d2copy;
    if (d1.side[0] == d2.side[j]) {
      switch (j) {
      case 0:
	break;
      case 1:
	d2 = rotateN(d2);
	break;
      case 2:
	d2 = rotateW(d2);
	break;
      case 3:
	d2 = rotateE(d2);
	break;
      case 4:
	d2 = rotateS(d2);
	break;
      default: // case 5:
	d2 = rotateN(d2);
	d2 = rotateN(d2);
	break;
      }
    }

    // search for front side
    for (i = 0; i < 3; i++) {
      if (d1.side[1] == d2.side[1])
	break;
      d2 = rotateR(d2);
    }

    // compare dice1 with dice2
    for (i = 0; i < DICE; i++) {
      if (d1.side[i] != d2.side[i]) {
	isEqual = 0;
	break;
      }
    }
    if (isEqual)
      break;
  }

  if (isEqual)
    printf("Yes\n");
  else
    printf("No\n");
  return 0;
}

dice_t rotateN(dice_t d){
  int tmp;
  tmp = d.side[0];
  d.side[0] = d.side[1];
  d.side[1] = d.side[5];
  d.side[5] = d.side[4];
  d.side[4] = tmp;
  return d;
}

dice_t rotateS(dice_t d){
  int tmp;
  tmp = d.side[0];
  d.side[0] = d.side[4];
  d.side[4] = d.side[5];
  d.side[5] = d.side[1];
  d.side[1] = tmp;
  return d;
}

dice_t rotateW(dice_t d){
  int tmp;
  tmp = d.side[0];
  d.side[0] = d.side[2];
  d.side[2] = d.side[5];
  d.side[5] = d.side[3];
  d.side[3] = tmp;
  return d;
}

dice_t rotateE(dice_t d){
  int tmp;
  tmp = d.side[0];
  d.side[0] = d.side[3];
  d.side[3] = d.side[5];
  d.side[5] = d.side[2];
  d.side[2] = tmp;
  return d;
}

dice_t rotateR(dice_t d){
  int tmp;
  tmp = d.side[1];
  d.side[1] = d.side[2];
  d.side[2] = d.side[4];
  d.side[4] = d.side[3];
  d.side[3] = tmp;
  return d;
}

dice_t rotateL(dice_t d){
  int tmp;
  tmp = d.side[1];
  d.side[1] = d.side[3];
  d.side[3] = d.side[4];
  d.side[4] = d.side[2];
  d.side[2] = tmp;
  return d;
}

Measured memory_bytes: 580
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;

namespace Program
{
    public class AGC019B
    {
        static public void Main(string[] args)
        {
            var A = NextString;
            var N = A.Length;

            var ans = 1L;
            var addAry = new long[26];
            for (int i = 0; i < N; ++i)
            {
                for (int j = 0; j < 26; ++j)
                {
                    if ((j + 'a') != A[i]) ans += addAry[j];
                }
                ++addAry[A[i] - 'a'];
            }

            Console.WriteLine(ans);
        }

        static class Console_
        {
            private static Queue<string> param = new Queue<string>();
            public static string NextString()
            {
                if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item);
                return param.Dequeue();
            }
        }
        static int NextInt => int.Parse(Console_.NextString());
        static long NextLong => long.Parse(Console_.NextString());
        static string NextString => Console_.NextString();

        static IEnumerable<long> Prime(long x)
        {
            if (x < 2) yield break;
            yield return 2;
            var halfx = x / 2;
            var table = new bool[halfx + 1];
            var max = (long)(Math.Sqrt(x) / 2);
            for (long i = 1; i <= max; ++i)
            {
                if (table[i]) continue;
                var add = 2 * i + 1;
                yield return add;
                for (long j = 2 * i * (i + 1); j <= halfx; j += add) table[j] = true;
            }
            for (long i = max + 1; i <= halfx; ++i) if (!table[i]) yield return 2 * i + 1;
        }
        static IEnumerable<long> Divisor(long x)
        {
            if (x < 1) yield break;
            var max = (long)Math.Sqrt(x);
            for (long i = 1; i < max; ++i)
            {
                if (x % i != 0) continue;
                yield return i;
                if (i != x / i) yield return x / i;
            }
        }
        static long GCD(long a, long b)
        {
            long tmpa = a, tmpb = b;
            while (tmpb > 0) { var tmp = tmpb; tmpb = tmpa % tmpb; tmpa = tmp; }
            return tmpa;
        }
    }
}


Measured memory_bytes: 12640
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
using namespace std;

typedef long long ll;
typedef double db;
typedef long double ldb;

template<class T> inline void checkmin(T &a,const T &b){if(b<a) a=b;}
template<class T> inline void checkmax(T &a,const T &b){if(b>a) a=b;}

const int inf=1e9+10;

int n,k,ans=0;
vector <int> v; 

int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++){
		int x;
		cin>>x;
		v.pb(x);
	}
	sort(v.begin(),v.end());
	for(int i=0;i<k;i++){
		ans+=v[i];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#define ll long long
using namespace std;
int main() {
	int n,k;
	cin >> n>>k;
	vector<int>h(n);
	vector<int>dp(n, 1000000000);
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	dp[0] = 0;
	//dp[1] = abs(h[0]-h[1]);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= k; j++) {
			if (i + j <n) {
				dp[i + j] = min(dp[i] + abs(h[i] - h[i + j]), dp[i + j]);

			}
		}
	}

	cout << dp[n - 1] << endl;
}

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

#define sz(x) (int)x.size() 
#define pb push_back 
#define mp make_pair 
#define fi(a, b) for(int i=a; i<=b; i++) 
#define fj(a, b) for(int j=a; j<=b; j++) 
#define fo(a, b) for(int o=a; o<=b; o++) 
#define fdi(a, b) for(int i=a; i>=b; i--) 
#define fdj(a, b) for(int j=a; j>=b; j--) 
#define fdo(a, b) for(int o=a; o>=b; o--) 

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while(false) {}
#endif

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<int> vi; 
typedef vector<ll> vll;
typedef vector<pii> vpii; 
typedef vector<pll> vpll; 
typedef long double ld;
typedef unsigned long long ull;

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

int const MAX = 2e5 + 41;

int n;
int a[MAX];
ll ans;
int nxt[MAX];

void solve() {
	a[n + 1] = (1 << 29) - 1;
	nxt[n + 1] = n + 1;
	fdi(n, 1) {
		nxt[i] = nxt[i + 1];
		if (a[i + 1] > 0) {
			nxt[i] = i + 1;
		}
	}
	fi(1, n) {
		int r = i;
		int x = 0;
		while (r <= n) {
			if (x & a[r]) {
				break;
			}			
			x ^= a[r];
			r = nxt[r];
		}
		ans += (r - i);
	}
	printf("%lld\n", ans);
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%d", &n);
	fi(1, n) {
		scanf("%d", &a[i]);
	}  
	solve();		

	
#ifdef LOCAL
	err("ELAPSED TIME: %.3Lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
string s,t;
  cin>>s>>t;
  ll S=s.size();
  ll T=t.size();
vector<vector<ll>> dp(S+1,vector<ll>(T+1));
  
  for(ll i=1;i<=S;i++) {
for(ll j=1;j<=T;j++) {
if(s[i-1]==t[j-1]) {
dp[i][j]=dp[i-1][j-1]+1;
}
  else {
dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
  }
}
  }
  
 string W;
  
 
  ll i=S;
  ll j=T;
  while(dp[i][j]!=0) {
if(s[i-1]==t[j-1]) {
W+=s[i-1];
  i--;
  j--;
}
    else if(dp[i][j-1]==dp[i][j]) {
j--;
    }
    else {
i--;
    }
  }
      

  
  reverse(all(W));
  cout<<W<<endl;
}
 
    
    
 

Measured memory_bytes: 73668
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                  as A
import qualified Data.Array.Unboxed          as AU
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import           Data.Ord
import           Data.Time
import qualified Data.Vector                 as V
import qualified Data.Vector.Mutable         as VM
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readIntegers :: IO [Integer]
readIntegers = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegerLists :: Int -> IO [[Integer]]
readIntegerLists n =
  replicateM n (map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine)

readInts :: IO [Int]
readInts = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readIntLists :: Int -> IO [[Int]]
readIntLists n =
  replicateM n (map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine)

readStrings :: IO [String]
readStrings = map BS.unpack . BS.words <$> BS.getLine

readStringLists :: Int -> IO [[String]]
readStringLists n = replicateM n (map BS.unpack . BS.words <$> BS.getLine)

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

main :: IO ()
main = do
  [h, w] <- readInts
  [h', w'] <- readInts
  print $ (h - h') * (w - w')


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

using namespace std;

//#define int long long
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF (1 << 30)
#define fi first
#define se second

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int dist[10][10];

void Warshall_Floyd() {
	for(int k = 0; k < 10; ++k) for(int i = 0; i < 10; ++i) for(int j = 0; j < 10; ++j) {
		dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
	}
}

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

    int h, w;
    cin >> h >> w;
    int c[10][10], a[h][w];
    rep(i, 10) rep(j, 10) cin >> dist[i][j];
    Warshall_Floyd();
    int res = 0;
    rep(i, h) rep(j, w) {
        cin >> a[i][j];
        if(a[i][j] != -1) res += dist[a[i][j]][1];
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void){
	long n,a[10000],i,Max=-1000000,Min=1000000,Sum=0;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%ld",&a[i]);
		if(a[i]>Max){
			Max=a[i];
		}
		if(a[i]<Min){
			Min=a[i];
		}
		Sum+=a[i];
	}
	printf("%ld %ld %ld\n",Min,Max,Sum);
	return 0;
}

Measured memory_bytes: 676
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int i=1;
        do{
        int x=i;
        if(x%3==0){
        	System.out.printf(" %d",i);
        }else{
       	while(true){
       	if(x%10==3){
        	System.out.printf(" %d",i);
        	break;
        }
       	x/=10;
       	if(x!=0) continue;
       	else break;
       	}
        }
        }while(++i<=n);
        System.out.println();
}
}

Measured memory_bytes: 39596
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define nibu(K,x) binary_search(K.begin(),K.end(),x)
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define out(x) cout<<x<<endl
#define put(x) out(x)
#define in(x) cin>>x
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
using ll = unsigned long long;
using vl = vector<ll>;
using vs = vector<string>;
const double pi = 3.14159265358979;
const ll mod = 1000000007;


int main() {
int N; 
  in(N);
  int K ;
  in(K);
  vector<bool> B(N,false);
  rep(i,K){
   int d ;
    in(d);
    rep(j,d){
      int a;
      in(a);
      if(B[a-1]==false) B[a-1]=true;
    }
  }
  int ans = 0;
 // rep(i,N) out(B[i]);
  rep(i,N){
   if(B[i]==false) ans++; 
  }
  out(ans);
}


Measured memory_bytes: 3632
import sys
input = sys.stdin.readline

import fractions
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0
def mult_crt(b1,m1,b2,m2):
    gcd = xgcd(m1,m2)
    if b1 % gcd[0] != b2 % gcd[0]:
        return False
    else:
        x = b1 + m1*(b2-b1)//gcd[0]*gcd[1]
        m3 = (m1*m2) // fractions.gcd(m1,m2)
        b3 = x % m3
        return b3,m3

N,M = (int(x) for x in input().split())
a = list(map(int, input().split()))
temp = [a[0],a[0]//2]
broke = False
for i in range(1,N):
    bm = mult_crt(temp[1],temp[0],a[i]//2,a[i])
    if bm == False:
        broke = True
        break
    else:
        temp[0] = bm[1]
        temp[1] = bm[0]
if broke:
    print('0')
else:
    dm = divmod(M,temp[0])
    if dm[1] >= temp[1]:
        print(dm[0]+1)
    else:
        print(dm[0])

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

int main(){
  int N;
  cin >>N;
  
  vector<int> H(N);
  rep(i,0,N) cin >>H[i];
  
  int ans = 0; 
  int a = 0;
  rep(i,0,N-1){
    if(H[i]<H[i+1]){
      ans = max(a,ans);
      a = 0;
    }else if(H[i]>=H[i+1]) a++;
    if(i==N-2) ans = max(a,ans);
  }
  
  cout <<ans<< endl;
}

Measured memory_bytes: 640
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

// Matsuzaki Number
// 2013/05/12
public class Main{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;

	int n, p;

	void run(){
		for(;;){
			n=sc.nextInt();
			p=sc.nextInt();
			if(n==-1){
				break;
			}
			solve();
		}
	}

	int max=200000;
	int[] prime, is;

	void solve(){
		if(prime==null){
			prime=new int[max];
			fill(prime, INF);
			boolean[] isPrime=new boolean[max];
			fill(isPrime, true);
			isPrime[0]=isPrime[1]=false;
			int at=0;
			for(int j=0; j<max; j++){
				if(!isPrime[j]){
					continue;
				}
				prime[at++]=j;
				for(int i=j*2; i<max; i+=j){
					isPrime[i]=false;
				}
			}
			is=new int[40000];
		}
		int k=binarySearch(prime, n);
		if(k<0){
			k=-k-1;
		}
		if(prime[k]<=n){
			k++;
		}
		fill(is, INF);
		for(int i=0; i<200; i++){
			for(int j=i; j<200; j++){
				is[i+j*200]=prime[k+i]+prime[k+j];
			}
		}
		sort(is);
		println(is[p-1]+"");
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 27724