akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    
   // output
   int cnt = 1;
   int i;
   cin >> i;
   while (i != 0) {
     cout << "Case "<< cnt << ": " << i << endl;
     cnt = cnt + 1;
     cin >> i;
   }    
}


Measured memory_bytes: 3064
#include <iostream>
 int main() {
 	std::string S;
 	std::cin >> S;
 	if (S == "ooo") {
 		std::cout << "1000" <<std::endl;
 	} else if (S == "xoo" || S == "oxo" || S == "oox") {
 		std::cout << "900" <<std::endl;
 	} else if (S == "oxx" || S == "xox" || S == "xxo") {
 		std::cout << "800" <<std::endl;
 	} else if (S == "xxx") {
 		std::cout << "700" <<std::endl;
 	}



















 	return 0;
 }

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

int main() {
	int a,b,d,n,T,cas=0;
	cin>>d>>n;
	if(n==100) n++;
	if(d==0) cout<<n<<endl;
	else if(d==1) cout<<n*100<<endl;
	else cout<<n*100*100<<endl;
	return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
  int now[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K; cin >> K;
  cout << now[K - 1] << endl;

  return 0;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

int main()
{
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int n;cin>>n;
  int ans=0;
  rep(i,n){
    int l,r;cin>>l>>r;
    ans+=r-l+1;
  }
  cout(ans);
  return 0;
}

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


namespace Test1 {

    


    class ClassMain {
        
        
        //   0
        // 1[2]3 4 
        //   5
        public static int[] dice = new int[6];

        public static void left() {
            int[] dice2 = new int[6];
            dice2[0] = dice[3];
            dice2[1] = dice[0];
            dice2[2] = dice[2];
            dice2[3] = dice[5];
            dice2[4] = dice[4];
            dice2[5] = dice[1];
            dice = dice2;
        }
        public static void right() {
            int[] dice2 = new int[6];
            dice2[0] = dice[1];
            dice2[1] = dice[5];
            dice2[2] = dice[2];
            dice2[3] = dice[0];
            dice2[4] = dice[4];
            dice2[5] = dice[3];
            dice = dice2;
        }

        public static void south() {
            int[] dice2 = new int[6];
            dice2[0] = dice[4];
            dice2[1] = dice[1];
            dice2[2] = dice[0];
            dice2[3] = dice[3];
            dice2[4] = dice[5];
            dice2[5] = dice[2];
            dice = dice2;
        }

        public static void north() {
            int[] dice2 = new int[6];
            dice2[0] = dice[2];
            dice2[1] = dice[1];
            dice2[2] = dice[5];
            dice2[3] = dice[3];
            dice2[4] = dice[0];
            dice2[5] = dice[4];
            dice = dice2;
        }
        public static void east() {
            int[] dice2 = new int[6];
            dice2[0] = dice[0];
            dice2[1] = dice[4];
            dice2[2] = dice[1];
            dice2[3] = dice[2];
            dice2[4] = dice[3];
            dice2[5] = dice[5];
            dice = dice2;
        }
        public static void west() {
            int[] dice2 = new int[6];
            dice2[0] = dice[0];
            dice2[1] = dice[2];
            dice2[2] = dice[3];
            dice2[3] = dice[4];
            dice2[4] = dice[1];
            dice2[5] = dice[5];
            dice = dice2;
        }


        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                int n = int.Parse(line);
                if (n == 0) { break; }
                List<int> intlis = Enumerable.Range(1, 30).ToList() ;
                intlis.Remove(n);
                for (int i = 0; i < 27; i++) {
                    intlis.Remove(int.Parse(Console.ReadLine()));
                }

                
               
                Console.WriteLine(intlis.ElementAt(0));
                Console.WriteLine(intlis.ElementAt(1));


            }
        }

        
    }



    
}

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

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

    vector<pair<ll, ll>> A(N);

    rep(i, N) cin >> A.at(i).first >> A.at(i).second;

    sort(A.begin(), A.end());

    ll ans = 0;
    ll m = 0;

    rep(i, N)
    {
        if (m + A.at(i).second < M)
        {
            m += A.at(i).second;
            ans += A.at(i).first * A.at(i).second;
        }
        else
        {
            ans += A.at(i).first * (M - m);
            break;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4776
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
  int a,b;
  cin >> a >> b;
  if (a <= 0 && b >= 0) cout << "Zero" << endl;
  else if (a > 0 && b > 0) cout << "Positive" << endl;
  else if (a < 0 && b < 0){
    if ((abs(a)-abs(b)+1)%2 == 1) cout << "Negative" << endl;
    else cout << "Positive" << endl;
    //cout << (abs(a)-abs(b)+1) << endl;
  }
  return 0;
  
}


Measured memory_bytes: 3648
#include<cstdio>
using namespace std;

int main(){
  int no;
  double w, h, bmi;
  while(~scanf("%d,%lf,%lf", &no, &w, &h)) {
    if(w / h / h >= 25)
      printf("%d\n", no);
  }
  return 0;
}

Measured memory_bytes: 1056
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
typedef long long ll;

using ipair = pair<int, int>;

ll INF = 1e16+7;
ll mod = 1e9+7;

bool operator>(const ipair a,const ipair b){return a.first > b.first;}

int main(){
  ll N;
  cin >> N;
  vector<int> A(N), B(N), C(N);
  rep(i, N) cin >> A[i];
  rep(i, N) cin >> B[i];
  rep(i, N) cin >> C[i];
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  sort(C.begin(), C.end());

  ll ans = 0LL;

  rep(i, N){
    // B[i]未満の個数
    ll a_b = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
    // B[i]より大きい個数
    ll b_c = C.end() - upper_bound(C.begin(), C.end(), B[i]);
    ans += a_b * b_c;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
int n,m,i,j,t,k,s,len,sump,p[20];
inline int Pow(int x,int y)
{
	int ret=1;
	while (y)
	{
		if (y&1) ret=1ll*ret*x%mod;
		x=1ll*x*x%mod;y>>=1;
	}
	return ret;
}
inline int Mod(int x)
{
	return x>=mod ? x-mod : x;
}
struct Poly
{
	int e[300005];
	int& operator[](int x)
	{
		return e[x];
	}
	void FWT(int len)
	{
		for (int le=2;le<=len;le<<=1)
		 for (int i=0,m=le>>1;i<len;i+=le)
		  for (int j=i,tmp;j<i+m;++j)
		   tmp=e[j+m],e[j+m]=Mod(e[j]-tmp+mod),e[j]=Mod(e[j]+tmp);
	}
	void IFWT(int len)
	{
		FWT(len);
		int tmp=Pow(len,mod-2);
		for (int i=0;i<len;++i)
		 e[i]=1ll*e[i]*tmp%mod;
	}
}E,P,S;

int main()
{
	scanf("%d",&n);len=(1<<n);
	for (i=0;i<len;++i) scanf("%d",&P[i]),sump+=P[i];
	sump=Pow(sump,mod-2);
	for (i=0;i<len;++i) P[i]=1ll*P[i]*sump%mod;
	//--P[0];if (P[0]<0) P[0]+=mod;else P[0]=0;
	(--P[0])<0 ? P[0]+=mod : 0,S[0]=len-1;
	//S[0]=len-1;
	for (i=1;i<len;++i) S[i]=mod-1;
	P.FWT(len);S.FWT(len);
	for (i=1;i<len;++i) E[i]=1ll*S[i]*Pow(P[i],mod-2)%mod;
	E.IFWT(len);
	int tmp=mod-E[0];
	for (i=0;i<len;++i) printf("%d\n",Mod(tmp+E[i]));
	return 0;
}

Measured memory_bytes: 5888
object Main extends App {

  def solve(arr: Array[Int]): Boolean = {
    val go = if (arr.count(_ == 5) == 2) true else false
    val nana = if (arr.count(_ == 7) == 1) true else false
    go & nana
  }

  val sc = new java.util.Scanner(Console.in)
  val a, b, c = sc.nextInt()

  val result = solve(Array(a, b, c))
  if (result) println("YES") else println("NO")
}

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

using namespace std;
using ll =long long;

#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
void coY() {cout <<"Yes"<<endl;}
void coN(){cout <<"No"<<endl;}

const ll INF = 1LL << 60;

//Write From this Line

const int mod = 1e9+7;
int main()
{
	//基本的にはBCより前に何個連続シテAがあるかを見るのだが、
	//BC.BC間にAしかなければ流用出来る。
	string s ;
	cin>> s ;
	ll a_count = 0 ;
	ll ans = 0 ; 
	rep(i,s.size()){
		if(s[i] == 'A'){
			a_count ++ ;
		}else if(s[i] == 'B'){
			i ++ ;
			if(i < s.size() && s[i] == 'C'){
				ans += a_count ; 
			}else if(i < s.size()){
				//つまり、A -> B -> B やら A -> B -> A のとき
				if(s[i] == 'B') a_count = 0 ;
				else if(s[i] == 'A') a_count = 1 ;
			}
		}else a_count = 0 ;
	}
	cout << ans << endl;
}
//70000*65000


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int score1 = 0, score2 = 0;
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		for(int i = 0; i < n; i++){
			String card1 = scan.next();
			String card2 = scan.next();
			if(card1.compareTo(card2) > 0){
				score1 += 3;
			}else if(card1.compareTo(card2) == 0){
				score1 += 1;
				score2 += 1;
			}else{
				score2 += 3;
			}
		}
		scan.close();
		System.out.println(score1 + " " + score2);
	}
}

Measured memory_bytes: 29420
import java.io.File;
import java.io.FileNotFoundException;
import java.lang.management.ManagementFactory;
import java.lang.management.ThreadMXBean;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws FileNotFoundException {

		ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
		long startCpuTime = threadMXBean.getCurrentThreadCpuTime(), stopCpuTime = 0;

		 Scanner scan = new Scanner(System.in);
		//Scanner scan = new Scanner(new File("D:\\UserArea\\J0124567\\Downloads\\0545-input.txt"));

		while (scan.hasNext()) {

			int n = scan.nextInt();
			int m = scan.nextInt();
			if (n == 0 && m == 0)
				break;
			Fr fr = new Fr(n, m);
			for (int i = 0; i < m; i++)
				fr.rel(scan.nextInt(), scan.nextInt());

			System.out.println(fr.count(2));
			// stopCpuTime = threadMXBean.getCurrentThreadCpuTime();

		}

		scan.close();
		// stopCpuTime = threadMXBean.getCurrentThreadCpuTime();
		// System.out.println("CPU=" + (stopCpuTime - startCpuTime) / 1000000);

		System.exit(0);
	}
}

