akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()

	N := readInt()
	K := readInt()
	m := make(map[int]int)
	for i := 0; i < N; i++ {
		a := readInt()
		m[a]++
	}
	b := make([]int, 0, len(m))
	for _, v := range m {
		b = append(b, v)
	}
	sort.Ints(b)
	var ans int
	for i := 0; i+K < len(b); i++ {
		ans += b[i]
	}
	println(ans)
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	for(int i=1;true;++i){
		int x,y; cin>>x>>y;
		if(!x&&!y)break;
		cout<<min(x,y)<<" "s<<max(x,y)<<"\n"s;
	}
}


Measured memory_bytes: 3116
import math
 
k=int(input())
cnt=0
tmp=[]
for a in range(k):
  a=a+1
  for b in range(k):
    b=b+1
    tmp.append(math.gcd(a,b))
for i in tmp:
  if i==1:
    cnt=cnt+k
  else:
    for j in range(k):
      j=j+1
      cnt=cnt+math.gcd(i,j)
print(cnt)
      

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  while(A * C > 0){
    C -= B;
    if(C <= 0) break;
    A -= D;
    if(A <= 0) break;
  }
  if(A <= 0) cout << "No" << endl;
  else if(C <= 0) cout << "Yes" << endl; 
}


Measured memory_bytes: 3636
N, W = list(map(int, input().split()))

w1, v = list(map(int, input().split()))
V = [[] for _ in range(4)]
V[0].append(v)

for _ in range(N-1):
    w, v = list(map(int, input().split()))
    V[w-w1].append(v)

S = []
for vl in V:
    vl.sort(reverse=True)
    s = [0]
    for v in vl:
        s.append(s[-1]+v)
    S.append(s)

ans = 0
for n0, s0 in enumerate(S[0]):
    for n1, s1 in enumerate(S[1]):
        for n2, s2 in enumerate(S[2]):
            for n3, s3 in enumerate(S[3]):
                if n0*w1 + n1*(w1+1) + n2*(w1+2) + n3*(w1+3)<=W:
                    ans = max(ans, s0+s1+s2+s3)
print(ans)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(int argc,char *argv[]){
	int m,n;
	int *b;
	int **A;
	int *c;
	cin >> n >> m;
	A = new int*[n];
	for(int i=0; i < n; i++){
		A[i] = new int[m];	
	}
	for(int i=0; i < n; i++){
		for(int j=0; j < m;j++){
			cin >> A[i][j];		
		}
	}
	b = new int[m];
	for(int i=0; i < m; i++){
		cin >> b[i];	
	}
	c = new int[n];
	for(int i=0; i < n; i++){
		c[i] = 0;
		for(int j=0; j < m; j++){
			c[i] += A[i][j] * b[j];
		//	cout << " + " <<A[i][j] << "*" << b[j];
		}
		//cout <<  "=" << c[i] << endl;
		cout << c[i] << endl;
	}
	delete[] c;
	
	delete[] b;
	for(int i=0; i < n; i++){
		delete[] A[i];
	}
	delete[] A;

	return 0;
}

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

