akhauriyash/Code-Regression huggingface dataset:
#ifdef _MSC_VER
#include "stdc++.h"
#endif
#ifdef __GNUC__
#include<bits/stdc++.h>
#endif
using namespace std;

using ll = long long;

//vector
using vi = vector<int>;
using vii = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

//constant
const double EPS = 1e-10;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(), (x).rend()

//debug
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

// vector
//template<typename T> vector<vector<T>> vv(ll H, ll W, T v) { return vector<vector<T>> vec(H, vector<T>(W, v)); }

// view vector
template<typename T> void view(T e) { cout << e << endl; }
template<typename T> void view(const vector<T>& v) { for (const auto& e : v) { cout << e << " "; } cout << endl; }
template<typename T> void view(const vector<vector<T> >& vv) { for (const auto& v : vv) { view(v); } }

// DP
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 (b < a) { a = b; return 1; } return 0; }




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


void add(vll& a, vll& b) {
    REP(i, a.size()) {
        a[i] += b[i];
    }
}

bool masterAll(vll& a, ll X) {
    REP(i, a.size()) {
        if (a[i] < X) return false;
    }
    return true;
}

int main() {

    int N, M, X;
    cin >> N >> M >> X;

    vector<tuple<ll, vll>> V(N, tuple<ll, vll>(0, vll(M, 0)));
    REP(i, N) {
        cin >> get<0>(V[i]);
        REP(j, M) {
            cin >> get<1>(V[i])[j];
        }
    }

    ll ans = 1e20;
    bool flag = false;
    REP(i, (1 << N)) {
        ll ret = 0;
        vll skill(M);
        REP(j, N) {
            if (i & (1 << j)) {
                ret += get<0>(V[j]);
                if (ret >= ans) break;
                add(skill, get<1>(V[j]));
                if (masterAll(skill, X)) {
                    flag = true;
                    chmin(ans, ret);
                    break;
                }
            }
        }
    }

    if (flag) cout << ans << endl;
    else cout << -1 << endl;

    return 0;
}



Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18

using namespace std;

int main(void){
  string s;
  cin >> s;
  
  vector<char> t(0);
  for (int i = 0; i < s.size(); i++){
    if (t.size() == 0)
      t.emplace_back(s[i]);
    else if (t[t.size()-1] == 'S' && s[i] == 'T'){
      t.pop_back();
    }
    else {
      t.emplace_back(s[i]);
    }
  }
 
  cout << t.size() << endl;

  return 0;
}


Measured memory_bytes: 772
from heapq import heappop, heappush, heapify

H, W = map(int, input().split())
S = [input() for _ in range(H)]

dx = [1,0]
dy = [0,1]

res = 1

heap = [(1, 0, 0)]
heapify(heap)
visited = [[0 for j in range(W)] for i in range(H)]
visited[0][0] = 1

while heap:
    c, x, y = heappop(heap)
    for i in range(2):
        nx, ny = x + dx[i], y + dy[i]
        if not (0 <= nx < H and 0 <= ny < W):
            continue
        if visited[nx][ny]:
            continue
        if S[x][y] == S[nx][ny]:
            visited[nx][ny] = c
            heappush(heap, (c, nx, ny))
        else:
            visited[nx][ny] = c + 1
            heappush(heap, (c + 1, nx, ny))

if S[0][0] == '#':
    print((visited[-1][-1]+1)//2)
else:
    print(visited[-1][-1]//2)

Measured memory_bytes: 48348
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 100000
int sizeD;
int D[200];
vector<int> cnt[200][26];
int cnt2[200];
char S[MAX_N+1];
int main(){
	int N,Q;
	cin>>N>>Q;
	
	cin>>S;
	
	for(int i=1;i*i<=N;i++){
		if(N%i==0){
			D[sizeD++]=i;
			D[sizeD++]=N/i;
		}
	}
	
	sort(D,D+sizeD);
	
	for(int j=0;j<sizeD;j++){
		for(int i=0;i<26;i++){
			cnt[j][i]=vector<int> (D[j]);
		}
	}
	
	for(int i=0;i<N;i++){
		S[i]-='a';
	}
	
	for(int j=0;j<sizeD;j++){
		for(int i=0;i<N;i++){
			cnt[j][S[i]][i%D[j]]++;
		}
		for(int i=0;i<D[j];i++){
			for(int c=0;c<26;c++){
				if(cnt[j][c][i]==N/D[j]){
					cnt2[j]++;
					break;
				}else if(cnt[j][c][i]>0){
					break;
				}
			}
		}
	}
	
	for(int z=0;z<Q;z++){
		int p;
		char c;
		cin>>p>>c;
		c-='a';
		p--;
		for(int j=0;j<sizeD;j++)
		{
			if(cnt[j][S[p]][p%D[j]]--==N/D[j]){
				cnt2[j]--;
			}
			if(++cnt[j][c][p%D[j]]==N/D[j]){
				cnt2[j]++;
			}
		}
		S[p]=c;
		
		for(int j=0;j<sizeD;j++){
			if(cnt2[j]==D[j])
			{
				cout<<D[j]<<endl;
				break;
			}
		}
	}
}


Measured memory_bytes: 39608
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
c=0
while c<m:
  d=a[0]/2
  for i in range(n):
    if a[0]==0:
      c=m
    if a[i]>d:
      a[i]//=2
      c+=1
      if c==m:
        break  
    else:
      a.sort(reverse=True)
      break
print(sum(a))

Measured memory_bytes: 20064
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int rate;
		if(x <=599){
			rate = 8;
		}else if(x <= 799){
			rate = 7;
		}else if(x <= 999){
			rate = 6;
		}else if(x <= 1199){
			rate = 5;
		}else if(x <= 1399){
			rate = 4;
		}else if(x <= 1599){
			rate = 3;
		}else if(x <= 1799){
			rate = 2;
		}else{
			rate = 1;
		}
		System.out.println(rate);
	}
}