class Fr {
	boolean[] stu;

	public Fr(int n, int m) {
		stu = new boolean[n + 1];
	}

	class linkComp implements Comparator<Link> {

		@Override
		public int compare(Link o1, Link o2) {
			if (o1.a > o2.a)
				return 1;
			else if (o1.a == o2.a)
				return 0;
			else
				return -1;
		}

	}

	public int count(int tm) {
		Collections.sort(link, new linkComp());
		stu[1] = true;
		int sum = 0;
		for (int i = 0; i < link.size(); i++)
			if (link.get(i).a == 1) {
				if (!stu[link.get(i).b]) {
					sum++;
					// System.out.println("- " + link.get(i).b);
				}
				stu[link.get(i).b] = true;
				sum += this.check(link.get(i).b, tm - 1);
			} else
				break;
		return sum;
	}

	private int check(int a, int t) {
		if (t == 0)
			return (0);
		int j = link.size() / 2;
		int k = j / 2;
		while (true) {
			if (link.get(j).a < a)
				j += k;
			else
				j -= k;
			if (k > 1)
				k /= 2;
			else
				break;
		}
		for (; link.get(j).a >= a; j--)
			;
		int sum = 0;
		for (j++; j < link.size() && link.get(j).a <= a; j++)
			if (link.get(j).a == a) {
				if (!stu[link.get(j).b]) {
					sum++;
					// System.out.println("- " + link.get(j).b);
				}
				stu[link.get(j).b] = true;
				if (t > 0)
					sum += this.check(link.get(j).b, t - 1);
			}

		return sum;
	}

