akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {

	private class Node<T> {
		T value;
		Node<T> left;
		Node<T> right;
		int pos;
		public Node(T value) {
			this.value = value;
			left = right = null;
			pos = -1;
		}
		public String toString() {
			return value.toString();
		}
	}
	
	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		int[] pre = new int[n];
		int[] in = new int[n];
		StringTokenizer st1 = new StringTokenizer(reader.readLine());
		StringTokenizer st2 = new StringTokenizer(reader.readLine());
		int rootId = 0;
		for (int i = 0; i < n; i++) {
			pre[i] = Integer.parseInt(st1.nextToken());
			in[i] = Integer.parseInt(st2.nextToken());
			if (i == 0) {
				rootId = pre[i];
			}
		}
		reader.close();
		
		Node<Integer> rootNode = new Node<Integer>(rootId);
		for (int i = 1; i < n; i++) {
			Node<Integer> current = new Node<Integer>(pre[i]);
			addNode(rootNode, current, in);
		}
		System.out.println(postOrder(rootNode));
	}

	private String postOrder(Node<Integer> rootNode) {
		StringBuilder sb = new StringBuilder();
		Stack<Node<Integer>> stack = new Stack<Node<Integer>>();
		Node<Integer> current = rootNode;
		Node<Integer> lastVisited = null;
		while (current != null || !stack.isEmpty()) {
			if (current != null) {
				stack.push(current);
				current = current.left;
			} else {
				Node<Integer> peekNode = stack.peek();
				if (peekNode.right != null && peekNode.right != lastVisited) {
					current = peekNode.right;
				} else {
					if (sb.length() != 0) {
						sb.append(" ");
					}
					sb.append(peekNode);
					lastVisited = stack.pop();
				}
			}
		}
		return sb.toString();
	}

	private void addNode(Node<Integer> rootNode, Node<Integer> newNode, int[] in) {
		newNode.pos = findPos(in, newNode.value);
		Stack<Node<Integer>> stack = new Stack<Node<Integer>>();
		stack.push(rootNode);
		while (!stack.isEmpty()) {			
			Node<Integer> current = stack.pop();
			if (current.pos == -1) {
				current.pos = findPos(in, current.value);
			}
			if (newNode.pos < current.pos) {
				if (current.left == null) {
					current.left = newNode;
					return;
				} else {
					stack.push(current.left);
				}
			} else {
				if (current.right == null) {
					current.right = newNode;
					return;
				} else {
					stack.push(current.right);
				}
			}
		}
	}

	private int findPos(int[] in, int id) {
		for (int i = 0; i < in.length; i++) {
			if (in[i] == id) {
				return i;
			}
		}
		return -1;
	}
}



Measured memory_bytes: 24276
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;
#define int long long
int32_t main()
{
  string s;
  int n,i,j,k,l;
 cin>>n;
 cin>>s;
 if(n&1)
  cout<<"No";
 else
 { bool hi=true;
   for(i=0;i<n/2;i++)
   {
     if(s[i]==s[n/2+i])
      continue;
    hi=false;
    break;
   }
   if(hi) cout<<"Yes";
   else cout<<"No";
 }
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
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; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint N, A;
lint arr[100000];
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	lint score = 0;
	cin >> N;
	REP(i, N) {
		cin >> arr[i];
	}
	REP(i, N) {
		cin >> A;
		if (arr[i] < A) {
			score += (A - arr[i]) / 2;
		}
		else{
			score -= arr[i] - A;
		}
	}
	if (score < 0) cout << "No" << endl;
	else cout << "Yes" << endl;
}


Measured memory_bytes: 384
H,W,K = map(int,input().split())
c = []
row = [0]*H
col = [0]*W
total = 0

for i in range(H):
    c.append(list(input()))
    for j in range(W):
        if c[i][j] == '#':
            row[i] += 1
            col[j] += 1
            total += 1

#print(total)
ans = 0
for i in range(2**(H+W)):
    x = [0]*(H+W)
    ii = i
    for j in range(H+W):
        x[j] = ii % 2
        ii//=2
    #print(x)
    D = 0
    for j in range(H):
        D += row[j]*x[j]
    for j in range(H,H+W):
        D += col[j-H]*x[j]

    for j in range(H):
        for k in range(W):
            if c[j][k] == '#':
                D -= x[j]*x[H+k]
    
    if total -D == K:
        ans += 1
    #print(x,ans)

print(ans)

Measured memory_bytes: 73756
#include <bits/stdc++.h>
using namespace std;
//#define int long long
typedef pair<int,int> ii;
typedef tuple<int,int,int> iii;
#define ll long long
#define miniiPQ priority_queue<ii,vector<ii>,greater<ii> >
#define minPQ priority_queue<int,vector<int>,greater<int> >
#define PQ priority_queue<int>
#define iiPQ priority_queue<ii>
#define US unordered_set<int>
#define UMS unordered_multiset<int>
#define UM unordered_map<int>
#define ST stack<int>
 
void m1(){
  int x,n,k;
  cin >> x >>n;
  US us;
  for(int i=0;i<n;++i){
  	cin >> k;
    us.insert(k);
  }
  for(int i=0;i<=100;++i){
  	if(us.find(x-i) == us.end()){
    	cout << x-i;
      	return;
    }
    if(us.find(x+i) == us.end()){
    	cout << x+i;
      	return;
    }
  }
}
 
/*
void m2(){
  int t; cin >> t;
  while(t--) m1();
}
*/
 
int main(){
  //freopen("in.txt","r",stdin);
  m1();
  //m2();
}

