akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
typedef long long ll;

ll N;

int main() {
    cin >> N;

    bool f = false;
    for (ll h = 1; h <= 3500; h++) {
        for (ll w = 1; w <= 3500; w++) {
            if ((4*h*w - w*N - h*N) > 0 && N*h*w % (4*h*w - w*N - h*N) == 0) {
                cout << h << " " << N*h*w / (4*h*w - w*N - h*N) << " " << w << endl;
                f = true;
                break;
            }
        }
        if (f) break;
    }

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int i;
	int n;
	int amount = 100000;
	
	scanf("%d", &n);
	
	for( i = 0 ; i < n ; i++ )
	{
		amount *= 1.05;
		if( amount % 1000 != 0 ) amount += (1000 - amount % 1000);
	}
	
	printf("%d\n", amount );
	
	return 0;
	
	
}

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

int main(){
    string s;
    cin>>s;
    int cnt=0;
    int fst=0;
    int end=s.size()-1;
    while(fst<=end){
        if(s[fst]!=s[end])cnt++;
        fst++;
        end--;
    }
    cout<<cnt<<endl;
    return 0;
}

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

int main(){
	#ifndef ONLINE_JUDGE
	    // for getting input from input.txt
	    freopen("input.txt", "r", stdin);
	    // for writing output to output.txt
	    freopen("output.txt", "w", stdout);
	#endif

	int a;
	cin >> a;
	int rem = a % 1000;
	if(rem==0){
		cout << 0;
	}
	else{
		cout << 1000 - rem;
	}

	return 0;
}

Measured memory_bytes: 3672
using System;
using System.Linq;

namespace ITP1_11_A {
    class Dice {
        private int[] _dice;

        public Dice(int[] dice) {
            _dice = dice;
        }

        public int GetTop() {
            return _dice[0];
        }

        public void Move(string dir) {
            foreach (var d in dir) {
                Move(d);
            }
        }

        public void Move(char dir) {
            int temp = _dice[0];
            switch (dir) {
                case 'E':
                    _dice[0] = _dice[3];
                    _dice[3] = _dice[5];
                    _dice[5] = _dice[2];
                    _dice[2] = temp;
                    break;
                case 'W':
                    _dice[0] = _dice[2];
                    _dice[2] = _dice[5];
                    _dice[5] = _dice[3];
                    _dice[3] = temp;
                    break;
                case 'N':
                    _dice[0] = _dice[1];
                    _dice[1] = _dice[5];
                    _dice[5] = _dice[4];
                    _dice[4] = temp;
                    break;
                case 'S':
                    _dice[0] = _dice[4];
                    _dice[4] = _dice[5];
                    _dice[5] = _dice[1];
                    _dice[1] = temp;
                    break;
            }
        }
    }

    class Program {
        static void Main(string[] args) {
            int[] nums = Console.ReadLine().Split(' ')
                .Select(s => int.Parse(s))
                .ToArray();
            string dir = Console.ReadLine();
            Dice dice = new Dice(nums);
            dice.Move(dir);
            Console.WriteLine(dice.GetTop());
        }
    }
}

Measured memory_bytes: 9584
import heapq
def main():
	N, M = map(int, input().split())
	A = list(map(int, input().split()))
	heapq.heapify(A)
	BC = [0]*M
	for i in range(M):
		BC[i] = list(map(int, input().split()))
	BC.sort(key = lambda x: -x[1])
	for B, C in BC:
		if A[0] >= C:
			break
		for _ in range(B):
			if A[0] >= C:
				break
			heapq.heapreplace(A, C)
	print(sum(A))


if __name__ == '__main__':
	main()

Measured memory_bytes: 36172
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

vector<int> get_prime(int n) {
    if(n <= 1) return vector<int>{};
    vector<bool> is_prime(n+1, true);
    vector<int> prime;
    for (int i = 2; i <= n; ++i) {
        if(!is_prime[i]) continue;
        prime.emplace_back(i);
        for (int j = i*2; j <= n; j += i) {
            is_prime[j] = false;
        }
    }
    return prime;
}

int main() {
    const auto primes = get_prime(1300000);
    set<int> s;
    for (auto &&i : primes) s.insert(i);
    int n;
    while(cin >> n, n){
        if(s.count(n)){
            puts("0");
            continue;
        }
        auto ub = s.lower_bound(n);
        auto lb = ub;
        lb--;
        printf("%d\n", (*ub)-(*lb));
    }
    return 0;
}


Measured memory_bytes: 7848
#include <stdio.h>

int main(void) {
	// your code goes here
	int n,i,count=0,odd=0,two=0;
	scanf("%d",&n);
	int *a = (int*)malloc(sizeof(int)*n);
	for(i =0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]%4==0)
			count++;
		else if(a[i]%2==0)
			two++;
		else
			odd++;
	}
//	printf("%d %d %d\n",count,two,odd);
	if(two==0&&odd<=count+1)
		printf("Yes");
	else if(two!=0)
	{
		if(two!=0)
			odd++;
//			printf("%d %d %d",count,two,odd);
		if(odd<=count+1)
			printf("Yes");
		else 
		printf("No");
			
	}
	else
		printf("No");
		
	
	return 0;
}


Measured memory_bytes: 512
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <iomanip>       // fixed, setprecision
using namespace std;

int main()
{
  int N, h, m = 0, c = 0;
  cin >> N;
  for (int i = 0; i < N; i++)
  {
    cin >> h;
    if (h >= m)
    {
      c++;
    }
    m = max(m, h);
  }
  cout << c << endl;
}


Measured memory_bytes: 3192
parseInt(x) = parse(Int, x)
parsemap(x::Array{SubString{String}, 1}) = map(parseInt, x)
ipad(x,y) = lpad(x,6,0)*lpad(y,6,0)