	class Link {
		public Link(int i, int j) {
			a = i;
			b = j;
		}

		int a, b;
	}

	List<Link> link = new ArrayList<Link>();

	public void rel(int i, int j) {
		link.add(new Link(i, j));
		link.add(new Link(j, i));
	}

}

Measured memory_bytes: 55560
import numpy as np

N = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)
A.append(0)

# diminish in travel distance if we cancel travelling to ai.
# |a_{i+1} - a_{i}| + |a_{i} - a_{i-1}| - ||a_{i+1} - a_{i-1}|

orig_dist = 0
for i in range(1, len(A)):
    orig_dist += abs(A[i] - A[i - 1])

# print(orig_dist)


for i in range(1, len(A) - 1):
    d = orig_dist - \
        abs(A[i+1] - A[i]) - \
        abs(A[i] - A[i-1]) + \
        abs(A[i+1] - A[i-1])
    print(d)


Measured memory_bytes: 22840
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

const lint mod = 998244353;
inline lint emod(lint a, lint p = mod) { return (a % p + p) % p; }

inline lint invm(lint a, lint p = mod) { a %= p; return a == 1 ? 1 : -p / a * invm(p % a) % p; }

inline lint powm(lint a, lint n, lint p = mod) { return !n ? 1 : powm(a * a % p, n >> 1, p) * (n & 1 ? a : 1) % p; }

V<lint> fact, ifact;
void init_fact(int n) {
  fact.assign(n + 1, 1), ifact.assign(n + 1, 1);
  for (int i = 2; i < n + 1; i++) fact[i] = i * fact[i - 1] % mod;
  ifact[n] = invm(fact[n]);
  for (int i = n; i > 2; i--) ifact[i - 1] = i * ifact[i] % mod;
}

inline lint comb(lint n, lint r) {
  if (n < 0 or r < 0 or r > n) return 0;
  return fact[n] * ifact[r] % mod * ifact[n - r] % mod;
}

inline lint mulcomb(lint n, lint r) {
  if (n < 1 or r < 0) return 0;
  return fact[r + n - 1] * ifact[r] % mod * ifact[n - 1] % mod;
}

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  lint k, n; cin >> k >> n;
  init_fact(k + n);
  auto calc = [&](lint m, lint k, lint n) {
    lint res = 0;
    for (lint j = 0; j < m + 1; j++) {
      res = (res + comb(m, j) * powm(2, j) % mod * mulcomb(k - 2 * m + j, n - j)) % mod;
    }
    return res;
  };
  V<> res(k);
  for (int i = 2; i < k + 2; i++) {
    if (i & 1) res[i - 2] = emod(calc(i / 2, k, n));
    else res[i - 2] = emod(calc(i / 2 - 1, k - 1, n) + calc(i / 2 - 1, k - 1, n - 1));
  }
  for (auto&& i : res) cout << i << '\n';
  for (int i = k - 2; i >= 0; i--) cout << res[i] << '\n';
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;

long long cnt;
int l;
int A[1000000];
int n;
vector<int> G;

//間隔gを指定した挿入ソート
void insertionSort(int A[], int n, int g)
{
    for( int i = g; i < n; i++ ){
        int v = A[i];
        int j = i - g;
        while( j >= 0 && A[j] > v ){
            A[j + g] = A[j];
            j -= g;
            cnt++;
        }
        A[j + g] = v;
    }
}

void shellSort(int A[], int n)
{
    //数列 G = { 1, 4, 13, 40, 121, 364, 1093, ... } を生成
    for( int h = 1; ; ){
        if( h > n ) break;
        G.push_back(h);
        h = 3*h + 1;
    }

    for( int i = G.size()-1; i >= 0; i-- ){ //逆順に G[i] = g を指定
        insertionSort(A, n, G[i]);
    }
}

int main()
{
    cin >> n;
    //より速い入力scanf関数を使用
    //for( int i = 0; i < n; i++ ) scanf("%d", &A[i]);
    for( int i = 0; i < n; i++ ) cin >> A[i];
    cnt = 0;

    shellSort(A, n);

    cout << G.size() << endl;
    for( int i = G.size() - 1; i >= 0; i-- ){
        //printf("%d", G[i]);
        //if( i ) printf(" ");
        cout << G[i];
        if( i ) cout << " ";
    }
    //printf("\n");
    //printf("%d\n", cnt);
    cout << endl << cnt << endl;
    for( int i = 0; i < n; i++ ) //printf("%d\n", A[i]);
        cout << A[i] << endl;
    return 0;
}

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

