akhauriyash/Code-Regression huggingface dataset:
# -*- coding:utf-8 -*-

def solve():
    N, M, C = list(map(int, input().split()))
    B = list(map(int, input().split()))

    ans= 0
    for i in range(N):
        A = list(map(int, input().split()))
        sum = C
        for j in range(M):
            sum += A[j]*B[j]
        if sum > 0:
            ans += 1

    print(ans)

if __name__ == "__main__":
    solve()


Measured memory_bytes: 3060
class PERM_COMB_MOD():
    # http://drken1215.hatenablog.com/entry/2018/06/08/210000
    def __init__(self, max_n=510000, mod=10**9+7):
        self.fac = [0]*max_n
        self.finv = [0]*max_n
        self.inv = [0]*max_n
        self.fac[0] = self.fac[1] = 1
        self.finv[0] = self.finv[1] = 1
        self.inv[1] = 1
        self.max = max_n
        self.mod = mod
        self._maesyori()

    def _maesyori(self):
        for i in range(2,self.max):
            self.fac[i] = self.fac[i-1] * i % self.mod
            self.inv[i] = self.mod - self.inv[self.mod % i] * (self.mod // i) % self.mod
            self.finv[i] = self.finv[i-1] * self.inv[i] % self.mod

    def perm(self, n, k):
        if n < k : return 0
        if n < 0 or k < 0:return 0
        return self.fac[n] * self.finv[n-k] % self.mod % self.mod

    def comb(self, n, k):
        if n < k : return 0
        if n < 0 or k < 0:return 0
        return self.fac[n] * (self.finv[k] * self.finv[n-k] % self.mod) % self.mod

    def h(self, n, k):
        if n == k == 0:
            return 1
        return self.comb(n+k-1, k)

PCM = PERM_COMB_MOD(3*10**6+100)
mod = 10**9+7

r1,c1,r2,c2 = map(int, input().split())

def sq(R,L):
    R+=1
    L+=1
    ret = 0
    for i in range(R):
        ret += PCM.comb(L+i, i+1)
    ret %= mod
    return ret
ans = sq(r2, c2) - sq(r2, c1-1) - sq(r1-1, c2) + sq(r1-1,c1-1)
ans %= mod
print(ans)

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

using namespace std;
struct node{
    int b;int c;
};
bool cmp(node&a,node&b)
{
    return a.c>b.c;
}
int main()
{
    vector<node>vec;
    vec.clear();
    int  a[100005];
    int n,m;
    cin>>n>>m;
    int pos=0;
    for(int i=0;i<n;i++)
        scanf("%d",&a[i]);
    sort(a,a+n);
    node ex;
    for(int i=0;i<m;i++)
    {
        scanf("%d %d",&ex.b,&ex.c);
        vec.push_back(ex);
    }
    sort(vec.begin(),vec.end(),cmp);
    for(int i=0;i<m;i++)
    {
        if(vec[i].c>a[pos]&&pos<n){
        int p=pos;
        while(p<pos+vec[i].b&&vec[i].c>a[p]&&p<n)
            p++;
        for(int j=pos;j<p;j++)
            {a[j]=vec[i].c;}
        pos=p;}
        else break;
    }
    long long res=0;
    for(int i=0;i<n;i++)
        {res+=a[i];
        }
    cout<<res<<endl;
}

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

pair<int, int> p[3004];
bool a[MAX][MAX];

bool s(int n){
	if(0 <= n && n <= 5000)return 1;
	return 0;
}

int main(){
	int n, t1, t2;
	while(cin >> n, n){
		fill((int*)a, (int*)(a+MAX), 0);
		for(int i = 0;i < n;i++){
			cin >> t1 >> t2;
			p[i].first = t1;
			p[i].second = t2;
			a[t2][t1] = 1;
		}
		
		int ans = 0;
		int p1[4][2], f1, f2;
		for(int i = 0;i < n;i++){
			for(int j = 0;j < n;j++){
				f1 = f2 = 0;
				t1 = p[i].first-p[j].first;
				t2 = p[i].second-p[j].second;
				if(!t1 && !t2)continue;
				int x1=p[i].first-t2,y1=p[i].second+t1,x2=p[j].first-t2,y2=p[j].second+t1;
				int x3=p[i].first-t2,y3=p[i].second+t1,x4=p[j].first+t2,y4=p[j].second-t1;
				if(s(x1)&&s(y1)&&a[y1][x1]&&s(x2)&&s(y2)&&a[y2][x2])
				ans = max(ans, t1*t1+t2*t2);
				if(s(y3)&&s(x3)&&a[y3][x3]&&s(y4)&&s(x4)&&a[y4][x4])
				ans = max(ans, t1*t1+t2*t2);
			}
		}
		//cout << endl;
		//for(int i = 0;i < 4;i++)cout << (i>>1&1) << " " << (i&1) << endl;
		cout << ans << endl;
	}
	return 0;
}

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

int main()
{
    int n, ans = 0;
    string s;
    cin >> n >> s;
    rep(i, n - 2)
    {
        if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
            ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
using namespace std;

#define MAX 100001

int parent(int a){return a/2;}
int left(int a){return 2*a;}
int right(int a){return 2*a+1;}

int main(){
    int H, i, A[MAX+1];
    
    cin >> H;
    for(i=1 ; i<=H ; i++){
        cin >> A[i];
    }
    
    for(i=1 ; i<=H ; i++){
        printf("node %d: key = %d, ", i, A[i]);
        if(parent(i) >= 1){printf("parent key = %d, ", A[parent(i)]);}
        if(left(i) <= H){printf("left key = %d, ", A[left(i)]);}
        if(right(i) <= H){printf("right key = %d, ", A[right(i)]);}
        printf("\n");
    }
    
    return 0;
}


Measured memory_bytes: 3240
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define rep1(i,n)for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=(int)(n)-1;0<=i;i--)
#define rrep1(i,n) for(int i=(int)(n);1<=i;i--)

#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 

#define pcount __builtin_popcount
#define SZ(x) ((int)(x).size())
#define LEN(x) ((int)(x).length())

#define dump(x)  cerr << #x << " = " << (x) << endl;

#define endl "\n"

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;}

typedef long long lint;

using namespace std;
int main(){
	string s,t,u;
	cin>>s>>t>>u;
	cout<<char(s.at(0)+'A'-'a')<<char(t.at(0)+'A'-'a')<<char(u.at(0)+'A'-'a')<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define mod 1000000007
#define MaxN 2002
using namespace std;

vector<long long> dp(MaxN,-1);

long long f(long long x)
{
    if(dp[x] != -1) return dp[x];
    long long ret = 0;
    for(int i = 3; i <= x; i++)
    {
        ret += f(x-i);
        if(ret >= mod)
            ret -= mod;
    }
    dp[x] = ret;
    return dp[x];
}

int main()
{
    int s;
    cin >> s;
    dp[0] = 1; dp[1] = 0; dp[2] = 0; dp[3] = 1; 
    cout << f(s) << endl;

}


Measured memory_bytes: 3660
H, W = map(int, input().split())

if H % 3 == 0 or W % 3 == 0:
    print(0)
    exit()

ans2_1 = 10 ** 10
ans2_2 = 10 ** 10
ans2_3 = 10 ** 10
ans2_4 = 10 ** 10
ans3_1 = 10 ** 10
ans3_2 = 10 ** 10
ans3_3 = 10 ** 10
ans3_4 = 10 ** 10

ans1 = W
ans4 = H

h1 = (H + 2) // 3
h2 = H - h1
s1 = h1 * W
if W % 2 == 0:
    ans2_1 = abs(s1 - h2 * (W // 2))
else:
    s2 = h2 * (W // 2 + 1)
    s3 = h2 * (W // 2)
    ans2_2 = max(s1, s2, s3) - min(s1, s2, s3)

h1 = H // 3
h2 = H - h1
s1 = h1 * W
if W % 2 == 0:
    ans2_3 = abs(s1 - h2 * (W // 2))
else:
    s2 = h2 * (W // 2 + 1)
    s3 = h2 * (W // 2)
    ans2_4 = max(s1, s2, s3) - min(s1, s2, s3)

w1 = (W + 2) // 3
w2 = W - w1
s1 = H * w1
if H % 2 == 0:
    ans3_1 = abs(s1 - w2 * (H // 2))
else:
    s2 = w2 * (H // 2 + 1)
    s3 = w2 * (H // 2)
    ans3_2 = max(s1, s2, s3) - min(s1, s2, s3)

w1 = W // 3
w2 = W - w1
s1 = w1 * H
if H % 2 == 0:
    ans3_3 = abs(s1 - w2 * (H // 2))
else:
    s2 = w2 * (H // 2 + 1)
    s3 = w2 * (H // 2)
    ans3_4 = max(s1, s2, s3) - min(s1, s2, s3)

print(int(min(ans1, ans2_1, ans2_2, ans2_3, ans2_4, ans3_1, ans3_2, ans3_3, ans3_4, ans4)))


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

/**
 * Created by paz on 17-3-12.
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int n[] = new int[N];
        for(int i = 0; i < N; i++) {
            n[i] = sc.nextInt();
        }
        Arrays.sort(n);
        int s = 0;
        long sum = 0;
        for(int i = 0; i < N - 1; i++) {
            sum += n[i];
            if(sum * 2 < n[i+1]) {
                s = i + 1;
            }
        }
        System.out.println(N - s);
    }
}


Measured memory_bytes: 50816
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    val c = sc.nextInt()
    println(problem093c(a, b, c))
}

fun problem093c(a: Int, b: Int, c: Int): Int {
    val list = listOf(a, b, c).sorted().toMutableList()
    var count = 0
    while (!list.all { it == list[2] }) {
        when {
            list[1] != list[2] -> {
                list[0]++
                list[1]++
            }
            list[2] - list[0] >= 2 -> {
                list[0] += 2
            }
            else -> {
                count++
                list[0]++
            }
        }
        count++
    }
    return count
}

Measured memory_bytes: 34036
def helper(n,m,x,y,X,Y):
	for i in range(x+1,y+1):
		if all(n<i for n in X) and all(n>=i for n in Y):
			return "No War"
	return "War"

n,m,x,y=map(int,raw_input().split(' '))
X = map(int,raw_input().split(' ')) 
Y = map(int,raw_input().split(' '))
print helper(n,m,x,y,X,Y)

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

#define N_MAX 100

void
print_array(int *a, int n)
{
	int i;

	for (i = 0; i < n; i++)
		printf("%d%s", a[i], i + 1 < n ? " " : "");
	printf("\n");
}

int
insertion_sort(int *a, int n)
{
	int i, j, v;
	for (i = 1; i < n; i++) {
		v = a[i];
		j = i - 1;
		while (0 <= j && v < a[j]) {
			a[j + 1] = a[j];
			j--;
		}
		a[j + 1] = v;
		print_array(a, n);
	}
}

int main(void)
{
	int p0, i, n = 0;
	int a[N_MAX];
	char *p;

	scanf("%d", &p0);

	if (p0 < 1 || N_MAX < p0)
		return 1;

	while (n < p0)
		scanf("%d", a + n++);

	print_array(a, n);
	insertion_sort(a, n);

	return 0;
}



Measured memory_bytes: 2040
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

auto & in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;


class union_find
{
private:
	std::vector<int>parent;
	std::vector<int>rank;
	std::vector<int>size;
public:
	union_find(int n)
	{
		parent.resize(n);
		rank.resize(n);
		size.resize(n);
		for (int i = 0; i < n; ++i)
		{
			parent[i] = i;
			rank[i] = 0;
			size[i] = 1;
		}
	}
	void unite(int x, int y)
	{
		int xr = find(x);
		int yr = find(y);
		if (xr == yr) {
			return;
		}

		//yrを新しい親に
		if (rank[xr] > rank[yr])
		{
			std::swap(xr, yr);
		}
		if (rank[xr] == rank[yr]) {
			++rank[yr];
		}
		size[yr] += size[xr];
		parent[xr] = yr;
	}
	int find(int x)
	{
		if (parent[x] == x)
		{
			return x;
		}
		else
		{
			return parent[x] = find(parent[x]);
		}
	}
	bool check(int x, int y)
	{
		return find(x) == find(y);
	}
	int getsize(int x) {
		return size[find(x)];
	}
};


int64_t N, M, Q;
int32_t A[200000];
int32_t B[200000];
int32_t T[200000];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N >> M >> Q;
	union_find single(N + 10);
	for (int i = 0; i < Q; i++)
	{
		in >> A[i] >> B[i] >> T[i];//--A[i]; --B[i];
	}
	for (int i = 0; i < Q; i++)
	{
		if (T[i] == 0) {
			single.unite(A[i], B[i]);
		}
	}
	bool T1find = false;
	for (int i = 0; i < Q; i++)
	{
		if (T[i] == 1) {
			T1find = true;
			if (single.check(A[i], B[i])) {
				out << "No" << endl;
				return 0;
			}
		}
	}


	int nnn = 0;
	int64_t needM = 0, maxM = 0;
	for (int i = 0; i < N; i++)
	{
		if (single.find(i) == i) {
			++nnn;
			needM += single.getsize(i) - 1;
		}
	}
	assert(needM == N - nnn);
	maxM = needM + int64_t(nnn) * int64_t(nnn - 1) / 2;
	if ((maxM < int64_t(M))) {
		out << "No" << endl;
		return 0;
	}

	if (T1find) {
		if (nnn < 3) {
			out << "No" << endl;
			return 0;
		}
	}
	else {
		--needM;
	}
	needM += nnn;
	if (M < needM) {
		out << "No" << endl;
		return 0;
	}


	out << "Yes" << endl;

	return 0;
}
#endif


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define rep(i,l,r) for(int i = (int)l;i<(int)r;i++)
#define td(v) v.begin(),v.end()
//#define M   1000000007 // 1e9 + 7
#define MAXN 100100
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
	
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);

}

int dp[MAXN];
int h[MAXN];
int32_t main(){
	fastio;
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=n;i++){
		dp[i] = 1e18;
		cin>>h[i];
	}
	dp[1]=0;
	dp[0] = 1e18;
	for(int i=2;i<=n;i++){
		for(int j=1;j<=k;j++){
			if(i-j>=1){
				dp[i] = min(dp[i],dp[i-j] + abs(h[i]-h[i-j]));
			}
		}
	}
	cout<< dp[n]<<endl;
	
	
	
}

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

typedef long long ll;

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


Measured memory_bytes: 640
N,K = map(int, input().split())
#余りの分布
L = [0]*(K)

for i in range(1, N+1):
    L[i%K] += 1
ans = 0
for a in range(K):
    b = (K-a)%K
    c = (K-a)%K
    if (b+c)%K==0:
        ans = ans + L[a]*L[b]*L[c]
print(ans)

Measured memory_bytes: 4596
#include<bits/stdc++.h>
using namespace std;
int n,a[200005],z[200005],f[200005],zt,ft,zr;long long k,l,r;
inline int chck(long long v)
{
	long long cnt=0;
	if(v>=0)
	{
		cnt=1ll*zr*(zt+ft)+1ll*zt*ft+1ll*zr*(zr-1)/2;
		for(int i=1;i<=zt;i++) cnt+=upper_bound(z+i+1,z+zt+1,v/z[i])-z-1-i;
		for(int i=1;i<=ft;i++) cnt+=upper_bound(f+i+1,f+ft+1,v/f[i])-f-1-i;
	}
	else
	{
		v=-v;
		for(int i=1;i<=ft;i++) cnt+=z+zt+1-lower_bound(z+1,z+zt+1,v/f[i]+!!(v%f[i]));
	}
	return cnt>=k;
}
int main()
{
	scanf("%d%lld",&n,&k),zt=ft=zr=0,r=(long long)1e18,l=-r;
	for(int i=1;i<=n;i++) scanf("%d",a+i);
	for(int i=1;i<=n;i++) if(a[i]>0) z[++zt]=a[i];else if(a[i]<0) f[++ft]=-a[i];else zr++;
	sort(z+1,z+zt+1),sort(f+1,f+ft+1);
	while(l<r) {if(chck((l+r)>>1)) r=(l+r)>>1;else l=((l+r)>>1)+1;}
	return printf("%lld\n",l),0;
}

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

using namespace std;

const int N = 1e6 + 9;

int n, a[N], can[N];

main(){
    cin>> n;
    can[0] = 1;
    for(int i = 1; i <= n; i++){
        cin>> a[i];
        for(int j = 1e4; j >= 0; j--){
            if(can[j] == 1)can[j + a[i]] = 1;
        }
    }
    for(int j = 1e4; j >= 0; j--){
        if(can[j] == 1 && j % 10 != 0){
            cout<< j;
            return 0;
        }
    }
    cout<< 0;
}

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

int main(){
  string s;
  cin >> s;
  if(s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I') cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3604
#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
ll R, C;

bool bound(ll x1, ll y1){
    return x1 == 0 || x1 == R || y1 == 0 || y1 == C;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> R >> C >> N;
    vector<pair<pair<ll, ll>, int>> A, B;
    rep(i, N){
        int x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        if(bound(x1, y1) && bound(x2, y2)){
            if(C * x1 >= R * y1){
                A.pb(mp(mp(x1, y1), i));
            }
            else{
                B.pb(mp(mp(x1, y1), i));
            }
            if(C * x2 >= R * y2){
                A.pb(mp(mp(x2, y2), i));
            }
            else{
                B.pb(mp(mp(x2, y2), i));
            }

        }
    }
    
    sort(all(A)), sort(all(B));
    reverse(all(B));
    A.insert(A.end(), all(B));
    
    stack<int> st;
    rep(i, A.size()){
        if(st.empty()){
            st.push(A[i].second);
        }
        else{
            if(st.top() == A[i].second){
                st.pop();
            }
            else{
                st.push((A[i].second));
            }
        }
    }
    
    if(st.empty()){
        output("YES");
    }
    else{
        output("NO");
    }
    
    return 0;
}

Measured memory_bytes: 10788
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	K, X := ReadInt(), ReadInt()
	for i := X - (K - 1); i <= X+(K-1); i++ {
		fmt.Printf("%d ", i)
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int a; cin >> a;
    string s; cin >> s;
    if(a >= 3200) cout << s << endl;
    else cout << "red" << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    long long X, Y;
    cin >> X >> Y;
    if (X % Y == 0) {
        cout << -1 << endl;
    } else {
        cout << X << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		while(true){
			String str = br.readLine();
			
			if(str == null){
				break;
			}
			
			int n = Integer.parseInt(str);
			
			System.out.println(AreaDivider.maximumAreaNum(n));
		}
	}

}

class AreaDivider{
	static long maximumAreaNum(int n){
		long result = 2;
		
		for(int i = 2; i <= n; i++){
			result += i;
		}
		
		return result;
	}
}

Measured memory_bytes: 24340
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	int a[100010] ;
	cin >> n;
	for(int i=0;i<n;i++) {
		cin >> a[i] ;
	}
	int flag=1;
	for(int i=1;i<n;i++) {
		if(a[i-1]<a[i]) a[i]-=1;
		if(a[i-1]>a[i]) {
			flag=0;
			break;
		}
	}
	if(flag==1) cout <<"Yes"<<endl;
	else cout <<"No"<<endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
typedef pair<int,int> P;
typedef vector<int> ivec;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }


const int MOD=1000000007;
int INF=100100100100100;

signed main(){
  int n,a,b;cin>>n>>a>>b;
  cout<<min(a,b)<<" "<<max((int)0,a+b-n)<<endl;
  return 0;
}


Measured memory_bytes: 3620
#!/usr/bin/env python3
import sys


def solve(M: int, K: int):
    n = 2 ** M
    if n <= K or (M == 1 and K == 1):
        print(-1)
        return -1
    if M == 1 and K == 0:
        print('0 0 1 1')
        return
    ret = []
    for i in range(n):
        if i != K:
            ret.append(i)
    ret.append(K)
    for i in range(n - 1, -1, -1):
        if i != K:
            ret.append(i)
    ret.append(K)
    print(' '.join([str(i) for i in ret]))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    M = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(M, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 74688
#include<iostream>
using namespace std;
#include<vector>
int main(){
  int n,m,c;
  cin>>n>>m>>c;
  vector<int> b(m);
  for(int i=0;i<m;i++) cin>>b[i];
 
  int cnt=0;
  for(int i=0;i<n;i++){
    int res=c;
    for(int j=0;j<m;j++){
      int a;
      cin>>a;
      res+=a*b[j];
    }
    if(res>0) cnt++;
  }
  cout<<cnt<<endl;
  return 0;
}

Measured memory_bytes: 256
A, B, C, K = input().split()
# A=1 B=0 C=-1 K
ans = 0

if int(A) >= int(K):
    ans = K
elif int(A) + int(B) >= int(K):
    ans = A
else:
    ans = int(A) - (int(K) - (int(A) + int(B)))
print(ans)

Measured memory_bytes: 9068
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <iostream>
#include <sstream>
using namespace std;

typedef long long int64;
const int inf = (int)1e9;

int main()
{
	while(true) {
		
		int n, m, h, k;
		vector<int> state, score;
		vector<pair<int, int> > edge;
		vector<pair<int, int> > hist;
		
		scanf("%d%d%d%d", &n, &m, &h, &k);
		if(n == 0)
			break;
		score.resize(n);
		for(int i = 0; i < n; ++i)
			scanf("%d", &score[i]);
		edge.resize(m);
		for(int i = 0; i < m; ++i)
			scanf("%d%d", &edge[i].second, &edge[i].first);
		sort(edge.begin(), edge.end());
		
		state.resize(n);
		hist.resize(m);
		for(int i = 0; i < n; ++i)
			state[i] = i;
		for(int i = 0; i < m; ++i) {
			int a = edge[i].second;
			int b = a - 1;
			swap(state[a], state[b]);
			hist[i] = make_pair(state[a], state[b]);
		}
		
		vector<int> xscore;
		xscore.resize(n);
		for(int i = 0; i < n; ++i)
			xscore[state[i]] = score[i];
		
		int ans = 0;
		int start = 0;
		
		for(int i = 0; i < k; ++i)
			start += xscore[i];
		ans = start;
		
		//for(int i = 0; i < n; ++i)
		//	printf("[debug] %d -> %d\n", i, xscore[i]);
		
		for(int i = 0; i < m; ++i) {
			
			int a = hist[i].first;
			int b = hist[i].second;
			
			if(a < k && b < k)
				continue;
			if(a >= k && b >= k)
				continue;
			
			int t = start;
			
			t += a < k ? -xscore[a] : xscore[a];
			t += b < k ? -xscore[b] : xscore[b];
			
			ans = min(t, ans);
		}
		
		printf("%d\n", ans);
	}
	
	return 0;
}

/* ハラスメントに負けず */
/* 0完太陽にも負けず */
/* はやく人権を獲得したい */
/* nullmineralが書きましたが */
/* 責任はまったくとりません */

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

using V = vector<ll>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s; cin >> s;
    const ll n = s.size();
    vector<V> cnt(n, V(26, 0));
    rep(i, n) cnt[i][s[i]-'a']++;
    vector<V> S(n+1, V(26, 0));
    rep(i, n) rep(j, 26) {
        S[i+1][j] = S[i][j] + cnt[i][j];
    }
    ll ans = 1;
    rep(i, n) rep(j, 26) {
        if (cnt[i][j] > 0) continue;
        ans += S[i][j];
    }
    cout << ans << endl;
}


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

int N,M;
vector<int> a(1010),b(1010),c(1010);
int d[110][110];
 
int main(){
  cin >> N >> M;
  for(int i=1;i<=M;i++){cin >> a[i] >> b[i] >> c[i];}
  for(int i=1;i<=N;i++){
    for(int j=1;j<=N;j++){d[i][j]=100000000;}
  }
  for(int i=1;i<=M;i++){d[a[i]][b[i]]=c[i]; d[b[i]][a[i]]=c[i];}
  for(int k=1;k<=N;k++){
    for(int i=1;i<=N;i++){
      for(int j=1;j<=N;j++){d[i][j]=min(d[i][j],d[i][k]+d[k][j]);}
    }
  }
  int ans=0;
  for(int i=1;i<=M;i++){
    if(d[a[i]][b[i]]!=c[i]){ans++;}
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

#define N 200000

int main(){
	int i,j,n,maxv=0,minv;
	int a[N];

	scanf("%d",&n);
	
	for(i=0;i<n;i++) scanf("%d",&a[i]);
	
maxv=-1000000000;	
minv=a[0];
	
for(j=1;j<n;j++){
  if(maxv<a[j]-minv)maxv=a[j]-minv;
  if(minv>a[j])minv=a[j];
	}
	
	
	printf("%d\n",maxv);
	
	return 0;
	}

Measured memory_bytes: 1380
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
const double PI=3.14159265358979323846;
const in MOD = 1000000007;
const in INF=1<<30;
using P=pair<int,int>;
vector<int> dx={0,1,-1,0};
vector<int> dy={1,0,0,-1};



int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cout << fixed << setprecision(10);
    vector<vector<int>> a(3,vector<int>(3,0));
    rep(i,3)rep(j,3) cin>>a[i][j];
    int n;
    cin>>n;
    vector<int> b(n,0);
    rep(i,n) cin>>b.at(i);
     rep(i,3)rep(j,3){
         rep(k,n){
             if(a[i][j]==b[k]){
                 a[i][j]=0;
                 break;
             }
         }
     }
     bool flag =0;
     rep(i,3){
         if(a[i][0]+a[i][1]+a[i][2]==0) flag =1;
         if(a[0][i]+a[1][i]+a[2][i]==0) flag=1;
     }
     if(a[0][0]+a[1][1]+a[2][2]==0) flag=1;
     if(a[2][0]+a[1][1]+a[0][2]==0) flag =1;
     if(flag) cout<<"Yes"<<endl;
     else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void)
{
    int a, b, c;
    int divide, cnt = 0;
 
    scanf("%d %d %d", &a, &b, &c);
    for (divide = a; divide <= b; divide++){
        if (c % divide == 0){
            cnt++;
        }
    }
    printf("%d\n", cnt);
 
    return 0;
}

Measured memory_bytes: 596
#include<iostream>

using namespace std;

int main(){
    int x,n;
    cin >> x >> n;
    if(n==0){
        cout << x;
        return 0;
    }
    int p[n];
    for (int i=0; i<n; i++){
        cin >> p[i];
    }
    int output[2];
    bool flag=true;
    for(int i=n; i>=0; i--){
        flag=true;
        for(int j=0; j<n;j++){
            if(x+i==p[j]){ 
                flag=false;
            }
        }
        //cout << "flag " << flag << "x+i=" << x+i << endl;
        if(flag==true){
            //cout << x+i <<endl;
            output[0]=x+i;
        }
    }
    
    for(int i=n; i>=0; i--){
        flag = true;
        for(int j=0; j<n;j++){
            if(x-i==p[j]){
                flag=false;
            }
        }
        //cout << "flag " << flag << "x+i=" << x-i << endl;
        if(flag==true){
            //cout << x-i <<endl;
            output[1]=x-i;
        }
    }
    int dis[2];
    dis[0] = abs(x-output[0]);
    dis[1] = abs(x-output[1]);
    //cout << dis[0] << " " << dis[1] <<endl;

    if(dis[1]==dis[0]){
        cout << output[1];
        return 0;
    }

    if(dis[1] > dis[0]){
        cout << output[0];
    }else{
        cout << output[1];
    }

    return 0;
}

Measured memory_bytes: 3500
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))
L_A = [0] * (N+1)
R_A = [0] * (N+1)
for i in range(N):
    L_A[1+i] = gcd(L_A[i], A[i])
for i in reversed(range(N)):
    R_A[i] = gcd(R_A[i+1], A[i])
print(max(gcd(L_A[i], R_A[i+1]) for i in range(N)))


Measured memory_bytes: 16056
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define cvector vector<char>
#define svector vector<string>
#define lque queue<ll>
#define lpque priority_queue<ll>
#define dlpque priority_queue<ll,lvector,greater<ll>>
#define P pair<ll,ll>
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
#define rep(i,n) for(ll i=0; i<n; ++i)
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s,t;cin>>s>>t;
  string ss=s+s;
  ll aa=ss.length(),b=t.length(),pos=-1,num=0;
  bool isok=true;
  map<char,lvector> mp;
  rep(i,aa) mp[ss[i]].emplace_back(i);
  rep(i,b) {
    pos++;
    auto itr=lower_bound(ALL(mp[t[i]]),pos);
    if(itr==mp[t[i]].end()) {
      pos=0;num++;
      itr=lower_bound(ALL(mp[t[i]]),pos);
      if(itr==mp[t[i]].end()) isok=false;      
    }
    if(!isok) break;
    pos=*itr;
  }
  print(isok?aa*num+pos+1:-1);
  return 0;
}


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

ll modpow (ll a, int n, ll mod) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1 > 0)
      ret = ((ret % mod) * (a % mod)) % mod;
    a = ((a % mod) * (a % mod)) % mod;
    n >>= 1;
  }
  return ret;
}

int main(void){
  int n;
  cin >> n;
  vector<int> A(n);
  map<int, int> P;
  REP(i, n) {
    int in;
    cin >> in;
    P[in]++;
  }
  if (n % 2 == 1) {
    for (const auto& p : P) {
      // cerr << p.first << "," << p.second << endl;
      if ((p.first == 0 && p.second != 1) || (p.first != 0 && p.second != 2)) {
        cout << 0 << endl;
        return 0;
      }
    }
  } else {
    for (const auto& p : P) {
      if (p.second != 2) {
        cout << 0 << endl;
        return 0;
      }
    }
  }
  cout << modpow(2, n / 2, MOD) << endl;
  return 0;
}


Measured memory_bytes: 3584
import Control.Monad
import Data.List

solve :: Int -> [String] -> [String]
solve n xss 
  | (length $ head xss) == n = xss
  | otherwise = solve n xss'
    where
      xss' = concat $ map f xss
      f xs = [xs++[x] | x<-['a'..succ m]]
        where
          m = maximum xs

main = do 
  n <- readLn :: IO Int 
  let res = solve n ["a"]
  forM_ (sort res)  putStrLn


Measured memory_bytes: 49660
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}



int main(){
  int H,W;cin>>H>>W;
  vs a(H);rep(i,H)cin>>a[i];
  rep(i,H){
    bool ok=true;
    rep(j,W){
      if(a[i][j]=='#'){
        ok =false;
      }
    }
    if(ok){
     rep(j,W)a[i][j]='s';
    }
  }
  rep(i,W){
    bool ok=true;
    rep(j,H){
      if(a[j][i]=='#'){
        ok =false;
      }
    }
    if(ok){
     rep(j,H)a[j][i]='s';
    }
  }
  rep(i,H){
    bool ok =true;
    rep(j,W){
      if(a[i][j]!='s')ok =false;
    }
    if(!ok){
      rep(j,W){
        if(a[i][j]=='s')continue;
        cout<<a[i][j];
      }
      cout<<endl;
    }
    
    
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,m,x;
vector <vector<int>> textList;
vector <bool> isBought;
long totalCost = -1;
vector <int> skillVector;
void calc(){
    //cout << "calc " << "selectList.size():" << selectList.size() << endl;
    long currentCost = 0;
    for(int i = 0; i < isBought.size(); i++){
        if(isBought[i]){
        currentCost+=textList[i][0];
            for(int j = 1; j<=m; j++){
                skillVector[j-1]+=textList[i][j];
            }
        }
    }
    bool isValid = true;
    for(int i = 0; i < skillVector.size();i++){
        //cout << " skillVector[i]:"<<skillVector[i];
        if(skillVector[i]<x){
            isValid=false;
        }
    }
    //cout << endl;
    //cout << "currentCost:" << currentCost<<endl;
    if(isValid){
        if(totalCost==-1){
            totalCost=currentCost;
        }else{
            if(totalCost>currentCost){
                totalCost=currentCost;
            }
        }
    }
    for(int i = 0; i < skillVector.size();i++){
        skillVector[i]=0;
    }
#if 0
for(int i = 0; i < selectList.size(); i++){
    cout << selectList[i] << " ";
}
cout << endl;
#endif
}
void dfs(bool buy){
    //cout << "dfs " << textIndex << endl; 
    isBought.push_back(buy);
    if(isBought.size()==n){
        //探索終了結果判定
        calc();
        return;
    }
    dfs(true);
    isBought.pop_back();
    dfs(false);
    isBought.pop_back();
}
int main(){
    cin >> n >> m >> x;
    for(int i=0; i<n; i++){
        textList.push_back(vector<int>(m+1));
        for(int j = 0; j<=m; j++){
            cin >> textList[i][j];
        }
    }
    for(int i = 0; i < m ; i++){
        skillVector.push_back(0);
    }
    dfs(true);
    isBought.pop_back();
    dfs(false);
    isBought.pop_back();
    cout << totalCost << endl;
    #if 0
    cout << n << " " << m << " " << x << endl;
    for(int i = 0; i < textList.size(); i++){
        for(int j = 0; j<textList[i].size(); j++){
            cout << textList[i][j] << " ";
        }
        cout << endl;
    } 
    #endif
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <sstream>
#include <algorithm>
using namespace std;
int input;
string toString(int n){stringstream ss; ss << n; return ss.str();}
bool isPalindromicNum(int x){
  string s = toString(x);
  string _s = s;
  reverse(s.begin(), s.end());
  return s == _s;
}
void solve(){
  int margin = input;
  int ans;
  for(int i = 0 ; i < input + margin; i++){
    if(i % 10 == 0)continue;
    if(isPalindromicNum(i)){
      margin = abs(input - i);
      ans = i;
    }
  }
  cout << ans << endl;
}
int main(){
  while(cin >> input){
    solve();
  }
  return 0;
}

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

int main() {
  int a, b, c, x;
  cin >> a >> b >> c >> x;
  int ans = 0;
  rep(i, a + 1) rep(j, b + 1) rep(k, c + 1) {
    if (500 * i + 100 * j + 50 * k == x) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys

def base_convert(n, b):
    res = ''
    q = n
    while q:
        q, r = divmod(q, b)
        if r < 0: 
            q += 1
            r -= b
        res = str(r) + res

    return int(res) if res else 0

n, k = map(int, sys.stdin.readline().split())

def main():
    return len(str(base_convert(n, k)))

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
#include <math.h>

int main()
{
    char a[3], b[3], flg;
    for(int j = 0; j<3; j++)
        scanf("%c", &a[j]);
    scanf("%c", &flg);
    for(int j = 0; j<3; j++)
        scanf("%c", &b[j]);
    if((a[0] == b[2]) && (a[1] == b[1]) && (a[2] == b[0]))
        printf("YES");
    else
        printf("NO");

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main (void) {
    ll H, W;
    cin >> H >> W;
    ll ans;
    if (H == 1 || W == 1) {
        ans = 1;
    } else if (H * W  % 2 == 0) {
        ans = (H * W) / 2;
    } else {
        ans = (H * W) / 2 + 1;
    }
    cout << ans <<endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	N := ReadInt()
	fmt.Println((N - 1) * N / 2)
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1840
#include <stdio.h>

int main(){

  int s,sum=0,min,sec,i;
  for(i=0;i<4;i++){
  scanf("%d",&s);
  sum += s;
  }
  min=sum/60;
  sec=sum%60;
  printf("%d\n",min);
  printf("%d\n",sec);
  return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
#include <limits.h>
#define MAX 2000000000
typedef struct{
  int x;
  char c;
}card;
card M[100000];
int Partition(int, int);
void Quicksort(int, int);
void merge(int, int, int,card[]);
void mergeSort(int, int, card[]);
int main(){
  int i, p, n;
  char c;
  card N[100000];
  scanf("%d%c", &n, &c);
  for(i = 0; i < n; i++){
    scanf("%c%d%c", &N[i].c, &N[i].x, &c);
    M[i] = N[i];
}
  p = 0;
  mergeSort(0, n, N);
  Quicksort(0, n-1);
  for(i = 0; i < n; i++){
    if(N[i].c != M[i].c){
      printf("Not stable\n");
break; }
    if(i == (n - 1))
      printf("Stable\n");
}
  for(i = 0; i < n; i++){
    printf("%c %d\n", M[i].c, M[i].x);
    }
return 0; }
int Partition(int e, int s){
  card tmp;
  int i, j, x;
  x = M[s].x;
i = e - 1;
  for(j = e; j < s; j++){
    if (M[j].x <= x){
      i++;
      tmp = M[i];
      M[i] = M[j];
      M[j] = tmp;
} }
  tmp = M[i + 1];
  M[i + 1] = M[s];
  M[s] = tmp;
    return (i + 1);
}
void Quicksort(int e, int s){
  int w;
  if(e < s){
     w = Partition(e, s);
     Quicksort(e, w-1);
     Quicksort(w+1, s);
} }
void merge(int left, int mid, int right, card K[]){
  int i, j, k;
  int n1 = mid - left;
  int n2 = right - mid;
  card L[100001], R[100001];
  for(i = 0; i < n1; i++){
    L[i] = K[left + i];
  }
  for(i = 0; i < n2; i++){
    R[i] = K[mid+i];
  }
  L[n1].x = MAX;
  R[n2].x = MAX;
  i = 0;
  j = 0;
  for(k = left; k < right; k++){
    if(L[i].x <= R[j].x)
      K[k]=L[i++];
    else
      K[k]=R[j++];
} }
void mergeSort(int left, int right, card K[]){
  if((left + 1) < right){
    int mid = (left + right) / 2;
    mergeSort(left, mid, K);
    mergeSort(mid, right, K);
    merge(left, mid, right, K);
} }



Measured memory_bytes: 4128
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => long.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	int N;
	void Solve()
	{
		N = F();
		var A = G();
		int m = A.Min(), M = A.Max(), mi = 0, Mi = 0;
		while (A[mi] != m) mi++;
		while (A[Mi] != M) Mi++;
		if (m >= 0)
		{
			Console.WriteLine(N - 1);
			Pos();
		}
		else if (M <= 0)
		{
			Console.WriteLine(N - 1);
			Neg();
		}
		else if (M >= -m)
		{
			Console.WriteLine(2 * N - 1);
			Unif(Mi);
			Pos();
		}
		else
		{
			Console.WriteLine(2 * N - 1);
			Unif(mi);
			Neg();
		}
	}
	void Unif(int k) { for (var i = 0; i < N; i++) F(k, i); }
	void Pos() { for (var i = 1; i < N; i++) F(i - 1, i); }
	void Neg() { for (var i = N - 1; i > 0; i--) F(i, i - 1); }
	void F(int x, int y) => Console.WriteLine("{0} {1}", x + 1, y + 1);
}


Measured memory_bytes: 13396
n, m, c = map(int, input().split())
b = list(map(int, input().split()))
a = [list(map(int, input().split())) for _ in range(n)]

cnt = 0
for i in range(n):
    x = 0 + c
    for j in range(m):
        x += b[j] * a[i][j]
    if x > 0:
        cnt += 1

print(cnt)


Measured memory_bytes: 3060
import java.util.Scanner;	//Scannerクラス：Java標準入力を取得する

class Main{
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			int n = sc.nextInt();
			int m = sc.nextInt();
			int [][] A = new int [n][m];
			int [] b = new int[m];


			for(int i = 0;i < n;i++) {
				for(int j = 0;j < m;j++) {
					A[i][j] = sc.nextInt();
				}
			}
			for(int i = 0;i < m;i++) {
				b[i] = sc.nextInt();
			}
			for(int i = 0;i < n;i++) {
				int sum = 0;
				for(int j = 0;j < m;j++) {
					sum += A[i][j] * b[j];
				}
				System.out.println(sum);
			}
		}
	}
}




Measured memory_bytes: 40504
#include <iostream>

using namespace std;

int digits(int x)
{
	if (x >= 1000000) return 7;
	if (x >= 100000) return 6;
	if (x >= 10000) return 5;
	if (x >= 1000) return 4;
	if (x >= 100) return 3;
	if (x >= 10) return 2;
	if (x >= 1) return 1;
}
int main()
{
	int a;
	int b;
	int x;
	int y;
	while (cin >> a >> b)
	{
		x = a + b;
		int y = digits(x);
		cout << y << endl;
	}

	return 0;
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
#include<cstdio>
#include<cctype>

using namespace std;

void push(int x);
int pop(void);

int top,S[1000];
int main()
{
  int a,b;
  top=0;
  char s[100];
  while(scanf("%s",s) !=EOF){
    if(s[0] == '+'){
      a=pop();
      b=pop();
      push(a+b);
    }
    else if(s[0] == '-'){
      b=pop();
      a=pop();
      push(a-b);
    }
    else if(s[0]=='*'){
      a=pop();
      b=pop();
      push(a*b);
    }
    else push(atoi(s));
  }
  cout<<pop()<<endl;
}

void push(int x){
  S[++top]=x;
}

int pop(){
  top--;
  return S[top+1];
}



Measured memory_bytes: 3240
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define ll long long
int main() {
    int n;
    cin>>n;
    string s;
    cin>>s;
    int c=1;
    REPS(i,n-1)
    {
        if(s[i]==s[i-1])
        continue;
        else c++;
    }
    cout<<c;
}

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

int main() {
	int N, M, a, b, way[200000] = {};
	bool check = false;
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> a >> b;
		if (a == 1) way[b]++;
		if (b == N) way[a]++;
	}
	for (int i = 2; i < N; i++) {
		if (way[i] >= 2) check = true;
	}
	if (check) cout << "POSSIBLE";
	else cout << "IMPOSSIBLE";
}

Measured memory_bytes: 1024
n = int(input())
A = list(map(int, input().split()))
maxA = max(A)
abs_min = 10**9
A.remove(maxA)
for a in A:
  if abs_min > abs(maxA/2 - a):
    abs_min = abs(maxA/2 - a)
    r = a
print(maxA, r)


Measured memory_bytes: 20120
# coding:utf-8
def main():
    n = int(input())
    l = list(map(int, input().split()))
    count = 1

    #対象の山
    for i in range(1,n):
        view = True
        #比較される山
        for j in range(0,i):
            if l[j] > l[i]:
                view = False
        if view == True:
            count = count + 1

    print(count)

if __name__ == '__main__' :
    main()

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define cinv(n,vec) VL vec(n);rep(i,n)cin>>vec[i]
#define int long long
#define itn int
#define pb push_back
#define eb emplace_back
#define m_p make_pair
#define m_t make_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a),greater<>())
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) (signed)(a.size())
#define debg(a) cout<<#a<<" "<<a<<endl;
#define debgp(a) cout<<#a<<" "<<a.fi<<" : "<<a.se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define callp(a) for(auto [k,v]:a)cout<<k<<":"<<v<<endl
#define show(a) for(cont &y:a){for(cont &x:y){cout<<x<<" ";}cout<<endl;}
#define out(a) cout<<(a)<<endl
#define ENDL cout<<endl
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define LINE puts("------------------")
#define fi first
#define se second
#define V vector
#define P pair
#define T tuple
#define PQ priority_queue
#define cont const auto
#define VV(type,name,y,x,a) vector<vector<type>> name = vector<vector<type>>(y,vector<type>(x,a))
typedef long long ll;
typedef double D;
typedef long double LD;
typedef string str;
typedef vector<ll> VL;
typedef pair<ll,ll> PL;
typedef vector<pair<ll,ll>> VP;
typedef tuple<ll,ll,ll> T3;
typedef tuple<ll,ll,ll,ll> T4;
typedef struct{ll to;ll cost;} Graphs;
typedef V<V<Graphs>> AdjList;
const signed INF = (1LL<<30);
const long long MOD = (1e9+7);
const long long LINF = (1LL<<60);
const long long LMAX = LLONG_MAX;
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}

template<class T>inline T gcd(T a,T b){if(b==0)return a; return(gcd(b,a%b));}
template<class T>inline T lcm(T a,T b){return a/gcd(a,b)*b;}
template<class T>inline bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<class T>T center(T a,T b,T c){
  if( (a<=b&&b<=c)||(a>=b&&b>=c) )return b;
  if( (b>=a&&a>=c)||(b<=a&&a<=c) )return a;
  return c;
}
void print(){}
template<class Head,class... Tail>
void print(Head&& head, Tail&&... tail){
  cout<<head<<endl;
  print(forward<Tail>(tail)...);
}
void input(){}
template<class Head,class... Tail>
void input(Head&& head, Tail&&... tail){
  cin>>head;
  input(forward<Tail>(tail)...);
}
template<typename T>
ostream &operator<<(ostream&out,const vector<T>&v){
  if(!v.empty()){
    copy(v.begin(),v.end(),ostream_iterator<T>(out,", "));
    out<<"\b\b";
  }
  return out;
}
template<typename T1, typename T2>
ostream &operator<<(ostream&out,const pair<T1,T2>&p){
  out<<p.first<<", "<<p.second;
  return out;
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(10);
  
  ll k,s;
  input(k,s);
  k++;
  ll ans=0;
  //rep(i,k)rep(j,k)rep(l,k)ans+=(i+j+l==s);
  rep(i,k)rep(j,k)ans+=(i+j<=s&&s-i-j<k);
  out(ans);



  return 0;
}


Measured memory_bytes: 256