akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)


int main() {
	
	lint N;
	cin >> N;
	vector<lint>A(N);
	rep(i, N) {
		cin >> A[i];
	}
	vector<lint>V(N + 3);
	rep(i, N) {
		V[A[i]]++;
	}
	lint sum = 0;
	rep(i, V.size()) {
		if (V[i] >= 2) {
			sum += V[i]*(V[i]-1)/2;
		}
	}
	rep(i, N) {
		cout << sum - max(lint(0), V[A[i]] - 1) << endl;
	}
}

Measured memory_bytes: 5760
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)

typedef long long ll;

struct E {
  int v, i;
};

vector<E> g[100000+10];
int n;

int es[100000+10][3];

void go(int p, int u, int c) {
  int c2 = 1;
  for(const E& e : g[u]) {
    if(e.v == p) {
      continue;
    }
    if(c2 == c) {
      ++c2;
    }
    es[e.i][2] = c2;
    go(u, e.v, c2);
    ++c2;
  }
}

int main(void) {
  scanf("%d", &n);
  REP(i, n-1) {
    int u, v;
    scanf("%d%d", &u, &v);
    --u;
    --v;
    es[i][0] = u;
    es[i][1] = v;
    g[u].push_back((E){v, i});
    g[v].push_back((E){u, i});
  }
  int k = 0;
  REP(i, n) {
    k = max(k, (int)g[i].size());
  }
  go(-1, 0, -1);
  printf("%d\n", k);
  REP(i, n-1) {
    printf("%d\n", es[i][2]);
  }
  return 0;
}


Measured memory_bytes: 8832
# div2019-2B - Picking Up
from collections import defaultdict

n = int(input())
arr = sorted([list(map(int, input().rstrip().split())) for _ in range(n)])
cnt = defaultdict(int)
for i in range(n):
    for j in range(i + 1, n):
        dif = (arr[j][0] - arr[i][0], arr[j][1] - arr[i][1])
        cnt[dif] += 1
print(n - max(cnt.values(), default=0))

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

const int N = 220000;

vector<int> con[N];

int root[N];
inline int find_root(int u) {
	if (u == root[u]) return root[u];
	return root[u] = find_root(root[u]);
}

int vis[N];
vector<int> cur;
void dfs(int u) {
	vis[u] = 1;
	cur.push_back(u);
	for (int v : con[u]) if (!vis[v]) dfs(v);
}

int cnt[N];
int ans[N];

int main() {
	
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	int n, m, k; cin >> n >> m >> k;
	for (int i = 1; i <= n; i++) root[i] = i;
	while (m--) {
		int u, v; cin >> u >> v;
		int a = find_root(u), b = find_root(v);
		if (a == b) continue;
		root[a] = b;
	}
	while (k--) {
		int u, v; cin >> u >> v;
		con[u].push_back(v), con[v].push_back(u);
	}
	for (int i = 1; i <= n; i++) if (!vis[i]) {
		cur.clear();
		dfs(i);
		for (auto u : cur) cnt[find_root(u)] = 0;
		for (auto u : cur) cnt[find_root(u)]++;
		for (auto u : cur) ans[u] = cnt[find_root(u)];
	}
	for (int i = 1; i <= n; i++) cout << ans[i] << " \n"[i == n];
	
	return 0;
}


Measured memory_bytes: 14872
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
using namespace std;

int main(){
    int n,k;
    cin >> n >> k;
    int height[n];
    for(int h=0;h<n;h++){
        cin >> height[h];
    }
    int ans=0;
    for (int h=0;h<n;h++){
        ans = ans + (height[h] >= k);
    }
    cout << ans << endl;
}

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

#define INF 0x7fffffff;