function main()
	n,m = map(parseInt, split(readline()))
	py = Array{Int}(3,m)
	for i in 1:m
		py[1:2,i] = parsemap(split(readline()))
		py[3,i] = i
	end
	py = sortcols(py, by = x->(x[1],x[2]))
	py[2,1] = 1
	for i in 2:m
		if py[1,i] != py[1,i-1]
			py[2,i] = 1
		else
			py[2,i] = py[2,i-1]+1
		end
	end
	py = sortcols(py, by = x->(x[3]))
	for i in 1:m
		println(ipad(py[1,i],py[2,i]))
	end
end
main()

Measured memory_bytes: 164728
<?php
  
  //組み合わせ
fscanf(STDIN,"%d",$n);
$a_li = explode(" ",trim(fgets(STDIN)));
$sepa = array();

for($i=0;$i<$n;$i++){
 $sepa[$a_li[$i]]++;
 $sepa[$a_li[$i]+1]++;
 $sepa[$a_li[$i]-1]++;

}
asort($sepa);

//print_r($sepa);

echo end($sepa)."\n";

Measured memory_bytes: 19188
import java.util.*;
 
public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i<n; i++) {
            a[i] = sc.nextInt();
        }
        System.out.println(minsort(a));
         
    }
    public static int myindex(int[] a,int b){
        for (int i=0;i<a.length;i++){
            if (a[i]==b) {
                return i;
            }
        }
        return -1;
    }
    public static int minsort(int[] a){
        int [] sorted=a.clone();
        Arrays.sort(sorted);
        int n=a.length;
        int cost=0;
        for (int i=0;i<n;i++){
            int cnt=0;
            int c1= myindex(a,sorted[i]);
            while (c1!=i){
                cnt++;
                int c2= myindex(a,sorted[c1]);
                cost+=a[c2];
                int work=a[c2];
                a[c2]=a[c1];
                a[c1]=work;
                c1=c2;
            }
            cost+=Math.min(sorted[i]*cnt, sorted[i]*2+sorted[0]*(cnt+2));
        }
        return cost;
    }
}



Measured memory_bytes: 31912
s=input()
n=len(s)
dp=[0]*(n)
dp[0]=1
if n==1:
    print(1)
    exit()
if n==2:
    if s[0]==s[1]:
        print(1)
    else:
        print(2)
    exit()
if s[0]==s[1]:
    dp[1]=1
else:
    dp[1]=2
if s[0]!=s[1] and s[1]!=s[2]:
    dp[2]=3
else:
    dp[2]=2
for i in range(3,n):
    if s[i]!=s[i-1]:
        dp[i]=dp[i-1]+1
    else:
        dp[i]=dp[i-3]+2
print(dp[n-1])

Measured memory_bytes: 11240
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main() {
	int n, ma, mb;
	cin >> n >> ma >> mb;

	int a, b, c;

	vector< vector<int> > d1(410, vector<int>(410, 10000));
	d1[0][0] = 0;
	for (int i = 0; i < n; i++) {
		cin >> a >> b >> c;
		vector< vector<int> > d2 = d1;
		for (int j = 0; j+a < 410; j++) {
			for (int k = 0; k+b < 410; k++) {
				d2[j+a][k+b] = min(d2[j+a][k+b], d1[j][k]+c);
			}
		}
		d1 = d2;
	}
	int dd = 10000;
	for (int i = 1; ; i++) {
		if (ma*i < 410 && mb*i < 410) {
			dd = min(dd, d1[ma*i][mb*i]);
		} else {
			break;
		}
	}
	if (dd == 10000) {
		cout << -1 << endl;
	} else {
		cout << dd << endl;
	}
	return 0;
}

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

typedef long long ll;
typedef pair<int, pair<int, int>> piii;
//loop
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//STL
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

//const
#define MOD 1000000007 //10^9+7:合同式の法

//acronym
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first      //pairの一つ目の要素
#define S second     //pairの二つ目の要素

const int INF = 1e9;

void Main()
{
    int N;
    cin >> N;
    vector<ll> a(N);
    REP(i, N) { cin >> a.at(i); }

    ll S = a.at(0);
    FOR(i, 1, N - 1)
    {
        S = S ^ a.at(i);
    }

    REP(i, N)
    {
        if (i != 0) cout << " ";
        ll ans = S ^ a.at(i);
        cout << ans;
    }
    cout << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    Main();
    return 0;
}


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

typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
  int n, m;
  cin >> n >> m;
  priority_queue<int> q;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    q.push(a);
  }
  for (int i = 0; i < m; i++) {
    int a = q.top(); q.pop();
    q.push(a/2);
  }
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += q.top(); q.pop();
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
  int a, b;
  char op;
  cin >> a >> op >> b;
  if (op == '+') {
    cout << a + b << endl;
  }
  else {
    cout << a - b << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){

    int n[100],x[100],ans,i,j,k,l,num=1;
    
    n[1]=1;
    x[1]=1;
     
    while(1){
	 scanf("%d",&n[num]);  	 
  	 scanf("%d",&x[num]);
   
     //printf ("num %d n= %d x %d\n",num,n[num],x[num]);
   	 	 
  	 if ((n[num]==0)&&(x[num]==0)) break;
  	 ++num;  	 
    }
  
  l=1;
  while(l<num){	 
    ans=0;
    for(i=1;i<=n[l]-2;++i){
	  for(j=i+1;j<=n[l]-1;++j){
		for(k=j+1;k<=n[l];++k){
	    if (i+j+k==x[l]) ans+=1;	
	    }   	     
	  }
    }	 	  
      printf ("%d\n",ans);
      ++l;
  }  	

	return 0;
}

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

int main() {
    ll n;
    cin >> n;
    ll p = n;
    for (int i = 1; i < n; ++i) {
        p *= i;
        p %= 1000000007;
    }
    cout << p << endl;
}


Measured memory_bytes: 256
main = do
    a <- read <$> getLine
    b <- read <$> getLine
    c <- read <$> getLine
    x <- read <$> getLine
    print $ solve a b c x