Measured memory_bytes: 3640
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007
"""
#N,K,Mが入力
    n,k,m=LI() 
    #N
    #x1 y1
    #.  .
    #xn ynが入力
    N=I()
    p=LIR(N)
    print(n,k,m,p)
"""
def resolve():
    n,m=LI()
    S=LIR(m)
    ans=list(str().rjust(n,"0"))
    memo=[-1]*n
    for i in range(m):
        s,c=S[i]
        if(memo[s-1]!=-1 and memo[s-1]!=c):
            print(-1)
            return
        if(s==1 and c==0 and n>1):
            print(-1)
            return
        memo[s-1]=c
        ans[(s-1)]=str(c)
    if ans[0]=="0" and n>1:
        ans[0]="1"
    buf="".join(ans)
    print(buf)
    return

import sys
from io import StringIO
import unittest

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3 3
1 7
3 2
1 7"""
        output = """702"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """3 2
2 1
2 3"""
        output = """-1"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """3 1
1 0"""
        output = """-1"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()


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

using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i,m,n) for(int i = m - 1; i >= n; i--)
#define ALL(v) v.begin(), v.end()
#define itn int
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
#define YES() cout << "YES" << endl
#define NO() cout << "NO" << endl
template<typename T, typename U>
inline bool CMAX(T &m, U x) { if (m < x) { m = x; return true; } return false; }
template<typename T, typename U>
inline bool CMIN(T &m, U x) { if (m > x) { m = x; return true; } return false; }

typedef long long lint;
typedef long double ldouble;
const int INF = 1e9;
const lint LINF = 1e18;
const ldouble pi = acosl(-1);
int main(){
    int h,m;
    ldouble a,b;
    cin >> a >> b >> h >> m;
    ldouble tansin = ((ldouble)h * 60 + (ldouble)m) * 0.5;
    ldouble tyosin = 6.0 * (ldouble)m;
    ldouble kakudo = tansin-tyosin;
    ldouble c = powl(a,2) + powl(b,2) - 2.0 * a * b * cosl(kakudo * (pi/180.0));
    
    cout << std::fixed << std::setprecision(20) << powl(c,0.5) << endl;
    return 0;
}

Measured memory_bytes: 4172
#include <iostream>
#include<queue>
#include<vector>
// #include <cmath>
// #include <string.h>
// #include <bits/stdc++.h>
using namespace std;

int main(){
	int n,k, temp;
	cin>>n>>k;
	
    priority_queue <int, vector<int>, greater<int> > q;
	for (int i = 0; i < n; ++i)
	{	cin>>temp;
		q.push(temp);	
	}
	temp =0;
	for (int i = 0; i < k; ++i)
	{
		temp += q.top(); q.pop();
	}
	cout<<temp;
	return 0;
}

Measured memory_bytes: 3628
import bisect
A, B, Q = map(int, input().split())
INF = 10 ** 18
s = [-INF] + [int(input()) for i in range(A)] + [INF]
t = [-INF] + [int(input()) for i in range(B)] + [INF]
for q in range(Q):
  x = int(input())
  b, d = bisect.bisect_right(s, x), bisect.bisect_right(t, x)
  res = INF
  for S in [s[b - 1], s[b]]:
    for T in [t[d - 1], t[d]]:
      d1, d2 = abs(S - x) + abs(T - S), abs(T - x) + abs(S - T)
      res = min(res, d1, d2)
  print(res)


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

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

	int64_t n = s.size(), mod = 1000000007;

	vector<vector<int64_t>> dp(n + 1, vector<int64_t>(13, 0));
	dp[0][0] = 1;

	for (int64_t i = 0; i < n; i++)
	{
		for (int64_t j = 0; j < 13; j++)
		{
			if (s[i] == '?')
			{
				for (int64_t d = 0; d <= 9; d++)
				{
					(dp[i + 1][(10 * j + d) % 13] += dp[i][j]) %= mod;
				}
			}
			else
			{
				(dp[i + 1][(10 * j + (s[i] - '0')) % 13] += dp[i][j]) %= mod;
			}
		}
	}

	cout << dp[n][5] << endl;

	return 0;
}

Measured memory_bytes: 13696
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	ll a,b,c,d;
 	cin>>a>>b>>c>>d;
 	for(ll i=0;i<200;i++)
 	{
 		if(i%2==0)
 		{
 			c=max(0LL,c-b);
 			if(c<=0)
 			{
 				cout<<"Yes"<<endl;
 				return 0;
 			}
 		}
 		else
 		{
 			a=max(0LL,a-d);
 			if(a<=0)
 			{
 				cout<<"No"<<endl;
 				return 0;
 			}
 		}
 	}	
    return 0;
}

Measured memory_bytes: 3648
using System;
using System.Globalization;
using System.IO;

namespace ABC119A_2
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                Console.SetIn(new StreamReader(args[0]));
            }

            new Program().Solve();
        }

        void Solve()
        {
            var date = DateTime.Parse(Console.ReadLine());
            var last = DateTime.Parse("2019/04/30");
            Console.Error.WriteLine(date);
            Console.Error.WriteLine(last);

            if (date.Date <= last.Date)
            {
                Console.WriteLine("Heisei");
            }
            else
            {
                Console.WriteLine("TBD");
            }
        }
    }
}


Measured memory_bytes: 13664
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(300000)


