akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define REP(i,N) for(ll i=0;i<N;++i)

struct Node {
	Node(){};
	~Node() {
		delete left;
		delete right;
	};	
	long long key; 
	Node *parent;
	Node *left;
	Node *right;
};

// root node is not nullptr
void insert(Node *root, Node *z) {
	Node *y = nullptr;
	Node *x = root;
	while (x != nullptr) {
		y = x;
		if (z->key < x->key) {
			x = x->left;
		} else {
			x = x->right;
		}
	}
	z->parent = y;
	if (z->key < y->key) {
		y->left = z;
	} else {
		y->right = z;
	}
}

bool find(Node *root, ll key) {
	if (root == nullptr) return false;
	if (root->key == key) return true;
	Node *ptr = key < root->key ? root->left : root->right;
	return find(ptr, key);
}

Node* find_using_loop(Node *root, ll key) {
	while (root != nullptr && key != root->key) {
		if (key < root->key) root = root->left;
		else root = root->right;
	}
	return root;
}

Node* get_minimum(Node *x) {
	while (x->left != nullptr) {
		x = x->left;
	}
	return x;
}

/// returns the next node to z
Node* get_successor(Node *z) {
	if (z->right != nullptr) {
		return get_minimum(z->right);
	}
	Node *y = z->parent;
	while (y != nullptr && z == y->right) {
		z = y;
		y = y->parent;
	}
	return y;
}

/// z: target to delete
///
void delete_node(Node **root, Node *z) {
	if (z == nullptr) return;
	Node *x;
	/// find the real target to delete
	Node *y;
	if (z->left == nullptr || z->right == nullptr) {
		y = z;
	} else {
		y = get_successor(z);
	}
	/// determine the child of y
	if (y->left != nullptr) {
		x = y->left;
	} else {
		x = y->right;
	}

	if (x != nullptr) {
		x->parent = y->parent;
	}
	/// yがroot nodeだった場合
	if (y->parent == nullptr) {
		*root = x;
	} else if (y == y->parent->left) {
		y->parent->left = x;
	} else {
		y->parent->right = x;
	}	

	if (y != z) {
		z->key = y->key;
	}
}

void print_by_preorder(Node *node) {
	if (node == nullptr) return;
	cout << " " << node-> key; 
	print_by_preorder(node->left);
	print_by_preorder(node->right);
}

void print_by_inorder(Node *node) {
	if (node == nullptr) return;
	print_by_inorder(node->left);
	cout << " " << node-> key; 
	print_by_inorder(node->right);
}

int main () {
	ll m;
	cin >> m;
	Node *root = new Node();
	REP(i,m) {
		string s;
		cin >> s;
		ll key;
		if (s[0] == 'i') {
			cin >> key;
			// initialize root node
			if (i==0) {
				// root node
				root->left = root->right = nullptr;
				root->key = key;
				continue;
			}
			Node *node = new Node();
			node->key = key;
			node->left = nullptr; // caution
			node->right= nullptr; // caution
			insert(root, node);
		} else if (s[0] == 'p') {
			print_by_inorder(root);
			cout << endl;
			print_by_preorder(root);
			cout << endl;
		} else if (s[0] == 'f') {
			cin >> key;
			//1.
			//cout << (find(root, key) ? "Yes" : "No") << endl;
			//2.
		  Node *t = find_using_loop(root, key);	
			if (t == nullptr) {
				cout << "no" << endl;
			} else {
				cout << "yes" << endl;
			}
		} else if (s[0] == 'd') {
			cin >> key;
			Node *t = find_using_loop(root, key);
			Node** pp_root = &root;
			delete_node(pp_root, t);	
		}
	}
	delete root; 
	return 0;
}




Measured memory_bytes: 21856
import java.util.*;


public class Main{

  public static void main(String... args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long[] arr = new long[n];
    for(int i=0;i<n;i++){
      arr[i] = sc.nextLong() - (i+1);
    }
    Arrays.sort(arr);
    long b, ans1 = 0, ans2 = 0;
    if (n % 2 == 1){
      b = arr[n/2];
      for(int i=0;i<n;i++){
        ans1 += Math.abs(arr[i]-b);
      }
      System.out.println(ans1);
    }else{
      b = arr[n/2-1];
      for(int i=0;i<n;i++){
        ans1 += Math.abs(arr[i]-b);
      }
      b = arr[n/2];
      for(int i=0;i<n;i++){
        ans2 += Math.abs(arr[i]-b);
      }
      System.out.println(Math.min(ans1, ans2));
    }
  }
}


Measured memory_bytes: 87892
N = int(input())
C = sorted(map(int, input().split()))
mod = 10**9+7
# そのビットが異なる確率 * それ以上のビットが立っている数の期待値 * c
ans = 0
for i, c in enumerate(C[::-1], 2):
    ans += i * c
ans %= mod
ans = ans * pow(2, 2*N-2, mod) % mod
print(ans)


Measured memory_bytes: 31756
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define mkp make_pair
#define fi first
#define se second
#define pt(num) cout << num << "\n"
#define mCalc(a, s, b) (a)=((a)s(b))%MOD
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define INF 1000000000000000000
#define MOD 1000000007LL
#define MAX 101010
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;

ll dp[22][2100000];