int main(){
  long r,d,x;
  std::cin >> r>>d>>x;
  
  for (int i = 0; i < 10; i++) {
    /* code */
    x=r*x-d;
    std::cout << x << std::endl;
  }
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll A[101010],S;
ll D[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>A[i];
		S+=A[i];
	}
	ll B=1LL*N*(N+1)/2;
	if(S%B) return _P("NO\n");
	ll num=S/B;
	
	A[N]=A[0];
	
	ll tot=0;
	FOR(i,N) {
		ll D=A[i+1]-A[i]+num*(N-1);
		if(D%N) return _P("NO\n");
		ll E=num-D/N;
		if(E<0) return _P("NO\n");
		tot += E;
	}
	if(tot==num) _P("YES\n");
	else  _P("NO\n");
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


Measured memory_bytes: 1024
#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define all(x) begin(x),end(x)
using namespace std;
const int INF = 1e9;
template<class T=int> using V = vector<T>;
template<class T=int> using PQ = priority_queue<T>;
template<class T=int> using PQG = priority_queue<T, V<T>, greater<T>>;
typedef long long ll;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
template<class T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#define YN(e) cout << ((e) ? "YES" : "NO") << endl
#define yn(e) cout << ((e) ? "Yes" : "No") << endl
#pragma endregion RegionDefs

void solve()
{
    IN(n, k);
    vector<bool> v(n);
    rep(i, k)
    {
        IN(d);
        rep(j, d)
        {
            IN(a);
            v[a-1] = true;
        }
    }
    ll s = 0;
    rep(i, n)
        if (!v[i]) s++;
    cout << s << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 3656
import string

alphabets = string.ascii_lowercase

S = input()

res = float("inf")

for i, a in enumerate(alphabets):
    cnt = 0
    T = list(S)
    flag = True
    while len(set(T)) != 1 and flag:
        cnt += 1
        flag = False
        for j in range(len(T) - 1):
            if T[j] == a or T[j + 1] == a:
                T[j] = a
                flag = True
        T = T[:-1]
    if flag:
        res = min(res, cnt)

print(res)


Measured memory_bytes: 3772
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
N = int(input())
ab = [list(map(int,input().split())) for _ in range(N-1)]
tree = [[] for _ in range(N)]
for i in range(N-1):
    a,b = ab[i]
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)
    index = -1
    MAX = 0
for i in range(N):
    li = tree[i]
    n = len(li)
    if n > MAX:
        MAX = n
        index = i
d = defaultdict(int)

def dfs(cur,parent,prevcolor):
    li = tree[cur]
    n = len(li)
    if n == 0:
        return
    flag = 0
    for i in range(n):
        chi = li[i]
        if chi == parent:
            flag = 1
            continue
        a = (prevcolor+1+i)%MAX
        if flag == 1:
            a -= 1
        d[(cur,chi)] = a
        d[(chi,cur)] = a
        dfs(chi,cur,a)
dfs(index,-1,0)
print(MAX)
for i in range(N-1):
    a,b = ab[i]
    ans = d[(a-1,b-1)]
    if ans == 0:
        ans += MAX
    print(1+ans%MAX)

Measured memory_bytes: 100520
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n, m;
	vector<int> a[3], b[3];
	for(;;){
		for(int i = 0; i < 3; i++){
			a[i].clear();
			b[i].clear();
		}
		cin >> n >> m;
		if(n == 0 && m == 0) break;
		for(int i = 0; i < 3; i++){
			int num;
			cin >> num;
			for(int j = 0; j < num; j++){
				int in;
				cin >> in;
				a[i].push_back(in);
			}
		}
		if(a[2][0] == 1){
			for(int i = 0; i < 3; i++){
				for(int j = 0; j < a[i].size(); j++){
					b[2 - i].push_back(a[i][j]);
				}
			}
		}else{
			for(int i = 0; i < 3; i++){
				for(int j = 0; j < a[i].size(); j++){
					b[i].push_back(a[i][j]);
				}
			}
		}

		int ans = 0;
		bool flag = true;
		for(int i = 1; i <= n; i++){
			if(ans % 2 == 0){
				for(int j = 0; j < 3; j++){
					if(!b[j].empty() && b[j][0] == i){
						ans = (3 * ans) + j;
						b[j].erase(b[j].begin());
					}
				}
			}else{
				for(int j = 0; j < 3; j++){
					if(!b[j].empty() && b[j][0] == i){
						ans = (3 * ans) + (2 - j);
						b[j].erase(b[j].begin());
					}
				}
			}
			if(ans > m){
				flag = false;
				break;
			}
		}
		if(flag) cout << ans << endl;
		else cout << "-1" << endl;
	}
	return 0;
}

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

int main(){
    int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2,
     1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 
     15, 2, 2, 5, 4, 1, 4, 1, 51};

    int k;
    cin >> k;
    cout << a[k-1] << endl;
}


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

using vi = std::vector<int64_t>;

class BIT {
public:
    BIT(int n) : bit(n + 1) {}
    void inc(int64_t a, int c) {
        a++; // 1-based index
        while (a < bit.size()) {
            bit[a] += c;
            a += lsb(a);
        }
    }

