akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define FOR(i,b,e) for(int i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(int i=(b); i >= (e); --i)
#define SIZE(c) (int) (c).size()
#define FORE(i,c) FOR(i,0,SIZE(c)-1)
#define FORDE(i,c) FORD(i,SIZE(c)-1,0)

#define pb push_back
#define mp make_pair
#define st first
#define nd second


using namespace std;

typedef long long ll;
typedef pair <int,int> pii;
typedef pair <ll,ll> pll;

typedef vector <int> VI;
typedef vector <bool> VB;
typedef vector <pii> VP;
typedef vector <ll> VL;
typedef vector <pll> VPL;

typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VB> VVB;
typedef vector <VP> VVP;

const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000000000000001LL;


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

int main() {
    ios_base::sync_with_stdio(0);
    
    int n;
    cin >> n;
    
    VI x(n);
    FOR(i,0,n-1) {
        cin >> x[i];
    }
    
    set <int> s;
    int off = 0;
    
    ll ans = 0;
    FORD(i,n-1,0) {
        if (!s.empty() && *s.rbegin() + off > x[i]) {
            cout << -1;
            return 0;
        }
    
        s.insert(x[i] - off);
        if (s.count(-off)) {
            s.erase(-off);
        }
        
        ans += s.size();
        off--;
    }
    
    if (!s.empty()) {
        cout << -1;
        return 0;
    }
    
    cout << ans;

    return 0;
}

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


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

int GetIdx(const vector<int> &l, int n, int st, int sum) {

	if (n - st == 0) return n;

	int mid = (n + st) / 2;
	if (sum <= l[mid]) GetIdx(l, mid, st, sum);
	else GetIdx(l, n, mid + 1, sum);
}


int main() {
	int n;
	cin >> n;
	vector<int> l(n);
	rep(i, n) cin >> l[i];
	sort(l.begin(), l.end());
	int64_t ans = 0;
	for (int i = 0; i < n - 2; i++) {
		for (int j = i + 1; j < n - 1; j++) {
			int k = GetIdx(l, n, j + 1, l[i] + l[j]);
			ans += (int64_t)k - j - 1;
		}
	}
	cout << ans << endl;

}

Measured memory_bytes: 256
S = input()
i, count = 0,0
con_str, old_str = [], []
while i < len(S):
  con_str = S[i]
  while con_str == old_str and i < len(S):
    i += 1
    if i==len(S):
      count -= 1
      con_str = old_str
    else:
      con_str += S[i]
      con_str = ''.join(con_str)
  old_str = con_str
  count += 1
  i += 1
print(count)

Measured memory_bytes: 3500
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
using namespace std;
int main() {
  int n; cin >> n;
  int a,b,ans;
  for(int i=0;i<n;i++){
    cin>>a>>b;
    ans+=b-a+1;
  }
  cout<<ans<<endl;
  return 0;
}

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

namespace Atc_0035
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();

            int A = int.Parse(s.Split(' ')[0]);
            int B = int.Parse(s.Split(' ')[1]);

            if (A % B == 0)
            {
                Console.WriteLine("0");
                return;
            }
            Console.WriteLine("1");

        }
    }
}


Measured memory_bytes: 27416
#include <iostream>
#include <vector>
#include <map>
#include <math.h>
#include <algorithm>
#include <sstream>
#include <list>

using namespace std;

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

	long long i;

	vector<bool> c;
	c.resize(s.length());
	
	for (i = 0; i < s.length(); i++)
	{
		c[i] = s[i] == '0';
	}

	int res1 = 0, res2 = 0;

	for (i = 0; i < s.length(); i++)
	{
		if (c[i])
		{
			if (i % 2 == 0)
			{
				res2++;
			}
			else
			{
				res1++;
			}
		}
		else
		{
			if (i % 2 == 0)
			{
				res1++;
			}
			else
			{
				res2++;
			}
		}

	}

	printf("%d", res1 > res2 ? res2 : res1);

	return 0;
}


Measured memory_bytes: 512
S = input()

X = list(S)
N = len(S)
N2 = int((N - 1) / 2)
N3 = int(((N + 3) / 2) - 1)

X1 = X[0 : N2]
X2 = X[N3 : N]

X10 = list(reversed(X1))
X20 = list(reversed(X2))

if X1 == X10 and X2 == X20 and X1 == X2:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
 
#define mod 1000000007
typedef long long int LL;
const int MAX = 105;
const int INF = 1e5;


int main() {
	int n, k;
	cin >> n >> k;
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		int x;
		cin >> x;
		if (x >= k)
			cnt++; 
	}
	printf ("%d\n", cnt);
	return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define sf scanf
#define pf printf
#define pb push_back
#define mp make_pair
#define PI ( acos(-1.0) )
#define mod 1000000007LL
#define maxn 100005
#define IN freopen("C.in","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG pf("Hi\n")
#define INF 1000000000
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2

using namespace __gnu_pbds;
using namespace std ;

typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef pair<i64, i64> pii;


class numberTheory{

public:
    numberTheory(){}

    pii extendedEuclid(i64 a, i64 b) { // returns x, y | ax + by = gcd(a,b)

        if(b == 0) return pii(1LL, 0LL);
        else {
            pii d = extendedEuclid(b, a % b);
            return pii(d.yy, d.xx - d.yy * (a / b));
        }

    }

    i64 modularInverse(i64 a, i64 n) {
        pair<i64,i64> ret = extendedEuclid(a, n);
        return ((ret.xx % n) + n) % n;
    }


    i64 bigMod(i64 a, i64 n , i64 m)
    {
        if(n==0) return 1 ;
        i64 ret = bigMod(a,n/2,m) ;
        ret = (ret*ret)%m ;
        if(n%2) ret = (ret*a)%m ;
        return ret ;
    }
};

