akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>

int main() {
	std::string a, b, c;
	std::cin >> a >> b >> c;
	int A = 0, B = 0, C = 0, flag = 0;
	while (true) {
		if (flag==0) {
			if (a[A] == 'a') {
				flag = 0;
			}
			else if (a[A] == 'b') {
				flag = 1;
			}
			else {
				flag = 2;
			}
			A++;
			if (A == a.size()+1) {
				std::cout << 'A' << std::endl;
				break;
			}
		}
		else if (flag == 1) {
			if (b[B] == 'a') {
				flag = 0;
			}
			else if (b[B] == 'b') {
				flag = 1;
			}
			else {
				flag = 2;
			}
			B++;
			if (B == b.size()+1) {
				std::cout << 'B' << std::endl;
				break;
			}
		}
		else {
			if (c[C] == 'a') {
				flag = 0;
			}
			else if (c[C] == 'b') {
				flag = 1;
			}
			else {
				flag = 2;
			}
			C++;
			if (C == c.size()+1) {
				std::cout << 'C' << std::endl;
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
#define INFL 0x3f3f3f3f3f3f3f3fLL
const ll mod = 1e9 + 7;
const int M = 2e6 + 5;
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll expo(ll base,ll pow){ll ans = 1;
   if(pow < 0) return 0;
   while(pow!=0){if(pow&1==1){ans = ans*base;ans = ans%mod;}
   base *= base;base%=mod;pow/=2;}return ans;}
ll inv(ll x){return expo(x,mod-2);}
ll mult_mod(ll a , ll b){a = a%mod; b = b%mod;ll c = (a * b)%mod;return c;}
ll add_mod(ll a , ll b){a = (a + mod)%mod;b = (b + mod)%mod;ll c = (a + b)%mod;return c;}
ll fac[(int)(2e6 + 7)] , inv_fac[(int)(2e6 + 7)];
void precomp_factorial(){fac[0] = 1;for(ll i = 1 ; i <= M ; i++) fac[i] = mult_mod(i , fac[i - 1]);
    inv_fac[M] = inv(fac[M]);for(ll i = M - 1 ; i >= 0 ; i--) inv_fac[i] = mult_mod(i + 1 , inv_fac[i + 1]);}
ll nCk(ll n , ll k){ll ans = fac[n];ans = mult_mod(ans , inv_fac[n - k]);ans = mult_mod(ans , inv_fac[k]);return ans;}
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};    // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};


int main() {
    
   int n;
   cin >> n;
   int val1 = (n+1)/2;
   double ans = (1.0*val1)/(1.0*n);
   printf("%0.8f", ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> s(h+2, vector<char>(w+2, '.'));
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      cin >> s[i][j];
    }
  }
  
  string ans = "Yes";
  for (int i = 1; i <= h; i++) {
    for (int j = 1; j <= w; j++) {
      if (s[i][j]=='#' && s[i+1][j]!='#' && s[i-1][j]!='#' &&
          s[i][j+1]!='#' && s[i][j-1]!='#') {
        ans = "No";
        break;
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#define INF 1e8
using namespace std;
int main(void){
set<long long> s;
int n,k;
cin>>n>>k;
if(n==k)
cout<<"Yes";
else
cout<<"No";
}



Measured memory_bytes: 3096
#include <stdio.h>
#include<math.h>
int main(void){
    double x1,y1,x2,y2;
    scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);
    printf("%.8f\n",sqrt((double)(x2-x1)*(x2-x1)+(y2-y1)*(y2-y1)));
    return 0;
    }



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

int main()
{
    int sx, sy, tx, ty;

    cin >> sx >> sy >> tx >> ty;

    const int dx = tx - sx, dy = ty - sy;
    cout << string(dy, 'U') << string(dx, 'R');
    cout << string(dy, 'D') << string(dx, 'L');
    cout << 'L'<<  string(dy + 1, 'U') << string(dx + 1, 'R') << 'D';
    cout << 'R'<< string(dy + 1, 'D') << string(dx + 1, 'L') << 'U';

    cout << endl;
    return 0;
}


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

int main(){
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;++i)cin>>a[i];
    ll ans = 0; ll soul = 1;
    for(int j=1;j<=65;++j){
        ll count_e = 0,count_o = 0;
        for(int i=0;i<n;++i){
            if(a[i]&1)count_o++;
            else count_e++;
            a[i] = (a[i]>>1);
        }
        ll pettu = (count_o*count_e)%mod;
        ans = (ans + pettu*soul)%mod;
        soul = (soul*2LL)%mod;
    }
    cout<<ans;

}

Measured memory_bytes: 5920
#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<functional>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;


#define MOD (1000000000+7)


int main(void)
{
	int n;

	while(scanf("%d\n", &n)==1)
	{
		vector<char> s(n+2);
		vi c(26);

		scanf("%[a-z]", &s[0]);
		for(int i=0;i<n;i++)
		{
			c[s[i]-'a']++;
		}
		ll ans=1;
		for(int mc:c)
		{
			ans=(ans*(mc+1))%MOD;
		}
		printf("%lld\n", ans-1);
	}

	return 0;
}


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Node {
	int key;
	Node parent, left, right;

	public Node(int key) {
		super();
		this.key = key;
	}

}

class Tree {
	Node root;



	void insert(Node z) {
		Node y = null; // parent of x
		Node x = this.root; // the root of Tree

		while (x != null) {
			y = x;
			if (z.key < x.key) {
				x = x.left;
			} else {
				x = x.right;
			}
		}
		z.parent = y;

		if (y == null) {
			this.root = z;
		} else {
			if (z.key < y.key) {
				y.left = z;
			} else {
				y.right = z;
			}
		}
	}


}

public class Main {

	static StringBuilder sb;

	public static void printPreOrder(Node node) {
		if (node == null) {
			return;
		}

		sb.append(" " + node.key);
		printPreOrder(node.left);
		printPreOrder(node.right);
	}

	public static void printInOrder(Node node) {
		if (node == null) {
			return;
		}

		printInOrder(node.left);
		sb.append(" " + node.key);
		printInOrder(node.right);
	}

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

		int m = Integer.parseInt(br.readLine());
		String[] operation;
		int key;
		Tree tree = new Tree();
		sb = new StringBuilder();

		for (int i = 0; i < m; i++) {
			operation = br.readLine().split(" ");
			if (operation[0].equals("insert")) {
				key = Integer.parseInt(operation[1]);
				tree.insert(new Node(key));
			} else {
				printInOrder(tree.root);
				sb.append("\n");
				printPreOrder(tree.root);
				System.out.println(sb.toString());
				sb.setLength(0);
			}
		}
	}
}


Measured memory_bytes: 139900
A,B,K = map(int,input().split())
def calc_exchange(my_cookie,partner_cookie):
 if my_cookie%2 != 0:
  my_cookie = my_cookie -1
 my_cookie = my_cookie / 2
 partner_cookie = partner_cookie + my_cookie
 return my_cookie,partner_cookie
A_cookie = A
B_cookie = B
for i in range(K):
 if i%2 ==0:
  my_cookie = A_cookie
  partner_cookie = B_cookie
  A_cookie,B_cookie = calc_exchange(my_cookie,partner_cookie)
 else:
  my_cookie = B_cookie
  partner_cookie = A_cookie
  B_cookie,A_cookie = calc_exchange(my_cookie,partner_cookie)
print(int(A_cookie),int(B_cookie))

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stdio.h>
#include<deque>
#include<map>
#include<queue>
#include<cmath>

typedef long long ll;

#define debug(x) cout << #x << '=' << x << endl;
#define debug_arr(a, n) for(ll i = 0; i < n; i++)cout << a[i] << ' '
#define inf 100000000000
#define loop(i,n) for(ll i = 0; i < n; i++)
#define graph vector<vector<ll>>
#define P pair<ll,ll>

using namespace std;

ll c[2000][2000] = {0}, mod = 1000000007;


ll combination(int a, int b){
    if(c[a][b] != 0) return c[a][b];

    if(b == 0 || a == b){
        c[a][b] = 1;
        return 1;
    }
    if(b == 1){
        c[a][b] = a;
        return a;
    }
    ll tmp;
    tmp = combination(a-1,b) + combination(a-1,b-1);
    tmp %= mod;

    c[a][b] = tmp;
    return tmp;
}

int main(){
    int n,k,red,blue;
    cin >> n >> k;

    red = n - k;
    blue = k;

    ll result;

    for(int i = 1;i <= k; i++){
        if(red < i - 1){
            cout << "0" << endl;
            continue;
        }
        ll redGroup = combination(red+1, i);
        ll blueGroup = combination(blue-1, i-1);

        result = redGroup * blueGroup;
        result %= mod;

        cout << result << endl;
    }
}

Measured memory_bytes: 29696
def gcd(a,b):
    while b:
        a,b=b,a%b
    return a

def lcm(a,b):
    return (a*b)//gcd(a,b)

N=int(input())
T=[int(input()) for _ in range(N)]
a=T[0]
for i in range(1,N):
    a=lcm(a,T[i])
print(a)


Measured memory_bytes: 3060
// AOJ 1186
#include<cstdio>
#include<algorithm>
#define repi(i,a,b) for( int i = (a); i != (b); ++i )

int sqr( int x )
{
	return x*x;
}

int main()
{
	int h, w;
	while( scanf( "%d%d", &h, &w ), h|w )
	{
		int d = sqr(h)+sqr(w);
		int ansh = 151, answ = 0;

		repi( i, 1, 151 )
		{
			repi( j, i+1, 151 )
			{
				if( sqr(i)+sqr(j) > d || (sqr(i)+sqr(j) == d && i > h) )
				{
					int ansd = sqr(answ)+sqr(ansh), dij = sqr(i)+sqr(j);

					if( ansd > dij || (ansd==dij && ansh > i) )
						ansh = i, answ = j;
				}
			}
		}
						

		printf( "%d %d\n", ansh, answ );
	}

	return 0;
}

Measured memory_bytes: 1028
n = int(input())
ab = [[int(i) for i in input().split()] for j in range(n)]

if n % 2 == 1:
    ab.sort(reverse=True,key=lambda x: x[1])
    max_ab = ab[n//2][1]
    ab.sort(reverse=True,key=lambda x: x[0])
    print(max_ab-ab[n//2][0]+1)
else:
    ab.sort(reverse=True,key=lambda x: x[1])
    ab1 = ab[n//2][1]
    ab2 = ab[n//2-1][1]
    ab.sort(key=lambda x: x[0])
    ab3 = ab[n//2][0]
    ab4 = ab[n//2-1][0]
    
    print(ab1+ab2-(ab3+ab4)+1)


Measured memory_bytes: 120120
using System;

namespace aoj9c
{
    class Program
    {
        static void Main(string[] args)
        {
            int pt_taro = 0;
            int pt_hanako = 0;

            int n = int.Parse(Console.ReadLine());      //??????????????°

            for(int i = 0; i < n; i++)
            {
                string[] card = (Console.ReadLine()).Split(' ');
                /*card[0]????????????????????? card[1]?????±???????????????*/
                int j = String.Compare(card[0],card[1]);

                if (j < 0)
                {
                    pt_hanako += 3;
                }
                else if(j > 0)
                {
                    pt_taro += 3;
                }
                else
                {
                    pt_taro++;
                    pt_hanako++;
                }
            }
            Console.WriteLine(pt_taro + " " + pt_hanako);
        }
    }
}

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

#define REP(i, n) for(int i = 0; i != n; ++i)
#define REPR(i, n) for(int i = n - 1; i != -1; --i)
#define FOR(i, a, b) for(int i = a; i != b; ++i)
#define RBF(i, n) for(auto &i : n)
#define ABS(n) (n < 0 ? -n : n)
#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define IN(n) (cin >> n)
#define OUT(n) (cout << n << "\n")
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define V vector<int>

using namespace std;
using ll = long long;

int main() {
    int N;
    IN(N);
    int i = sqrt(N);
    OUT(i * i);
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define int long long
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N; cin >> N;
    if (N == 1) {
        cout << 1 << endl;
        return 0;
    }
    if (N == 2) {
        cout << 2 << endl;
        return 0;
    }
    int ans;
    rep(i, N) {
        if (N < i * (i + 1) / 2) {
            ans = i;
            break;
        }
        else if (N == i * (i + 1) / 2) {
            REP(j,i+1)cout << j << endl;
            return 0;
        }
    }
    int M = ans * (ans + 1) / 2 - N;
    REP(i, ans+1) {
        if (i == M)continue;
        cout << i << endl;
    }
}

Measured memory_bytes: 3632
n,m=map(int,input().split())
p=[[] for i in range(m)]
s=[[] for i in range(m)]
k=[True for i in range(n)]
ac=0
wa=[0 for i in range(n)]

for i in range(m):
    p[i],s[i]=input().split()

p=list(map(int,p))

for i in range(m):
    if k[p[i]-1]:
        if s[i]=="AC":
            k[p[i]-1]=False
            ac+=1
        else:
            wa[p[i]-1]+=1

for i in range(n):
    if k[i]:
        wa[i]=0

print(ac,sum(wa))

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

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);

template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl
#else
#define dbg(x) true
#endif

void solve(long long N, std::vector<long long> A) {
  ll ans = 0;
  ll pre = 0;
  REP(i, N) {
    if (pre > A[i]) {
      ans += pre - A[i];
    } else {
      pre = A[i];
    }
  }
  cout << ans << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  std::vector<long long> A(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &A[i]);
  }
  solve(N, std::move(A));
  return 0;
}


Measured memory_bytes: 4772
//IOI 2021

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

#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 2 * 1000 + 17;

int h, w, x = 1, y = 1;
char a[MAXN][MAXN];

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cin >> h >> w;
	memset(a, '.', sizeof(a));
	for (int i = 1; i <= h; i++)
		for (int j = 1; j <= w; j++)
			cin >> a[i][j];
	a[x][y] = '.';
	while (x != h || y != w) {
		if (a[x][y + 1] == '#') {
			a[x][y + 1] = '.';
			y++;
			continue;
		}
		if (a[x + 1][y] == '#') {
			a[x + 1][y] = '.';
			x++;
			continue;
		}
		cout << "Impossible";
		return 0;
	}
	for (int i = 1; i <= h; i++)
		for (int j = 1; j <= w; j++)
			if (a[i][j] == '#') {
				cout << "Impossible";
				return 0;
			}
	cout << "Possible";
	return 0;
}


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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

bool isfav(int N, int m) {
    if(m == 0) return false;
    return N/m == N%m;
}

int32_t main() {

    int N; cin >> N;

    int ans = 0;
    
    for(int x = 1; x*x < N; ++x) {
        if(N%x == 0) {
            if(isfav(N, N/x-1)) ans += N/x-1;
            if(isfav(N, x-1)) ans += x-1;
        }
    }

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long int
using namespace std;
int n,i,cnt[5],j,l,res;
string s;
main(){
	cin>>n;
	while(n--){
		cin>>s;
		if(s[0]=='M')cnt[0]++;
		else if(s[0]=='A')cnt[1]++;
		else if(s[0]=='R')cnt[2]++;
		else if(s[0]=='C')cnt[3]++;
		else if(s[0]=='H')cnt[4]++;
	}
	for(i=0;i<5;i++)
	for(j=i+1;j<5;j++)
	for(l=j+1;l<5;l++)
	res+=cnt[i]*cnt[j]*cnt[l];
	cout<<res;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
import collections
import copy
input = sys.stdin.readline
 
# bisect_left(lists, 3)
# bisect_right(lists, 3)
 
def main():
	N, M = map(int, input().split(" "))
	#N = int(input())
	#S = input()

	LR = []
	min_i = -1
	max_i = -1
	min_a = -1
	max_a = -1
	for i in range(M):
		L, R = map(int, input().split(" "))
		LR.append((L, R))
		if i == 0:
			min_i = L
			max_i = R
			min_a = L
			max_a = R
		else:
			if L > min_i:
				min_i = L
			if max_i > R:
				max_i = R

	ans = 0
	for i in range(min_i, max_i+1):
		ans += 1

	print(ans)


if __name__ == "__main__":
	main()

Measured memory_bytes: 17096
from fractions import gcd

def lcm(x, y):
    return x * y // gcd(x, y)

n, m = map(int, input().split())
a = [i // 2 for i in set(list(map(int, input().split())))]
b = []
for i in a:
    cnt = 0
    while i % 2 == 0:
        i //= 2
        cnt += 1
    b.append(cnt)

L = 1
ans = 0
if len(set(b)) == 1:
    for j in a:
        L = lcm(j, L)
        if m < L:
            ans = 0
            break
        else:
            ans = (m // L) - (m // (L * 2))
    print(ans)
else:
    print(0)


Measured memory_bytes: 16280
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--)
#define reprev(i,n) reprrev(i,0,n)
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
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; }
#define pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll INF = 1LL<<60;
 
const int MAX = 510000;
const int MOD = 1000000007;
 
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;
}
 
struct UnionFind {
	vector<int> par, rank;
 
	UnionFind(int n) : par(n, -1), rank(n, 0) { }
	void init(int n) { par.assign(n, -1), rank.assign(n, 0); }
 
	int root(int x) {
		if (par[x] == -1) return x;
		else return par[x] = root(par[x]);
	}
 
	bool issame(int x, int y) {
		return root(x) == root(y);
	}
 
	bool merge(int x, int y) {
		x = root(x); y = root(y);
		if (x == y) return false;
		if (rank[x] < rank[y]) swap(x, y);
		if (rank[x] == rank[y]) ++rank[x];
		par[y] = x;
		return true;
	}
};

vector<ll> dp(100010, INF);
ll N;
vector<ll> h;

int dfs(ll i){
  if(dp[i] != INF){
    return dp[i];
  }
  if(i == 0){
    return dp[i] = 0;
  }
  else{
    dp[i] = min(dp[i], dfs(i - 1) + abs(h[i] - h[i - 1]));
    if (i > 1) dp[i] = min(dp[i], dfs(i - 2) + abs(h[i] - h[i - 2]));
  }
  return dp[i];
}
 
int main() {
	cin >> N;
	rep(i, N) {
      ll a;
      cin >> a;
      h.push_back(a);
    }
  	cout << dfs(N-1) << endl;
}

Measured memory_bytes: 5108
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>

using namespace std;

long long int gcd(long long int a, long long int b) {
//
if(a<0) a=b;
if(b<0) b=a;
//
    if (b == 0) return a;
    return gcd(b, a%b);
}

long long int lcm(long long int a, long long int b) {
    return a*b/gcd(a, b);
}

int main(){

	long long int a, b, c, d, cd, cdiv, ddiv, cddiv, ans;

	cin>> a >> b >> c >> d;
	cd=lcm(c, d);

	cdiv=b/c-(a-1)/c;
	ddiv=b/d-(a-1)/d;
	cddiv=b/(cd)-(a-1)/cd;

	ans=b-a+1-cdiv-ddiv+cddiv;

	cout<< ans << endl;

}

Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll n,time=0;
  cin >> n;
  ll a[n],b[n];
  P sc[n];
  for(int i=0;i<n;i++){
    cin >> a[i] >> b[i];
    sc[i].first = b[i];
    sc[i].second = a[i];
  }
  sort(sc,sc+n,greater<P>());
  time =100000000000;
  for(int i=0;i<n;i++){
    if(time>=sc[i].first){
      time = sc[i].first;
    }
    time -= sc[i].second;
  }
  if(time>=0) cout <<"Yes\n";
  else cout <<"No\n";
}


Measured memory_bytes: 6528
import java.util.Scanner;

public class Main{

	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int result = 0;
		int[] k = new int[5];
		
		for(int i = a; i <= b; i ++) {
			int n = i;
			for(int j = 0; j < 5; j ++) {
				k[j] = (n % 10);
				n = n / 10;
				}
			if(k[0] == k[4] && k[1] == k[3]) {
				result ++;
			}
		}
		System.out.println(result);
	}
}


Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long int ll;

int main(){
    int n; cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    ll l=2,r=2;
    for(int i=n-1;i>=0;i--){
        l=(l+a[i]-1)/a[i]*a[i];
        r=r/a[i]*a[i]+a[i]-1;
    }
    if(l>r){
        cout << -1 << endl;
        return 0;
    }
    cout << l << " " << r << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>

using namespace std;

int main() {

	vector<vector<int>> c(3, vector<int>(3));
	for (int i = 0; i < 3; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			cin >> c[i][j];
		}
	}

	//aに対するチェック
	for (int i = 0; i < 2; i++)
	{
		for (int j = 0; j < 2; j++)
		{
			if (c[i][j] - c[i + 1][j] != c[i][j + 1] - c[i + 1][j + 1]) {
				cout << "No" << endl;
				return 0;
			}
		}
	}

	//bに対するチェック
	for (int i = 0; i < 2; i++)
	{
		for (int j = 0; j < 2; j++)
		{
			if (c[i][j] - c[i][j + 1] != c[i + 1][j] - c[i + 1][j + 1]) {
				cout << "No" << endl;
				return 0;
			}
		}
	}

	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	string s;
	int n;
	cin>>s>>n;
	string str;
	bool check[n];
	rep(i,n)check[i]=false;
	rep(i,n){
		cin>>str;
		rep(j,str.size()){
			rep(k,str.size()-s.size()+1){
				string sub=str.substr(k,s.size());
				if(sub==s){
					check[i]=true;
					break;
				}
			}
			if(check[i])break;
			char c=str[0];
			str+=c;
			str.erase(0,1);
		}
	}
	int ans=0;
	rep(i,n)if(check[i])ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
#define test int t; cin>>t; while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
using namespace std;

int main()
{
  long long n; cin>>n;
  if(n%2) cout<<n/2+1<<endl;
  else cout<<n/2<<endl;
}

Measured memory_bytes: 3604
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=998244353
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    D=list(map(int,input().split()))
    M=max(D)

    if(D[0]!=0):
        print(0)
        return

    C=[0]*(M+1)
    for d in D:
        C[d]+=1

    if(C[0]!=1):
        print(0)
        return

    if(any(C[i]==0 for i in range(M+1))):
        print(0)
        return

    ans=1
    for i in range(1,M+1):
        ans*=pow(C[i-1],C[i],MOD)
        ans%=MOD
    print(ans)
resolve()

Measured memory_bytes: 53292
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#define T 10000
#define inf 0x7fffffff
using namespace std;
int n,cnt=1,ans,s,head[10001],q[10001],to[10001],h[10001];
bool mark[10001];
struct data
{
	int to,next,v;
} e[200001];
void ins(int u,int v,int w)
{
	cnt++;
	e[cnt].to=v;
	e[cnt].v=w;
	e[cnt].next=head[u];
	head[u]=cnt;
}
void insert(int u,int v,int w)
{
	ins(u,v,w);
	ins(v,u,0);
}
bool bfs()
{
	int t=0,w=1,i,now;
	memset(h,-1,sizeof(h));
	h[0]=q[0]=0;
	while(t<w)
	{
		now=q[t];
		t++;
		i=head[now];
		while(i)
		{
			if(h[e[i].to]==-1&&e[i].v)
			{
				h[e[i].to]=h[now]+1;
				q[w++]=e[i].to;
			}
			i=e[i].next;
		}
	}
	if(h[T]==-1)return 0;
	return 1;
}
int dfs(int x,int f)
{
	if(x==T)return f;
	int i=head[x];
	int w,used=0;
	while(i)
	{
		if(e[i].v&&h[e[i].to]==h[x]+1)
		{
			w=f-used;
			w=dfs(e[i].to,min(w,e[i].v));
			e[i].v-=w;
			e[i^1].v+=w;
			used+=w;
			if(used==f)return f;
		}
		i=e[i].next;
	}
	if(!used)h[x]=-1;
	return used;
}
void dinic()
{
	while(bfs())ans-=dfs(0,inf);
}
int main()
{
	int x;
	cin>>x;
	int ans=0;
	int now=0;
	while(1)
	{
		now+=x;
		ans++;
		if(now>=360)
			now-=360;
		if(now==0)
			break;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3544
h,w=map(int,input().split())
A=[list(input()) for i in range(h)]
answ=[]
ansh=[]
for i in range(h):
  if not all([a=="." for a in A[i]]):
    answ.append(i)
for j in range(w):
  if not all([A[i][j]=="." for i in range(h)]):
    ansh.append(j)
for i in answ:
  for j in ansh:
    print(A[i][j],end="")
  print("")

Measured memory_bytes: 9240
use std::io::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn main() {
    let a: i32 = read();
    let b: i32 = read();

    if a == b {
        println!("Draw");
        return;
    }

    if a == 1 {
        println!("Alice");
        return;
    }
    if b == 1 {
        println!("Bob");
        return;
    }
    println!("{}", if a > b { "Alice" } else { "Bob" })
}


Measured memory_bytes: 4352
gets
a = gets.split.map {|x| x.to_i}
s = 0
mns = 0
mn = 100000000000
a.each { |v|
  s += v.abs
  if v < 0
    mns += 1
  end
  if v.abs < mn
    mn = v.abs
  end
}
if mns % 2 == 1
  s -= 2*mn
end
puts s


Measured memory_bytes: 8580
#include<bits/stdc++.h>
using namespace std;
#define SORT(x) sort(x.begin(),x.end())
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
    int n;cin>>n;ll a=0;
    rep(i,n){
        ll t;
        cin>>t;
        a=(a^t);
    }
    if(a==0)    cout<<"Yes"<<endl;
    else        cout<<"No"<<endl;
    return 0;
}


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

int main(){
    string S, T;
    string prev;
    int count1, count2, si;
    int K, front=0, back=0;
    cin >> S >> K;
    si = S.size();
    S = S + S[0];

    prev[0] = S[0];
    for(int i =0; i<3*si-1; i++){
        //cout << "i=" << i << " count=" << front << endl;
        int j = i%si;
        if(i == si-1) count1 = front;
        if(i == 2*si-1) count2 = front;
        if(prev[0] == S[j+1]){
            prev[0] = 1;
            front++;
            //cout << "change" << prev << endl;
        }
        else{
            prev[0] = S[j+1];
            //cout << "S[j+1] " << S[j+1] << endl;
            //cout << "unchange" << prev <<endl;
        }
    }
    int c1, c2, c3;
    double ans;
    c1 = count1;
    c2 = count2-c1;
    c3 = front-count2;
    //cout << "count1=" << count1 << " count2=" << count2 << endl;
    //cout << "c1=" << c1 << " c2=" << c2 << " c3=" << c3 << endl;
            
    if(c1 == c2){
        //cout << "pattern1" << endl;
        //cout << double(c1)*double(K) << endl;
        ans = double(c1)*double(K);
    }
    else if(c1 == c3){
        //cout << "pattern2" << endl;
        if(K%2 == 0){
            //cout << (c1+c2)*K/2 << endl;
            ans = (double(c1)+double(c2))*double(K)/2;
        }
        else{
            //cout << (double(c1)+double(c2))*double(K/2) + c1 << endl;
            ans = (double(c1)+double(c2))*double(K/2) + c1;
        }
    }
    else{ // c1 != c2 = c3
        //cout << "pattern3" << endl;
        //cout << c1 + double(c2)*double(K-1) << endl;
        ans = c1 + double(c2)*double(K-1);
    }
    printf("%.0f\n", ans);
}

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

int main()
{
    int n;
    cin>>n;
    for(int i=n;;i++){
        string s=to_string(i);
        bool flag=true;
        for(int j=0;j<s.length()-1;j++){
            if(s[j]!=s[j+1])
                flag=false;
        }
        if(flag){
            cout<<s;
            return 0;
        }
            
    }




}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>

using namespace std;

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
string s;
cin >> s;
s[3] = '8';
cout << s << "\n";
  return 0;
}

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

int divisor(int x,int y){
    return x/y;
}

int main(void){
    int k,a,b;
    cin>>k>>a>>b;
    if(divisor(a-1,k)!=divisor(b,k)) cout<<"OK"<<endl;
    else cout<<"NG"<<endl;
}



Measured memory_bytes: 3616
#include <stdio.h>

int main(void) {
	int W, H, x, y, r;
	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	if ((x <= 0) || (y <= 0) || (x < r) || (y < r)) {
		printf("No\n");
	} else if ((x + r <= W) && (y + r <= H)) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}
	return 0;
}

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

int main(){
int n;
string s,t;
cin>>n;
cin >> s>>t;
for (int i=0;i<n;++i){
   cout << s[i]<< t[i];
}
}

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

using namespace std;

int main(){
   string s;
   cin >> s;
   cout << s.substr(0,4) << " " << s.substr(4)<<endl;
}


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

// int n;

int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	// int t;
	// cin>>t;
	// while(t--) {

	// }

	// cin>>n;
	int a, b;
	cin>>a>>b;

	if(b & 1) cout<<"No\n";
	else if(b > 4*a || b < 2*a) cout<<"No\n";
	else cout<<"Yes\n";
		
	
}




Measured memory_bytes: 3628
# coding: utf-8
N = int(input())
H = list(map(int, input().split()))
m = 0
c = 0
for i in range(N - 1):
    if H[i] >= H[i+1]:
        c += 1
        m = max(m, c)
    else:
        c = 0
print(m)

Measured memory_bytes: 14224
#include <bits/stdc++.h>
#define int long long
#define rep(i, a, n) for(int i = (int)(a);(i) < (int)(n);++(i))
#define repe(i, a, n) for(int i = (int)(a);(i) <= (int)(n);++(i))
#define repif(i, a, x) for(int i = (int)(a);(x);++(i))
#define repr(i, a, n) for(int i = ((int)(a)-1);(i) >= (int)(n);--(i))
#define reper(i, a, n) for(int i = (int)(a);(i) >= (int)(n);--(i))
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define RNG(x, a, n) &((x)[a]), &((x)[n])
#define ADD(a, b) (((a%MOD+MOD)%MOD+(b%MOD+MOD)%MOD)%MOD)
#define SUB(a, b) (((a%MOD+MOD)%MOD-(b%MOD+MOD)%MOD+MOD)%MOD)
#define MUL(a, b) ((((a%MOD+MOD)%MOD)*((b%MOD+MOD)%MOD))%MOD)
#define CHADD(a, b) (a = ADD(a, b))
#define CHMUL(a, b) (a = MUL(a, b))
#define CEIL(x) ((int)ceil(((double)x)))
#define POW(x, y) ((int)pow(x, y))
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define gcd(x, y) __gcd(x, y)
#define lcm(x, y) (x/gcd(x,y)*y)
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define yes cout << "yes" << endl
#define no cout << "no" << endl
#define fcout cout << fixed << setprecision(10)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define PI (acos(-1))
#define EPS (1e-10)
#define INF LLONG_MAX
#define MOD 1000000007LL
using namespace std;
using VI = vector<int>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using Complex = complex<double>;
template<typename T, template<typename> typename C = less> using PQ = priority_queue<T, vector<T>, C<T>>;
template<typename T> bool chmax(T& a, const T& b){ if(a<b){ a=b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b){ if(a>b){ a=b; return true; } return false; }
template<typename I> int ACC(I f, I l, int i = 0){ return accumulate(f, l, i); }


int N, K;
int A[510];
VI d;


VI divisor(int n, bool r = false){
    VI ret;
    repif(i, 1, i*i <= n){
        if(n%i == 0){
            ret.pb(i);
            if(i*i != n) ret.pb(n/i);
        }
    }
    if(r) sort(ALL(ret), greater<int>());
    else sort(ALL(ret));
    return ret;
}


signed main(){
    cin >> N >> K;
    rep(i, 0, N) cin >> A[i];

    d = divisor(ACC(RNG(A, 0, N)), true);

    int ans = 0;
    for(int x : d){
        VI b;
        b.pb(0);
        rep(i, 0, N) b.pb(A[i]%x);
        sort(ALL(b));
        repe(i, 1, N) b[i] += b[i-1];
        repe(i, 1, N)
            if(b[i]-b[0] == x*(N-i)-(b[N]-b[i]) && b[i]-b[0] <= K){ ans = x; break; }
        if(ans) break;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{       
   public static void main(String[] args){

      Scanner sc = new Scanner(System.in);                                            
      
      String S = sc.next();       
      
      String ans = S.substring(0,4) + " " + S.substring(4,12);
      
      System.out.println(ans);
      
   }
}
        
        


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

using namespace std;
using ll = long long;

const ll MOD_VAL = 1e9+7;
ll dp[10005][105];
string k;
int d;

int main(){
    int sum = 0;
    cin>>k>>d;
    int len = k.length();
    for(int i=0;i<len;i++){
        int val = k[i] - '0';
        sum += val;
        if(i!=0)
            for(int j=0;j<d;j++){
                for(int z=0;z<=9;z++) {
                    dp[i][(j + z) % d] += dp[i - 1][j];
                    dp[i][(j + z) % d] %= MOD_VAL;
                }
            }
        for(int j=0;j<val;j++){
            dp[i][(sum-val+j)%d]++;
            dp[i][(sum-val+j)%d] %= MOD_VAL;
        }
    }
    cout<<(MOD_VAL + dp[len-1][0]-1+(sum % d == 0))%MOD_VAL;
    return 0;
}

Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
 
#define N (int)3e3+5
#define f1 first
#define s2 second
#define INF 9999999
#define pb push_back
#define ll long long
#define ull unsigned long long;
#define all(a) a.begin(),a.end()
#define fri(a) freopen(a,"r",stdin);
#define fro(a) freopen(a,"w",stdout);

string  str1,str2,ans;
int dp[N][N],n,m;

void lcs(){
	for(int i = 0; i <= n ;i++){
		for(int j = 0; j <= m; j++){
			if(i == 0 || j == 0){
				dp[i][j]=0;
			}
			else if(str1[i-1] == str2[j-1]){
				dp[i][j]=1+dp[i-1][j-1];
			}
			else dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}

}

int main(){
	//fri("in.txt");
	//fro("out.txt");
	cin >> str1 >> str2;
	n = str1.length();
	m = str2.length();
	memset(dp,-1,sizeof(dp));
	lcs();
	while(n>0 && m>0){
		if(str1[n-1]==str2[m-1]){
			ans.pb(str1[n-1]);
			n--;
			m--;
		}
		else if(dp[n-1][m]>dp[n][m-1]){
			n--;
		}
		else m--;
	}
	reverse(all(ans));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 35584
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	n, a := r.nextInt(), r.nextInt()
	r.Scan(true)
	x := r.nextStringArray().toInts()

	type dp struct {
		i, s, c int
	}

	DP := map[dp]int{}

	var f func(i, s, c int) int
	f = func(i, s, c int) int {
		cnt, ok := DP[dp{i, s, c}]
		if ok {
			return cnt
		}
		if i >= n {
			if c >= 1 && a*c == s {
				cnt++
			}
			return cnt
		}
		cnt += f(i+1, s+x[i], c+1) + f(i+1, s, c)
		DP[dp{i, s, c}] = cnt
		return cnt
	}
	fmt.Fprintln(stdout, f(0, 0, 0))
}


Measured memory_bytes: 38272
#include<iostream>
#include<complex>
#include<cstdio>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define X real()
#define Y imag()

typedef long double D;
typedef complex<D> P;
struct L{P a, b;};

const D EPS = 1e-8;

D det(P a, P b) {return a.X * b.Y - a.Y * b.X;}
P vec(L a) {return a.b - a.a;} 

// 直線の交点
P pLL(L a, L b) {return a.a + vec(a) * (det(vec(b), b.a - a.a) / det(vec(b), vec(a)));}

int n;
P pp[11];
D l[11], res;

// ２点を決めてロープがピンと張る点
P b(int i, int j) {return pp[i] + (pp[j] - pp[i]) * (norm(pp[i] - pp[j]) + l[i] * l[i] - l[j] * l[j]) / (2 * norm(pp[i] - pp[j]));}

// 点を決めた時にどれだけ高くできるか求めてresを更新
void h(P p) {
  D r = 1e9;
  rep (i, n) r = min(r, sqrt(max(l[i] * l[i] - norm(pp[i] - p), (D)0)));
  res = max(res, r);
}

int main() {
  while (cin >> n, n) {
    rep (i, n) cin >> pp[i].X >> pp[i].Y >> l[i];
    res = 0;
    // １点
    rep (i, n) h(pp[i]);
    // ２点
    rep (i, n) rep (j, i) h(b(i, j));
    // ３点
    rep (i, n) rep (j, i) rep (k, j) if (abs(det(pp[j] - pp[i], pp[k] - pp[i])) > EPS) {
      P b1 = b(i, j), b2 = b(i, k);
      h(pLL((L){b1, b1 + (pp[i] - pp[j]) * P(0, 1)}, (L){b2, b2 + (pp[i] - pp[k]) * P(0, 1)}));
    }
    printf("%.12Lf\n", res);
  }
  return 0;
}

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

typedef long long ll;
const int N = 1e5 + 100;

int n, x, y;
ll ans;
bool mark[N];
vector<int> nei[N], have[N], vec;
set<int> st[N];

void add(int u, int v) {
	nei[u].push_back(v);
	nei[v].push_back(u);
}

void dfs(int v) {
	mark[v] = true;
	vec.push_back(v);
	for (int u: nei[v])
		if(mark[u] == false)
			dfs(u);
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	ans = -n;
	while(n--) {
		cin >> x >> y;
		have[y].push_back(x);
		st[x].insert(y);
	}
	for (int i = 0; i < N; i++)
		for (int j = 1; j < have[i].size(); j++)
			add(have[i][j - 1], have[i][j]);
	for (int i = 0; i < N; i++)
		if(mark[i] == false) {
			vec.clear();
			dfs(i);
			set<int> help;
			for (int u: vec)
				help.insert(st[u].begin(), st[u].end());
			ans += 1LL * vec.size() * help.size();
		}
	cout << ans;
	return 0;
}

Measured memory_bytes: 21504
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <string>

#include<stdio.h>
#include<math.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

using namespace std;

int main(){

  int n,x;

  while(1){
    cin >>n >>x;

    if(n==0 && x==0) break;

    int num=0;

    for(int i=1;i<=n;i++){
      for(int j=i+1;j<=n;j++){
	for(int k=j+1;k<=n;k++){
	  if(i+j+k==x) num++;
	}
      }
    }
    cout <<num <<endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#ifdef _DEBUG_
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl
#else
#define dump(val)
#endif

using namespace std;

typedef long long int ll;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<ll> X(M);
    REP(i, 0, M) {
        cin >> X[i];
    }
    sort(begin(X), end(X));
    vector<ll> dis;
    REP(i, 0, M - 1) {
        dis.push_back(X[i + 1] - X[i]);
    }
    sort(begin(dis), end(dis), greater<ll>());
    ll ans = 0;
    REP(i, N - 1, M - 1) {
        ans += dis[i];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2168
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;
constexpr int kNumBit = 40;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vs){
  for (const T& v : vs) os << v << " ";
  return os;
}

template<typename T1, typename T2>
ostream& operator << (ostream& os, const map<T1, T2>& m){
  for (const auto [k, v] : m) os << "{" << k << "," << v << "} ";
  return os;
}

int main() {
  LL N, K; cin >> N >> K;
  vector<LL> A(N); cin >> A;
  map<LL, LL> m0, m1;
  for (int i = 0; i < N; ++i) {
    bitset<kNumBit> b(A[i]);
    for (int j = 0; j < kNumBit; ++j) {
      if (b.test(j)) m1[j]++;
      else           m0[j]++;
    }
  }

  LL ans = 0;
  for (int j = kNumBit - 1; j >= 0; --j) {
    if ((1LL << j) > K) continue;
    if (m0[j] <= m1[j]) continue;

    LL tmp = ans | (1LL << j);
    if (tmp <= K) ans = tmp;
  }

  LL f = 0;
  for (LL x : A) {
    LL v = ans ^ x;
    f += v;
  }

  cout << f << endl;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  int L[K];
  for (int i = 0; i < K; i++) {
    cin >> L[i];
  }
  for (int m = N; m <= N * 10; m++) {
    int tmp = m;
    while (tmp > 0) {
      int d = tmp % 10;
      int find = 0;
      for (int num = 0; num < K; num++) {
        if (d == L[num]) {
          find = 1;
          break;
        }
      }
      if (find == 1) {
        break;
      } else {
        tmp = tmp / 10;
      }
    }
    if (tmp == 0) {
      cout << m << endl;
      break;
    }
  }
}

Measured memory_bytes: 256
s = input()

for i in range(len(s)-1):
    if s[i] == s[i+1]:
        print(i+1, i+2)
        exit()
for i in range(len(s)-2):
    if s[i] == s[i+2]:
        print(i+1, i+3)
        exit()
print(-1, -1)

Measured memory_bytes: 9060
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int num[4];
string ans;
string temp;
int dfs(int i,int j, int k){
  int sum=num[0];
  int d[3];
  d[0]=i;
  d[1]=j;
  d[2]=k;

  int key=1;

  for(int i=0;i<3;i++){
    if(d[i]==0)
      sum-=num[key];
    else if(d[i]==1)
      sum+=num[key];
    key++;
  }
  if(sum==7)
    return 1;
  else
    return 0;
}
int main(){
  char a[5];
  cin >> a;
  for(int i=0;i<4;i++){
    temp+=a[i];
    num[i]=a[i]-'0';
    if(i!=3)
      temp+=' ';
  }

  int i,j,k;
  char op[]={"-+"};
  for(i=0;i<2;i++){
    for(j=0;j<2;j++){
      for(k=0;k<2;k++){
        temp[1]=op[i];
        temp[3]=op[j];
        temp[5]=op[k];
        if(dfs(i,j,k)==1)
          break;
      }
      if(k!=2)
        break;
    }
    if(j!=2)
      break;
  }

  temp+="=7";
  cout << temp << endl;
  return 0;
}

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

int main(){

  int x,y,w,h;
  int me,mw,mn,ms;
  int n;
  int m;
  int a,b;

  cin >> m;

  for(int l=0;l<m;l++){
    int ans = 0;

    cin >> x >> y >> w >> h;
    cin >> n;

    for(int i=0;i<n;i++){
      cin >> a >> b;
      if(a >= x && a <= x+w && b >= y && b <= y+h) ans++;
    }
  
    cout << ans << endl;
  }
}

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

using namespace std;

int main() {
	int n, q;
	vector<int> S, T;

	cin >> n;
	S.resize(n);
	for (auto &Si: S) {
		cin >> Si;
	}

	cin >> q;
	T.resize(q);
	for (auto &Ti: T) {
		cin >> Ti;
	}

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

	int ans = 0;
	for (auto Ti: T) {
		if (binary_search(S.begin(), S.end(), Ti)) {
			++ans;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) do {cout << (A) << '\n'; exit(0);} while (false)

ll N, M;
vector<ll> A, S;

ll ormorecount(ll t)
{
  ll ret = 0;
  for (ll i = 0; i < N; i++)
  {
    ll a = A.at(i);

    auto it = lower_bound(A.begin(), A.end(), t - a);
    ll tmp = N - (it - A.begin());

    ret += tmp;
  }
  return ret;
}

ll ormoresum(ll t)
{
  ll ret = 0;
  ll cntall = 0;
  for (ll i = 0; i < N; i++)
  {
    ll a = A.at(i);

    auto it = lower_bound(A.begin(), A.end(), t - a);
    ll ind = it - A.begin();
    ll cnt = N - ind;
    cntall += cnt;

    ll tmp = S.at(ind);
    ret += cnt * a + tmp;
  }
  ret -= max(0LL, t * (cntall - M));
  return ret;
}

int main()
{
  cin >> N >> M;
  A.resize(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }
  sort(A.begin(), A.end());

  S.resize(N + 1), S.back() = 0;
  for (ll i = N; i > 0; i--)
  {
    S.at(i - 1) = S.at(i) + A.at(i - 1);
  }

  ll ok = 0, ng = 2e5 + 10;
  while (abs(ok - ng) > 1)
  {
    ll mid = (ok + ng) / 2;
    if (ormorecount(mid) >= M)
      ok = mid;
    else
      ng = mid;
  }

  cout << ormoresum(ok) << endl;
}

Measured memory_bytes: 1792