int main(void) {
    ll N;
    cin >> N;
    ll a[22][22];
    ll i, j, k;
    
    for(i=0; i<N; i++)
        for(j=0; j<N; j++)
            cin >> a[i][j];
    
    dp[0][0]=1;
    for(i=0; i<N; i++) {
        for(j=0; j<1<<N; j++) {
            ll c=0;
            for(k=0; k<N; k++)
                if(j>>k&1) c++;
            if(c!=i) continue;
            
            for(k=0; k<N; k++) {
                if(dp[i][j]==0 || a[i][k]==0 || j>>k&1) continue;
                mCalc(dp[i+1][j|1<<k], +, dp[i][j]);
            }
        }
    }
    
    pt(dp[N][(1<<N)-1]);
}



Measured memory_bytes: 309504
class Dice():
    def __init__(self, up, back, right, left, front, down):
        self.up = up
        self.down = down
        self.right = right
        self.left = left
        self.front = front
        self.back = back
    
    def north(self):
        temp = self.up
        self.up = self.back
        self.back = self.down
        self.down = self.front
        self.front = temp
    
    def south(self):
        temp = self.up
        self.up = self.front
        self.front = self.down
        self.down = self.back
        self.back = temp
        
    def east(self):
        temp = self.up
        self.up = self.left
        self.left = self.down
        self.down = self.right
        self.right = temp
    
    def west(self):
        temp = self.up
        self.up = self.right
        self.right = self.down
        self.down = self.left
        self.left = temp
    
    def counterclockwise(self):
        temp = self.back
        self.back = self.left
        self.left = self.front
        self.front = self.right
        self.right = temp
    
    def clockwise(self):
        temp = self.back
        self.back = self.right
        self.right = self.front
        self.front = self.left
        self.left = temp
        
    def operate(self, op):
        if op == "N":
            self.north()
        elif op == "S":
            self.south()
        elif op == "E":
            self.east()
        elif op == "W":
            self.west()
        
    def fix_up(self, up):
        if self.down == up:
            self.north()
            self.north()
        elif self.right == up:
            self.west()
        elif self.left == up:
            self.east()
        elif self.front == up:
            self.south()
        elif self.back == up:
            self.north()

    def fix_back_with_fixed_up(self, back):
        if self.right == back:
            self.clockwise()
        elif self.left == back:
            self.counterclockwise()
        elif self.front == back:
            self.clockwise()
            self.clockwise()

up, back, right, left, front, down = map(int, input().split())
dice = Dice(up, back, right, left, front, down)

question_n = int(input())
for _ in range(question_n):
    q_up, q_back = map(int, input().split())
    dice.fix_up(q_up)
    dice.fix_back_with_fixed_up(q_back)
    print(dice.right)


Measured memory_bytes: 5616
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,copy
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
if n%2:
    print(0)
    quit()
res = 0
now = 10
while now <= n:
    res += n//now
    now *= 5
print(res)

Measured memory_bytes: 5500
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
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

def solve():
    h,w = LI()
    cy,cx = LI()
    gy,gx = LI()
    s = [input() for _ in range(h)]
    cy -= 1
    cx -= 1
    gy -= 1
    gx -= 1
    d = [(1,0),(-1,0),(0,1),(0,-1)]
    bfs = [[float("inf")]*w for i in range(h)]
    bfs[cy][cx] = 0
    q = deque([(cy,cx)])
    while q:
        y,x = q.popleft()
        b = bfs[y][x]
        if (y,x) == (gy,gx):
            print(b)
            return
        for dy,dx in d:
            ny,nx = y+dy,x+dx
            if 0 <= ny < h and 0 <= nx < w and s[ny][nx] != "#" and b < bfs[ny][nx]:
                bfs[ny][nx] = b
                q.appendleft((ny,nx))
        nb = b+1
        for dy in range(-2,3):
            for dx in range(-2,3):
                ny,nx = y+dy,x+dx
                if 0 <= ny < h and 0 <= nx < w and s[ny][nx] != "#" and nb < bfs[ny][nx]:
                    bfs[ny][nx] = nb
                    q.append((ny,nx))
    print(-1)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 104288
import copy


def move(lon, lat, com):
    target, other, pop_index, insert_index = lon, lat, 0, 3
    if com == "E" or com == "W":
        target, other = lat, lon
    if com == "S" or com == "W":
        pop_index, insert_index = 3, 0
    target.insert(insert_index, target.pop(pop_index))
    other[0], other[2] = target[0], target[2]


def set_upper(lon, lat, upper):
    com = "N" if upper in lon else "E"
    for _i in range(4):
        move(lon, lat, com)
        if lon[0] == upper:
            break


def rotate(lon, lat, com):
    if com == "R":
        lon[1], lat[1], lon[3], lat[3] = lat[3], lon[1], lat[1], lon[3]
    elif com == "L":
        lon[1], lat[1], lon[3], lat[3] = lat[1], lon[3], lat[3], lon[1]


longitude = [0, 1, 5, 4]
latitude = [0, 3, 5, 2]

values = list(input().split())
u, f = values[longitude[0] - 1], values[longitude[1] - 1]
values2 = list(input().split())
longitude2, latitude2 = copy.copy(longitude), copy.copy(latitude)
result = "No"
for i in range(6):
    set_upper(longitude2, latitude2, i)
    for j in range(4):
        rotate(longitude2, latitude2, "R")
        if values[0] != values2[longitude2[0]]:
            continue
        elif values[1] != values2[longitude2[1]]:
            continue
        elif values[2] != values2[latitude2[3]]:
            continue
        elif values[3] != values2[latitude2[1]]:
            continue
        elif values[4] != values2[longitude2[3]]:
            continue
        elif values[5] != values2[longitude2[2]]:
            continue
        else:
            result = "Yes"
            break
    if result == "Yes":
        break
print(result)