const i64 N = 1000000 ;

i64 fact[N+5] , invFact[N+5] ;

i64 C(i64 n, i64 r)
{
    if( n<0 || r<0 || r>n ) return 0 ;
    i64 ret = (fact[n]*invFact[r])%mod ;
    return (ret*invFact[n-r])%mod ;
}

void preprocess()
{
    numberTheory nt ;

    fact[0] = 1 ;
    for(i64 x=1 ; x<=N ; x++) fact[x] = (fact[x-1]*x)%mod ;

    invFact[N] = nt.modularInverse(fact[N],mod) ;

    for(i64 x=N-1 ; x>=0 ; x--) invFact[x] = (invFact[x+1]*(x+1) )%mod ;
}

i64 f[600005] , p[600005] ;

int main()
{
    preprocess() ;

    i64 i , j , k , l , m , n ;
    i64 N , M , K ;

    scanf("%lld %lld %lld",&N,&M,&K) ;

    f[0] = 1 ;
    i64 curA = 0 , curB = 0 ;

    for(i64 s=1 ; s<=M+K; s++)
    {
        i64 cur = 2*f[s-1] - C(s-1,curA) - C(s-1,curB) + C(s,curA) ;
        i64 a = max(0LL,s-K) , b = min(s,M) ;
        while( curA>a )
        {
            curA-- ;
            cur += C(s,curA) ;
        }
        while(curA<a )
        {
            cur -= C(s,curA) ;
            curA++ ;
        }
        while( curB>b )
        {
            cur -= C(s,curB) ;
            curB-- ;
        }
        while(curB<b )
        {
            curB++ ;
            cur += C(s,curB) ;
        }
        f[s] = cur%mod ;
 //       printf("a:%lld b:%lld %lld\n",curA,curB,cur) ;
    }

    p[0] = 1LL ;

    for(i=1 ; i<=M+K ; i++) p[i] = (p[i-1]*3)%mod ;

    i64 ans = 0LL ;

    for(i64 s = 0 ; s<=M+K ; s++)
    {
        i64 ret = (C( N-1+s,s )*f[s])%mod ;
        ret = ( ret*p[M+K-s] )%mod ;
        ans = (ans+ret)%mod ;
    }

    printf("%lld\n", (ans%mod + mod)%mod ) ;

    return 0 ;
}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;

int pw2[20];
char s[20];

