akhauriyash/Code-Regression huggingface dataset:
s = input()
t = input()

s_len = len(s)
t_len = len(t)

dp = [[0]*(t_len+1) for t_item in range(0, s_len+1)]


for i in range(1, s_len+1):
    for j in range(1, t_len+1):
        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])

N=dp[s_len][t_len]
y=s_len
x=t_len
H=[]
while N>0:
    if dp[y][x-1]-dp[y][x]==0:
        x-=1
        continue
    if dp[y-1][x]-dp[y][x]==0:
        y-=1
        continue
    H.append(t[x-1])
    N-=1
    y-=1
    x-=1
print(''.join(H[::-1]))

Measured memory_bytes: 112220
from collections import deque

def main():
    s = list(input())
    Q = int(input())
    Qry = []
    for i in range(Q):
        q = list(input().split())
        Qry.append(q)
    d = deque(s)

    flg = 0
    l = 0
    r = len(s) -1
    for i, q in enumerate(Qry):
        if int(q[0]) == 1:
            tmp = l
            l = r
            r = tmp
            if flg == 0:
                flg =1
            else:
                flg = 0
        if int(q[0]) == 2:
            if int(q[1]) == 1:
                if flg == 0:
                    d.appendleft(q[2])
                else:
                    d.append(q[2])
            if int(q[1]) == 2:
                if flg ==1:
                    d.appendleft(q[2])
                else:
                    d.append(q[2])
    ans = []
    if flg == 0:
        for _ in range(len(d)):
            ans.append(d.popleft())
    if flg == 1:
        for _ in range(len(d)):
            ans.append(d.pop())
    print(''.join(ans))

if __name__=='__main__':
    main()


Measured memory_bytes: 121584
// 2014/12/10 Tazoe

#include <iostream>
using namespace std;

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

	int P[100] = {0};

	for(int i=0; i<N*(N-1)/2; i++){
		int A, B, C, D;
		cin >> A >> B >> C >> D;

		if(C>D){
			P[A-1] += 3;
		}
		else if(C<D){
			P[B-1] += 3;
		}
		else{
			P[A-1] += 1;
			P[B-1] += 1;
		}
	}

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

		for(int j=0; j<N; j++){
			if(P[i]<P[j]){
				cnt++;
			}
		}

		cout << cnt+1 << endl;
	}

	return 0;
}

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

#ifdef _PRINTDEBUG
  #include "lib/printdebug.hpp"
#else
  #define printdebug(...) 1
#endif
#define MOD_1_000_000_007 (1000000007LL)
#define LINF (1LL<<60)
#define rep(i, n)   for (long long i = 0; i <  (long long)(n); i++)
#define rep1(i, n)  for (long long i = 1; i <  (long long)(n); i++)
#define rep2(i, n)  for (long long i = 2; i <  (long long)(n); i++)
#define rep0c(i, n) for (long long i = 0; i <= (long long)(n); i++)
#define rep1c(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define rep2c(i, n) for (long long i = 2; i <= (long long)(n); i++)
#define repc0(n, i) for (long long i = (long long)(n); i >= 0; i--)
#define repc1(n, i) for (long long i = (long long)(n); i >= 1; i--)
#define repc2(n, i) for (long long i = (long long)(n); i >= 2; i--)
#define REP(i, n, m) for (long long i = (long long)(n); i < (long long)(m); i++)

namespace solver {
  using namespace std;
  typedef long long ll;

  string S, S1 = "", S2 = "";
  ll Q, T[200020], F[200020];
  char C[200020];
  bool flip = false;

  void init() {
    cin >> S;
    scanf("%lld", &Q);
    ll t, f;
    char c;
    rep(i, Q) {
      scanf("%lld", &t);
      if(t == 1) flip = !flip;
      else if(t == 2) {
        scanf("%lld %c", &f, &c);
        if(flip) f = 3-f;
        if(f==1) S1.append(1, c);
        else if(f==2) S2.append(1, c);
      }
    }
  }

  void solve() {
    reverse(S1.begin(), S1.end());
    S1.append(S);
    S1.append(S2);
    if(flip) reverse(S1.begin(), S1.end());
    cout << S1 << endl;
  }
}

int main() {
  solver::init();
  solver::solve();
  return 0;
}

Measured memory_bytes: 1348
s=input()
n=len(s)
if n % 2 == 1:
    hn = n//2
    if s[hn] =="1":
        s=s.replace("1","p").replace("0","1").replace("p","0")
    res = 0
    while res <= hn and s[hn+res] == "0" and s[hn-res] == "0":
        res += 1
    print(res+hn if res != 0 else hn+1)
else:
    hn = n//2
    res = 0
    if s[hn] =="1" and s[hn-1]=="1":
        s=s.replace("1","p").replace("0","1").replace("p","0")
    while res < hn and s[hn+res] == "0" and s[hn-res-1] == "0":
        res += 1
    print(res+hn)

Measured memory_bytes: 42096
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

ll a[111][111];
ll ans;
int n;