int main() {
    string S;
    cin >> S;
    vector<int> A(S.size());
    if(S.size() >= 3) {
    if(S.size() % 2 == 1) {
        rep(i, S.size()-2) {
            if(S[2*i] == 'R') A[2*i] = 1;
            if(S[2*i] == 'U') A[2*i] = 1;
            if(S[2*i] == 'D') A[2*i] = 1;
            }
        rep(i, S.size()-3) {
            if(S[2*i+1] == 'L') A[2*i+1] = 1;
            if(S[2*i+1] == 'U') A[2*i+1] = 1;
            if(S[2*i+1] == 'D') A[2*i+1] = 1;
        }
        }
    if(S.size() % 2 == 0) {
        rep(i, S.size()-3) {
            if(S[2*i] == 'R') A[2*i] = 1;
            if(S[2*i] == 'U') A[2*i] = 1;
            if(S[2*i] == 'D') A[2*i] = 1;
            if(S[2*i+1] == 'L') A[2*i+1] = 1;
            if(S[2*i+1] == 'U') A[2*i+1] = 1;
            if(S[2*i+1] == 'D') A[2*i+1] = 1;
        }
        }
    } else if (S.size() == 1) {
        if(S[0] == 'R') A[0] = 1;
        if(S[0] == 'U') A[0] = 1;
        if(S[0] == 'D') A[0] = 1;
    } else if(S.size() == 2) {
        if(S[0] == 'R') A[0] = 1;
        if(S[0] == 'U') A[0] = 1;
        if(S[0] == 'D') A[0] = 1;
        if(S[1] == 'L') A[1] = 1;
        if(S[1] == 'U') A[1] = 1;
        if(S[1] == 'D') A[1] = 1;
    }
    int sum=0;

    rep(i, A.size()) sum+=A[i];

    if(sum == A.size()) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main(){
	unsigned long long a,b;
  
  	cin >> a >> b;
  
  	if(a == 1 || b == 1){
      cout << '1';
      return 0;
    }
  	if(a * b % 2 == 0){
    	cout << a * b / 2; 
    } else {
     	cout << a * b / 2 + 1; 
    }
  
	return 0;
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

template<class T>
bool ChangeMax(T&a,const T&b){
  if(a >= b) return false;
  a = b;    return true;
}

template<class T>
bool ChangeMin(T&a,const T&b){
  if(a <= b) return false;
  a = b;    return true;  
}

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}


int main(){
  int x; cin >> x;
  int ans = 1;
  for(int i = 2; i <= x; ++i){
    int y = i*i;
    while(y <= x){
      ChangeMax(ans,y);
      y *= i;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3556
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define reg register
typedef long long ll;
template<typename T>inline T read(){
	reg T x=0;reg short f=1;reg char c=getchar();
	for(;!isdigit(c);f=c=='-'?-1:1,c=getchar());
	for(;isdigit(c);x=x*10+(c^48),c=getchar());
	return x*f;
}
const int MN=2005;
int n,k,root,s[MN],t[MN],dis[MN][MN];
struct edge{int to,nxt;}es[MN<<1];
int h[MN],cnt;
inline void ins(int s,int t){
	es[++cnt]=(edge){t,h[s]};h[s]=cnt;
	es[++cnt]=(edge){s,h[t]};h[t]=cnt;
}
inline void dfs(int fa,int st,int dep){
	for(reg int i=h[st];i;i=es[i].nxt)
		if(es[i].to!=fa){
			dis[root][es[i].to]=dis[es[i].to][root]=dep;
			dfs(st,es[i].to,dep+1);
		}
}
int main(){
	n=read<int>();k=read<int>();reg int ans=0x7fffffff;
	for(reg int i=1;i<n;i++)ins(s[i]=read<int>(),t[i]=read<int>());
	for(reg int i=1;i<=n;i++)dfs(root=i,i,1);
	if(k&1){
		k>>=1;
		for(reg int i=1;i<n;i++){
			reg int cnt=0;
			for(reg int j=1;j<=n;j++)
				if(dis[j][s[i]]>k&&dis[j][t[i]]>k)cnt++;
			ans=min(ans,cnt);
		}
	}
	else
		for(reg int i=1;i<=n;i++){
			reg int cnt=0;
			for(reg int j=1;j<=n;j++)
				if((i^j)&&(dis[i][j]<<1)>k)cnt++;
			ans=min(ans,cnt);
		}
	printf("%d\n",ans);
    return 0;
}

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

int main() {
  // input
  int a, b, c;  cin >> a >> b >> c;
  
  // calc
  int ans;
  if (a * c <= b) ans = c;
  else ans = b / a;
  
  // output
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  int a,b;
  cin >> a >> b;
  cout << max(a+b,max(a-b,a*b))<< endl;
}



Measured memory_bytes: 256
N,M= gets.split.map(&:to_i)

#Mの約数かつM/N以下で最大のものを求める
max = 1

#Mの約数：M^(1/2)まで調べれば十分
for i in 1..[Math.sqrt(M).to_i,M/N].min do
  next if M%i != 0
  max = i
  if M/i <= M/N
    max = M/i
    break
  end
end

puts max


Measured memory_bytes: 1788
from collections import deque

n, m = map(int, input().split())
graph = [[] for _ in range(n + 1)]
for _ in range(m):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

infi = 10 ** 20
que = deque([(1, 0, -1)])
par = [-1] * (n + 1)
dist = [infi] * (n + 1)

while que:
    v, d, p = que.popleft()
    if dist[v] <= d:
        continue
    dist[v] = d
    par[v] = p
    for u in graph[v]:
        if par[u] == v:
            continue
        que.append((u, d + 1, v))

print("Yes")
print(*par[2:], sep="\n")


Measured memory_bytes: 53080
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<array>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

#ifdef ONLINE_JUDGE
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#define int128 __int128
#else
#define int128 long long
#endif

#define all(x) x.begin(), x.end()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(nullptr));

ll mod = 1e9 + 7;

namespace {
    ll mul(ll a, ll b) {
        ll val = a * b - (ll)((ld)a * b / mod) * mod;
        if (val < 0) val += mod;
        if (val >= mod) val -= mod;
        return val;
    }
    ll poww(ll a, ll b) {
        ll val = 1;
        a %= mod;
        while (b > 0) {
            if (b % 2) val = mul(a, val);
            a = mul(a, a);
            b >>= 1;
        }
        return val % mod;
    }
    ll inv(ll a) {
        return poww(a, mod - 2);
    }
}

ll const maxn = 3e5 + 5;


signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("output.txt", "w", stdout);
    ll n; cin >> n;
    vector<ll>a(n + 1);
    for (ll i = 0; i < n + 1; i++) cin >> a[i];
    vector<ll>suf(n + 1);
    suf[n] = a[n];
    for (ll i = n - 1; i >= 0; i--) {
        suf[i] = suf[i + 1] + a[i];
    }
    ll ans = 0;
    ll cur = 1;
    for (ll i = 0; i <= n; i++) {
        ans += cur;
        ll s = suf[i];
        if (cur < a[i]) {
            cout << -1;
            return 0;
        }
        cur -= a[i];
        ll kek = min(cur * 2, s - a[i]) - cur;
        if (kek < 0) {
            cout << -1;
            return 0;
        }
        cur += kek;        
    }
    if (cur != 0) {
        cout << -1;
        return 0;
    }

    cout << ans << endl;
    return 0;
}

/*

*/

Measured memory_bytes: 4736
#include <stdio.h>
#include <stdlib.h>

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

long int binary_search_right(long int list[], long int list_size, long int x){
    long int left, right, mid;
    left = 0;
    right = list_size - 1;

    while (left <= right) {
        mid = (left + right)/2;
        if(list[left] < x && x <= list[right] && right - left == 1){
            return left;
        }else if(list[mid] < x){
            left = mid;
        }
        else{
            right = mid;
        }
    }
    while(1){
        printf("error");
    }
}

long int binary_search_left(long int list[], long int list_size, long int x){
    long int left, right, mid;
    left = 0;
    right = list_size - 1;

    while (left <= right) {
        mid = (left + right)/2;
        if(list[left] <= x && x < list[right]&& right - left == 1){
            return right;
        }else if(list[mid] <= x){
            left = mid;
        }
        else{
            right = mid;
        }
    }
    while(1){
        printf("error");
    }
}

int main(void){
    long int n, i;
    scanf("%d", &n);
    long int a[1000000], b[1000000], c[1000000];
    for(i = 0; i < n; i++){scanf("%d", &a[i]);}
    for(i = 0; i < n; i++){scanf("%d", &b[i]);}
    for(i = 0; i < n; i++){scanf("%d", &c[i]);}

    qsort(a, n, sizeof(long int), compare_int);
    qsort(c, n, sizeof(long int), compare_int);

    long int a_b, b_c, k;
    long int tmp;
    long int ans = 0;
    if(n == 1){
        if(a[0] < b[0] && b[0] < c[0]){
            printf("1\n");
            return 0;
        }else{
            printf("0\n");
            return 0;
        }
    }

    for(i = 0; i < n; i++){
        if(b[i] > a[n - 1]){
            a_b = n;
        }else if(b[i] <= a[0]){
            a_b = 0;
        }else{
            a_b = binary_search_right(a, n, b[i]) + 1;//(条件を満たす最大の配置番号＋１)通りがある
        }

        if(b[i] >= c[n - 1]){
            b_c = 0;
        }else if(b[i] < c[0]){
            b_c = n;
        }else{
            b_c = n - binary_search_left(c, n, b[i]);
        }
        ans = ans +  a_b * b_c;
        //printf("%d %d %d\n", i, a_b, b_c);
    }
    printf("%ld\n", ans);
    return 0;
}

Measured memory_bytes: 4868
n, m = map(int, input().split())
l, r = 0, n-1
for _ in range(m):
    tl, tr = map(int, input().split())
    if tl-1 > l:
        l = tl-1
    if tr-1 < r:
        r = tr-1
print(0 if r < l else r-l+1)

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

int main() {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    int res = a[n - 1] - a[0];
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int N;
string S;
map<char, vector<int>> v;

ll count(int i, char c1, char c2) {
    ll ret = 0;

    for(auto j: v[c1]) {
        if (i >= j) continue;

        auto itk = lower_bound(ALL(v[c2]), j);

        if (itk != v[c2].end()){
            ret += v[c2].end() - itk;

            if(2 * j - i < N && S[2 * j - i] == c2) ret--;
        }
    }

    for(auto j: v[c2]) {
        if (i >= j) continue;

        auto itk = lower_bound(ALL(v[c1]), j);

        if (itk != v[c1].end()){
            ret += v[c1].end() - itk;

            if(2 * j - i < N && S[2 * j - i] == c1) ret--;
        }
    }

    return ret;
}


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    cin >> N;
    cin >> S;

    REP(i, N) {
        v[S[i]].pb(i);
    }

    ll ans = 0;
    REP(i, N) {
        if (S[i] == 'R') ans += count(i, 'G', 'B');
        if (S[i] == 'G') ans += count(i, 'R', 'B');
        if (S[i] == 'B') ans += count(i, 'R', 'G');
    }

    cout << ans << endl;
    
}


Measured memory_bytes: 3696
N = int( input())
s = list( input())
I = ['S', 'W']
Flag = False
for x in I:
    for y in I:
        ANS = ['']*N
        ANS[0] = x
        ANS[-1] = y
        for i in range(N-2):
            if ANS[i] == 'S':
                if s[i] == 'o':
                    ANS[i+1] = ANS[i-1]
                else:
                    if ANS[i-1] == 'S':
                        ANS[i+1] = 'W'
                    else:
                        ANS[i+1] = 'S'
            else:
                if s[i] == 'x':
                    ANS[i+1] = ANS[i-1]
                else:
                    if ANS[i-1] == 'S':
                        ANS[i+1] = 'W'
                    else:
                        ANS[i+1] = 'S'
        if ANS[-2] == 'S':
            if s[-2] == 'o':
                if ANS[-3] == ANS[-1]:
                    pass
                else:
                    continue
            else:
                if ANS[-3] == ANS[-1]:
                    continue
                else:
                    pass
        else:
            if s[-2] == 'o':
                if ANS[-3] != ANS[-1]:
                    pass
                else:
                    continue
            else:
                if ANS[-3] != ANS[-1]:
                    continue
                else:
                    pass
        if ANS[-1] == 'S':
            if s[-1] == 'o':
                if ANS[-2] == ANS[0]:
                    pass
                else:
                    continue
            else:
                if ANS[-2] == ANS[0]:
                    continue
                else:
                    pass
        else:
            if s[-1] == 'o':
                if ANS[-2] != ANS[0]:
                    pass
                else:
                    continue
            else:
                if ANS[-2] != ANS[0]:
                    continue
                else:
                    pass
        print(''.join(ANS))
        Flag = True
        break
    if Flag:
        break
if Flag == False:
    print(-1)

Measured memory_bytes: 5584
import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.List;

public class Main {
    public static void main(String args[]) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int input[]=new int[n];
        for (int i=0;i<n;i++){
            int x=sc.nextInt();
            input[i]=x;
        }
        int max=-1;
        int max2=-1;
        for (int i=0;i<n;i++){
            if (input[i]>=max){
                max2=max;
                max=input[i];
            }else if (input[i]>=max2){
                max2=input[i];
            }
        }
        for (int i:input){
            if (i==max) System.out.println(max2);
            else System.out.println(max);
        }



    }

}



Measured memory_bytes: 103844
#include <stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card {
  char suit;
  int value;
};

struct Card L[MAX/2+2], R[MAX/2+2];

void merge(struct Card A[], int n, int left, int mid, int right) {
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  for(int i=0;i<n1;i++) L[i] = A[left + i];
  for(int i=0;i<n2;i++) R[i] = A[mid  + i];
  L[n1].value = R[n2].value = SENTINEL;
  i = j = 0;
  for(k=left; k<right; k++) {
    if(L[i].value <= R[j].value) {
      A[k] = L[i++];
    } else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(struct Card A[], int n, int left, int right) {
  if(left+1 < right) {
    int mid = (left+right) / 2;
    mergeSort(A,n,left,mid);
    mergeSort(A,n,mid, right);
    merge(A,n,left,mid,right);
  }
}

int partition(struct Card A[], int n, int p, int r) {
  int i, j;
  struct Card t, x;
  x = A[r];
  i = p-1;
  for(j=p; j<r; j++) {
    if(A[j].value <= x.value) {
      i++;
      t=A[i]; A[i]=A[j]; A[j]=t;
    }
  }
  t=A[i+1]; A[i+1]=A[r]; A[r]=t;
  return i+1;
}

void quickSort(struct Card A[], int n, int p, int r) {
  int q;
  if(p<r) {
    q = partition(A,n,p,r);
    quickSort(A,n,p,q-1);
    quickSort(A,n,q+1,r);
  }
}

int main() {
  int n, i, v;
  struct Card A[MAX], B[MAX];
  char S[10];
  int stable = 1;

  scanf("%d", &n);

  for(i=0;i<n;i++) {
    scanf("%s %d",S,&v);
    A[i].suit =  B[i].suit  = S[0];
    A[i].value = B[i].value = v;
  }

  mergeSort(A,n,0,n);
  quickSort(B,n,0,n-1);

  for(i=0;i<n;i++) {
    // マージソートとクイックソートの結果を比べる
    if(A[i].suit != B[i].suit) stable = 0;
  }

  if(stable==1) printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++) {
    printf("%c %d\n",B[i].suit,B[i].value);
  }

  return 0;
}

Measured memory_bytes: 4012
#include <iostream>

using namespace std;

int main()
{
	/*
		ABC131 E問題
		N K
		頂点数NにおけるKの最大値は(N-1)C2
		したがってひとまず maxK = (N-1)(N-2)/2を計算し、Kがそれより大きければ-1を出力
		小さければ M = N-1 + maxK-K を出力。
		1 2
		1 3
		1 4
		.
		.
		.
		1 N
		と出力。
		その後maxK-Kの数だけ
		2 3
		2 4
		.
		.
		2 N
		3 4
		3 5
		.
		.
		3 N
		.
		.
		を出力する。
	*/
	int N, K,maxK;
	cin >> N >> K;

	maxK = (N - 1)*(N - 2) / 2;
	if (K > maxK) {
		cout << -1;
		return 0;
	}

	//Mを出力
	cout << N - 1 + maxK - K << endl;

	//N-1回
	for (int i = 2; i <= N; i++)
		cout << "1 " << i << endl;

	int time = 0;
	//maxK - K 回
	for (int i = 2; i <= N - 1; i++) {
		for (int j = i + 1; j <= N; j++, time++) {
			if (time >= maxK - K)
				break;
			cout << i << " " << j << endl;
		}
		if (time >= maxK - K)
			break;
	}
}

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

using namespace std;

string s, t;

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

	int ans = 0;
	for (unsigned int i = 0; i < s.size(); i++) {
		if (s[i] != t[i]) {
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3844
#include<stdio.h>

int main(){
    int i/*,flag*/;
    float x[4],y[4],a;

    while(1){

        for(i = 0/*,flag = 0*/;i < 4;i++){
            if(scanf("%f%f",&x[i],&y[i]) == EOF){
                /*
                flag = 1;
                break;
                */
                return 0;
            }
        }
        /*
        if(flag){
            flag = 0;
            break;
        }
        */
        /*
        if(x[0] == x[1] && y[2] == y[3]){
            puts("YES");
        }else if(x[2] == x[3] && y[0] == y[1]){
            puts("YES");
        }else if(x[0] == x[1] || x[2] == x[3]){
            puts("NO");
        }else{
            */
            a = (y[1] - y[0]) * (y[3] - y[2]) + (x[1] - x[0]) * (x[3] - x[2]);
            if(a){
                puts("NO");
            }else{
                puts("YES");
            }
        //}
    }

    return 0;
}

Measured memory_bytes: 608
n, k, q = map(int, input().split())
a = [int(input()) for i in range(q)]
point = [k] * n
for i in range(q):
    point[a[i]-1] += 1
for i in range(n):
    ans = point[i] - q
    if ans > 0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 10452
type Seq = [Int]

insertionSortVerbose    :: Seq -> [Seq]
insertionSortVerbose xs = tail $ scanl step xs [0..length xs-1]

step      :: Seq -> Int -> Seq
step es n = let (pre,x:post) = splitAt n es in insertOrderd x pre ++ post
 
insertOrderd      :: Int -> Seq -> Seq
insertOrderd x ts = let (pre,post) = span (< x) ts in pre ++ (x:post)
 
main :: IO () 
main = getContents >>= mapM_ putStrLn.map (unwords.map show).insertionSortVerbose.map read.words.last.lines

Measured memory_bytes: 4008
import numpy as np
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
A = [[int(i) for i in input().split()] for i in range(n)]
B = np.array(b).reshape(m,1)
cnt = 0
for i in range(n):
    x = np.dot(A[i], B)+c
    if x >0:
    	cnt += 1

print(cnt)

Measured memory_bytes: 12428
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    int N;
    Map<String,Integer> map = new TreeMap<String,Integer>();
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.N = sc.nextInt();
    }
    
    //解答処理
    private List<String> solve() {
    	int max = 0;
        List<String> answer = new ArrayList<String>();
        
        for (int i=0; i<N; i++) {
        	String S = sc.next();
        	//キーが既にある場合は値を増やして上書き
        	if (map.containsKey(S)) {
        		map.put(S, map.get(S)+1);
        	} else {
        		map.put(S, 1);
        	}
        }
        
        //最大値の算出
        for (String S : map.keySet()) {
        	max = Math.max(max, map.get(S));
        }
        
        //最大回数のキーをリストに格納
        for (String S : map.keySet()) {
        	if (max == map.get(S)) {
        		answer.add(S);
        	}
        }
        
        return answer;
    }
    
    //出力
    public void show(List<String> answer) {
        for (int i=0; i<answer.size(); i++) {
        	System.out.println(answer.get(i));
        }
    }

}


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

using namespace std;

int64_t solve(int64_t /*n*/, int64_t k,
              std::vector<std::pair<int64_t, int64_t>> as) {
  std::sort(as.begin(), as.end(),
            [](auto& lhs, auto& rhs) { return lhs.first < rhs.first; });
  for (auto& a : as) {
    if (k <= a.second) {
      return a.first;
    }
    k -= a.second;
  }
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int64_t n;
  std::cin >> n;
  int64_t k;
  std::cin >> k;
  std::vector<std::pair<int64_t, int64_t>> as(n);
  for (int i = 0; i < n; i++) {
    std::cin >> as[i].first;
    std::cin >> as[i].second;
  }
  auto const res = solve(n, k, std::move(as));
  std::cout << res << std::endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template


int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    
    ll T1, T2, A1, A2, B1, B2;
    cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
    
    if(T1 * A1 + T2 * A2 == T1 * B1 + T2 * B2) {
        output("infinity");
        return 0;
    }
    if(T1 * A1 + T2 * A2 > T1 * B1 + T2 * B2) {
        swap(A1, B1);
        swap(A2, B2);
    }
    if(A1 < B1) {
        output(0);
        return 0;
    }
    ll diff = (T1 * B1 + T2 * B2) - (T1 * A1 + T2 * A2);
    
    ll x = (T1 * A1 - T1 * B1) / diff;
    if((T1 * A1 - T1 * B1) % diff == 0) output(x * 2);
    else output(x * 2 + 1);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,r;
  cin>>n;
  r=n%10;
  if(r==2||r==4||r==5||r==7||r==9)
  cout<<"hon"<<endl;
  else if(r==0||r==1||r==6||r==8)
  cout<<"pon"<<endl;
  else if(r==3)
  cout<<"bon"<<endl;
} 


Measured memory_bytes: 3644
N=int(input())+1
t,x,y,r=[0]*N,[0]*N,[0]*N,1
N-=1
for i in range(N):
    i+=1
    t[i],x[i],y[i]=map(int,input().split())

def a(t,x,y):
    return (x+y<=t)*(1-(x+y-t)%2)

for i in range(N):
    r*=a(t[i+1]-t[i],abs(x[i+1]-x[i]),abs(y[i+1]-y[i]))
print(['No','Yes'][r])

Measured memory_bytes: 17372
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<utility>

using namespace std;

typedef long long int64;

int main(void){
    int64 A,B;
    cin>>A>>B;
    if((A+B)%2){
        cout<<"IMPOSSIBLE"<<endl;
    }else{
        cout<<(A+B)/2<<endl;
    }
    return 0;
}

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

#define ll long long
#define pb push_back
#define bit(a , b) (((a)>>(b))&1)

const int maxn = 1e5 + 20;

pair<vector<int> , int> solve(ll n)
{
	vector<int> ans;
	if(n == 1)
	{
		ans.pb(1);
		ans.pb(1);
		return {ans , 1};
	}

	if(n == 2)
	{
		ans.pb(1);
		ans.pb(50);
		ans.pb(50);
		ans.pb(1);

		return {ans , 2};
	}

	vector<int> tmp;
	int F = 0;

	if(n % 2 == 1)
	{
		auto shit = solve(n / 2);
		F = shit.second;
		tmp = shit.first;
	}
	else
	{
		auto shit = solve(n / 2 - 1);
		F = shit.second;
		tmp = shit.first;
	}

	int mx1 = 0 , mx = 0;
	for(auto x : tmp)
	{
		if(x < 50)
			mx1 = max(mx1 , x);
		mx = max(mx , x);
	}

	int ahhh = F;

	for(int i = 0; i < F; i++)
		ans.pb(tmp[i]);
	
	ans.pb(mx1 + 1);
	F++;

	if(mx < 50)
		mx = 49;

	if(n % 2 == 0)
	{
		F++;
		ans.pb(mx + 1);
		ans.pb(mx + 1);
	}

	for(int i = ahhh; i < (int)tmp.size(); i++)
		ans.pb(tmp[i]);

	ans.pb(mx1 + 1);

	return {ans , F};
}

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

	ll n;
	cin >> n;

	vector<int> ans = solve(n).first;

	cout << ans.size() << endl;
	for(auto x : ans)
		cout << x << " ";
	cout << endl;

}










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

#define ll long long
#define ar array

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

	int n, r;
	cin >> n >> r;
	if(n<10)
		r+=100*(10-n);
	cout << r;
}