    int64_t get(int64_t a) {
        a++; // 1-based index
        int64_t r = 0;
        while (a > 0) {
            r += bit[a];
            a -= lsb(a);
        }
        return r;
    }
private:
    int64_t lsb(int64_t a) {
        return a & -a;
    }

    vi bit;
};

int bin_search(const vi &v, int l, int r, int64_t x) {
    while (r - l > 1) {
        auto m = l + (r - l) / 2;
        (v[m] >= x ? l : r) = m;
    }
    return l;
}


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

    int n; int64_t k; std::cin >> n >> k;
    vi v(n);
    for (auto &a : v) std::cin >> a;
    for (auto &a : v) a -= k; // remove k, now positive sum denotes mean > k
    for (int i = 1; i < n; i++) v[i] += v[i-1]; // make cumulative
    // compress to range 0..n-1
    auto c = v;
    v.push_back(0); n++; // make it possible to lookup zero
    sort(v.begin(), v.end(), std::greater<int64_t>());
    for (auto &a : c) a = bin_search(v, 0, n, a);
    BIT bit(n);
    for (auto &a : c) bit.inc(a, 1);

    int64_t r = bit.get(bin_search(v, 0, n, 0));
    for (auto &a : c) {
        bit.inc(a, -1);
        r += bit.get(a);
    }

    std::cout << r << std::endl;
}



Measured memory_bytes: 6400
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define tp tuple<int,int,int>
#define mtp make_tuple
using namespace std;

const int N=1e5+5;

int calc(int x)
{
    return x*x*x*x*x;
}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int x;
    cin>>x;
    for(int i=-2000;i<=2000;i++)
    {
        for(int j=-2000;j<=2000;j++) if(calc(i)-calc(j)==x) return cout<<i<<' '<<j,0;
    }
}


Measured memory_bytes: 3640
N, M = list(map(int, input().split()))
St = [input().split() for _ in range(N)]
Ch = [input().split() for _ in range(M)]

for i in range(N):
    memo = []
    for j in range(M):
        diff = abs(int(St[i][0]) - int(Ch[j][0])) + abs(int(St[i][1]) - int(Ch[j][1]))
        memo.append(diff)
    print(memo.index(min(memo)) + 1)


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


#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (ll i=0; i<n; i++)
#define	Rep1(i, n)	for (ll i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	ll N;
	string S;
	cin >>N >>S;
	vector<ll> s(N, 0);
	Rep0(i, N)
		if ('G'==S.at(i))
			s.at(i)=1;
		else if ('B' ==S.at(i))
			s.at(i)=2;
	vector<ll> L0(N, 0);
	vector<ll> R0(N, 0);
	vector<ll> L1(N, 0);
	vector<ll> R1(N, 0);
	vector<ll> L2(N, 0);
	vector<ll> R2(N, 0);
	ll R=0, G=0, B=0;
	Rep0(i, N) {
		if (0==s.at(i))
			R++;
		else if (1==s.at(i))
			G++;
		else // 2
			B++;
		L0.at(i)=R;
		L1.at(i)=G;
		L2.at(i)=B;
	}
	R=G=B=0;
	for (ll i=N-1; i>=0; i--) {
		if (0==s.at(i))
			R++;
		else if (1==s.at(i))
			G++;
		else // 2
			B++;
		R0.at(i)=R;
		R1.at(i)=G;
		R2.at(i)=B;
	}
	ll SS=0;
	for (ll i=1; i<N-1; i++) {
		if (0==s.at(i))
			SS +=L1.at(i-1)*R2.at(i+1)+L2.at(i-1)*R1.at(i+1);
		else if (1==s.at(i))
			SS +=L0.at(i-1)*R2.at(i+1)+L2.at(i-1)*R0.at(i+1);
		else //2
			SS +=L0.at(i-1)*R1.at(i+1)+L1.at(i-1)*R0.at(i+1);
	}
	for (ll i=1; i<N-1; i++) {
		ll sss=s.at(i);
		for (ll j=1; j<N; j++) {
			if (i-j<0)
				break;
			if (i+j>=N)
				break;
			if (sss==s.at(i-j))
				continue;
			if (sss==s.at(i+j))
				continue;
			if (s.at(i-j)==s.at(i+j))
				continue;
			SS--;
		}
	}
	cout <<SS <<endl;
	return 0;
}



Measured memory_bytes: 3768
N = int(input())
s = [int(input()) for i in range(N)]

while True:
    if sum(s)%10 !=0:
        print(sum(s))
        exit()
    else:
        num = [n for n in s if n % 10 != 0]
        if len(num) == 0:
            print(0)
            exit()
        else:
            print(sum(s) - min(num))
            exit()

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

using namespace std ; 

const int N = 1e5 + 7 ; 

int n ; 
int deg[N] ; 
string s ; 

int main(){
    ios_base::sync_with_stdio(0) ; 
    cin.tie(0) ; 
    //freopen("in.in" , "r" , stdin) ;
    cin>>s ;
    n = s.size() ;  
    if(s[n-1] == '1' || s[0] =='0')return cout<< -1 , 0 ;

    for(int i = 0 ; i < n /2 -1; i++){
        if(s[i] !=s[n-2-i])return cout<< -1  , 0 ; 
    }
    int cur =1 ; 
    int t = 2 ; 
    for(int i = n- 2; i >=0 ;i --){
        if(s[i] =='0'){
            cout<< t++ <<" " << cur <<"\n" ; 
        }
        else{
            cout<< t++ <<" " << cur <<"\n" ; 
            cur = t -1; 
        }
    }

    return 0 ;
}


