akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
//#include"testlib.h"
#define endl "\n"
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define watch(x) cout << (#x)<<" = "<<x<<endl
#define sz(s)    (int)(s.size())
#define PI acos(-1)
#define EPS 1e-100
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	//freopen("street.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
void fast() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}
int n, m, q;
vector<vi> v1;
vi arr;
int ans = 0;
void solve(int idx, int prev) {
	if (idx == n) {
		int could = 0;
		for (auto& it : v1) {
			int b = it[1] - 1, a = it[0] - 1, c = it[2];
			if (arr[b] - arr[a] == c)
				could += it.back();
		}
		ans = max(ans, could);
		return;
	}
	for (int i = prev; i <= m; i++) {
		arr[idx] = i;
		solve(idx + 1, i);
	}
}
int main() {
//	file();
	fast();
	cin >> n >> m >> q;
	v1 = vector<vi>(q, vi(4));
	for (auto& it : v1)
		for (auto& tt : it)
			cin >> tt;
	arr = vi(n);
	solve(0, 1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3564
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <memory.h>
#include <cmath>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <ctime>
#include <iostream>
#include <functional>
#include <complex>
#include <stdlib.h>
#include <random>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef pair<pii, int> p3i;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<p3i> v3i;
typedef vector<vii> vvii;
typedef vector<p3i> vp3i;
typedef long double ld;
typedef vector<ld> vld;

#define pb push_back
#define mp make_pair
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define REPD(i, n) for (int (i) = (n) - 1; (i) >= 0; (i)--)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define FORD(i,a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define rv(v) reverse(all(v))
#define CL(v, val) memset((v), (val), sizeof((v)))
#define SORT(a) sort(all(a))
#define un(v) SORT(v), (v).resize(unique(all(v)) - (v).begin())
#define eps 1.0e-9
#define X first
#define Y second
#define bit(n) (1 << (n))
#define bit64(n) (ll(1) << (n))
#define sqr(x) ((x) * (x))

int main(void) {
	int h1, s1, h2, s2;
	scanf("%d%d%d%d", &h1, &s1, &h2, &s2);
	int id = 0;
	while (true) {
		if (id == 0) {
			h2 -= s1;
			if (h2 <= 0) {
				printf("Yes\n");
				return 0;
			}
		}
		else {
			h1 -= s2;
			if (h1 <= 0) {
				printf("No\n");
				return 0;
			}
		}

		id = 1 - id;
	}
}

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

typedef long long ll;

const long long MOD = 1000000007;
long long modpow(long long a, long long n, long long m)
{
    long long ans = 1;
    while (n)
    {
        if (n & 1)
        {
            ans = (ans * a) % m;
        }
        a = (a * a) % m;
        n >>= 1;
    }
    return ans;
}
long long combi(long long n, long long a)
{
    long long ans = 1, ans1 = 1;
    for (long long i = n - a + 1; i <= n; i++)
    {
        ans *= i % MOD;
        ans %= MOD;
    }

    for (long long i = 2; i <= a; i++)
        ans1 = (ans1 * i) % MOD;
    ans1 = modpow(ans1, MOD - 2, MOD);
    return ((ans % MOD) * ans1) % MOD;
}

void dfs(string s, char mx, ll N)
{
    if (s.length() == (size_t)N)
    {
        cout << s.c_str() << endl;
    }
    else
    {
        for (char c = 'a'; c <= mx; c++)
        {
            dfs(s + c, ((c == mx) ? (char)(mx) : mx), N);
        }
    }
}

int bfs(int a, int b, int h, int w, char tmp[][101])
{
    int ans[101][101] = {0};
    char c[101][101] = {0};
    queue<pair<int, int>> s;

    for (int i = 0; i <= h; i++)
    {
        for (int j = 0; j <= w; j++)
        {
            c[i][j] = tmp[i][j];
        }
    }

    s.push(make_pair(a, b));

    while (s.size() > 0)
    {

        pair<int, int> tmp = s.front();
        s.pop();
        c[tmp.first][tmp.second] = '#';
        for (int i = -1; i <= 1; i++)
        {
            for (int j = -1; j <= 1; j++)
            {
                if (tmp.first + i < 1 || tmp.first + i > h)
                {
                    continue;
                }
                if (tmp.second + j < 1 || tmp.second + j > w)
                {
                    continue;
                }
                if (i != 0 && j != 0)
                {
                    continue;
                }
                if (i == 0 && j == 0)
                {
                    continue;
                }
                if (c[tmp.first + i][tmp.second + j] == '#')
                {
                    continue;
                }
                c[tmp.first + i][tmp.second + j] = '#';
                if (ans[tmp.first + i][tmp.second + j] == 0)
                {
                    ans[tmp.first + i][tmp.second + j] = ans[tmp.first][tmp.second] + 1;
                }
                else
                {
                    ans[tmp.first + i][tmp.second + j] = min(ans[tmp.first + i][tmp.second + j], ans[tmp.first][tmp.second] + 1);
                }
                s.push(make_pair(tmp.first + i, tmp.second + j));
            }
        }
    }

    int asd = 0;

    for (int i = 1; i <= h; i++)
    {
        for (int j = 1; j <= w; j++)
        {
            asd = max(a, ans[i][j]);
        }
    }

    return asd;
}

ll gcd(ll a, ll b)
{
    if (a % b == 0)
    {
        return (b);
    }
    else
    {
        return (gcd(b, a % b));
    }
}

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

int main()
{
    double r;
    cin >> r;

    cout << 2.0 * r * 3.1415 << endl;

    return 0;
}


Measured memory_bytes: 3816
n,k = map(int, input().split())

trees = [int(input()) for i in range(n)]

trees.sort(reverse=True)

mindiff = trees[0]-trees[k-1]
for i in range(n-k+1):
    if(trees[i]-trees[i+k-1] <mindiff):
        mindiff = trees[i] - trees[i+k-1]
print(mindiff) 


Measured memory_bytes: 7384
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>

using std::list;
using std::max;
using std::min;
using std::vector;

int main()
{
  int a, b;
  scanf("%d%d", &a, &b);
  printf("%d\n", a + b / 2);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;


int s;
bool memo[10000000];

int res() {
	memo[s] = 1;
	for (int i = 2;i <= 1000000;i++) {
		if (s % 2 == 0) s /= 2;
		else s = 3 * s + 1;
		if (memo[s]) return i;
		else memo[s] = 1;
	}
}

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

	cin >> s;
	cout << res() << "\n";
	
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
 
import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict

S = input()
T = input()
lenS = len(S)
lenT = len(T)
F1 = [False]*26
F2 = [False]*26
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in range(lenS):
    F1[alpha.index(S[i])] = True
for i in range(lenT):
    F2[alpha.index(T[i])] = True
for i in range(26):
    if not F1[i] and F2[i]:
        print(-1)
        sys.exit()

ind = S.index(T[0])
ans = ind+1
for i in range(1,lenT):
    S = S[ind+1:] + S[:ind+1]
    ind = S.index(T[i])
    ans += ind+1

print(ans)


Measured memory_bytes: 3976
#include<cstdio>
#include<algorithm>
using namespace std;
int n,k,ans,vis[200001];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&k);
		vis[k]++;
	}
	for (int i=-1;i<=100001;i++)ans=max(ans,vis[i]+vis[i-1]+vis[i+1]);
	printf("%d",ans);
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(void){
    int x,y;
    while(true){
        cin >> x;
        cin >> y;
        if(x == 0 && y == 0){
            break;
        }
        if(x < y){
            cout << x << " " << y << endl;
        }
        else{
            cout << y << " " << x << endl;
        }
    }
    
}



Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define int long long
#define pb push_back
#define mod 1000000007
#define setbits(x) __builtin_popcountll(x)
#define zerobits(x) __builtin_ctzll(x)
#define inf 1e18
#define pre(x,y) fixed<<setprecision(y)<<x
#define pq priority_queue<int>
#define mpq priority_queue<int,vector<int>,greater<int>>
#define gcd(x,y) __gcd(x,y)
#define mp make_pair

int dfs(vector<int> v[],vector<vector<int>> &dp,int src,int p,int b)
{

	if(dp[src][b]!=-1) return dp[src][b];
	int w1=1;
	int w2=1;
	int ans=0;
	for(auto x:v[src])
	{
		if(x!=p)
		{
			
			w1=(w1*dfs(v,dp,x,src,0))%mod;
			if(!b)
			{
				w2=(w2*dfs(v,dp,x,src,1))%mod;
			}
		}
	}
	ans=(ans+w1)%mod;
	if(!b) ans=(ans+w2)%mod;
	return dp[src][b]=ans;
}





int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,i,j,k;
    cin>>n;
    vector<int> v[n];
    int x,y;
    for(i=1;i<n;i++)
    {
    	cin>>x>>y;
    	x--;y--;
    	v[x].pb(y);
    	v[y].pb(x);
    }
    vector<vector<int>> dp(n,vector<int>(2));
    for(i=0;i<n;i++)
    {
    	dp[i][0]=-1;
    	dp[i][1]=-1;
    }
    cout<<dfs(v,dp,0,0,0)<<endl;
	return 0;
}


Measured memory_bytes: 23676
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <vector>
#include <map>

int main() {
	std::string s;
	std::cin >> s;
	int ans = s.size();
	char c = s[0];
	for (int i = 1;i < s.size();i++) {
		if (c != s[i]) {
			if (i>s.size()-i) {
				if (ans > i) {
					ans = i;
				}
				c = s[i];
			}
			else {
				if (ans > s.size() - i) {
					ans = s.size() - i;
				}
				c = s[i];
			}
		}
	}
	std::cout << ans << std::endl;
	return 0;
}
	


Measured memory_bytes: 512
#include <stdio.h>

int main(void) {
    int S[14] = {};
    int H[14] = {};
    int C[14] = {};
    int D[14] = {};
    int n, number;
    char suit;
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        (void)getchar();
        scanf("%c %d", &suit, &number);

        if (suit == 'S') S[number] = 1;
        else if (suit == 'H') H[number] = 1;
        else if (suit == 'C') C[number] = 1;
        else if (suit == 'D') D[number] = 1;
    }

    for (int i = 1; i <= 13; i++) {
        if (S[i] == 0) printf("S %d\n", i);
    }
    for (int i = 1; i <= 13; i++) {
        if (H[i] == 0) printf("H %d\n", i);
    }
    for (int i = 1; i <= 13; i++) {
        if (C[i] == 0) printf("C %d\n", i);
    }
    for (int i = 1; i <= 13; i++) {
        if (D[i] == 0) printf("D %d\n", i);
    }

    return 0;
}


