akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//---------------------------
using namespace std;
//---------------------------
#define REP(i,n) for(int i = 0; i < (n); i++)
#define P(x) cout << (x) << "\n"
#define fcout cout << fixed << setprecision(18)

#define MOD 1000000007 // 1e9+7
#define PI 3.1415926535
/*
3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
*/
#define ll long long int // 10^18
#define INF 1000000001 // 1e9+1
#define LINF 1000000000000000001 // 1e18+1

int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
//---------------------------
int64_t N,W,sm=0;
int64_t w[200];
int64_t v[200];
vector<int64_t> v1,v2,v3,v4;
int i,j,k,l,con;
int cnt[4];

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

  // ifstream in("input.txt");
  // cin.rdbuf(in.rdbuf());

  cin>>N>>W;

  REP(i,N){
    cin>>w[i]>>v[i];
    if(i==0){
      v1.push_back(v[i]);
    }
    if(i>=1){
      con=w[i]-w[0];
      if(con==0)v1.push_back(v[i]);
      if(con==1)v2.push_back(v[i]);
      if(con==2)v3.push_back(v[i]);
      if(con==3)v4.push_back(v[i]);
    }
  }
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  sort(v3.begin(), v3.end());
  sort(v4.begin(), v4.end());

  reverse(v1.begin(), v1.end());
  reverse(v2.begin(), v2.end());
  reverse(v3.begin(), v3.end());
  reverse(v4.begin(), v4.end());

  for(i=0;i<(int)v1.size();i++){
    if(i+1==(int)v1.size())continue;
    v1[i+1]+=v1[i];
  }
  for(i=0;i<(int)v2.size();i++){
    if(i+1==(int)v2.size())continue;
    v2[i+1]+=v2[i];
  }
  for(i=0;i<(int)v3.size();i++){
    if(i+1==(int)v3.size())continue;
    v3[i+1]+=v3[i];
  }
  for(i=0;i<(int)v4.size();i++){
    if(i+1==(int)v4.size())continue;
    v4[i+1]+=v4[i];
  }
  v1.insert(v1.begin(), 0);
  v2.insert(v2.begin(), 0);
  v3.insert(v3.begin(), 0);
  v4.insert(v4.begin(), 0);

  REP(i, (int)v1.size()){
    REP(j, (int)v2.size()){
      REP(k, (int)v3.size()){
        REP(l, (int)v4.size()){
          if(i*w[0]+j*(w[0]+1)+k*(w[0]+2)+l*(w[0]+3)<=W){
            sm=max(sm, v1[i]+v2[j]+v3[k]+v4[l]);
          }
        }
      }
    }
  }
  cout<<sm<<endl;
  return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

ll N;
vector<ll> A, B;
vector<vector<ll>> dp;

ll f(ll l, ll r) {
    if (dp[l][r] != INF) {
        return dp[l][r];
    }
    if (abs(l - r) == 1) {
        return 0;
    } else if (abs(l - r) == 2) {
        return dp[l][r] = A[l] + A[r - 1];
    }
    ll res = INF;
    for (ll k = l + 1; k < r; k++) {
        res = min(res, f(l, k) + f(k, r) + B[k] - B[l] + B[r] - B[k]);
    }
    return dp[l][r] = res;
}

void solve() {
    cin >> N;
    A.resize(N);
    B.resize(N + 1, 0);
    rep(i, N) cin >> A[i];
    rep(i, N) {
        B[i + 1] += B[i] + A[i];
    }
    dp.resize(N, vector<ll>(N + 1, INF));
    cout << f(0, N) << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 4508
#include<iostream>
//abc054_d
using namespace std;
int dp[401][401][41];
int main() {

	int n, ma, mb;
	cin >> n >> ma >> mb;
	int i, j, k;
	int a[41], b[41], c[41];
	for (i = 1; i <= n; i++) {
		cin >> a[i] >> b[i] >> c[i];
	}


	for (i = 0; i <= 400; i++) {
		for (j = 0; j <= 400; j++) {
			for (k = 0; k <= 41; k++) {
				dp[i][j][k] = 100000000;
			}
		}
	}
	dp[0][0][0] = 0;

	for (k = 1; k <= n; k++) {
		for (i = 0; i <= 400; i++) {
			for (j = 0; j <= 400; j++) {
				dp[i][j][k] = dp[i][j][k - 1];
				if (i - a[k] >= 0 && j - b[k] >= 0) {
					if (dp[i - a[k]][j - b[k]][k - 1] + c[k] < dp[i][j][k]) {
						dp[i][j][k] = dp[i - a[k]][j - b[k]][k - 1] + c[k];
					}
				}
			}
		}
	}

	k = dp[ma][mb][n];
	i = ma;
	j = mb;
	while (i <= 400 && j <= 400) {
		if (dp[i][j][n] < k) {
			k = dp[i][j][n];
		}
		i += ma;
		j += mb;
	}
	if (k == 100000000) {
		cout << -1 << endl;
		return 0;
	}
	cout << k << endl;
	return 0;



}

Measured memory_bytes: 29368
N = int(input())
hs = list(map(int, input().split()))

count = 0
max_h = max(hs)

for h in range(1, max_h+1):
    in_region = False

    #    print("h", h)
    for i in range(N):
        # print(i)
        if h <= hs[i]:
            in_region = True
        else:
            if in_region:
                in_region = False
                count += 1

    if in_region:
        count += 1

print(count)


Measured memory_bytes: 3060
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;

const int TableNum = 5070721;
const int StringLengthMax = 14;
char g_HashTable[TableNum][StringLengthMax];

int ConvertCharToNum(char ch)
{
    if(ch == 'A') return 1;
    else if(ch == 'C') return 2;
    else if(ch == 'G') return 3;
    else if(ch == 'T') return 4;
    else return 0;
}

ll GetKey(char str[])
{
    long long sum = 0; 
    long long p = 1;
    int len = strlen(str);
    for(int i  = 0; i < len; i++)
    {
        sum += p*(ConvertCharToNum(str[i]));
        p *=5;
    }
    return sum;
}

int h1(int key)
{
    return key % TableNum;
}

int h2(int key)
{
    return 1 + (key % (TableNum - 1));
}

int find(char str[])
{
    long long key, i, h;
    key = GetKey(str);
    for(i = 0;;i++)
    {
        h = (h1(key) + i * h2(key)) % TableNum;
        if(strcmp(g_HashTable[h], str) == 0)
        {
            return 1;
        }
        else if (strlen(g_HashTable[h]) == 0)
        {
            return 0;
        }
    }
    return 0;
}

int insert(char str[])
{
    long long key, i, h;
    key = GetKey(str);
    for(i = 0;; i++)
    {
        h = (h1(key) + i * h2(key)) % TableNum;
        if(strcmp(g_HashTable[h], str) == 0)
        {
            return 1;
        }
        else if(strlen(g_HashTable[h]) == 0)
        {
            strcpy(g_HashTable[h], str);
            return 0;
        }
    }
    return 0;
}

int main()
{
    int  n, h;
    char str[StringLengthMax], com[9];
    for(int i = 0;i < TableNum; i++)
    {
        g_HashTable[i][0] = '\0';
    }
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%s %s", com, str);
        if(com[0] == 'i')
        {
            insert(str);
        }
        else
        {
            if(find(str))
            {
                printf("yes\n");
            }
            else
            {
                printf("no\n");
            }
            
        }
    }
    return 0;
}