int main() {
  int a,b,m,ans;
  int ma=INF;
  int mb=INF;
  cin >> a >> b >> m;
  vector<int> aa(a);
  vector<int> bb(b);
  for(int i=0; i<a; i++) {
    cin >> aa[i];
    ma = min(ma,aa[i]);
  }
  for(int i=0; i<b; i++) {
    cin >> bb[i];
    mb = min(mb,bb[i]);
  }
  ans = ma + mb;

  for(int i=0; i<m; i++) {
    int x , y , c;
    cin >> x >> y >> c;
    ans = min(ans , aa[x-1]+bb[y-1]-c);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1152
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    A = LI()
    G = [[] for _ in range(N)]
    dp = [inf for _ in range(N)]
    ans = [0] * N
    for i in range(N-1):
        a, b = LI_()
        G[a].append(b)
        G[b].append(a)

    def update_dp(i):
        j = bisect.bisect_left(dp, A[i])
        before_val = dp[j]
        dp[j] = A[i]
        return j, before_val

    visited = set()

    def dfs(v):
        visited.add(v)

        j = bisect.bisect_left(dp, A[v])
        before_val = dp[j]
        dp[j] = A[v]

        ans[v] = bisect.bisect_left(dp, inf)
        for next_v in G[v]:
            if next_v in visited:
                continue
            dfs(next_v)

        # restore dp
        dp[j] = before_val

    dfs(0)
    for a in ans:
        print(a)

main()



Measured memory_bytes: 388860
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read


#n,m = [int(i) for i in read().split()]

s = input()

n = len(s)
t = s[:(n-1)//2]
u = s[(n-1)//2+1:]

if s==s[::-1] and t==t[::-1] and u==u[::-1]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = sc.nextInt();
        }
        
        long min = 10000000000L;
        for (int i = 1; i <= 100; i++) {
            long tmp = 0;
            for (int j = 0; j < n; j++) {
                tmp += (long)Math.pow(array[j] - i, 2);
            }
            min = Math.min(min, tmp);
        }
        System.out.println(min);
    }
}


Measured memory_bytes: 23124
#include <iostream>
#include <string>
using namespace std;
int main () {
  string s, t;
  int a, b;
  string u;
  cin >> s >> t;
  cin >> a >> b;
  cin >> u;
  if (s == u){
    cout << --a << " " << b << endl;
  }else if (t == u){
    cout << a << " " << --b << endl;
  }else{
    cout << a << " " << b << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int n,m;
    cin >> n >> m;
    int lmax = 0;
    int rmin = 100000;
    rep(i,m){
        int l,r;
        cin >> l >> r;
        lmax = max(lmax,l);
        rmin = min(rmin,r);
    }
    //cout << lmax << " " << rmin << endl;
    if(rmin < lmax)cout << 0 << endl;
    else cout << rmin - lmax+1 << endl;
    return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 50;
constexpr double pi=3.14159265358979;

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;
}
using namespace std;

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


void solve(){
    int n;
    cin>>n;
    int cnt=0;
    vector<bool>prime=prime_table(55000);
    rep(i,55001){
      if(prime[i]&&i%5==1){//常に5で割った余りが１であれば5個選ぶと5の倍数になる
        ++cnt;
        cout<<i<<" ";
      }
      if(cnt==n)break;
    }
}

signed main(){
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	solve();
	return 0;
}


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

const int maxn = 2e5 + 5;
char s[maxn];
int fa[maxn];
bool gd[maxn];

int find(int x) {
    if (x == fa[x]) return x;
    return fa[x] = find(fa[x]);
}

void merge(int x, int y) {
    fa[find(x)] = find(y);
}

bool solve(int x, int y) {
    int n = strlen(s);
    for (int i = 0; i < n; ++i) fa[i] = i;

    for (int i = x; i <= y; ++i) {
        if (s[i] == '#') continue;
        for (int j = 1; j <= 2; ++j) {
            if (i + j < n && s[i + j] != '#')
                merge(i, i + j);
        }
    }
    return find(x) == find(y);
}

int main() {
    int n, a, b, c, d; scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
    scanf("%s", s);

    --a, --b, --c, --d;
    if (a > b) {
        swap(a, b);
        swap(c, d);
    }

    if (c < a || d < b) {
        puts("No");
        return 0;
    }

    if (c < d) {
        if (solve(a, c) && solve(b, d)) puts("Yes");
        else puts("No");
        return 0;
    }

    if (!solve(a, c) || !solve(b, d)) {
        puts("No");
        return 0;
    }

    solve(a, c);

    vector<int> v;
    for (int i = a; i <= c; ++i) {
        if (find(i) == find(a))
            gd[i] = true;
    }

    solve(b, d);

    for (int i = b; i <= d; ++i) {
        if (find(i) == find(b)) {
            if (i - 1 >= a && gd[i - 1] && i + 1 <= c && gd[i + 1]) {
                puts("Yes");
                return 0;
            }
        }
    }
    puts("No");
}


Measured memory_bytes: 3200
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a) = min((a), (b)))
#define chmax(a, b) ((a) = max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);
const double eps = 1e-10;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, -1, 0, 1};

int main(){
    string s; cin>>s;
    map<int, int> mp;
    for(int i=0; i<4; i++){
        mp[s[i] - 'A']++;
    }

    int cnt = 0;
    bool valid = true;
    for(auto i:mp){
        if(i.second != 2){
            valid = false;
        }
        cnt++;
    }

    if(cnt == 2 && valid){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

int main() {
    int N; string S;
    cin >> N >> S;
    long long r = 0, g = 0, b = 0;
    for (auto c : S) {
        if (c == 'R') ++r;
        else if (c == 'G') ++g;
        else ++b;
    }
    long long all = r * g * b;
    long long sub = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = i+1; j < N; ++j) {
            if (S[i] == S[j]) continue;
            int k = j*2-i;
            if (k >= N || S[k] == S[i] || S[k] == S[j]) continue;
            ++sub;
        }
    }
    cout << all - sub << endl;
}

