akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <set>
#include <vector>

int main()
{
    int n;
    std::cin >> n;

    std::vector<int> a(n);
    std::vector<int> idx(n);
    for (int i = 0; i < n; i++) {
        std::cin >> a[i];
        a[i]--;
        idx[a[i]] = i;
    }

    std::set<int> s;

    long long ans = 0;
    for (int i = n - 1; i >= 0; i--) {
        int id = idx[i];
        s.insert(id);

        std::vector<int> l(2, -1);
        std::vector<int> r(2, n);

        auto pos = s.find(id);
        for (int j = 0; j < 2; j++) {
            if (pos == s.begin()) {
                break;
            }
            pos--;
            l[j] = *pos;
        }

        pos = s.find(id);
        for (int j = 0; j < 2; j++) {
            pos++;
            if (pos == s.end()) {
                break;
            }
            r[j] = *pos;
        }

        std::vector<int> ls(2);
        ls[0] = id - l[0];
        ls[1] = l[0] - l[1];

        std::vector<int> rs(2);
        rs[0] = r[0] - id;
        rs[1] = r[1] - r[0];

        long long c = (long long)ls[0] * rs[1] + (long long)ls[1] * rs[0];
        ans += c * (i + 1);
    }

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


Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  string s;
  cin >> s;
  ll n=s.size();
  ll W=0,E=0,N=0,S=0;
  for(ll i=0;i<n;i++) {
    if(s[i]=='W') W=1;
    if(s[i]=='E') E=1;
    if(s[i]=='N') N=1;
    if(s[i]=='S') S=1;
  }
  if((W^E)||(N^S)) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)


int main() {
  int X, A;
  cin >> X >> A;
  if (X < A)
    cout << 0;
  else
    cout << 10;
  cout << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <ctime>

#define inf 0x3f3f3f3f
#define Inf 0x3FFFFFFFFFFFFFFFLL
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Rep(i, n) for (int i = 1; i <= (n); ++i)
#define clr(x, a) memset(x, (a), sizeof x)
using namespace std;
typedef long long ll;
ll f[22][11];
ll a[22];
ll dfs(int d, int p, int flag, int z) {
  if (d < 0) return !z;
  if (f[d][p] != -1 && !flag && !z) return f[d][p];
  int end = flag ? a[d] : 9;
  int ret = 0;
  for (int i = 0; i <= end; ++i) {
    int diff = max(i - p, p - i);
    if (z || diff <= 1) {
      ret += dfs(d - 1, i, flag && i == end, z && i == 0);
    }
  }
  if (!flag && !z) f[d][p] = ret;
  return ret;
}

ll cal(ll n) {
  int m = 0;
  while (n) {
    a[m++] = n % 10;
    n /= 10;
  }
  clr(f, -1);
  return dfs(m - 1, 10, 1, 1);
}
int main() {
  int k; scanf("%d", &k);
  ll l = 1, r = 3234566667LL, mid;
  ll ans;
  while (l <= r) {
    ll mid = (l + r) / 2;
    int t = cal(mid);
    if (t >= k) {
      ans = mid;
      r = mid - 1;
    } else {
      l = mid + 1;
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int w,n,a[31];
  int i,c1,c2,t;

  scanf("%d",&w);
  for(i=1;i<=w;i++){
    a[i]=i;
  }
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d,%d",&c1,&c2);
    t=a[c1];
    a[c1]=a[c2];
    a[c2]=t;
  }
  for(i=1;i<=w;i++){
    printf("%d\n",a[i]);
  }
  return 0;
}
    

Measured memory_bytes: 596
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int a[n+1];
	
	for(int i=1;i<=n;i++)
	cin>>a[i];
	
	int j=1,s=0;
	for(int i=1;i<=n;i++){
	
	if(a[i]==j)
	{
		j++;
		s++;
	}
	}
	if(s==0)
	cout<<"-1"<<endl;
	else
	cout<<n-s<<endl;
	return 0;
	
}

Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long d = sc.nextLong();
		long e = sc.nextLong();
		FiveTrans ft = new FiveTrans(a, b, c, d, e);
		System.out.println(ft.calcTime(n));
	}
}

class FiveTrans {
	ArrayList<Long> limits = new ArrayList<Long>();
	
	public FiveTrans(long... limits) {
		for (long limit : limits) {
			this.limits.add(limit);
		}
	}
	
	public long calcTime(long n) {
		long minLimit = Long.MAX_VALUE;
		for (long limit : limits) {
			if (limit < minLimit) {
				minLimit = limit;
			}
		}
		long time = (n - 1) / minLimit + 5;
		return time;
	}
}


Measured memory_bytes: 22996
#include<iostream>
#include<cmath>
#include<numeric>
#include<algorithm>
#include<vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define int64 long long 
using namespace std;