void dfs(vector<int>& v){
    int m=v.size();
    ll ret=0;
    rep(i,m){
        ll res=inf;
        rep(j,m){
            if(i==j)continue;
            res=min(res,a[v[i]][v[j]]);
        }
        ret+=res;
    }
    if(m==1)ret=0;
    ans=max(ans,ret);
    REP(i,v[m-1]+1,n){
        bool ok=true;
        rep(j,m)if(a[v[j]][i]==0)ok=false;
        if(!ok)continue;
        v.push_back(i);
        dfs(v);
        v.pop_back();
    }
}
int main(){
    cin>>n;
    int m;
    cin>>m;
    rep(i,m){
        int x,y,z;
        cin>>x>>y>>z;
        --x;--y;
        a[x][y]=a[y][x]=z;
    }
    rep(i,n){
        vector<int> v(1,i);
        dfs(v);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3252
#include<stdio.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
 
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


void solve(long long N, std::vector<long long> A, std::vector<long long> K){

}

int main(){
    int N, M;

    map<int, int> a;
    map<int, int> b;
    cin>>N;
    REP(i, N){
        int val; cin>>val; a[val]++;
    }

    cin>>M;
    VI T(M);
    REP(i, M){
        int val; cin>>val; b[val]++;
        T[i] = val;
    }
    REP(i, M){
        if(a[T[i]]>=1){
            a[T[i]]--;
        }
        else{
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;

}


Measured memory_bytes: 19712
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define sll            set<ll int>
#define msll        multiset<ll int>
#define io    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

ll n;
double p[3003];
double ans=0;
double dp[3002][3003];

double go(ll i, ll heads){
    // i-th par hoon heads k sath
    if(i==1){
        if(heads==1) return p[i];
        if(heads>1 || heads<0) return 0;
        if(heads==0) return (1-p[i]);
    }
    if(dp[i][heads]!=-1) return dp[i][heads];

    return dp[i][heads]=(p[i]*go(i-1,heads-1))+((1-p[i])*go(i-1,heads));

}

int main()
{
    io
    ll i,j;
    for(i=0;i<=3000;i++) for(j=0;j<=3000;j++) dp[i][j]=-1;
    cin>>n;
    for(i=1;i<=n;i++) cin>>p[i];
    for(ll h=n;h>n-h;h--) ans+=go(n,h);
    cout<<setprecision(12)<<ans;

    return 0;
}

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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(6);
    /*start*/
    ll x;
    cin >> x;
    ll p = 100;
    int res = 0;
    while(p<x){
        p += p / 100;
        res++;
    }
    c(res);
}


Measured memory_bytes: 3652
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	n, m := nextInt(), nextInt()

	ans := (1900*m + 100*(n-m)) * (1 << uint(m))
	fmt.Println(ans)

}


Measured memory_bytes: 640
package main

import "fmt"

func main(){
	var A, B int
	fmt.Scan(&A, &B)

	if A == 1{
		A = 14
	}
	if B == 1{
		B = 14
	}


	if A == B{
		fmt.Println("Draw")
	}else if A > B {
		fmt.Println("Alice")
	}else {
		fmt.Println("Bob")
	}

}

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

#define rep_(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) rep_(v, 0, n)
#define lep(v, n) rep_(v, 1, n + 1)
#define rrep_(v, f, l) for (int v = (l), v##_ = (f); v >= v##_; --v)
#define rrep(v, n) rrep_(v, 0, n - 1)
#define rlep(v, n) rrep_(v, 1, n)
#define show_a(a, size) rep(a##_it, size) std::cout << a[a##_it] << " \n"[a##_it == a##_it_ - 1];
#define show_v(v) show_a(v, v.size())
#define eachv(v, i) rep(i, v.size())
#define reachv(v, i) rrep(i, v.size())
#define debug(x) std::cerr << #x << " = " << x << "\n";

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }

int main()
{
    int n, m;
    while (n = in(), m = in(), n){
        int bucket[128] = {};
        rep(i, n){
            rep(j, m){
                bucket[j] += in();
            }
        }
        vector<pair<int, int> > v;
        rep(i, m) v.push_back(make_pair(-bucket[i], i));
        sort(v.begin(), v.end());
        eachv(v, i){
            printf("%d%c", v[i].second + 1, " \n"[i == i_ - 1]);
        }
    }
    return (0);
}

Measured memory_bytes: 1192
#include <iostream>
#include <cstdint>

int main() {
  std::int_fast64_t n, m;
  std::cin >> n >> m;
  std::cout << (m <= 2 * n ? m / 2 : n + (m - 2 * n) / 4) << std::endl;
  return 0;
}

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

int Simple( long long int m, long long int n )
{
    long long int x = 1;
    for( int i = 0; i < n; i++ )
    {
        x *= m;
        x %= 1000000007;
    }
    return x;
}

int Power( long long int m, long long int n )
{
    long long int x = 1;
    long long int c = 1;

    //指数部がnになるまで繰り返す
    while( n != 1 )
    {
        //指数mod2が1なら (m*m)^(n/2) * mの形に直す。cが最後のmを表す。
        if( n % 2 == 1 )
            c *= m;
        m *= m;
        n /= 2;

        //mが1000000007を超えたら、1...7で割った余りをmに入れる。cも同様。
        if( m > 1000000007 )
            m %= 1000000007;
        if( c > 1000000007 )
            c %= 1000000007;
    }

    //xにcを入れてから、最終的な計算を行う。
    x *= c;

    for( int i = 0; i < n; i++ )
    {
        x *= m;
        x %= 1000000007;
    }
    return x;
}

int main()
{
    long long int m, n;

    cin >> m >> n;

    //cout << Simple( m, n ) << endl;
    cout << Power( m, n ) << endl;

    return 0;
}


Measured memory_bytes: 3080
str_dict = [0, 0, 0] 
val1 = 0
for i in range(int(input())):
  line = input()
  val1 += line.count('AB')
  if line[0] == 'B' and line[-1] == 'A':
    str_dict[2] += 1
  elif line[0] == 'B':
    str_dict[0] += 1
  elif line[-1] == 'A':
    str_dict[1] += 1
if str_dict[2] == 0:
  print(val1+min(str_dict[0], str_dict[1]))
else:
  if str_dict[0]+str_dict[1] > 0:
    print(val1+str_dict[2]+min(str_dict[0], str_dict[1]))
  else:
    print(val1+str_dict[2]-1)


Measured memory_bytes: 3064
N = int(input())
ta = 0
xa = 0
ya = 0
for i in range(N):
  t,x,y = [int(x) for x in input().split()]
  tb = t-ta
  xb = abs(x-xa)
  yb = abs(y-ya)
  if tb-xb-yb<0 or (tb-xb-yb)%2!=0:
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
const int maxx = 1e5 + 7;
int n;
int a[maxx];

int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	bool chk = 1;
	for(int i = n; i > 1; i--) {
		if(a[i] >= a[i - 1]) continue;
		else {
			a[i - 1]--;
			if(a[i] < a[i - 1]) {
				chk = 0;
				break;
			}
		}
	}
	if(chk) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
int main(){
    int o,n,s,d;
    scanf("%d", &o);
    n=o;
    s=0;
    while (n!=0) {
        d = n % 10;
        n = n / 10;
        s = s + d;
    }
    if(o%s==0){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }

    return 0;
}


Measured memory_bytes: 128
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        TreeMap<String, Integer> map = new TreeMap<>();
        int max = 0;
        for(int i = 0; i < N; i++) {
            String key = sc.next();
            if(map.containsKey(key)) {
                int val = map.get(key);
                map.put(key, ++val);
            } else {
                map.put(key, 1);
            }
            int val = map.get(key);
            max = Math.max(val, max);
        }
        for(Map.Entry<String, Integer> entry : map.entrySet()) {
            int val = entry.getValue();
            String key = entry.getKey();
            if(val == max) System.out.println(key);
        }
    }
}


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