Measured memory_bytes: 71996
N = int(input())
S = input()

#i文字目以降のRGBの数
RGB = [[0]*(N+1) for i in range(3)]
for i in range(N-1,-1,-1):
    if S[i] == "R":
        RGB[0][i] = RGB[0][i+1]+1
        RGB[1][i] = RGB[1][i+1]
        RGB[2][i] = RGB[2][i+1]
    elif S[i] == "G":
        RGB[0][i] = RGB[0][i+1]
        RGB[1][i] = RGB[1][i+1]+1
        RGB[2][i] = RGB[2][i+1]
    else:
        RGB[0][i] = RGB[0][i+1]
        RGB[1][i] = RGB[1][i+1]
        RGB[2][i] = RGB[2][i+1]+1

ans = 0
for i in range(N-2):
    for j in range(i+1,N-1):
        if (S[i] == "R" and S[j] == "G") or (S[i] == "G" and S[j] == "R"):
            ans += RGB[2][j]
            if j+(j-i) < N and S[j+(j-i)] == "B":
                ans -= 1
        elif (S[i] == "G" and S[j] == "B") or (S[i] == "B" and S[j] == "G"):
            ans += RGB[0][j]
            if j+(j-i) < N and S[j+(j-i)] == "R":
                ans -= 1
        elif (S[i] == "R" and S[j] == "B") or (S[i] == "B" and S[j] == "R"):
            ans += RGB[1][j]
            if j+(j-i) < N and S[j+(j-i)] == "G":
                ans -= 1
print(ans)


Measured memory_bytes: 68900
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)
#define toupper(S) transform(S.begin(),S.end(),S.begin(),toupper)
#define tolower(S) transform(S.begin(),S.end(),S.begin(),tolower)
const lint MOD = pow(10, 9) + 7;


int main() {
	int N, R;
	cin >> N >> R;
	if (N >= 10) {
		cout << R << endl;
	}
	else {
		cout << R + 100 * (10 - N) << endl;
	}
}

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

const int MAX = 1000000;
bool ifnprime[MAX+1];

void set(){
    ifnprime[0] = ifnprime[1] = true;
    for(int i = 2; i*i <= MAX; i++){
        if( !ifnprime[i] ){
            int j = i*i;
            while( j <= MAX ){
                ifnprime[j] = true;
                j += i;
            }
        }
    }
}


int main(){
    set();
    int a, d, n;
    while( cin>>a>>d>>n, a||d||n ){
        int c=0,m=a-d;
        while(c<n){
            m += d;
            if(!ifnprime[m]) c++;
        }
        cout << m << endl;
    }
    return 0;
}

Measured memory_bytes: 2136
import itertools

def solve():
    N = int(input())
    P = tuple(map(int, input().split()))
    Q = tuple(map(int, input().split()))
    l = [i for i in range(1, N+1)]
    p = tuple(itertools.permutations(l))
    P_index = p.index(P)
    Q_index = p.index(Q)
    print(abs(Q_index - P_index))


if __name__ == "__main__":
    solve()

Measured memory_bytes: 69668
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
using namespace std;
long long int mod = 1e9 + 7;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<long long int> x(k, 0);
  for(int i=1; i<=n; i++) x[i%k]++;

  long long int cnt = 0;
  cnt += x[0]*x[0]*x[0];
  if (k%2 == 0){
    cnt += x[k/2]*x[k/2]*x[k/2];
  }
  cout << cnt << endl;


  return 0;
}




//


Measured memory_bytes: 1792
import sys
N,K = [int(n) for n in input().split()]
D = set([str(n) for n in input().split()])
# OK = sorted(list(set([0,1,2,3,4,5,6,7,8,9]) - D))
for i in range(N,100001):
    stri = set(list(str(i)))
    find = True
    for d in D:
        if d in stri:
            find = False
            break
    if find:
        print(i)
        sys.exit()


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

int main()
{
    int K, X;
    cin >> K >> X;

    int lb = X - K + 1;
    int ub = X + K - 1;

    cout << lb;
    for (int i = lb+1; i <= ub; ++i) {
        cout << ' ' << i;
    }
    cout << endl;

    return 0;
}



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

int main() {
  int w, h, n;
  cin >> w >> h >> n;

  int max_x = w, min_x = 0;
  int max_y = h, min_y = 0;
  int x = 0, y = 0, a = 0;
  for (int i=0; i<n; i++) {
    cin >> x >> y >> a;
    if (a == 1) {
      if (x > min_x) min_x = x;
    }
    if (a == 2) {
      if (max_x > x) max_x = x;
    }
    if (a == 3) {
      if (y > min_y) min_y = y;
    }
    if (a == 4) {
      if (max_y > y) max_y = y;
    }
  }

  int ans = 0;
  if (max_x > min_x && max_y > min_y) ans = (max_x - min_x) * (max_y - min_y);
  cout << ans << endl;
}

Measured memory_bytes: 504
#include<cstdio>
 
char c,a[5]={'a','e','i','o','u'};
 