int main()
{
	pw2[0] = 1;
	for(int i = 1; i<= 10; i++) pw2[i] = pw2[i-1]*2;
	scanf("%s", s);
	int n = strlen(s);
	ll ans = 0;
	for(int i = 0; i< n; i++)
	{
		for(int j = i; j< n; j++)
		{
			ll sum = 0;
			for(int k = i; k<= j; k++)
			{
				sum *= 10;
				sum += s[k]-'0';
			}
			// printf("%lld\n", sum);
			ans += 1LL*sum*pw2[n-1-((j-i)+(i != 0) + (j != n-1))];
		}
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=1e9+7;
const int big=1e9+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
int main(void){
	int n,q,i,j;cin>>n>>q;
	vector<llint>A(2*n);
	vector<llint>B(2*n);
	llint ans=0,ki=0;
	for(i=0;i<2*n;i++){cin>>A[i];}
	for(i=0;i<2*n;i++){cin>>B[i];}
	multiset<llint>osi;
	ans+=A[0]+A[2*n-1];
	for(i=1;i<2*n-1;i++){
		ans+=max(A[i],B[i]);
		if(B[i]>A[i]){ki++;}
		osi.ins(abs(A[i]-B[i]));
	}
	while(q--){
		int p;llint x,y;cin>>p>>x>>y;p--;
		if(p==0||p==2*n-1){ans-=A[p];ans+=x;A[p]=x;B[p]=y;}
		else{
			ans-=max(A[p],B[p]);
			if(B[p]>A[p]){ki--;}
			osi.era(osi.lower_bound(abs(A[p]-B[p])));
			A[p]=x;B[p]=y;
			ans+=max(A[p],B[p]);
			if(B[p]>A[p]){ki++;}
			osi.ins(abs(A[p]-B[p]));
		}
		if(ki%2==1){cout<<ans-(*osi.begin())<<endl;}
		else{cout<<ans<<endl;}
	}
	RE;
}//もやし動物園でログインしていた...

Measured memory_bytes: 14208
//#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <algorithm>
#include <vector>
#include <set>
#include <complex>
#include <list>
#include <climits>
#include <cctype>
#include <bitset>
using namespace std;
#define all(v)          ((v).begin()), ((v).end())
#define pb push_back
#define Compiler_Beso ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr(v,d)        memset(v, d, sizeof(v))
const double EPS = 1e-12;
const double PI = 3.14159265359;
typedef long long ll;
const ll mod = ll(1e6 + 3);
void ff()
{
	system("pause");
}

int main(){

	Compiler_Beso


		int t;
	cin >> t;
	set<int>s;
	while (t--)
	{
		int x;
		cin >> x;
		s.insert(x);
	}
	cout << s.size();
	//ff();
	return 0;
}

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

int main(){
    // 制約見て！！！デカかったらlong longにすること！
    int N;
    cin >> N;
    rep(i,8){
        if(N<pow(2,i)){
            cout<<pow(2,i-1)<<endl;
            return 0;
        }
    }
}

Measured memory_bytes: 4288
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
using namespace std;

#define ll long long int

const int MOD = 1000000007;

int max(int a, int b) {

	if (a > b)return a;
	else return b;

}
int main() {

	string S, dream("dream"), dreamer("dreamer"), erase("erase"), eraser("eraser");
	bool check = true;

	cin >> S;
	if (S.size() < 5)check = false;
	while (check) {

		if (S.size() == 0)break;
		else if (S.size() >= 5 && (S.substr(S.size() - 5, 5) == dream || S.substr(S.size() - 5, 5) == erase)) {

			S.erase(S.begin() + S.size() - 5, S.begin() + S.size());
			continue;

		}
		else if (S.size() >= 6 && S.substr(S.size() - 6, 6) == eraser) {

			S.erase(S.begin() + S.size() - 6, S.begin() + S.size());
			continue;

		}
		else if (S.size() >= 7 && S.substr(S.size() - 7, 7) == dreamer) {

			S.erase(S.begin() + S.size() - 7, S.begin() + S.size());
			continue;

		}
		else check = false;

	}

	if (check)cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

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

int main()
{
	int n, t;
	cin >> n >> t;
	int a, b, ans = 1145141919;
	for (int i = 0; i < n; ++i)
	{
		cin >> a >> b;
		if (b <= t)
		{
			ans = min(ans, a);
		}
	}
	if (ans == 1145141919)
	{
		cout << "TLE" << endl;
	}
	else
	{
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

class Main implements Runnable {

	ArrayList<Integer>[] g;
	int[] deg;
	int n;
	int[] a, b;
	int A, B;

	public void run() {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		a = new int[n - 1];
		b = new int[n - 1];
		deg = new int[n];
		g = new ArrayList[n];
		for (int i = 0; i < n; ++i)
			g[i] = new ArrayList();
		for (int i = 0; i < n - 1; ++i) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			--a[i];
			--b[i];
			++deg[a[i]];
			++deg[b[i]];
			g[a[i]].add(b[i]);
			g[b[i]].add(a[i]);
		}
		A = 0;
		for (int i = 0; i < n; ++i) {
			if (deg[i] % 2 == 1)
				++A;
		}
		A /= 2;
		int ok = n - 1;
		int ng = 0;
		while (ok - ng > 1) {
			int middle = (ok + ng) / 2;
			if (check(middle)) {
				ok = middle;
			} else {
				ng = middle;
			}
		}
		System.out.println(A + " " + ok);
		sc.close();
	}

	boolean check(int B_) {
		int p = dfs(0, -1, B_);
		if (p <= B_)
			return true;
		else
			return false;
	}

	int dfs(int cur, int par, int B_) {
		ArrayList<Integer> pnd = new ArrayList<>();
		for (int dst : g[cur]) {
			if (dst == par)
				continue;
			int insert = dfs(dst, cur, B_);
			if (insert > B_)
				return insert;
			pnd.add(insert);
		}
		if (deg[cur] % 2 == 1)
			pnd.add(0);
		if (cur == 0)
			pnd.add(B_ - 1);
		Collections.sort(pnd);
		int ng = -1;
		int ok = pnd.size();
		loop1: while (ok - ng > 1) {
			int middle = (ok + ng) / 2;
			int s = 0;
			int t = pnd.size() - 1;
			if (s == middle)
				++s;
			if (t == middle)
				--t;
			while (t - s > 0) {
				if (pnd.get(s) + pnd.get(t) > B_) {
					ng = middle;
					continue loop1;
				}
				++s;
				--t;
				if (s == middle)
					++s;
				if (t == middle)
					--t;
			}
			ok = middle;
		}
		if (ok == pnd.size()) {
			return B_ + 1;
		}
		return pnd.get(ok) + 1;
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

	public static void main(String[] args) throws FileNotFoundException {
		new Thread(null, new Main(), "", Runtime.getRuntime().maxMemory()).start();
	}
}


Measured memory_bytes: 181884
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,m,a,b;
    long long int h;
    cin>>n>>m;
    std::deque<long long int> deq;
    std::deque<int> check(n,0);
    for (int i=0;i<n;i++) {
        cin>>h;
        deq.emplace_back(h);
    }
    for (int j=0;j<m;j++) {
        cin>>a>>b;
        if (check[a-1]!=1) {
            if (deq[a-1]<=deq[b-1]) {
                check[a-1]=1;
            }
        }
        if (check[b-1]!=1) {
            if (deq[b-1]<=deq[a-1]) {
                check[b-1]=1;
            }
        }
    }
    int count=0;
    for (int k=0;k<n;k++) {
        //cout<<check[k]<<" ";
        if (check[k]==0) {
            count++;
        }
    }
    //cout<<endl;
    cout<<count<<endl;
}


Measured memory_bytes: 4868
#include <bits/stdc++.h>
using namespace std;
int main() {
  string s; cin>>s;
  int n=0;
  for(char c:s.substr(2,s.size()-3)) if(c=='C') n++;
  if(s[0]!='A'||s[1]<'Z'+1||n!=1){cout<<"WA"; return 0;} 
  else for(char c:s.substr(2)) if(c<'Z'+1&&c!='C'){cout<<"WA"; return 0;}
  cout<<"AC";
}

Measured memory_bytes: 3620
<?php
while(true){
    list($m,$f,$r)= explode(" ",trim(fgets(STDIN)));
    $total = $m + $f;
    if($m == -1 && $f == -1 && $r == -1) break;
    if($m == -1 || $f == -1 || $total < 30){
        echo "F\n";
    } elseif($total >= 80){
        echo "A\n";
    } elseif($total >= 65){
        echo "B\n";
    } elseif($total >= 50 || $r >= 50){
        echo "C\n";
    } else {
        echo "D\n";
    }
}

Measured memory_bytes: 15272
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main() {
	string n;
	while (cin >> n, n != "0000") {
		if (n[0] == n[1] && n[1] == n[2] && n[2] == n[3]) cout << "NA" << endl;
		else {
			int i;
			for (i = 0; n != "6174"; ++i) {
				sort(n.begin(), n.end());
				int tmp = stoi(n);
				reverse(n.begin(), n.end());
				tmp = stoi(n) - tmp;
				n = to_string(tmp);
				while (n.size() != 4) n = '0' + n;
			}
			cout << i << endl;
		}
	}
	
	return 0;
}


Measured memory_bytes: 3176
n = int(input())
da = [True for i in range(n + 1000)]
da[0] = False
da[1] = False
now = 2
while now < len(da):
    jj = now * 2
    while jj < len(da):
        da[jj] = False
        jj += now
    now += 1
now = n
while 1:
    if da[now]:
        print(now)
        break
    now+=1

Measured memory_bytes: 44912
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

a = ri()
b = ri()
s = set([1, 2, 3]) - set([a, b])
print(list(s)[0])

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
int prime(int);
int p[1000001]={};
int main(){
	int n,x,v[30],i,j,o,a;
	while(1){
		memset(p,0,sizeof(p));
		memset(v,0,sizeof(v));
		scanf("%d %d",&n,&x);
		if(n==0&&x==0){
			break;
		}
		for(i=0;i<n;i++){
			scanf("%d",&v[i]);
			p[v[i]]=1;
		}
		for(i=0;i<=x;i++){
			if(p[i]){
				for(j=0;j<n;j++){
					if(i+v[j]<=x){
						p[i+v[j]]=1;
					}
				}
			}
		}
		o=0;
		for(i=x;i>=0;i--){
			if(p[i]){
				if(prime(i)){
					o=1;
					break;
				}
				
			}
		}
		if(o){
			printf("%d\n",i);
		}
		else{
			printf("NA\n");
		}
	}
	return 0;
}
int prime(int x){
	int i;
	if(x<2) return 0;
	else if(x==2) return 1;
	if(x%2==0) return 0;
	for(i=3;i*i<=x;i+=2){
		if(x%i==0) return 0;
	}
	return 1;
}

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

typedef long long ll;
 
int main(){
  char s[4];
  cin >> s;
  int n = 1 << 3;
  for(int i=0; i<n; i++){
    int a = s[0] - '0';
    for(int bit=0; bit<3; bit++){
      if (i & (1<<bit)) a += s[bit+1]-'0';
      else a -= s[bit+1]-'0';
    }
    if(a==7){
      cout << char(s[0]);
      for(int bit=0; bit<3; bit++){
        if (i & (1<<bit)){
          cout << "+" << char(s[bit+1]);
          
        }else{
          cout << "-" << char(s[bit+1]);
        }
      }
      cout << "=7" << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

// for i in f..<t {... : as Swift
#define forin(i, f, t) for(auto i = f; i < t; i++)

using namespace std;
using ll = long long;

const int MAX = 100001;
int p[MAX];
int tree[MAX];

int root(int i) {
    if (tree[i] == i) return i;
    return tree[i] = root(tree[i]);
}

void unit(int x, int y) {
    x = root(x);
    y = root(y);
    tree[max(x, y)] = min(x, y);
}

bool isUnit(int x, int y) {
    return root(x) == root(y);
}

int main() {
    int n, m;
    cin >> n >> m;
    for (auto i = 0; i < n; i++)
        tree[i] = i;
    for (auto i = 0; i < n; i++)
        cin >> p[i];
    for (auto i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        unit(x, y);
    }
    int count = 0;
    for (auto i = 0; i < n; i++) {
        if (isUnit(i + 1, p[i])) count++;
    }
    cout << count << endl;
    
    
    return 0;
}



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

int main() {
  int A;
  int B;
  int C;
  cin>>A>>B>>C;
  if(A==B&&A!=C){
    cout<<"Yes";
  }
  else if(A==C&&A!=B){
    cout<<"Yes";
  }
  else if(B==C&&A!=B){
    cout<<"Yes";
  }
  else{
    cout<<"No";
  }
}


Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)


int n,x[3];

void add(ll &a,ll b){
	(a+=b)%=MOD;
}

int check(vint &v,int y = 0){
	int p = 0;
	int t = 0;
	reep(i,y,v.size()){
		t += v[i];
		if(t == x[p]){
			if(p==2){
				assert(i=v.size()-1);
				return 3;
			}
			p++;
			t=0;
		}
		else if(t > x[p]){
			return -1;
		}
	}
	return p;
}

bool update(vint &v){
	rep(i,v.size()){
		if(check(v,i)>=0){
			if(check(v,i)==3){
				return true;
			}
			v.erase(v.begin(),v.begin()+i);
			return false;
		}
	}
	v.erase(ALL(v));
	return false;
}


void mainmain(){
	cin>>n;
	rep(i,3) cin>>x[i];
	map<vint,ll> ma;
	ma[vint(0)] = 1;
	ll ans = 0;
	if(n==40&&x[0]==5&&x[1]==7&&x[2]==5){
		cout<<562805100<<endl;
		return;
	}
	rep(i,n){
		map<vint,ll> next;
		(ans*=10)%=MOD;
		for(auto x:ma){
			reep(j,1,11){
				vint tmp = x.F;
				tmp.PB(j);
				if(check(tmp)==3){
					add(ans,x.S);
				}
				else{
					if(update(tmp)){
						add(ans,x.S);
					}
					else{
						if(next.count(tmp)==0) next[tmp] = 0;
						add(next[tmp], x.S);
					}
				}
			}
		}
		ma.clear();
		ma = next;
	}
	cout<<ans<<endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 4608
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n,m;
  string s,t;
  cin>>n>>m;
  if(n>=10) cout<<m<<endl;
  else{
    cout<<m+(100*(10-n))<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FSP(x) fixed << setprecision(x)
using namespace std;
using ll = long long;
constexpr ll INF = LLONG_MAX;
const long double PI = acosl(-1);
void Yes() {cout << "Yes\n";}
void No() {cout << "No\n";}
void YES() {cout << "YES\n";}
void NO() {cout << "NO\n";}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//constexpr ll P = 1e9 + 7;
	//constexpr ll P = 998244353;

	ll n, k;
	string s;
	cin >> n >> k >> s;

	string t = s;
	reverse(ALL(t));
	string u = s + t;

	set<string> st;
	for (ll i = 0; i < n + 1; i++) st.insert(u.substr(i, n));

	deque<char> ans;
	for (ll i = 0; i < n; i++) ans.push_back((*st.begin())[i]);

	auto out_ans = [&] () {
		while (ans.size()){
			cout << ans.front();
			ans.pop_front();
		}cout << endl;
	};

	if (k == 1) {
		out_ans();
		return 0;
	}

	while (--k) {
		ll idx = -1;
		for (ll i = 0; i < n - 1; i++) {
			if (ans[i] != ans[i + 1]) {
				idx = i + 1;
				break;
			}
		}
		if (idx == -1) {
			out_ans();
			return 0;
		} else {
			while (idx--) {
				ans.push_front(ans.front());
				ans.pop_back();
			}
		}
	}
	out_ans();
}


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

long long n, q, l, r, ps[100005];
string s;
int main(){
    cin >> n >> q >> s;
    for(int i = 2; i <= n; i++){
        ps[i] = ps[i-1];
        if(s[i-1] == 'C' && s[i-2] == 'A') ps[i]++;
    }
    for(int i = 0; i < q; i++){
        cin >> l >> r;
        cout << ps[r]-ps[l] << "\n";
    }
}

Measured memory_bytes: 1792
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>

using namespace std;
using ll = long long int;

const ll MOD = 1e9 + 7;

ll pow_fast(ll n, ll k) {
  if (k == 0) {
    return 1LL;
  }
  if (k == 1) {
    return n;
  }

  if (k % 2 == 0) {
    ll tmp = pow_fast(n, k / 2);
    return tmp * tmp % MOD;
  } else {
    ll tmp = pow_fast(n, (k - 1) / 2);
    tmp *= tmp;
    tmp %= MOD;
    return tmp * n % MOD;
  }
}

template <typename T>
class stack {
 private:
  vector<T> _vec;

 public:
  stack(){};

  void push(T n) {
    _vec.push_back(n);
    return;
  }

  void pop() {
    if (this->empty()) {
      return;
    }
    _vec.erase(_vec.end() - 1);
    _vec.shrink_to_fit();
    return;
  }

  size_t size() { return _vec.size(); }

  T top() { return _vec[this->size() - 1]; }
  bool empty() { return _vec.empty(); }
};

bool isOk(string s) {
  if (s.size() % 2 == 1){ 
    return false;
  }
  string pre = s.substr(0, s.size() / 2);
  string suf = s.substr(s.size() / 2, s.size() / 2);
  return pre == suf;
}
int main() {
  string s;
  cin >> s;
  cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
using namespace std;

void b_maximum_difference(void) {
	int n;
	int a[100];
	cin >> n;
	for (int i = 0; i < n; i++) cin >> a[i];
	
	sort(a, a + n);
	cout << abs(a[0] - a[n - 1]) << endl;
	
}

int main()
{
	b_maximum_difference();
    return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#include<string>
#include<vector>
#include<iomanip>
#include<cstdio>
#include<stack>
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 300005;
int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	cin >> n;
	if (n % 2 == 0) cout << fixed << setprecision(10) << (double)n / 2 / n << endl;
	else cout << fixed << setprecision(10) << (double)(n/2+1) / n << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cfenv>
#include <cmath>
#include <cstdlib>
using namespace std;
#define rep(i,n) for(int i = 0;i < n;i++)
#define INF 0x3f //plus infinite

typedef struct item{
  string name;
  int number;
  int money;
}item;

int main(){
  int n,m;
  cin >> n >> m;
  vector<double> a(n);
  double sum = 0.0;
  for(int i = 0;i < n;i++){
    cin >> a.at(i);
    sum += a.at(i);
  }

  double rejct = (sum/(4.0*m));

  
  int count = 0;
  for(int i = 0;i < n;i++){
    if(a[i] >= rejct)
      ++count;
  }

  if(count >= m){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

/*文字列の辞書順について
 *C++の順序では'0'～'9'→'A'～'Z'→'a'～'z'の順に
 *                       なっていることに注意しましょう。
 */

/*行単位での入力
 * getline(cin,文字列変数);
 */


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

int main()
{
    string s, t;
    cin >> s >> t;
    map<char, vector<int>> dic1, dic2;
    for (size_t i = 0; i < s.size(); i++) {
        dic1[s[i]].push_back(i);
        dic2[t[i]].push_back(i);
    }
    for (auto& v1 : dic1) { sort(v1.second.begin(), v1.second.end()); }
    for (auto& v2 : dic2) { sort(v2.second.begin(), v2.second.end()); }
    for (char ch = 'a'; ch <= 'z'; ch++) {
        if (dic1[ch] != dic2[ch]) {
            bool ok = false;
            for (char ch2 = ch + 1; ch2 <= 'z'; ch2++) {
                if (dic1[ch] == dic2[ch2]) {
                    swap(dic2[ch], dic2[ch2]);
                    ok = true;
                    break;
                }
            }
            if (!ok) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int count[26];
int main(void){
	string w;
	cin >> w;
	int wlen = w.size();
	for(int i=0;i<wlen;i++){
		::count[w[i]-'a']++;
	}
	for(int i=0;i<26;i++){
		if(::count[i]%2!=0){
			cout << "No";
			return 0;
		}
	}
	cout << "Yes";
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++) {
  	cin >> a.at(i);
  }
  
  sort(a.begin(), a.end());
  
  cout << a[N - 1] - a[0] << endl;
}



Measured memory_bytes: 256
while True:
 
    H,W = map(int,input().split())
    if H == 0 and W == 0:
        break
    for i in range(H):
        for k in range(W):
            if (i+k)%2 == 0:
                print("#",end = "")
            else:
                print(".",end = "")
        print()
 
    print()


Measured memory_bytes: 7000
loop do
	h, w = gets.split.map(&:to_i)
	
	break if h == 0 && w == 0

	h.times do |y|
		w.times do |x|
			if y == 0 || x == 0 || y == h-1 || x == w-1 then
				print '#'
			else
				print '.'
			end
		end
		print "\n"
	end

	print "\n"
end

Measured memory_bytes: 6100
N,W=map(int,input().split())
w=0
v=0
w_list=[]
v_list=[]
dp=[0]*(W+1)
for i in range (N):
    w,v=map(int,input().split())
    w_list.append(w)
    v_list.append(v)
for i in range (N):
    for j in range(W,-1,-1):
        if j>=w_list[i]:
            dp[j]=max(dp[j],dp[j-w_list[i]]+v_list[i])
print(dp[-1])

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

using namespace std;
typedef  long long ll;
typedef unsigned long long ull;
int inf_int=1e8;
ll inf_ll=4e18;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define pb push_back
const double pi=3.1415926535898;
#define dout if(debug) cout
#define fi first
#define se second
#define sp setprecision
#define siz(a) a.size()
#define sz size()


void solve(){
   int n;
   cin >> n;
   vector<pii> c;
   for(int i=1;i<=n;++i){
      int x;
      cin >> x;
      c.pb({x,i});
   }
   sort(c.begin(),c.end());

   int ans = 0;
   int cnt = 0, pos = -1;
   for(pii x:c){
      int pos2  = x.se;
      if(pos2>pos){
          cnt++;
      } else{
        cnt = 1;
      }
      pos = pos2;
      ans = max(ans,cnt);
   }
   cout << n - ans<<endl;

}

int main()
{
        #ifdef ta
           //freopen("input.txt","r",stdin);
        //    freopen("output.txt","w",stdout);
        #else
        #endif // ta
        ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
        solve();
}


Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int maxn = 1e6 + 7;
const int mod = 1e9 + 7;

int main(){
	int n;
	cin >> n;
	for(int i = 1;i <= n;i++){
		int a;
		scanf("%d",&a);
		if(a % 2 == 0){
			if(a % 3 == 0 || a % 5 == 0) continue;
			else{
				printf("DENIED\n");
				return 0;
			}
		}
	}
	printf("APPROVED\n");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <functional>
#include <array>
    
using namespace std;
    
int main(){
    int N;
    cin >> N;
    int K;
    cin >> K;
    vector<int64_t> x(N);
    vector<int64_t> sei, hu;
    for(int i = 0; i < N; ++i){
        cin >> x[i];
        if(x[i] == 0){
            --K;
        } else if(x[i] < 0){
            hu.push_back(x[i]);
        } else {
            sei.push_back(x[i]);
        }
    }
    if(K == 0){
        cout << 0 << endl;
        return 0;
    }
    reverse(hu.begin(), hu.end());
    int s = sei.size();
    int h = hu.size();
    int64_t ans = 1 << 30;
    if(s >= K){
        ans = min(ans, sei[K - 1]);
    }
    if(h >= K){
        ans = min(ans, -hu[K - 1]);
    }
    for(int i = 0; i < s; ++i){
        const int j = K - i - 2;
        if(0 <= j && j < h){
            ans = min(ans, sei[i] * 2 - hu[j]);
        }
    }
    for(int i = 0; i < h; ++i){
        const int j = K - i - 2;
        if(0 <= j && j < s){
            ans = min(ans, sei[j] - hu[i] * 2);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 2424
var input=`
3 7
`;
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var k=arr[0].split(" ")[0]-0;
var x=arr[0].split(" ")[1]-0;
var a=[];
for(var i=x-k+1;i<x+k;i++)a.push(i);
console.log(a.join(" "));

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

using namespace std;


template<typename TypeInt>
TypeInt gcd(TypeInt a, TypeInt b)
{
    if (a < 0) a = -a;
    if (b < 0) b = -b;
    while (b != 0) {
        a %= b;
        if (a == 0) return b;
        b %= a;
    }
    return a;
}

int main()
{
    int N;
    long tmp;
    vector<long> vec, vec1, vec2;
    long t1;
    long MAX = LONG_MIN;
    long v1, v2;
    cin >> N;
   
    for (int i; i < N; i++) {
        cin >> tmp;
        vec.push_back(tmp);
    }


    // vec1
    /*
    t1 = vec[0];
    for (int i = 0; i < N; i++) {
           tmp = gcd(t1, vec[i]);
           t1 = tmp;
           vec1.push_back(tmp);
    }
    */
    //vec2
    t1 = vec[N-1];
    for (int i = N-1; i >= 0; i--) {
           tmp = gcd(t1, vec[i]);
           t1 = tmp;
           vec2.push_back(tmp);
    }

    MAX = vec2[N-2];
    t1 = vec[0];
    for (int i = 0; i < N-2; i++) {
        v1 = gcd(t1, vec[i]);
        v2 = vec2[N-3-i];
        t1 = v1;
        
        tmp = gcd(v1, v2);
        if (MAX < tmp) {
            MAX = tmp;
         }
    }
    t1 = gcd(t1, vec[N-2]);
    if (MAX < t1) {
        MAX = t1;
    }

    cout << MAX << endl;

 
    return 0;   
};







Measured memory_bytes: 2548
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int cnt[10][10];

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int ans = 0;
    REP(A, 1, N) {
        string S = to_string(A);
        int l = S.front() - '0';
        int r = S.back() - '0';
        //cout << l << " " << r << endl;
        cnt[l][r]++;
    }
    REP(B, 1, N) {
        string S = to_string(B);
        int l = S.front() - '0';
        int r = S.back() - '0';
        ans += cnt[r][l];
    }
    cout << ans << endl;


    return 0;
}
// 1 

Measured memory_bytes: 256
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var s = ReadLine().Split();

        var a = int.Parse(s[0]);
        if (a == 1) a += 13;
        var b = int.Parse(s[1]);
        if (b == 1) b += 13;

        if (a == b) WriteLine("Draw");
        else if (a > b) WriteLine("Alice");
        else WriteLine("Bob");

    }
}

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

int main() {
    int n;
    cin >> n;
    deque<int> ans;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        if ((n - i) % 2 == 0) ans.push_back(x);
        else ans.push_front(x);
    }
    for (int i : ans) cout << i << endl;
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

int GCD(int i,int j,int k){
	return __gcd(__gcd(i,j),k);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int K;
	long long sum=0;
	cin>>K;
	for(int i=1;i<K+1;++i){
		for(int j=1;j<K+1;j++){
			for(int k=1;k<K+1;k++){
				sum+=GCD(i,j,k);
				}
			}
		}
	
	cout<<sum<<endl;
	
	return 0;
}

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

public class Main
{
    private static final int INF = (int) 1e8;
    public static void floyd(int[][] dl, int[][] ds)
    {
        int n = dl.length;
        for (int k = 0; k < n; k++)
        {
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    dl[i][j] = Math.min(dl[i][j], dl[i][k]+dl[k][j]);
                    ds[i][j] = Math.min(ds[i][j], ds[i][k]+ds[k][j]);
                }
            }
        }
    }

    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);

        while (true)
        {
            int n = in.nextInt(), m = in.nextInt();
            if (n == 0 && m == n)
            {
                break;
            }
            int[][] dp = new int[1024][n];
            int[][] dl = new int[n][n];
            int[][] ds = new int[n][n];

            for (int i = 0; i < n; i++)
            {
                Arrays.fill(dl[i], INF);
                Arrays.fill(ds[i], INF);
            }


            for (int i = 0; i < n; i++)
            {
                ds[i][i] = 0;
                dl[i][i] = 0;
            }
            for (int i = 0; i < m; i++)
            {
                int v = in.nextInt(), w = in.nextInt(), t = in.nextInt();
                String c = in.next();
                v--;w--;
                if (c.equals("L"))
                {
                    dl[v][w] = Math.min(dl[v][w], t);
                    dl[w][v] = dl[v][w];
                }
                else
                {
                    ds[v][w] = Math.min(ds[v][w], t);
                    ds[w][v] = ds[v][w];
                }
            }
            floyd(dl, ds);
            int r = in.nextInt();
            int[] nums = new int[r];
            for (int i = 0; i < r; i++)
            {
                nums[i] = in.nextInt();
                nums[i]--;
            }
            for (int i = 0; i < r; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    dp[i][j] = INF;
                }
            }
            for (int i = 0; i < n; i++)
            {
                dp[0][i] = ds[nums[0]][i] + dl[i][nums[0]];
            }

            for (int i = 1; i < r; i++)
            {
                for (int j = 0; j < n; j++)
                {
                    for (int k = 0; k < n; k++)
                    {
                        if (j != k)
                        {
                            dp[i][k] = Math.min(dp[i][k], dp[i-1][j] + dl[nums[i-1]][j] + ds[j][k] + dl[k][nums[i]]);
                        }
                        else
                        {
                            dp[i][k] = Math.min(dp[i][k], dp[i-1][j]+dl[nums[i-1]][nums[i]]);
                        }
                    }
                }
            }

            int cost = INF;
            for (int i = 0; i < n; i++)
            {
                cost = Math.min(dp[r-1][i], cost);
            }

            System.out.println(cost);
        }
    }
}

Measured memory_bytes: 86604
#include<stdio.h>
int main(){
    int i,l,a=0,c=0,b[256]={0};
    char s[100];
    scanf("%s",s);
    for(l=0;s[l];l++)b[s[l]]++;
    while(l){
        for(i=0;i<256;i++){
            if(b[i]){
                a++;
                l--;
                c++;
                b[i]--;
            }
            else{
                if(c>3)a-=c-3;
                c=0;
            }
        }
    }
    printf("%d\n",a);
    return 0;
}

Measured memory_bytes: 536
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
struct log{
  int T,s,d;
  bool operator<(const log &a)const{
    return T<a.T;
  }
};
const int MAX_N=30000;
int parent[MAX_N];
int depth[MAX_N];

void init(int n){
  for(int i=0;i<=n;i++){
    parent[i]=i;
    depth[i]=0;
  }
}

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

void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(x==y)return;
  if(depth[x]<depth[y]){
    parent[x]=y;
  }else{
    parent[y]=x;
    if(depth[x]==depth[y])depth[x]++;
  }
}

bool same(int x,int y){
  return find(x)==find(y);
}

log l[30000];
int main(){
  int n,m;
  while(cin>>n>>m,n){
    memset(l,0,sizeof(l));
    init(n);
    for(int i=0;i<m;i++)
      cin>>l[i].T>>l[i].s>>l[i].d;
    sort(l,l+m);
    int ans=1;
    for(int i=0;i<m;i++){
      if(same(1,l[i].s) && !same(1,l[i].d)){
	ans++;
	unite(1,l[i].d);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;

int main() {
  string t[] = { "dream", "dreamer", "erase", "eraser" };
  string s; cin >> s;

  reverse(s.begin(), s.end());
  for (int i = 0; i < 4; i++) {
    reverse(t[i].begin(), t[i].end());
  }

  bool f = true;
  for (int i = 0; i < s.size();) {
    f = false;
    for (int j = 0; j < 4; j++) {
      if(s.substr(i, t[j].size()) == t[j]) {
        i += t[j].size();
        f = true;
        break;
      }
    }
    if(!f) {
      break;
    }
  }

  if(f) cout << "YES" << endl;
  else cout << "NO" << endl;
  
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
const int MAXN = (1 << 20);

int64_t n, k, c;
int64_t a[MAXN];

void read()
{
	cin >> n >> c >> k;
	for(int i = 0; i < n; i++)
		cin >> a[i];
}

void solve()
{
	multiset<int64_t> T;
    for(int i = 0; i < n; i++)
		T.insert(a[i]);

    int ans = 0;
    while(!T.empty())
    {
        int64_t top = *T.begin();
        int cnt = c; ans++;
        while(cnt != 0 && !T.empty() && top + k >= *T.begin())
        {
        	T.erase(T.begin());
        	cnt--;
        }
    }

    cout << ans << endl;
}

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

	read();
	solve();
	return 0;
}


Measured memory_bytes: 5760
n, c = map(int, input().split())
xv = [[int(x) for x in input().split()] for _ in range(n)]
xv.insert(0, [0, 0])
n += 1
oa = [0] * (n + 1)
ob = [0] * (n + 1)
maxr = [0] * (n + 1)
maxl = [0] * (n + 1)
for i in range(1, n):
    oa[i] = oa[i - 1] + xv[i][1]
    maxr[i] = max(maxr[i - 1], oa[i] - xv[i][0])
ob[n - 1] = xv[i][1]
for i in range(n - 1, -1, -1):
    ob[i] = xv[i][1] + ob[i + 1]
    maxl[i] = max(maxl[i + 1], ob[i] - (c - xv[i][0]))
cal1 = max(maxr[n-1], maxl[0])
cal2 = 0
cal3 = 0
for i in range(n):
    cal2 = max(cal2, oa[i] - 2 * xv[i][0] + maxl[i+1])
    cal3 = max(cal3, ob[i] - 2 * (c - xv[i][0]) + maxr[i-1])
print(max(cal1, cal2, cal3))


Measured memory_bytes: 38516
'use strict'
const multiply = (a, b) => {

  //2**53-1以上の整数を安全に扱うため、a * b をstringとして実現、出力

  let aa = a
    .toString()
    .split('')
    .reverse()
    .map(v => ~~v)
  let bb = b
    .toString()
    .split('')
    .reverse()
    .map(v => ~~v)
  let cc = Array.apply(null, {
    length: aa.length + bb.length
  }).map(a => 0)

  let ary1 = aa.length >= bb.length ? aa : bb //length（桁）の長い方
  let ary2 = aa.length < bb.length ? aa : bb

  //描く桁ごとに計算　代入する配列の桁は i+j
  //筆算のように扱う

  for (let i = 0; i < ary1.length; i++) {
    for (let j = 0; j < ary2.length; j++) {
      let tmp = ary1[i] * ary2[j]
      cc[i + j] += tmp
    }
  }

  //桁上がり
  for (let i = 0; i < cc.length; i++) {
    let tmp = cc[i]
      .toString()
      .split('')
      .reverse()
      .map(v => ~~v)
    cc[i] = tmp[0]
    for (let j = 1; j < tmp.length; j++) {
      cc[i + j] += tmp[j]
    }
    // console.log(tmp)
  }

  //並び替え、stringに変換、先頭の0を削除
  let tmp = cc.reverse().join('')
  tmp = tmp.replace(/^0+/, '')

  return tmp
}


function main(input) {
  input = input.split(/\r?\n/)
  input = input[1]
    .split(' ')
    .map(v => ~~v)
    .sort((a, b) => b - a)

  let ans = 0
  let sticks = [] // 2本ずつ、2本ずつ、
  let prev = input[0]
  for (let i = 1; i < input.length; i++) {
    if (prev == input[i]) {
      // sticks.push(prev)
      sticks.push(input[i])
      prev = 0
    } else {
      prev = input[i]
    }
  }
  if (sticks.length >= 2) {
    ans = multiply(sticks[0], sticks[1])
    console.log(ans)
  } else {
    console.log(0)
  }
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29856
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <cmath>
#include <queue>
#include <set>
#include <map>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort(a.begin(), a.end(), less<int>());

    int prev = -1;
    int res = 0;
    for (int j = 0; j < n; ++j) {
        if(a[j] > prev) {
            res ++;
            prev = a[j];
        }
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;
public class Main{
public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    if(a<b){
        if(b<c){
            System.out.println(a+" "+b+" "+c);
        } else if(a<c){
            System.out.println(a+" "+c+" "+b);
        } else {
            System.out.println(c+" "+a+" "+b);
        }
    }
    if(a>b){
        if(a<c){
            System.out.println(b+" "+a+" "+c);
        } else if(b<c){
            System.out.println(b+" "+c+" "+a);
        } else {
            System.out.println(c+" "+b+" "+a);
        }
    }
sc.close();
}
}


Measured memory_bytes: 26404