def solve(N: int, a: "List[int]"):
    ret = float('inf')
    mn = min(a)
    mx = max(a)
    for v in range(mn, mx + 1):
        tmp = 0
        for x in a:
            tmp += (x - v) ** 2
        ret = min(ret, tmp)
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cstring>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
using namespace std;
typedef int gitype;
typedef long long LL;
gitype gi () {
    gitype ret=0; char ch=getchar();
    while((ch<'0' || ch>'9') && ch!='-') ch=getchar();
    char c=ch=='-'?getchar():ch;
    while(c>='0' && c<='9') ret=ret*10+c-'0',c=getchar();
    return ch=='-'?-ret:ret;
}
const int N = 500;
const int R = 2000;
int n,m,tot;
LL f[R][N],w1[N][N],w2[N][N];
int main () {
    while(scanf("%d%d",&n,&m) && (n||m)) {
        int u,v; LL t; char ops[10];
        memset(w1,3,sizeof(w1));
        memset(w2,3,sizeof(w2));
        memset(f,3,sizeof(f));
        for(int i=1;i<=m;i+=1) {
            u=gi(); v=gi(); t=gi(); scanf("%s",ops);
            if(ops[0]=='L') w1[v][u] = w1[u][v] = min(w1[u][v],t);
            else w2[v][u] = w2[u][v] = min(w2[u][v],t);
        }
        for(int i=1;i<=n;i+=1) w1[i][i]=w2[i][i]=0;
        for(int k=1;k<=n;k+=1) {
            for(int i=1;i<=n;i+=1) {
                for(int j=1;j<=n;j+=1) {
                    w1[i][j] = min(w1[i][j], w1[i][k] + w1[k][j]);
                    w2[i][j] = min(w2[i][j], w2[i][k] + w2[k][j]);
                    
                }
            }
        }
        int b,r=gi(); int p=gi(); LL ans=(1ll<<60);
        f[1][p]=0;
        for(int i=2;i<=r;i+=1) {
            swap(b,p); p=gi();
            for(int j=1;j<=n;j+=1) {
                for(int k=1;k<=n;k+=1) {
                    f[i][j] = min(f[i][j], f[i-1][k] + w1[b][k] + w2[k][j] + w1[j][p]);
                }
                f[i][j] = min(f[i][j], f[i-1][j] + w1[b][p]);
                if(i==r) ans=min(ans,f[i][j]);
            }
        }
        printf("%lld\n",ans);
    }
    return 0;
}

Measured memory_bytes: 14780
#include <iostream>
#include <cstring>

using namespace std;
char s[2000005];
long long r[2000005], v[2000005];
int main()
{
    cin >> s;
    long long n = strlen(s), p10 = 1, sol = 0;

    for(long long i = n - 1; i >= 0; --i)
    {
        r[i] = r[i + 1] + (s[i] - '0') * p10;
        r[i] %= 2019;
        p10 *= 10;
        p10 %= 2019;
    }

    for(long long i = 0; i <= n; ++i)
    {
        ++v[r[i]];
    }

    for(long long i = 0; i <= 2019; ++i)
    {
        sol += (v[i] - 1) * v[i] / 2;
    }

    cout << sol << '\n';
    return 0;
}


Measured memory_bytes: 5388
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main() {
  int n;
  cin >> n;
  if (n == 1) {
    cout << "Yes" << endl;
    return 0;
  }
  vector<int> h(n);
  for (int i = 0;i < n;i++) {
    cin >> h[i];
  }
  for (int i = n-2;i >= 0;i--) {
    if (h[i] > h[i+1] + 1) {
      cout << "No" << endl;
      return 0;
    }
    if (h[i] == h[i+1] + 1) h[i]--;
  }
  cout <<"Yes" << endl;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main()
{
    unsigned long long h, s = 1;
    int flag = 0;
    cin >> h;
    for(int i = 0; i < 64; i++){
        if(h < s){
            cout << s - 1 << endl;
            break;
        }
        s *= 2;
    }
    return 0;
}

Measured memory_bytes: 256
n, m, c = map(int, input().split())
b = list(map(int, input().split()))

ans = 0
for _ in range(n):
    a = list(map(int, input().split()))
    s = c
    for i in range(m):
        s += a[i] * b[i]
    if 0 < s:
        ans += 1
print(ans)

Measured memory_bytes: 3064
// 2011/01/08 Tazoe

#include <iostream>
#include <string>
using namespace std;

int main()
{
	while(true){
		string r, a;
		cin >> r >> a;
		if(r=="0"&&a=="0")
			break;

		int h = 0;
		int b = 0;
		for(int i=0; i<4; i++)
			for(int j=0; j<4; j++)
				if(r[i]==a[j])
					if(i==j)
						h++;
					else
						b++;

		cout << h << ' ' << b << endl;
	}

	return 0;
}

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

using namespace std;

#define long long long
#define INF ((long) 2e18)
#define MOD ((long) (1e9 + 7))
#define umap unordered_map

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

    long t = 1;
    //cin >> t;

    while (t--) {
        long n, m;
        cin >> n >> m;

        umap<long, long> wa;
        set<long> ac;
        while (m--) {
            long p;
            string s;
            cin >> p >> s;
            if (s == "AC") ac.insert(p);
            else if (not ac.count(p)) {
                wa[p]++;
            }
        }
        long count = ac.size();
        long total = 0;
        for (auto &x : ac) {
            total += wa[x];
        }
        printf("%lld %lld\n", count, total);
    }
}


Measured memory_bytes: 11944
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//????????????????????????????????????
#define int long long
#define str string
typedef long long ll;
typedef long double ld;
const ll inf = 999999999999999999;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {
	ll to, cost;
};
ll gcm(ll i, ll j) {//?????§??¬?´???°
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
int n, ans;
char a[1000][1000];
int dp[1000][1000];
signed main() {
	while (cin >> n&&n != 0) {
		ans = 0;
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++) {
				cin >> a[i][j];
				dp[i][j] = 0;
			}
		for (int i = 0; i < n; i++) {
			if (a[i][0] == '.')
				dp[i][0] = 1;
			if (a[0][i] == '.')
				dp[0][i] = 1;
		}
		for (int i = 1; i < n; i++) {
			for (int j = 1; j < n; j++) {
				if (a[i][j] == '.') {
					dp[i][j] = min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1])) + 1;
					ans = max(ans, dp[i][j]);
				}
			}
		}
		cout << ans << endl;