Measured memory_bytes: 6316
#include <bits/stdc++.h>
#include <cmath>
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;}
const long long INFLL = 1LL<<60;
const int INF = 1<<28;
void solve(int a){cout<<( a?"Yes":"No")<<endl;}
int main(){
	int n;
	cin >>n;
	int ansa;
	int ansb;
	int d=0;
	vector<int>a(n,0);
	for(int i=0;i<n;i++){
		cin >>a[i];
	}
	sort(a.begin(),a.end(),greater<int>());
	ansa=a[0];
	ansb=a[1];
	d=abs(ansa/2-ansb);
	for(int i=2;i<n;i++){
		if(chmin(d,abs(ansa/2-a[i]))){
			ansb=a[i];
		}
	}

	printf("%d %d\n",ansa,ansb);
}

Measured memory_bytes: 640
k = gets.to_i

def gcd(a,b)
  if a > b
    m = a
    n = b
  else
    m = b
    n = a
  end
  while true
    r = m % n
    if r == 0
      return n
    end
    m = n
    n = r
  end
end

sum = 0
k.times { |_x|
  x = _x+1
  k.times { |_y|
    y = _y+1
    t = gcd(x,y)
    k.times { |_z|
      z = _z+1
      s = gcd(t,z)
      sum += s
    }
  }
}
puts sum


Measured memory_bytes: 14420
//--- pB ---//
import java.util.*;
import java.lang.*;
import java.io.*;
public class Main {
	public static void main (String[] args) throws java.lang.Exception {
		new Solution();
	}
}
class Solution {
	Reader reader;
	PrintWriter out;
	public Solution() {
		reader = new Reader();
		out = new PrintWriter(System.out);
		while (reader.hasNext()) {
			run_case();
		}
		out.flush();
	}

	private void run_case() {
		int a = reader.ni();
		int b = reader.ni();
		int c = reader.ni();
		int k = reader.ni();

		int res = 0;
		if (k <= a) {
			res = k;
		} else {
			res += a;
			k -= a;
			if (k <= b) {

			} else {
				k -= b;
				if (k <= c) {
					res -= k;
				}
			}
		}

		out.println(res);

		return;
	}
}