Measured memory_bytes: 3656
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int P[100001];

int Find(int A) {
	if (P[A] < 0) return A;
	return P[A] = Find(P[A]);
}

bool Unite(int A, int B) {
	int a = Find(A);
	int b = Find(B);
	if (a == b) return false;
	if (P[a] > P[b]) swap(a, b);
	P[a] += P[b];
	P[b] = a;
	return true;
}

int Size(int A) {
	return -P[Find(A)];
}

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


	int N, M, K;
	cin >> N >> M >> K;

	rep1(i, N) P[i] = -1;

	vector<int> f[100001], b[100001];

	rep(i, M) {
		int a, b;
		cin >> a >> b;
		Unite(a, b);
		f[a].pb(b);
		f[b].pb(a);
	}
	rep(i, K) {
		int c, d;
		cin >> c >> d;
		b[c].pb(d);
		b[d].pb(c);
	}

	rep1(i, N) {
		int kotae = Size(i) - 1;
		for (int p : f[i]) {
			if (Find(i) == Find(p)) {
				kotae--;
			}
		}
		for (int p : b[i]) {
			if (Find(i) == Find(p)) {
				kotae--;
			}
		}
		cosp(kotae);
	}


	Would you please return 0;
}

Measured memory_bytes: 12280
#include<iostream>
#include<cstring>
#include<cmath>
#include<cstdio>

#define maxn 100005

using namespace std;

inline int getint()
{
	int num=0,flag=1;char c;
	while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;
	while(c>='0'&&c<='9')num=num*10+c-48,c=getchar();
	return num*flag;
}

int n;
char s[maxn];
int ans;

int main()
{
    n=getint();
	scanf("%s",s+1);
	for(int i=1;i<=n;i++)if(s[i]!=s[i-1])ans++;
	printf("%lld\n",ans);
}


Measured memory_bytes: 384
n = gets.to_i
commands = Array.new(n) {gets.chomp.split}

class Doubly_linked_node
  attr_accessor :next, :prev, :key
  def initialize
    @next = nil
    @prev = nil
    @key = nil
  end
end

class Doubly_linked_list
  def initialize
    @first_node = Doubly_linked_node.new
    @last_node = Doubly_linked_node.new
    @first_node.next = @last_node
    @last_node.prev = @first_node
  end


  def insert(key)
    tmp = Doubly_linked_node.new
    tmp.key = key
    tmp.next = @first_node.next
    tmp.prev = @first_node
    @first_node.next.prev = tmp
    @first_node.next = tmp
  end

  def delete(key)
    cur = @first_node.next
    while cur.key != nil
      if cur.key == key
        cur.next.prev = cur.prev
        cur.prev.next = cur.next
        break
      end
      cur = cur.next
    end
  end

  def delete_first
    @first_node.next.next.prev = @first_node
    @first_node.next = @first_node.next.next
  end

  def delete_last
    @last_node.prev.prev.next = @last_node
    @last_node.prev = @last_node.prev.prev
  end

  def puts_answer
    ans = []
    cur = @first_node.next
    while cur.key != nil
      ans.push(cur.key)
      cur = cur.next
    end
    puts ans.join(" ")
  end
end

dll = Doubly_linked_list.new

commands.each do |s|
  case s[0]
  when "insert"
    dll.insert s[1]
  when "delete"
    dll.delete s[1]
  when "deleteFirst"
    dll.delete_first
  when "deleteLast"
    dll.delete_last
  end
end

dll.puts_answer


Measured memory_bytes: 301436
import java.awt.print.Printable;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		
		Scanner scan =new Scanner(System.in);
		int n=scan.nextInt();
		int[] arr=new int[n];
		for(int i=0;i<n;i++){
			arr[i]=scan.nextInt();
		}
		insertsort(arr,n);
	}

	public  static void insertsort(int[] arr,int n){
		arrPrint(arr);
		for(int i=1;i<n;i++){
			int tmp=arr[i];
			int j=i-1;
			while(j>=0&&arr[j]>tmp){
				arr[j+1]=arr[j];
				j--;
			}
			arr[j+1]=tmp;
			arrPrint(arr);
		}
	}
	public static void arrPrint(int[] arr){
		int i=0;
		for(i=0;i<arr.length-1;i++)
			System.out.print(arr[i]+" ");
		System.out.println(arr[i]);
	}
}



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

int main() {
	int N;
	cin >> N;
	string ans;
	do {
		if (N % -2 == -1) {
			N -= 1;
			ans += '1';
		}
		else ans += to_string(N % 2);
	} while (N /= -2);
	reverse(ans.begin(), ans.end());
	cout << ans;
}

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

typedef long long ll;

int MOD=1000000007;