int main(void){
	register int i;
	c=getchar();
	for(i=0;i<5;++i)
		if(c==a[i])
			return puts("vowel"),0;
	puts("consonant");
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int count = 0;
  for(int i = 0; i < n-2; i++) {
    if(s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
N, K, Q = map(int, input().split())
list = [int(input()) for i in range(Q)]
p_list = []
for i in range(N):
    p_list.append(0)
for i in list:
    p_list[i-1] += 1
for i in p_list:
    if K - (Q - i) > 0:
        print("Yes")
    else:
        print("No")



Measured memory_bytes: 8592
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,l;
    cin>>n>>l;
    string s[n];
    for(int i=0;i<n;i++)
        cin>>s[i];

    sort(s,s+n);
    for(int i=0;i<n;i++)
        cout<<s[i];

    return 0;
}


Measured memory_bytes: 3584
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions
import itertools
import copy
import collections
from operator import itemgetter
#以下てんぷら
def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
#n = ip()                                     #入力整数1つ
#n,k= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
n = ip()                      #入力セット(整数改行あり)(1/2)
a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
#こっから本文
s = a[0]
for i in range(1,n):
    s = lcm(s,a[i])
print(s)

Measured memory_bytes: 13612
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int K = scanner.nextInt();

        String S = scanner.next();
        char[] ch = S.toCharArray();
        Character chatk = ch[K-1];
        ch[K-1] = Character.toLowerCase(chatk);

        System.out.println(String.valueOf(ch));
    }
}

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

int a[1010][1010], lfr[1010];