//		getchar(); getchar();
	}
}

Measured memory_bytes: 11764
//https://atcoder.jp/contests/dp/tasks/dp_a
//A - Frog 1

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

const int inf=1e9+7;

int main() {
	
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	
	int n;
	cin>>n;
	vector<int> h(n);
	for(int& x:h) cin>>x;
	
	vector<int> dp(n, inf);
	dp[0]=0;
	for(int i=0; i<n; ++i){
		for(int j:{i+1, i+2}){
			if(j<n){
				dp[j]=min(dp[j], dp[i]+abs(h[i]-h[j]));
			}
		}
	}
	cout<<dp[n-1]<<"\n";
	
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main () {
    long long n;
    cin >> n;
    vector<long long> a(n),b(n),c(n);
    vector<long long> bc(n);
    vector<long long> acc_b(n+1);
    for(long long i = 0; i < n; i++) {
        cin >> a[i];
    }
    for(long long i = 0; i < n; i++) {
        cin >> b[i];
    }
    for(long long i = 0; i < n; i++) {
        cin >> c[i];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    
    long long ic = 0;
    for (long long i = 0; i < n; i++) {
        while(ic < n && c[ic] <= b[i]) ic++;
        bc[i] = n - ic;
    }
    for (long long i = 0; i < n; i++) {
        if(i == 0) {
            acc_b[n-1-i] = bc[n-1-i];
        } else {
            acc_b[n-1-i] = bc[n-1-i] + acc_b[n-i];
        }
    }
    acc_b[n] = 0;

    long long ib = 0;
    long long ans = 0;
    for (long long i = 0; i < n; i++) {
        while(ib < n && b[ib] <= a[i]) ib++;
        ans += acc_b[ib];
    }
    cout << ans << endl;
}

Measured memory_bytes: 4224
import math
def gcd(a,b):
    if a == 0:
        return b
    if b == 0:
        return a
    if a >= b:
        return gcd(b, a%b)
    else:
        return gcd(a, b%a)

a,b = map(int, input().split())
print(gcd(a,b))

Measured memory_bytes: 7776
N,M,K=map(int, input().split())
div=10**9+7

def modinv(a, m):
    b = m
    u = 1
    v = 0
    while (b):
        t = a // b
        a -= t * b 
        a = a^b
        b = a^b
        a = a^b
        u -= t * v
        u = u^v
        v = u^v
        u = u^v
    u %= m 
    if (u < 0): u += m
    return u

def ncr(n, r):
    res = 1
    for i in range(1, r+1):
        res = res*n*modinv(i, div) % div
        n = n-1
    return res % div

result = 0
comb = ncr(N*M-2, K-2)
for d in range(1, N):
    result += d*comb*M*M*(N-d)

for d in range(1, M):
    result += d*comb*(M-d)*N*N

print(result % div)


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

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

const int inf=LLONG_MAX/3;

struct Node{
	int x;
	mutable int v,d;
	bool operator<(const Node&rhs)const{
		return x<rhs.x;
	}
};

signed main(){
	int n=read(),k=read(),ans=0,bias=0;
	set<Node> s{Node{0,0,0}};
	REP(i,n){
		int a=read(),b=read();
		ans+=a*2;
		if(b==1&&a*2>k){
			cout<<-1<<endl;
			return 0;
		}
		bias=(bias+a*2)%k;
		int t=(k-bias)%k;
		auto itr=s.lower_bound(Node{t});
		if(itr==s.end()||itr->x!=t){
			if(itr==s.begin())
				itr=s.end();
			itr--;
			itr=s.insert(Node{t,itr->v+(t+k-itr->x)%k*itr->d,itr->d}).first;
		}
		if(b==1){
			itr->d=1;
			itr++;
			while(1){
				if(itr==s.end())itr=s.begin();
				int w=(itr->x+bias)%k;
				if(0<w&&w<a*2)itr=s.erase(itr);
				else break;
			}
		}
	}
	int m=inf;
	for(auto z:s)chmin(m,z.v);
	cout<<ans+m<<endl;
}


Measured memory_bytes: 6400
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



const int N = 2e3+10;
int n, m, a[N][N], L[N][N], R[N][N], H[N][N];
char s[N][N];

int main() {
	scanf("%d%d", &n, &m);
	REP(i,1,n) scanf("%s", s[i]+1);
	REP(i,1,n-1) REP(j,1,m-1) {
		int t = (s[i][j]=='#')^(s[i+1][j]=='#')^(s[i][j+1]=='#')^(s[i+1][j+1]=='#');
		a[i][j] = !t;
	}
	REP(i,1,n-1) {
		REP(j,1,m-1) if (a[i][j]) {
			if (a[i][j-1]) L[i][j] = L[i][j-1];
			else L[i][j] = j;
		}
		PER(j,1,m-1) if (a[i][j]) {
			if (a[i][j+1]) R[i][j] = R[i][j+1];
			else R[i][j] = j;
		}
	}
	int ans = max(n,m);
	REP(i,1,n-1) REP(j,1,m-1) if (a[i][j]) {
		H[i][j] = H[i-1][j]+1;
		if (H[i-1][j]) {
			L[i][j] = max(L[i][j],L[i-1][j]);
			R[i][j] = min(R[i][j],R[i-1][j]);
		}
		ans = max(ans, (H[i][j]+1)*(R[i][j]-L[i][j]+2));
	}
	printf("%d\n", ans);
}









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

int main(){
	int n;
	cin >> n;
	string s;
	
	int y = 0;
	for(int i = 0; i < n; ++i){
		cin >> s;
		if(s == "Y"){
			y = 1;
		}
	}
	if(y == 1) cout << "Four" << endl;
	else cout << "Three" << endl;
	
	return 0;
}
		

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

int n, k;
int posb[4001][4001] = {};

int calc(int i, int j){
  int a, b, c, d;
  if(i <= -1 * k || j <= -1 * k){
    a = 0;
    b = 0;
    c = 0;
    d = 0;
  }
  else{
    d = posb[i+k-1][j+k-1];
    if(i > 0 && j > 0){
      a = posb[i-1][j-1];
      b = posb[i-1][j+k-1];
      c = posb[i+k-1][j-1];
    }
    else{
      a = 0;
      if(i <= 0 && j <= 0){
        b = 0;
        c = 0;
      }
      else{
        if(j > 0){
          b = 0;
          c = posb[i+k-1][j-1];
        }
        else{
          b = posb[i-1][j+k-1];
          c = 0;
        }
      }
    }
  }
  return d + a - b - c;
}

int main(){
  cin >> n >> k;
  int x[100000];
  int y[100000];
  for(int i = 0 ; i < n ; i++){
    int a, b;
    char c;
    cin >> a >> b >> c;
    if(c == 'B'){
      x[i] = a % (2 * k);
      y[i] = b  % (2 * k);
    }
    else{
      x[i] = (a) % (2 * k);
      y[i] = (b + k) % (2 * k);
    }
  }
  for(int i = 0 ; i < n ; i++){
    posb[x[i]][y[i]]++;
    posb[x[i]+2*k][y[i]+2*k]++;
    posb[x[i]+2*k][y[i]]++;
    posb[x[i]][y[i]+2*k]++;
  }
  for(int i = 0 ; i < 4 * k ; i++){
    for(int j = 0 ; j < 4 * k - 1 ; j++){
      posb[j+1][i] += posb[j][i];
    }
  }

  for(int i = 0 ; i < 4 * k ; i++){
    for(int j = 0 ; j < 4 * k - 1 ; j++){
      posb[i][j+1] += posb[i][j];
    }
  }

  int ans = 0;
  for(int i = 0 ; i < 2*k ; i++){
    for(int j = 0 ; j < 2*k ; j++){
      int tmp = calc(i, j) + calc(i + k, j + k);// + calc(i - k, j + k) + calc(i + k, j - k) + calc(i - k, j - k);
      if(ans < tmp) ans = tmp;
    }
  }
  cout << ans << endl;
}


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


int main()
{
    ll n;
    cin>>n;
    ll a[n];
    ll i,j;
    ll sum=0;
    
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        
    }
    sort(a,a+n);
    ll res=a[n-1];
    ll ind = n-2;
    ll cur=0;
    for(i=2;i<n;i++)
    {
        cur++;
        res+=a[ind];
        if(cur==2)
        {
            cur=0;
            ind--;
        }
    }
    cout<<res<<"\n";
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 5180
using System;
 
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    string[] input = Console.ReadLine().Split(' ');
    int a =int.Parse(input[0]);
    int b =int.Parse(input[1]);
    int c =int.Parse(input[2]);
      
      int newA = b;
      int newB =a;
      
      int newC=newA;
      int newA2=c;
      
      Console.WriteLine(newA2+" "+newB+" "+newC);

    
  }

}
}