int main(){
  ll N;
  cin >> N;
  vector<ll> x(N+10), y(N+10), h(N+10);
  ll x1, y1, h1;
  for(int i=0; i<N; i++){
    cin >> x[i] >> y[i] >> h[i];
    if(h[i]>=1){
      x1=x[i]; 
      y1=y[i]; 
      h1=h[i];
    }
  }
 
  for(int i=0; i<=100; i++){
    for(int j=0; j<=100; j++){
      ll H=max(0LL, h1+abs(i-x1)+abs(j-y1));
      bool ans=true;
      for(int k=0; k<N; k++){
	if(h[k] != max(0LL, H-abs(i-x[k])-abs(j-y[k]))){
	  ans=false;
	  break;
	}
      }
      if(ans){
	cout << i << " " << j << " " << H << endl;
	return 0;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int w = scanner.nextInt();
        final int h = scanner.nextInt();
        final int x = scanner.nextInt();
        final int y = scanner.nextInt();

        final BigDecimal divide = BigDecimal.valueOf(w).multiply(BigDecimal.valueOf(h)).divide(BigDecimal.valueOf(2));
        final int able = x * 2 == w && y * 2 == h ? 1 : 0;
        System.out.println(divide + " " + able);
    }
}


Measured memory_bytes: 22740
#include<iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <map>

using namespace std;


int main()
{
    // 整数の入力
    long long N,maxindex,minindex,maxNumber,minNumber,i,inputNumber;
    maxNumber = -10000000;
    minNumber = 10000000;
    cin >> N;
    for (i= 1;i<= N;i++){
        cin >> inputNumber;
        if (inputNumber < minNumber){
            minNumber = inputNumber;
            minindex = i;
        }

        if(inputNumber > maxNumber){
            maxNumber = inputNumber;
            maxindex = i;
        }
    }

    if (maxNumber > - minNumber){
        cout << 2 * N << endl;
        cout << maxindex << " " << 1 << endl;
        cout << maxindex << " " << 1 << endl;
        for (i = 1;i<N;i++){
            cout << i << " " << i+1 << endl;
            cout << i << " " << i+1 << endl;
        }
    }else{
        cout << 2 * N << endl;
        cout << minindex << " " << N << endl;
        cout << minindex << " " << N << endl;
        for (i = N;i>1;i--){
            cout << i << " " << i-1 << endl;
            cout << i << " " << i-1 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
ll mod = 1e9 + 7;

using namespace std;



int main()

{
	int A,B,C;

	cin >> A >> B>>C;
	bool flg = false;

	for (int i = 1; i <= B; i++)
	{
		int x = A * i;
		if (x % B == C)
		{
			flg = true;
			break;
		}
	}
	if (flg)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO"<< endl;
	}
	

	return 0;
	
}


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

using namespace std;

int N, M;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int64_t t1, t2, a1, a2, b1, b2;
  cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;

  if (a1 > b1 == a2 > b2) {
    cout << 0 << endl;
    return 0;
  }

  a1 *= t1;
  a2 *= t2;
  b1 *= t1;
  b2 *= t2;

  if (b1 < a1) {
    swap(a1, b1);
    swap(a2, b2);
  }
  auto s1 = a1 + a2;
  auto s2 = b1 + b2;

  if (s1 == s2) {
    cout << "infinity" << endl;
    return 0;
  }

  auto diff = abs(s1 - s2);

  int64_t x;
  if (s1 < s2) {
    cout << 0 << endl;
    return 0;
    x = a1;
  } else {
    x = b1 - a1;
  }
  auto d = x / diff;
  bool just = x % diff == 0;
  int64_t ans = d * 2 + 1;
  if (just) --ans;
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

class Main {
    public static long knapsack2(long[] w, int[] v, long C) {
        int n = w.length;

        int max_v = 100000; // N <= 100, v[i] <= 1000
        long[] dp = new long[max_v+1]; // value为dp[i]需要的最小权重
        Arrays.fill(dp, Integer.MAX_VALUE);
        

        dp[0] = 0;
        for (int i = 1; i <= n; i++) {
            for (int j = max_v; j >= 1; j--) {
                if (j >= v[i-1]) {
                    dp[j] = Math.min(dp[j], dp[j- v[i-1]]+w[i-1]);
                }
            }
        }

        long ans = 0;
        for (int j = max_v; j >= 1; j--) {
            if (dp[j] <= C) {
                ans = j;
                break;
            }
        }
        return ans;
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        long C = in.nextLong();

        long[] w = new long[N];
        int[] v = new int[N];
        for (int i = 0; i < N; i++) {
            w[i]  = in.nextLong();
            v[i] = in.nextInt();
        }
        in.close();

        // call function hear
        long ret = knapsack2(w, v, C);
        System.out.println(ret);
    }
}

Measured memory_bytes: 22100
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////



int main(){
    int n;
    cin >> n;
	ll p = 1;
	rep(i,1,n+1){
	    p *= i;
	    p = mod(p);
	}
	P(p);
	return  0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1 << 29;
const int MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    // 値：個数のmap
    map<long long, long long> mp;
    long long a;
    rep(i, n) {
        cin >> a;
        mp[a] += 1;
    }

    int q;
    cin >> q;

    // 最初に全ての和を求めておく
    long long sum = 0;
    for (auto itr : mp) {
        sum += itr.first * itr.second;
    }

    // Q回操作
    int b, c;
    rep(i, q) {
        cin >> b >> c;

        //  値Cの個数に値Bの個数を足して値Bの個数を0にする
        long long num_b;
        num_b = mp[b];
        mp[c] += num_b;
        mp[b] = 0;

        // sumの更新をする
        sum += (c - b) * num_b;
        cout << sum << endl;
    }
}


Measured memory_bytes: 9548
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    int n; cin >> n;
    vector<int> h(n);
    for(int i = 0; i < n; i++) cin >> h[i];
    h.front()--;
    for(int i = 1; i < n; i++)
    {
        if(h[i - 1] < h[i]) h[i]--;
    }
    bool ok = true;
    for(int i = 1; i < n; i++)
    {
        if(h[i - 1] > h[i]) ok = false;
    }
    cout << (ok ? "Yes" : "No") << endl;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 640
n = gets.to_i
ans = 10 ** 6

(n+1).times do |i|
    c = i.to_s(6).chars.inject(0) {|r, v| r + v.to_i}
    c += (n - i).to_s(9).chars.inject(0) {|r, v| r + v.to_i}
    ans = c if ans > c
end

puts ans

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

int main() {
    int n,a[100],tmp;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n/2; i++) {
        tmp = a[i];
        a[i] = a[n-i-1];
        a[n - i-1] = tmp;
    }
    /*
    for (int i = 0; i < n-1; i++) {
        for (int j = i; j < n; j++) {
            
           if (a[i] < a[j]) {
                tmp = a[i];
                a[i] = a[j];
                a[j] = tmp;
            }
        }
    }
            */

    for (int i = 0; i < n-1; i++) {
        printf("%d ",a[i]);
    }
    printf("%d\n",a[n-1]);

    return 0;
}



Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

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

    ll ans = 0;
    for (ll a = 1; a < N; a++) {
        ans += (N - 1) / a;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int a,b;
int main()
{
	cin>>a>>b;
	cout<<max(a+b,max(a-b,a*b))<<endl;
	return 0;
}

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

int main() {
    long long int s=1;
    int N;
    cin >> N;
    long double keta=0;

    for(int i=0; i<N; i++){
        long long int a;
        cin >> a;
        keta += log10(a);
        s *= a;
    }

    if(keta>18){
        cout << -1 << endl;
    }
    else{
        if(s > 1000000000000000000){
            cout << -1 << endl;
        }
        else{
            cout << s << endl;
        }
    }
}

Measured memory_bytes: 3896
#include<stdio.h>


int main(void){
    int a,b;
    int c[9][9];

    for(a=1;a<10;a++){
        for(b=1;b<10;b++){
            c[a][b]=a*b;
            printf("%dx%d=%d\n",a,b,c[a][b]);
        }
    }

    return 0;
}


Measured memory_bytes: 2672
n, a, b = gets.split.map(&:to_i)
ans = 0
(1..n).each do |i|
  sum = 0
  i.to_s.length.times do |j|
    sum += i.to_s[j].to_i
  end
  if (a <= sum) && (sum <= b)
    ans += i
  end
end
puts ans

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


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


  ll a,b,c;  
  cin >> a >> b >> c;
  ll d = c-a-b;
  if(d>0 && d*d - 4*a*b > 0){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
  
  return 0;
    

}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int,int> p;
const int inf=(1<<30);
#define rep(i,a,n)	for(int i=a;i<n;i++)
#define rrep(i,a,n) for(int i=(a-1);i>=n;i--)

int main(){
	ll n,h,w;
	cin>>n>>h>>w;
	ll ans=0;
	rep(i,0,n){
		ll a,b;
		cin>>a>>b;
		if(a>=h&&b>=w)ans++;
		else continue;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <stdio.h>

using namespace std;

int main(int argc, char const *argv[])
{
    int h, w;

    while(true)
    {
        cin >> h >> w;
        if (h == 0 && w == 0) {
            break;
        }
        
        for(int i = 0; i < h; i++)
        {
            for(int j = 0; j < w; j++)
            {
                if(i==0 || j==0 || i==h-1 || j==w-1)
                {
                    printf("#");
                }
                else
                {
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    
    return 0;
}



Measured memory_bytes: 3064
from collections import defaultdict
from heapq import heappop, heappush

YEN = 10**15
INF = float('inf')


class Graph:
    def __init__(self):
        self.__graph = defaultdict(list)

    def add_edge(self, source, destination, cost):
        self.__graph[source].append((destination, cost))
        self.__graph[destination].append((source, cost))

    @property
    def graph(self):
        return self.__graph


class Dijkstra:
    def __init__(self, graph, source):
        self.__costs = defaultdict(lambda: INF)
        costs = self.__costs
        costs[source] = 0
        g = graph.graph
        q = []
        heappush(q, (costs[source], source))

        while q:
            cp, p = heappop(q)
            if costs[p] < cp:
                continue
            for dst, cost in g[p]:
                alternative = cp + cost
                if costs[dst] > alternative:
                    costs[dst] = alternative
                    heappush(q, (alternative, dst))

    def minimum_cost(self, destination):
        return self.__costs[destination]


def spline(func_=int, iter_=None):
    if iter_ is None:
        iter_ = input().split()
    return map(func_, iter_)


def main():
    n, m, s, t = spline()
    g_yen = Graph()
    g_snuuk = Graph()
    for _ in range(m):
        u, v, cost, b = spline()
        g_yen.add_edge(u, v, cost)
        g_snuuk.add_edge(u, v, b)
    d_s = Dijkstra(g_yen, s)
    d_t = Dijkstra(g_snuuk, t)
    costs = [0] * n
    costs[-1] = YEN - d_s.minimum_cost(n) - d_t.minimum_cost(n)
    for i in range(n - 2, -1, -1):
        cost = YEN - d_s.minimum_cost(i + 1) - d_t.minimum_cost(i + 1)
        costs[i] = max(cost, costs[i + 1])
    for cost in costs:
        print(cost)


if __name__ == "__main__":
    main()


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

void check(vector<bool> &a, int i) {
  for (int p = 1; p * p <= i; p++) {
    if (i % p == 0) {
      int q = i / p;
      a[p] = !a[p];
      a[q] = !a[q];
      if (p * p == i) {
        a[q] = !a[q];
      }
    }
  }
}

int main() {
  int N;
  cin >> N;
  
  vector<bool> a(N + 1);
  int temp;
  for (int i = 1; i <= N; i++) {
    cin >> temp;
    a[i] = (temp == 1);
  }
  
  int cnt = 0;
  
  for (int i = N; i >= 1; i--) {
    if (a[i]) {
      cnt++;
      check(a, i);
      a[i] = !a[i];
    }
  }
  
  cout << cnt << endl;
  
  for (int i = 1; i <= N; i++) {
    if (a[i]) cout << i << " ";
  }
}

Measured memory_bytes: 1152
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <cassert>
#include <random>
#include <tuple>

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

using namespace std;
typedef long long ll;
typedef pair<int, int> P;


const int MAX_V = 110;
const ll INF = 1e18;

struct edge {
    int to, rev;
    ll cap;
    edge(int to, ll cap, int rev): to(to), cap(cap), rev(rev) { }
};

vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from, int to, ll cap) {
    G[from].push_back(edge(to, cap, G[to].size()));
    G[to].push_back(edge(from, 0, G[from].size() - 1));
}

ll dfs(int v, int t, ll f) {
    if (v == t) return f;
    used[v] = true;
    for (int i = 0; i < G[v].size(); i++) {
        edge &e = G[v][i];
        if (!used[e.to] && e.cap > 0) {
            ll d = dfs(e.to, t, min(f, e.cap));
            if (d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

ll max_flow(int s, int t) {
    ll flow = 0;
    for (;;) {
        memset(used, 0, sizeof(used));
        ll f = dfs(s, t, INF);
        if (f == 0) return flow;
        flow += f;
    }
}




int main() {
    int n; cin >> n;
    vector<int> a(n); rep(i, n) cin >> a[i];

    ll benefit  = 0;
    rep(i, n) {
        if (a[i] >= 0) {
            benefit += a[i];
            add_edge(100, i, a[i]);
        } else {
            add_edge(i, 101, abs(a[i]));
        }
    }

    rep(i, n) {
        int num1 = i + 1;
        for (int j = 2; num1*j <= n; j++) {
            int num2 = num1 * j;
            add_edge(num2-1, num1-1, INF);
        }
    }


    cout << benefit - max_flow(100, 101) << endl;



    return 0;
}

Measured memory_bytes: 256
//C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

//ここまで標準include

using namespace std;

int main() {
	long long n;
	cin >> n;
	long long ans = 0;
	if (n % 2 == 1) {
		cout << 0 << endl;
	}
	else {
		for (long long i = 0; i < 1000000; i++) {
			long long l;
			l = n / (long long)(10 * pow(5, i));
			ans += l;
		}
		cout << ans << endl;
	}
}


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

int main() {
    int W, H, x, y ,r;
    cin >> W >> H >> x >> y >> r;
    
    if(x-r < 0 || x+r > W || y-r < 0 || y+r > H ) cout << "No" << endl;
    else cout << "Yes" << endl;
}


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

int main(){
    int W,H,x,y,r;
    
    cin >> W >> H >> x >> y >> r;
    
    if(0 <= x-r && x+r <= W && 0 <= y-r  && y+r <=H ){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    
    return 0; 
}

Measured memory_bytes: 1160
#define ENABLE_DEBUG 1
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#if ENABLE_DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                \
  do {                            \
    cerr << " \033[33m (L";       \
    cerr << __LINE__ << ") ";     \
    cerr << #__VA_ARGS__ << ": "; \
    cerr << "\033[0m";            \
    debug(__VA_ARGS__);           \
    cerr << endl;                 \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

const i64 MOD = 1'000'000'007;

struct mint {
  long long x;
  mint(long long x = 0) : x((x % MOD + MOD) % MOD) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  vector<int> T(N);
  for (auto& x : T) cin >> x;
  vector<int> A(N);
  for (auto& x : A) cin >> x;

  auto solve = [&]() -> mint {
    if (T.back() != A.front()) return 0;
    const int hmax = T.back();
    int prev = hmax;
    mint ans = 1;
    int ti = N - 1;
    for (int i = N - 1; i >= 0; --i) {
      if (T[i] == hmax) {
        ti = i;
        continue;
      }
      if (T[i] > prev) return 0;
      if (T[i] == prev) {
        ans *= prev;
      }
      prev = T[i];
    }
    int ai = 0;
    prev = hmax;
    REP(i, N) {
      if (A[i] == hmax) {
        ai = i;
        continue;
      }
      if (A[i] > prev) return 0;
      if (A[i] == prev) {
        ans *= prev;
      }
      prev = A[i];
    }
    if (ai < ti) return 0;
    if (ai - ti - 1 > 0) {
      ans *= mint(hmax).pow(ai - ti - 1);
    }
    return ans;
  };

  cout << solve() << '\n';
}

Measured memory_bytes: 3924
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<queue>
#include<set>

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF (long long)(1e18)
#define EPS (1e-20)
#define MOD (int)(1e9+7)

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX 210000

int N, K;
int used[MAX];
int temp[MAX], temp2[MAX], temp3[MAX];
priority_queue <int> td[MAX];
priority_queue <int>  fuga;
vector <pair<int,int>> hoge;
vector <int>type;
priority_queue <int> hogehoge;


signed main(){
	cout<<fixed<<setprecision(7);
	
	set<int> tt;
	set<int> ttt;
	int count = 0;
	int t, d;
	int ans = 0;
	
	cin>>N>>K;
	
	for(int i = 0; i < N; i++){
		cin>>t>>d;
		hoge.push_back(make_pair(d,t));
		tt.insert(t);
		
	}
	
	sort(hoge.begin(),hoge.end());
	
	for(int i = 0; i < K; i++){
		temp[i] += hoge[N-i-1].first;
		if(used[hoge[N-i-1].second] == 0){
			temp2[i]++;
			used[hoge[N-i-1].second] = i+1;
			temp3[i] = hoge[N-i-1].second;
			count++;
		}
		temp[i+1] += temp[i];
		temp2[i+1] += temp2[i];
		// cout<<i<<" temp = "<<temp[i]<<" "<<hoge[N-i-1].first<<" "<<hoge[N-i-1].second<<endl;
	}
	
	for(int i = N-K-1; i >= 0; i--){
		td[hoge[i].second].push(hoge[i].first);
		// cout<<i<<" td "<<hoge[i].second<<" "<<hoge[i].first<<endl;
	}
	// cout<<"XXX "<<endl;
	
	for(int y : tt){//cout<<y<<" "<<" "<<tt.size()<<" "<<used[y]<<endl;
		if(used[y]) continue;
		if(!td[y].empty())hogehoge.push(td[y].top());
	}
	
		// cout<<"YYY "<<endl;
	ans = temp[K-1]+temp2[K-1]*temp2[K-1];
	
	// for(int i = 0; i < K; i++){
		// cout<<i<<" temp "<<temp[i]<<endl;
	// }
	for(int i = K-1, xx = 0, tete = tt.size(); i >= 1; i--){//cout<<i<<" "<<temp[i]<<" "<<xx<<endl;
	// cout<<temp2[i-1]<<" "<<temp2[i]+K-i<<" tete "<<tete<<endl;
		
		if(temp3[i]){
			xx += temp[i]-temp[i-1];
		} else {
			if(hogehoge.size() == 0) break;
				xx += hogehoge.top(); hogehoge.pop();
		}
		ans = max(temp[i-1]+xx+(temp2[i-1]+K-i)*(temp2[i-1]+K-i),ans);
		// cout<<" end "<<xx<<" temp[i]-> "<<temp[i-1]<<" ans = "<<ans<<endl;
		if(temp2[i-1]+K-i == tete){
			break;
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}

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

bool solve() {
  int A, B;
  string S;
  cin >> A >> B >> S;
  rep(i, 0, A) if(S[i] == '-') return false;
  if(S[A] != '-') return false;
  rep(i, A + 1, S.size()) if(S[i] == '-') return false;
  return true;
}

int main() {
  cout << (solve() ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int N,result;
  scanf("%d",&N);
    for(int i=0;i<3;i++) {
      result = N%10;
      N = N/10;
      if(result==7) {
	printf("Yes");
	break;
      }
    }
    if(result!=7) {
      printf("No");
    }
  return 0;
}

Measured memory_bytes: 1708
#include <cstdint>
#include <iostream>

using namespace std;

int32_t main() {
  while (true) {
    uint32_t h, w;
    cin >> h >> w;

    if (h == 0 && w == 0)
      break;

    uint32_t diag = h * h + w * w;

    uint32_t min_h = 200;
    uint32_t min_w = 200;
    for (uint32_t i = 1; i <= 150; i++) {
      for (uint32_t j = i + 1; j <= 150; j++) {
        uint32_t d = i * i + j * j;
        if ((diag == d && h < i) || (diag < d)) {
          if (min_h * min_h + min_w * min_w > i * i + j * j) {
            min_h = i;
            min_w = j;
          }
        }
      }
    }
    cout << min_h << " " << min_w << endl;
  }

  return 0;
}

Measured memory_bytes: 3100
Imports System.Collections.Generic
Imports System.Console

Module Program
    Sub Main()
        Dim N As Integer = NextInt()
        Dim a As Integer() = New Integer(N - 1) {}

        For i As Integer = 0 To N - 1
            a(i) = NextInt()
        Next

        Dim j As Integer = 1
        Dim dic As New Dictionary(Of Integer, Boolean)

        For i As Integer = 1 To N
            dic(j) = True
            j = a(j - 1)
            If dic.ContainsKey(j) Then
                Exit For
            ElseIf j = 2 Then
                WriteLine(i)
                Exit Sub
            End If
        Next

        WriteLine(-1)
    End Sub

    Function NextInt() As Integer
        Return CInt(NextString())
    End Function

    Function NextString() As String
        Dim result As New List(Of Char)
        Do
            Dim tmp As Integer = Read()
            If tmp < 0 Then Exit Do
            Dim nextChar As Char = Chr(tmp)

            If Not Char.IsWhiteSpace(nextChar) Then
                result.Add(nextChar)
            ElseIf nextChar <> vbCr Then
                Exit Do
            End If
        Loop
        Return New String(result.ToArray())
    End Function

End Module


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

int main() {

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

    int p=1,ans=0;
    for(int i=0;i<n;i++){
       if(arr[i]==p) p++;
       else ans++;
    }

    if(p==1) ans=-1;
    cout << ans <<'\n';

    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;
#define INF 1e9

static const int seed=702;
static const int D=365;
static const int ntype=26;
static int ans[D+1];
static int max_score=-INF;
static int t=1e5;
class Contest{
public:
    Contest(){
        last=0;
    }
    int s[D+1];
    int c;
    int last;
};

static Contest contest[ntype+1];

void Input(){
    int d;
    cin>>d;
    for(int i=1;i<=ntype;++i){
        int t;
        cin>>t;
        contest[i].c=t;
    }
    for(int day=1;day<=D;++day){
        for(int type=1;type<=ntype;++type){
            int t;
            cin>>t;
            contest[type].s[day]=t;
        }
    }
}

int evaluate(){
    int sum=0;
    vector<int> l(ntype+1,0);
    for(int day=1;day<=D;++day){
        int type=ans[day];
        sum+=contest[type].s[day];
        l[type]=day;
        for(int t=1;t<=ntype;++t){
            sum-=contest[t].c*(day-l[t]);
        }
    }
    return sum;   
}

void Output(){
    for(int d=1;d<=D;++d) cout<<ans[d]<<endl;
}

void Init(){
    for(int d=1;d<=D;++d) ans[d]=rand()%ntype+1;
}

void Greedy(){
    vector<int> l(ntype+1,0);
    int score=0;
    for(int d=1;d<=D;++d){
        for(int i=1;i<=ntype;++i) score-=contest[i].c*(d-l[i]);
        int temp=score;
        int t=-1;
        for(int i=1;i<=ntype;++i){
            int k=contest[i].s[d]+contest[i].c*(d-l[i])+score;
            if(k>temp){
                temp=k;
                t=i;
            }
        }
        ans[d]=t;
        l[t]=d;
    }
}

void solve(int time){
    max_score=evaluate();
    for(int i=0;i<time;++i){
        int p=rand()%D+1;
        int temp=ans[p];
        ans[p]=rand()%ntype+1;
        int temp_score=evaluate();
        if(max_score<temp_score) max_score=temp_score;
        else ans[p]=temp;
    }
}

int main(){
    srand(seed);
    Input();
    Greedy();
    solve(t);
    Output();
}


Measured memory_bytes: 3632