Measured memory_bytes: 256
#include <functional>
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#include <string>
#include <cstring>
#include <math.h>
using namespace std;


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

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	int i, N, c[4] = { 0,0,0,0 };
	string s;
	cin >> N;
	for (i = 0; i < N; ++i) {
		cin >> s;
		if (s == "AC") {
			++c[0];
		}
		else if (s == "WA") {
			++c[1];
		}
		else if (s == "TLE") {
			++c[2];
		}
		else {
			++c[3];
		}
	}
	cout << "AC x " << c[0] << endl;
	cout << "WA x " << c[1] << endl;
	cout << "TLE x " << c[2] << endl;
	cout << "RE x " << c[3] << endl;
}

Measured memory_bytes: 3600
package main

import "fmt"

func main() {
	var N, M int
	fmt.Scan(&N, &M)
	roads := make([][]int, N+1)
	for i := 1; i < N+1; i++ {
		roads[i] = make([]int, N+2)
	}
	for i := 0; i < M; i++ {
		var a, b int
		fmt.Scan(&a, &b)
		roads[a][b]++
		roads[b][a]++
	}
	for i := 1; i < N+1; i++ {
		sum := 0
		for j := 1; j < N+1; j++ {
			sum += roads[i][j]
		}
		fmt.Println(sum)
	}
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		try (Scanner sc = new Scanner(System.in)) {
			int N = Integer.parseInt(sc.next());
			int M = Integer.parseInt(sc.next());
			int C = Integer.parseInt(sc.next());
			int[] B = new int[M];
			for(int i = 0; i < M; i++) {
				B[i] = Integer.parseInt(sc.next());
			}
			int[][] A = new int[N][M];
			for(int i = 0; i < N; i++) {
				for(int j = 0; j < M; j++) {
					A[i][j] = Integer.parseInt(sc.next());
				}
			}
			
			int count = 0;
			
			for(int i = 0; i < N; i++) {
				int ret = 0;
				for(int j = 0; j < M; j++) {
					ret += A[i][j] * B[j]; 
				}
				if(ret + C > 0) {
					count++;
				}
			}
			
			
			System.out.println(count);
		} // Scanner Close
	}
}