int main(){
  int64 N,sweets,ans;
  cin>>N>>sweets;
  int64 kibou[N];
  rep(i,N){
    cin>>kibou[i];
  }
  sort(kibou,kibou+N);
  int64 sum[N];  
  sum[0]=kibou[0];
  for(int i=1;i<N;i++){
    sum[i]=kibou[i]+sum[i-1];
  }
  if(sum[N-1]<sweets){
    ans=N-1;
  }else if(sum[0]>sweets){
    ans=0;
  }else if(sum[N-1]==sweets){
    ans=N;
  }else{
    rep(i,N-1){
      if(sum[i]<=sweets && sweets<sum[i+1]){
        ans=i+1;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
// __uint128_t

int main(){
    ll a; double b; cin >> a >> b;
    ll B = b*1000;
    if(B%10 != 0) B++;
    B /=10;
    ll ans = (a*B)/100;
    cout << ans << endl;
    
}

Measured memory_bytes: 3712
/*	MASTER HAS FAILED MORE TIMES
	THAN BEGINNER HAS EVER TRIED
*/

#include <bits/stdc++.h>

using namespace std;

#define endl             '\n'
#define all(a)           a.begin(), a.end()
#define mem(a, n)        memset(a, n, sizeof(a))
#define Unique(n)        (n).erase(unique(all(n)), (n).end())
#define NumofDigits(n)   ((long long)log10(n)+1)
#define repeat(i, a, n)  for(int i=a; i<n; i++)
#define isPowerOfTwo(n)  (n && !(n & (n - 1)))

typedef long long ll;
typedef long double ld;

int sieve(int n);
unsigned long long pow(long long base, long long power);
long long gcd(long long a, long long b){ return a%b ? gcd(b, a%b) : b; }
long long lcm(long long a, long long b){ return a*b/gcd(a, b); }

void quicken(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
void file(){
#ifdef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif /*ONLINE_JUDGE*/
}

int main(){
    quicken();

    int n, m; cin >> n >> m;
    cout << n*(n-1)/2 + m*(m-1)/2;

    return 0;
}

unsigned long long pow(long long base, long long power){  /// mod?
    if(power==0)
        return 1;
    if(power==1)
        return base;

    unsigned long long ans = pow(base, power/2); /// mod?
    ans *= ans; /// ((ans%mod)*(ans%mod))%mod;

    if(power&1)
        return ans*base; /// ((ans%mod)*(base%mod))%mod;
    return ans;
}

int sieve(int n){
    int c = 0;
    vector<bool> isPrime(n+1, true);
    isPrime[0] = isPrime[1] = 0;

    for(long long i=2; i*i<=n; i++)
        if(isPrime[i])
            for(long long j=i*2; j<=n; j+=i)
                isPrime[j] = 0;
    repeat(i, 0, n+1)
    if(isPrime[i])
        c++;
    return c; /// primeCount [1:n]
}


Measured memory_bytes: 256
n = int(input())
cards = [input() for _ in range(n)]
t = 0
h = 0
for card in cards:
  c = card.split(' ')
  i = 0
  while True:
    l, r = [0, 0]
    if i < len(c[0]):
      l = ord(c[0][i])
    if i < len(c[1]):
      r = ord(c[1][i])
    if l == 0 and r == 0:
      t += 1
      h += 1
      break
    if r < l:
      t += 3
      break
    elif l < r:
      h += 3
      break
    i += 1
print("{0} {1}".format(t, h))


Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define int long long
#define N 100010
using namespace std;
const int INF = 1LL<<55;
const int mod = (1e9)+7;
const double EPS = 1e-8;
const double PI = 6.0 * asin(0.5);
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template< class T > void prArray(T a,char ch = ' '){
  for(int i=0;i<(int)a.size();i++,cout<<ch){
    if(i) cout<<ch;
    cout<<a[i];
  }
  cout<<endl;
}

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

int X,Y;
vector<int> A,B;
void calc(string s){
  int x = 0,y = 0;
  int dir = 0;
  for(char ch:s){
    if(ch == 'F') x += dx[dir], y += dy[dir];
    if(ch == 'T') {
      if(A.empty() || x) A.push_back(x);
      if(y)B.push_back(y);
      dir = !dir;
      x = y = 0;
    }
  }
  if(A.empty() || x) A.push_back(x);
  if(y)B.push_back(y);
}

unordered_set<int> used[2][8010];
int dfs(int flg,int idx,int sum,int target,vector<int> &v){
  if(idx == (int)v.size()) return sum == target;
  if(used[flg][idx].count(sum)) return 0;
  used[flg][idx].insert(sum);
  if(dfs(flg,idx+1,sum+v[idx],target,v)) return 1;
  if(v[idx] && dfs(flg,idx+1,sum-v[idx],target,v)) return 1;
  return 0;
}

signed main(){
  string s;
  cin>>s;
  cin>>X>>Y;
  calc(s);
  if(A.empty()) A.push_back(0);
  if(B.empty()) B.push_back(0);
  int a = dfs(0,1,A[0],X,A);
  int b = dfs(1,0,0,Y,B);
  int ans = a && b;
  cout<<(ans? "Yes":"No")<<endl;
  
  //for(int a:A)cout<<a<<" ";cout<<endl;
  //for(int b:B)cout<<b<<" ";cout<<endl;
  return 0;
}


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

class DICE
{
private:
	const int dice_tem[5][6] = { { 3,2,6,1,5,4 },{ 2,6,3,4,1,5 },
	{ 5,1,3,4,6,2 },{ 4,2,1,6,5,3 },{1,2,3,4,5,6} }; //{0}:W {1}:N {2}:S {3}:E {4}:defalut   
	const string dice_rl = "AWWWNWWWNWWWWNWWWSWWWSWWW"; 
	const int n = 6;
	int dice_i[6] = { 0 };
	int dice_j[6] = { 0 };
	int a = 4;

	void setup() {
		for (int i = 0; i < n; i++) {
			cin >> dice[i];
			dice_i[i] = dice[i];
		}
	}
public:
	int dice[6];
	int num = 0;
	const int dice_suffle_num = dice_rl.length();
	DICE() {
		setup();
	}

	void roll_dice() {
		switch (dice_rl[num])
		{
		case 78: //N
			a = 1;
			break;
		case 83: //S
			a = 2;
			break;
		case 87: //W
			a = 0;
			break;
		case 69: //E
			break;
			a = 3;
		default:
			a = 4;
			break;
		}

		for (int i = 0; i < n; i++) dice_j[i] = dice_i[dice_tem[a][i] - 1];
		for (int i = 0; i < n; i++) dice_i[i] = dice_j[i];
		num++;
	}
	int check(int i) {
		return dice_i[i];
	}
};

int main() {
	const int n = 6;
	bool flag = false;
	DICE base;
	DICE check;
    for (int i = 0; i < base.dice_suffle_num; i++) {
		check.roll_dice();
		for (int j = 0; j < n; j++) {
			if (base.dice[j] != check.check(j)) {
				flag = false;
				break;
			}
			flag = true;
		}
		if (flag == true)break;
	}
	if (flag == true) {
		cout << "Yes" << endl;
	}
	else if (flag == false) {
		cout << "No" << endl;
	}
	return 0;
}



Measured memory_bytes: 3220
#include<iostream>

using namespace std;

const static int MAX_N = 100;

int a[MAX_N];

int main() {
  int N;

  cin >> N;

  for (int i = 0; i < N; i++) { 
    cin >> a[i];
  }

  int cnt = 0;
  int minc = 1000000000;
  for (int n = -100; n <= 100; n++) {
    cnt = 0;
    for (int i = 0; i < N; i++) {
      cnt += (a[i] - n) * (a[i] - n);
    }
    minc = min(minc, cnt);
  }

  cout << minc << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100000;

int main(void){
    ll A, B;

    cin >> A >> B;

    if (A % 2 == 0 || B % 2 == 0) cout << "No" << endl; 
    else cout << "Yes" << endl;

    return 0;
}

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

namespace ConsoleApp62 {
    class Program {
        static void Main(string[] args) {
            int N = int.Parse(Console.ReadLine());

            string[] W = new string[N];

            for (int i = 0; i < N; i++) {
                W[i] = Console.ReadLine();
            }

            if (W.Length != W.Distinct().Count()) {
                Console.WriteLine("No");
                return;
            }

            for (int i = 0; i < N - 1; i++) {
                if (W[i][W[i].Length - 1] != W[i + 1][0]) {
                    Console.WriteLine("No");
                    return;
                }

            }

            Console.WriteLine("Yes");
        }
    }
}


Measured memory_bytes: 13280
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int n;
int ans = 0;
int sft[3] = {3,5,7};

bool check(int x){
	bool three=false,five=false,seven=false;
	while(x>0){
		if(x%10==3) three=true;
		else if(x%10==5) five = true;
		else if(x%10==7) seven = true;
		x/=10;
	}

	if(three&&five&&seven) return true;
	else return false;
}

void func(int digit,int x){
	if(digit>=10) return;
	int res = x;
	for(int i = 0; i < 3; i++){
		if(res + sft[i]*pow(10,digit) <= n){
			if(check(res + sft[i]*pow(10,digit))) ans++;
		}
		func(digit+1,res+sft[i]*pow(10,digit));
	}
}

int main()
{
	cin >> n;
	if(n<357){
		cout << 0 << endl;
		return 0;
	}
	func(0,0);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
 
  int n; rd(n);
  int m; rd(m);
 
  auto g=new int[][](n);
  foreach(i; 0..m){
    int a, b; rd(a, b);
    g[a-1]~=(b-1);
  }
 
  auto vis=new bool[](n), seq=new int[](0);
  bool multi=false;
  void dfs(int i){
if(vis[i]) return;
    vis[i]=true;
    int cnt=0;
    foreach(j; g[i]){
      if(vis[j]) continue;
      cnt++; dfs(j);
    }
    if(cnt>1) multi=true;
    seq=i~seq;
  }
   
  foreach(i; 0..n)if(vis[i]==false) dfs(i);
  writefln("%(%s\n%)", seq.map!(i=>i+1));
  if(multi) writeln(1);
  else writeln(0);
}
void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}


Measured memory_bytes: 15032
# coding: utf-8


def solve(*args: str) -> str:
    h, n = map(int, args[0].split())

    AB = [tuple(map(int, s.split())) for s in args[1:]]

    inf = 10**12
    dp = [inf]*(h+1)
    dp[0] = 0
    for a, b in AB:
        for i, m in enumerate(dp):
            k = min(h, i+a)
            dp[k] = min(dp[k], dp[i]+b)

    return str(dp[-1])


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


Measured memory_bytes: 41948
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T, class U> inline bool chmax(T& a,U b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> inline bool chmin(T& a,U b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const int dh[8] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dw[8] = {1, 0, -1, 0, 1, 1, -1, -1};

template <typename T> vector<T> dijkstra(const vector<vector<pair<int, T>>> &g, int s, bool flag){
    using P = pair<T, int>;
    const T inf = numeric_limits<T>::max();
    vector<T> ret(g.size(), inf); ret[s] = 0;
    if (flag) ret[0] = 1;
    priority_queue<P, vector<P>, greater<P>> que;
    que.emplace(ret[s], s);
    while (not que.empty()) {
        int v; T c; tie(c, v) = que.top(); que.pop();
        if (ret[v] < c) continue;
        for (auto &e : g[v]) {
            int u; T d; tie(u, d) = e;
            if (ret[v] == inf) continue;
            if (ret[u] > ret[v] + d) {
                ret[u] = ret[v] + d;
                que.emplace(ret[u], u);
            }
        }
    }
    return ret;
}

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    for (auto& e : s) cin >> e;
    
    vector<vector<pair<int, int>>> g(h*w);
    auto idx = [&] (int i, int j) { return i * w + j; };
    
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int v = idx(i, j);
            for (int k = 0; k < 2; k++) {
                int di = i + dh[k], dj = j + dw[k];
                if (di < 0 or h <= di or dj < 0 or w <= dj) continue;
                int u = idx(di, dj);
                if (s[i][j] == '.' and s[di][dj] == '#') g[v].emplace_back(u, 1);
                else g[v].emplace_back(u, 0);
            }
        }
    }
    
    vector<int> dist = dijkstra(g, 0, (s[0][0] == '#'));
    cout << dist[idx(h-1, w-1)] << endl;
    return 0;
}

Measured memory_bytes: 1152
N = int(input())

xys = []

for i in range(N):
    tmp_xy = []
    for j in range(int(input())):
        tmp_xy.append(tuple(map(int, input().split())))
    xys.append(tmp_xy)
        



status = [0 for _ in range(N)]

ans = 0

for i in range(2**N):
    tmp = format(i, 'b').zfill(N)

    
    for j in range(N):
        status[j] = int(tmp[-j-1])
    
    tmp_ans = 0
    isCorrect = True
    for j in range(N):
        if(status[j] == 1):
            for xy in xys[j]:

                if(status[xy[0]-1] != xy[1]):
                    isCorrect = False
                    break
            tmp_ans += 1
        if(not isCorrect):
            tmp_ans = 0
            break

    ans = max(ans, tmp_ans)

print(ans)

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

#define pb push_back
#define ff first
#define ss second

const long long MAXN = 1e5 + 21, inf = 1e18 + 21, LG = 20;

int n, c, k;
int a[MAXN];
long long ans, tmp, nxt;

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cin >> n >> c >> k;
    for (int i = 0; i < n; i++)
	cin >> a[i];
    sort(a, a + n);

    for (int i = 0; i < n; i++) {
	tmp = 0;
	ans++;
	nxt = a[i] + k;

	for (int j = i; j < n; j++) {
	    if (a[j] <= nxt) {
		tmp++;
		if (tmp == c) {
		    i = j;
		    break;
		}
		i = j;
	    }
	    else {
		i = (j - 1);
		break;
	    }
	}
    }

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


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <stack>
#include <cstdlib>
using namespace std;

int Len;

void dfs(string s,char mx)
{
	if (s.length() == Len) {
		cout << s<<'\n';
		return;
	}
	for(char x='a';x<=mx;x++)
		dfs(s + x, ((x == mx) ? (char)(mx + 1) : mx));
}

int main()
{
	
	cin >> Len;
	dfs("", 'a');
}

Measured memory_bytes: 1536
#include<stdio.h>
int main()
{
  unsigned long N;
  scanf("%lu",&N);
  unsigned long A[N],B[N];
  int i;
  for(i=0;i<N-1;i++){
    scanf("%lu",&A[i]);
    B[i]=0;
  }
  B[N-1]=0;
  unsigned long j;
  for(i=0;i<N-1;i++){
    j=A[i];
    B[j-1]=B[j-1]+1;
  }
  for(i=0;i<N;i++){
    printf("%lu\n",B[i]);
  }
  return 0;
}

Measured memory_bytes: 4856
#include <bits/stdc++.h>
#define il inline
#define RG register
#define ll long long
#define inf (1LL<<60)

using namespace std;

ll a[100005],k,ans1,ans2;

il ll gi(){
  RG ll x=0,q=1; RG char ch=getchar();
  while ((ch<'0' || ch>'9') && ch!='-') ch=getchar();
  if (ch=='-') q=-1,ch=getchar();
  while (ch>='0' && ch<='9') x=x*10+ch-48,ch=getchar();
  return q*x;
}

il ll check(RG ll key){
  for (RG ll i=1;i<=k;++i){
    if (key<a[i]) return 0;
    key-=key%a[i];
  }
  return key;
}

int main(){
  k=gi();
  for (RG ll i=1;i<=k;++i) a[i]=gi();
  if (a[k]!=2) puts("-1"),exit(0);
  RG ll l=2,r=inf,mid,res;
  while (l<=r){
    mid=(l+r)>>1,res=check(mid);
    if (res==2) ans1=mid,r=mid-1;
    else if (res>2) r=mid-1;
    else l=mid+1;
  }
  l=2,r=inf;
  while (l<=r){
    mid=(l+r)>>1,res=check(mid);
    if (res==2) ans2=mid,l=mid+1;
    else if (res>2) r=mid-1;
    else l=mid+1;
  }
  if (ans1 && ans2) cout<<ans1<<' '<<ans2;
  else cout<<-1;
  return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int w,h,x,y,r,flag=0;
		w = sc.nextInt();
		h = sc.nextInt();
		x = sc.nextInt();
		y = sc.nextInt();
		r = sc.nextInt();
		
		if(x+r>w)flag=1;
		if(x-r<0)flag=1;
		if(y+r>h)flag=1;
		if(y-r<0)flag=1;
		
		if(flag==0)System.out.println("Yes");
		else System.out.println("No");
	}
}



Measured memory_bytes: 26352
N,M,X,Y = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
x.sort(reverse=True)
y.sort()
OK = True
for i in range(X+1,Y+1):
    if x[0]<i and i<=y[0]:
        OK = False
print('War' if OK else 'No War')


Measured memory_bytes: 38256
#include <iostream>
using namespace std;
int main(void){
    int H,W;
    for(;;){
        cin>>H>>W;
        if(H==0,W==0){
            break;
        }
        for(int i=1;i<=H;i++){
            for(int y=1;y<=W;y++){
             cout<<"#";   
            }
            cout<<endl;
        }
        cout<<endl;
    }
}


Measured memory_bytes: 3100
#include<iostream>
using namespace std;
int main()
{
  int a,b;
  cin>>a>>b;
  if(a*b>=a+b && a*b>=a-b)
    cout<<a*b;
  else
    if(a-b>=a+b && a-b>=a*b)
      cout<<a-b;
  else
    if(a+b>=a-b && a+b>=a*b)
      cout<<a+b;
}


Measured memory_bytes: 256
def ascan; gets.split.map(&:to_i);end

require 'prime'

pr = []
g = Prime::EratosthenesGenerator.new
while (t = g.next) < 250000
    pr << t
end


while (n = gets.to_i) != 0
    p pr.bsearch_index{|x| 2*n < x} - pr.bsearch_index{|x| n < x}
end


Measured memory_bytes: 8620
def solve_d(n, k, s):
    res = 0
    for i in range(n - 1):
        if s[i] == s[i + 1]:
            res += 1
    d = n - 1 - res
    if 2 * k > d:
        return n - 1
    else:
        return res + 2 * k


def main():
    n, k = map(int, input().split())
    s = list(input())
    print(solve_d(n, k, s))


if __name__ == "__main__":
    main()


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

int main(){
  long long int x;
  cin >> x;
  if((x%11)==0 || ((((x*2)-1)%11)==0)){cout << ((x*2)/11) << endl;}
  else{cout << ((x*2)/11)+1 << endl;}
  return 0;
}


Measured memory_bytes: 384
from collections import deque
from typing import Optional


class DeletableDeque:
    """Deletable Deque: a deque that supports lazy deletion of values."""

    __slots__ = ["_set", "_deque"]

    def __init__(self, *initial_values: int) -> None:
        self._set = set()
        self._deque = deque([])

        if initial_values:
            for v in initial_values:
                self.append(v)

    @property
    def topleft(self) -> Optional[int]:
        """Return the leftmost value from the deque.
        If the deque is empty, None is returned.
        """
        while self._deque and self._deque[0] not in self._set:
            self._deque.popleft()
        if not self._deque:
            return None
        return self._deque[0]

    def append(self, value: int) -> None:
        """Append value to the right side of the deque."""
        if value in self._set:
            return
        self._set.add(value)
        self._deque.append(value)

    def delete(self, value: int) -> None:
        """Delete value from the deque."""
        if value not in self._set:
            return
        self._set.discard(value)


def agc018_b():
    # https://atcoder.jp/contests/agc018/tasks/agc018_b
    import sys
    from collections import Counter

    readline = sys.stdin.buffer.readline

    N, M = map(int, readline().split())
    A = [DeletableDeque(*map(int, readline().split())) for _ in range(N)]

    res = 301
    for _ in range(M):
        cnt = Counter(a.topleft for a in A)
        popular_sport = max(cnt, key=cnt.get)
        res = min(res, cnt[popular_sport])
        for a in A:
            a.delete(popular_sport)

    print(res)


if __name__ == "__main__":
    agc018_b()


Measured memory_bytes: 14028
#include <iostream>

using namespace std;

long long floor(long long a, long long b)
{
  return a / b;
}


long long solve(long long n)
{
  if (n % 2 == 1) {
    return 0;
  }

  long long result = 0;
  long long tmp;

  long long divisor = 10;
  while (divisor <= n) {
    tmp = floor(n, divisor);
    // cout << "tmp: " << tmp << endl;
    result += tmp;
    divisor *= 5;
  }

  return result;
}


int main(int argc, char const* argv[])
{
  long long n;

  cin >> n;

  cout << solve(n) << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int k = scanner.nextInt();
        int[] h = new int[n];
        for (int i = 0; i < n; i++) h[i] = scanner.nextInt();
        int[] dp = new int[n];
        for (int i = 1; i < n; i++) {
            int min = Integer.MAX_VALUE;
            for (int j = Math.max(0,i-k); j < i; j++) {
                min = Math.min(min, dp[j]+Math.abs(h[i]-h[j]));
            }
            dp[i]=min;
        }
        System.out.println(dp[n-1]);        
    }
}


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

int main(){
  int64_t N,K,first=0,roop=0,next=0;
  cin >> N >> K;
  vector<int64_t> A(N),B(N+1);
  for(int64_t i=0;i<N;i++){
    cin >> A.at(i);
    A.at(i)--;
  }
  B.at(0)=0;
  for(int64_t i=0;i<N;i++){
    B.at(i+1)=A.at(B.at(i));
  }
  int64_t i=0;
  while(true){
    if(B.at(i)==B.at(N)){
      first=i;
      break;
    }
    i++;
  }
  i=0;
  while(true){
    if(B.at(first-i)!=B.at(N-i)){
      first-=i-1;
      break;
    }
    if(i==first){
      first=0;
      break;
    }
    i++;
  }
  next=B.at(first);
  while(true){
    roop++;
    next=A.at(next);
    if(next==B.at(first)){
      break;
    }
  }
  if(K>first){
    K-=first;
    K=K%roop;
  }else{
    next=0;
  }
  while(true){
    if(K==0){
      cout << next+1 << endl;
      return 0;
    }
    K--;
    next=A.at(next);
  }
}
    

Measured memory_bytes: 6412
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
   int n;
   cin >> n;

   int* nums = new int[n];

   int k;
   for(int i=0;i<n;i++){
      cin >> k;
      nums[i] = k;
   }

   sort(nums, nums + n);

   long ans = 0;
   if(n%2==0){
      for(int i=0;i<n/2;i++){
         ans += 2 * (nums[i+n/2] - nums[i]);
      }

      ans -= nums[n/2] - nums[n/2-1];
   }
   else{
      for(int i=0;i<n/2-1;i++){
         ans += 2 * (nums[i+n/2+2] - nums[i]);
      }

      ans += max(nums[n/2] + nums[n/2+1] - 2 * nums[n/2-1], 2 * nums[n/2+1] - nums[n/2] - nums[n/2-1]);
   }

   cout << ans << endl;
}

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

using namespace std;

int main(){
    string s[3]; cin >> s[0] >> s[1] >> s[2];

    cout << (char)toupper(s[0][0]) << (char)toupper(s[1][0]) << (char)toupper(s[2][0]) << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		while(true)
		{
			int a = scan.nextInt();
			String str = scan.next();
			int b = scan.nextInt();

			if(str.equals("?") ) break;

			switch(str)
			{
				case "+":
					System.out.println(a+b);
					break;
				case "-":
					System.out.println(a-b);
					break;
				case "*":
					System.out.println(a*b);
					break;
				case "/":
					System.out.println(a/b);

				default:
					break;
			}
		}

		scan.close();
	}
}