Measured memory_bytes: 1616
#include <iostream>

using namespace std;

int main()
{
  int s,k;
  int cnt = 0;

  cin >> k >> s;

  for ( int i = 0; i <= k; ++i ) {
    for( int j = 0; j <= k; ++j ) {
      int tmp = s-i-j;
      if ( tmp >= 0 && tmp <= k ) cnt++;
    }
  }

  cout << cnt << "\n";
}


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

const long long INF = 1LL << 60;
int MOD = 1000000007;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define vi vector<int>
#define vii vector< vector<int> >

int GetDigit(int num) { return log10(num) + 1; }
int gcd(int a, int b) {
	while (1) { if (a < b) swap(a, b); if (!b) break; a %= b; }
	return a;
}
int lcm(int a, int b) { return a * b / gcd(a, b); }

int N, M;
int S[5];
int C[5];

int main() {

	cin >> N >> M;
	rep(i, M) {
		cin >> S[i] >> C[i];
	}

	int ans = -1;
	rep(i, 1000) {
		int keta = GetDigit(i);
		if (i == 0) keta = 1;
		if (keta != N) continue;
		bool flag = true;
		rep(j, M) {
			if (to_string(i)[S[j] - 1] != to_string(C[j])[0]) {
				flag = false;
			}
		}
		if (flag) { ans = i; break; }
	}

	cout << ans << endl;

}


Measured memory_bytes: 640
S = list(str(input()))

ans = 0
num = 0
while num < len(S):
  num += 1
  s = S[:len(S)-num]
  if len(s) % 2 == 0:
    if s[:int(len(s)/2)] == s[int(len(s)/2):]:
      ans = len(s)
      break
print(ans)

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

int main(){
   int a, b;
   while(true){
      cin >> a >> b;
      if(a == 0 && b == 0){break;}
      if(a < b){
          cout << a << " " << b << endl;
      }else{
          cout << b << " " << a << endl;
      
      }
   }

}

Measured memory_bytes: 3004
N, M = list(map(int, input().split()))
H = list(map(int, input().split()))
good = [1 for i in range(N)]

for i in range(M):
    A, B = list(map(int, input().split()))
    A = A-1
    B = B-1
    if H[A] >= H[B]:
        good[B] = 0
    if H[A] <= H[B]:
        good[A] = 0
print(sum(good))

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

int main() {
    int N;
    cin >> N;
    int res = 0;
    int now = 0;
    for(int i=0; i<N; ++i) {
        char c; cin >> c;
        if(c == 'D') {
            now--;
        } else {
            now++;
        }
        res = max(res, now);
    }
    cout << res << endl;
}


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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

const pid_t pid = getpid();
// Problem Specific Parameter:

const int limit = 100010;
vector<int> graph[limit];


int opr(vector<int> val){
	int last = -1;

	rep(i, 30){
		if(val[i] >= 2){
			last = i;
		}
	}

	int start = 30;
	rep(i, last + 1, 30){
		if(val[i] == 0){
			start = i;
			break;
		}
	}

	val[start] = 1;
	rrep(i, start){
		val[i] = 0;
	}

	int ret = 0;
	rep(i, 30) if(val[i] > 0) ret |= (1 << i);
	return ret;
}

int dfs(int v, int p){
	vector<int> res(30, 0);

	for(auto &v2: graph[v]){
		if(v2 == p) continue;
		const int val = dfs(v2, v);
		rep(i, 30) if(val >> i & 1) res[i]++;
	}

	return opr(res);
}

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

	rep(i, n - 1){
		int a, b;
		cin >> a >> b;
		a--, b--;
		graph[a].push_back(b);
		graph[b].push_back(a);
	}

	const int val = dfs(0, -1);

	rrep(ans, 30){
		if(val >> ans & 1) {
			cout << ans << endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 20480
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define ms(i, j) memset(i, j, sizeof i)
#define LL long long
#define db double
using namespace std;
int h, w, n, mp[105][105], nowd = 0, nowi = 1, nowj = 0;
void clean() {
}
void solve() {
	clean();
	for (int i = 1; i <= n; i++) {
		int x;
		scanf("%d", &x);
		for (int j = 1; j <= x; j++) {
			if (!nowd) {
				nowj++; 
				if (nowj > w) nowj = w, nowi++, nowd = 1;
			} else {
				nowj--;
				if (nowj <= 0) nowj = 1, nowi++, nowd = 0;
			}
			mp[nowi][nowj] = i;
		}
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			printf("%d ", mp[i][j]);
		}
		printf("\n");
	}
}
int main() {
	scanf("%d%d%d", &h, &w, &n), solve();
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, ll> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int mod = 1e+9 + 7;
const int INF = 1e+9;

bool used[200005];

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

    int n;
    cin >> n;
    vector<vector<int>> pos(200005);
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        pos[a].push_back(i);
    }
    if(pos[1].size() == 0){
        cout << -1 << endl;
        return 0;
    }
    int now = pos[1][0];
    used[now] = true;
    for(int i = 2; i <= 200003; ++i){
        if(pos[i].size() == 0)  break;
        int tmp = upper_bound(pos[i].begin(), pos[i].end(), now) - pos[i].begin();
        if(tmp == pos[i].size())    break;
        now = pos[i][tmp];
        used[now] = true;
    }
    int res = 0;
    for(int i = 0; i < n; ++i){
        if(!used[i])    ++res;
    }
    cout << res << endl;
}

Measured memory_bytes: 11392
'use strict'