Measured memory_bytes: 23124
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] es = new int[n][n];
        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1;
            int b = sc.nextInt() - 1;
            es[a][b]++;es[b][a]++;
        }
        for (int i = 0; i < n; i++) {
            int each = 0;
            for (int j =0; j < n; j++) {
                if (es[i][j] != 0) each += es[i][j];
            }
            System.out.println(each);
        }
    }
}


Measured memory_bytes: 21844
#include "bits/stdc++.h"
using namespace std;

int main(void) {
    int N, A, B;
    cin >> N >> A >> B;
    string str;
    string str1;
    int sum;
    int ans = 0;
    for (int i = 1; i <= N; ++i) {
        str = to_string(i);
        sum = 0;
        for (int j = 0; j < str.length(); ++j) {
            str1 = { str[j] };
            sum += atoi(str1.c_str());
        }
        if (sum >= A && sum <= B) {
            ans += i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
using ll = long long;
using namespace std;

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

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

int main(){
    int N,L,MAX=0,sum=0;
    cin >>N;
    for (int i = 0; i < N; i++){
        cin >> L;
        sum += L;
        MAX=max(MAX,L);

    }
    if(MAX < (sum-MAX))cout << "Yes" <<endl;
    else cout << "No" <<endl;
    
    //cout << ans <<endl;

    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	int n,a=0,b=0,c;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>c;
		if(c%2==1)a++;
		else b++;
	}
	if(a%2==0)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<cstring>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
const int MAXN=1e5+5;
int read()
{
    int s=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
    return s*f;
}
int main()
{
    string s,t;
    while(cin>>s>>t)
    {
        cout<<t<<s<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<queue>
#include<cmath>
#include<cstdlib>
#define LL long long
#define LD long double
using namespace std;
const int NN=500 +117;
const int MM= +117;
int read(){
	int fl=1,x;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if(c=='-'){fl=-1;c=getchar();}
	for(x=0;c>='0'&&c<='9';c=getchar())
		x=(x<<3)+(x<<1)+c-'0';
	return x*fl;
}
void open(){
	freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
}
void close(){
	fclose(stdin);
	fclose(stdout);
}


int m,n;
LL v[2][NN][NN]={};
LL dp[2][NN][NN]={};
void upd(LL &x,LL y){
	x=max(x,y);
}
LL vof(int kd,int l,int r,int x){
	return v[kd][r][x]-v[kd][l-1][x];
}
int main(){
	//open();
	n=read();
	memset(dp,-60,sizeof dp);
	LL sum=0;
	for(int i=1;i<=n;++i){
		for(int j=1;j<=n;++j){
			if(i==j)continue;
			LL x=read();
			sum+=x;
			if(i<j){
				v[1][i][j]=x;
			}
			else v[0][j][i]=x;
		}
	}
	for(int i=1;i<=n;++i){
		for(int j=0;j<=n;++j){
			v[1][i][j]+=v[1][i-1][j];
			v[0][i][j]+=v[0][i-1][j];
		}
	}
	dp[0][0][0]=0;
	int now=0;
	for(int i=1;i<=n;++i){
		now^=1;
		for(int j=0;j<=i;++j){
			for(int l=0;l<=i;++l){
				dp[now][j][l]=0;
			}
		}
		for(int j=0;j<i;++j){
			for(int l=j;l<i;++l){
				upd(dp[now][j][l],dp[now^1][j][l]);
				upd(dp[now][l][i],dp[now^1][j][l]);
			}
		}
		for(int j=0;j<i;++j){
			for(int l=j;l<=i;++l){
				dp[now][j][l]+=vof(0,j+1,i,i+1)+vof(1,1,l,i+1);
			}
		}
	}
	LL ans=0;
	for(int j=0;j<n;++j){
		for(int l=j;l<=n;++l){
			upd(ans,dp[now][j][l]);
		}
	}
	ans=sum-ans;
	printf("%lld\n",ans);
	close();
	return 0;
}

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

using namespace std;

constexpr auto MOD=1000000007LL;

// // a^n mod m を計算する(繰り返し二乗法,二分累乗法:O(logn)) (再帰版)
// long long modpow(long long a,long long n){return n?modpow(a*a%MOD,n/2)*(n%2?a:1)%MOD:1;}

// MOD考慮power関数
inline long long modpow(long long a,long long n)
{
	long long ret=1;
	for(long long i=0;i<n;i++){
		ret*=a;
		ret%=MOD;
	}
	return ret;
}

// gcd関数
// inline long long gcd(long long a, long long b)
// {
// 	if(a<b) swap(a,b);
// 	if(a%b==0) return b;
// 	else return gcd(b,a%b);
// }

int main(){
	int n;
	cin>>n;
	long long zero = 0;
	map<pair<long long, long long>,vector<int>> bad;
	while(n--){
		long long x,y;
		cin >> x >> y;

		// 両方0ならカウントしてcontinue
		if(x==0 && y==0){
			zero++;
			continue;
		}
		
		// 既約分数計算
		long long g = gcd(x, y);
		x /= g;
		y /= g;
		
		// 符号情報を統一
		if(y < 0) x = -x, y = -y;
		if(y==0 && x<0) x = -x, y = -y;
		
		int rotate90 = (x <= 0);
		if(rotate90){ 
			swap(x, y);
			y = -y;
		}

		if(bad.count({x, y}) == 0) bad[{x,y}] = {0, 0};
		bad[{x, y}][rotate90]++;
	}

	// 組み合わせ計算
	long long ans = 1;
	for(auto x:bad){
		vector<int> c = x.second;
		ans *= (modpow(2, c[0]) - 1) + (modpow(2, c[1]) - 1) + 1;
		ans %= MOD;
	}

	ans += zero - 1;
	ans = (ans + MOD) % MOD;
	cout<< ans <<endl;
}


Measured memory_bytes: 25320
def solve(string):
    _, *l = map(int, string.split())
    l.sort()
    ans = 0
    for i, l0 in enumerate(l[:-2]):
        for j, l1 in enumerate(l[i + 1:-1]):
            if l0 == l1:
                continue
            for l2 in l[i + j + 2:]:
                if l1 == l2:
                    continue
                if l2 < l0 + l1:
                    ans += 1
                else:
                    break
    return str(ans)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Measured memory_bytes: 8972
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int ans = 0;
		for (int i=1; i<=5; i++) {
			if (0 == sc.nextInt()) {
				ans = i;
				break;
			}
		}

		System.out.println(ans);
		sc.close();
	}

}

Measured memory_bytes: 35708
#include <bits/stdc++.h>
using namespace std;
struct coma{
    int id;
    int l;
    int u;
    int r;
    int d;
};
void solve(vector<int>&anss,vector<coma>comas){
    if(comas.empty())return;
    else{
        pair<int,int>ru=make_pair(1000,1000);
        int ruid=-1;
        for(int i=0;i<comas.size();++i){
            if(ru>make_pair(comas[i].r,comas[i].u)){
                ru=make_pair(comas[i].r,comas[i].u);
                ruid=i;
            }
        }
        anss.push_back(comas[ruid].id);
        coma startcoma(comas[ruid]);
        const int y=startcoma.d;
        int ar=startcoma.r;
        int al;
        int x=startcoma.r-1;
        vector<bool>ups(comas.size());
        while(true){
            x++;
            bool flag=false;
            for(int i=0;i<comas.size();++i){
                if(comas[i].r==x&&comas[i].d>y&&comas[i].u<y){
                    al=x;
                    flag=true;
                    break;
                }else{

                }
            }
            if(flag)break;
            if(x==502){
                al=502;
                break;
            }
        }
        for(int i=0;i<comas.size();++i){
            if(comas[i].d<=y&&comas[i].l<=al&&comas[i].r>=ar){
                ups[i]=true;
            }else{
                ups[i]=false;
            }
        }
        {
            vector<coma>a,b;
            for(int i=0;i<comas.size();++i){
                if(i==ruid)continue;
                if(ups[i])a.push_back(comas[i]);
                else b.push_back(comas[i]);
            }
            solve(anss,a);
            solve(anss,b);
        }
    }
}
int main(){
    bool flag=false;
    while(true){
        int N;cin>>N;
        if(!N)break;

        if(flag)cout<<endl;
        else flag=true;
        vector<coma>comas;
        for(int i=0;i<N;++i){
            int l,d,r,u;cin>>r>>u>>l>>d;
            comas.push_back(coma{i,l,u,r,d});
        }
        vector<int>anss;
        solve(anss,comas);
        vector<int>nums(N);
        for(int i=0;i<N;++i){
            nums[anss[i]]=i;
        }
        for(int i=0;i<anss.size();++i){
            cout<<nums[i]+1<<endl;
        }
    }
    return 0;

}

Measured memory_bytes: 3048
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(N)]

ans = 0
for i in range(N):
    a = A[i]
    tmp = C
    for j in range(M):
        tmp += a[j] * B[j]
    if tmp > 0:
        ans += 1
print(ans)


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

#define MAXN (100010)

int n;
int a[MAXN];
int dp[2][MAXN];

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; ++ i){
		scanf("%d", a + i);
	}
	dp[0][1] = dp[1][1] = 1; //0 up ; 1 down
	for(int i = 2; i <= n; ++ i){
		dp[0][i] = std::min(dp[0][i - 1], dp[1][i - 1]) + 1;
		dp[1][i] = std::min(dp[0][i - 1], dp[1][i - 1]) + 1;
		if(a[i - 1] <= a[i]){
			dp[0][i] = std::min(dp[0][i], dp[0][i - 1]);
		}
		if(a[i - 1] >= a[i]){
			dp[1][i] = std::min(dp[1][i], dp[1][i - 1]);
    	}
	}
	printf("%d\n", std::min(dp[0][n], dp[1][n]));
	
	/*
	int ans = 1;
	for(int i = 3; i <= n; ++ i){
		if((a[i] >= a[i - 1] && a[i - 1] >= a[i - 2]) || (a[i] <= a[i - 1] && a[i - 1] <= a[i - 2])){
			continue;
		}
		i ++;
		ans ++;
	}
	printf("%d\n", ans);
	*/
	return 0;
}

