akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int p[1001], d[1001][2], x[1001];
int dp[1001][2][5001];
int t[5001];
int min(const int &a, const int &b){return a>b?b:a;}
int main(){
        int n;
        scanf("%d", &n);
        for(int i=2; i<=n; i++) scanf("%d", p+i);
        for(int i=1; i<=n; i++) scanf("%d", x+i);
        for(int i=n; i>=1; i--){
                for(int c = 0; c<2; c++){
                        int m = 100000000;
                        for(int j=0; j<=x[i]; j++) if(m > dp[i][c][j]) m = dp[i][c][j];
                        d[i][c] = m;
                        if(m >= 100000000){
                                printf("IMPOSSIBLE\n");
                                return 0;
                        }
                        //printf("^^^node %d, color %d, d %d\n", i, c, m);
                }
                int p = ::p[i];
                for(int c=0; c<2; c++){
                        for(int j=0; j<=5000; j++){
                                t[j] = 100000000;
                                // i) I am c
                                if(j-x[i] >= 0) t[j] = dp[p][c][j-x[i]] + d[i][1-c];
                                // ii) I am 1-c
                                if(j-d[i][1-c] >= 0) t[j] = min(t[j], dp[p][c][j-d[i][1-c]] + x[i]);
                        }
                        for(int j=0; j<=5000; j++) dp[p][c][j] = t[j];
                }
        }
        printf("POSSIBLE\n");
        return 0;
}

Measured memory_bytes: 39040
int main(){
  int a, b, p;
  scanf("%d %d", &a, &b);
  
  if(a == b){
    p = a + b;
  }else if(a > b){
    p = 2 * a -1;
  }else{
    p = 2 * b -1;
  }
  printf("%d", p);
  return 0;
}

Measured memory_bytes: 128
def main():
    N = int(input())
    H = [int(i) for i in input().split()]

    flag = True
    for i in range(N-1)[::-1]:
        if H[i] > H[i+1]:
            if H[i] - H[i+1] == 1:
                H[i] -= 1
            else:
                flag = False

    if flag:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 85336
#include <iostream>
using namespace std;
int main()
{
//	int t = 1; // cin >> t;
//	while (t--) {
	int a, b , c, k;
	cin >> a >> b >> c;
	cin >> k;
	while (k--)
	{
		if (b <= a)
			b = b * 2;
		else if (c <= b)
			c = c * 2;
	}

//	}
	if (b > a && c > b)
		cout << "Yes";
	else
		cout << "No";

	return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	int x,n;cin>>x>>n;
	vector<int> p(n);
	for(int i = 0; i < n; i++) {
		cin>>p[i];
	}
	sort(ALL(p));

	vector<int> b(102);
	for(int i = 0; i < b.size(); i++) {
		b[i] = i;
	}
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < b.size(); j++) {
			if (p[i] == b[j]){
				b.erase(b.begin() + j);
			}
		}
	}
	int ans = 1000;
	int ans_b = 1000; 
	for(int i = 0; i < b.size(); i++) {
		if (ans > abs(x - b[i])){
			ans = abs(x - b[i]);
			ans_b = b[i];
		}
	}
	cout << ans_b << endl;
	return 0;
}

Measured memory_bytes: 3640
from collections import Counter
from fractions import gcd

n = int(input())
xys = [tuple(map(int, input().split())) for _ in range(n)]
MOD = 998244353