{-金額を忘れてとにかく可能な支払い方法を列挙する→金額が正しいものを数える-}
solve :: Int -> Int -> Int -> Int -> Int
solve a b c x = length $ filter (x==) [ 500*a' + 100*b' + 50*c' | a'<-[0..a], b'<-[0..b], c'<-[0..c] ]

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

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

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

    cout << t << s << endl;
}


Measured memory_bytes: 256
gets

ans = 1
ig = false
gets.split(" ").each do |sa|
  a = sa.to_i(10)

  if a === 0
    puts "0"
    exit
  end

  ans *= a unless ig
  
  if ans > 1000000000000000000
    ig = true
    ans = -1
  end
end

if ans > 1000000000000000000
  puts "-1"
  exit
end

puts ans.to_s


Measured memory_bytes: 20856
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
long long MOD = (long long)1e9 + 7;

int n, pcnt[2], len, f[200009], pos[2];
string s, x[2];
long long rmd[2], ba;
bool flag[2];

long long quickpow(long long b, int e)
{
	return e ? ((e & 1 ? b : 1)*quickpow(((b%MOD)*(b%MOD)) % MOD, e >> 1)) % MOD : 1;
}

int gun(long long cur)
{
	int cnt = 0;
	while (cur) {
		if (cur & 1) cnt++;
		cur /= 2;
	}
	return cnt;
}

void fun(int ix, long long cur)
{
	while (cur) {
		cur %= gun(cur);
		f[ix]++;
	}
}

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> s;
	len = s.length();
	x[0] = s; x[1] = s;
	for (int j = 0; j < 2; j++) {
		for (int i = 0; i < len; i++) {
			if (s[i] == '0' + j) {
				x[j][i] = 1 - j + '0';
				pos[j] = i;
				flag[j] = true;
				break;
			}
		}
	}
	for (int j = 0; j < 2; j++) {
		if (flag[j]) {
			for (int i = 0; i < len; i++) {
				pcnt[j] += x[j][i] - '0';
			}
			ba = 1;
			if (pcnt[j] == 0) continue;
			for (int i = len - 1; i >= 0; i--) {
				if (x[j][i] == '1') {
					rmd[j] += ba % pcnt[j];
					rmd[j] %= pcnt[j];
				}
				ba = ba + ba;
				ba %= pcnt[j];
			}
		}
	}
	for (int i = 0; i < len; i++) {
		int cur = s[i] - '0';
		long long tmp = rmd[cur];
		MOD = pcnt[cur];
		if (pcnt[cur] == 0) {
			cout << 0 << E;
			continue;
		}
		f[i] = 1;
		if (cur == 0) {
			tmp -= quickpow(2, len - pos[cur] - 1);
			if (tmp < 0) tmp += MOD;
			tmp += quickpow(2, len - i - 1);
			tmp %= MOD;
		}
		else {
			tmp += quickpow(2, len - pos[cur] - 1);
			tmp %= MOD;
			tmp -= quickpow(2, len - i - 1);
			if (tmp < 0) tmp += MOD;
		}
		fun(i, tmp);
		cout << f[i] << E;
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 4656
// Username: WillTheBill
// Time of creation: 2020-09-27 15:23
// Original filename: main.cp.cpp

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

// shortcuts
#define pb push_back
#define fi first
#define se second

// IO
#define multitest signed __T; cin >> __T; while(__T--)
void _masterread(){}
template<typename T,typename... V>
void _masterread(T& t, V&... v){cin >> t;_masterread(v...);}
#define read(...)_masterread(__VA_ARGS__)
void _masterprint(){cout << endl;}
template<typename T,typename... V>
void _masterprint(T t, V... v){cout << t;if(sizeof...(v)) cout << " ";_masterprint(v...);}
#define print(...)_masterprint(__VA_ARGS__)

// DEBUG
// colored output???
template <typename T> // start forward declaration
void _print(T t);
template<typename T1,typename T2>
void _print(pair<T1,T2> p);
template<typename T>
void _print(vector<T>v);
template <typename T> // end forward declaration
void _print(T t){cerr<<t;}
template<typename T1,typename T2>
void _print(pair<T1,T2> p){cerr<<"{";_print(p.first);cerr<<", ";_print(p.second);cerr<<"}";}
template<typename T>
void _print(vector<T>v){cerr<<"(";for(unsigned _i=0;_i<v.size();_i++)_print(v[_i]),cerr<<(_i==v.size()-1?"":", ");cerr << ")";}
void _masterdebug(){cerr<<"]\n";}
template<typename T,typename... V>
void _masterdebug(T t,V... v){_print(t);if(sizeof...(v))cerr<<", ";_masterdebug(v...);}
#ifdef __local__
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"] = [";_masterdebug(__VA_ARGS__)
#else
#define debug(...) 
#endif

// ordered_set and ordered_map
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2>
using ordered_map = tree<T1, T2, less<T1>, rb_tree_tag, tree_order_statistics_node_update>;

// TYPES
// #define int long long

struct ST{
    vector<int> arr;
    ST(int N){
        int size = 1;
        while(size < N) size <<= 1;
        arr = vector<int> (2 * size);
    }
    int u(int idx, int l, int r, int qidx, int qval){
        if(qidx < l || qidx > r) return arr[idx];
        if(l == r) return (arr[idx] = qval);
        int m = (l + r) / 2;
        return arr[idx] = max(u(idx * 2, l, m, qidx, qval), u(idx * 2 + 1, m + 1, r, qidx, qval));
    }
    int q(int idx, int l, int r, int ql, int qr){
        if(ql > r || qr < l) return 0;
        if(l >= ql && r <= qr) return arr[idx];
        int m = (l + r) / 2;
        return max(q(idx * 2, l, m, ql, qr), q(idx * 2 + 1, m + 1, r, ql, qr));
    }
};

signed main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int N, K; read(N,K);
    ST st (300001);
    for(int i = 0; i < N; i++){
        int t; read(t);
        int l = max(0, t - K);
        int r = min(300000, t + K);
        int mx = st.q(1, 0, 300000, l, r);
        st.u(1, 0, 300000, t, mx + 1);
    }
    print(st.q(1,0,300000,0,300000));
}


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