Measured memory_bytes: 26252
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
    int n;
    cin >> n;
    ll sum = 0;
    rep(i,1,n+1){
        for(int j=i;j<=n;j+=i){
            sum += j;
        }
    }
    // rep(i,1,n+1){
    //     for(int j=i;j<n;j+i){
    //         sum += j;
    //     }
    // }
    cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 3620
from collections import Counter
from itertools import combinations
N=int(input())
S=[input()[0] for i in range(N)]
S=Counter(S)
h=combinations(['M','A','R','C','H'],3)
h_dic={'M':0,'A':0,'R':0,'C':0,'H':0}
ans = 0
for key,value in S.items():
    if key in h_dic:
        h_dic[key] = value

for i in h:
    tmp = 1
    for j in i:
        tmp *= h_dic[j]
    ans += tmp
print(ans)

Measured memory_bytes: 4224
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt();
	    int a =0;
	    int h[]  = new int[N];
	    int NN1[] = new int[N];
	    int xx1[] = new int[N];
	    int NN2[] = new int[N];
	    int xx2[] = new int[N];
	    int NN3[] = new int[N];
	    int xx3[] = new int[N];
	    //int x =0,y=0,z=0;
	    for(int i = 0;i < N;i++){
	    	a = sc.nextInt();
    		NN1[i] = a;
    		a = sc.nextInt();
    		NN2[i] = a;
    		a = sc.nextInt();
    		NN3[i] = a; 	
    	}
	    for(int k = 0;k<N;k++){
	    	for(int l = 0;l<N;l++){
	   			//if(k==l) continue;
	   			if(NN1[k]==NN1[l]){
	   				if(k==l){
	   					NN1[k]=NN1[k];
	   				}else{
	   					xx1[k] = 0;
	   					break;
	   				}
	   			}
	   			xx1[k]=NN1[k];
    			/*if(k==l) continue;
	   			if(NN1[k]==NN1[l]){
	   				NN1[k] = 0;
	   			}
	   			if(k==l) continue;
    			if(NN1[k]==NN1[l]){
	    			NN1[k] = 0;
	    		}*/
	   		}
	    	
	   	}
	    for(int k = 0;k<N;k++){
	    	for(int l = 0;l<N;l++){
	   			//if(k==l) continue;
	   			if(NN2[k]==NN2[l]){
	   				if(k==l){
	   					NN2[k]=NN2[k];
	   				}else{
	   					xx2[k] = 0;
	   					break;
	   				}
	   			}
	   			xx2[k] = NN2[k];
	   				
    			/*if(k==l) continue;
	   			if(NN2[k]==NN2[l]){
	   				NN2[k] = 0;
	   			}
	   			if(k==l) continue;
    			if(NN2[k]==NN2[l]){
	    			NN2[k] = 0;
	    		}*/
	   		}
	    	
	   	}
	    for(int k = 0;k<N;k++){
	    	for(int l = 0;l<N;l++){
	   			if(k==l) continue;
	   			if(NN3[k]==NN3[l]){
	   				xx3[k] = 0;
	   				break;
	   			}
    			/*if(k==l) continue;
	   			if(NN3[k]==NN3[l]){
	   				NN3[k] = 0;
	   			}
	   			if(k==l) continue;
    			if(NN3[k]==NN3[l]){
	    			NN3[k] = 0;
	    		}*/
	   			xx3[k]=NN3[k];
	    	}	
   			
	   	}
	    for(int i = 0;i<N;i++){
	    	h[i]=xx1[i]+xx2[i]+xx3[i];
	    	System.out.println(h[i]);
	    }
	}

}