const main = (INPUT) => {
  const input = INPUT.split('\n')[0].split(' ').map(n => Number(n))

  if (input[1] < input[0]) {
    console.log(0)
  } else if (input[1] / input[0] <= input[2]) {
    console.log(Math.floor(input[1] / input[0]))
  } else {
    console.log(input[2])
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 21064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;

int main(){
    string s; cin >>s;
    int n = s.size();
    
    if(s[0]==s[1]){
        cout << "1 2" << endl;
        return 0;
    }
    for (int i = 2; i < n; ++i) {
        if(s[i]==s[i-1]){
            cout << i << " " << i+1 << endl;
            return 0;
        }
        if(s[i]==s[i-2]){
            cout << i-1 << " " << i+1 << endl;
            return 0;
        }
    }
    
    cout << "-1 -1" << endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
 
int main(void){
int N,i;
  long sum=0;
  scanf("%d",&N);
  for(i=1;i<N+1;i++){
     if (i % 3 != 0 && i % 5 != 0) {
    sum=sum+i;}}
  printf("%ld",sum);
  return 0;
}

Measured memory_bytes: 1728
#include<bits/stdc++.h>
using namespace std;
int a,b,c;
int main()
{
	cin>>a>>b>>c;if(a==1) {cout<<"YES\n";exit(0);}
	for(int i=1;i<=100;i++) if(a*i%b==c) {cout<<"YES\n";exit(0);}
	cout<<"NO\n";exit(0);
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
 
using namespace std;
typedef long long Int;
#define INF (1LL<<60)

Int dp[20][54000];
Int table[54000];
Int a,b;

int henkan(const string X){
if(X == "A") return 1;
if(X == "B") return 2;
if(X == "C") return 3;
if(X == "D") return 4;
if(X == "E") return 5;
if(X == "F") return 6;

}

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

	string X,Y;
	cin >> X>>Y;

	a=henkan(X);
	b=henkan(Y);

	if(a<b)	cout<<"<"<<endl;
	else if(a>b)	cout<<">"<<endl;
	else 	cout<<"="<<endl;

	return 0;
}

Measured memory_bytes: 256
A,B,C,X=readlines.map &:to_i
M = X + 10
a = [0] * M
(A+1).times {|i| a[500*i] = 1 if 500*i<M}
b = [0] * M
(B+1).times {|i| M.times {|j| b[j+i*100] += a[j] if j+i*100<M}}
c = [0] * M
(C+1).times {|i| M.times {|j| c[j+i*50] += b[j] if j+i*50<M}}
p c[X]


Measured memory_bytes: 2300
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;

int main(){
  while(true){
    int n;
    long long m;
    cin >> n >> m;
    if(n == 0 && m == 0) break;
    vector<pair<int,int>> x(n);
    long long ans = 0;
    for(auto &p: x){
      cin >> p.first >> p.second;
      ans += p.first * p.second;
    }

    sort(x.begin(), x.end(), [](const pair<int, int>& a, const pair<int, int>& b) { return a.second > b.second; });

    for(auto p: x){
      int d = min(m, (long long)p.first);
      ans -= d * p.second;
      m -= p.first;
      if(m <= 0) break;
    }
    // for(auto p: x)
      // cout << p.first << " " << p.second << endl;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3152
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<stack>
#include<cassert>
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define mem(x,y) memset(x,y,sizeof x)
#define sqr(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
const int INF=2e9;
const db eps=1e-12;
template<typename T>
inline void read(T &x) {
	x=0; int f=1; char ch=getchar();
	while( (ch<'0' || ch>'9') && ch!='-') ch=getchar(); if(ch=='-') {f=-1; ch=getchar();}
	while(ch>='0' && ch <='9') x=x*10+ch-'0',ch=getchar();
	x*=f;
}
//==========================head template==========================
const int N=100010;
ll d[N];
int n;
map<ll,int> key;
pli seq[N];
int fa[N],sz[N];
ll ret[N];
signed main() {
  read(n);
  for(int i=1;i<=n;i++) read(d[i]);
  for(int i=1;i<=n;i++) key[d[i]]=i;
  for(int i=1;i<=n;i++) seq[i]=mp(d[i],i);
  sort(seq+1,seq+n+1); reverse(seq+1,seq+n+1);
  for(int i=1;i<=n;i++) sz[i]=1;
  for(int i=1;i<n;i++) {
    int u=seq[i].S;
    ll delta=d[u]+sz[u]-(n-sz[u]);
    //printf("%lld %d\n",delta,u);
    if(!key.count(delta)) {puts("-1"); return 0;}
    fa[u]=key[delta];
    sz[fa[u]]+=sz[u];
    ret[fa[u]]+=ret[u]+sz[u];
  }
  if(seq[n].F!=ret[seq[n].S]) {
    puts("-1"); return 0;
  }
  for(int i=1;i<=n;i++)
    if(fa[i]) {printf("%d %d\n",i,fa[i]);}
  return 0;
}


Measured memory_bytes: 11520
#include <iostream>
#include <string>
using namespace std;
int main() {
  int i, m, h,sum;
  string str;
  while(cin >> str) {
	if(str == "-") {break;}
	cin >> m;
	for(i = 0; i < m; i++) {
	  cin >> h;
	  sum += h;
	}
	for(i = 0; i < sum; i++) {
	  str += str[0];
	  str.erase(str.begin());
	}
	cout << str << endl;
	str.clear();
	sum = 0;
  }

  return 0;
}

Measured memory_bytes: 3132
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		while(true){
			int e = scan.nextInt();
			if(e==0){
				break;
			}
			int m=10000000;
			int x=0;
			for(int z=0;z<1000;z++){
				for(int y=0;y<1000;y++){
					x=e-(z*z*z)-(y*y);
					if(x<0){
						continue;
					}
					if(x+y+z<m){
						m=x+y+z;
					}

				}

			}

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

Measured memory_bytes: 25956
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define rep4(i,a,n) for(ll i=(n)-1;i>=a;i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define mod 1000000007
#define INF 1000000000000000000
/****************************/
int k;
int c[11];
bool used[11];
int main()
{
	zero(c);
	zero(used);
  	cin>>k;
  	rep(i,k)
  	{
  		int now=10;
  		while(1)
  		{
  			c[now]++;
  			used[now]=1;
  			if(now==1) break;
  			if(c[now]==10)
			{
  				now--;
  				continue;
			}
  			if(!used[now-1]) break;
  			if(c[now]>c[now-1]+1)
  			{
  				now--;
			}
			else
			{
				break;
			}
		}
		rep3(j,now+1,11)
		{
			c[j]=max(0,c[j-1]-1);
		}
		/*bool have=false;
		rep3(i,1,11)
		{
			if(c[i]!=0)
			{
				cout<<c[i];
				have=1;
			}
			else
			{
				if(have) cout<<c[i];
			}
		}
		cout<<endl;*/
	}
	bool have=false;
	rep3(i,1,11)
	{
		if(c[i]!=0)
		{
			cout<<c[i];
			have=1;
		}
		else
		{
			if(have) cout<<c[i];
		}
	}
	cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int k,viz[100005],x,n,a,b,c,t;
long long dist[100005];
queue <int> q;
vector <int> v[100005];
vector <int> cost[100005];
void solve()
{
    q.push(k);
    viz[k]=1;
    while(!q.empty())
    {
        x=q.front();
        q.pop();
        for(int i=0;i<v[x].size();++i)
        {
            if(!viz[v[x][i]]||dist[v[x][i]]>dist[x]+cost[x][i])
            {
                viz[v[x][i]]=1;
                dist[v[x][i]]=dist[x]+cost[x][i];
                q.push(v[x][i]);
            }
        }
    }
}
int main()
{
    cin>>n;
    for(int i=1;i<n;++i)
    {
        cin>>a>>b>>c;
        v[a].push_back(b);
        v[b].push_back(a);
        cost[a].push_back(c);
        cost[b].push_back(c);
    }
    cin>>t>>k;
    solve();
    for(int i=1;i<=t;++i)
    {
        cin>>a>>b;
        cout<<dist[a]+dist[b]<<'\n';
    }
    return 0;
}


Measured memory_bytes: 14576
import java.util.Scanner;;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int max = Integer.MIN_VALUE;
        for(int i = 1;i<=1000;i++){
            for(int j = 2;j<20;j++){
                int tmp = (int)Math.pow(i,j);
                if(tmp>a){
                    break;
                }
                if(max < tmp && tmp<=a){
                    max = tmp;
                }
            }
        }
        System.out.println(max);
    }
}

Measured memory_bytes: 21972
#include<cstdio>
#include<cstring>
const int MAXN=410;

int n;
long long a[MAXN];
long long f[MAXN][MAXN];

inline long long min(long long x,long long y){
	return x<y?x:y;
}
int main(){
	memset(f,0x3f,sizeof(f));
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		a[i]+=a[i-1];f[i][i]=0;
	}
	for(int len=2;len<=n;len++)
		for(int r=1;r<=n;r++){
			int l=r-len+1;
			if(l<1)
				continue;
			for(int k=l;k<r;k++)
				f[l][r]=min(f[l][r],f[l][k]+f[k+1][r]);
			f[l][r]+=a[r]-a[l-1];
			// printf("%d %d %lld\n",l,r,f[l][r]);
		}
	printf("%lld\n",f[1][n]);
	return 0;
}

Measured memory_bytes: 1536
#coding: utf-8
from collections import defaultdict
import sys

H, W, M = (int(x) for x in input().split())

NH = [[0, i] for i in range(H)]
NW = [[0, i] for i in range(W)]

B = defaultdict(int) 
for i in range(M):
    h, w = (int(x)-1 for x in input().split())
    B[(h, w)] = 0
    NH[h][0] += 1
    NW[w][0] += 1

NH.sort(reverse=True)
NW.sort(reverse=True)
maxH = NH[0][0]
maxW = NW[0][0]

for i in range(H):
    countH, idxH = NH[i] 
    if countH != maxH:
        break

    for j in range(W):
        countW, idxW = NW[j] 
        if countW!= maxW:
            break

        if (idxH, idxW) not in B:
            print(maxH + maxW)
            sys.exit(0)

print(maxH + maxW - 1)


Measured memory_bytes: 130140
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

s = input()
t = input()
ans = 0
for i in range(3):
    if s[i] == t[i]:
        ans+=1
print(ans)

Measured memory_bytes: 4200
#include<stdio.h>
int main(){
	int i,n,x;
	
	scanf("%d",&n);
	
	for(i=3;i<=n;i++){
		
		if(i%3==0){
			printf(" %d",i);
		}
		else if(i%10==3){
			printf(" %d",i);
		}
		else{
			for(x=i;x!=0;x/=10){
				if(x%10==3){
					printf(" %d",i);
					break;
				}
			}
		}
	}
	printf("\n");
	
	return 0;
}


Measured memory_bytes: 2104