Measured memory_bytes: 2072
a,b,c = map(int,input().split())

oldCookies = []
oldCookies.append([a,b,c])

answer = 0

while(True):
	if a % 2 == 1 or b % 2 == 1 or c % 2 == 1:
		break 
	after_a = b / 2 + c / 2
	after_b = a / 2 + c / 2
	after_c = a / 2 + b / 2
	a = after_a
	b = after_b 
	c = after_c
	cookies = [a,b,c]
	answer += 1 
	
	for i in range(len(oldCookies)):
		if oldCookies[i] == cookies:
			answer = -1
			break

	if answer == -1:
		break

print(answer)

Measured memory_bytes: 61944
from operator import itemgetter, attrgetter
N = int(input())
keys=[]
values=[]
nums = []
number = 0 

for i in range(N):
    num = i+1
    a, b = input().split()
    nums.append(num)
    keys.append(a)
    values.append(int(b))

d = zip(nums, keys, values)

dout = sorted(d, key=itemgetter(2), reverse=True)
dout = sorted(dout, key=itemgetter(1))

nu, a, b = zip(*dout)
for n in nu:
    print(n)

Measured memory_bytes: 3064
class UnionFind:
    import sys
    sys.setrecursionlimit(100000)

    def __init__(self, v_num):
        self.parent = [n for n in range(v_num)]
        self.rank = [0 for n in range(v_num)]

    def find(self, v):
        if v == self.parent[v]:
            return v
        else:
            root = self.find(self.parent[v])
            self.parent[v] = root
            return root

    def unite(self, a_v, other_v):
        a_root = self.find(a_v)
        other_root = self.find(other_v)
        if a_root == other_root:
            return
        if self.rank[a_root] < self.rank[other_root]:
            self.parent[a_root] = other_root
        else:
            self.parent[other_root] = a_root
            if self.rank[a_root] == self.rank[other_root]:
                self.rank[a_root] += 1

    def same(self, a_v, other_v):
        return self.find(a_v) == self.find(other_v)