Measured memory_bytes: 1408
#include <iostream>

using namespace std;

int main(){
    int n,m;
    cin >> n >> m;
    long int cases=0;
    if((n-m)*(n-m)<=1){
        cases=1;
        for(int i=n;i>=1;i--){
            cases*=i;
            cases=cases%1000000007;
        }
        for(int i=m;i>=1;i--){
            cases*=i;
            cases=cases%1000000007;
        }
        if(n-m==0){
            cases*=2;
            cases=cases%1000000007;
        }
    }
    cout << cases << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
#ABC97 C

import sys
import math
import bisect
import time
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

f = defaultdict(lambda : 0)
s = input()
k = I()
n = len(s)
for i in range(1,k+1):
    for j in range(n-i+1):
        f[s[j:j+i]] = 1
f = sorted(f.items())
print(f[k-1][0])


Measured memory_bytes: 6128
n = int(input())
h = list(map(int, input().split()))
before = h[0]
for i in range(1, n):
    if h[i] == before:
        continue
    else:
        h[i] -= 1
        if h[i] >= before:
            before = h[i]
            continue
        else:
            print("No")
            exit()

print("Yes")

Measured memory_bytes: 15020
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

#define ll  long long
#define PR  pair<int, int>

const int N = 3e5 + 10;
const int MOD = 1e9 + 7;
const long long INF = 5e18;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    int pos = 0, neg = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] > 0) {
            pos = 1;
        } else if (a[i] < 0) {
            neg = 1;
        } else {
            continue;
        }
    }
    vector<PR> ans;
    if (pos && neg) {
        int mx = -1e9, mn = 1e9, pmx = 0, pmn = 0;
        for (int i = 0;  i < n; i++) {
            if (mx < a[i]) {
                mx = a[i];
                pmx = i;
            }
            if (mn > a[i]) {
                mn = a[i];
                pmn = i;
            }
        }
        if (abs(mx) >= abs(mn)) {
            neg = 0;
            for (int i = 0; i < n; i++) {
                ans.push_back({pmx + 1, i + 1});
                a[i] += a[pmx];
            }
        } else {
            for (int i = 0; i < n; i++) {
                ans.push_back({pmn + 1, i + 1});
                a[i] += a[pmn];
            }
        }
    }
    if (neg) {
        for (int i = n - 2; i >= 0; i--) {
            while (a[i] > a[i + 1]) {
                int mn = 1e9, pos = 0;
                for (int j = 0; j < n; j++) {
                    if (mn > a[j]) {
                        mn = a[j];
                        pos = j;
                    }
                }
                ans.push_back({pos + 1, i + 1});
                a[i] += a[pos];
            }
        }
    } else {
        for (int i = 1; i < n; i++) {
            while (a[i] < a[i - 1]) {
                int mx = -1e9, pos = 0;
                for (int j = 0; j < n; j++) {
                    if (mx < a[j]) {
                        mx = a[j];
                        pos = j;
                    }
                }
                ans.push_back({pos + 1, i + 1});
                a[i] += a[pos];
            }
        }
    }