Measured memory_bytes: 35652
n = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(1, n - 1):
        if p[i - 1] < p[i] < p[i + 1] or p[i - 1] > p[i] > p[i + 1]:
                ans += 1

print(ans)

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

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<double, double> Pdd;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;

const ll mod = 1e9+7;
const int INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;

int h, w;
char s[1000][1001];
ll ma[1000][1000];

int main(void){
    cin >> h >> w; for(int i = 0;i < h;i++)scanf("%s", &s[i]);
    for(int i = 0;i < h;i++)for(int j = 0;j < w;j++)ma[i][j] = INF;
    queue <PP> que;
    for(int i = 0;i < h;i++)for(int j = 0;j < w;j++){
        if(s[i][j] == '#')que.push(PP(P(i, j), 0));
    }
    while(que.size()){
        PP pp = que.front(); que.pop();
        ll I = pp.first.first;
        ll J = pp.first.second;
        ll S = pp.second;
        if(S >= ma[I][J])continue;
        ma[I][J] = S;
        if(I > 0)que.push(PP(P(I-1, J), S+1));
        if(J > 0)que.push(PP(P(I, J-1), S+1));
        if(I < h-1)que.push(PP(P(I+1, J), S+1));
        if(J < w-1)que.push(PP(P(I, J+1), S+1));
    }
    /*for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++){
            printf("%lld ", ma[i][j]);
        }
        printf("\n");
    }*/
    ll ans = 0;
    for(int i = 0;i < h;i++)for(int j = 0;j < w;j++)ans = max(ans, ma[i][j]);
    cout << ans << endl;
    return 0;
}


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

int64_t mod = 1000000007;
int64_t large = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    int S;
    cin >> S;
    map<int, int> list;
    list[S]++;
    while (true)
    {
        int tmp;
        if (S % 2 == 0)
            tmp = S /= 2;
        else
            tmp = S * 3 + 1;
        if (list.find(tmp) == list.end())
            list[tmp]++;

        else
        {
            cout << list.size() + 1;
            break;
        }
        S = tmp;
    }
}

Measured memory_bytes: 256
program palindrome_philia
  implicit none
  character(100) :: s
  integer :: n, i, m = 0
  read(*,*) s
  n = len_trim(s)
  do i = 1, n/2
    if (s(i:i) /= s(n-i+1:n-i+1)) m = m+1
  end do
  write(*,'(i0)') m
end program palindrome_philia