#define REP(i, start, count) for(int i=(start); i<(int)(count); ++i)
#define rep(i, count) REP(i, 0, count)
#define ALLOF(c) (c).begin(), (c).end()

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> veci;
typedef vector<long long> vecll;
typedef vector<unsigned long long> vecull;

vector<veci> c;

bool check(int a0) {
    bool flag = true;

    veci a(3);
    veci b(3);

    a[0] = a0;
    rep(i, 3) {
        b[i] = c[0][i] - a[0];
        if (b[i] < 0) {
            flag = false;
            break;
        }
    }

    REP(i, 1, 3) {
        a[i] = c[i][0] - b[0];
        if (a[i] < 0) {
            flag = false;
            break;
        }
    }

    if (!flag) return false;

    rep(i, 3) {
        rep(k, 3) {
            if (c[i][k] != a[i] + b[k]) {
                flag = false;
                break;
            }
        }
    }

    return flag;
}

int main(void) {
    c.assign(3, veci(3, 0));

    rep(i, 3) {
        rep(k, 3) {
            cin >> c[i][k];
        }
    }

    bool flag = false;
    for (int a = 0; a <= 100; ++a) {

        if (check(a)) {
            flag = true;
            break;
        }
    }

    if (flag) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import Foundation
 
let N = Int(readLine()!)!
let array = readLine()!.componentsSeparatedByString(" ").map { Int($0)! }
var answer = "APPROVED"
for i in 0..<N {
  if array[i] % 2 == 0 {
    if array[i] % 3 != 0 && array[i] % 5 != 0 {
      answer = "DENIED"
      break
    }
  }
}
print(answer)

Measured memory_bytes: 7528
def count(x,y):
	c = 0
	for i in range(len(x)):
		c += (x[i]!=y[i])
	return c
s = input()
t = input()
mx = len(s)
for i in range(0, len(s) - len(t) + 1):
	c = count(s[i:i+len(t)], t)
	mx = min(mx,c)
print(mx)

Measured memory_bytes: 9128
#include<iostream>
using namespace std;
int main(){
    int H,W,i,j;
    while(1){
        cin >> H >> W;
        if(H == 0 && W == 0){
            break;
        }
        
        for(i=0;i<H;i++){
            for(j=0;j<W;j++){
                    cout << "#";
            }
            cout << endl;
        }
        cout << endl;
        
    }
    
    return 0;
}


Measured memory_bytes: 3068
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt();

        PriorityQueue<Long> q = new PriorityQueue<>();

        for (int i = 0; i < n; i++) {
            q.add(-sc.nextLong());
        }

        for (int i = 0; i < m; i++) {
            long x = q.remove();
            q.add(x / 2);
        }

        long sum = 0;
        while (!q.isEmpty()) sum += q.remove();

        System.out.println(-sum);
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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

}