int main() {
	int N;
	cin >> N;
	for(int i=1; i<=N; ++i){
		for(int j=0; j<N-1; ++j) cin >> a[i][j];
	}
	vector<int> cand(N);
	for(int i=0; i<N; ++i) cand[i]=i+1;
	int ans=0, fin=0;
	vector<bool> psd(N+1, 0);
	while(fin<N){
		vector<int> nx;
		for(int i=0; i<cand.size(); ++i){
			int s=a[cand[i]][lfr[cand[i]]];
			if(a[s][lfr[s]]==cand[i]){
				if(!psd[cand[i]]){
					nx.push_back(cand[i]);
					psd[cand[i]]=1;
				}
				if(!psd[s]){
					nx.push_back(s);
					psd[s]=1;
				}
			}
		}
		if(nx.size()<1){
			cout << -1 << endl;
			return 0;
		}
		for(int i=0; i<nx.size(); ++i){
			++lfr[nx[i]];
			if(lfr[nx[i]]==N-1) ++fin;
			psd[nx[i]]=0;
		}
		nx.swap(cand);
		++ans;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4224
h, w = map(int, input().split())

ds = []

for i in range(1, h):
  s1 = w*i
  s2 = (h-i)*(w//2)
  s3 = (h-i)*(w-w//2)
  d1 = max(s1, s2, s3) - min(s1, s2, s3)
  
  s1 = w*i
  s2 = w*((h-i)//2)
  s3 = w*(h-(h-i)//2-i)
  d2 = max(s1, s2, s3) - min(s1, s2, s3)
  
  if i == h-1:
    d = d1
  else:
    d = min(d1, d2)
  ds.append(d)

for i in range(1, w):
  s1 = h*i
  s2 = (w-i)*(h//2)
  s3 = (w-i)*(h-h//2)
  d1 = max(s1, s2, s3) - min(s1, s2, s3)
  
  s1 = h*i
  s2 = h*((w-i)//2)
  s3 = h*(w-(w-i)//2-i)
  d2 = max(s1, s2, s3) - min(s1, s2, s3)
  
  if i == w-1:
    d = d1
  else:
    d = min(d1, d2)
  ds.append(d)
  
print(min(ds))



Measured memory_bytes: 51436
#pragma target("avx")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;
using V = std::vector<ll>;
template<typename T> using pq = std::priority_queue<T>;
template<typename T> using rpq = std::priority_queue<T, std::vector<T>, std::greater<T>>;

#define rep(i,b,e) for(ll i=b; i<e; i++)
#define be(vec) vec.begin(),vec.end()
#define print(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define scan(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second

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

int main(){
	int n;
	scanf("%d", &n);
	V a(n), b(n);
	rep(i, 1, n+1) scanf("%ld %ld", &a[n-i], &b[n-i]);
	ll ans = 0;
	rep(i, 0, n){
		a[i] += ans;
		ans += (b[i] - a[i]%b[i]) % b[i];
	}
	printf("%ld\n", ans);
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<string> vs;
ll llmax = LLONG_MAX;
vll d1 = {1, 0, -1, 0}, d2 = {0, 1, 0, -1};
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}
void sortll(vll &a) {sort(a.begin(), a.end());}
void sortc(string &a) {sort(a.begin(), a.end());}
void sorts(vs &a) {sort(a.begin(), a.end());}

int main() {
  ll n;
  cin >> n;
  vs s(n);
  for (ll i = 0; i < n; i++) cin >> s[i];
  sorts(s);
  vector<pair<ll, string>> vp(0);
  for (ll i = 0; i < n; i++) {
    string t = s[i];
    ll cnt = 0;
    while (i < n && t == s[i]) {
      cnt++;
      i++;
    }
    i--;
    vp.push_back(make_pair(cnt, t));
  }
  sort(vp.begin(), vp.end());
  vs ans(0);
  ll m = vp.size() - 1;
  while (m >= 0 && vp[vp.size() - 1].first == vp[m].first) {
    ans.push_back(vp[m].second);
    m--;
  }
  for (ll i = 0; i < ans.size(); i++) {
    cout << ans[ans.size() - 1 - i] << endl;
  }
}

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

typedef struct Node{
  int value;
  Node *parent, *left, *right;
} Node;

Node *NIL, *root;

void insert(int k){
  Node *y = NIL, *x = root, *z;

  z = (Node *)malloc(sizeof(Node));
  z->value = k;
  z->left = z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->value < x->value) x = x->left;
    else x = x->right;
  }
  z->parent = y;

  if(y == NIL) root = z;
  else if(z->value < y->value) y->left = z;
  else y->right = z;
}

Node* find(Node *x, int k){
  if(x == NIL || x->value == k) return x;

  if(k < x->value) return find(x->left, k);
  else return find(x->right, k);
}

Node* treeMinimum(Node *x){
  //search the minimum value of the tree
  while(x->left != NIL) x = x->left;
  return x;
}

Node* treeSuccessor(Node *x){
  Node *y;
  //search the node that has smallest value larger than x's value
  if(x->right != NIL) return treeMinimum(x->right);
  y = x->parent;
  
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void Delete(Node *z){
  Node *x, *y;//

  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z); //if node z has two children, search the successor

  if(y->left != NIL) x = y->left; //if node y has left child, node x is y's left child
  else x = y->right; //if node y doesn't have left child, node x is y's right child

  if(x != NIL) x->parent = y->parent; //x's parent

  if(y == NIL) root = x; //if y is root, x is root
  else if(y == y->parent->left) y->parent->left = x; //if y is a left child of y's parent, parent's left child is x
  else y->parent->right = x; //if y is a right child of y's parent, parent's right child is x

  if(y != z) z->value = y->value; //assign y's value to z's value
}

void preParse(Node *node){
  if(node == NIL) return ;

  cout << " " << node->value;
  if(node->left != NIL) preParse(node->left);
  if(node->right != NIL) preParse(node->right);
}

void inParse(Node *node){
  if(node == NIL) return ;

  if(node->left != NIL) inParse(node->left);
  cout << " " << node->value;
  if(node->right != NIL) inParse(node->right);
}

int main(){

  int n, key;
  string command;

  //input
  cin >> n;
  for(int i = 0;i < n;i++){
    cin >> command;
    if(command == "insert"){
      cin >> key;
      insert(key);
    }else if(command == "print"){
      inParse(root);
      cout << endl;
      preParse(root);
      cout << endl;
    }else if(command == "find"){
      cin >> key;
      if(find(root, key)) cout << "yes" << endl;
      else cout << "no" << endl;
    }else if(command == "delete"){
      cin >> key;
      Delete(find(root, key));
    }
  }

  return 0;
}




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

const int INF = 1e9;

int main() {
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> C(N);
    vector<vector<int>> A(N, vector<int>(M));
    for(int i = 0; i < N; ++i) {
        cin >> C[i];
        for(int j = 0; j < M; ++j) cin >> A[i][j];
    }
    int ans = INF;
    for(int bit = 0; bit < (1 << N); ++bit) [&]() {
        bitset<20> bs(bit);
        int cost = 0;
        vector<int> al(M);
        for(int i = 0; i < N; ++i) {
            if(bs[i]) {
                cost += C[i];
                for(int j = 0; j < M; ++j) al[j] += A[i][j];
            }
        }
        for(int j = 0; j < M; ++j) {
            if(X > al[j]) return;
        }
        ans = min(ans, cost);
    }();
    if(ans == INF) ans = -1;
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;
struct edge {int from,to,cost;};

signed main() {
int n;
cin>>n;
double a[n];
for(int i=0;i<n;i++)cin>>a[i];
double p=0;
for(int i=0;i<n;i++)p+=double(1)/a[i];
cout<< std::setprecision(20)<<double(1)/p;
return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define forn(i, a, n) for(ll i = a; i < n; i++)

#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<iomanip>
#include<cassert>
#include<stack>
#include<deque>
#include<list>
#include<sstream>
#include<unordered_map>
#include<time.h>
#include<functional>
#pragma comment(linker, "/STACK:8809999999")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef pair<ld, ld> pld;
typedef pair<ll, pll> pllp;
typedef pair<pll, ll> ppll;
typedef pair<pll, pll> ppp;
typedef vector<vector<vector<ll>>> vvv;
const ll mod = 1e9 + 7;
const ll atcmod = 998244353;
const ld eps = 1e-9;
const ll settled = 400007;


vector<pll> pe;
ll globe;

ll pussy_hacker(ll m, ll i)
{
	ll ans = 0;
	forn(j, 0, pe[i].second + 1)
	{
		if (i + 1 < pe.size())
			ans += pussy_hacker(m, i + 1);
		else
			if (m > 1 && (m - 1) > globe / (m - 1))
				ans += m - 1;
		m *= pe[i].first;
	}

	return ans;
}

int main()
{
	ios_base::sync_with_stdio(false); cout.tie(NULL);
#ifndef overlord
	/*freopen("capitals.in", "r", stdin);
	freopen("capitals.out", "w", stdout);*/
#else
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll n;
	cin >> n;
	globe = n;
	if (n == 1)
	{
		cout << 0;
		return 0;
	}

	forn(i, 2, (ll)sqrt((ld)n) + 1)
	{
		if (n % i == 0)
		{
			pe.push_back({ i, 0 });
			while (n % i == 0)
			{
				pe.back().second++;
				n /= i;
			}
		}
		
		if (n == 1)
			break;
	}

	if (n > 1)
		pe.push_back({ n, 1 });

	cout << pussy_hacker(1, 0);
	return 0;
}

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

using namespace std;

int main() {
  array<array<int, 3>, 3> row;
  for (int i = 0; i < 3; i++) {
    array<int, 3> column;
    int a1, a2, a3;
    scanf("%d %d %d", &a1, &a2, &a3);
    column[0] = a1;
    column[1] = a2;
    column[2] = a3;
    row[i] = column;
  }
  int n;
  scanf("%d", &n);
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    int b;
    scanf("%d", &b);
    v[i] = b;
  }
  
  bool bingo = false;
  if ((find(v.begin(), v.end(), row[0][0]) != v.end() &&
       find(v.begin(), v.end(), row[0][1]) != v.end() &&
       find(v.begin(), v.end(), row[0][2]) != v.end()) ||
      (find(v.begin(), v.end(), row[0][0]) != v.end() &&
       find(v.begin(), v.end(), row[1][0]) != v.end() &&
       find(v.begin(), v.end(), row[2][0]) != v.end()) ||
      (find(v.begin(), v.end(), row[2][0]) != v.end() &&
       find(v.begin(), v.end(), row[2][1]) != v.end() &&
       find(v.begin(), v.end(), row[2][2]) != v.end()) ||
      (find(v.begin(), v.end(), row[0][2]) != v.end() &&
       find(v.begin(), v.end(), row[1][2]) != v.end() &&
       find(v.begin(), v.end(), row[2][2]) != v.end()) ||
      (find(v.begin(), v.end(), row[0][0]) != v.end() &&
       find(v.begin(), v.end(), row[1][1]) != v.end() &&
       find(v.begin(), v.end(), row[2][2]) != v.end()) ||
      (find(v.begin(), v.end(), row[0][2]) != v.end() &&
       find(v.begin(), v.end(), row[1][1]) != v.end() &&
       find(v.begin(), v.end(), row[2][0]) != v.end()) ||
      (find(v.begin(), v.end(), row[1][0]) != v.end() &&
       find(v.begin(), v.end(), row[1][1]) != v.end() &&
       find(v.begin(), v.end(), row[1][2]) != v.end()) ||
      (find(v.begin(), v.end(), row[0][1]) != v.end() &&
       find(v.begin(), v.end(), row[1][1]) != v.end() &&
       find(v.begin(), v.end(), row[2][1]) != v.end())) {
    bingo = true;
  }
  
  cout << (bingo ? "Yes": "No") << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

int main(int argc, char const *argv[])
{
	int n; cin >> n;
	string s; cin >> s;
	int cntr = 0, cntb = 0;
	for (auto u : s)	{
		((u == 'R') ? cntr : cntb) += 1;
	}
	if (cntr > cntb) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
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 all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long int ll;
typedef long double ld;
const ll INF=(1LL<<62);
const ld pi=acosl((ld)-1);
// const ll mod = 1000000007;
const ll mod = 1234567;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
#define endn "\n"

bool solve(){
    ll n;cin>>n;
    vector<ll>A(n+1);
    vector<ll>B(n);
    rep(i,n+1)cin>>A[i];
    rep(i,n)cin>>B[i];
    ll ans=0;
    rep(i,n){ 
        if(A[i]>B[i]){
            ans+=B[i];
        }else{
            ans+=A[i];
            B[i]-=A[i];
            ll num=max((ll)0,A[i+1]-B[i]);
            ans+=A[i+1]-num;
            A[i+1]=num;
        }
        
    }
    cout<<ans<<endl;
    return false;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout<<fixed<<setprecision(30);
    solve();
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int n;
int t[100001],x[100001],y[100001];
int i=0;
int main(void){scanf("%d",&n);for(;i<n;i++){scanf("%d %d %d",&t[i],&x[i],&y[i]);if(abs(x[i])+abs(y[i])>t[i]||(x[i]+y[i])%2!=t[i]%2){printf("No");break;}}if(i==n){printf("Yes");}return 0;}

Measured memory_bytes: 1280
N, K = map(int, input().split())
mod = 10**9+7

ans = 0

for i in range(K, N+2):
	l = (i - 1) * i // 2
	r = (2 * N - i + 1) * i // 2
	ans += r - l + 1
	ans %= mod

print(ans)

Measured memory_bytes: 8888
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();

        if(a == 0) {
            System.out.println(1);
        }
        else{
            System.out.print(0);
        }
    }
}

Measured memory_bytes: 35568
//Author: Fuadul Hasan(fuadul202@gmail.com)
#include<bits/stdc++.h>
using namespace std;

#define ll long long
const int N   = 2e5 + 5;

int main(){
	
	int n,m;
	cin>>n>>m;
	if(((m/4)+(m%4)/2)>n||m%2){
		cout<<"No"<<endl;
	}else if(n*2>m){
		cout<<"No"<<endl;
	}else{
		cout<<"Yes"<<endl;
	}


	

	return 0;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<ll> a(n);
	ll sum = 0, mi = 1e18;
	int cnt = 0, id = -1;
	bool zero = false;
	rep(i,n){
		cin >> a[i];
		sum += abs(a[i]);
		if(mi > abs(a[i])){
			id = i;
			mi = abs(a[i]);
		}
		if(a[i] < 0) cnt++;
		if(a[i] == 0) zero = true;
	}
	if(cnt%2 == 1 && !zero) sum -= 2*mi;
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 1024
from collections import Counter

N, P = map(int, input().split())
S = input()

def check(n):
    ans = 0
    for i in range(1, N+1):
        v = int(S[-i])
        if v%n==0:
            ans += N-(i-1)
    return ans

ans = 0
if P==2:
    ans = check(2)
elif P==5:
    ans = check(5)
else:
    ac = [0]*(N+1)
    for i in range(1, N+1):
        ac[i] = (ac[i-1]+int(S[-i])*pow(10, i-1, P))%P
    c = Counter(ac)
    for i in c.values():
        ans += i*(i-1)//2

print(ans)

Measured memory_bytes: 43852
#include <bits/stdc++.h>
#define rep(i, n) for (ll 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;
    cin >> N;
    unordered_map<ll,ll> mp;
    for(int x=1;x<=N;++x)for(int y=1;y<=N;++y){
        ll a = x*x + y*y;
        ll b = x*y;
        if(a+b>N) continue;
        for(int z=1;z<=N;++z){
            ll c = z*z;
            ll d = (x+y)*z;
            if(a+b+c+d > N) break;
            ++mp[a+b+c+d];
        }
    }

    for(int i=1;i<=N;++i){
        cout << mp[i] << endl;
    }
}


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

bool search(int);

int q,T[500];

int main(){

  int n,S[10000],counter=0;

  cin >>n;
  for(int i=0 ; i < n ; i++)cin >>S[i];

  cin >>q;
  for(int i=0 ; i < q ; i++)cin >>T[i];

  for(int i=0 ; i < n ; i++)counter+=search(S[i]);

  cout <<counter<<endl;

  return 0;
}

bool search(int s){

  for(int i=0 ; i < q ; i++){
    if( s == T[i] ){
      T[i]=-1;
      return 1;
    }
  }
  
  return 0;

}

Measured memory_bytes: 1200
'use strict'

const main = (INPUT) => {
  const input = INPUT.split('\n')
  const [N, K] = input[0].split(' ').map(n => Number(n))
  const h = input[1].split(' ').map(n => Number(n))
  let ans = 0
  for (let i = 0; i < h.length; i++) {
    if (h[i] >= K) {
      ans++
    }
  }
  console.log(ans)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 36924
mod = 10**9+7
def power(a,n):
  ans = 1
  while n:
    if n%2:
      ans = (ans*a)%mod
    a = (a*a)%mod
    n >>= 1
  return ans%mod 
n = int(input())
a = list(map(int,input().split()))
x = [0 for _ in range(n)]
for ai in a:
  x[ai] += 1
if n%2 == 0:
  if sum(x[0::2]) != 0:
    print(0)
    exit()
  for i in range(1,n,2):
    if x[i] != 2:
      print(0)
      exit()
  print(power(2,n//2))
else:
  if sum(x[1::2]) != 0:
    print(0)
    exit()
  if x[0] != 1:
    print(0)
    exit()
  if n == 1:
    print(1)
    exit()
  for i in range(2,n,2):
    if x[i] != 2:
      print(0)
      exit()
  print(power(2,(n-1)//2))



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

using namespace std;

const int size = 2e5 + 7;
long long int dp[2][size];
int mod = 1e9 + 7;  	
vector<int> graph[size];

long long int solve(int flag, int parent, int u){
	if(dp[flag][u] != -1) return dp[flag][u];
	long long int ans = 1, l =1, r = 1;
	bool hasChild = false;
	for(int v: graph[u]){
		if(v == parent) continue;
		hasChild = true;
		if(flag == 0){
			ans *= (solve(1, u, v) + solve(0, u, v))%mod;
		}
		else{
			ans *= solve(0, u, v)%mod;
		}
		ans %= mod;
	}
	if(!hasChild) return 1;
	// if(flag == 0) ans += r;
	dp[flag][u] = ans;
	return ans;
}

int main(){
	int n;
	cin>>n;
	for(int x=0;x<n-1;x++){
		int u, v;
		cin>>u>>v;
		graph[u].push_back(v);
		graph[v].push_back(u);
	}
	int  root = 1;
	for(int x=1;x<=n;x++){
		if(graph[x].size() == 1) root = x;
	}
	for(int x=0;x<size;x++) dp[0][x] = dp[1][x] = -1;
	// cout<<root<<"\n";
	cout<<(solve(0,-1,root) + solve(1,-1,root))%mod;
	// cout<<<<"\n";
	return 0;
}

Measured memory_bytes: 20608
#include<cstdio>
#include<algorithm>
using namespace std;
int a,b,k;
int main()
{
	scanf("%d%d%d",&a,&b,&k);
	if(k>(b-a+1)/2)
	{
		for(int i=a;i<=b;i++)
			printf("%d\n",i);
	}
	else
	{
		for(int i=a;i<=a+k-1;i++)
			printf("%d\n",i);
		for(int i=b-k+1;i<=b;i++)
			printf("%d\n",i);
	}
	return 0;
}
/*
1 9 4
*/

Measured memory_bytes: 128
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


n, m, k = map(int, input().split())
friends = {}
blocks = {}
for i in range(n):
    friends[i] = 0
    blocks[i] = 0
uf_friends = UnionFind(n)
for i in range(m):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    friends[x] += 1
    friends[y] += 1
    uf_friends.union(x, y)

for i in range(k):
    x, y = map(int, input().split())
    x -= 1
    y -= 1
    if (uf_friends.same(x, y)):
        blocks[x] += 1
        blocks[y] += 1

ans = []
for i in range(n):
    ans.append(str(uf_friends.size(i) - friends[i] - blocks[i] - 1))

print(' '.join(ans))


Measured memory_bytes: 116060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define pb(a) push_back(a)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

typedef long long unsigned int ll;
typedef pair<ll, ll> P;

int main(){
  int n;
  cin >> n;
  int w[n];
  int sum = 0;
  REP(i,n){
    cin >> w[i];
    sum += w[i];
  }
  int s1=0,s2=0;
  int res;
  REP(i,n){
    s1 += w[i];
    if(s1>=sum/2){
      res = min(abs(sum-s1-s1),abs((sum-s1+w[i])-(s1-w[i])));
      cout << res << endl;
      break;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int x;cin>>x;
  long long int ans=x/11;
  int z=x%11;

  if(z==0){cout<<2*ans<<endl;}
  else if(z<=6){cout<<2*ans+1<<endl;}
  else{cout<<2*ans+2<<endl;}
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long double ldouble;
const ldouble eps = 0.000000001;
bool eq(ldouble a,ldouble b){return (-eps<a-b && a-b<eps);}

struct Point{
  ldouble x,y;
  Point operator + (const Point p)const{
    return (Point){x+p.x,y+p.y};
  }
  Point operator - (const Point p)const{
    return (Point){x-p.x,y-p.y};
  }
  Point operator * (const ldouble r)const{
    return (Point){x*r,y*r};
  }
};
bool eq(Point a,Point b){return ( eq(a.x,b.x) && eq(a.y,b.y) );}
 
typedef Point Vector;

ldouble dot(Vector a,Vector b){return a.x*b.x+a.y*b.y;}
ldouble cross(Vector a,Vector b){return a.x*b.y-b.x*a.y;}
ldouble norm(Vector v){return dot(v,v);}
ldouble abs(Vector v){return sqrt(norm(v));}
 
 
Point project(Point a,Point b,Point p){
  Point base=b-a;
  ldouble r=dot(p-a,base)/norm(base);
  return a+base*r;
}

int n;
ldouble A,B;
vector<Point> t;
Point s,g;
ldouble ans;
 
ldouble func0(double H,double W){
  ldouble a=1.0;
  ldouble b=-2.0*W;
  ldouble c=W*W-(A*A*H*H)/(B*B-A*A);
  if(b*b-4.0*a*c<0)return min(H*B+W*A, sqrt(H*H+W*W)*B);
  ldouble t = (-b+sqrt(b*b-4.0*a*c))/(2.0*a);
  if(t>W){
    t=(-b-sqrt(b*b-4.0*a*c))/(2.0*a);
    if(t<0)return 0;
  }
  return t;
}
ldouble func02(Point a,Point b,Point g){
  Point D=project(a,b,g);
  return func0( abs(g-D) , abs(a-D) );
}
ldouble func(ldouble H,ldouble W){
  ldouble t=func0(H,W);
  ldouble ff = t*A+B*sqrt((W-t)*(W-t)+H*H );
  return ff;
} 
ldouble func2(Point a,Point b,Point g){
  Point D=project(a,b,g);
  return func( abs(g-D) , abs(a-D) );
}
 
void solve(){
  vector<Point> T;
  for(int i=0;i<n;i++){
    T.push_back(t[i]);
    if(i+1<n){
      ldouble tt = func02(t[i],t[i+1],g);
      Vector base=t[i+1]-t[i];      
      Point next =  t[i]+ base*( tt /abs(base) );
      if(!eq(next,t[i])&&!eq(next,t[i+1])
         && eq(abs(t[i]-next)+abs(t[i+1]-next),abs(t[i]-t[i+1]))
         )T.push_back(next);
    }
  }
   
  t=T;
  n=t.size();
  vector<ldouble> u(n);  
  u[0]=0;
  u[1]=abs(t[0]-t[1])*A;
  for(int i=2;i<n;i++){
    u[i]=u[i-1]+abs(t[i]-t[i-1])*A;
    for(int j=1;j<i;j++){
      u[i]=min(u[i],u[j-1]+func2(t[j-1],t[j],t[i]));
      u[i]=min(u[i],u[j-1]+func2(t[i],t[i-1],t[j-1]));
    }
  }
  for(int i=0;i+1<n;i++){
    ldouble na = u[i]+func2(t[i],t[i+1],g);
    ans=min(ans,na);
  }
}
 
int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  while(1){
    vector<Point> nt;
    cin>>n;
    if(n==0)break;
    t.clear();t.resize(n);
    for(int i=0;i<n;i++)cin>>t[i].x>>t[i].y;
    cin>>A>>B>>s.x>>s.y>>g.x>>g.y;
    int flg=0,f=-1;
    for(int i=0;i<n;i++){
      int j=(i+1)%n;      
      if(eq(s,t[i]))flg=1;
      if(eq( abs(s-t[i])+abs(s-t[j]) , abs(t[i]-t[j]) )){
        f=j;
        break;
      }
    }
    if(flg==0)nt.push_back(s);
    else f=(f+n-1)%n;
    for(int j=0;j<n;j++)nt.push_back(t[(f+j)%n]);
    n=nt.size();
    t=nt;
    ans=abs(s-g)*B;
    solve();
    reverse(t.begin()+1,t.end());
    solve();
    double ans2=ans;
    printf("%.14f\n",ans2);
  }
  return 0;
}

Measured memory_bytes: 1312
#include<bits/stdc++.h>
#define sf(x) scanf("%d",&x);
#define pf(x); printf("%d\n",x);
using namespace std;
int main()
{
   int a,i;
  cin>>a;
  string s,t;
  cin>>s>>t;
 for(i=0;i<a;i++)
 {
     cout<<s[i]<<t[i];
 }
  return 0;
}

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

const int N = 1e6+5 , inf = 1e9+5;

int n , k , A[N] , dp[N];

main(){
  cin >> n >> k;
  for(int i = 0 ; i < N ; i++) dp[i] = inf;
  for(int i = 1 ; i <= n ; i++) cin >> A[i];
  dp[1] = 0;
  for(int i = 1 ; i <= n ; i++)
    for(int j = 1 ; j <= k ; j++)
      dp[i+j] = min(dp[i+j],dp[i]+abs(A[i]-A[i+j]));
  cout << dp[n] << "\n";
}

Measured memory_bytes: 6400
#include<cstdio>
#include<string>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<map>
#include<queue>
#define For(i,j,k) for(ll i=j;i<=k;++i)
#define Dow(i,j,k) for(ll i=k;i>=j;--i)
#define ll long long
#define inf 1e17
using namespace std;
inline ll read()
{
	ll t=0,f=1;char c=getchar();
	while(c<'0'||c>'9')	{if(c=='-')	f=-1;c=getchar();}
	while(c<='9'&&c>='0')	t=t*10LL+c-48LL,c=getchar();
	return t*f;
}
int n,x,ans;
map<int,int> mp;
int main()
{
	n=read();
	For(i,1,n)
	{
		x=read();
		if(mp[x])	mp[x]=0,ans--;else mp[x]=1,ans++;
	}
	cout<<ans<<endl;
} 

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

int main(){
  string s;
  int a, b, c, d;
  cin >> s;
  a = s[0] - '0'; b = s[1] - '0'; c = s[2] - '0'; d = s[3] - '0';
  if(a + b + c + d == 7) printf("%d+%d+%d+%d=7\n", a, b, c, d);
  else if(a - b + c + d == 7) printf("%d-%d+%d+%d=7\n", a, b, c, d);
  else if(a + b - c + d == 7) printf("%d+%d-%d+%d=7\n", a, b, c, d);
  else if(a + b + c - d == 7) printf("%d+%d+%d-%d=7\n", a, b, c, d);
  else if(a - b - c + d == 7) printf("%d-%d-%d+%d=7\n", a, b, c, d);
  else if(a + b - c - d == 7) printf("%d+%d-%d-%d=7\n", a, b, c, d);
  else if(a - b + c - d == 7) printf("%d-%d+%d-%d=7\n", a, b, c, d);
  else if(a - b - c - d == 7) printf("%d-%d-%d-%d=7\n", a, b, c, d);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAXN 2010
ll C[MAXN][MAXN];
const ll mod = 1e9+7;
void init(){
	C[0][0] = 1;
	C[1][0] = 1;
	C[1][1] = 1;
	for(int i=2; i<MAXN; ++i){
		C[i][0] = 1;
		for(int j=1; j<MAXN; ++j)
			C[i][j] = (C[i-1][j] + C[i-1][j-1])%mod;
	}
}

int main(){
	init();
	ll n, b, r;
	cin >> n >> b;
	r = n-b;
	for(ll i=1; i<=b; ++i){
		ll r1 = C[r+1][i];
		ll r2 = C[b-1][i-1]; 
		cout << (r1*r2)%mod << endl;
	}
}


Measured memory_bytes: 31744
#if defined(__GNUC__)
#include <bits/stdc++.h>
// __GNUC__
#else
#include "bits/stdc++.h"
#endif
using namespace std;

#define int long long

#if defined(__GNUC__)
#define __int32 __int32_t
#endif // __GNUC__

#define itn __int32
#define REP(i, n) for(itn (i) = 0; (i) < (n); ++(i))
#define REP2(i, x, n) for(itn (i) = x; (i) < (n); ++(i))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) std::sort(ALL(x))
#define RSORT(x, T) std::sort(ALL(x), greater<T>())
#define REVERCE(x) std::reverce(ALL(x))

#define INT_POW(x, y) [](int a, int b) -> int {int c = a; REP(i, b - 1){c *= a;} return c;}(x, y)
#define INT_POWM(x, y, m) [](int a, int b, int m) -> int {int c = a; REP(i, b - 1){c *= a; c %= m;} return c;}(x, y, m)

struct md {
	int y;
	int x;
};

itn main() {
	std::ios::sync_with_stdio(false);

	itn h, w;
	cin >> h >> w;

	int sy, sx;
	sy = sx = 0;

	int gy = h - 1;
	int gx = w - 1;

	vector<vector<char>> m(h);

	vector<vector<int>> mn(h);

	int cnt = 0;

	REP(i, h) {
		m[i].resize(w);
		mn[i].resize(w, 99999999);
		REP(j, w) {
			cin >> m[i][j];
			if (m[i][j] == '.') {
				++cnt;
			}
		}
	}

	deque<md> mq;
	mq.push_back(md{ sy, sx });
	mn[sy][sx] = 1;

	int res = -1;

	while (!mq.empty()) {

		if (mq[0].y < (h - 1) && (m[mq[0].y + 1][mq[0].x] == '.' || m[mq[0].y + 1][mq[0].x] == '-')) {
			if (mq[0].y + 1 == gy && mq[0].x == gx) {
				res = mn[mq[0].y][mq[0].x] + 1;
				break;
			}
			mn[mq[0].y + 1][mq[0].x] = min(mn[mq[0].y + 1][mq[0].x], mn[mq[0].y][mq[0].x] + 1);
			if (m[mq[0].y + 1][mq[0].x] == '.') {
				m[mq[0].y + 1][mq[0].x] = '-';
				mq.push_back(md{ mq[0].y + 1, mq[0].x });
			}
		}

		if (mq[0].x < (w - 1) && (m[mq[0].y][mq[0].x + 1] == '.' || m[mq[0].y][mq[0].x + 1] == '-')) {
			if (mq[0].y == gy && mq[0].x + 1 == gx) {
				res = mn[mq[0].y][mq[0].x] + 1;
				break;
			}
			mn[mq[0].y][mq[0].x + 1] = min(mn[mq[0].y][mq[0].x + 1], mn[mq[0].y][mq[0].x] + 1);
			if (m[mq[0].y][mq[0].x + 1] == '.') {
				m[mq[0].y][mq[0].x + 1] = '-';
				mq.push_back(md{ mq[0].y, mq[0].x + 1 });
			}
		}

		if (mq[0].y > 0 && (m[mq[0].y - 1][mq[0].x] == '.' || m[mq[0].y - 1][mq[0].x] == '-')) {
			if (mq[0].y - 1 == gy && mq[0].x == gx) {
				res = mn[mq[0].y][mq[0].x] + 1;
				break;
			}
			mn[mq[0].y - 1][mq[0].x] = min(mn[mq[0].y - 1][mq[0].x], mn[mq[0].y][mq[0].x] + 1);
			if (m[mq[0].y - 1][mq[0].x] == '.') {
				m[mq[0].y - 1][mq[0].x] = '-';
				mq.push_back(md{ mq[0].y - 1, mq[0].x });
			}
		}

		if (mq[0].x > 0 && (m[mq[0].y][mq[0].x - 1] == '.' || m[mq[0].y][mq[0].x - 1] == '-')) {
			if (mq[0].y == gy && mq[0].x - 1 == gx) {
				res = mn[mq[0].y][mq[0].x] + 1;
				break;
			}
			mn[mq[0].y][mq[0].x - 1] = min(mn[mq[0].y][mq[0].x - 1], mn[mq[0].y][mq[0].x] + 1);
			if (m[mq[0].y][mq[0].x - 1] == '.') {
				m[mq[0].y][mq[0].x - 1] = '-';
				mq.push_back(md{ mq[0].y, mq[0].x - 1 });
			}
		}

		m[mq[0].y][mq[0].x] = '*';
		mq.pop_front();
	}

	if (res == -1) {
		cout << -1;
	}
	else {
		cout << cnt - res;
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
  public static void main(String[] args) {
  Scanner scan =  new Scanner(System.in);
 int a = scan.nextInt();
 long b=1;
 long c =  (long)Math.pow(10, 9)+7;
 for(int i=1;i<=a;i++){
	 b=i*b % c;
 }
   System.out.println(b);
  }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
const int N = 2510, INF = 1e9;
int n, m, p, a, b, c, ans = 0;
struct Edge
{
    int from,to,dist;
};
vector<Edge> edges;
vector<int> g[N];
bool inq[N];
int d[N];
int cnt[N];
void init()
{
    for(int i=0;i<=n-1;i++)
        g[i].clear();
    edges.clear();
}
void addedge(int from,int to,int dist)
{
    edges.push_back((Edge){from,to,dist});
    int num=edges.size();
    g[from].push_back(num-1);
}
bool spfa(int s)
{
    queue<int> q;
    memset(inq,0,sizeof(inq));
    memset(cnt,0,sizeof(cnt));
    memset(d,0x3f,sizeof(d));
    d[s]=0;
    inq[s]=1;
    q.push(s);
    while(!q.empty())
    {
        int u=q.front();
        q.pop();
        inq[u]=0;
        for(int i=0;i<g[u].size();i++)
        {
            Edge e=edges[g[u][i]];
            if(d[e.to]>d[u]+e.dist)
            {
                d[e.to]=d[u]+e.dist;
                if(!inq[e.to])
                {
                    q.push(e.to);
                    inq[e.to]=1;
                    if(++cnt[e.to]>n+2500)
                        return false;
                }
            }
        }
    }
    return true;
}
int main() {
    cin >> n >> m >> p;
    for(int i = 0; i < m; i++) scanf("%d%d%d", &a, &b, &c), addedge(--a, --b, p-c);
    spfa(0);
    if(cnt[n-1] > n) cout << -1;
    else cout << max(-d[n-1], 0);
}

Measured memory_bytes: 512