Measured memory_bytes: 28372
#include <bits/stdc++.h>
using namespace std;
#define ll  long long
struct triple{ll   x=0;ll   y=0;ll   z=0;void mt(ll   a,ll   b, ll   c){x=a;y=b;z=c;} void holify(){x=69;y=420;z=911;}};
#define pb push_back
#define x first 
#define y second
#define vec vector
#define pf(vec,val) vec.insert(vec.begin(),val)
#define mp make_pair
#define pii pair<ll  ,ll  >
#define maxll  69696991169
#define minll  -69696942069
#define sz(vec) (ll )vec.size()
#define speedup ios_base::sync_with_stdio(0); cin.tie(NUll ); cout.tie(NUll );
#define loop(mep) for(auto it = mep.begin();it!=mep.end();++it)
//#define usaco_crap(str)ifstream cin((string)str + (string)".in"); ofstream cout ((string)str+(string)".out");
#define range(n) =0;i<(n);i++
#define prll  (vec) for(auto it=vec.begin();it!=vec.end();++it)cerr<<*it<<" ";cerr<<endl;
// mt make triple // triple.mt(a,b,c) //
int  main(){
	int a,b; cin>>a>>b;
	if(a>=1&&a<=9&&b>=1&&b<=9)cout<<a*b;
	else cout<<-1;
}