Measured memory_bytes: 768
#include<iostream>
#include<cstring>
using namespace std;
int main(){
    char a[101],b[101];
    cin>>a>>b;
    if(strlen(a)>strlen(b))cout<<"GREATER"<<endl;
    else if(strlen(a)<strlen(b))cout<<"LESS"<<endl;
    else cout<<(strcmp(a,b)?strcmp(a,b)>0?"GREATER":"LESS":"EQUAL")<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.Closeable;
import java.io.IOException;
import java.util.NoSuchElementException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author HBonsai
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CMultipleGift solver = new CMultipleGift();
        solver.solve(1, in, out);
        out.close();
    }

    static class CMultipleGift {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            long X = in.nextLong();
            long Y = in.nextLong();
            int ans = 0;
            for (long i = X; i <= Y; ans++) {
                i *= 2;
            }
            out.println(ans);
        }

    }

    static class FastScanner implements Closeable {
        private final InputStream in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        public FastScanner(InputStream in) {
            this.in = in;
        }

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte()) return buffer[ptr++];
            else return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
            return hasNextByte();
        }

        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public void close() {
            try {
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}



Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
#define int long long
signed main() {
	int n, k;
	cin >> n >> k;
	int x[n], y[n], Cmpx[n], Cmpy[n];
	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i];
		Cmpx[i] = x[i], Cmpy[i] = y[i];
	}
	sort(Cmpx, Cmpx + n);
	sort(Cmpy, Cmpy + n);
	long long ans = (Cmpx[n - 1] - Cmpx[0]) * (Cmpy[n - 1] - Cmpy[0]);
	for (int x1 = 0; x1 < n; x1++) {
		for (int x2 = x1 + 1; x2 < n; x2++) {
			for (int y1 = 0; y1 < n; y1++) {
				for (int y2 = y1 + 1; y2 < n; y2++) {
					int cnt = 0;
					for (int i = 0; i < n; i++) {
						if (x[i] >= Cmpx[x1] && x[i] <= Cmpx[x2] && y[i] >= Cmpy[y1] && y[i] <= Cmpy[y2]) {
							cnt++;
						}
					}
					if (cnt >= k) {
						ans = min(ans, (Cmpx[x2] - Cmpx[x1]) * (Cmpy[y2] - Cmpy[y1]));
					}
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import itertools
import copy
from collections import deque
import heapq
a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())
if a < b:
    ax = a + v*t
    bx = b + w*t
    if ax >= bx:
        print("YES")
    else:
        print("NO")
else:
    ax = a - v*t
    bx = b - w*t
    if ax <= bx:
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 9620
#include <iostream>
#include <string>
using namespace std;
string kaiten(string str1){
    char s = str1[0];
    for(int i=0;i<str1.length();i++){
        
        if(i!=str1.length()-1)str1[i]=str1[i+1];
        else str1[i]=s;
    }
    return str1;
}
int main(){
    string str1,str2;
    cin>>str1;
    cin>>str2;
    
    int ans=0;
    for(int i=0;i<str1.length();i++){
        if(str1==str2)ans=1;
        else str1=kaiten(str1);
    }
    if(ans==1)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static Scanner;

class Program
{
    static void Main() => new Program().Solve();

    public void Solve()
    {
        int k = ReadInt();
        if (k % 2 == 0 || k % 5 == 0)
        {
            Console.WriteLine(-1);
            return;
        }
        int n = 0;
        int c = 0;
        do
        {
            n = n * 10 + 7;
            n %= k;
            c++;
        }
        while (n != 0);
        Console.WriteLine(c);
    }
}

static class Scanner
{
    static Queue<string> que = new Queue<string>();
    public static string Read() { if (!que.Any()) foreach (var s in Console.ReadLine().Split()) que.Enqueue(s); return que.Dequeue(); }
    public static int ReadInt() => int.Parse(Read());
    public static IEnumerable<string> Read(long n) { for (long i = 0; i < n; i++) yield return Read(); }
    public static IEnumerable<int> ReadInt(long n) => Read(n).Select(int.Parse);
}


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

int main(){
    int n, m;
    while(1){
        cin >> n >> m;
        if(n == 0)
            break;

        vector<int> taro(n), hana(m);
        int diff = 0;
        for(int i=0; i<n; i++){
            cin >> taro[i];
            diff += taro[i];
        }
        for(int i=0; i<m; i++){
            cin >> hana[i];
            diff -= hana[i];
        }

        int an = -1, am = -1, temp = 1e9;
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                if(2 * (taro[i] - hana[j]) == diff){
                    if(taro[i] + hana[j] < temp){
                        an = i;
                        am = j;
                        temp = taro[i] + hana[j];
                    }
                }
            }
        }

        if(an == -1){
            cout << -1 << endl;
        }else{
            cout << taro[an] << ' ' << hana[am] << endl;
        }
    }
    
    return 0;
}

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

double s(ll x) {
  ll xx = x, sum = 0;
  while (xx) {
    sum += xx % 10;
    xx /= 10;
  }
  return (double)x / sum;
}

int main() {
  int K;
  cin >> K;
  ll n = 1, m = 1;
  for (ll i = 1; i <= K; i++) {
    cout << n << endl;
    while (s(n + m) > s(n + m * 10)) m *= 10;
    n += m;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int x;
void inp()
{
    cin >> x;
}
void process()
{
    cout << (x == 0);
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("test.inp","r", stdin);
    inp();
    process();
    return 0;
}


Measured memory_bytes: 3608
#include<iostream>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
#include<numeric>
#include<cmath>
using namespace std;
int inf = 1000000000;

int dx[8] = {0,1,1,1,0,-1,-1,-1};
int dy[8] = {1,1,0,-1,-1,-1,0,1};
vector< vector<int> > ans;

vector< vector<int> > check(vector< vector<int> > b, int r, int c){
  if( b[r][c] == -1 ) return b;
  vector< vector<int> > bb = b;
  for(int d=0; d<8; d++){
    int x = c; int y = r;
    while(true){
      x += dx[d]; y += dy[d];
      if( x < 0 || y < 0 || x >= 8 || y >= 8 ) break;
      if( bb[y][x] == 1 ){
        return b;
      }
      bb[y][x] = -1;
    }
  }
  bb[r][c] = 1;
  return bb;
}
bool f = false;
vector< vector<int> > dfs(vector< vector<int> > b, int q){
  if( f ) return b;
  if( q == 8 ){
    f = true;
    ans = b;
    return b;
  }
  for(int i=0; i<8; i++){
    for(int j=0; j<8; j++){
      vector< vector<int> > bb = check(b, i, j);
      if( b == bb ) continue;
      dfs(bb, q+1);
    }
  }
  return b;
}


int main(){
  int n;
  cin >> n;
  vector< vector<int> > b(8, vector<int>(8, 0));
  for(int i=0; i<n; i++){
    int r, c;
    cin >> r >> c;
    b[r][c] = 1;
    b = check(b, r, c);
  }
  dfs(b, n);
  for(int i=0; i<ans.size(); i++){
    for(int j=0; j<ans[i].size(); j++){
      if( ans[i][j] == -1 ) cout << ".";
      else if( ans[i][j] == 1 ) cout << "Q";
      else cout << ".";
    }
    cout << endl;
  }


  return 0;
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b) - 1; (i) >= (a); --(i)) //Reversi for
#define ll long long
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define yes cout << "yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define no cout << "no" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    ll a[3];
    cin >> a[0] >> a[1] >> a[2];
    if (a[0] % 2 == 0 || a[1] % 2 == 0 || a[2] % 2 == 0) {
        cout << 0 << endl;
    }else{
        qsort(a, 3, sizeof(ll), asc);
        cout << a[0] * a[1] << endl;
    }
    
    return 0;
}


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

namespace ABC120A
{
    class Program
    {
        static void Main(string[] args)
        {
            int a, b, c,d;
            var word = Console.ReadLine().Split(' ');
            a = int.Parse(word[0]);
            b = int.Parse(word[1]);

            c = int.Parse(word[2]);
            d = b/a;
            if (d <= c)
                Console.WriteLine(d);
            else if (c < d)
                Console.WriteLine(c);

            Console.ReadKey();
        }
        

    }
}

Measured memory_bytes: 11092
module Main where
import Data.Char
int = read :: String -> Int
getWord :: IO String
getWord = do
  c <- getChar
  if isSpace c
  then
    return []
  else do
    ws <- getWord
    return (c:ws)
getInt = fmap int getWord
replace pred a = map (\x -> if pred x then a else x)

main = interact $ printer . solver . parser
parser = concat . lines
printer = unlines . (:[])

solver xs = (xs!!0:xs!!4:xs!!8:[])

Measured memory_bytes: 380
//Solution By SlavicG
#include "bits/stdc++.h"
using namespace std;
 
#define        ll                   long long
 
#define  forn(i,n)                  for(int i=0;i<n;i++)
#define     all(v)                  v.begin(), v.end()
#define    rall(v)                  v.rbegin(),v.rend()
 
#define        pb                    push_back
#define     sz(a)                    (int)a.size()
 
#define     fastio                  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define       endl                  "\n"

int main()
{
	string s = "";
	int k;
	cin >> k;
	while(k--)
		s+="ACL";
	cout<<s;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
int main(){
    char buf[3];
    cin >> buf[0] >> buf[1] >> buf[2];
    int ans = -1;

int a = 0;
for(int i = 0;i< 3;i++)
{
        if(buf[i] =='R')
        {
            a++;
        }
        else if(buf[i] == 'S')
        {
            ans = max(a,ans);
            a = 0;
        }
}   
ans = max(a,ans);
    cout << ans << endl;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std ;
 
struct edge{
	int u , v , w ;
};
 
vector<edge> E ;
int n , p[100010] ;
 
bool operator < (edge A , edge B){
	return A.w < B.w ;
} 
 
int Find(int x)
{
	if(p[x] == x)return x ;
	return p[x] = Find(p[x]) ;
}
 
void Union(int x , int y){
	p[Find(x)] = p[y] ;
}
 
long long int kruskal()
{
	long long int ret = 0 ;
 
	for(int i = 0 ; i <= n ; i++)p[i] = i ;
 
	for (edge x : E){
		if(Find(x.u) == Find(x.v))continue ;
 
		Union(x.u , x.v) ;
		ret += (long long)x.w ;
	}
	return ret ;
}
 
int main(int argc, char const *argv[])
{
	pair<int , int> x[100010] , y[100010] ;
 
	scanf("%d" , &n) ;
 
	for(int i = 0 ; i < n ; i++){
		scanf("%d %d" , &x[i].first , &y[i].first) ;
		x[i].second = y[i].second = i+1 ; 
	}
 
	sort(x , x+n) ;
	sort(y , y+n) ;
 
	edge a ;
 
	for (int i = 0 ; i < n-1 ; i++){
		a.u = x[i].second ;
		a.v = x[i+1].second ;
		a.w = x[i+1].first-x[i].first ;
		E.push_back(a) ;
	}
 
	for (int i = 0 ; i < n-1 ; i++){
		a.u = y[i].second ;
		a.v = y[i+1].second ;
		a.w = y[i+1].first-y[i].first ;
		E.push_back(a) ;
	}
 
	sort(E.begin(), E.end()) ;
 
	printf("%lld\n", kruskal());
 
	return 0;
}

Measured memory_bytes: 6516
n, q = [parse(Int, x) for x in split(chomp(readline()))]
str = readline() |> chomp

ac = zeros(Int, n)
count = 0
for i = 1:n-1
    if str[i] == 'A' && str[i+1] == 'C'
        count += 1
    end
    ac[i+1] = count
end

for i = 1:q
    l, r = [parse(Int, x) for x in split(chomp(readline()))]
    val = ac[r] - ac[l]
    println(val)
end

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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define N 111

const int INF = 1 << 30 ;
typedef long long ll ;
typedef pair < int , int > pii ;

ll a[N] ;

int main() {
  ll n ;
  cin >> n; 
  for(int i = 0 ;i<n ;i++)cin>> a[i] ;

  cout << abs(*max_element(a,a+n) - *min_element(a,a+n)) << endl ;
	
  return 0 ;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#include<assert.h>
#include<chrono>
#include<random>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
#define SZ(x) ((int)x.size())
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
inline LL read()
{
	LL f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
template<typename T>inline void write(T x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
template<typename T>inline void pr1(T x){write(x);putchar(' ');}
template<typename T>inline void pr2(T x){write(x);putchar('\n');}
template<typename T>inline void chkmin(T &x,T y){x=x<y?x:y;}
template<typename T>inline void chkmax(T &x,T y){x=x>y?x:y;}
const int MAXN=55;
int T[MAXN],A[MAXN];
char ch[MAXN];
int main()
{
	int n=read();
	memset(T,-1,sizeof(T));
	for(int i=1;i<=n;i++)
	{
		memset(A,0,sizeof(A));
		scanf("%s",ch+1);int len=strlen(ch+1);
		for(int j=1;j<=len;j++)++A[ch[j]-'a'+1];
		for(int j=1;j<=26;j++)
			T[j]=(T[j]==-1?A[j]:min(T[j],A[j]));
	}
	for(int i=1;i<=26;i++)
		for(int j=1;j<=T[i];j++)putchar('a'+i-1);
	return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
using namespace std;

typedef pair <int, int> pii;

pii a[100010];
int vis[100010];
vector <pii> from[100010];
vector <int> ans;

int dfs(int x) {
	vis[x] = 1; int now = 0;
	for (int i = 0; i < from[x].size(); i++) {
		int v = from[x][i].fi;
		if (vis[v]) continue;
		if (dfs(v) != a[v].se) ans.push_back(from[x][i].se), now ^= 1;
	}
	return now;
}

int main () {
	int n, m; scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &a[i].fi, &a[i].se);
	}
	sort(a, a + n);
	int last = 0;
	for (int i = 0; i <= n; i++) {
		if (a[i].se == last) last = a[i].se, a[i].se = 0;
		else last = a[i].se, a[i].se = 1;
	}
	for (int i = 0; i < m; i++) {
		int l, r; scanf("%d%d", &l, &r);
		int ll = lower_bound(a, a + n, mp(l, -1)) - a;
		int rr = lower_bound(a, a + n, mp(r, 10)) - a;
		from[ll].push_back(mp(rr, i + 1));
		from[rr].push_back(mp(ll, i + 1));
	}
	for (int i = 0; i <= n; i++) {
		if (vis[i]) continue;
		if (dfs(i) != a[i].se) {
			printf("-1\n");
			return 0;
		}
	}
	sort(ans.begin(), ans.end());
	printf("%d\n", ans.size());
	for (int i = 0; i < ans.size(); i++) {
		printf("%d ", ans[i]);
	}
	printf("\n");
	return 0;
}


Measured memory_bytes: 15100
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

 
const int INF=1e9+5;
 
int32_t main()
{
	IOS;
    int n;
    scanf("%d", &n);
    vector<int> h(n);
    for(int& x : h) {
        scanf("%d", &x);
    }
    vector<int> dp(n, INF);
    dp[0] = 0;
    for(int i = 0; i < n; ++i) {
        for(int j : {i + 1, i + 2}) {
            if(j < n) {
                dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
            }
        }
    }

    printf("%d\n", dp[n-1]);

	return 0;
}

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

int main(){
    int n;cin>>n;
    vector<int> b(n-1);
    for(int i=0;i<n-1;i++){
        cin>>b[i];
    }
    int ans=0,tmp=b[n-2];
    for(int i=n-2;i>=-1;i--){
        if(i<0){
            ans+=b[0];
            continue;
        }
        if(i==n-2){
            ans+=b[i];
            continue;
        }
        tmp=b[i]<b[i+1]?b[i]:b[i+1];
        ans+=tmp;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
using namespace std;
const int MAXN = (int) 1500 + 10;
const int INF = (int) 0x3f3f3f3f;
typedef long long LL;

int m,n;
int h[MAXN],w[MAXN];
int cnt[1500000 + 10];

void work(){
    while(scanf("%d%d",&n,&m)&&n&&m){
        for(int i=1;i<=n;i++) scanf("%d",&h[i]);
        for(int i=1;i<=m;i++) scanf("%d",&w[i]);
        for(int i=2;i<=n;i++) h[i]+=h[i-1];
        for(int i=2;i<=m;i++) w[i]+=w[i-1];
        for(int i=1;i<=1500000;i++) cnt[i]=0;
        for(int i=0;i<n;i++){
            for(int j=i+1;j<=n;j++){
                cnt[h[j]-h[i]]++;
            }
        }
        LL ans=0;
        for(int i=0;i<m;i++){
            for(int j=i+1;j<=m;j++) ans+=cnt[w[j]-w[i]];
        }
        printf("%lld\n",ans);
    }
}

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













Measured memory_bytes: 8480
#include<bits/stdc++.h>
using namespace std;
///////////////////////////////////////////////////////////////////////////////////////////////////////
const int maxn=1e5+10;
int dp[3][maxn];
int n;
int a[maxn];
int b[maxn];
int c[maxn];
int main(){
	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i]>>b[i]>>c[i];
	}
	
	for(int i=1;i<=n;i++){
		dp[0][i]=a[i]+max(dp[1][i-1],dp[2][i-1]);
		dp[1][i]=b[i]+max(dp[0][i-1],dp[2][i-1]);
		dp[2][i]=c[i]+max(dp[0][i-1],dp[1][i-1]);
	}
	cout<<max(dp[1][n],max(dp[0][n],dp[2][n]));
	return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>

#define MOD 1000000007LL

long long fact[200010], factinv[200010];

void factorial(void) {
	int i, j;
	long long P, Q, R, EXP;
 
	fact[0] = 1; factinv[0] = 1;
	for (i=1;i<=200000;i++) {
		fact[i] = fact[i-1];
		fact[i] *= i;
		fact[i] %= MOD;
 
		factinv[i] = factinv[i-1];
		P = 1;
		Q = i;
		EXP = 1000000005LL;
		while (EXP>0) {
			if (EXP & 1) P *= Q;
			Q *= Q;
			EXP >>= 1;
			P %= MOD;
			Q %= MOD;
		}
		factinv[i] *= P;
		factinv[i] %= MOD;
	}
 
}

long long comb_mod(int a, int b) {
	long long P=1;
	P = P * fact[a];
	P = P * factinv[a-b] % MOD;
	P = P * factinv[b]   % MOD;
	return P;
}

long long print_ratio(long long y, long long x) {
    // x assumed exponent of 2
    long long z, prod, t;
    prod = 1LL; t = 2LL;
    z = MOD - 1 - x;
    while (z) {
        if (z & 1) prod = prod*t % MOD;
        t = t*t % MOD;
        z >>= 1;
    }
    return prod*y%MOD;
}

int main(void) {
    int i, B, W;
    long long z, denom, num, black[200010], white[200010];
    factorial();
    scanf("%d%d", &B, &W);
    black[0] = 0LL;
    white[0] = 0LL;
    for (i=1;i<=B+W;i++) {
//        denom = i-1;
        if (i<B) { black[i] = 0LL; }
        else {
            num = black[i-1] + print_ratio(comb_mod(i-1,B-1), i);
            black[i] = num % MOD;
        }

        if (i<W) { white[i] = 0LL; }
        else {
            num = white[i-1] + print_ratio(comb_mod(i-1,W-1),i);
            white[i] = num % MOD;
        }

    }
    // for (i=0;i<B+W;i++) {
    //     printf("%9lld ", black[i]);
    // }
    // printf("\n");
    // for (i=0;i<B+W;i++) {
    //     printf("%9lld ", white[i]);
    // }
    // printf("\n");
    // printf("%lld\n", binomial(3,1));

    for (i=1;i<=B+W;i++) {
        z = print_ratio(1,1) - print_ratio(black[i-1],1) + print_ratio(white[i-1],1) + MOD;
        // printf("%10lld/%10lld\n", num, denom);
        printf("%lld\n", z % MOD);
    }

    return 0;
}

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

int main() {
  int s;
  cin>>s;
  int count=1;
  
  if(s==1||s==2||s==4){
    cout<<4;
   }
  else {
  while(s!=1){
    if(s%2==0)
    s=s/2;
  else
    s=3*s+1;
    
    count++;
    }
   cout<<count+1;
  }
  
  
  
     
  
}




Measured memory_bytes: 256
h, n = map(int, input().split())
inf = float("inf")

dp = [[inf]*(h+1) for i in range(n+1)]
dp[0][0] = 0

#dp[i][j] = i個目までの魔法を使って、ダメージの和をjにするときの最小コスト

for i in range(n):
  a, b = map(int, input().split())
  for j in range(h+1):  
    dp[i+1][j] = min(dp[i][j], dp[i+1][max(0, j-a)] + b)
"""
for i in range(n+1):
  print(dp[i])
"""
print(dp[n][h])

Measured memory_bytes: 289544
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

n = int(input())
a = list(map(int,input().split()))
cnt = [0]*(n)
for i in range(len(a)):
    cnt[a[i]-1]+=1
for i in range(len(cnt)):
    print(cnt[i])

Measured memory_bytes: 51012
import sys, re
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from collections import deque, defaultdict, Counter
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop, heapify
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M = MAP()
ab = [LIST() for _ in range(M)]

#隣接行列
contact = [[0]*N for _ in range(N)]

for a, b in ab:
	contact[a-1][b-1] = 1
	contact[b-1][a-1] = 1

A = list(x for x in range(1, N))
ans = 0

for X in permutations(A, N-1):
	#print(X)
	tmp = 0
	for y in X:
		if contact[tmp][y] == 1:
			tmp = y
		else:
			break
	else:
		#print("成功")
		ans += 1

print(ans)


Measured memory_bytes: 5316
import java.util.*;
import java.lang.*;
import java.io.*;
import java.util.Scanner;

class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a < b)
		{
			System.out.println("a < b");
		}else if(a > b){
			System.out.println("a > b");
		}else
			System.out.println("a == b");
	}
}

Measured memory_bytes: 26168
import java.util.*;
import static java.lang.System.*;

//https://atcoder.jp/contests/abc075/tasks/abc075_c
//O(n^2)の全探索。たかだかn=250
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();

        boolean[][] edges = new boolean[N][N];
        for (int m = 0; m < M; m++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            edges[a-1][b-1] = true;
            edges[b-1][a-1] = true;
        }

        solver(N, edges);
    }

    public static void solver(int N, boolean[][] edges){
        //橋になり得る辺と接するノード
        Set<Integer> left_nodes = new HashSet<Integer>();
        for(int n = 0; n < N; n++) {
            left_nodes.add(n);
        }

        //1つの辺としか繋がっていないノードに接する辺は橋になりえる
        //橋になり得る辺を除いて、再度チェックする(まとめて非連結になる可能性があるため)
        int ans = 0;
        int before_ans = ans + 1;
        while (ans != before_ans) {
            before_ans = ans;
            HashMap<Integer, Integer>  bridgeable_nodes = new HashMap<Integer, Integer>(); //孤立する可能性があるノード

            for(Integer from: left_nodes) {
                ArrayList<Integer> bridge_nodes = new ArrayList<Integer>();  //nとつながるノード
                for(int to=0; to<N; to++){
                    if(edges[from][to] == true){ bridge_nodes.add(to); }
                }

                //1つの辺として繋がっていないノード
                if (bridge_nodes.size() == 1){
                    bridgeable_nodes.put(from, bridge_nodes.get(0));
                }
            }

            //孤立するノードを外して再度検出処理をする
            for(Integer from: bridgeable_nodes.keySet()) {
                int to = bridgeable_nodes.get(from);
                left_nodes.remove(from);

                //一緒に孤立する場合には、1つのノードしか数えない。例えば、1<->2しかない場合。1も2も孤立するが、橋は１つ
                if(edges[from][to] == false){
                    continue;
                }

                edges[from][to] = false; //このノードと繋がっていることは忘れる。まとめて孤立する可能性がある
                edges[to][from] = false;

                ans++;
            }
        }

        out.println(ans);
    }
}


Measured memory_bytes: 21844
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<utility>//swapでaとbの値を入れ替える
#define rep(i,n) for(int i=0;i<(n);i++)
#define ll long long
#define sort(s) sort(s.begin(),s.end())
#define r(s) reverse(s.begin(),s.end())
using namespace std;

int main() {
	int a,b,c;
	cin >> a>>b>>c;
	if (a + b >= c)cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

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


int main(){
  string a,b;
  cin >> a >> b;
  vector<char> s,t;
  rep(i,a.length()) s.push_back(a[i]);
  rep(i,b.length()) t.push_back(b[i]);
  sort(s.begin(),s.end());
  sort(t.begin(),t.end(),greater<char>());
  bool ok = true;
  int k = s.size();
  int l = t.size();

  if(k<l){
    rep(i,k){
      if(s[i]!=t[i]) ok = false;
    }
    if(ok){
      cout << "Yes" << endl;
      return 0;
    }
  }

  
  ok = false;
  int tmp=-1;
  rep(i,min(k,l)){
    int j=0;

    while(j<=i){
      if(s[j]!=t[j]){
        tmp=j;break;
      } 
      j++;
    }

    if(tmp>=0){
      if(s[tmp]<t[tmp]){
        cout << "Yes" << endl;
        return 0;
      }
    }
  
  }

  if(k<l&&tmp<0) ok = true;
  
  if(ok) cout << "Yes" << endl;
  else cout << "No" <<endl;


  return 0; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
#define DEBUG 0 
#define LIMIT (LONG_MAX / 10)
#define POSITIVE_LAST_D (LONG_MAX % 10)
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;


int main(){
    int n,m;
    cin>>n>>m;
    int s[5]={};
    int c[5]={};
    rep(i,m){
        cin>>s[i]>>c[i];
    }
    for(int i=(n==1?0:pow(10,n-1));i<pow(10,n);i++){
        int cnt=0;
        rep(j,m){
            if(n==1){
                if(s[j]==1&&c[j]==i)cnt++;
            }else if(n==2){
                if(s[j]==1&&c[j]==(i/10))cnt++;
                if(s[j]==2&&c[j]==(i%10))cnt++;
            }else{
                if(s[j]==1&&c[j]==(i/100))cnt++;
                if(s[j]==2&&c[j]==((i/10)%10))cnt++;
                if(s[j]==3&&c[j]==(i%10))cnt++;
            }
        }
        if(cnt==m){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <limits>
#include <queue>
#include <map>

using namespace std;


struct edge {
    int src;
    int dst;
    int weight;

    edge(int src, int dst, int w) : src(src), dst(dst), weight(w) {}
};

bool operator < (const edge &a, const edge &b) {
  return a.weight > b.weight;
}


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

    vector<map<int, int>> G(n);
    for (int i = 0; i < n; ++i) {
        int u, k;
        cin >> u >> k;

        for (int j = 0; j < k; ++j) {
            int v, c;
            cin >> v >> c;
            G[u][v] = c;
        }
    }

    // Dijkstra's algorithm (with pritority queue)
    vector<int> d(n, -1);
    vector<bool> visited(n, false);
    priority_queue<edge> Q;

    Q.push(edge(-1, 0, 0));
    while (!Q.empty()) {
        auto e = Q.top(); Q.pop();
        if (visited[e.dst])
            continue;
        d[e.dst] = e.weight;
        visited[e.dst] = true;

        int i = e.dst;
        int minw = numeric_limits<int>::max();
        for (auto& x : G[i]) {
            if (visited[x.first])
                continue;
            int w = x.second + d[i];
            Q.push(edge(i, x.first, w));
        }
    }

    for (int i = 0; i < n; ++i) {
        cout << i << " " << d[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 29352
mod = 1000000007

def mod_cmb(n: int, k: int, p: int) -> int:
    if n < 0 or k < 0 or n < k: return 0
    if n == 0 or k == 0: return 1
    if (k > n - k):
        return mod_cmb(n, n - k, p)
    c = d = 1
    for i in range(k):
        c *= (n - i)
        d *= (k - i)
        c %= p
        d %= p
    return c * pow(d, -1, p) % p

def main():
    n, a, b = map(int, input().split())

    ans = pow(2, n, mod) - 1

    tmp_a = mod_cmb(n , a, mod)
    tmp_b = mod_cmb(n , b, mod)

    print((ans-tmp_a-tmp_b)%mod)

if __name__ == '__main__':
    main()


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

double dista(vector<int> &x, vector<int> &y, int i,int j){
    double distance;
    distance = (x.at(i) - x.at(j)) * (x.at(i) - x.at(j)) + (y.at(i) - y.at(j)) * (y.at(i) - y.at(j));
    distance = sqrt(distance);
    return distance;
}

int main(){
    int N;
    cin >> N;
    vector<int> x(N);
    vector<int> y(N);
    for(int i=0;i<N;i++){
        cin >> x.at(i);
        cin >> y.at(i);
    }

    double distance;
    int nhiku = 1;
   for(int i=1;i<N;i++){
       nhiku = nhiku * i;
   } 

    distance = 0;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){

            if(i != j){
                distance += dista(x,y,i,j) * nhiku;
            }

        }
    }
    int nkai = 1;
    for(int i=1;i<=N;i++){
        nkai = nkai*i;
    }
    distance = distance /nkai;
    printf("%lf", distance);

    return 0;
}


Measured memory_bytes: 256
//
//  main.c
//  AOJ Areas on the Cross-Section Diagram
//
//  Created by NEO Trinity on 2019/2/27.
//  Copyright © 2019 NEO Trinity. All rights reserved.
//

#include <stdio.h>
struct stack
{
    int a;
    int b;
};

typedef struct stack Stack;

int  stack1 [20010];
int top1=0;
void  push1 (int t)
{
    top1++;
    stack1[top1]=t;
}
int pop1()
{
    top1--;
    return stack1[top1+1];
}

Stack stack2 [20010];
int top2=0;
void push2 (Stack t)
{
    top2++;
    stack2[top2]=t;
}
Stack pop2()
{
    top2--;
    return  stack2[top2+1];
}


int main()
{
    char ch;
    int j,sum=0;
    Stack t;
    for(int i=0;scanf("%c",&ch)!=EOF;i++)
    {
        if(ch=='\\') push1(i);
        if(ch=='/' && top1>0)
        {
            j=pop1();
            sum+=i-j;
            t.a=i-j;
            t.b=j;
//            printf("%d\n",t.a);
            while(top2>0 && stack2[top2].b>j)
            {
                t.a+=pop2().a;
            }
            push2(t);
        }
        
    }
    printf("%d\n",sum);
    int ans[top2+10];
    printf("%d",top2);
    
    if(top2!=0)printf(" ");
//    printf("%d\n",pop2().a);
//     printf("%d\n",pop2().a);
    int n=top2;
    for(int i=0;i<n;i++)
    {
        ans[i]=pop2().a;
//        printf("hi=%d i=%d\t ",ans[i],i);
    }
    for(int i=n-1;i>-1;i--)
    {
        printf("%d",ans[i]);
        if(i!=0)printf(" ");
    }
    printf("\n");
    return 0;
}
/*
 31
 5 4 2 1 19 5
    /\_/\/\
\  /       \
 \/         \  _/\
             \/
*/



Measured memory_bytes: 2064
#include<iostream>

using namespace std;
const int INF = 1000000;

int main()
{
  int edge[10][10];
  int n;
  for(;cin>>n,n;)
    {
      for(int i=0;i<10;i++)
	for(int j=0;j<10;j++)
	  {
	    if(i!=j)
	      edge[i][j]=INF;
	    else
	      edge[i][j]=0;
	  }
      int max_num=0;
      for(int i=0;i<n;i++)
	{
	  int a,b,c;
	  cin>>a>>b>>c;
	  edge[a][b]=c;
	  edge[b][a]=c;
	  max_num=max(max_num,max(a,b));
	}
      for(int k=0;k<=max_num;k++)
	for(int i=0;i<=max_num;i++)
	  for(int j=0;j<=max_num;j++)
	    {
	      edge[i][j]=min(edge[i][j],edge[i][k]+edge[k][j]);
	    }
      int ans=0,sum=INF*10;
      for(int i=0;i<=max_num;i++)
	{
	  int tmp=0;
	  for(int j=0;j<=max_num;j++)
	    {
	      tmp+=edge[i][j];
	    }
	  if(tmp<sum)
	    {
	      ans=i;
	      sum=tmp;
	    }
	}
      cout<<ans<<" "<<sum<<endl;
    }
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
 
int main(){
char a[100][100];
int b = 0,c = 0;
  
  cin >> b >> c;
  for(int Q = 0;Q < b;Q++){
  	for(int W = 0;W < c;W++){
    	cin >> a[Q][W];
    }
  }
  
  for(int Q = 0;Q < b;Q++){
    for(int S = 0;S < 2;S++){
  	for(int W = 0;W < c;W++){
    	cout << a[Q][W];
    }
    cout << endl;
    }
  }
return 0;
}

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

int main()
{
    
    int ans,sccs,hit=0,brow=0;
    int success[4] = {0},answer[4] = {0};
    
    while (1) {
        cin >> sccs >> ans;
        if (ans == 0 && sccs == 0) break;
        hit = 0;
        brow = 0;
        
        for (int i = 3; i >= 0; i--) {
            answer[i] = ans % 10;
            ans = ans / 10;
            success[i] = sccs % 10;
            sccs = sccs / 10;
        }
        
        for (int i = 0; i < 4; i++) {
            for (int k = 0; k < 4; k++) {
                if (answer[i] == success[k]) {
                    if (i == k) {
                        hit++;
                        break;
                    }else {
                        brow++;
                        break;
                    }
                }
            }
        }
        
        cout << hit << " " <<  brow << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a; i < n; i++)
#define per(i,n,a) for (int i = n - 1; i >= a; i--)
using namespace std;

int A[210],N;
int main() {
    int dmin = 100;
    scanf("%d", &N);
    rep(i, 0, N) {
        int A;
        scanf("%d", &A);
        int d = 0;
        while (A % 2 == 0) {
            A /= 2;
            d++;
        }
        dmin = min(dmin, d);
    }
    printf("%d\n", dmin);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define F(i,a,b) for(i = a; i <= b; i ++)
#define RF(i,a,b) for(i = a; i >= b;i --)
#define sz(a) sizeof(a)
using namespace std;

typedef pair<int,int> pii;
typedef pair<char,int> pci;
typedef map<int,int> mii;
typedef map<char,int> mci;
typedef unordered_map<int,int> umii;
typedef unordered_map<char,int> umci;

void solve()
{
    int n,i,k;
    cin>>n>>k;
    int *height_arr = new int[sz(int) * n], * sol = new int[sz(int) * n];
    F(i,0,n - 1)
        cin>>height_arr[i];
    sol[n - 1] = 0;
    RF(i, n - 2, 0)
    {
        sol[i] = INT_MAX;
        int j;
        F(j,i + 1,i + k)
        {
            if(j >= n)
                break;
            sol[i] = min(abs(height_arr[j] - height_arr[i]) + sol[j]
                    ,sol[i]);
        }
    }
    cout<<sol[0]<<'\n';
}

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


Measured memory_bytes: 1024
function hamming(){
   var obj={};
   for(var i=1;i<=1000000;i++){
      var h=i;
      while(h%2==0)h/=2;
      while(h%3==0)h/=3;
      while(h%5==0)h/=5;
      if(h==1)obj[i]=true
   }
   return obj;
}
var Numbers=hamming();
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.replace(/\n$/,"")).split("\n");
while(true){
   var mn=(Arr.shift()).split(" ").map(Number);
   if(mn[0]==0)break;
   var cnt=0;
   for(var i=mn[0];i<=mn[1];i++){
      if(Numbers[i])cnt++;
   }
   console.log(cnt);
}

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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  
  for (int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  int c=0;
  for (int i=0; i<N-1; i++){
    if (vec.at(i) > vec.at(i+1)){
      c++;
    }
  }
  
  cout << c+1 << endl;
} 

Measured memory_bytes: 256
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-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())

N = inp()
lines = [set() for _ in range(N)]
ABs = []
for _ in range(N-1):
    a,b = inpl()
    a,b = a-1, b-1
    ABs.append((a,b))
    lines[a].add(b)
    lines[b].add(a)


K = -1
ki = -1
for i in range(N):
    if K < len(lines[i]):
        K = len(lines[i])
        ki = i



colors = [defaultdict(int) for _ in range(N)]

def dfs(s,bs,bk):
    cnt = 0
    for t in lines[s]:
        if t == bs:
            continue
        else:
            if cnt == bk:
                cnt += 1
            colors[s][t] = cnt
            colors[t][s] = cnt
            dfs(t,s,cnt)
            cnt += 1


for i,t in enumerate(lines[ki]):
    colors[ki][t] = i
    colors[t][ki] = i
    dfs(t,ki,i)

print(K)
for a,b in ABs:
    print(colors[a][b]+1)


Measured memory_bytes: 96012
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int N;
string S;
string ns;
const string JOI = "JOI#";

ll IC[100005];
ll JC[100005];

ll dp[100005][4];
ll solve(const string &s){
  memset(dp,0,sizeof(dp));
  dp[0][0] = 1;
  for(int i=0;i<s.size();i++){
    for(int j=0;j<4;j++){
      if( s[i] == JOI[j] ) dp[i+1][j+1] += dp[i][j];
      dp[i+1][j] += dp[i][j];
    }
  }
  return dp[s.size()][3];
}

int main(){

  cin >> N;
  cin >> S;

  ll res = solve( S );

  S="a"+S;

  for(int i=1;i<=N;i++){
    if( S[i] == 'J' ) JC[i] = JC[i-1] + 1;
    else JC[i] = JC[i-1];
  }

  for(int i=N;i>=1;i--){
    if( S[i] == 'I' ) IC[i] = IC[i+1] + 1;
    else IC[i] = IC[i+1];
  }
  
  ll lmax = 0;
  for(int i=1;i<=N;i++){
    lmax = max( lmax, JC[i]*IC[i] );
  }
  res = res + lmax;
  
  S = S.substr(1);
  ns = "J" + S;
  res = max( res, solve( ns ) );
  ns = S + "I";
  res = max( res, solve( ns ) );

  cout << res << endl;


  
  

}

Measured memory_bytes: 8052
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,a[10000],b,c[500],i,k=0,j;
  for(cin>>n,i=0;i<n;i++)cin>>a[i];
  for(cin>>b,i=0;i<b;i++)cin>>c[i];
  for(i=0;i<b;i++)for(j=0;j<n;j++){
    if(c[i]==a[j]){k++;break;}
  }
  cout<<k<<endl;
}

Measured memory_bytes: 3140