v_num, query = (int(n) for n in input().split(" "))
uf = UnionFind(v_num)
for _ in range(query):
    com, a, b = (int(n) for n in input().split(" "))
    if com == 0:
        uf.unite(a, b)
    else:
        if uf.same(a, b):
            print(1)
        else:
            print(0)

Measured memory_bytes: 8068
#include<bits/stdc++.h>
#define N 200100
using namespace std;
int main(){
	int n,k,s;
	scanf("%d%d%d",&n,&k,&s);
	for(int i=0;i<k;i++){
		printf("%d ",s);
	}
	for(int i=0;i<n-k;i++){
		printf("%d ",s>n?1:s+1);
	}
	return 0;
}

Measured memory_bytes: 1280
#include <atcoder/math>
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int main() {
    int t;
    cin >> t;
    while (t--) {
        ll n, m, a, b;
        cin >> n >> m >> a >> b;
        cout << atcoder::floor_sum(n, m, a, b) << "\n";
    }

    return 0;
}

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

int a(string s) {
  int res = 0;
  int len = (int) s.size();
  for(int i=0;i<len;i++) {
    if(s[i] == '+')
      res++;
    else
      res--;
  }
  return res;
}

int main() {
  string s;
  cin >> s;
  cout << a(s);
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sqr(x) ((x)*(x))
#define mp make_pair
#define uint unsigned
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
	write(a); puts("");
}
inline int rnd(int x){
	return (rand()<<16|rand())%x;
}
const int N=2005;
int f[N][N],g[N][N],jb[N],jj[N],zs[N],n,m,ans;
char ch[N][N];
inline int get(int pos,int x){
	if(zs[pos]<x)return pos;
	else return get(jb[pos],x);
}
inline int ggg(int pos,int x){
	if(zs[pos]<x)return pos;
	else return ggg(jj[pos],x);
}
int main(){
	n=read(); m=read();
	ans=max(n,m);
	for(int i=1;i<=n;i++)scanf("%s",ch[i]+1);
	for(int i=1;i<=n;i++){
		for(int j=1;j<m;j++){
			f[i][j]=ch[i][j]==ch[i][j+1];
			g[i][j]=f[i][j]==f[i-1][j]?g[i-1][j]+1:1;
		}
	}
	zs[0]=zs[m]=-1e9;
	for(int i=1;i<=n;i++){
		for(int j=1;j<m;j++){
			jb[j]=get(j-1,zs[j]=g[i][j]);
		}
		for(int j=m-1;j;j--){	
			jj[j]=ggg(j+1,zs[j]);
			//cout<<i<<" "<<j<<" "<<zs[j]<<" "<<jj[j]<<" "<<jj[j]-jb[j]<<endl;
			ans=max(ans,(jj[j]-jb[j])*zs[j]);
		}
	}
	cout<<ans<<endl;
}

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