//    for (int i = 0; i < n; i++) {
//        cout << a[i] << " ";
//    }
//    cout << '\n';
    cout << ans.size() << '\n';
    for (auto i : ans) {
        cout << i.first << " " << i.second << '\n';
    }
    return 0;
}


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

int main()
{
  int N;
  cin >> N;
  vector<long long int> a(N);
  for (int i = 0; i < N; i++)
  {
    cin >> a[i];
  }
  long long int ans = 0;
  map<long long int, int> mp;
  for (int i = 0; i < N; i++)
  {
    mp[a[i]]++;
  }
  for (auto itr = mp.begin(); itr != mp.end(); itr++)
  {
    if (itr->first <= itr->second)
    {
      ans += itr->second - itr->first;
    }
    else
    {
      ans += itr->second;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 7040
#include <bits/stdc++.h> 
using namespace std;
 
int INF = 0x3f3f3f3f;
const int mod = 1000000007;
 
 
 
int main(){
	int prime[1005];
	long long int i,j;
	for(i=1;i<=1000;i++){
		prime[i]=1;
	}
	prime[1]=0;
	prime[2]=1;
	for(i=2;i<=1000;i++){
		if(prime[i]==1){
			for(j=2;j*i<=1000;j++){
				prime[j*i]=0;
			}
		}
	}
	long long int n;
	cin>>n;
	int num[1005];
	long long int namae;
	memset(num,0,sizeof(num));
	for(i=2;i<=n;i++){
		if(prime[i]==1){
			num[i]+=1;
		}else{
			for(j=2;j<=i;j++){
				namae = i;
				while(prime[j]==1 && namae%j==0){
					num[j]+=1;
					namae=namae/j;
				}
			}
		}
	}
	long long int ans=1;
	for(i=1;i<=n;i++){
		ans *= (num[i]+1);
		ans = ans%mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(long long x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl

#define all(x) x.begin(),x.end()
typedef pair<long long,long long> P;
typedef pair<long long,P> PP;
long long dp[55][2];
long long n;
long long a[55];
long long p;
int main()
{
	cin>>n>>p;
	rep(i,n)cin>>a[i];
	dp[0][0]=1;
	rep(i,n)
	{
		if(a[i]%2==0)
		{
			dp[i+1][0]=2*dp[i][0];
			dp[i+1][1]=2*dp[i][1];
		}
		else
		{
			dp[i+1][0]=dp[i][0]+dp[i][1];
			dp[i+1][1]=dp[i][1]+dp[i][0];
		}
	}
	cout<<dp[n][p]<<endl;
	return 0;
}

Measured memory_bytes: 256