Measured memory_bytes: 256
N = int(input())
S = []
for i in range(N):
    a,b=input().split()
    S.append((a, int(b)))

S_sort = sorted(S, key=lambda x:(x[0], -x[1]))

for i in range(N):
    for j in range(N):
        if S[j][0]==S_sort[i][0] and S[j][1]==S_sort[i][1]:
            print(j+1)

Measured memory_bytes: 3064
#r, d, x = map(int,input().split())
#n = int(input())
#ls = list(map(int,input().split()))
s = input()

if 0 < int(s[2:]) < 13 and 0 < int(s[0:2]) < 13:
  print("AMBIGUOUS")
elif 0 < int(s[2:]) < 13:
  print("YYMM")
elif 0 < int(s[0:2]) < 13:
  print("MMYY")
else:
  print("NA")

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

int main(){
  ll n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int cnt=0;
  int b = a[0];
  while(1){
    cnt++;
    if(b==2) break;
    if(cnt==n+1) break;
    b = a[b-1];
  }
  if(cnt==n+1) cout << -1 << endl;
  else cout << cnt << endl;
}

Measured memory_bytes: 3748
n,k = map(int,input().split())
height = list(map(int,input().split()))
cost_list = []
for m in range(1,n+1):
  if m <= k:
    cost_list.append(abs(height[m-1]-height[0]))
  else:
    Min = cost_list[-1] + abs(height[m-2]-height[m-1])
    if k > 1:
      for x in range(2,k+1):
        money2 = cost_list[-x] + abs(height[m-x-1]-height[m-1])
        if money2 < Min:
          Min = money2 
    cost_list.append(Min)