Measured memory_bytes: 60180
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
      
		String s=sc.next();
		
		 int m = Integer.parseInt(s.substring(5,7));
	        if(m<=4){
	            System.out.println("Heisei");
	        }else{
	            System.out.println("TBD");
	        }
	}
}

Measured memory_bytes: 23124
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n; readV(n);
  int[] a; readA(n, a);

  auto mi = a.reduce!min, ma = a.reduce!max;
  auto t = (n.to!long*(n+1)/2+1)/2;

  auto calc(int x)
  {
    auto b = a.map!(ai => ai >= x ? +1 : -1).array;
    auto s = new int[](n+1);
    foreach (i; 0..n) s[i+1] = s[i] + b[i];

    auto ft = new FenwickTree!int(n*2+1), ans = 0L;
    foreach (i; 0..n+1) {
      ans += ft[0..s[i]+n+1];
      ++ft[s[i]+n];
    }

    return ans < t;
  }

  auto bs = iota(mi, ma+1).map!(x => tuple(x, calc(x))).assumeSorted!"a[1]<b[1]";
  writeln(bs.lowerBound(tuple(0, true)).back[0]);
}

class FenwickTree(T)
{
  const size_t n;
  T[] buf;

  this(size_t n)
  {
    this.n = n;
    this.buf = new T[](n+1);
  }

  void opIndexOpAssign(string op)(T val, size_t i) if (op == "+" || op == "-")
  {
    ++i;
    for (; i <= n; i += i & -i) mixin("buf[i] " ~ op ~ "= val;");
  }

  void opIndexUnary(string op)(size_t i) if (op == "++" || op == "--")
  {
    ++i;
    for (; i <= n; i += i & -i) mixin("buf[i]" ~ op ~ ";");
  }

  pure T opSlice(size_t r, size_t l) { return get(l) - get(r); }
  pure T opIndex(size_t i) { return opSlice(i, i+1); }
  pure size_t opDollar() { return n; }

private:

  pure T get(size_t i)
  {
    auto s = T(0);
    for (; i > 0; i -= i & -i) s += buf[i];
    return s;
  }
}


Measured memory_bytes: 11588
#include<stdio.h>
int main(void)
{
	int si=0,a,b,i,c[1001],d[1001],ms=1,cant=0;
	scanf("%d %d",&a,&b);
	while(a!=0 && b!=0){
	si=0;
	ms=1;
	cant=0;
	for(i=0;i<1001;i++){
		c[i]=0;
		d[i]=0;
	}
	for(i=1;i<=a;i++){
		scanf("%d",&c[i]);
	}
	for(i=0;i<b;i++){
		scanf("%d",&d[i]);
	}
	while(ms<a){
		ms=ms+d[si];
		ms=ms+c[ms];
		cant++;
		si++;
	}
	printf("%d\n",cant);
		scanf("%d %d",&a,&b);
	}
	return 0;
}

Measured memory_bytes: 1036
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
count = 0
for i in range(n):
    if i == n-1:
        if x == a[i]:
            count += 1
    elif x >= a[i]:
        count += 1
        x -= a[i]
print(count)

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

char n;
int ans;