int main()
{
	int a[100], b[100],c[100],n,ans;
	cin >> n;

	ans = 0;

	for (int i = 1;i <= n;i++)
	{
		cin >> a[i];
	}
	for (int i = 1;i <= n;i++)
	{
		cin >> b[i];
	}
	for (int i = 1;i < n;i++)
	{
		cin >> c[i];
	}

	for (int i = 1;i <= n;i++)
	{
		ans += b[a[i]];
		if (i-1!=0&&a[i]== a[i - 1]+1)
			ans += c[a[i-1]];
	}

	cout << ans;
	return 0;
}

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

int main() {
    long long N;
    cin >> N;
    vector<long long> a(N+1,0);
    long long odd = 0;
    
    for(int i = 0; i < N; i++){
        cin >> a[i];
        if(a[i] % 2 != 0){
            odd++;
        }
    }

cout << (odd % 2 == 0 ? "YES":"NO") << endl;

}

Measured memory_bytes: 1024
#include <cstdio>


const int MAXN=1e5+10;

struct Node{
    int lbound,rbound;
    int diff;
    Node *left,*right;
};

Node segtree[MAXN*2];
Node* next_pos=segtree;
int n,q;

Node* build(int left,int right){
    auto* cur=next_pos;
    next_pos++;
    cur->lbound=left;
    cur->rbound=right;
    cur->diff=0;
    int mid=(left+right)/2;
    if (right-left==1) return cur;
    cur->left=build(left,mid);
    cur->right=build(mid,right);
    return cur;
}

void update(Node& self,int l,int r,int u){
    // puts("s");
    int mid=(self.lbound+self.rbound)/2;
    if (l==self.lbound&&r==self.rbound){
        self.diff+=u;
    }else if (l>=mid){
        update(*self.right,l,r,u);
    }else if (r<=mid){
        update(*self.left,l,r,u);
    }else{
        update(*self.left,l,mid,u);
        update(*self.right,mid,r,u);
    }
}

int query(Node& self,int i){
    // puts("q");
    if (self.rbound-self.lbound==1&&self.lbound==i) return self.diff;
    int mid=(self.lbound+self.rbound)/2;
    if (i>=mid) return query(*self.right,i)+self.diff;
    else return query(*self.left,i)+self.diff;
}

int main(){
    scanf("%d%d",&n,&q);
    build(1,n+1);
    for(int i=0;i<q;i++){
        int t;
        scanf("%d",&t);
        if (t==0){
            int s,t,x;
            scanf("%d%d%d",&s,&t,&x);
            update(segtree[0],s,t+1,x);
        }else{
            int i;
            scanf("%d",&i);
            printf("%d\n",query(segtree[0],i));
        }

    }
    return 0;
}


Measured memory_bytes: 9008
K = 10**9 + 7

n,a,b = map(int,input().split())

# 組み合わせ計算
# 約分してから計算するアルゴリズム
# 10^9 + 7 で割ったあまりを返すバージョン
MOD = 1000000007

def combination(n, r):
    # n >= 0, r >= 0, r <= n を仮定
    if n < 0 or r < 0 or n < r:
        return -1

    # r <= n - r を仮定
    if n - r < r:
        r = n - r

    # r < 2 の場合
    if r == 0:
        return 1
    if r == 1:
        return n

    # nCr の分子
    # [n - r + 1, n - r + 2, ... , n - 1, n]
    numerator = [n - r + 1 + i for i in range(r)]


    # nCr の分母
    # [1, 2, ... , r - 1, r]
    denominator = [i + 1 for i in range(r)]

    # nCr を約分する
    for i in range(r):
        # i番目の分母で約分する
        # 0番目は1なので省略

        # 元の（今までの約分を行う前の）i番目の分母の値
        original_denominator = i + 1

        # 今までの約分を行った後の、i番目の分母の値
        # 今回の約分で割る数
        divisor = denominator[i]

        # divisorが1（全て約分済み）の場合は無視する
        if divisor == 1:
            continue

        # 約分する相手の分子を決める
        # 0～i番目の分子（約分前）の中で、
        # original_denominatorで割り切れる数
        # （一つしかない）を選ぶ
        # remainder = i番目の分子 % original_denominator
        # とするとき、
        # (i - remainder)番目の分子 = i番目の分子 - remainder
        # (i - remainder)番目の分子 % original_denominator
        #  = (i番目の分子 - remainder) % original_denominator
        #  = 0
        # なので、(i - remainder)番目の分子を選べばよい。

        # remainder = i番目の分子 % original_denominator
        #           = (n - r + i + 1) % (i + 1)
        #           = (n - r) % (i + 1)
        remainder = (n - r) % original_denominator

        # divisor で約分できるペアをすべて約分する
        for j in range(i, r, original_denominator):
            numerator[j - remainder] = numerator[j - remainder] // divisor
            denominator[j] = denominator[j] // divisor

    ans = 1
    for i in numerator:
        ans = (ans * i) % MOD
    return ans

print((pow(2, n, K) - combination(n, a) - combination(n, b) - 1) % K)

Measured memory_bytes: 19152
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;


int main(){
	ll n, k;
	cin >> n >> k;
	ll ans = 0LL;
	rep(i, n -1) ans = k * (ans/(k-1)) + ans % (k-1) + 1;
	cout << ans << endl;
}

Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define trace1(a) cout << a << 'n';
#define trace2(a, b) cout << a << ' ' << b << 'n';
#define trace3(a, b, c) cout << a << ' ' << b << ' ' << c << 'n';
#define trace4(a, b, c, d) cout << a << ' ' << b << ' ' << c << ' ' << d << 'n';
#define trace5(a, b, c, d, e) cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << 'n';
#define trace6(a, b, c, d, e, f) cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << ' ' << f << 'n';
#define range(n) for(int i = 0; i < n; i++)
#define printArr(harry, tam) range(tam) cout << harry[i] << " n"[i == tam -1];
#define maxn -2000000 //negative value to break code and force you to put right constraint
#define MOD 1000000007
#define md(x) (x) % mod;
#define sc scanf
#define pr printf
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ps push
#define prt(x) cout << (#x) << " is " << (x) << endl
#define EPS 1e-9
#define INF 1000000000
#define INFd 1e9
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<double> vd;