print(cost_list[-1])

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

int main() {
    int N, K;
    cin >> N >> K;
    
    int Counter[N];
    for (int i = 0; i < N; i++) {
        Counter[i] = 0;
    }

    for (int i = 0; i < K; i++) {
        int d_i;
        cin >> d_i;
        for (int j = 0; j < d_i; j++) {
            int A;
            cin >> A;
            for (int k = 0; k < N; k++) {
                if (A-1 == k) {
                    Counter[k] += 1;
                }
            }
        }
    }

    int total = 0;
    for (int i = 0; i < N; i++) {
        if (Counter[i] == 0) {
            total += 1;
        }
    }
    cout << total << endl;
}

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

typedef long long int ll;
typedef long double ld;

//****************************************************                
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll> 
#define vpll vector<pll>
#define all(X) X.begin(),X.end()
#define endl "\n" //comment it for interactive questions
#define trace1(a) cerr << #a << ": " << a << endl;
#define trace2(a,b) cerr << #a << ": " << a << " " << #b << ": " << b << endl;
#define trace3(a,b,c) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << endl;
#define trace4(a,b,c,d) cerr << #a << ": " << a << " " << #b << ": " << b << " " << #c << ": " << c << #d << ": " << d << endl;
#define OC freopen("input.txt" , "r", stdin); freopen("output.txt" , "w", stdout) 
#define MOD (ll)1e9+7; //change it for other mods
#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
        //*******************************************************
//Some Functions

ll powmod(ll a,ll b)
{
   ll res = 1;
   while(b > 0) {
      if(b & 1) res = (res * a) % MOD;
      a = (a*a)%MOD;
      b = b >> 1; 
  }
  return res % MOD;
}

void solve()
{
    string s, t;
    cin >> s >> t;
    ll dp[s.size()+1][t.size()+1];
    pll dps[s.size()+1][t.size()+1];
    for(ll i=0;i<=s.size();i++) {
    	for(ll j=0;j<=t.size();j++) {
    		if(i == 0 || j == 0) {
    			dp[i][j] = 0;
    		} else {
    			ll tmp = (s[i-1] == t[j-1]) ? 1 : 0;
    			dp[i][j] = max(dp[i-1][j-1] + tmp, dp[i-1][j]);
    			dp[i][j] = max(dp[i][j], dp[i][j-1]);
    			if(dp[i][j] == dp[i-1][j-1] + tmp && tmp == 1) {
    				dps[i][j] = mp(i-1, j-1);
    			} else if(dp[i][j] == dp[i][j-1]) {
    				dps[i][j] = mp(i, j-1);
    			} else {
    				dps[i][j] = mp(i-1, j);
    			}
    		}
    	}
    }
    string ans = "";
    ll ind1 = s.size();
    ll ind2 = t.size();
    while(1) {
        pll temp = dps[ind1][ind2];
        if(temp.ff == ind1-1 && temp.ss == ind2-1) {
            ans += s[ind1-1];
        }
        ind1 = temp.ff;
        ind2 = temp.ss;
        if(ind1 == 0 || ind2 == 0) {
            break;
        }
    }
    reverse(all(ans));
    cout << ans << "\n";
}