excludes = 0
for i, (x1, y1) in enumerate(xys):
    slopes = []
    for x2, y2 in xys[i + 1:]:
        dx, dy = x2 - x1, y2 - y1
        if dx == 0:
            slopes.append(1j)
        elif dy == 0:
            slopes.append(1)
        else:
            m = gcd(dx, dy)
            slopes.append(dx // m + dy // m * 1j)
    for c in Counter(slopes).values():
        if c > 1:
            excludes += 2 ** c - c - 1
    excludes %= MOD

print((pow(2, n, MOD) - excludes - (n * (n - 1) // 2) - n - 1) % MOD)


Measured memory_bytes: 5472
using System;
using System.Collections.Generic;
using System.Linq;

public static partial class Program
{
    //テンプレここから
    private static int ToInt(this string str) => int.Parse(str);
    private static long ToLong(this string str) => long.Parse(str);
    private static int[] ToInt(this IEnumerable<string> strs) => strs.Select(x => x.ToInt()).ToArray();
    private static long[] ToLong(this IEnumerable<string> strs) => strs.Select(x => x.ToLong()).ToArray();
    public static int[] SpTInts(this string str, char opr = ' ') => str.Split(opr).ToInt();
    public static long[] SpTLongs(this string str, char opr = ' ') => str.Split(opr).ToLong();
    public static string CRL() => Console.ReadLine();
    public static void CWL(object obj) => Console.WriteLine(obj);
    public static int Diff(int a, int b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    public static long Diff(long a, long b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    public static int Sign(this int i) => Math.Sign(i);
    public static bool IsEven(this int i) => i % 2 == 0;
    public static int[] dx = new int[] {0, -1, 0, 1};
    public static int[] dy = new int[] {-1, 0, 1, 0};
    public static string alphabet = "abcdefghijklmnopqrstuvwxyz";
    //テンプレここまで
}

public static partial class Program
{
    public static void Main()
    {
        var xy = CRL().SpTLongs();
        var x = xy[0];
        var y = xy[1];

        long count = 0;
        while (x <= y)
        {
            count++;
            x *= 2;
        }

        CWL(count);
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#define ll long long
#define si(n) scanf("%d",&n)
#define sl(n) scanf("%lld",&n)
#define pi(n) prllf("%d",n)
#define pl(n) prllf("%d",n)
using namespace std;

int main(){
  int x;
  cin>>x;
  vector <int> v;
  v.push_back(1);
  for(int i=2;i<=31;i++){
    int j = i;
    while(true){
      j*=i;
      if(j>1000){
        break;
      }
      else{
        v.push_back(j);
      }
    }
  }
  sort(v.begin(),v.end());
  if(x==1){
    cout<<"1"<<endl;
  }
  else{
    for(int i=0;i<v.size();i++){
      if(v[i]==x){
        cout<<v[i];
        break;
      }
      else if(v[i]<x && v[i+1]>x){
        cout<<v[i];
        break;
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String n = br.readLine();
		List<Integer>list = new ArrayList<Integer>();
		String[]fList = br.readLine().split(" ");
		for(int i = 0; i < Integer.parseInt(n); i++){
			list.add(Integer.parseInt(fList[i]));
		}
		System.out.println(searchMin(list) + " " + searchMax(list) + " " + sum(list));
	}

	static int searchMin(List<Integer> list) {
		int min = 1000000;
		for (int i = 0; i < list.size(); i++) {
			if (min > list.get(i)) {
				min = list.get(i);
			}
		}
		return min;
	}

	static int searchMax(List<Integer> list) {
		int max = -1000000;
		for (int i = 0; i < list.size(); i++) {
			if (max < list.get(i)) {
				max = list.get(i);
			}
		}
		return max;
	}

	static long sum(List<Integer> list) {
		long sum = 0;
		for (int i = 0; i < list.size(); i++) {
			sum = sum + list.get(i);
		}
		return sum;
	}
}

Measured memory_bytes: 28936
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
int main()
{
    ll n,m;
    cin>>n>>m;
    char arr[n][m];
    for(ll i=0;i<n;i++)
        for(ll j=0;j<m;j++)
            cin>>arr[i][j];
    ll dp[n][m];
    for(ll i=0;i<n;i++)
        for(ll j=0;j<m;j++)
            dp[i][j]=0;
    for(ll i=0;i<n;i++)
    {
        if(arr[i][0]=='#')
            break;
        else
            dp[i][0]=1;
    }
    for(ll i=0;i<m;i++)
    {
        if(arr[0][i]=='#')
            break;
        else
            dp[0][i]=1;
    }
    // for(ll i=0;i<n;i++)
    // {
    //     for(ll j=0;j<m;j++)
    //         cout<<dp[i][j]<<" ";
    //     cout<<"\n";
    // }
    for(ll i=1;i<n;i++)
        for(ll j=1;j<m;j++)
            if(arr[i][j]=='.')
                dp[i][j]=((dp[i-1][j])%mod+(dp[i][j-1])%mod)%mod;
    cout<<dp[n-1][m-1]<<"\n";
}


Measured memory_bytes: 12316
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T &a){int t = 0;for(auto itr :a){if(t++)cout << " "; cout << itr;} cout <<endl; }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
signed main(){
    //    std::ios_base::sync_with_stdio(false);
    //    cin.tie(NULL);
    vector<pii>v(5);
    int maxi = 0;
    for(auto & e: v){
        cin  >> e.second; e.first = (10 - (e.second % 10)) % 10;
    }
    sort(all(v));
    int ans = 0;
    rep(i,5){
        ans += v[i].second + v[i].first;
        cmax(maxi,v[i].first);
    }
    cout << ans - maxi << endl;
}




Measured memory_bytes: 256
import heapq

N,M=map(int,input().split())
A=list(map(int,input().split()))
A=sorted(A)

que = []
for a in A:
  heapq.heappush(que, -1*a)
 
for a in range(M):
  maxvalue = -1 * heapq.heappop(que)
  maxvalue /= 2
  heapq.heappush(que, -1*maxvalue)
 
print(sum([int(-1*a) for a in que]))
  

Measured memory_bytes: 15044
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 200
int main() {
	char s[N] = "", x[N]="", ss[N] = "", *p1, *p2;
	int i= 0,j,k,flg = 0,xLength;
	char n[2][5] = { {"No"},{"Yes"} };
	fgets(s,sizeof(s),stdin);
	fgets(x,sizeof(x),stdin);
	
	s[strlen(s) - 1] = '\0';
	x[strlen(x) - 1] = '\0';
	strcat(ss, s);
	strcat(s, ss);
	p1 = s;
	p2 = x;
	xLength = strlen(x);

	while (*p1) {
		j = 0;
		if (*p1 == *p2) {
			//printf("*%c\n", *p1);
			for (k = 1; k <= xLength; k++) if (*(p2+k) != *(p1+k)) { 
				//printf("*%d %c %c\n",i, *(p2 + k), *(p1+ k)); 
				break; }
		}
		if (k == xLength) { flg = 1;  break; }
		*(p1++);
		i++;
	}
	/*while (i<=strlen(s)-strlen(x)) {
		j = 0;
		if (s[i] == x[j]) {
			for (k = 1; k <= strlen(x); k++)
				if (x[j + k] != s[i + k]) break;
		}
		if (k == strlen(x)) {
			flg = 1;
			break;
		}
		j++;
		i++;
	}
	*/
	printf("%s\n", n[flg]);
	return 0;
}

Measured memory_bytes: 2680
package main

import "fmt"
import "sort"
import "strings"

func main(){
 var N, L int;
  fmt.Scan(&N);
  var strs[]string;
  fmt.Scan(&L);
  for i:=0;i<N;i++{
    var input string;
    fmt.Scan(&input)
    strs = append(strs, input)
  }
  sort.Strings(strs);
  fmt.Println(strings.Join(strs, ""))
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define repl(i, l, r) for (ll i = (l); i < (r); i++)
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define CST(x) cout << fixed << setprecision(x)
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
const ll MOD = 1000000007;
const int inf = 1e9 + 10;
const ll INF = 4e18;
int main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<string> s(n);
	vector<pair<int, int>> l, r;
	rep(i, n) {
		cin >> s[i];
		int op = 0, cl = 0, now = 0;
		for (auto c : s[i]) {
			if (c == ')')
				now--;
			else
				now++;
			cl = max(cl, -now);
		}
		if (now >= 0)
			l.push_back({cl, i});
		else
			r.push_back({now + cl, i});
	}
	sort(all(l)), sort(all(r), greater<pair<int, int>>());
	string T;
	for (auto t : l) T += s[t.second];
	for (auto t : r) T += s[t.second];

	int cnt = 0, now = 0;
	for (auto c : T) {
		if (c == ')')
			now--;
		else
			now++;
		cnt = max(cnt, -now);
	}
	if (now == 0 and cnt <= 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m, s, c;
  cin >> n >> m;
  int res[3] = {-1,-1,-1};
  bool can = true;
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (res[s - 1] == -1) res[s - 1] = c;
    else if (res[s - 1] != c) can = false;
  }
  if ((res[0] == 0 && n > 1) || !can)  {
    cout << "-1\n";
    return 0;
  }
  if (res[0] == -1 && n > 1) res[0] = 1;
  for (int j = 0; j < n; j++) cout << (res[j] == -1? 0:res[j]);
  cout << '\n';
  
  return 0;
}

Measured memory_bytes: 256
/* ABC143-B
   Takatan */

#include<stdio.h>
int main(void){
    int number, delicious, sum, sum_square, i;
    sum = 0;
    sum_square = 0;


    scanf( "%d" , &number);
    for(i=0; i < number; i++){
        scanf( "%d" , &delicious);
        sum += delicious;
        sum_square += delicious * delicious;
    }
    printf( "%d\n" , (sum * sum - sum_square)/2);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;
int dx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int dy[8] = {1, 1, 0, -1, -1, -1, 0, 1};

int main() {
  int n, k;
  cin >> n >> k;
  int ans = 1;
  for (int i = 0; i < n; i++) {
    ans = min(ans + k, ans * 2);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            if (a < b)
            {
                Console.WriteLine("a < b");
            }
            else if (a > b)
            {
                Console.WriteLine("a > b");
            }
            else
            {
                Console.WriteLine("a == b");
            }
        }
    }
}



Measured memory_bytes: 15776
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#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;

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

    vector<Int> L(3); cin >> L[0] >> L[1] >> L[2];

    if (L[0]%2==1 and L[1]%2==1 and L[2]%2==1) {
        L.erase(max_element(L.begin(), L.end()));
        cout << L[0]*L[1] << endl;
    }
    else {
        cout << 0 << endl;
    }
}


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

using namespace std;

int main(){
	string s,t;
	int a,b;
  	string x;
  	cin>>s>>t;
  	cin>>a>>b;
  	cin>>x;
  	
  
  	if(x == s)
      a--;
  	else if(x==t)
      b--;
  
  	cout<<a<<" "<<b<<endl;
 


return 0;
}

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

#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>
#include <cstdlib>
#include <random>
#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
//typedef vector<ll> vec;
//typedef vector<vec> mat;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;

ll N,K;

int main(){
  cin>>N>>K;
  if(N%K!=0)cout<<1<<endl;
  else cout<<0<<endl;
  return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))
ma = min(a)

a = list(map(lambda x: x - ma, a))

befscore = 1
score = 1
f = True
for i in range(n):
    score = score + a[i]

    if i >= k:
        score = int(score - a[i - k])
        if befscore >= score:
            print("No")
        else:
            print("Yes")

    befscore = score


Measured memory_bytes: 102816
import java.util.*;
public class Main {
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        String s = sc.next();
        sc.close();

        if(s.length() > k) {
        String new_s = s.substring(0,k); 
            System.out.println(new_s + "...");
        }else{
            System.out.println(s);
        }

    }
}


Measured memory_bytes: 27068
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <tuple>
#include <cassert>
#include <memory>
using namespace std;
typedef long long ll;
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;

template <class T> struct FenwickTree {

    vector < T > node;
    FenwickTree (int n) : node(n, 0) {}

    void add(int idx, T val) {
        for (int i = idx; i < node.size(); i |= i + 1) {
            node[i] += val;
        }
    }

    void update(int idx, T val) {
        add(idx, -sum(idx, idx + 1));
        add(idx, val);
    }

    T sum(int idx) {
        T ret = 0;
        for (int i = idx - 1; i >= 0; i = (i & (i + 1)) - 1) {
            ret += node[i];
        }
        return ret;
    }

    T sum(int l, int r) {
        return sum(r) - sum(l);
    }

};


int main ()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    ll ans = 0;
    map<ll, ll> cnt;
    for (int i = 0; i < N; i++) {
        ans += cnt[A[i] - (i + 1)];
        cnt[-(A[i] + (i + 1))]++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 27472
import sys
from collections import defaultdict

def main():
    input = sys.stdin.readline
    N = int(input())
    A = list(map(int, input().split()))

    d = defaultdict(lambda: 0)
    for a in A:
        d[a-1] += 1
        d[a] += 1
        d[a+1] += 1

    ans = 0
    for key in d:
        ans = max(ans, d[key])

    return ans


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


Measured memory_bytes: 20112
#include <iostream>
#include <typeinfo>
#include <cstring>
#include <utility>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>

using namespace std;


double getDistance(pair<double, double> p1, pair<double, double> p2) {
    return sqrt(pow(p1.first - p2.first, 2) + pow(p1.second - p2.second, 2));
}


int main() {
    // inputs
    int N;
    cin >> N;

    vector< pair<double, double> > points(N);
    for (int i = 0; i < N; i++) {
        double x, y;
        cin >> x >> y;
        points[i] = make_pair(x, y);
    }


    // test
    int nc2 = N * (N-1) / 2;
    double totalLength = 0;    
    for (int i = 0; i < N; i++) {
        for (int j = i; j < N; j++) {
            totalLength += getDistance(points[i], points[j]);
        }
    }

    printf("%.16f", totalLength / nc2 * (N - 1));
    return 0;
}

// :!g++ -std=c++11 % && ./a.out



Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
const int N=1e5+5,P=2200+5;
int n,tot,p[P];
long long a[N],s[N],t[N];
bool flg[P];
std::map<long long,int> mp;

void init() {
	for(int i=2;i<P;++i) {
		if(!flg[i]) p[++tot]=i;
		for(int j=1;j<=tot&&i*p[j]<P;++j) {
			flg[i*p[j]]=1;
			if(i%p[j]==0) break;
		}
	}
}
void solve() {
	scanf("%d",&n);
	for(int k=1;k<=n;++k) {
		long long x;
		scanf("%lld",&x);
		t[k]=1;
		for(int i=1;1LL*p[i]*p[i]*p[i]<=x;++i) {
			long long c=1LL*p[i]*p[i]*p[i];
			while(x%c==0) x/=c;
		}
		++mp[s[k]=x];
		for(int i=1;1LL*p[i]*p[i]*p[i]<=x;++i) {
			int cnt=0;
			while(x%p[i]==0) x/=p[i],++cnt;
			if(cnt==1) t[k]*=1LL*p[i]*p[i];
			if(cnt==2) t[k]*=p[i];
		}
		long long rt=sqrt(x);
		rt*rt==x?t[k]*=rt:t[k]*=x*x;
	}
	int ans=0;
	if(mp[1]) ++ans,mp[1]=0;
	for(int i=1;i<=n;++i) {
		ans+=std::max(mp[s[i]],mp[t[i]]);
		mp[s[i]]=mp[t[i]]=0;
	}
	printf("%d\n",ans);
}
int main() {
	init();
	solve();
	return 0;
}

Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
ll gcd(ll a, ll b){
  ll r=a%b;
  while(r>0){
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
int main() {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  
  ll ans = a[0];
  for(ll i=1;i<n;i++){
    ans = gcd(ans,a[i]);
    //cout << ans << endl;
  }
  
  cout << ans << endl;
  
  return(0);
}


Measured memory_bytes: 4024
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793

int main(){
   int n;
   cin >> n;
   VI h(n);
   rep(i,n){
       cin >> h.at(i);
   }
   int ans=0;
   int cnt=0;
   rep(i,n-1){
       if(h.at(i)>=h.at(i+1)){
           cnt++;
       }
       else cnt=0;
       ans=max(ans,cnt);
   }
   cout << ans << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define MAX_N 40
#define INF 100000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n, p1, p2;
vector<P> e[600];
vector<int> out;
vector<int> par;
bool saw[600];
bool see[600];
int dp[601][301];
P pre[1001];

P dfs(int v, bool ac){
    saw[v] = true;
    P ret = P(1,0);
    if(ac) ret.second++;
    rep(i,e[v].size()){
        int to = e[v][i].first, id = e[v][i].second;
        if(saw[to]) continue;
        if(id == 1){
            P q = dfs(to,ac);
            ret.first += q.first;
            ret.second += q.second;
        } else{
            P q = dfs(to,ac^1);
            ret.first += q.first;
            ret.second += q.second;
        }
    }
    return ret;
}

void dfs2(int v, bool ac){
    if(ac) out.push_back(v);
    see[v] = true;
    rep(i,e[v].size()){
        int to = e[v][i].first, id = e[v][i].second;
        if(see[to]) continue;
        if(id == 1){
            dfs2(to,ac);
        } else{
            dfs2(to,ac^1);
        }
    }
}

void solve(){
    rep(i,600) e[i].clear();
    memset(saw,0,sizeof(saw));
    memset(see,0,sizeof(see));
    memset(dp,0,sizeof(dp));
    out.clear();
    par.clear();
    rep(i,n){
        int f, t; string judge;
        cin >> f >> t >> judge;
        f--; t--;
        if(f == t) continue;
        if(judge == "yes"){
            e[f].push_back(P(t,1));
            e[t].push_back(P(f,1));
        } else{
            e[f].push_back(P(t,2));
            e[t].push_back(P(f,2));
        }
    }
    int cnt = 0;
    dp[0][0] = 1;
    rep(i,p1+p2){
        if(saw[i]) continue;
        par.push_back(i);
        pre[cnt] = dfs(i,true);
        P p = pre[cnt];
        cnt++;
        for(int j = 0; j <= p1-p.second; j++){
            dp[cnt][j+p.second] += dp[cnt-1][j];
            if(dp[cnt][j+p.second] > 2) dp[cnt][j+p.second] = 2;
        }
        for(int j = 0; j <= p1-(p.first-p.second); j++){
            dp[cnt][j+p.first-p.second] += dp[cnt-1][j];
            if(dp[cnt][j+p.first-p.second] > 2){
                dp[cnt][j+p.first-p.second] = 2;
            }
        }
    }
    if(dp[cnt][p1] != 1){
        cout << "no" << endl;
        return;
    }
    int now = p1;
    for(int i = cnt-1; i >= 0; i--){
        if(now >= pre[i].second && dp[i][now-pre[i].second] > 0){
            now -= pre[i].second;
            dfs2(par[i],true);
        } else{
            now = now-(pre[i].first-pre[i].second);
            dfs2(par[i],false);
        }
    }
    sort(out.begin(),out.end());
    rep(i,out.size()) cout << out[i]+1 << endl;
    cout << "end" << endl;
}

int main(){
    while(cin >> n >> p1 >> p2){
        if(n ==  0 && p1 == 0 && p2 == 0) break;
        solve();
    }
}

Measured memory_bytes: 3852
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

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

    int a = gi();
    int b = gi();
    int c = gi() - (a-b);

    printf("%d\n", (c < 0 ? 0 : c));

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <algorithm>

int MOD_BIG = 1000000007;
int MOD_BIG2 = 998244353;
using std::string;
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using ll = long long;
using pint = std::pair<int, int>;
using pll = std::pair<ll, ll>;
using std::vector;

#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

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

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

int main() {
    
    ll K;
    cin >> K;
    if (K % 2 == 0) {
        cout << -1 << endl;
        return 0;
    }
    ll ans = 0;
    ll m = 0;
    ll n = 7;
    while (true) {
        m += n;
        m %= K;
        ans++;
        n = (n*10) % K;
        if (m == 0) break;
        if (ans > 10000000) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 3632
#include <cstdio>
#include <algorithm>
#include <cctype>
#include <vector>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 1e5+5;
int n, a[N], b[N], c[N], d[N], ans;
int f[N], fa[N];
int find(int x) { return fa[x] == x?x:fa[x] = find(fa[x]); }
void merge(int x, int y) 
{ 
    x = find(x), y = find(y);
    if(x == y) return;
    fa[x] = y, f[y] += f[x]; 
} 
vector<int> s[N];
int main()
{
    n = read(), ++n;
    for(int i = 1; i < n; ++i) c[i] = a[i] = read(), c[n] = a[0] ^= a[i];
    for(int i = 1; i < n; ++i) d[i] = b[i] = read(), d[n] = b[0] ^= b[i];
    sort(c+1, c+1+n), sort(d+1, d+1+n);
    for(int i = 1; i <= n; ++i) if(c[i]^d[i]) return puts("-1"), 0;
    for(int i = 0; i < n; ++i)
        a[i] = lower_bound(c+1, c+1+n, a[i])-c,
        b[i] = lower_bound(d+1, d+1+n, b[i])-d;
    a[n] = a[0], b[n] = b[0], fa[n] = n, f[n] = -1;
    for(int i = 1; i < n; ++i) fa[i] = i, f[i] = a[i] != b[i];
    for(int i = 1; i <= n; ++i) 
        if(a[i] != b[i]||n == i)
            s[a[i]].push_back(i), merge(s[a[i]][0], i);
    for(int i = 1; i <= n; ++i) 
        if(a[i] != b[i]||n == i) merge(i, s[b[i]][0]);
    for(int i = 1; i <= n; ++i) 
        if((a[i] != b[i]||n == i)&&find(i) == i) ans += 1+f[find(i)];
    printf("%d\n", ans);
    return 0;
}

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

long long n, x;

// レベルiバーガーの厚さ　Ai
vector<long long> A;

// レベルiバーガーに含まれるパティの総数 Pi
vector<long long> P;

// レベルnnバーガーの下からxx層に含まれるパティの枚数 f(nn, xx)
long long f(long long nn, long long xx){
    
    // レベル0バーガーはパティ1枚
    if(nn == 0){
        return (xx <= 0 ? 0 : 1);

    // xx層 が 1+レベルnn-1バーガーの総数 以下の場合
    }else if(xx <= 1 + A[nn - 1]){
        // nn-1バーガーのxx-1層を見ればいい（xx-1の-1は一番下のバン）
        return f(nn - 1, xx - 1);

    }else{

        // [B][レベルi-1バーガー] | -> [P][レベルi-1バーガー][B]
        //
        // 丸々レベルnn-1バーガー1つに内包されるパティの数 + 1枚のパティ + 
        // レベルnn-1バーガーの中の (xx-レベルnn-1バーガーの総数とBとP)層
        return P[nn - 1] + 1 + f(nn - 1, xx - 2 - A[nn - 1]);
    }
}

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

    cin >> n >> x;

    A.push_back(1);
    P.push_back(1);
    for(long long i = 0; i < n; i++){

        // [B][レベルi-1バーガー][P][レベルi-1バーガー][B]
        A.push_back(A[i] * 2 + 3);
        P.push_back(P[i] * 2 + 1);
    }

    cout << f(n, x) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int n,i,j,b[1024]={0},w;
  for(i=1;i<1024;i++){
    j=i;w=0;
    while(1){
      w+=j;
      if(w>=1024){break;}
      b[w]++;
      j++;
    }
  }
  while(scanf("%d",&n),n!=0){
    printf("%d\n",b[n]-1);
  }
  return 0;
}



Measured memory_bytes: 2020
#include<stdio.h>

int main()
{
    int p,q,r,a,b,c;

    scanf("%d%d%d",&p,&q,&r);

    a=p+q;
    b=p+r;
    c=q+r;

    if(a<=b&&a<=c)
    {
        printf("%d\n",a);
    }
    else if(b<=a&&b<=c)
    {
        printf("%d\n",b);
    }
    else
    {
        printf("%d\n",c);
    }

    return 0;
}

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


int main()
{

	string input;
	cin >> input;


	int result = 700;
	for (int i = 0; i < input.length(); i++) {
		if (input[i] == 'o') {
			result += 100;
		}
	}

	cout << result << endl;
	
	int quit; cin >> quit;
	return 0;
}






Measured memory_bytes: 256
# -*- coding: utf-8 -*-




sx,sy,tx,ty = map(int, input().split())

r = 'R'*(tx-sx)
l = 'L'*(tx-sx)
u = 'U'*(ty-sy)
d = 'D'*(ty-sy)

ans = r+u
ans += 'R'+d+'D'+l+'LU'
ans += u+r
ans += 'U'+l+'L'+d+'DR'
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  ll dx = tx - sx;
  ll dy = ty - sy;
  string ans;
  ans += string(dx, 'R');
  ans += string(dy, 'U');
  ans += string(dx, 'L');
  ans += string(dy+1, 'D');
  ans += string(dx+1, 'R');
  ans += string(dy+1, 'U');
  ans += "LU";
  ans += string(dx+1, 'L');
  ans += string(dy+1, 'D');
  ans += 'R';
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	int i, H, W, K;
	char A[802][802] = {};
	scanf("%d %d %d", &H, &W, &K);
	for (i = 1; i <= H; i++) scanf("%s", &(A[i][1]));
	
	int j, dist[802][802], q[640000][2], head, tail;
	for (i = 1; i <= H; i++) {
		for (j = 1; j <= W; j++) {
			if (A[i][j] == 'S') {
				q[0][0] = i;
				q[0][1] = j;
				dist[i][j] = 0;
			} else dist[i][j] = K + 2;
		}
	}
	
	int t = q[0][0], b = q[0][0], l = q[0][1], r = q[0][1];
	for (head = 0, tail = 1; head < tail; head++) {
		i = q[head][0];
		j = q[head][1];
		if (dist[i][j] >= K) break;
		
		if (A[i-1][j] == '.' && dist[i-1][j] > dist[i][j] + 1) {
			dist[i-1][j] = dist[i][j] + 1;
			q[tail][0] = i - 1;
			q[tail++][1] = j;
			if (i - 1 < t) t = i - 1;
		}
		if (A[i+1][j] == '.' && dist[i+1][j] > dist[i][j] + 1) {
			dist[i+1][j] = dist[i][j] + 1;
			q[tail][0] = i + 1;
			q[tail++][1] = j;
			if (i + 1 > b) b = i + 1;
		}
		if (A[i][j-1] == '.' && dist[i][j-1] > dist[i][j] + 1) {
			dist[i][j-1] = dist[i][j] + 1;
			q[tail][0] = i;
			q[tail++][1] = j - 1;
			if (j - 1 < l) l = j - 1;
		}
		if (A[i][j+1] == '.' && dist[i][j+1] > dist[i][j] + 1) {
			dist[i][j+1] = dist[i][j] + 1;
			q[tail][0] = i;
			q[tail++][1] = j + 1;
			if (j + 1 > r) r = j + 1;
		}
	}
	
	int ans = H + W;
	if ((t + K - 2) / K < ans) ans = (t + K - 2) / K;
	if ((H - b + K - 1) / K < ans) ans = (H - b + K - 1) / K;
	if ((l + K - 2) / K < ans) ans = (l + K - 2) / K;
	if ((W - r + K - 1) / K < ans) ans = (W - r + K - 1) / K;
	printf("%d\n", ans + 1);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 9752
#include <vector>
#include <algorithm>
#include <set>
#include <iostream>
#include <unordered_set>
using namespace std;

typedef long long ll;
ll n, k;
vector<ll> a;

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        ll x;
        cin >> x;
        a.push_back(x);
    }

    ll num = 0;
    for (ll i = 42; i >= 0; i--) {
        int one_sum = 0, zero_sum = 0;
        for (int j = 0; j < n; j++) {
            if (((a[j] >> i) & 1ll)) one_sum++;
            else zero_sum++;
        }
        if (zero_sum > one_sum && (num + (1ll << i)) <= k) num += (1ll << i);
    }
    ll ans = 0;
    for (int i = 0; i < n; i++) ans += (num ^ a[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define PRINTALL(V)    \
  for (auto v : (V)) { \
    cerr << v << " ";  \
  }                    \
  cerr << "\n";
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> using vec = std::vector<T>;
template <class T> void print(const T &x) { cout << x << "\n"; }
const int MOD = 1000000007, INF = 1061109567;
const double EPS = 1e-10, PI = acos(-1.0);
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  string N;
  cin >> N;
  string rN = N;
  reverse(ALL(rN));
  if (N == rN) {
    print("Yes");
  } else {
    print("No");
  }
}

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

using namespace std;
typedef long long ll;
ll cal(ll n){
	ll ans=0;
	while(n){
		ans+=n/5;
		n=n/5;
	}
	return ans;
}
int main(){
	ll n;
	cin>>n;
	if(n&1){
		cout<<0<<endl;
		return 0;
	}
	n>>=1;
	cout<<cal(n)<<endl;
	return 0;
}


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

long long  gcd(long long a,long long b)
{
if(b==0)return a;

else 
{
    long long  t;
    t=a;a=b; b=t%b;
    return gcd(a,b);
}
}
int main()
{long long a,b;
cin>>a>>b;
long long  t=gcd(a,b);
long long  k=gcd(a,b);
long long  sum=1;
for(long long  i=2;i*i<=k;i++)
{if (t%i==0){t=t/i;sum++;}

    while(t%i==0)
   { t=t/i;}

}
if (t!=1)sum++;
cout <<sum;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

int main() {
  int n, m, c;
  std::cin >> n >> m >> c;

  std::vector<int> b_array(m);
  for (size_t i = 0; i < m; ++i) {
    std::cin >> b_array.at(i);
  }

  unsigned int ans = 0;
  for (size_t i = 0; i < n; ++i) {
    std::vector<int> a_array(m);
    for (size_t j = 0; j < m; ++j) {
      std::cin >> a_array.at(j);
    }
    int sum = c;
    for (size_t j = 0; j < m; ++j) {
      sum += a_array.at(j) * b_array.at(j);
    }
    if (sum > 0) {
      ans += 1;
    }
  }

  std::cout << ans << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int SX,SY,TX,TY;
  cin>>SX>>SY>>TX>>TY;
  for(int M=0;M<TX-SX;M++){
    cout<<'R';
  }
  for(int M=0;M<TY-SY;M++){
    cout<<'U';
  }
  for(int M=0;M<TX-SX;M++){
    cout<<'L';
  }
  for(int M=0;M<TY-SY;M++){
    cout<<'D';
  }
  cout<<'D';
  for(int M=0;M<TX-SX;M++){
    cout<<'R';
  }
  cout<<'R';
  cout<<'U';
  for(int M=0;M<TY-SY;M++){
    cout<<'U';
  }
  cout<<'L';
  cout<<'U';
  for(int M=0;M<TX-SX;M++){
    cout<<'L';
  }
  cout<<'L';
  for(int M=0;M<TY-SY;M++){
    cout<<'D';
  }
  cout<<'D';
  cout<<'R'<<endl;
}

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

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

    string s; cin >> s;

    int ans = 1e9;
    for (char c = 'a'; c <= 'z'; ++c)
    {
        vector< int > dis(s.size() + 1, 1e9);
        for (int i = (int)s.size() - 1; i >= 0; --i)
            dis[i] = (s[i] == c? i : dis[i + 1]);
        int res = 0;
        for (int i = 0; i < s.size(); ++i)
            res = max(res, (dis[i] == (int)(1e9)? (int)s.size() - i : dis[i] - i));

        ans = min(ans, res);
    }

    cout << ans << '\n';
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int dat[1000]={0};
    while(1)
    {
        int a=0,b=0;
        int res=scanf("%d %d",&a,&b);
        if(res!=2)
        {
            if(res==0)
            {
                break;
            }
            if(res==-1)
            {
                 break;
            }
            int violate=*(int*)0;
            *(int*)0=913;
        }if(!a||!b)
        {
            int cnt=0;
            for(int i=1;i<1000;i++)
            {
                if(dat[i]%2==1)cnt++;
                dat[i]=0;
            }
            if((cnt==2 && dat[1]==dat[2]))
            {
                puts("OK");
            }
            else
            {
                puts("NG");
            }
            continue;
        }
        dat[a]=1-dat[a];
        dat[b]=1-dat[b];
    }
    return 0;
}

Measured memory_bytes: 1012
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
#define ALL(x)    (x).begin(),(x).end()
#define UNIQ(c)   (c).erase(unique(ALL((c))), end((c)))
#define mp        make_pair
#define eb        emplace_back
#define REP(i, a) for (int i = 0; i < (a); i++)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);

std::vector<int> v[501010];
int dp[501010];
int main() {
	INIT;
	int n;
	string s;
	cin >> n >> s;
	s = "000" + s + "000";
	n += 6;
	REP(i, n - 3) {
		if (s.substr(i, 3) != "101") continue;
		int l = i - 1;
		while (s[l] == '1') --l;
		++l;
		int r = i + 3;
		while (s[r] == '1') ++r;
		v[l].emplace_back(i + 3);
		v[l + 1].emplace_back(i + 3);
		v[i].emplace_back(i + 3);
		v[i].emplace_back(r - 1);
		v[i].emplace_back(r);
	}
	REP(i, n - 1) {
		dp[i + 1] = max(dp[i + 1], dp[i]);
		for (int x = 0; x < v[i].size(); x++) {
			dp[v[i][x]] = max(dp[v[i][x]], dp[i] + v[i][x] - i - 2);
		}
	}
	cout << dp[n - 1] << endl;
	return 0;
}

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

int main() {
  
  vector<int> t(3);
  
  rep(i,3) cin >> t.at(i);
  
  sort(t.begin(), t.end());
  
  cout << t.at(0) + t.at(1) << endl;
  
}


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

const int MAXN = 100000+9;
struct E{
	int next,to;
}edge[MAXN<<1];
int head[MAXN],edge_num;
int n;
int degree[MAXN];
int dp[MAXN];
int A,B;
int limit;

void addedge(int x,int y){
	degree[x]++;
	edge[++edge_num].next=head[x];
	edge[edge_num].to=y;
	head[x]=edge_num;
}

bool DP(int x,int fa){
	vector<int> vec;
	int cnt=0;
	if(degree[x]%2==1)
		vec.push_back(0);
	for(int i=head[x];i;i=edge[i].next){
		if(edge[i].to!=fa){
			if(!DP(edge[i].to,x))return false;
			if(dp[edge[i].to]!=-1)vec.push_back(dp[edge[i].to]+1);
		}
	}

	sort(vec.begin(),vec.end());
	if(vec.size()%2==1){
		int loc=-1;
		int l=0,r=vec.size()-1;
		while(l<=r){
			int mid=l+r>>1;
			bool jud=1;
			int p1=0,p2=vec.size()-1;
			while(p1<p2){
				if(p1==mid)p1++;
				if(p2==mid)p2--;
				if(vec[p1]+vec[p2]>limit){
					jud=0;
					break;
				}
				p1++;p2--;
			}
			if(jud){
				loc=mid;
				r=mid-1;
			}
			else
				l=mid+1;
		}
		if(loc==-1){
			return false;
		}
		dp[x]=vec[loc];
		return true;
	}
	else{
		for(int i=0,j=vec.size()-1;i<j;i++,j--){
			if(vec[i]+vec[j]>limit){
				return false;
			}
		}
		dp[x]=-1;return true;
	}
}

bool check(int len){
	limit=len;
	memset(dp,0,sizeof(dp));
	return DP(1,0);
}

void solve(){
	int l=1,r=n;
	while(l<=r){
		int mid=l+r>>1;
		if(check(mid)){
			r=mid-1;
			B=mid;
		}
		else
			l=mid+1;
	}
}

int main(){
	//freopen("in.in","r",stdin);
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		addedge(a,b);
		addedge(b,a);
	}
	for(int i=1;i<=n;i++){
		if(degree[i]%2==1)
			A++;
	}
	A/=2;
	solve();
	printf("%d %d\n",A,B);
	return 0;
}

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

int dp[3001][3001];

int main(){   
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    int N = s.size();
    int M = t.size();   
    
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= M; j++) {
            if (s[i - 1] == t[j - 1]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            } else {
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        
        }
    }
    int i = N, j = M;
    string ans;
    while (i && j) {
        if (s[i - 1] == t[j - 1]) {
            ans = s[i - 1] + ans;
            i--;
            j--;
            continue;
        }
        if (dp[i - 1][j] > dp[i][j - 1]) {
            i--;
        }
        else {
            j--;
        }
    }
    cout << ans << "\n";


    return 0;
}


Measured memory_bytes: 35456
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <numeric>
#include <set>
// #include <bits/stdc++.h>

using namespace std;
typedef long long li;

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

    li n;
    cin >> n;

    vector<vector<li>> profit(n, vector<li>(3));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < 3; ++j) {
            cin >> profit[i][j];
        }
    }

    vector<vector<li>> dp(n, vector<li>(3));

    dp[0] = profit[0];

    for (int day = 1; day < n; ++day) {
        for (int activity = 0; activity < 3; ++activity) {
            for (int prev_activity = 0; prev_activity < 3; ++prev_activity) {
                if (activity == prev_activity) {
                    continue;
                }
                dp[day][activity] = max(dp[day][activity], dp[day - 1][prev_activity] + profit[day][activity]);
            }
        }
    }
    
    cout << *max_element(dp[n-1].begin(), dp[n-1].end()) << endl;
    return 0;
}


Measured memory_bytes: 11264
A, B = map(int,input().split())
Arate = 0.08
Brate = 0.10

flag = False
for i in range(1,1009):
  tmpA = int(i*Arate)
  tmpB = int(i*Brate)

  if tmpA == A and tmpB == B:
    print(i)
    flag = True
    break


if flag is False: print(-1)



Measured memory_bytes: 2940
from collections import Counter
_, *lst = open(0).read().split()
c = Counter(lst)
func = lambda x: str(c[x]) if x in c else '0'
print('AC x ' + func('AC'))
print('WA x ' + func('WA'))
print('TLE x ' + func('TLE'))
print('RE x ' + func('RE'))


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


int nextInt() { int x; scanf("%d", &x); return x;}

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool link(int x, int y) { //新たな併合を行うとtrue
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) { // 要素xが含まれる集合の大きさ
    return -data[root(x)];
  }
};

int main2() {
  int N = nextInt();
  int M = nextInt();

  UnionFind uf(N * 2);
  
  REP(i, M) {
    int a = nextInt() - 1;
    int b = nextInt() - 1;
    uf.link(2*a, 2*b+1);
    uf.link(2*a+1, 2*b);
  }
  if (uf.size(0) == 2*N) {
    ll ans = (ll)N*(N-1)/2 - M;
    cout << ans << endl;
  } else {
    ll A = 0, B = 0;
    REP(i, N) {
      if (uf.root(0) == uf.root(2*i)) {
        A++;
      } else {
        B++;
      }
    }
    ll ans = A*B - M;
    cout << ans << endl;
  }
  return 0;
}

int main() {
  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 1024
#include<vector>
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<limits.h>
#include<cmath>
#include<queue>
#include<map>
#define rep(i,n) for (int i=0; i<n; i++)
using namespace std;
typedef long long ll;

ll gcd(ll a,ll b){
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

int main(){

  int n,m; cin >> n >> m;
  vector<int> a(n); rep(i,n){cin>>a[i];}
  vector<pair<int,int> > cb(m); rep(i,m){cin>>cb[i].second>>cb[i].first;}

  sort(a.begin(),a.end());
  sort(cb.begin(),cb.end(), greater<pair<int,int> >());

  vector<ll> d(n);
  int flag=0;
  int index=0;
  rep(i,m){
    rep(j,cb[i].second){
      d[index]=cb[i].first;
      index++;
      if (index >= n){flag=1;break;}
    }
    if (flag==1){break;}
  }
  
  ll ans=0;

  rep(i,n){
    if (d[i]>a[i]){a[i]=d[i];}
    ans+=a[i];
  }

  cout << ans;
  

  return 0;
}


Measured memory_bytes: 2176
#include "bits/stdc++.h"
#define ll long long
#define ld long double 
#define For(i, a, n) for(long long i = a; (a < n) ? (i < n) : (i > n); (a < n) ? (i++) : (i--))
#define ee 1000000007
#define pb push_back
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;
  
void solve() {
	ll n, d, x, y;
	cin >> n >> d;
	ll ans = 0;
	For(i, 0, n) {
		cin >> x >> y;
		ld a = sqrt(x * x + y * y);
		if(a <= d)
			ans++;
	}
	cout << ans << "\n";
}

int main() {
    fio;
    ll t = 1;
    //cin >> t;
    while(t--) {
    	solve();
    }
}

Measured memory_bytes: 3692