int main(){
  ll n;
  string s1,s2;
  cin>>n;
  cin>>s1>>s2;
  ll i=0;
  ll ans=0;
  if(s1[0]==s2[0])
    {
      i=1;
      ans=3;

    }
  else
  {
    i=2;
    ans=6;
  }
  for(;i<n;i++)
  {
      if(s1[i]==s2[i])
      {
        if(s1[i-1]==s2[i-1])
        {
          ans=(ans*2)%MOD;
        }
      }
      else
      {
        if(s1[i-1]==s2[i-1])
        {
          ans=(ans*2)%MOD;
        }
        else
          ans=(ans*3)%MOD;
          i++;
      }
  }
  cout<<ans;
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#define Max 200000
#define top 2000000000
typedef long long ll;

ll cnt = 0;
int L[Max/2+2],R[Max/2+2];

void  merge(int A[],int n,int left,int mid,int right){
	int i,j,k;
	int n1 = mid - left;
	int n2 = right - mid;
	for(i=0;i<n1;i++) L[i] = A[left+i];
	for(i=0;i<n2;i++) R[i] = A[mid+i];
	L[n1] = R[n2] = top;
	i = j = 0;
	for(k=left;k<right;){
		if(L[i]<=R[j]) A[k++] = L[i++];
		else{
			A[k++] = R[j++];
			cnt += n1 - i;
		} 
	}
}

void mergeSort(int A[],int n,int left,int right){
	if(left+1<right){
		int mid = left + (right-left)/2;
		mergeSort(A,n,left,mid);
		mergeSort(A,n,mid,right);
		merge(A,n,left,mid,right);
	}
}

int main(){
	int A[Max],n,i;
	cin>>n;
	for(i=0;i<n;i++) cin>>A[i];
	mergeSort(A,n,0,n);
	cout<<cnt<<endl;
	
	return 0;
}


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

using namespace std;

typedef long long ll;

ll par[100005], rk[100005], sz[100005];
ll inconv[100005];

ll find_par(int x){
	if (par[x] != x) par[x] = find_par(par[x]);
	return par[x];
}

bool is_same_set(int x, int y){
	return find_par(x) == find_par(y);
}

void merger(int x, int y){
	if (is_same_set(x,y)) return;
	int X = find_par(x), Y = find_par(y);
	if (rk[X] > rk[Y]){
		par[Y] = X;
		sz[X] += sz[Y];
	}
	else{
		par[X] = Y;
		sz[Y] += sz[X];
		if (rk[X] == rk[Y]) rk[Y]++;
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll N, M, A, B;
	vector<pair<ll,ll> > v;
	cin >> N >> M;
	inconv[M] = (N*(N-1))/2;
	for (int i = 1; i <= N; ++i){
		par[i] = i;
		sz[i] = 1;
		rk[i] = 0;
	}
	for (int i = 1; i <= M; ++i){
		cin >> A >> B;
		v.push_back(make_pair(A,B));
	}
	reverse(v.begin(),v.end());
	for (int i = 0; i < v.size(); ++i){
		inconv[M-i-1] = inconv[M-i]; 
		if (is_same_set(v[i].first,v[i].second)) continue;
		inconv[M-i-1] -= (sz[find_par(v[i].first)]*sz[find_par(v[i].second)]);
		merger(v[i].first,v[i].second);
	}
	for (int i = 1; i <= M; ++i){
		cout << inconv[i] << '\n';
	}
	cout << flush;
	//for (int i = 0; i < 1e9; ++i){for (int j = 0; j < 1e9; ++j){}}
	
}

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

int main(void){
	  char wether[7];
	  char cycle[3][7] = {
		    "Sunny",
		    "Cloudy",
		    "Rainy"
	  };
	  int a;
	  scanf("%s", wether);
	  if(strcmp(&cycle[0][0], wether) == 0) a = 1;
	  else if(strcmp(&cycle[1][0], wether) == 0) a = 2;
          else a = 0;
	  printf("%s\n", cycle[a]);
	  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,m;cin >> n >> m;
	vector<int> a(n,1);
	vector<bool> b(n);
	b[0]=true;
	rep(i,m){
		int x,y;cin >> x >> y;
		a[--x]--;
		a[--y]++;
		if(b[x]) b[y]=true;
		if(a[x]==0) b[x]=false;
	}
	int ans=0;
	rep(i,n) if(b[i]) ans++;
	cout << ans << endl;
}

Measured memory_bytes: 640
#ABC 128C
def main():
    import sys
    N, M = map(int, sys.stdin.readline().split())
    Light = [tuple(map(int, sys.stdin.readline().split())) for _ in range(M)]
    P = list(map(int, sys.stdin.readline().split()))
    #print(Light)
    #print(P)
    ans = 0
    for i in range(2**N):
        cnt = [0 for _ in range(M)]
        for m in range(M):
            for s in Light[m][1:]:
                cnt[m] += (i>>N-s)&1
        cnt = list(map(lambda x:x%2, cnt))
        if cnt == P:
            ans +=1
    print(ans)

if __name__=='__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
    int N,C;
    cin>>N>>C;
    ll mi=1e18;
    int D[35][35],c[3][35];
    for(int i=0; i<C; i++){
        for(int j=0; j<C; j++){
            cin>>D[i][j];
        }
    }
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            int x;
            cin>>x;
            x--;
            c[(i+j)%3][x]++;
        }
    }
    for(int i=0; i<C; i++){
        for(int j=0; j<C; j++){
            for(int k=0; k<C; k++){
                ll ans=0;
                if(i == k || i == j || j == k) {
					continue;
				}
                for(int l=0; l<C; l++)ans+=D[l][i]*c[0][l];
                for(int l=0; l<C; l++)ans+=D[l][j]*c[1][l];
                for(int l=0; l<C; l++)ans+=D[l][k]*c[2][l];
                mi=min(ans,mi);
            }
        }
    }
    cout<<mi<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <string>