int main()
{
    FAST_IO;
    #ifndef ONLINE_JUDGE 
     // OC;
    #endif
    ll t = 1;
    // cin >> t;
    while(t--){
        solve();
    }
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

ll n, ans = 0;
void dfs(string s, char mx) {
  if (s.size() == n) {
    cout << s << endl;
    return;
  }
  for (char i = 'a'; i <= mx + 1; ++i) {
    string t = s;
    t += i;
    dfs(t, max(mx, i));
  }
}

int main() {
  cin >> n;
  dfs("", 'a' - 1);
  return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;


int main(){
    string s;
    cin >> s;
    if(s[0]==s[1]&&s[2]==s[3]&&s[0]!=s[2]){cout<<"Yes"<<endl; return 0;}
    if(s[0]==s[2]&&s[1]==s[3]&&s[0]!=s[1]){cout<<"Yes"<<endl; return 0;}
    if(s[0]==s[3]&&s[2]==s[1]&&s[0]!=s[2]){cout<<"Yes"<<endl; return 0;}
    cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import Control.Monad
import Control.Monad.ST
import Data.List
import Data.Array.ST
import Data.Array
import Data.Maybe (fromJust)
import Debug.Trace


increment :: (STArray s Char Int) -> Char -> ST s (STArray s Char Int)
increment arr c = do
    v <- readArray arr c
    writeArray arr c (v + 1)
    return arr

countAlphabets :: String -> [Int]
countAlphabets str = elems (runSTArray $ do
    arr <- newArray ('a', 'z') 0
    forM_ str (increment arr)
    return arr)

createMinList :: [Int] -> [Int] -> [Int]
createMinList [] [] = []
createMinList (a:ax) (b:bx) = m:(createMinList ax bx)
    where
        m = min a b

createMinCounts :: [[Int]] -> [Int]
createMinCounts arr =
    foldl createMinList (replicate 26 10000) arr

createStringFromCount :: Char -> [Int] -> String
createStringFromCount _ [] = ""
createStringFromCount c (x:xs) = (replicate x c) ++ (createStringFromCount next xs)
    where
        next = toEnum ((fromEnum c) + 1) :: Char

solve :: [String] -> String
solve arr =
    createStringFromCount 'a' $ createMinCounts $ map countAlphabets arr

main :: IO ()
main = do
    n <- fst . fromJust . BS.readInt <$> BS.getLine
    arr <- replicateM n (BS.unpack <$> BS.getLine)
    putStrLn $ solve arr


Measured memory_bytes: 892
#include <stdio.h>
#define NUM 4

int main(void)
{
  int n[NUM];
  int a = 0;
  int i;

  for(i=0;i<NUM;i++)
    {
      scanf("%d",&n[i]);
      a += n[i];
    }
  printf("%d\n%d\n",a/60,a%60);
  return 0;
}

Measured memory_bytes: 592
/*
 It's better to sleep happy and tired rather than disappointed and frustrated
 There's only 1 thing that's impossible and that is defeating a man who doesn't give up
*/
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mx2 102
#define mx3 1003
#define mx4 10004
#define mx5 100005
#define mx6 1000006
#define mod 1000000007
#define PI 3.14159265
#define deb(x) cout << #x << " " << x << endl;
#define fo(i,n) for(int i=0 ; i<n ; i++)
#define Fo(i,k,n) for(int i=k ; i<n ; i++)
 
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pair<int,int>,int> piii;

const int inf=0x3f3f3f3f;
int n,m , ans , sum , a , b ,dp[mx5],vis[mx5];
vector<int> adj[mx5];
string str;

int dfs(int u )
{
	vis[u]=1;
	dp[u]=1;
	int t=0;
	for(auto v : adj[u])
	{
		if(!vis[v])
		{
			t=max(t,dfs(v));
		}
		else
		{
			t=max(t,dp[v]);
		}
	}
	dp[u]=t+1;
	ans=max(ans,dp[u]);
	// deb(u);deb(dp[u]);
	return dp[u];
}
 
int main() {
	ios::sync_with_stdio(false);
	//int t;cin>>t;while(t--)
	{
		cin>>n>>m;
		fo(i,m)
		{
			cin>>a>>b;
			adj[a].pb(b);
		}
		Fo(i,1,n+1)
		{
			if(!vis[i])
			{
				dfs(i);
			}
		}
		cout<<ans-1;
	}
	return 0;
}


Measured memory_bytes: 8576
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
 
int32_t main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k;
    cin>>n>>k;
    int w[n],v[n];
    for(int i=0;i<n;i++){
    	cin>>w[i]>>v[i];
    }
    int dp[n+1][k+1];
    for(int i=0;i<=k;i++){
    	dp[0][i]=0;
    }
    for(int i=0;i<=n;i++){
    	dp[i][0]=0;
    }
    for(int i=1;i<=n;i++){
    	for(int j=1;j<=k;j++){
    		if(j>=w[i-1]){
    			dp[i][j] = max(dp[i-1][j],v[i-1]+dp[i-1][j-w[i-1]]);
    		}
    		else{
    			dp[i][j] = dp[i-1][j];
    		}
    	}
    }
    cout<<dp[n][k];
    return 0;
}

Measured memory_bytes: 82516
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct Node{
  int key;
struct  Node *right, *left, *parent;
};

struct Node *root, *NIL;

struct Node * find(struct Node *u, int k){
  while(u!=NIL && k!=u->key){
    if(k < u->key) u=u->left;
    else u=u->right;
  }
  return u;
  }



void insert(int k){
struct  Node *y=NIL;
struct  Node *x=root;
struct  Node *z;

  z = (struct Node *)malloc(sizeof(struct Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!= NIL){
    y = x;
    if(z->key < x->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }


  z->parent = y;
  if(y == NIL){
    root = z;
  }
  else{
    if(z->key < y->key){
      y->left = z;
    }
    else{
      y->right = z;
    }
  }
}


void inorder(struct Node *u){
  if (u == NIL) return;
  inorder(u->left);
  printf(" %d", u->key);
  inorder(u->right);
}


void preorder(struct Node *u){
  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n,i,x;
  char *com;
  char *pri="print";
  char *ins="insert";


 com = (char *)malloc(7*sizeof(char));

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",com);
    if(com[0]=='f'){
      scanf("%d",&x);
     struct  Node *t = find(root,x);
      if(t!=NIL) printf("yes\n");
      else printf("no\n");
      }
    
    else if(strncmp(com,ins,6)==0){

      scanf("%d",&x);
      insert(x);
    }

     else if(strncmp(com,pri,5)==0){

      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}



Measured memory_bytes: 20432
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
bool vis[1000][1000];
int main() {
	double a,b,temp1,temp;
	cin>>a>>b;
	for(int i=1;i<=10000;i++)
	{
		temp1=(double)(i)*0.08;
		temp=(double)(i)*0.1;
		temp1=floor(temp1);temp=floor(temp);
		if(temp1==a&&temp==b)
		{
			cout<<i<<endl;return 0;
		}
	}
cout<<-1;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>

using namespace std;

int main(int argc, char **argv) {
    int n;
    cin >> n;
    std::vector<int> vec(n, 0);
    for (int i = 0; i < n; ++i) {
        cin >> vec[i];
    }

    std::vector<int> f(n, 0), b(n , 0);
    f[0] = vec[0];
    b[n-1] = vec[n-1];
    for (int i=1; i<n; ++i) {
        f[i] = f[i-1] + vec[i];
    }
    for (int i=n-2; i>=0; --i) {
        b[i] = b[i+1] + vec[i];
    }
    int ans{1000000};
    for (int i=0; i<n-1; ++i) {
        ans = min(ans, abs(f[i]-b[i+1]));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
N = gets.to_i

v_table = {}
(N - 1).times{
	u, v, w = gets.strip.split(/ /).collect(&:to_i)
	if table = v_table[u]
		table[v] = w
	else
		v_table[u] = { v => w }
	end
	if table = v_table[v]
		table[u] = w
	else
		v_table[v] = { u => w }
	end
}

def color(v_table)
	queue = [1]
	col_table = { 1 => 0 }
	while cur = queue.pop
		col = col_table[cur]
		v_table[cur].each{|v, w|
			if col_table[v] == nil
				if w % 2 == 0
					col_table[v] = col
				else
					col_table[v] = 1 - col
				end
				queue << v
			end
		}
	end
	col_table
end

col_table = color(v_table)

(1..N).each{|n|
	puts col_table[n]
}




Measured memory_bytes: 46460
#include<bits/stdc++.h>
#define ll long long
#define inf 9999999999999999
#define F first
#define S second
#define eb emplace_back
#define mpp make_pair
#define P(x) cout<<__LINE__ <<": "<<#x<<' '<<(x)<<'\n'
#define dbg cout<<__LINE__ <<": 0manush\n"
#define read(x) freopen("input.txt","r",stdin)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pi 2*acos(0.0)
#define ee exp(1)
#define mx 100009
#define mod 10000007
using namespace std;
ll dp[109][mx];

int main(){//read(x);
//fast;
ll r,g,h,i,j,t,e,a,b,c,d,n,l,k,z=0;
cin>>n>>k;
ll w[n],p[n];l=0;
for(i=0;i<n;i++){cin>>w[i]>>p[i];l+=p[i];}
dp[n][0]=0;
for(i=1;i<=l;i++)dp[n][i]=inf;
for(i=n-1;i>=0;i--){
    for(j=0;j<=l;j++){
        dp[i][j]=min(dp[i+1][j],(j-p[i]>=0)?w[i]+dp[i+1][j-p[i]]:inf);
        //printf("%2lld ",dp[i][j]);
    }//cout<<endl;
}
a=0;
    for(j=0;j<=l;j++){
        if(dp[0][j]<=k){
            a=max(a,j);
//          cout<<j<<' '<<dp[0][j]<<endl;
        }
    }//cout<<endl;
    cout<<a<<endl;
}





















Measured memory_bytes: 82348
#include<bits/stdc++.h>
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x)  (long long)(x).size()
#define sqr(x) (x)*(x)
#define sof sizeof
#define resz resize
#define ins insert
#define lowerB lower_bound
#define upperB upper_bound
#define mkp make_pair
#define mkt make_tuple
#define act(a,v) (get<(long long)a>(v))
#define mod 1000000007
#define mod1 998244353
#define N 200003
#define inf 1e18
#define minf -1e18
#define min3(a,b,c) min(a,min(b,c));
#define max3(a,b,c) max(a,max(b,c));
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define sumall(v) accumulate(all(v),(ll)0)
#define suma accumulate
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION(n) std::cout.unsetf ( std::ios::floatfield );std::cout.precision((ll)n)
#define PI M_PI
#define fi first
#define se second
#define here cout<<"RSSB"<<endl
#define showzero cout<<std::showpoint
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define br "\n"
#define spac " "
#define zero (ll)0
using namespace  std ;
typedef double db;
typedef long long ll ;
typedef vector<int>vi ;
//typedef vector<l>vl ;
typedef vector<ll>vll ;
typedef vector<vector<ll> >vvl ;
typedef pair<int,int> pii ;
typedef pair<ll,ll> pll ;
typedef vector<pll>vpll;
typedef vector<string>vstr;
typedef vector<tuple<ll,ll,ll> >vtll;
typedef vector<bool>vbool ;
void READ(vll &v, ll n){ll a ;for(ll i=0 ; i<n ; i=i+1){cin>>a ;v.pb(a);}}
void PRINT(vll &v , ll a = 0){for(ll i=a ; i<v.size() ; i=i+1){/*v[i] = max((ll)0,v[i]);*/cout<<v[i]<<"\n" ;}cout<<"\n" ;}
double logy(ll n , ll b){if(b==0){return(-1);}if(n==1){return(0);}return((db)log10(n)/log10(b));}
long long power(long long k , long long n , long long m=mod){long long res = 1;while(n){if(n%2!=0){res = (res*k)%m ;}k = (k*k)%m ;n = n/2 ;}return(res) ;}
double power(double p , ll t){db q = 1;while(t){if(t%2){q*=p;}p*=p;t/=2;}return(q);}
ll dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
ll dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
vpll dr;
void call(){dr.pb(mkp(1,0));dr.pb(mkp(-1,0));dr.pb(mkp(0,1));dr.pb(mkp(0,-1));}
ll n,m,k;
bool ok = false;
bool check(string str)
{
    m = sz(str);
    for(ll i =0 ; i<m ; i++)
    {
        if(str[i]==str[m-1-i])
        {
            continue;
        }
        return(false);
    }
    return(true);
}
int main()
{
    FastIO ;
    PRECISION(20) ;
    ll a,b,c,d,i,j,t,x,y,z,x1,y1,z1,e,f;
    db p,q,r,u,w ;
    char ch,chr ;
    string str,st,str1,str2,str3,str4;
    //ll a1=0,a2=0,b1=0,b2=0,c1=0 ;
    //cin>>str>>str1;
    //call();
    //Constructive is Weak!!
    cin>>n;
    p = n/3.00;
    showzero;
    cout<<p*sqr(p);
}

Measured memory_bytes: 256