int main(){
  int a, b;
  cin >> a >> b;
  if(a < 0 && 0 < b) {
    cout << "Zero" << endl;
    return 0;
  }
  if(a > 0) {
    cout << "Positive" << endl;
    return 0;
  }
  if(b < 0) {
    if( (abs(a) - abs(b) + 1) % 2 == 0) {
      cout << "Positive" << endl;
      return 0;
    } else {
      cout << "Negative" << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
package main

import "fmt"

func main()  {
	var a, b int
	fmt.Scan(&a, &b)
	switch {
	case a < b:
		fmt.Println("a < b")
	case a > b:
		fmt.Println("a > b")
	case a == b:
		fmt.Println("a == b")
	}
}


Measured memory_bytes: 1096
#include<bits/stdc++.h>
using namespace std;
namespace whatever{
	int readu(){
		char ch=getchar();
		while(!isdigit(ch))
			ch=getchar();
		int value=ch-'0';
		ch=getchar();
		while(isdigit(ch)){
			value=value*10+ch-'0';
			ch=getchar();
		}
		return value;
	}
	void writeu(int n){
		if(n<10)
			putchar(n+'0');
		else{
			writeu(n/10);
			putchar(n%10+'0');
		}
	}
	void run(){
		int h=readu();
		int w=readu();
		static int x1[1000000];
		static int y1[1000000];
		static int x2[1000000];
		static int y2[1000000];
		int size=0;
		static int cnt[501][501];
		for(int i=1; i<=h; ++i)
			for(int j=1; j<=w; ++j)
				cnt[i][j]=readu();
		for(int i=1; i<h; ++i)
			for(int j=1; j<=w; ++j)
				if(cnt[i][j]%2){
					cnt[i+1][j]+=cnt[i][j];
					x1[size]=i;
					y1[size]=j;
					x2[size]=i+1;
					y2[size]=j;
					++size;
				}
		for(int j=1; j<w; ++j)
			if(cnt[h][j]%2){
				cnt[h][j+1]+=cnt[h][j];
				x1[size]=h;
				y1[size]=j;
				x2[size]=h;
				y2[size]=j+1;
				++size;
			}
		writeu(size);
		putchar('\n');
		for(int i=0; i<size; ++i){
			writeu(x1[i]);
			putchar(' ');
			writeu(y1[i]);
			putchar(' ');
			writeu(x2[i]);
			putchar(' ');
			writeu(y2[i]);
			putchar('\n');
		}
	}
}
int main(){
	whatever::run();
}

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

int main() {
	
	int n;
	cin >> n;
	vector<tuple<int, int, int>> t(n);
	int h_max = 0;
	rep(i, n){
		int x, y, h;
		cin >> x >> y >> h;
		t[i] = make_tuple(x, y, h);
		if(h_max < h) h_max = h;
	}
	int ans[3] = {0};
	bool is_answer_found = false;
	
	for(int cx = 0; cx <= 100; cx++){
		for(int cy = 0; cy <= 100; cy++){
			int h;
			
			for(h = h_max; h <= h_max + 200; h++){
				bool is_all_correct = true;
				rep(i, n){	
					int tmp = max(0, h - abs(get<0>(t[i]) - cx) - abs(get<1>(t[i]) - cy));
					if(get<2>(t[i]) != tmp){
						is_all_correct = false;
						break;
					}
				}
				if(is_all_correct){
					is_answer_found = true;
					break;
				}
			}
			if(is_answer_found){
				ans[0] = cx;
				ans[1] = cy;
				ans[2] = h;
				break;
			}
		}
		if(is_answer_found) break;
	}
	cout << ans[0] << " " << ans[1] << " " << ans[2] << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define LL long long
template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
const long long LLINF = 1LL << 62;
const int INF = 1LL << 30;
using namespace std;

int main(void) {
	int N, X;
	cin >> N >> X;
	vector<int> L(N);
	rep(i, N) cin >> L[i];

	vector<int> ruiseki(N+1);
	for (int i = 1; i <= N; i++)
	{
		ruiseki[i] = ruiseki[i-1] + L[i-1];
	}

	cout << upper_bound(ALL(ruiseki), X) - ruiseki.begin() << endl;
	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    abc150c()
}

fun abc150c() {
    val n = readLine()!!.toInt()
    val p = readLine()!!.split(' ').map { it.toInt() }.joinToString("")
    val q = readLine()!!.split(' ').map { it.toInt() }.joinToString("")

    val perms = permutation((1..n).joinToString(""), "").map { it.toString() }

    val a = perms.indexOf(p)
    val b = perms.indexOf(q)

    val answer = Math.abs(a - b)

    println(answer)
}

fun permutation(q: String, ans: String): List<Int> {
    return if (q.length <= 1) {
        listOf((ans + q).toInt())
    } else {
        (q.indices).map {
            permutation(q.substring(0, it) + q.substring(it + 1), ans + q[it])
        }.flatten()
    }
}


Measured memory_bytes: 67420
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
int const INF = 1001001001;


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

int N,H;
cin >> N >> H;
vi a(N),b(N);
rep(i,N) cin >> a[i] >> b[i];

int normal = *max_element(all(a));
sort(all(b), greater<int>());
int ans = 0;
rep(i,N) {
    if(b[i] > normal) {
        H -= b[i];
        ans++;
    }
    if(H <= 0) {
        cout << ans << endl;
        return 0;
    }
}
ans += (H + normal - 1) / normal;
cout << ans << endl;
return 0;
}

Measured memory_bytes: 1024
#!/usr/local/gnu/bin/bash
read n k
l=(`seq 0 $n`)
for i in `seq $k`
do
    read d
    read -a a
    for j in ${a[@]}
    do
        l[$j]="x"
    done
done
l=(`echo ${l[@]} | tr -d 0x`)
echo ${#l[@]}


Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const int INF=1<<30,MOD=1000000007;
const ll LINF=1ll<<60;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _overload3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPARR(i,v) for(int i=0;i<v.size();++i)
#define all(v) (v).begin(),(v).end()
#define uniq(v) sort(all(v));v.erase(unique(all(v)),v.end())
#define bit(n) (1ll<<(n))
template<class T>bool chmax(T&a,const T&b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T&a,const T&b){if(a>b){a=b;return true;}return false;}
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"":"im")<<"possible"<<endl
#define Poss(n) cout<<((n)?"P":"Imp")<<"ossible"<<endl
template<typename T>ostream&operator<<(ostream&o,const vector<T>&v){for(T i:v)o<<i<<' ';return o;}
template<typename T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<typename T>ostream&operator<<(ostream&o,const set<T>&v){for(T i:v)o<<i<<' ';return o;}
template<typename T,typename U>ostream&operator<<(ostream&o,const pair<T,U>&v){o<<v.first<<' '<<v.second;return o;}

class UnionFind{
private:
public:
    vi data;
    UnionFind(int size):data(size,-1){}
    bool unite(int x,int y){
        x=root(x);y=root(y);
        if(x!=y){
            if(data[y]<data[x])swap(x,y);
            data[x]+=data[y];data[y]=x;
        }
        return x!=y;
    }
    bool find(int x,int y){
        return root(x)==root(y);
    }
    int root(int x){
        return data[x]<0?x:data[x]=root(data[x]);
    }
    int size(int x){
        return -data[root(x)];
    }
};

int main(){
    int h,w;
    cin>>h>>w;
    UnionFind uf(h*w);
    vector<string> m(h);
    REP(i,h)cin>>m[i];
    REP(x,w){
        REP(y,h){
            if(x && m[y][x]!=m[y][x-1])uf.unite(y*w+x, y*w+x-1);
            if(y && m[y][x]!=m[y-1][x])uf.unite(y*w+x, y*w+x-w);
        }
    }
    //cerr<<uf.data<<endl;
    map<ll,ll> bl,wh;
    REP(x,w){
        REP(y,h){
            if(m[y][x]=='#')bl[uf.root(y*w+x)]++;
            else wh[uf.root(y*w+x)]++;
        }
    }
    ll ans=0;
    for(P a:bl){
        ans+=a.second*wh[a.first];
    }
    cout<<ans<<endl;
    return 0;
}


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

#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define pb push_back
#define fst first
#define snd second
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

main(){
  string s; cin >> s;
  int c = 0;
  rep(i,s.size()) if(s[i] == 'p') c++;

  cout << s.size() / 2 - c << endl;
}

Measured memory_bytes: 512
import Control.Applicative
import Data.List

main = do hws <- (map read) . (concatMap words) . lines <$> getContents
          putStr . unlines $ map unlines (solve hws)

solve :: [Int] -> [[String]]
solve (h:w:res) | h == 0 && w == 0 = []
                | otherwise = makeBoard 1 h w : solve res

makeBoard :: Int -> Int -> Int -> [String]
makeBoard l h w | l == (h+1) = []
                | l `mod` 2 == 1 = (take w . concat $ repeat "#.") : makeBoard (l+1) h w
                | l `mod` 2 == 0 = (take w . concat $ repeat ".#") : makeBoard (l+1) h w

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



struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
int N = 10000000;
int NN;
//エラトステネスの篩
bool is_prime[ 10000000 + 1 ];
vector<int> P;
void Eratosthenes( const int N )
{
    for( int i = 0; i <= N; i++ )
    {
        is_prime[ i ] = true;//初期化
    }
    for( int i = 2; i <= N; i++ )
    {
        if( is_prime[ i ] )
        {
          if(i >= NN){
            cout << i << endl;
            return;
          }
            for( int j = 2 * i; j <= N; j += i )
            {
                is_prime[ j ] = false;
            }
            P.emplace_back( i );
        }
    }
}

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

}


Measured memory_bytes: 10112
import sys
from heapq import heappush, heappop
#input = sys.stdin.readline

def main():
    s=list(input())
    n=len(s)
    ans=[0]*n
    l,r,a,b,flg=0,0,0,0,0
    for i in range(n):
        if flg==0:
            if s[i]=='L':
                a,b=i-1,i
                flg=1
        else:
            if s[i]=='R':
                flg=0
                r=i-1
                ans[a]=(a-l)//2+(r-a)//2+1
                ans[b]=(b-l)//2+(r-b)//2+1
                l,r,a,b=i,0,0,0
        if i==n-1:
            r=i
            ans[a]=(a-l)//2+(r-a)//2+1
            ans[b]=(b-l)//2+(r-b)//2+1
    print(' '.join(map(str,ans)))

if __name__ == '__main__':
    main()

Measured memory_bytes: 11300
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int main()
{
	int n,i,ans,x;
	scanf("%d",&n);
	ans=0;
	for(i=1;i<=n;i++)
	{
		scanf("%d",&x);
		ans=ans^x;	
	}
	if(ans)
		printf("No");
	else
		printf("Yes");
	return 0;
 } 

Measured memory_bytes: 256
A,B,C,D=map(int,input().split())

def unko(x,C,D):
  import fractions
  t=int(fractions.gcd(C,D))
  t_=C*D//t
  return x-(x//C+x//D-x//t_)
print(int(unko(B,C,D)-unko(A-1,C,D)))
  


Measured memory_bytes: 5044
# Ruby 2.3.7

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


alice = 0
bob = 0

tmp =0
tmp_i = 0

while  1 do
  if as.empty?
    break
  end

  as.each_with_index do |a, i|
    if tmp < a
      tmp = a
      tmp_i = i
    end

  end

  as.delete_at(tmp_i)

  alice += tmp
  tmp = 0

  if as.empty?
    break
  end

  as.each_with_index do |a, i|
    if tmp < a
      tmp = a
      tmp_i = i
    end

  end

  bob += tmp
  tmp = 0
  as.delete_at(tmp_i)

end

puts "#{alice - bob}"





Measured memory_bytes: 1788
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;
typedef unsigned int uint;
typedef long long ll;

#define fori(n) for(ll i=0; i<(n); i++)
#define forn(i, n) for(ll i=0; i<(n); i++)
#define forn3(i, x, n) for(ll i=(x); i<(n); i++)

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
    ll r, D, x;
    cin>>r>>D>>x;

    for(int i=0; i<10; i++) {
        x=r*x-D;
        cout<<x<<endl;
    }

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T>
using vec = std::vector<T>;

int main() {
    int N,M;
    cin >> N >> M;
    vec<int> H(N);
    rep(i,N) cin >> H[i];
    vec<bool> G(N,true);
    rep(i,M){
        int a,b;
        cin >> a >> b;
        --a,--b;
        if(H[a] <= H[b]) G[a] = false;
        if(H[a] >= H[b]) G[b] = false;
    }
    int ans = 0;
    rep(i,N) {
        if(G[i]) ++ans;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3788
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define fore(i,a) for(auto &i:a)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)


using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }


int N, A[10101];
//---------------------------------------------------------------------------------------------------
void _main() {
	while (cin >> N) {
		if (N == 0) return;
		rep(i, 0, N) cin >> A[i];

		int min = 0;
		rep(i, 0, N) min += A[i];

		int answer = 0;
		rep(i, 0, N) if (A[i] * N <= min) answer++;
		printf("%d\n", answer);
	}
}


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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using graph=vector<vector<int>>;

graph T;
vector<int> val;

vector<int> lis,ans;

void dfs(int u,int p){
	auto it=lower_bound(lis.begin(),lis.end(),val[u]);
	int pos,val_pre;
	if(it==lis.end()){
		pos=-1;
		lis.emplace_back(val[u]);
	}
	else{
		pos=it-lis.begin();
		val_pre=lis[pos];
		lis[pos]=val[u];
	}

	ans[u]=lis.size();
	for(int v:T[u]) if(v!=p) dfs(v,u);

	if(pos==-1) lis.pop_back();
	else        lis[pos]=val_pre;
}

int main(){
	int n; scanf("%d",&n);
	T.resize(n);
	val.resize(n);
	rep(u,n) scanf("%d",&val[u]);
	rep(i,n-1){
		int u,v; scanf("%d%d",&u,&v); u--; v--;
		T[u].emplace_back(v);
		T[v].emplace_back(u);
	}

	ans.resize(n);
	dfs(0,-1);

	rep(u,n) printf("%d\n",ans[u]);

	return 0;
}


Measured memory_bytes: 27164
#include <bits/stdc++.h>
using namespace std;
const long long INF=1e18l+5;
int main(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
// #ifndef ONLINE_JUDGE 
//     freopen("input.txt", "r", stdin); 
//     freopen("output.txt", "w", stdout); 
// #endif
   int n,k;
   cin>> n>> k;
   vector<int> weight(n),value(n);
   for (int i=0;i<n;i++){
         //int weight, value;
         cin>> weight[i]>>  value[i];
}
   int sum_value=0;
   for (int i=0;i<n;i++){
      sum_value+=value[i];
   }
   vector <long long> dp(100000+1,INF);
   dp[0]=0;
   //dp[i] = the minimum total weight of items with total value exactly i
   for (int i=0;i<n;i++){
   			for (int val_cu=sum_value - value[i];val_cu>=0;val_cu--){
   			dp[val_cu+value[i]]=min(dp[val_cu+value[i]],dp[val_cu]+weight[i]);
   		}
   }
   long long ans=0;

   for (int i=0;i<=sum_value;i++){
      if(dp[i]<=k){
         ans=max(ans,(long long)i);
      }
   }
   cout<<ans;
	return 0;

}


Measured memory_bytes: 1024
#include <algorithm>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e10;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }
int h;
int score;
void f(int mp[20][5]) {
  int diff[5] = {};
  bool change = true;
  rep(i, h) {
    int tar = INF;
    int s;
    rep(j, 3) if (mp[i][j] != 0 && mp[i][j] == mp[i][j + 1] && mp[i][j + 1] == mp[i][j + 2]) {
      tar = mp[i][j];
      s = j;
      change = false;
      break;
    }
    // cout << tar << ' ' << s << endl;
    if (tar == INF) continue;
    loop(j, s, 5) {
      if (mp[i][j] == tar) {
        score += tar;
        diff[j]++;
        mp[i][j] = 0;
      } else
        break;
    }
  }
  // cout << score << endl;
  rep(l, h) {
    rep(i, 5) {
      for (int j = h - 1; j > 0; j--) {
        if (mp[j][i] == 0) {
          for (int k = j; k > 0; k--) {
            mp[k][i] = mp[k - 1][i];
          }
        }
      }
    }
  }
  rep(i, 5) rep(j, diff[i]) mp[j][i] = 0;
  // cout << endl;
  // rep(i, h) {
  //   rep(j, 5) cout << mp[i][j] << ' ';
  //   cout << endl;
  // }

  if (change) {
    return;
  } else {
    f(mp);
  }
}

signed main() {
  while (cin >> h) {
    if (h == 0) break;
    int mp[20][5] = {};
    score = 0;
    rep(i, h) rep(j, 5) cin >> mp[i][j];

    f(mp);
    cout << score << endl;
  }
  return 0;
}



Measured memory_bytes: 3032
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD 1000000007
 
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template <class T>
void print(T& x){printf("%d\n", x);}
void printvec(vector<int> a){
    rep(i, a.size()-1){
        printf("%d ", a[i]);
    }
    printf("%d\n", a[a.size()-1]);
}
 
int main()
{
    int first=0, second=0, third=0, tmp;
    while(scanf("%d", &tmp)!=EOF){
        if(tmp >= first){
            third = second;
            second = first;
            first = tmp;
        }else if(tmp >= second){
            third = second;
            second = tmp;
        }else if(tmp > third){
            third = tmp;
        }
    }

    printf("%d\n%d\n%d\n", first, second, third);
    return 0;
}


Measured memory_bytes: 3204
#include<stdio.h>
#include<math.h>
#define N 10000

int han(int);

int main(){

  int i,array[N],cnt=0,n;

  scanf("%d",&n);

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

  for(i=0;i<n;i++){
    if(han(array[i])==1)cnt++;
  }

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

  return 0;
}

int han(int a){
  int i;
  double num;

  if(a<2)return 0;
  else if(a==2)return 1;
  else if(a%2==0)return 0;

  num=sqrt(a);

  for(i=3;i<=num;i+=2){
    if(a%i==0) return 0;
  }

  return 1;
}



Measured memory_bytes: 2036
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <utility>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
using namespace std;
#define INF 1000000007
#define LINF 1000000000000000007
#define MOD 1000000007
#define int long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 1
#ifdef MODE
#define DEB(X) cout << #X << ": " << X << " ";
#define ARDEB(i, X) cout << #X << "[" << i << "]: " << X[i] << " ";
#define END cout << endl;
#else
#define DEB(X) \
    {          \
    }
#define ARDEB(i, X) \
    {               \
    }
#define END \
    {       \
    }
#endif
typedef pair<int, int> P;
struct edge{int to,cost;};
typedef long long ll;


signed main()
{
    int n,m;
    pair<int,int> p[111111];
    cin>>n>>m;
    rep(i,m){
        cin>>p[i].first>>p[i].second;
    }
    sort(p,p+m);
    int min=INF,max=0,ans=0;
    rep(i,m){
        min=std::min(min,p[i].second);
        max=std::max(max,p[i].first);
        if(min-max<=0){
            max=p[i].first;
            min=p[i].second;
            ans++;
        }
    }
    if(min-max>0)ans++;
    cout<<ans<<endl;
}


Measured memory_bytes: 1920
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float("INF")

#solve
def solve():
    n, m, s = LI()
    uvab = LIR(m)
    cd = LIR(n)
    dp = [[inf] * 2501 for i in range(n)]
    edg = [[] for i in range(n)]
    for u, v, a, b in uvab:
        edg[u - 1].append((v - 1, a, b))
        edg[v - 1].append((u - 1, a, b))
    for i, (c, d) in enumerate(cd):
        edg[i].append((i, -c, d))
    if s >= 2501:
        s = 2500
    q = [(0, 0, s)]
    dp[0][s] = 0
    time = 0
    while q:
        time, p, score = heappop(q)
        for e, a, b in edg[p]:
            timebuf = time
            if 0 <= score - a <= 2500:
                timebuf += b
                if dp[e][score - a] > timebuf:
                    dp[e][score - a] = timebuf
                    heappush(q, (timebuf, e, score - a))
    
    for i in range(1, n):
        print(min(dp[i]))

    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 101644
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(ll i=a;i>=b;i--)
#define FORL(i,x) for(int i=head[x];i;i=nxt[i])
#define ALL(a)  (a).begin(),(a).end()
#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())
#define PB push_back
#define MP make_pair
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



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

  ll n = s.length();

  ll now = 0;
  ll nownum = 0;

  vector<ll> v;

  FOR(i,0,n-1){
    // cout << nownum << " " << now << " " << s[i] << endl;
    if(now!=1 && s[i]=='<'){
      if(nownum!=0) {
        v.PB(nownum);
      }
      nownum = 0;
      now = 1;
      ++nownum;
    //   cout << "case1" << endl;
    }
    else if(now!=-1 && s[i]=='>'){
      if(nownum!=0){
        v.PB(nownum);
      }
      nownum = 0;
      now = -1;
      --nownum;
    //   cout << "case2" << endl;
    }
    else if(now==1 && s[i]=='<'){
        ++nownum;
        // cout << "case3" << endl;
    }
    else if(now==-1 && s[i]=='>'){
        --nownum;
        // cout << "case4" << endl;
    }
  }

  v.PB(nownum);


  ll sizev = SZ(v);

//   FOR(i,0,sizev-1) cout << v[i] << endl;

//   cout << sizev << endl;

  ll refv = 0;

  ll ans = 0;

  if(sizev!=1){

  while(refv<sizev-1){
    if(refv==0 && v[0]>0){
      FOR(i,0,v[0]) ans += i;
      ++refv;
    //   cout << ans << endl;
      continue;
    }

    FOR(i,0,-v[refv]) ans += i;
    if(refv==0){
    }
    else if(v[refv-1]<-v[refv]) ans -= v[refv-1];
    else ans -= -v[refv];
    FOR(i,0,v[refv+1]) ans += i;

    refv += 2;

    // cout << ans << endl;
  }

  if(v[sizev-1]<0){
    FOR(i,0,-v[sizev-1]) ans += i;
    if(v[sizev-2]<=-v[sizev-1]) ans -= v[sizev-2];
  }

  }

  else{
    FOR(i,0,abs(v[0])) ans += i;
  }



  cout << ans << endl;



}

Measured memory_bytes: 3068
import java.util.Scanner;
import java.util.HashSet;
public class Main {

  public static void main(String[] args) {
    Scanner s = new Scanner(System.in);
    int n = s.nextInt();
    HashSet<Integer> S = new HashSet<Integer>();
    for (int i = 0; i < n; i++) {
      S.add(s.nextInt());
    }
    int q = s.nextInt();
    int[] T = new int[q];
    for (int i = 0; i < q; i++) {
      T[i] = s.nextInt();
    }
    int count = 0;
    for (int t : T) {
      if (S.contains(t))
        count++;
    }
    System.out.println(count);
  }
}



Measured memory_bytes: 40968
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
A = LIST()

def make_divisors(n):
   divisors = []
   for i in range(1, int(n**0.5)+1):
       if n % i == 0:
           divisors.append(i)
           if i != n // i:
               divisors.append(n//i)
   divisors.sort(reverse=True)
   return divisors

for i in make_divisors(sum(A)):
	# print(i)
	r = sorted([x%i for x in A if x%i != 0])
	# print(r)
	if r == []:
		print(i)
		break
	acc = list(accumulate(r))
	for j in range(len(r)-1):  # しきり
		down = acc[j]
		up = i*(len(r)-j-1)-(acc[-1]-acc[j])
		if abs(up-down)%i != 0:
			continue
		else:
			if max(up, down) <= K:
				print(i)
				sys.exit(0)


Measured memory_bytes: 5204
using System;

namespace ConsoleApp3
{
	class Program
	{
		static void Main(string[] args)
		{
			int x = int.Parse(Console.ReadLine());
			for (int i = x; ; i++)
			{
				if (IsPrime(i))
				{
					Console.WriteLine(i);
					return;
				}
			}
		}

		static bool IsPrime(int num)
		{
			if (num == 1)
			{
				return true;
			}
			for (int i = 2; i * i <= num; i++)
			{
				if (num %i == 0)
				{
					return false;
				}
			}
			return true;
		}
	}
}


Measured memory_bytes: 13140
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    A, B = map(int, readline().split())
    def gcd(x, y):
        if not x%y:
            return y
        return gcd(y, x%y)
    
    def factorize(x):
        res = []
        for i in range(2, int(x**0.5)+1):
            if x%i != 0:
                continue
            cnt = 0
            while x%i == 0:
                x //= i
                cnt += 1 
            res.append((i, cnt))
        if x != 1:
            res.append((x, 1))
        return res

    print(len(factorize(gcd(A, B)))+1) 
if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define per(i,n,j) for(int i=(n);i>=(j);i--)
using ll=long long;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a,ll b){return(a%b)?gcd(b,a%b):b;}
ll lcm(ll a,ll b){return(a*b/gcd(a,b));}
const ll INF=1LL<<60;

ll a,b,c,d;

int main(){
    cin>>a>>b>>c>>d;
    ll cnt=b-a+1;;
    cnt-=b/c;
    cnt-=b/d;
    cnt+=(a-1)/c;
    cnt+=(a-1)/d;
    ll num=lcm(c,d);
    cnt+=(b/num);  
    cnt-=(a-1)/num;
    cout<<cnt<<"\n";
    return 0;
}


Measured memory_bytes: 3588
for _ in xrange(input()):
    L = raw_input()
    X,L1 = L[0:1],L[1:].replace("-","")
    for op,c in ((op,c) for op,c in zip(L1[::2],L1[1::2]) if c not in X):
        if op == "<":
            X = c + X
        else:
            X = X + c
    print X

Measured memory_bytes: 4216
n = gets.chomp.to_i
h = gets.chomp.split(' ').map(&:to_i)
h << 10 ** 9 + 1

combo = Array.new(n, 0)
combo.each_with_index do |_, i|
  if h[i] >= h[i + 1]
    combo[i] = 1
    if i > 0
      combo[i] += combo[i - 1]
    end
  end
end

puts combo.max


Measured memory_bytes: 10500
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#define int long long
#define ll getchar();getchar();return 0;
using namespace std;
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n%i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	int ans;
	for (int i = (min(x, y)); i >= 1; i--) {
		if (x%i == 0 && y%i == 0) {
			ans = i;
			break;
		}
	}
	return ans;
}
int yakusuunowa(int n) {
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (n%i == 0)ans += i;
	}
	return ans;
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int ketanowa(int n) {
	int cnt = 0, sum = 0;
	for (int i = 10; i <= n * 10; i *= 10) {
		if (i == 10)cnt += n % i;
		else sum += (n%i - n % (i / 10)) / (i / 10);
	}
	return cnt + sum;
}
signed main() {
	char x, y;
	cin >> x >> y;
	if (x - 'a' < y - 'a')puts("<");
	else if (x - 'a' == y - 'a')puts("=");
	else puts(">");
	ll
}

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

#define gc getchar 
#define pc putchar
#define fRead	freopen("input.txt","r",stdin) 
#define fWrite	freopen ("output.txt","w",stdout)
#define LL              long long
#define PI              acos(-1.0)
#define pb              push_back
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define f              	first
#define s              	second
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define vi              vector <int>
#define vL              vector <LL>

using namespace std;
#define scani2(a,b) scani(a) , scani(b)
#define scani3(a,b,c) scani(a), scani(b), scani(c)
#define scani4(a,b,c,d) scani(a), scani(b), scani(c), scani(d)
#define scani5(a,b,c,d,e) scani(a), scani(b), scani(c), scani(d) , scani(e)
template <typename T> T scani(T &n){n = 0;bool negative = false;char c = gc();while( c < '0' || c > '9'){if(c == '-') negative = true;c = gc();}while(c >= '0' && c <= '9'){n = n*10 + c-48;c = gc();}if(negative) n = ~(n-1);return n;}
template <typename T> void write(T n,int type = true){if(n<0) {pc('-');n = -n;}if(!n) {pc('0');if(type==32) pc(' '); else if(type) pc('\n'); return;}char buff[22];int len = 0;while(n) buff[len++] = n%10+48,n/=10;for(int i=len-1;i>=0;i--) pc(buff[i]);if(type==32) pc(' '); else if(type) pc('\n');}
int scans(char *a){int i=0;char c = 0;while(c < 33) c = gc();while(c > 33){a[i++] = c;c = gc();}a[i] = 0;return i;}
const int MOD = 1e9 + 7;


int main() {
	int n; scani(n);
	int c = n%10;
	n/=100;
	if(n==c){
		printf("Yes\n");
	} else {
		printf("No\n");
	}

	return 0;
}

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

int main() {

	ll n; cin >> n;
	vector<ll> a(n);
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
	}
	ll ans = 0;
	for (ll i = 0; i < n; i++) {
		while (true) {
			if (a[i] % 2 == 0 && a[i] / 2 != 0) {
				ans++;
				a[i] /= 2;
			}
			else {
				break;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3660
use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::str::FromStr;

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

fn main() {
    let MOD: i64 = 1000000007;
    let n:usize = read();
    let m:usize = read();
    let mut dp:Vec<i64> = vec![0;n + 1];
    for i in 0..m{
        let a:usize = read();
        dp[a] = -1;
    }
    dp[0] = 1;
    for i in 1..n + 1{
       if dp[i] != -1 && dp[i - 1] != -1 {
           dp[i] += dp[i - 1];
           dp[i] %= MOD;
       }
           if i > 1  && dp[i] != -1 && dp[i - 2] != -1{
               dp[i] += dp[i - 2];
               dp[i] %= MOD;
           }
    }
    println!("{}",dp[n]);
}

Measured memory_bytes: 2752