#include <functional>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;

bool ct(string &str) {
	int n = str.length();
	set<char> st;
	int i;
	for(i = 0; i < n; i++) {
		st.insert(str[i]);
	}
	return st.size() == 1;
}

int main() {
    ios_base::sync_with_stdio(false);
	string str;
	cin >> str;
	set<char> chars;
	int i, j;
	int n = str.length();
	for(i = 0; i < n; i++) {
		chars.insert(str[i]);
	}
	int minval = 1e9;
	for(char x: chars) {
		string curr = str;
		int cs = str.length();
		while((!ct(curr)) && cs > 1) {
			string nw(cs - 1, '.');
			for(i = 0; i < cs - 1; i++) {
				nw[i] = curr[i];
				if(curr[i + 1] == x) {
					nw[i] = x;
				}
			}
			curr = nw;
			cs--;
		}
		minval = min(minval, n - cs);
	}
	cout << minval;	
				
		
	
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 1000000007;
int main()
{
    ll INF = 10000000;
    ll n, m;
    cin >> n >> m;
    vector<vector<char>> maze(n, vector<char>(m));
    rep(i, n)
    {
        rep(j, m)
        {
            cin >> maze[i][j];
        }
    }
    vector<vector<ll>> d(n, vector<ll>(m));
    rep(i, n)
    {
        rep(j, m)
        {
            d[i][j] = 1;
        }
    }
    ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
    queue<tuple<ll, ll, ll>> que;
    ll ans = 0;
    rep(i, n)
    {
        rep(j, m)
        {
            ll b = 0;
            ll w = 0;
            if (d[i][j] == 1)
            {
                if (maze[i][j] == '#')
                {
                    que.push(tuple<ll, ll, ll>(i, j, 1));
                    b++;
                }
                else
                {
                    que.push(tuple<ll, ll, ll>(i, j, 0));
                    w++;
                }
                d[i][j] = 0;
                while (!que.empty())
                {
                    tuple<ll, ll, ll> p = que.front();
                    que.pop();
                    for (ll x = 0; x < 4; x++)
                    {
                        ll nx = get<0>(p) + dx[x], ny = get<1>(p) + dy[x];
                        ll ch = get<2>(p);
                        if (0 <= nx && nx < n && 0 <= ny && ny < m)
                        {

                            if (d[nx][ny] == 1)
                            {
                                if (maze[nx][ny] == '#' && ch == 0)
                                {
                                    d[nx][ny] = 0;
                                    que.push(tuple<ll, ll, ll>(nx, ny, 1));
                                    b++;
                                }
                                else if (maze[nx][ny] == '.' && ch == 1)
                                {
                                    d[nx][ny] = 0;
                                    que.push(tuple<ll, ll, ll>(nx, ny, 0));
                                    w++;
                                }
                            }
                        }
                    }
                }
            }
            ans += b * w;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4960
#include <iostream>
#include <vector>
#include <map>
#include <utility>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stack>
#include <queue>

#define REP(i,a,n) for(int i=a;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define vsort(v) sort(v.begin(),v.end())
#define asort(a,n) sort(a, a + n)
#define vi vector<int>
#define vd vector<double>

//ここからAtCoder向けdefine
#define yes cout << "YES" << endl;
#define no cout << "NO" << endl;

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vi vec(N);
    rep(i, N){
        cin >> vec[i];
    }
    vsort(vec);
    int max = 0;
    rep(i, N){
        max += vec[i];
    }
    if(max % 10 == 0){
        rep(i, N){
            if(vec[i] % 10 != 0){
                cout << max - vec[i] << endl;
                return 0;
            }
        }
        cout << 0 << endl;
    }else{
        cout << max << endl;
    }

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)

int N;
vll A;

ll val(ll b)
{
    ll ret = 0;
    for (int n=0; n<N; ++n) {
        ret += abs(A[n] - b);
    }
    return ret;
}

int main(int argc, const char * argv[]) {
    cin >> N;
    A = vll(N);
    for (int n=0; n<N; ++n) {
        cin >> A[n];
        A[n] -= n+1;
    }
    
    sort(A.begin(), A.end());
    
    int i = N/2 ;
    cout << val(A[i]) << endl;

    return 0;
}


Measured memory_bytes: 1792
N, K, C = gets.chomp.split(" ").map(&:to_i)
S = gets.chomp
left = Array.new(K)
right = Array.new(K)
l, r = 0, N - 1

K.times do |k|
    l += 1 while S[l] == "x"
    r -= 1 while S[r] == "x"
    left[k] = l
    right[K - k - 1] = r
    l += C + 1
    r -= C + 1
end

result = []
K.times do |i|
    if left[i] == right[i]
        result << left[i] + 1
    end
end

puts result


    

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

int main() {
    string s;
    cin >> s;
    vector<char> c(s.size());
    for(int i = 0; i < s.size(); i++){
        c.at(i) = s.at(i);
    } 
    vector<char> co = c;
    reverse(c.begin(),c.end());
    if(co == c){
        vector<char> c1((s.size()-1)/2);
        for(int i = 0; i < (s.size() - 1)/2;i++) {
            c1.at(i) = c.at(i);
        }
        vector<char> c1o = c1;
        reverse(c1.begin(),c1.end());
        if(c1 == c1o) {
            vector<char> c2(s.size()-((s.size()+3)/2)+1);
            int i1 = 0;
            for(int i = ((s.size() + 3) / 2) - 1 ; i < s.size(); i++) {
                c2.at(i1) = co.at(i);
                i1++;
            }
            vector<char> c2o = c2;
            reverse(c2.begin(),c2.end());
            if(c2 == c2o){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

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

int main() {
	int num,num2;
	std::cin >> num;
	std::cin >> num2;
	if(num > num2) {
		std::cout << "a > b" << std::endl;
	}else if(num == num2) {
		std::cout << "a == b" << std::endl;
	}else {
		std::cout << "a < b" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include <stdio.h>
int abs(int a){
    return a>0?a:-a;
}
int main(void){
	int t,n,h[100],i;
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d",&h[i]);
		}
		int max=0;
        int min=0;
		for(i=0;i<n-1;i++){
            int t=h[i+1]-h[i];
			if(t>0&&t>max)
                max=t;
            else if(t<0){
                t=abs(t);
                if(t>min)
                    min=t;
            }
		}
		printf("%d %d\n",max,min);
	}
	return 0;
}

Measured memory_bytes: 596
import Foundation

func readWords<T>(_ f: (Substring) -> T) -> [T] {
    return readLine()!.split(separator: " ").map(f)
}

func main() {
    let nw = readWords { Int($0)! }
    let n = nw[0]
    let w = nw[1]

    var items = [(w: Int, v: Int)]()
    var totalWeight = 0
    var totalValue = 0
    for _ in 1...n { 
        let wv = readWords { Int($0)! }
        items.append((w: wv[0], v: wv[1]))
        totalWeight += wv[0]
        totalValue += wv[1]
    }

    // ある価値での最小の重さ
    var dp = [Int](repeating: totalWeight, count: totalValue+1)
    dp[0] = 0
    
    for i in 0..<n {
        let item = items[i]
        for value in (0...totalValue).reversed() {
            if value + item.v <= totalValue { 
                dp[value+item.v] = min(dp[value+item.v], dp[value]+item.w)
            }
        }
    }

    let ans = dp.enumerated().filter { $0.1 <= w }
    print(ans.last!.0)
}


main()

Measured memory_bytes: 16080
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<math.h>
#include<limits.h>
#include<string>
#include<iomanip>
#include<numeric>
#include<queue>
using namespace std;

long long  mod = 1000000007;

long max(long x, long y) {
	return x > y ? x : y;
}

long min(long x, long y) {
	return x < y ? x : y;
}

long factorial(long n) {
	if (n == 1) {
		return 1;
	}
	else {
		return n * factorial(n - 1);
	}
}

long long  fel(long long  n,long long  f) {

		if (f == 1) {
			return n % mod;
		}
		else if (f % 2 == 0) {
			return (fel(n,f / 2) * fel(n,f / 2)) % mod;
		}
		else {
			return ((n  * fel(n,f / 2) %mod) * fel(n,f / 2))% mod;
		}
	

}


int main()
{
	long a, b;
	cin >> a >> b;
	long long ans = 1;
	for (int i = 2;i <= max(a, b);i++) {
		while (true) {
			if (a % i == 0 or b % i == 0) {
				if (a % i == 0) {
					a = a / i;
				}
				if (b % i == 0) {
					b = b / i;
				}
				ans = ans * i;
			}
			else {
				break;
			}
		}
	}
	cout << ans;
}







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

int main(){
  int i,j,k,cnt;
  int h,w;
  cin>>h>>w;
  string s[h+2];
  s[0]="";s[h+1]="";
  for(i=0;i<w+2;i++){
    s[0]+='.';
    s[h+1]+='.';
  }
  for(i=0;i<h;i++)cin>>s[i+1];
  for(i=0;i<h;i++){
    s[i+1]='.'+s[i+1]+'.';
  }
  for(i=0;i<h;i++){
    for(j=0;j<w;j++){
      if(s[i][j]=='#' && s[i+1][j]=='.' &&s[i-1][j]=='.' && s[i][j+1]=='.' && s[i][j-1]=='.'){
        cout<<"No";
        return 0;
      }
    }
  }
  cout<<"Yes";
}

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

int main()
{
    char s1[sz],s2[sz],s3[sz];
    cin>>s1;
    cin>>s2;
    cin>>s3;
    printf("%c%c%c\n",s1[0],s2[1],s3[2]);

    return 0;
}


Measured memory_bytes: 3628
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

N=gets.to_i
sp=array(N)
N.times do|i|
    sp[i]=get
    sp[i][1]=sp[i][1].to_i
    sp[i].push(i)
end
sp.sort!{|x,y| x[0]<=>y[0]}
point=[]
(N-1).times do|i|
  if sp[i][0]==sp[i+1][0]
      point.push(sp[i])
  else
      point.push(sp[i])
      if point!=[]
          point.sort!{|x,y| y[1]<=>x[1]}
          point.each do|s,p,i|
              puts i+1
          end
          point=[]
      end
  end
end
point.push(sp[N-1])
      if point!=[]
          point.sort!{|x,y| y[1]<=>x[1]}
          point.each do|s,p,i|
              puts i+1
          end
      end

Measured memory_bytes: 1916
N = int(input())
p = list(map(int, input().split()))
count = 0

for i in range(N-2):
    p1,p2,p3 = p[i:i+3]
    if p1 < p2 < p3 or p1 > p2 > p3:
        count += 1
print(count)

Measured memory_bytes: 3060
// #pragma GCC optimize ("O3")
// #pragma GCC target ("sse4")

#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const int NINF = -1*INF;
const long long LLINF = 1ll << 60;
const long long LLNINF = -1*LLINF;

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) {
    os << "{ ";
    for(auto& y : x) os << y << " ";
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) {
	return os << "[ " << p.first << ", " << p.second << "]" ;
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<pi> vpi;
typedef vector<vector<int>> vvi;
typedef vector<vll> vvll;
typedef vector<vd> vvd;
typedef vector<vld> vvld;
 
#define mp make_pair
#define pb push_back
#define pf push_front
#define all(x) x.begin(), x.end()
#define revAll(x) x.rbegin(), x.rend()
#define gcd(a, b) __gcd(a, b)
#define popcount(x) __builtin_popcount(x)
#define isize(x) (int)(x.size())
#define rep(i,n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define umap unordered_map

const int MOD = 1e9 + 7;
int n;
vvi G = vvi(100000 + 100);

ll mul(ll a, ll b) {
  unsigned long long x = (long long) a * b;
  unsigned xh = (unsigned) (x >> 32), xl = (unsigned) x, d, m;
  asm(
    "divl %4; \n\t"
    : "=a" (d), "=d" (m)
    : "d" (xh), "a" (xl), "r" (MOD)
  );
  return m;
}

int madd(ll a, ll b){
	a += b;
	if (a >= MOD) a -= MOD;
	return a;
}

int msub(ll a, ll b){
	a -= b;
	if (a < 0) a += MOD;
	return a;
}


pll dfs(int node, int prnt){
	ll w = 1, b = 1;
	for(const auto& nbhr : G[node]){
		if (prnt == nbhr) continue;
		auto [nbhr_w, nbhr_b] = dfs(nbhr, node);	
		w = mul(w, nbhr_b + nbhr_w);
		b = mul(b, nbhr_w);	
	}
	return {w, b};
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
	cin >> n;
	rep(i, n-1){
		int u, v; cin >> u >> v;
		u--; v--;
		G[u].pb(v);
		G[v].pb(u);
	}
	pll ret = dfs(0, -1);
	ll ans = madd(ret.first, ret.second);
	cout << ans << "\n";
}

Measured memory_bytes: 15496
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#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<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
using namespace std;
int n,q[1000005],l,r;
ll c,h[1000006],dp[1000005];
double calc(int x){
    return dp[x]+h[x]*1.0*h[x];
}
double xl(int x,int y){
    return (calc(x)-calc(y)*1.0)/(h[x]*1.0-h[y])/2.0;
}
int main(){
    scanf("%d%lld",&n,&c);
    for(int i=1;i<=n;++i)scanf("%lld",h+i);
    l=r=1,q[1]=1;
    for(int i=2;i<=n;++i){
        while(l<r&&xl(q[l],q[l+1])<=h[i])++l;
        dp[i]=c+dp[q[l]]+(h[q[l]]-h[i])*(h[q[l]]-h[i]);
        while(l<r&&xl(q[r],i)<xl(q[r-1],q[r]))--r;
        q[++r]=i;
    }
    printf("%lld\n",dp[n]);
	//system("pause");
	return 0;
}


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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string N;
  cin >> N;
  string ans = "ABC";
  ans += N;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}


int N;
vi h;
vi dp;

int rec(int n){
    
    if(dp[n] != infi) return dp[n];
    int res = infi;
    if(n-1 >= 0) chmin(res,rec(n-1)+abs(h[n-1]-h[n]));
    if(n-2 >= 0) chmin(res,rec(n-2)+abs(h[n-2]-h[n]));
    
    return dp[n] = res;
    
}


int main(){

    cin >> N;
    h.resize(N);
    in(N,h);
    dp.assign(N,infi);
    dp[0] = 0;
    
    cout << rec(N-1) << endl;
    

    return 0;
}


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

int main() {
  int N, L;
  cin >> N >> L;
  string s[110];
  for(int i = 0; i < N; i++) cin >> s[i];
  sort(s, s + N);
  for(int i = 0; i < N; i++) cout << s[i];
  cout << endl;
}


Measured memory_bytes: 256
#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<int> vec(n);
  int s1=0,s2=0;
  rep(i,n){
    cin >> vec[i];
    s2 += vec[i];
  }

  int ans = 1e7;
  int diff;
  rep(i,n){
    s1+=vec[i];
    s2-=vec[i];
    if(s2>=s1) diff=s2-s1;
    if(s2<s1) diff =s1-s2;
    ans = min(ans,diff);
  }

  cout << ans << endl;

}


Measured memory_bytes: 256
import sys
a = [list(map(int, l.split(","))) for l in sys.stdin]
dp = a[0]

for i in range(1, (len(a)+1)//2):
    _dp = [0]*(i+1)
    for j in range(i):
        _dp[j] = max(_dp[j], dp[j]+a[i][j])
        _dp[j+1] = max(_dp[j+1], dp[j]+a[i][j+1])
    dp = _dp

for i in range((len(a)+1)//2, len(a)):
    _dp = [0]*(len(dp)-1)
    for j in range(len(_dp)):
        _dp[j] = max(dp[j], dp[j+1]) + a[i][j]
    dp = _dp

print(dp[0])


Measured memory_bytes: 5608
#include <iostream>

using namespace std;

const int kInf = 1 << 26;
const int kMaxV = 10;

int d[kMaxV][kMaxV];

void WarshallFloyd(){
  for(int k=0; k<kMaxV; k++){
	for(int i=0; i<kMaxV; i++){
	  for(int j=0; j<kMaxV; j++){
		d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
	  }
	}
  }
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  while(1){
	int n;
	cin >> n;
	if(n == 0){
	  return 0;
	}

	for(int i=0; i<kMaxV; i++){
	  for(int j=0; j<kMaxV; j++){
		d[i][j] = kInf;
	  }
	}

	for(int i=0; i<kMaxV; i++){
	  d[i][i] = 0;
	}
	
	for(int i=0; i<n; i++){
	  int a, b, c;
	  cin >> a >> b >> c;
	  d[a][b] = c;
	  d[b][a] = c;
	}
	WarshallFloyd();

	int min_town = -1;
	int min_sum = kInf;
	for(int i=0; i<kMaxV; i++){
	  int sum = 0;
	  for(int j=0; j<kMaxV; j++){
		if(d[i][j] >= kInf){
		  continue;
		}
		sum += d[i][j];
	  }
	  if(sum == 0){
		break;
	  }
	  if(sum < min_sum){
		min_sum = sum;
		min_town = i;
	  }
	}
	cout << min_town << " " << min_sum << endl;
  }
  
  return 0;
}

Measured memory_bytes: 3168