class Reader {
	BufferedReader br;
	StringTokenizer st;
	public Reader(){
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public String next() {
		if (st.hasMoreTokens()) return st.nextToken();
		try {
			st = new StringTokenizer(br.readLine());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return st.nextToken();
	}
	public boolean hasNext() {
		try {
			if (!st.hasMoreTokens() && !br.ready()) return false;
			else return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}
	public int ni() {return Integer.parseInt(this.next());}
	public long nl() {return Long.parseLong(this.next());}
	public String ns() {return this.next();}
}


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

string s[4];

int main(){
	for(int i=0;i<3;i++) cin >> s[i], reverse(s[i].begin(),s[i].end());
	int cur = 0;
	while(s[cur]!=""){
		int ccur = s[cur].back()-'a';
		s[cur].pop_back();
		cur = ccur;
	}
	cout << (char)(cur+'A') << endl;
	return 0;
}


Measured memory_bytes: 256
H, W, N = map(int, input().split())

Y = [W+100]*(H+1)
P = [[] for i in range(W+1)]
for i in range(N):
    x, y = map(int, input().split())
    if x < y:
        continue
    Y[x-y] = min(Y[x-y], y-1)
    P[y-1].append(x-1)
base = 0
ans = H
for y in range(W):
    while Y[base] == y:
        base += 1
    xmin = y + base
    for x in P[y]:
        if xmin <= x:
            ans = min(x, ans)
print(ans)

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

int main(){
  int groups[12] = {1,3,1,2,1,2,1,1,2,1,2,1};
  int x, y;
  cin>>x>>y;
  cout<<(groups[x-1]==groups[y-1]?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
     int count = 0;
     char s[3], t[3];
     scanf("%s", s);
     scanf("%s", t);

     for (int i = 0; i < 3; i++) {
          if (s[i] == t[i]) {
               count++;
          }
     }
     printf("%d\n", count);
     return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rep(i, st, n) for (int i = (st); i < (n); ++i)
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef long double ld;
 
template <typename T1, typename T2> bool chkmin(T1 &x, T2 y) { return y < x ? (x = y, true) : false; }
template <typename T1, typename T2> bool chkmax(T1 &x, T2 y) { return y > x ? (x = y, true) : false; }

const int N = 200050;
int dp[N][4];
 
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
#ifdef DEBUG
    freopen("in", "r", stdin);
#endif
    
    string s;
    cin >> s;
    int n = s.size();
    for (int i = 1; i <= n; ++i)
    {
        for (int len = 1; len <= i && len <= 3; ++len)
        {
            if (i - len == 0)
            {
                dp[i][len] = 1;
                continue;
            }
            for (int lenw = 1; lenw <= i - len && lenw <= 3; ++lenw)
            {
                if (lenw != len || s.substr(i - len, len) != s.substr(i - 2 * len, len))
                {
                    chkmax(dp[i][len], dp[i - len][lenw] + 1);
                }
            }
        }
    }
    cout << max(dp[n][1], max(dp[n][2], dp[n][3])) << '\n';
    
    return 0;
}

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

using namespace std;

int d[11][11], f[111][111];
int main()
{
	int a, b, e = 0;
	cin >> a >> b;
	for (int i = 1; i <= a; i++)
		for (int j = 1; j <= b; j++)
			cin >> d[i][j];
	for (int i = 0; i < 101; i++) {
		for (int j = 0; j < 101; j++) {
			for (int k = 1; k <= a; k++)
				for (int l = 1; l <= b; l++)
					f[i][j] = max(f[i][j], d[k][l] - k * i - l * j);
			if (f[i][j] <= 100)
				e++;
		}
	}
	for (int k = 1; k <= a; k++) {
		for (int l = 1; l <= b; l++) {
			int m = 114514;
			for (int i = 0; i < 101; i++)
				for (int j = 0; j < 101; j++)
					m = min(m, f[i][j] + k * i + l * j);
			if (m != d[k][l]) {
				cout << "Impossible" << endl;
				return 0;
			}
		}
	}
	cout << "Possible\n202 " << e + 200 << "\n";
	for (int i = 0; i < 100; i++) {
		cout << i + 1 << ' ' << i + 2 << " X\n";
		cout << i + 102 << ' ' << i + 103 << " Y\n";
	}
	for (int i = 1; i < 102; i++)
		for (int j = 102; j < 203; j++)
			if (f[i - 1][202 - j] <= 100)
				cout << i << ' ' << j << ' ' << f[i - 1][202 - j] << '\n';
	cout << "1 202" << endl;
	return 0;
}


Measured memory_bytes: 384
n=list(input())
le=len(n)
if le==1:
  print(int(n[0]))
  exit()
x=list(n)
x.remove(x[0])
if len(set(x))==1 and x[0]=='9':
  key=int(n[0])
  print(9*(le-1)+key)
  exit()
m=list(n)
m.remove(m[-1])
if len(set(m))==1 and m[0]=='9':
  print(9*(le-1)+8)
else:
  key=int(n[0])
  print(9*(le-1)+key-1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pip pair<int,pair<int,int> >
#define bs binary_search
#define gcd __gcd
#define fs first
#define sc second
int ABS(int a){return max(a,-a);}
ll ABS(ll a){return max(a,-a);}
double ABS(double a){return max(a,-a);}


int main()
{
	/*#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif*/

	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin>>n;
	ll a=2LL,b=1LL;
	ll x=b;
	for(int i=2;i<=n;i++)
	{
		x = a+b;
		a=b;
		b=x;
	}

	cout<<x;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
int main()
{
    using namespace std;
    int N, M, sum(0);
    cin >> N >> M;
    int H[N], A[M], B[M];
    bool result[N] = {false};
    for (int i = 0; i < N; i++)
    {
        cin >> H[i];
    }
    for (int i = 0; i < M; i++)
    {
        cin >> A[i] >> B[i];
    }
    for (int i = 0; i < M; i++)
    {
        if (H[A[i] - 1] == H[B[i] - 1])
        {
            result[A[i] - 1] = true;
            result[B[i] - 1] = true;
            continue;
        }
        int min = (H[A[i] - 1] > H[B[i] - 1]) ? B[i] - 1 : A[i] - 1;
        result[min] = true;
    }
    for (int i = 0; i < N; i++)
    {
        if (result[i] == false)
            sum++;
    }
    cout << sum << endl;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vector<pii> > vvpii;

#define pb push_back
#define endl '\n'
#define INF (int)1e9
#define MOD (ll)(1e9+7)
#define EPS 1e-9
#define gcd __gcd
#define rs resize
#define FOR(i,a,b) for(int i = a; i < b; i++)
#define by(T, x) [](const T& a, const T& b) { return a.x < b.x; } //for struct sorting

void printV(vector<int> v){
	for(int i = 0; i < v.size(); i++){
		cout << v[i] << " " ;
	}
	cout << endl;
}

void print2V(vvi v){
	FOR(i, 0, v.size()){
		FOR(j, 0, v[i].size()){
			cout << v[i][j] << " ";
		}
		cout << endl;
	}
}

ll n, k, arr[110], dp[110][100010], prefix[110][100010];

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

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

int main(){
	cin >> n >> k;
	for(ll i = 1; i <= n; i++){
		cin >> arr[i];
	}
	
	
	//initialization of the dp and prefix array
	for(ll i = 0; i <= n; i++){
		dp[i][0] = 1;
		prefix[i][0] = 1;
	}
	for(ll i = 0; i <= k; i++){
//		dp[0][i] = 1;
		prefix[0][i] = 1;
	}
/*	
	cout << "intial prefix arr: " << endl;
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <=k; j++){
			cout << prefix[i][j] << " ";
		}
		cout << endl;
	}
*/	
	for(ll i = 1; i <= n; i++){
		for(ll j = 1; j <= k; j++){
			ll first = (j-arr[i]-1 >= 0)?prefix[i-1][j-arr[i]-1] : 0;
//			cout << "prefix for last is: " <<  prefix[i-1][j] << endl;
			ll last = prefix[i-1][j];
			dp[i][j] = add(dp[i][j],sub(last,first));
//			cout << "last, first, dp[i][j]: " << last << " " << first << " " << dp[i][j] << endl;
			prefix[i][j] = add(prefix[i][j-1],dp[i][j]);
 		}
	}
	cout << dp[n][k] << endl;
	
	
/*	
	cout << "dp arr is: " << endl;
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <=k; j++){
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}
*/
}

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

const int n_max=100000;

int main() {

    int n,m;
    scanf("%d %d",&n,&m);

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

Measured memory_bytes: 892
#include <algorithm>
#include <cassert>
#include <cctype>
#include <chrono>
#define _USE_MATH_DEFINES
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const int INF = 0x3f3f3f3f, MOD = 1000000007;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
/*-----------------------------------------*/
int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  int H, W, h, w; cin >> H >> W >> h >> w;
  cout << (H - h) * (W - w) << '\n';
  return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
	public static void main(String[]args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[]v=new int[n];
		for(int i=0;i<n;i++)
			v[i]=sc.nextInt();
		long ans=0;
		for(int i=0;i<n;i++)
			ans+=Math.max(0,v[i]-sc.nextInt());
		System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 22484
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
long long int gcd(long long int x, long long int y){
  return y!=0 ? gcd(y, x%y) : x;
}
long long int lcm(long long int x, long long int y){
  return x*y/gcd(x, y);
}
long long int factorial(long long int x){
  return x==0 ? 1 : x*factorial(x-1);
}
int main(){
  int i, j, a[3];
  cin >> a[0] >> a[1] >> a[2];
  if(a[0]%2==0||a[1]%2==0||a[2]%2==0){
    cout << 0;
    return 0;
  }
  sort(a, a+3);
  cout << (long long)a[0]*a[1];
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <cmath>
#include <iomanip>
#include <set>
using namespace std;

int compare(unsigned ahp, unsigned aatk, unsigned bhp, unsigned batk) {
	auto anum = ceil(1.0 * ahp / batk);
	auto bnum = ceil(1.0 * bhp / aatk);
	return (anum > bnum) ? -1 : (anum < bnum ? 1 : 0);
}

int main()
{
	int a, b;
	cin >> a >> b;


	cout << (a <= 5 ? 0 : (a <= 12 ? b / 2 : b)) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <ctime>
#include <list>
#include <numeric>
#include <utility>
#include <ctime>
#define INF 100000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;

/*---------------------------------------------------*/

int h,w;
int c[15][15];
int a[205][205];

void wf(){
  rep(k,10){
    rep(i,10){
      rep(j,10){
	if(i==j)continue;
	c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
      }
    }
  }
}

int main(){
  cin>>h>>w;
  rep(i,10)rep(j,10)cin>>c[i][j];
  //cout<<"end"<<endl;
  wf();
  ll ans=0;
  rep(i,h)rep(j,w){
    cin>>a[i][j];
    if(a[i][j]==-1)continue;
    ans+=c[a[i][j]][1];
  }
  cout<<ans<<endl;
  return 0;
}


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

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

  int err0 = 0, err1 = 0;

  int len = s.length();
  char expected[2] = {'0', '1'};

  for (int i = 0; i < len; i++){
    char ex = expected[i&1];
    char c = s[i];
    if (c == ex){
      err1++;
    } else {
      err0++;
    }
  }

  int ans = min(err0, err1);
  cout << ans << endl;
}


Measured memory_bytes: 512
first = input()
second = input()
third = input()

d = {}
d["a"]=first
d["b"]=second
d["c"]=third


flag = False
run = "a"
while flag != True:
 
  if d[run] == "":
    flag = True
    print(run.upper())
  else:
    l = len(d[run])
    temp = d[run][0]
    
    d[run] = d[run][1:l]
    
    run = temp

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

int c(int k,int n)
{
    if (k>n) return 0;
    if ((k==0) or (k==n))
    {
        return 1;
    }
    else
    {
        return c(k-1,n-1)+c(k,n-1);
    }
}

int main()
{
    int n,m;
    cin>>n>>m;
    int a,b;
    a=c(2,n);b=c(2,m);
    cout<<a+b;
}


Measured memory_bytes: 256
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n = 0, m = 0, a = 0, b = 0; lli res = 0ll;
	cin >> n >> m;
	vector<vector<int> > v(m);
	for (int i = 0; i < n; ++i)
	{
		cin >> a >> b;
		if (a <= m)
			v[m - a].pb(b);
	}
	priority_queue<int> pq;
	for (int i = m - 1; i >= 0; --i)
	{
		for (auto j : v[i])
			pq.push(j);
		if (!pq.empty())
		{
			res += pq.top(); pq.pop();
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 8444
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9+7
int dp[10004],a[1003],b[1003],h,n;

int call(int H)
{
	if(H<=0)return 0;
	if(dp[H]!=-1)return dp[H];
	int ret = inf;
	for(int i=0;i<n;i++)
		ret = min(ret,call(H-a[i])+b[i]);
	return dp[H] = ret;
}

int main()
{
	memset(dp,-1,sizeof dp);
	scanf("%d %d",&h,&n);
	for(int i=0;i<n;i++)scanf("%d %d",&a[i],&b[i]);
	printf("%d",call(h));
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

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

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string sex_0,sex_mid;
  int right = 0;
  int left = n-1;
  rep(z,20){
    if(z == 0){
      cout << 0 << endl;
      cin >> sex_0;
      if(sex_0 == "Vacant") return 0;
      cout << n-1 << endl;
      cin >> sex_mid;
      if(sex_mid == "Vacant") return 0;
      continue;
    }else{
      int mid = (right + left) / 2;
      cout << mid << endl;
      cin >> sex_mid;
      if(sex_mid == "Vacant") return 0;

      if(sex_mid == sex_0){
        if(mid % 2 == 0){
          right = mid;
        }else{
          left = mid;
        }
      }else{
        if(mid % 2 == 0){
          left = mid;
        }else{
          right = mid;
        }
      }
    }
  }
  return 0;
}


Measured memory_bytes: 852
#include <stdio.h>

int main()
{
  char a[100], b[100], c[100];
  int ia=0, ib=0, ic=0;
  scanf("%s %s %s", a,b,c);
  
  char ans,index = 'a';
  while(index != '\0'){
    if(index == 'a'){
      index = a[ia];
      ans = 'A';
      ia++;
    }
    else if(index == 'b'){
      index = b[ib];
      ans = 'B';
      ib++;
    }
    else if(index == 'c'){
      index = c[ic];
      ans = 'C';
      ic++;
    }  
  }
  printf("%c", ans);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
//#include "lib/bigint2.h"

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; }  template <class T, class ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amax(T& a,T b){ if(a>b) a=b;}


int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n, k, ans =0;
	cin >>n >>k;
	VL h(n);
	rep(i, n) cin >>h[i];
	
	sort(all(h));
	rep(i, k) if(n-1-i>=0) h[n-1-i]=0;
	
	ll sm = accumulate(all(h), 0LL);
	cout << sm <<"\n";
	return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

#define MAX 246913

int main(void){
 
  int num[MAX]={0};
  int i,j,n;
  int prime[MAX]={0};

  for(i=2;i<=MAX;i++){                   //配列の2番以上の全てのメモリに1を書き込み
    prime[i]=1;
  }

  for(i=2;i<=MAX;i++){                   //配列の素数ではない番号のメモリに0を書き込み
    if(prime[i]==1){
      for(j=2;i*j<=MAX;j++){
	prime[i*j]=0;
      }
    }
  }

  j=0;

  while(1){
    scanf("%d", &n);                     //入力

    if(n == 0 || n > 123456)             //0もしくは不適切な値が入力されるとループ終了
      break;

    for(i=n+1;i<=n*2;i++){               //入力されたnに対して，n以上2n以下の素数の数を数える
      num[j] += prime[i];
    }
    j++;
  }

  for(i=0;i<j;i++){                     //出力
    printf("%d\n", num[i]);
  }

  return 0;
}

Measured memory_bytes: 2536
# include <iostream>

int slime[110] = {};
int n;

void solve();

int main()
{
    std::cin >> n;
    
    for (int i{}; i < n; ++i)
        std::cin >> slime[i];

    solve();
}


void solve()
{
    int result{};

    int col = 10000;
    for (int i{}; i < n - 1; ++i)
    {
        if (slime[i] == slime[i + 1]) {
            ++result;
            slime[i + 1] = col--;
        }
    }

    std::cout << result;

}

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
using namespace std;
typedef long long ll;
#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--)
#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))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}
int main() {
    ll n, p; cin >> n >> p;
    // [24 3]
    // 24 1 1
    // 12 2 1
    // 8 3 1
    // 6 4 1
    // 6 2 2 <- 最大

    // [30 3]
    // 30 1 1
    // 15 2 1
    // 10 3 1
    // 6 5 1
    // 5 3 2

    // [40 3]
    // 40 1 1
    // 20 2 1
    // 10 4 1
    // 10 2 2

    // [81 3]
    // 3 3 3

    // Pが10^12で、log2(1e12) = 39.86
    if (p == 1) {
        cout << 1 << endl;
    } else if (n == 1) {
        cout << p << endl;
    } else {
        ll res = 1;
        FOR(i, 2, 1000000000000) {
            if (p % (ll) pow(i, n) == 0) {
                res = i;
            } else if (pow(i, n) > p) {
                break;
            }
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 4044
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <functional>
using namespace std;

int main()
{
	int n;
	cin >> n;
	auto e = map<int, int>(), o = map<int, int>();
	e[0] = 0;
	o[0] = 0;
	for(auto i = 0; i < n; ++i){
		int v;
		cin >> v;
		if(i % 2 == 0) ++e[v];
		else ++o[v];
	}
	auto es = vector<pair<int, int>>(e.size()), os = vector<pair<int, int>>(o.size());
	int p = 0;
	for(auto it : e) es[p++] = make_pair(it.second, it.first);
	sort(es.begin(), es.end(), greater<pair<int, int>>());
	p = 0;
	for(auto it : o) os[p++] = make_pair(it.second, it.first);
	sort(os.begin(), os.end(), greater<pair<int, int>>());
	cout << n - (es[0].second != os[0].second ? es[0].first + os[0].first : max(es[0].first + os[1].first, es[1].first + os[0].first)) << endl;
	return 0;
}

Measured memory_bytes: 5760
#include <iostream>
#include <algorithm>
 
using namespace std;
 
const int N = 200005;
 
int n;
int a[N], b[N];
 
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i ++ ) cin >> a[i];
    for (int i = 0; i < n; i ++ ) cin >> b[n - i]; // 读入并将 B 翻转
    
    bool success = true; // 标记是否有合法的 B 的重排
    
    // 找第一个 a[i] == b[i] 的 i
    // 如果找到之后 success 被更新成 false 了，直接跳出
    for (int i = 1; i <= n && success; i ++ )
        if (a[i] == b[i])
        {
            // 这里要试图将 B 和 A 中相等的一段，用 B 的其它元素替换掉
            // 如果 a[i] 和 b[i] 不相等了，说明是 B 中和 A 相等的部分替换完了，直接跳出
            for (int k = 1; k <= n && a[i] == b[i]; k ++ )
            // 如果找到了 B 中的一个元素 b[k], 满足将 b[k] 与 b[i] 交换之后， a[k] != b[k] 且 a[i] != b[i]，
                if (b[k] != b[i] && a[k] != b[i])
                    swap(b[i], b[k]), i ++ ; // 那么将 b[i] 与 b[k] 交换，并让 i 走到下一个要替换的位置
 
            // 如果试图替换后 b[i] 仍与 a[i] 相同，说明不存在一组合法答案，让 success = false
            if (a[i] == b[i]) success = false;
        }
 
    puts(success ? "Yes" : "No");
    if (success) for (int i = 1; i <= n; i ++ ) cout << b[i] << ' '; 
 
    return 0;
}

Measured memory_bytes: 5192
#pragma GCC optimize ("O3")

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
using namespace std;

using QWORD = unsigned long long;
using SQWORD = long long;
using DWORD = unsigned int;
using SDWORD = int;
using WORD = unsigned short;
using SWORD = short;
using DOUBLE = double;
using FLOAT = float;

#define MIN_SDWORD (-2147483648)
#define MAX_SDWORD (2147483647)
#define ArrayLength(a)  (sizeof(a) / sizeof(a[0]))

static inline QWORD MAX(QWORD a, QWORD b) { return a > b ? a : b; }
static inline DWORD MAX(DWORD a, DWORD b) { return a > b ? a : b; }
static inline SDWORD MAX(SDWORD a, SDWORD b) { return a > b ? a : b; }
static inline QWORD MIN(QWORD a, QWORD b) { return a < b ? a : b; }
static inline DWORD MIN(DWORD a, DWORD b) { return a < b ? a : b; }
static inline SDWORD MIN(SDWORD a, SDWORD b) { return a < b ? a : b; }

#define BYTE_BITS   (8)
#define WORD_BITS   (16)
#define DWORD_BITS  (32)
#define QWORD_BITS  (64)

using M_BOOL = bool;
#define M_TRUE (true)
#define M_FALSE (false)
#define DIVISOR (1000000007)

#define MAX_FACTORY (60)
static DWORD adwFactoryNum[MAX_FACTORY];
static DWORD adwFactoryCumMul[MAX_FACTORY];
static DWORD s_dwFactoryNum = 0;

static inline void inputString(char *pcStr)
{
    char *pcCur = pcStr;
    for (;;) {
        char c = getchar();
        if (('\n' == c) || (EOF == c)) {
            break;
        }
        *pcCur = c;
        pcCur++;
    }
    *pcCur = '\0';
}

static DWORD getIdx(char c)
{
    return (DWORD)(c - 'a');
}

static inline M_BOOL registTbl(char *pcTbl, char ca, char cb)
{
    DWORD dwIdx = getIdx(ca);
    if (0 == pcTbl[dwIdx]) {
        pcTbl[dwIdx] = cb;
    } else {
        if (cb != pcTbl[dwIdx]) {
            return M_FALSE;
        }
    }
    return M_TRUE;
}

#define MAX_STRING (200000 + 1)
#define MAX_ALPHABETS (26)
int main()
{
    char acStr1[MAX_STRING];
    char acStr2[MAX_STRING];
    char acTransFormationTable1[MAX_ALPHABETS];
    char acTransFormationTable2[MAX_ALPHABETS];
    M_BOOL bMatched = M_FALSE;
    char *pcCur1 = acStr1;
    char *pcCur2 = acStr2;

    inputString(acStr1);
    inputString(acStr2);

    memset(acTransFormationTable1, 0, sizeof(acTransFormationTable1));
    memset(acTransFormationTable2, 0, sizeof(acTransFormationTable2));

    for (;;) {
        char c1, c2;
        c1 = *pcCur1;
        c2 = *pcCur2;

        if ((*pcCur1 == '\0') || (*pcCur2 == '\0')) {
            if (*pcCur2 == *pcCur1) {
                bMatched = M_TRUE;                
            } else {
                bMatched = M_FALSE;
            }
            break;
        }

        if (!registTbl(acTransFormationTable1, c1, c2)) {
            break;
        };
        if (!registTbl(acTransFormationTable2, c2, c1)) {
            break;
        }
        pcCur1++;
        pcCur2++;
    }

    if (bMatched) {
        printf("Yes");
    } else {
        printf("No");
    }

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;

pbds t;
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	vi l, r; vi vec; vector<int> tmp;
	int n; cin >> n;
	for(int i = 0; i < n; i++)
	{
		int x; cin >> x;
		tmp.pb(x);
		vec.pb(x);
	}
	sort(tmp.begin(), tmp.end());
	for(int i = 0; i < n; i++)
	{
		vec[i] = lower_bound(tmp.begin(), tmp.end(), vec[i]) - tmp.begin();
		//cout << vec[i] << ' ';
	}
	/*
	for(int i = 0; i < n; i++)
	{
		int x = vec[i];
		if(i&1) r.pb(x);
		else l.pb(x);
	}
	sort(l.begin(), l.end());
	sort(r.begin(), r.end());
	int ans = 0;
	vec.clear();
	for(int i = 0; i < n; i++)
	{
		int pos = i/2;
		if(i&1) vec.pb(r[pos]);
		else vec.pb(l[pos]);
	}
	t.insert(vec[0]);
	for(int i = 1; i < n; i++)
	{
		//cout << vec[i] << endl;
		int l = t.order_of_key(vec[i]);
		//cout << l << ' ' << t.size() << endl;
		ans += (t.size() - l);
		t.insert(vec[i]);
	}
	*/
	int ans = 0;
	for(int i = 0; i < n; i++)
	{
		if(i%2 != vec[i]%2) ans++;
	}
	ans>>=1;
	cout << ans;
}


Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
int Inf = (1 << 30);
ll inf = (1LL << 60);
const int MOD = 1e9 + 7;
const int T = 1000000001;
int main() {
	int a, b;
	cin >> a >> b;
	int i;
	for (i = 1; i <= 1000000; i++) {
		int tmp1 = i * 0.08;
		int tmp2 = i * 0.1;
		if (tmp1 == a && tmp2 == b) {
			cout << i;
			return 0;
		}
	}
	cout << -1;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<cmath>
using namespace std;
int main()
{
    int w,x,y,z;
    cin>>w>>x>>y>>z;
    if(w>x){w=x;}
    else{}
    if(y>z){y=z;}
    else{}
    cout<<w+y<<endl;
    return 0;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

const int64 mod = 1e9+7;

int64 fact[1010], inv[1010];

int64 mpow(int64 a, int64 b){
	if(b == 0) return 1;
	if(b%2) return a*mpow(a, b-1)%mod;
	int64 ret = mpow(a, b/2);
	return ret*ret%mod;
}

void init(){
	fact[0] = 1; inv[0] = 1;
	REP(i, 1009) fact[i+1] = fact[i]*(i+1)%mod;
	REP(i, 1010) inv[i] = mpow(fact[i], mod-2);
}

int64 comb(int64 a, int64 b){
	if(a < b) return 0;
	return fact[a]*inv[b]%mod*inv[a-b]%mod;
}

int main(void){
	int64 N, K;
	cin >> N >> K;
	int64 res = 0;
	if(K == 0){
		cout << N*N << endl;
		return 0;
	}
	FOR(i, K+1, N+1){
		res += (i-K)*((N+1)/i);
		if((N+1)%i >= K)
			res += ((N+1)%i-K);
	}
	cout << res << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	read := bufio.NewReader(os.Stdin)
	w := bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var k int
	fmt.Fscan(read, &k)

	sum := 0
	for p := 1; p <= k; p++ {
		for q := 1; q <= k; q++ {
			for r := 1; r <= k; r++ {
				sum += GCD(GCD(p, q), r)
			}
		}
	}
	fmt.Fprintln(w, sum)
}

func GCD(a, b int) int {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}


Measured memory_bytes: 1860
#include <bits/stdc++.h>
using namespace std;
int main(void){

    int a, b, c, cnt = 0;
    cin >> a >> b >> c ;
    
    for(int i = a; i <= b; i++){
        if(i % c == 0){
            cnt++;
        }
    }
    
    cout << cnt << endl;
    
}


Measured memory_bytes: 3592
from collections import deque

N = int(input())

q = deque()

for i in range(N):
    A, B = map(int, input().split())
    q.append((B, A))

work = sorted(q)

A_sum = 0
for w in work:
    A_sum += w[1]

    if A_sum > w[0]:
        print("No")
        exit(0)

print("Yes")

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll cnt(ll i, ll j){

  if(i < j){
    swap(i, j);
  }

  ll ret = 0;
  ret = i * (i+1)/2 + j * (j-1)/2;

  return ret;

}

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

  string s;
  cin >> s;

  ll cntu = 0;
  ll cntd = 0;

  ll ans = 0;
  rep(i, s.length()){

    if(s[i] == '<' && cntd > 0){
      ans += cnt(cntu, cntd);
      cntd = 0;
      cntu = 1;
    }else if(s[i] == '<'){
      cntu++;
    }else{
      cntd++;
    }
  }

  ans += cnt(cntu, cntd);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1172
#include <bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define int long long
#define st first
#define nd second
#define rd third
#define FOR(i, a, b) for(int i =(a); i <=(b); ++i)
#define RE(i, n) FOR(i, 1, n)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define REP(i, n) for(int i = 0;i <(n); ++i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
template<typename TH> void _dbg(const char* sdbg, TH h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename TH, typename... TA> void _dbg(const char* sdbg, TH h, TA... t) {
  while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}
#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
#define next ____next
#define prev ____prev
#define left ____left
#define hash ____hash
typedef long long ll;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<pair<int, int> > VPII;
typedef vector<pair<ll, ll> > VPLL;

template<class C> void mini(C&a4, C b4){a4=min(a4, b4); }
template<class C> void maxi(C&a4, C b4){a4=max(a4, b4); }
template<class T1, class T2>
ostream& operator<< (ostream &out, pair<T1, T2> pair) { return out << "(" << pair.first << ", " << pair.second << ")";}
template<class A, class B, class C> struct Triple { A first; B second; C third;
  bool operator<(const Triple& t) const { if (st != t.st) return st < t.st; if (nd != t.nd) return nd < t.nd; return rd < t.rd; } };
template<class T> void ResizeVec(T&, vector<int>) {}
template<class T> void ResizeVec(vector<T>& vec, vector<int> sz) {
  vec.resize(sz[0]); sz.erase(sz.begin()); if (sz.empty()) { return; }
  for (T& v : vec) { ResizeVec(v, sz); }
}
typedef Triple<int, int, int> TIII;
template<class A, class B, class C>
ostream& operator<< (ostream &out, Triple<A, B, C> t) { return out << "(" << t.st << ", " << t.nd << ", " << t.rd << ")"; }
template<class T> ostream& operator<<(ostream& out, vector<T> vec) { out<<"("; for (auto& v: vec) out<<v<<", "; return out<<")"; }

const int N = 2e6 + 5;
int a[N];
int32_t main() {

  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(10);
  cerr << fixed << setprecision(10);
  cin.tie(0);
  //double beg_clock = 1.0 * clock() / CLOCKS_PER_SEC;
  
  int n;
  cin>>n;
  RE (i, n) {
    cin>>a[i];
  }
  int res = 0;
  RE (i, n) {
    res += (a[a[i]] == i && i < a[i]);
  }
  cout<<res<<endl;
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
ll mod=1000000007;

int main(){
    std::ios::sync_with_stdio(false);
    int ar[31]={0};
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        while(a--){
            int b;
            cin>>b;
            ar[b]++;
        }
    }
    int ans=0;
    for(int i=1;i<31;i++)if(ar[i]==n)ans++;
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256