Measured memory_bytes: 11092
import java.util.*;

class Main {
    final Scanner sc = new Scanner(System.in);

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

    private void run() {
        int n = sc.nextInt();
        int[] count = new int[n+1];
        for (int i = 0; i < n-1; i++) {
            count[sc.nextInt()]++;
        }

        for (int i = 1; i <= n; i++) {
            System.out.println(count[i]);
        }

    }
}


Measured memory_bytes: 69792
def main():

    X = int(input())
    if X <= 100: return 0
    v = 100
    ans = 0
    while v < X:
        ans += 1
        v *= 1.01
        v = int(v)
        # print(v)s
    return ans

if __name__ == '__main__':
    print(main())

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

using namespace std;
int main()
{
    string s;
    cin>>s;
    int c[26] ={0};
    for(int i=0;i<s.length();i++)
    {
        c[s[i]-'a']++;
    }
    for(int i=0;i<26;i++)
    {
        if(c[i]%2==1)
        {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;

}


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

int main() {
  int N ;
  cin >> N;
  if (N / 1000 == N % 1000 / 100 && N % 100 / 10 == N / 1000 || N % 1000 / 100 == N % 100 / 10 && N % 10 / 1 == N % 1000 / 100){
    cout << "Yes" << endl; 
  }else{
    cout << "No" << endl;
  }
}

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

typedef long long int ll;
const ll mod = 1e9 + 7;
using matrix = vector<vector<ll>>;

void add_self(ll& a, ll b) {
    a = (a+b)%mod;
}

// computes A x B
matrix mult(matrix A, matrix B) {
    
    int rowsa = (int)A.size();
    int colsb = (int)B[1].size();
    int colsa = (int)A[1].size();
    matrix C(rowsa, vector<ll>(colsb));
    
    for(int i = 1; i < rowsa; i++) {
        for(int j = 1; j < colsb; ++j) {
            for(int l = 1; l < colsa; ++l) {
                C[i][j] = (C[i][j] + ((ll)A[i][l] * B[l][j]%mod)) % mod;
            }
        }
    }
    
    return C;
}

// compute A ^ p
matrix power(matrix A, ll p) {
    
    if(p == 1) {
        return A;
    } else if(p % 2 == 1) {
        return mult(A, power(A, p-1));
    } else {
        matrix X = power(A, p/2);
        return mult(X, X);
    }
    
}

int main() {
    
    int n; ll k;
    scanf("%d %lld", &n, &k);
    
    matrix G(n+1, vector<ll>(n+1, 0));
    
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= n; ++j) {
            scanf("%lld", &G[i][j]);
        }
    }
    
    G = power(G, k);
    
    ll ans = 0;
    
    for(int i = 1; i <= n; ++i) {
        for(int j = 1; j <= n; ++j) {
            add_self(ans, G[i][j]);
        }
    }
    
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

int main() {

    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n){
        cin >> s[i];
    }

    vector<vector<int>> cnt(n, vector<int>(26));
    rep(i, n){
        rep(j, s[i].size()){
            cnt[i][s[i][j]-'a']++;
        }
    }
    map<vector<int>, ll> mp;
    rep(i, n){
        mp[cnt[i]]++;
    }

    ll ans = 0;
    for(const auto& m : mp){
        if(m.second == 1) continue;
        ans += m.second * (m.second-1) / 2;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 39296
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define set_bits(a) __builtin_popcount(a)
#define pb push_back
#define pf push_front
#define mod 1000000007
#define M 998244353
#define fi first
#define se second
#define endl '\n'
#define INF 1e18
#define PI 3.14159265358979323846
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


int main()
{
    ll x;
    cin>>x;

    vector<ll>v;
    ll i;
    map<ll,ll>m;
    map<ll,ll>mp;
    for(i=-100000;i<=100000;i++)
    {
        ll x = i*i*i*i*i;
        mp[x]++;
        v.pb(x);
        m[x] = i;
    }
    ll a1,a2;
    if(x==1)
    {
        cout<<"0"<<" "<<"-1"<<endl;
        exit(0);
    }

    for(i=0;i<v.size();i++)
    {
        ll p =  v[i] - x;

        if(mp.find(p)!=mp.end())
        {
            a1 =  m[v[i]];
            a2 = m[p];
            break;
        }
    }


    cout<<a1<<" "<<a2<<endl;
}


Measured memory_bytes: 30036
#include <bits/stdc++.h>
using namespace std;
const int INF=999999999;

int main() {
 int64_t N,A,B;
 cin>>N>>A>>B;
if(N%(A+B)<=A){
 cout<<A*(N/(A+B))+N%(A+B)<<endl;}
else{
 cout<<A*(N/(A+B))+A<<endl;}
 return 0;}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
using namespace std;
int main(){
  int d , n;
  cin >> d >> n;
  if (n == 100) {
    n ++;
  }
  cout << fixed << setprecision(10) << (int) pow(100 , d ) * n << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int n, m;
vector<vector<int>> g;
vector<ll> S_edge;

vector<ll> bfs(int root) {
    vector<int> par(n, -1);
    vector<ll> paths(n, 0);
    queue<int> que;
    que.push(root);
    par[root] = root;
    while(que.size()) {
        int now = que.front();
        que.pop();
        for(auto next : g[now]) {
            if(par[next] >= 0) {
                continue;
            }
            par[next] = now;
            paths[next] = (paths[now] | (1LL << next));
            que.push(next);
        }
    }
    return paths;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    g.resize(n);
    for(int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        g[a - 1].emplace_back(b - 1);
        g[b - 1].emplace_back(a - 1);
    }
    cin >> m;
    S_edge.resize(m, 0);
    auto paths = bfs(n - 1);
    for(int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        S_edge[i] = (paths[u - 1] ^ paths[v - 1]);
    }

    ll ans = 0;
    for(int bit = 0; bit < (1 << m); bit++) {
        int sgn = (__builtin_popcount(bit) % 2 == 0 ? 1 : -1);
        ll S = 0;
        for(int i = 0; i < m; i++) {
            if(bit & (1 << i)) {
                S |= S_edge[i];
            }
        }
        int cnt = (n - 1) - __builtin_popcountll(S);
        ans += sgn * (1LL << cnt);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int N,A[100001];
	int N_lose=0;
	int anser;
	cin>>N;
	for(int i=1;i<=N;i++){
		cin>>A[i];
	}
	while(1){
		for(int i=1;i<=N;i++){
			if(A[i]!=0){
				for(int j=1;j<=N;j++){
					if(i!=j){
						A[j]%=A[i];
					}
				}
			}
		}

		N_lose=0;
		for(int i=1;i<=N;i++){
			if(A[i]==0)N_lose++;
			else anser=i;
		}
		if(N-N_lose==1){
			break;
		}
	}
	cout << A[anser];
	return 0;
}

Measured memory_bytes: 640
N,M,V,P = map(int,input().split())
A = list(map(int,input().split()))
A.sort()

def is_ok(i):
    if i<0: return False
    cur,rival = A[i]+M, A[N-P]
    if cur < rival: return False
    rem_p = V - P - i
    if rem_p <= 0: return True
    j = 0
    for k in range(i+1,N-P+1):
        z = min(M, cur-A[k])
        j += z
        if j >= rem_p * M: return True
    return False

ok = N-P
ng = -1
while ok-ng > 1:
    m = (ok+ng)//2
    if is_ok(m):
        ok = m
    else:
        ng = m

print(N-ok)

Measured memory_bytes: 14484
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
#define ld long double
#define ft first
#define sd second
using namespace std;

const int N = 1e5 + 9;
int n; ll m, up[N], down[N];
vector<int> g[N], f[N], fb[N];

void dfs1(int u, int par) {
    if(g[u].size() == 1 && u != 1) {
        down[u] = 1;
        return;
    }
    ll q = 1;
    f[u].resize(g[u].size());
    fb[u].resize(g[u].size());
    for(int i = 0; i < (int) g[u].size(); i++) {
        f[u][i] = (i > 0 ? f[u][i-1] : 1);
        // cout <<i<<","<< q << " ";
        int v = g[u][i];
        if(v == par) continue;
        dfs1(v, u);
        q = q * (1 + down[v]) % m;
        f[u][i] = q;
    }
    down[u] = q;
    q = 1;
    for(int i = (int) g[u].size() - 1; i >= 0; i--) {
        fb[u][i] = (i < (int) g[u].size() - 1 ? fb[u][i+1] : 1);
        int v = g[u][i];
        if(v == par) continue;
        q = q * (1 + down[v]) % m;
        fb[u][i] = q; 
    }
}

void dfs2(int u, int par) {
    for(int i = 0; i < (int) g[u].size(); i++) {
        int v = g[u][i];
        if(v == par) continue;
        up[v] = (up[u] * (i < (int) g[u].size()-1 ? fb[u][i+1] : 1) % m * (i > 0 ? f[u][i-1] : 1) % m + 1) % m;
        // cout << "up: " << v << " " << (i < (int) g[u].size()-1 ? fb[u][i+1] : 1) << " " << (i > 0 ? f[u][i-1] : 1) % m << "\n";
        dfs2(v, u);
    }
}


signed main() {

    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i < n; i++) {
        int u, v; cin >> u >> v;
        g[u].pb(v); g[v].pb(u);
    }
    for(int i = 1; i <= n; i++) {
        sort(g[i].begin(), g[i].end());
    }
    dfs1(1, 0);
    up[1] = 1;
    dfs2(1, 0);
    for(int i = 1; i <= n; i++) {
        cout << up[i] * down[i] % m << "\n";
        // cout << up[i] << " " << down[i] % m << "\n";
    }
    
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007ll
#define INF (1 << 28)    // for x <= 10^9
#define INFL (1ll << 60) // for x <=10^19
#define EPS (1e-10)

using namespace std;

using ll = long long;

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

  char tmp = '\0';
  for (char c : s) {
    if (tmp == c) {
      cout << "Bad" << endl;
      return 0;
    }

    tmp = c;
  }

  cout << "Good" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
using namespace std;

typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define sor(v) sort(v.begin(),v.end())
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define mp1(a,b,c) P1(a,P(b,c))
#define mp make_pair

const int INF=1000000000;
const int dre_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dre_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

const int kaijou[10]={1,1,2,6,24,120,720,5040,40320,362880};

int cast(int *a){
	int b[10];
	rep(i,8)b[i]=*a++;
	
	bool used[10];
	rep(i,8)used[i]=false;
	
	int ret=0;
	rep(i,8){
		int cnt=0;
		rep(j,b[i])if(!used[j])cnt++;
		ret+=cnt*kaijou[7-i];
		used[b[i]]=true;
	}
	
	return ret;
}

struct array{
	int a[8];
	int num;
	int cas;
};

int main(){
	static int cost[50010]; rep(i,50010)cost[i]=INF;
	static bool use[50010]; rep(i,50010)use[i]=false;
	
	queue<pair<array,int>> que;
	array a; rep(i,8)a.a[i]=i; a.num=0; a.cas=0;
	que.push(mp(a,0)); cost[0]=0;
	
	while(!que.empty()){
		pair<array,int> P=que.front(); que.pop();
/*rep(i,8){
	cout<<P.fr.a[i]<<" ";
}
	cout<<":"<<P.fr.num<<" "<<P.fr.cas<<endl;
	cout<<P.sc<<endl;
*/
		if(!use[P.fr.cas]){
			a=P.fr;
			
			a.a[a.num]=a.a[(a.num+4)%8];
			a.a[(a.num+4)%8]=0;
			a.num=(a.num+4)%8;
			a.cas=cast(a.a);
			if(cost[a.cas]>P.sc+1){
				cost[a.cas]=P.sc+1;
				que.push(mp(a,P.sc+1));
			}
			a=P.fr;
			
			if(a.num%4!=0){
				a.a[a.num]=a.a[a.num-1];
				a.a[a.num-1]=0;
				a.num--;
				a.cas=cast(a.a);
				if(cost[a.cas]>P.sc+1){
					cost[a.cas]=P.sc+1;
					que.push(mp(a,P.sc+1));
				}
				a=P.fr;
			}
			
			if(a.num%4!=3){
				a.a[a.num]=a.a[a.num+1];
				a.a[a.num+1]=0;
				a.num++;
				a.cas=cast(a.a);
				if(cost[a.cas]>P.sc+1){
					cost[a.cas]=P.sc+1;
					que.push(mp(a,P.sc+1));
				}
				a=P.fr;
			}
		
			use[P.fr.cas]=true;
		}
	}
	
	while(cin>>a.a[0]){
		rep1(i,7)scanf("%d",&a.a[i]);
		printf("%d\n",cost[cast(a.a)]);
	}
}

Measured memory_bytes: 1576
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <iterator>
#include <cmath>
#include <deque>
#include <stack>
using namespace std;

int main()
{
    {
        if (fopen("input.txt", "r")) {
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        }
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
    }

    int a, b, c;
    cin >> a >> b >> c;
    if (a + b + c >= 22)
        cout << "bust";
    else
        cout << "win";
    return 0;
}

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

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define test() ll t;cin>>t;for(ll test = 1;test<=t;test++)
#define f first
#define s second
#define pb push_back
#define ins insert
#define nl cout<<"\n"
#define P 1000000007
#define N 100005
#define MOD(x) ((x%P)+P)%P
#define show(x) cout<<x<<" "
#define vec(v) loop(i,0,v.size()) show(v[i]); nl

int main()
{
	fastio();
	

	ll n,w;
	cin>>n>>w;

	ll ans[w+1][n] = {};

	pair<int, int> item[n];

	loop(i,0,n)
	{
		int wt, val;
		cin>>wt>>val;
		item[i] = {wt,val};
	}

	loop(i,1,w+1)
	{
		loop(j,0,n)
		{
			if(j==0)
			{
				if(i>=item[j].f)
					ans[i][j] = item[j].s;
			}
			else
			{
				ans[i][j] = ans[i][j-1];

				if(i>=item[j].f)
					ans[i][j] = max(ans[i][j], item[j].s+ans[i-item[j].f][j-1]);
			}
		}
	}

	cout<<ans[w][n-1],nl;


	//cerr << "\nTime elapsed : " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
	return 0;
}

Measured memory_bytes: 78336
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	int n;
	vector<int> a(3);
	cin >> n;
	for(int i=0;i<n;i++){
		cin>>a[0]>>a[1]>>a[2];
		sort(a.begin(),a.end());
		if(a[2]*a[2]==a[0]*a[0] + a[1]*a[1]){
			cout << "YES" << endl;
		}else{
			cout << "NO" << endl;
		}
	}
}

Measured memory_bytes: 3100
#include <iostream>

using namespace std;

int main(){
  int h; cin >> h;
  int n; cin >> n;
  
  string res = "No";

  int w;
  for (int i = 0; i < n; i++) {
    cin >> w;
    h = h - w;
    if( h <= 0 ) {
      res = "Yes";
      break;
    }
  }
  
  cout << res << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int s;
  cin >> s;
  vector<long long int> vec(1000000, 1000000);
  vec.at(0) = s;
  bool finished = false;
  for(long long int i = 1; i < 1000000; i++) {
    if(vec.at(i - 1) % 2 == 0) {
      vec.at(i) = vec.at(i - 1) / 2;
    }
    else {
      vec.at(i) = vec.at(i - 1) * 3 + 1;
    }
    for(long long int j = 0; j < i; j++) {
      if(vec.at(j) == vec.at(i)) {
        cout << i + 1 << endl;
        finished = true;
        break;
      }
    }
    if(finished) {
      break;
    }
  }
}

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

using ll=long long;
const ll MOD=1000000007;

int main() {
  ll n,m;
  cin >> n >> m;
  vector<ll> a(n);
  vector<pair<ll,ll>> p(m);
  ll cnt=0;
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<m;i++){
    cin >> p[i].second >> p[i].first;
    cnt +=p[i].second;
  }
  //cout << cnt << endl;
  sort(p.begin(),p.end());
  reverse(p.begin(),p.end());
  priority_queue<ll,vector<ll>,greater<ll>> q;
  bool b=true;
  ll ans=0;
  for(int i=0;i<n;i++){
    q.push(a[i]);
  }
  int i=0;
  int j=0;
  ll CNT=0;
  while(b&&CNT<min(cnt,n)){
    ll c=q.top();
    if(p[i].first<=c){
      //cout << p[i].first << " " << c << endl;
      b=false;
    }
    else{
      q.pop();
      c=p[i].first;
      j++;
      CNT++;
      q.push(c);
      if(j>=p[i].second){
        i++;
        j=0;
      }
    }
  }
  for(int i=0;i<n;i++){
    ans +=q.top();
    //cout << q.top() << endl;
    q.pop();
  }
    cout << ans << endl;
}

Measured memory_bytes: 3704
N,X=map(int,input().split())
ai=list(map(int,input().split()))
ai.sort()
sum_of_the_candy=0
ans=0
if sum(ai)==X:
	ans=N
elif sum(ai)<X:
	ans=N-1
else:
	for i in range(N):
		sum_of_the_candy=sum_of_the_candy+ai[i]
		if sum_of_the_candy <= X:
			ans = ans +1
		else:
			break
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define f(a,n) for(ll i=a;i<n;i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define all(v) v.begin(),v.end()
using namespace std;
const ll mod=(1e+9)+7;
const ll size = 2e5+9;
ll gcd(ll a,ll b) {if(b==0)return a;return gcd(b,a%b);}
ll power(ll a,ll b,ll m = mod) {ll res = 1;while(b>0){if(b&1)res = (res*a)%m;b = b>>1;a = (a*a)%m;}return res;}


void solve()
{
    ll n;
    cin>>n;
    ll x = n,s = 0;
    while(x > 0)
    {
        s += x%10;
        x /= 10;
    }
    if(n%s == 0)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
}

int main()
{
    #ifdef JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    clock_t beg = clock();
    solve();
    clock_t end = clock();
    fprintf(stderr, "%.3f sec, Copyright %c 2019 Skyscraper. \n", double(end - beg) / CLOCKS_PER_SEC , 184);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
vector<int> x(10), y(10);
 
double distance(int i, int j) {
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx*dx+dy*dy, 0.5);
}

int main() {
    int N; cin >> N;
    for (int i = 1; i <= N; ++i) {
        cin >> x[i] >> y[i];
    }

    vector<int> v(N);
    for (int i = 0; i < N; ++i) {
        v[i] = i + 1;
    }
 
    int cnt=1;
    for (int i = 1; i <= N; ++i) {
        cnt *= i;
    }

    double dis_sum= 0.0;
    do {
        for (int i = 0; i < N - 1; ++i) {
            dis_sum += distance(v[i], v[i+1]);
        }
    } while (next_permutation(v.begin(), v.end()));
 
    cout << setprecision(10) << dis_sum / cnt << endl;
    return 0;
}

Measured memory_bytes: 4176