int main()
{
    for(int i = 0; i < 4; i++){
        cin >> n;
        if(n == '+')ans++;
        else ans--;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 768
#![allow(unused)]

//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
//入力マクロここまで

//input
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;
//use std::collections::VecDeque;
//use std::collections::BinaryHeap;

//use std::cmp::*;

fn main() {
    input! {
        k: u64,
        n: usize,
        a: [u64;n],
    }

    let mut a = a;
    a.sort();
    let mut kyori = vec![0; n];

    for i in 0..n - 1 {
        kyori[i] = a[i + 1] - a[i];
    }
    kyori[n - 1] = k + a[0] - a[n - 1];

    println!("{}", k - kyori.iter().max().unwrap());
}


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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    int N, X;
    cin >> N >> X;

    int ans = 1, D = 0;
    for (int i = 0, l; i < N; i++) {
        cin >> l;
        D += l;
        if (D <= X) ans++;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
import sys
sys.setrecursionlimit(500000) #これがないと再帰の回数オーバーでエラー出る。
N,M,P = map(int,input().split())
N-=1 #頂点番号を0スタートに。ただし頂点数はN+1となることに注意。
INF = float("inf")
edge = []
to = [[] for _ in range(N+1)] #普通に移動できる点
rto = [[] for _ in range(N+1)] #逆に戻れる点
reachablefrom = [False for _ in range(N+1)] #始点0から終点N-1へ行けるかチェック
reachableto = [False for _ in range(N+1)] #終点N-1から始点0へ戻れるかチェック
OK = [False for _ in range(N+1)] #どちらからもいける点を検出。ここ以外の点はどうでもよい。
for i in range(M):
  a,b,c = map(int,input().split())
  a-=1;b-=1 #頂点番号を0スタートに
  c-=P #ここで先に最後に払う分を引いておく。
  c = -c #最短経路にしたいのでコストを負にする。
  edge.append((a,b,c))
  to[a].append(b)
  rto[b].append(a)

def dfs(v):
  if reachablefrom[v]:
    return
  reachablefrom[v] = True
  for u in to[v]:
    dfs(u)

def rdfs(v):
  if reachableto[v]:
    return
  reachableto[v] = True
  for u in rto[v]:
    rdfs(u)
    
dfs(0)
rdfs(N)
for i in range(len(OK)): #len(OK)でもまあ良いか。
  OK[i] = reachablefrom[i]&reachableto[i]
#ここからベルマンフォード法
d = [INF for _ in range(N+1)]
d[0] = 0 #スタートのコストは0
upd = True #サイクルで更新の有無をチェック
step = 0
while upd:
  upd = False
  for i in range(M):
    a,b,c = edge[i]
    if not OK[a] or not OK[b]:
      continue
    new = d[a]+c
    if new < d[b]: #aから来たほうが最短
      upd = True
      d[b] = new
  step += 1
  if step > N+10: #最短経路が頂点の数よりも大きくなることない。
    print("-1")
    sys.exit()
ans = -d[N] #最後、コストをマイナスで戻す
ans = max(0,ans)
print(ans)

Measured memory_bytes: 64856
#include <bits/stdc++.h>
#define INF 114514810
#define FOR(i, r, n) for(int i=(r); i<(n); i++) 
#define REP(i, n) FOR(i, (0), n)

using namespace std;

long long int a, b;

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

int main(){
	cin >> a >> b;
	cout << gcd(a, b) << endl;
}

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

int main(){
  int n; cin >> n;
  bool flag = 0;
  ll ans = 0;
  vector<int> p(n + 1); for(int i = 1; i <= n; i++) cin >> p.at(i);
  
  for(int i = 1; i <= n; i++){
    if(p.at(i) == i){
      if(i == n){
        ans++;
      }
      else if(p.at(i+1) == i+1) {
        int count_tonari = 1;
        while(p.at(i + 1) == i + 1) {
          count_tonari++;
          i++;
          if(i == n) break;
        }
        if(count_tonari % 2 != 0){
          ans += count_tonari / 2 + 1;
        }
        else if(count_tonari % 2 == 0){
          ans += count_tonari / 2;
        }
      }
      else if(p.at(i+1) != i+1) {
        ans++;
      }
    }
  }

  cout << ans << endl;
  
  
}



Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<utility>
#include<queue>
#define INF 1111111
using namespace std;
typedef pair<int,int> P;

int main(){
   int n;
  cin >> n;
  int ans;
  int yaku;
   for(int i=1;i<=n;i+=2){
     yaku = 0;
     for(int j=1;j<=i;j+=2){

     if(i%j == 0)
       yaku++;
     }
     if(yaku == 8)
         ans++;
   }
 
  
  cout << ans << endl;
  
  
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


int n, d, a;
pair<int,int> xh[200000];
long long x[200000];

long long imos[200001];

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

	cin >> n >> d >> a;
	rep(i, n)cin >> xh[i].first >> xh[i].second;
	sort(xh, xh + n);

	rep(i, n)x[i] = xh[i].first;

	long long ans = 0;
	long long damage = 0;
	rep(i, n) {
		damage += imos[i];
		if (xh[i].second <= damage) continue;
		int e = lower_bound(x, x + n, x[i] + 2 * d + 1) - x;
		long long bomb = (xh[i].second - damage + a - 1) / a;
		damage += bomb * a;
		imos[e] -= bomb * a;
		ans += bomb;
	}

	cout << ans << endl;

	return 0;
} 

Measured memory_bytes: 4992
//Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
//#define file_input
//#define multitest
//#define measure_time
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define graph vector<v32>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
#define debug(x) cerr << (#x) << ": " << (x) << ln
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const double EPS = 1e-6;
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename... Args>
void print_container(const ContainerType<ValueType, Args...> &c)
{
	cout << "{ ";
	for (const auto &v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

void solve()
{
	int x, y, z;
	cin >> x >> y >> z;
	swap(x, y);
	swap(x, z);
	cout << x << " " << y << " " << z << ln;
	return;
}

int main()
{
	FASTIO;
#ifdef file_input
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	clock_t start, stop;
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
#ifdef measure_time
	start = clock();
#endif
	for (int tc = 1; tc < t + 1; tc++)
		solve();
#ifdef measure_time
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


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

int main()
{
	string s[500];
	int a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, h = 0;
	cin >> a;
	cin >> b;
	cin >> c;
	cin >> d;
	if (b>a)
	{
		e = b;
		b = a;
		a = e;
	}
	if (c>a)
	{
		e = c;
		c = a;
		a = e;
	}
	for ( e = 0; e < d; e++)
	{
		a *= 2;
	}


	cout << a+b+c << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=6005;
int n;
long long m,dp[N][N*2];
int main()
{
	cin>>n>>m;
	dp[0][3*n]=1;
	for(int i=0;i<3*n;i++)
	{
		for(int j=0;j<=6*n;j++)
		{
			if(dp[i][j]==0)
				continue;
			(dp[i+1][j-1]+=dp[i][j])%=m;
			(dp[i+2][j+1]+=dp[i][j]*(i+1))%=m;
			(dp[i+3][j]+=dp[i][j]*(i+1)%m*(i+2))%=m;
		}
	}
	long long ans=0;
	for(int j=0;j<=3*n;j++)
		ans+=dp[3*n][j];
	cout<<ans%m<<endl;
	return 0;
}

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

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

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

	int count = 0;
	for (int i = 0; i < N; i++) {
		if (i % 2 == 0 && a[i] % 2 == 1) {
			count++;
		}
	}

	cout << count << endl;

	return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>

int main( void ) {
	int i, ch, count[ 4 ] = {}, min;

	while ( ( ch = getchar() ) != EOF )
		switch ( ch ) {
			case 'K': count[ 0 ]++; break;
			case 'U': count[ 1 ]++; break;
			case 'P': count[ 2 ]++; break;
			case 'C': count[ 3 ]++; break;
		}

	min = count[ 0 ];
	for ( i = 4; i-- - 1; min = count[ i ] < min ? count[ i ] : min ) ;

	printf( "%d\n", min );

	return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdint>

int main() {
	int n;
	std::cin >> n;

	std::vector<int> vec(n);

	for (auto&& e : vec)
		std::cin >> e;

	auto solve = [&](bool positive) {
		int64_t ret = 0;

		int sum = 0;
		for (int i = 0; i < vec.size(); ++i) {
			sum += vec[i];

			if (sum == 0 || positive != sum > 0) {
				ret += std::abs(sum) + 1;
				sum = (positive ? 1 : -1);
			}
			
			positive = !positive;
		}

		return ret;
	};

	std::cout << std::min(solve(true), solve(false)) << std::endl;
}

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

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    COMinit();
    int h,w,a,b;
    cin>>h>>w>>a>>b;
    ll ans=0;
    int i=h-a,j=b+1;
    while(1<=i&&j<=w){
        ans=(ans+COM(i+j-2,i-1)*COM(h-i+w-j,h-i))%MOD;
        i--,j++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 12160
n = int(input())
s = str(input())

if len(s) % 2 != 0:
    ans = 'No'
else:
    h = len(s) // 2
    t1 = s[:h]
    t2 = s[h:]
    if t1 == t2:
        ans = 'Yes'
    else:
        ans = 'No'
print(ans)

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

int main() {
  string dir;
  cin >> dir;
  int east = 0, west = 0, north = 0, south = 0,size = dir.size();
  for (int i = 0; i < size; i++) {
    if (dir.at(i) == 'N') 
      north++;
    else if ('S' == dir.at(i))
      south++;
    else if ('E' == dir.at(i))
      east++;
    else if ('W' == dir.at(i))
      west++;
  }
  if ((north>0&&south==0)||(north==0&&south>0)||(east>0&&west==0)||(west>0&&east==0))
    cout << "No" << endl;
  else
    cout << "Yes" << endl;
  return 0;
}
  

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-4;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
bool used[51][51];
string ans[51][51];
bool great(string x, string y) {
	int l1 = x.length(); int l2 = y.length();
	if (l1 != l2)return l1 < l2;
	return x < y;
}
string maax(string x, string y) {
	if (x == "invalid")return y;
	else if (y == "invalid")return x;
	if (great(x, y))return y; return x;
}
string number(string x) {
	int len = x.length();
	if (!len)return "invalid";
	if (x[0] == '0'&&len>1)return "invalid";
	string res;
	rep(j, len) {
		if ('0' <= x[j] && x[j] <= '9') {
			res.push_back(x[j]);
		}
		else if (x[j] == '?') {
			res.push_back('9');
		}
		else {
			res = "invalid"; break;
		}
	}
	return res;
}
int n;
string s;
string dfs(int le, int ri) {
	if (used[le][ri])return ans[le][ri];
	used[le][ri] = true;
	if (le > ri)return ans[le][ri] = "invalid";
	string res = number(s.substr(le, ri - le + 1));
	if (res != "invalid")return ans[le][ri]=res;
	res = "invalid";
	if (s[ri] != '?'&&s[ri] != ')')return ans[le][ri] = "invalid";
	if (le + 1 >= n || (s[le + 1] != '?'&&s[le + 1] != '('))return ans[le][ri] = "invalid";
	for (int i = le + 2; i <= ri - 1; i++) {
		if (s[i] == '?' || s[i] == ',') {
			string l = dfs(le + 2, i - 1); string r = dfs(i + 1, ri - 1);
			if (l == "invalid" || r == "invalid")continue;
			if (s[le] == 'L' || s[le] == '?')res = maax(res, l);
			if (s[le] == 'R' || s[le] == '?')res = maax(res, r);
		}
	}
	return ans[le][ri]=res;
}
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> s; n = s.length();
	cout << dfs(0, n - 1) << endl;
	/*rep(i, n) {
		Rep(j, i, n) {
			cout << i << " " << j << endl;
			cout << ans[i][j] << endl;
		}
	}*/
	return 0;
}


Measured memory_bytes: 3304
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1e18+7;
const int inf=1e9+7;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    in x;
    cin>>x;
    in cnt=0ll;
    in yen=100ll;
    while(yen<x){
        cnt ++;
        yen *=1.01;
    }
    cout<<cnt<<endl;
}/*
./problem.exe
*/

Measured memory_bytes: 3652
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll x,y;
	cin>>x>>y;
	if(x%y==0) {
		cout<<-1<<endl;
	} else {
		cout<<x<<endl;
	}
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long N,X,T;
  	cin>>N;
  	cin>>X;
  	cin>>T;
  	long long ans;
  	if(N%X == 0)
  		ans= T * (N/X);
  	else 
      	ans= T * ((N/X)+1);
  	cout<<ans;
  	return 0;
}

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


int dp[1<<14][25];
int v[40];

int pt(int c){
	return c > 0 ? 50 + c * 10 : 0;
}
int toBit(int c[7],int add){
	int bit = 0;
	for(int i = 1 ; i < 7 ; i++){
		bit = (bit<<2) | c[i];
	}
	bit = (bit<<2) | (~v[add] ? v[add] : 0);
	return bit;
}

int f(int bit , int p){
	if(p == 25) return 0;
	if(~dp[bit][p]) return dp[bit][p];
	int c[7];
	rep(i,7) c[6-i] = bit >> (i*2) & 3;
	//if(p<=5){rep(i,7) cout << c[i];cout << "[" << bit << ":" << p << endl;}
	int ans = 0;
	if( p % 5 == 4 || p >= 20) return f(toBit(c,p+7),p+1)+pt(c[0]);

	rep(i,4){
		ans = max(ans,f(toBit(c,p+7),p+1)+pt(c[0]));
		if(~v[p]  )c[0] = (c[0]+1)%4;
		if(~v[p+1])c[1] = (c[1]+1)%4;
		if(~v[p+5])c[5] = (c[5]+1)%4;
		if(~v[p+6])c[6] = (c[6]+1)%4;
	}
	return dp[bit][p] = ans;
}
int main(){
	int T; cin >> T;
	while(T--){
		memset(v,-1,sizeof(v));
		rep(i,25) cin >> v[i] , v[i]--;
		memset(dp,-1,sizeof(dp));
		int bit = 0;
		rep(i,7) bit = (bit<<2) | (~v[i] ? v[i] : 0);
		//cout << ">"<< bit << endl;
		cout << f(bit,0) << endl;
	}
}

Measured memory_bytes: 2464
import math

n, d = map(int, input().split())
p = []
for i in range(n):
    p.append(list(map(int, input().split())))

cnt = 0
    
for i in range(n-1):
    for j in range(i+1, n):
        L=0
        for k in range(d):
            L += (p[i][k] - p[j][k])**2
        L = math.sqrt(L)
        if L.is_integer() == True:
            cnt+=1

print(cnt)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <cmath>
#include<bits/stdc++.h>
using namespace std;

int main(){
    int n, ma, mb;
    int ai, bi, ci;
    cin >> n >> ma >> mb;
    vector<vector<vector<int>>> dp(n+1,vector<vector<int>>(501,vector<int>(501,10000)));
    dp[0][0][0] = 0;
    int c;
    for(int i=0; i<n; i++){
        cin >> ai >> bi >> ci;
        for(int j=0; j<401; j++){
            for(int k=0; k<401; k++){
                dp[i+1][j][k] = min(dp[i+1][j][k],dp[i][j][k]);
                dp[i+1][j+ai][k+bi] = min(dp[i+1][j+ai][k+bi], dp[i][j][k] + ci);
            }
        }
    }
    int ans =5000;
    for(int i=1; i<n+1; i++){
        for(int j=1; j<401; j++){
            for(int k=1; k<401; k++){
                if(j*mb==k*ma){
                    ans = min(ans, dp[i][j][k]);
                }
            }
        }
    }
    if(ans ==5000){
        ans = -1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 44160
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(NULL);cin.tie(0);cout.tie(0);
using namespace std;
typedef long long ll;
const int maxn = 200005;
const int inf = 1e9;
int dp[maxn], h[maxn];
int main()
{
   int n, k;
   cin >> n >> k;
   for(int i=0;i<n;i++)cin >> h[i],dp[i]=inf;
   dp[0] = 0;
   for(int i=0;i<n;i++){
      for(int j=i+1;j<=i+k;j++){
         if(j<n)dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
      }
   }
   cout << dp[n-1] << endl;
   return 0;
}
/*
4
0 1 2 3
10 30 40 20

*/


Measured memory_bytes: 1024
a=int(input())
li = list(map(int,input().split()))	
count = 0
for i in range(1,a-1):
  if li[i-1]<li[i] and li[i]<li[i+1]:
    count += 1
  elif li[i-1]>li[i] and li[i]>li[i+1]:
    count += 1
  else:
    pass
print(count)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>

#define LEN 100005

typedef struct pp{
    char name[100];
    int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x){
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue(){
    P x = Q[head];
    head = (head+1)%LEN;
    return x;
}

int min(int a, int b){return a < b? a: b;}

int main(){
    int elaps = 0, c;
    int i, q;
    P u;
    scanf("%d %d", &n, &q);

    for(i = 1; i <=n; i++){
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    head = 1;
    tail = n+1;

    while (head != tail){
        u = dequeue();
        c = min(q, u.t);
        u.t -= c;
        elaps += c;
        if (u.t>0) enqueue(u);
        else {
            printf("%s %d\n", u.name, elaps);
        }
    }
    return 0;
}


Measured memory_bytes: 11952
#include<bits/stdc++.h>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
const int maxn = 3e5+10;
int main()
{
	int a,b;
	cin>>a>>b;
	int flag = 0;
	int ans = 0;
	for(int i=1;i<=1500;i++)
	{
		if(floor(i*0.08)==a&&floor(i*0.1)==b)
		{
			ans = i;
			flag = 1;
			break;
		}
		
	}
	if(flag==0) cout<<-1<<endl;
	else cout<<ans<<endl;
	return 0;
}


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

typedef long long ll;
const int maxn=3e5+10;
int n,ans,sum[maxn],summ[maxn];
char s[maxn];

int main(){
	cin>>n>>(s+1);
	for(int i=1;i<=n;++i)
		sum[i]=sum[i-1]+(s[i]=='W');
	for(int i=n;i;--i)
		summ[i]=summ[i+1]+(s[i]=='E');
	ans=n;
	for(int i=1;i<=n;++i)
		ans=min(ans,sum[i-1]+summ[i+1]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	ll N,A,B,C,D;
	cin>>N>>A>>B>>C>>D;
	A--;B--;C--;D--;
	string S;cin>>S;
	vector<int> a(N,0),b(N,0);
	a[A] = 1;
	b[B] = 1;
	rep(i,N){
		if(i+1<N)
		if(a[i]&&S[i+1] == '.'){
			a[i+1]++;
		}
		if(i+2<N)
		if(a[i]&&S[i+2] == '.'){
			a[i+2]++;
		}
		if(i+1<N)
		if(b[i]&&S[i+1] == '.'){
			b[i+1]++;
		}
		if(i+2<N)
		if(b[i]&&S[i+2] == '.'){
			b[i+2]++;
		}
	}
	bool can = false;
	for (int i = B-1; i+1 <= D; ++i){
		// if(S[i] == '.'&&a[i]&&b[i])b_w++;
		// else{
		// 	max_b_w = max(max_b_w, b_w);
		// 	b_w = 0;
		// }
		if(a[i]&&b[i+1]&&a[i+2]){
			can = true;
		}
	}
	string ans = "No";
	if(C<D){
		if(a[C]&&b[D])ans ="Yes";
	}
	else{
		if(a[C]&&b[D]&&can){
			ans = "Yes";
		}
	}
	print(a);
	print(b);
	cerr<<can<<endl;
	cout<<ans<<endl;
}

Measured memory_bytes: 2180
S = input()
A = "".join(list(reversed(S)))
i = 0

while i != len(S):
    if A[i:i+5] == "maerd":
        i += 5
    elif A[i:i+5] == "esare":
        i += 5
    elif A[i:i+7] == "remaerd":
        i += 7
    elif A[i:i+6] == "resare":
        i += 6
    else:
        print("NO")
        exit()
print("YES")

Measured memory_bytes: 9740
#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> B(N-1);
    rep(i,N-1) cin >> B[i];
    int ans = B[0] + B[N-2];
    for(int i=1;i<=N-2; ++i) {
        ans += min(B[i-1],B[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<map>
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
#define sort(s) sort(s.begin(),s.end())
#define r(s) reverse(s.begin(),s.end())
#define come return
constexpr auto AC = 0;
using namespace std;

int main() {
	int a, b;
	cin >> a >> b;
	if (a == b)cout << "Yes" << endl;
	else cout << "No" << endl;
	come AC;
}


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

int gyakuten(int x) {
  vector<int> gyaku;
  while (x > 0) {
    gyaku.push_back(x % 10);
    x /= 10;
  }
  
  reverse(gyaku.begin(), gyaku.end());
  int pro = 1;
  int s = 0;
  
  for (int i = 0; i < gyaku.size(); i++) {
    s += pro * gyaku.at(i);
    pro *= 10;
  }
  return s;
}

int main() {
  int a, b;
  cin >> a >> b;
  
  int ans = 0;
  for (int i = a; i <= b; i++) {
    if (gyakuten(i) == i) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n; cin >> n; n *= 2;
	vector<int> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end());
	int ans = 0;
	for(int i = 0; i < n; i += 2) ans += a[i];
	cout << ans << endl;
	return 0;
}


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

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	int N;
	cin >> N;
	string res = "AB";
	if (N <= 999) {
		res += 'C';
	}
	else {
		res += 'D';
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 892
#include <iostream>

int main()
{

    int x;
    int a, b, c;
    std::cin >> a >> b >> c;

    if (c < a){
        x = c;
        c = a;
        a = x;
    }

    if (c < b){
        x = c;
        c = b;
        b = x;
    }

    if (b < a){
        x = b;
        b = a;
        a = x;
    }

    std::cout << a << " " << b << " " << c << "\n";

    return 0;
}



Measured memory_bytes: 3096