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

int main(){
  string a; cin >>a;
  if(a=="SAT") {cout <<1; return 0;}
  if(a=="FRI") {cout <<2; return 0;}
  if(a=="THU") {cout <<3; return 0;}
  if(a=="WED") {cout <<4; return 0;}
  if(a=="TUE") {cout <<5; return 0;}
  if(a=="MON") {cout <<6; return 0;}
  if(a=="SUN") {cout <<7; return 0;}
}

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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<pair<LL, int> > HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 1000010, M = 3010;

int na, nb, nc, k;
LL x[N], y[N], z[N], t[N];

bool cmp(LL a, LL b)
{
	return a > b;
}

void merge(LL a[], int n, LL b[], int m)
{
	HEAP heap;
	for (int i = 0; i < m; i ++ ) heap.push({a[0] + b[i], 0});
	
	n = min(n * m, k);
	for (int i = 0; i < n; i ++ )
	{
		LL v = heap.top().F;
		int j = heap.top().S;
		heap.pop();
		
		t[i] = v;
		if (j + 1 < na) heap.push({v - a[j] + a[j + 1], j + 1});
	}

	na = n;
	memcpy(a, t, sizeof t);
}

int main()
{
	cin >> na >> nb >> nc >> k;
	for (int i = 0; i < na; i ++ ) cin >> x[i];
	for (int i = 0; i < nb; i ++ ) cin >> y[i];
	for (int i = 0; i < nc; i ++ ) cin >> z[i];
	
	sort(x, x + na, cmp);
	merge(x, na, y, nb);
	merge(x, na, z, nc);
	
	for (int i = 0; i < k; i ++ ) cout << x[i] << endl;
	return 0;
}

Measured memory_bytes: 13184
import scala.math.{min,max}

object Main {
  val sc = new java.util.Scanner(System.in)
  def roll(s: String, a: Array[Int]) = s match {
    case "North" => Array(a(1), a(5), a(2), a(3), a(0), a(4))
    case "East" => Array(a(3), a(1), a(0), a(5), a(4), a(2))
    case "West" => Array(a(2), a(1), a(5), a(0), a(4), a(3))
    case "South" => Array(a(4), a(0), a(2), a(3), a(5), a(1))
    case "Right" => Array(a(0), a(2), a(4), a(1), a(3), a(5))
    case "Left" => Array(a(0), a(3), a(1), a(4), a(2), a(5))
  }
  def main(args: Array[String]) {
    while(true) {
      val n = sc.nextInt
      if(n == 0) return
      var a = (1 to 6).toArray
      var ans = 1
      for(i <- 1 to n) {
        a = roll(sc.next, a)
        ans += a(0)
      }
      println(ans)
    }
  }
}

Measured memory_bytes: 52296
import sys
N,k=map(int,input().split())
A=[int(i) for i in input().split()]
if N==1:
    print(0)
    sys.exit()
dp=[0]*N
dp[0]=0
for i in range(1,N):
    j=1
    ans=float('inf')
    while True:
        if j<=k and i-j>=0:
            ans=min(abs(A[i]-A[i-j])+dp[i-j],ans)
            j+=1
        else:
            break
    dp[i]=ans
##print(dp)
    
print(dp[-1])
    
    


Measured memory_bytes: 84708
#include<cstdio>
#include<algorithm>
#include<cstring>
#define MN 100005
using namespace std;
int n,head[MN],f[MN],sz[MN],ans=0x3f3f3f3f,nans[MN],cnt,num;
struct edge{int to,next,w;}g[MN<<1];
long long res;
void dfs(int u,int fa){
	sz[u]=1;
	for(int i=head[u];i;i=g[i].next)if(g[i].to!=fa)dfs(g[i].to,u),sz[u]+=sz[g[i].to],f[u]=max(f[u],sz[g[i].to]);
	f[u]=max(f[u],n-sz[u]);ans=min(ans,f[u]);
	for(int i=head[u];i;i=g[i].next)if(g[i].to!=fa)res+=1ll*min(n-sz[g[i].to],sz[g[i].to])*2*g[i].w;
}
void ins(int u,int v,int w){g[++num].next=head[u];head[u]=num;g[num].to=v;g[num].w=w;}
int main(){
	scanf("%d",&n);int x,y,v;
	for(int i=1;i<n;i++)scanf("%d%d%d",&x,&y,&v),ins(x,y,v),ins(y,x,v);dfs(1,0);
	for(int i=1;i<=n;i++)if(f[i]==ans)nans[++cnt]=i;
	if(cnt==1){
		int tmp=0x3f3f3f3f;
		for(int i=head[nans[1]];i;i=g[i].next)tmp=min(tmp,g[i].w);
		res-=tmp;
	}else for(int i=head[nans[1]];i;i=g[i].next)if(f[g[i].to]==ans)res-=g[i].w;
	printf("%lld\n",res);
}

Measured memory_bytes: 7680
N = int(input())
for n in range(1, 3501):
    for w in range(1, 3501):
        denominator = 4*n*w - w*N - n*N
        numerator = n*w*N
        if denominator != 0 and numerator%denominator == 0:
            h = numerator // denominator
            if 0 < h <= 3500:
                print(h, n, w)
                break
    else:
        continue
    break
            

Measured memory_bytes: 41692
import java.util.Scanner;
import java.util.Stack;

//a trivial practice to evaluate reverse polish notation

public class Main {
	public static boolean is_operator(String token) {
		return token.equals("+") || token.equals("-") || token.equals("*");
	}
	
	
	public static int eval_simple_exp(int b, int a, String op) {
		if(op.equals("+")) return a + b;
		if(op.equals("-")) return a - b;
		if(op.equals("*")) return a * b;
		
		
		return 0;
	}
	
	
	//without any other validation about the expression's validity
	public static int eval_r_polish(String[] exp) {
		Stack<Integer> oprd_stk =new Stack<Integer>();
		int i = 0;
		
		
		while(i < exp.length) {
			String token = exp[i];
			if(is_operator(token)) {
				oprd_stk.push(eval_simple_exp(oprd_stk.pop(), oprd_stk.pop(), token));
			}else {
				oprd_stk.push(Integer.parseInt(token));
			}
			i++;
		}
		
		return oprd_stk.pop();
	}
	
	
	public static void main(String [] args) {
		Scanner cin = new Scanner(System.in);
		
		String str_exp = cin.nextLine();
		
		System.out.println(eval_r_polish(str_exp.split(" ")));
		
	}
}

Measured memory_bytes: 26048
#include <bits/stdc++.h>
#define fr(i, n) for (int i = 0; i < n; i++)
#define frab(i, a, b) for (ll i = a; i < b; i++)
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef long double ld;

const ll MOD = 1e9 + 7;
const ll INF = 2e9 + 10;
const int N = 2e6 + 10;

struct pt {
    ll x, y, n;
} a[N];

bool cmpx(pt a, pt b) {
    return a.x < b.x;
}

bool cmpy(pt a, pt b) {
    return a.y < b.y;
}


struct edge {
    ll v, u, w;
    bool operator < (const edge a) const {
        return w < a.w || w == a.w && v < a.v || w == a.w && v == a.v && u < a.u;
    }
};

edge g[N];
ll rnk[N], par[N];
set <edge> st;

void makeSet(int x) {
    rnk[x] = 0;
    par[x] = x;
}

int findSet(int x) {
    if (x == par[x])
        return x;
    return par[x] = findSet(par[x]);
}

void unionSets(int a, int b) {
    int a1 = findSet(a);
    int b1 = findSet(b);
    if (a1 == b1)
        return;
    if (rnk[a1] < rnk[b1])
        swap(a1, b1);
    if (rnk[a1] == rnk[b1])
        rnk[a1]++;
    par[b1] = a1;
}

int main() {
    //freopen("a.in", "r", stdin);
    int n;
    cin >> n;
    fr(i, n) {
        cin >> a[i].x >> a[i].y;
        a[i].n = i;
    }
    sort(a, a + n, cmpx);
    fr(i, n - 1) {
        g[i].v = a[i].n;
        g[i].u = a[i + 1].n;
        g[i].w = abs(a[i].x - a[i + 1].x);
        st.insert(g[i]);
    }

    sort(a, a + n, cmpy);
    fr(i, n - 1) {
        g[i + n - 1].v = a[i].n;
        g[i + n - 1].u = a[i + 1].n;
        g[i + n - 1].w = abs(a[i].y - a[i + 1].y);
        st.insert(g[i + n - 1]);
    }

    fr(i, n)
        makeSet(i);

    ll ans = 0, qua = 0;

    for (auto it = st.begin(); it != st.end(); it++) {
        edge t = *it;
        if (findSet(t.v) != findSet(t.u)) {
            unionSets(t.v, t.u);
            ans += t.w;
            qua++;
        }
        if (qua == n - 1)
            break;
    }
    cout << ans;

}


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

using namespace std;

int main() {
	int a;
	int mini = 10;
	int ans = 0;
	for (int i = 0; i < 5; ++i) {
		cin >> a;
		if (a % 10 != 0) {
			ans += a + (10 - a % 10);
			mini = min(mini, a % 10);
		} else ans += a;
	}
	ans += mini - 10;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,i;
  long long int ans=0,m=0,a=0,r=0,c=0,h=0;
  char s[11];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",s);
    switch(s[0]){
    case 'M' : m++; break;
    case 'A' : a++; break;
    case 'R' : r++; break;
    case 'C' : c++; break;
    case 'H' : h++; break;
    }
  }
  ans+= m*a*r;  ans+= m*a*c;  ans+= m*a*h;  ans+= m*r*h;
  ans+= m*c*h;  ans+= a*r*c;  ans+= a*r*h;  ans+= a*c*h;
  ans+= r*c*h;  ans+= m*r*c;
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <stack> 
#include <map>
#include <queue>
#include <unordered_map>
#include <cassert>
#include <iomanip>
#include <cmath>
#include <cstring>
using namespace std;

#define pb 					push_back

template<typename T,typename S>
ostream& operator <<(ostream& os, pair<T, S> input) {
	os<<"("<<input.first<<", "<<input.second<<")";
	return os;
}

template<typename T>
ostream& operator <<(ostream& os, vector<T> input) {
	for(auto t: input)
		os << t <<" ";

	return os;
}


string s;
int D;

long long dp [10002][3][102];
long long MOD = 1e9 + 7;
int solve(int in, int isPref, int mod) {
	if(in == s.size()) {
		if(0 == mod)
			return 1;
		else
			return 0;
	}

	if(dp[in][isPref][mod]!=-1)
		return dp[in][isPref][mod];
	int r = 9;

	if(isPref)
		r =s[in]-'0';

	long long ans =0;
	for(int d = 0; d<=r; d++){
		int rmod = (mod - d)%D;
		if(rmod <0)
			rmod +=D;

		assert(rmod >=0 && rmod < D);
		ans += solve(in + 1, isPref && (d==r), rmod);
		ans%=MOD;
	}

	return dp[in][isPref][mod] = ans;

}
int main() {
    //ios_base::sync_with_stdio(false);
	//cin.tie(0);
	//cout.tie(0);
	memset(dp, -1, sizeof dp);
	cin >> s;

	cin >> D;
	long long ans = (solve(0, 1, 0) -1 +MOD)%MOD;
	cout << ans<<"\n";
	return 0;
}



Measured memory_bytes: 25088
#include<stdio.h>

typedef struct{

  char m;
  int v;

}card;

int main(){

  int i, j, n, min, flag = 1, f = 0;

  card m1[36], m2[36], tmp; 

  scanf("%d",&n);
 
  for( i = 0; i < n; i++){

    scanf(" %c%d", &m1[i].m, &m1[i].v);
    m2[i].m = m1[i].m;
    m2[i].v = m1[i].v;

  }
  //bubblesort
  while(flag){

    flag = 0;

    for( i = n-1; i >= 1; i--){

      if( m1[i].v < m1[i-1].v){

	tmp = m1[i];
	m1[i] = m1[i-1];
	m1[i-1] = tmp;
	flag = 1;

      }
    }
  }

  for( i = 0; i < n; i++) {

    printf("%c%d", m1[i].m, m1[i].v);
    if(i != n-1)printf(" ");

  }
  printf("\n");

  printf("Stable\n");
  //???????????§

  //selectionsort
  for( i = 0; i < n; i++){

    min = i;

    for(j = i; j < n; j++){

      if(m2[j].v < m2[min].v){
	min = j;
      }
    }

    if( i != min){//????°??????????????????????????????????????????????

      tmp = m2[i];
      m2[i] = m2[min];
      m2[min] = tmp;

    }
  }
 
  for( i = 0; i < n; i++){

    printf("%c%d", m2[i].m, m2[i].v);

    if(i != n - 1)
      printf(" ");
  }

  printf("\n");
  //???????????§
  //bubblesort??¨??????????????????
  for( i = 0; i < n; i++){

    if( m1[i].m != m2[i].m) {

      printf("Not stable\n");
      f = 1;
      break;
    }

  }
  if(f != 1)
    printf("Stable\n");

  return 0;
}

Measured memory_bytes: 612
#include <iostream>

int main() {
  int N;  std::cin>>N;
  bool pos = false;

  for (int i = 0; 4*i <= N; ++i) {
    if ((N - 4*i) % 7 != 0)
      continue;
    int j = (N - 4*i) / 7;
    pos = true;
  }

  std::cout<<(pos ? "Yes" : "No")<<"\n";

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//long long a[200005];
//long long b[200005],c[200005];

int main ()
{

    long long int a,b, c,d,e,f,g,h,i,j,k,t,n,sum=0;

    cin >> a>>b;

    if (a<b)
    {
        cout << "0"<<"\n";
    }

    else
    {
        cout << "10"<<"\n";
    }

}


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

int main() {
  int q; cin >> q;
  multiset<int> ms;
  for (int i = 0; i < q; i++) {
    int cmd; cin >> cmd;
    if (cmd == 0) {
      int x; cin >> x;
      ms.insert(x);
      cout << ms.size() << endl;
    }
    if (cmd == 1) {
      int x; cin >> x;
      cout << ms.count(x) << endl;
    }
    if (cmd == 2) {
      int x; cin >> x;
      ms.erase(x);
    }
    if (cmd == 3) {
      int l, r; cin >> l >> r;
      for (auto itr = ms.lower_bound(l), end = ms.upper_bound(r); itr != end; itr++) {
        cout << *itr << endl;
      }
    }
  }
}


Measured memory_bytes: 12236
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define rep(index,num) for(int index=0;index<num;index++)
#define eps 1e-15
typedef long long ll;
int main(){
	int N,K;
	ll nurikata;
	scanf("%d %d",&N,&K);
	printf("%d\n",(int)(K*pow(K-1,N-1)));
	return 0;
}


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

const int mod = 1000000007;

//正しいあみだ1段分になっているか判定
//(隣り合うビットが互いに1の時はダメ)
bool ok(int x,int w) {
    for (int i = 0; i < w-2; i++) {
        if (((x>>i)&1) && ((x>>(i+1))&1))return false;
    }
    return true;
}

int main() {

    int h, w, k;
    cin >> h >> w >> k;

    vector<vector<int>>total(h + 1, vector<int>(w, 0)); //0は要素の初期化
    total[0][0] = 1;

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            for (int k = 0; k < 1 << (w - 1); k++) {
                if (!ok(k,w))continue;
                //左へ
                if (j >= 1 && (k >> (j - 1) & 1)) { 
                    total[i + 1][j - 1] += total[i][j];
                    total[i + 1][j - 1] %= mod;
                }
                //右へ
                else if (j <= w - 2 && (k >> j & 1)){
                    total[i + 1][j + 1] += total[i][j];
                    total[i + 1][j + 1] %= mod;
                }
                //下へ
                else{
                    total[i + 1][j] += total[i][j];
                    total[i + 1][j] %= mod;
                }
            }
        }
    }

    cout << total[h][k - 1]%mod << "\n";

    return 0;
}


Measured memory_bytes: 256
#import math
#import copy
#import sys
#import bisect
#input = sys.stdin.readline
mod=10**9+7
def factorial(x): #階乗計算
    n=1
    for i in range(x):
        n=(n*(i+1))%mod
    return n

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))
def div(x): #約数配列
    div=[1]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        if(x%check==0):
            div.append(check)
            while(x%check==0):
                x=x//check
        check+=1
    if x != 1:
      div.append(x)
    return div
def div2(x): #素因数分解配列
    div2=[]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        while x%check==0:
            div2.append(check)
            x/=check
        check+=1
    if x != 1:
      div2.append(x)
    return div2

def main():
    # x,y = map(int,input().split())           x=1,y=2
    # a = input().split()                      a=['1','2','3',...,'n']
    # a = list(map(int,input().split()))       a=[1,2,3,4,5,...,n]
    # li = input().split('T')	              FFFTFTTFF => li=['FFF', 'F', '', 'FF']
    # 複数行の「1 2 3 4」型の入力を一配列に
    # x = sorted([list(map(int, input().split())) for _ in range(n)])
    # ソート x.sort(key=lambda y:y[1])
    # [chr(i) for i in range(97, 97+26)] 英語小文字リスト
    # [chr(i) for i in range(65, 65+26)] 英語大文字リスト atcoder
    # ord(c) chr(2) alphabet <=> number
    n=int(input())
    if n==2:
        print(0)
        return
    ans=0
    for i in range(int(n**(1/2))+3):
        i+=1
        if (n-i)%i == 0 and i < (n-i)//i:
            if i==n**(1/2):
                break
            ans+=(n-i)//i
    print(ans)
main()

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

int main() {
  char x,y;
  cin >> x >> y;
  int a = x;
  int b = y;
  if(a > b) cout << ">" << endl;
  else if(a == b) cout << "=" << endl;
  else cout << "<" << endl;
}

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

using namespace std;
using ll = long long;

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

#define ALL(o) (o).begin(), (o).end()

template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T, vector<T>, greater<T> >;

const ll MOD = 1000000007;

int main() {
    int n,a,b,t;
    cin >> n;
    cin >> a >> b;
    int ans = 0;

    if(n*a < b) {
        ans += n*a;
    } else {
        ans += b;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

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

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/
	int kkt = 89;
	while (kkt) {
		ll N, M; scanf("%lld %lld", &N, &M); if (N == 0 && M == 0) break;
		vector<pair<ll, int>> score(N); for (int i = 0; i < N; i++) score[i].second = i;
		vector<pair<ll, int>> mn(N); for (int i = 0; i < N; i++) mn[i].second = i;
		for (int i = 0; i < M; i++) {
			ll s; scanf("%lld", &s);
			ll k; scanf("%lld", &k);
			if (k == 1) {
				ll x; scanf("%lld", &x);
				x--;
				score[x].first += s;
				mn[x].first += s;
			}
			else {
				for (int j = 0; j < k; j++) {
					ll x; scanf("%lld", &x);
					x--;
					score[x].first += s;
				}
			}
		}
		sort(score.rbegin(), score.rend());
		sort(mn.begin(), mn.end());
		if (score[0].second != mn[0].second) {
			cout << score[0].first - mn[0].first + 1<< "\n";
		}
		else {
			cout << max(score[0].first - mn[1].first, score[1].first - mn[0].first) + 1 << "\n";
		}
	}
	return 0;

}


Measured memory_bytes: 3432
H, W, A, B = map(int, input().split())

ans = 0 
MOD = 10**9 + 7
N = H + W - 2
fac = [1] * N
inv = [1] * N

# 階乗
for i in range(1, N):
    fac[i] = (fac[i - 1] * i) % MOD
 
# 高速な逆元テーブル　最初にN-1を求めておくことであとはiをかけるだけで残りの逆元が算出できる
inv[N - 1] = pow(fac[N - 1], MOD - 2, MOD)
for i in range(N - 1, 0, -1):
    inv[i - 1] = (inv[i] * i) % MOD
 
 
def f(x, y):
    ans = fac[x + y] * inv[x] * inv[y] % MOD
    return ans
 

for x in range(B, W):
    ans += f(x, H - A - 1) * f(W - 1 - x, A - 1)
    ans %= MOD
    
print(ans % MOD)

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

int main() {
    int N;
    cin >> N;
    vector<int> moti(N);
    
    for (int i =0; i < N; i++){
        cin >> moti.at(i);
    }
    
    sort(moti.begin(), moti.end());
    
    int f = 1;
    for (int j = 0; j + 1 < N; j++){
        if (moti.at(j) < moti.at(j + 1)){
            f++;
        }
    }
    cout << f << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
 
long long GCD(long long a, long long b) {
    if(b == 0) return a;
    else return GCD(b, a % b);
}
 
int main() {
    long long a, b;
    cin >> a >> b;
    long long MAX = GCD(a, b);
    long long res = 1;
    for(long long i = 2; i*i <= MAX; ++i) {
        if(MAX % i != 0) continue;
        while(MAX % i == 0) {
            MAX /= i;
        }
        ++res;
    }
    if(MAX != 1) ++res;
    cout << res << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
double x[510];
double y[510];
double z[510];
int v[510];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++)scanf("%lf%lf%lf",x+i,y+i,z+i);
		for(int i=0;i<a;i++)v[i]=0;
		int b;scanf("%d",&b);
		for(int i=0;i<b;i++){
			double tx,ty,tz,th;
			scanf("%lf%lf%lf%lf",&tx,&ty,&tz,&th);
			double d=sqrt(tx*tx+ty*ty+tz*tz);
			for(int j=0;j<a;j++){
				double r=sqrt(x[j]*x[j]+y[j]*y[j]+z[j]*z[j]);
				double h=acos((tx*x[j]+ty*y[j]+tz*z[j])/(d*r));
				if(h>th)continue;
		//		double l=cos(h)*r;
		//		if(d<l)continue;
				v[j]=1;
			}
		}
		int ret=0;
		for(int i=0;i<a;i++)ret+=v[i];
		printf("%d\n",ret);
	}
}

Measured memory_bytes: 1152
#include<stdio.h>
int main(){
	int a = 0;
	int b = 0;
	int c;
	int d;
	scanf("%d %d", &a, &b);
	c = a*b;
	d = 2 * (a + b);
	printf("%d %d\n", c, d);
	return 0;
}

Measured memory_bytes: 2596
#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()
{
	ios::sync_with_stdio(false);
	cin.tie(0);

	int	n;
	cin >> n;
	if (n / 100 == 7 || (n % 100) / 10 == 7 || n % 10 == 7)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


Measured memory_bytes: 3640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class Main {

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

        try {

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            List<String> input = Arrays.asList(br.readLine().split(" "));
            List<Integer> numbers = new ArrayList<>();

            for (String s : input) {
                numbers.add(Integer.parseInt(s));
            }

            int busCharge = numbers.get(0) * numbers.get(1);
            int taxiCharge = numbers.get(2);
            int result = taxiCharge;
            if (busCharge < taxiCharge) {
                result = busCharge;
            }

            System.out.println(result);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 21204
/*
 * main.c
 *
 *  Created on: 2019/07/07
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
	int N = 0, D = 0, i = 0, j = 0, ans = 0;
	int count = 0;
	double ansd = 0.0;
	int X[11][10] = {0};
	scanf("%d %d", &N, &D);
	for(i = 0; i < N; i++) {
		for(j = 0; j < D; j++) {
			scanf("%d", &X[i][j]);
		}
	}
	// copy
	for(j = 0; j < D; j++) {
		X[N][j] = X[0][j];
	}


	int k = 0;
	for(k = 0; k < N; k++) {
		for(i = k+1; i < N; i++) {
			ans = 0;
			for(j = 0; j < D; j++) {
				ans += abs(X[k][j] - X[i][j]) * abs(X[k][j] - X[i][j]);
			}
			//printf("k=%d i=%d x=%d %d ans=%d\n", k,i, X[k][0], X[i][0], ans);
			ansd = sqrt((double)ans);
			if (ceil(ansd) != floor(ansd)) {
				//
			} else {
				count++;
			}
		}
	}
	printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
    string str1,str2;
    cin>>str1;
    cin>>str2;
    int ch = 0;
    for(int i=0;i <=130;i++)
    {
        if(str1 == str2)
        {
            ch = 1;
            break;
        }
        str2 = str2.substr(1,str2.size()-1)+str2[0];
    }
    if(ch)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

signed main() {
	int a; string b;
	cin >> a >> b;
	int s = 0;
	for (int c = 0; c < a; c++) {
		string d;
		cin >> d;
		if (d.length() < b.length())continue;
		for (int e = 0; e < d.length(); e++) {
			for (int f = 1; f < d.length(); f++) {
				if (e+f<d.length()&&d[e] == b[0] && d[e + f] == b[1]) {
					for (int g = 2; g < b.length(); g++) {
						if (e + f*g >= d.length() || b[g] != d[e + f*g])break;
						if (g + 1 == b.length()) {
							s++; goto l;
						}
					}
				}
			}
		}
	l:;
	}
	cout << s << endl;
} 

Measured memory_bytes: 3096
n,a,b=map(int,input().split())
m=10**9+7
def c(k):
	x = 1
	for i in range(k):
		x=x*(n-i)*pow(i+1,m-2,m)%m
	return x
print((pow(2,n,m)-c(a)-c(b)-1)%m)


Measured memory_bytes: 2940
import java.io.*;
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.StringTokenizer; 
import java.util.*;


public  class Main 
{

	   
	   static class FastReader 
	    { 
	        BufferedReader br; 
	        StringTokenizer st; 
	       
	  
	        public FastReader() 
	        { 
	            br = new BufferedReader(new
	                     InputStreamReader(System.in)); 
	        } 
	  
	        String next() 
	        { 
	            while (st == null || !st.hasMoreTokens()) 
	            { 
	                try
	                { 
	                    st = new StringTokenizer(br.readLine()); 
	                } 
	                catch (IOException  e) 
	                { 
	                    e.printStackTrace(); 
	                } 
	            } 
	            return st.nextToken();
	            
	        } 
	  
	        int nextInt() 
	        { 
	            return Integer.parseInt(next()); 
	        } 
	  
	        long nextLong() 
	        { 
	            return Long.parseLong(next()); 
	        } 
	  
	        double nextDouble() 
	        { 
	            return Double.parseDouble(next()); 
	        } 
	  
	        String nextLine() 
	        { 
	            String str = ""; 
	            try
	            { 
	                str = br.readLine(); 
	            } 
	            catch (IOException e) 
	            { 
	                e.printStackTrace(); 
	            } 
	            return str; 
	        }

			public Character charAt(int i) {
				// TODO Auto-generated method stub
				return null;
			} 
	    } 

  

	  // Complete the hurdleRace function below.
//    public static void solve() {
//    	FastReader s=new FastReader();

   
    public static void main(String[] args) throws IOException {
    	FastReader s=new FastReader();
       	int n =s.nextInt();
       	int t =s.nextInt();
       	
        if(n*500>=t)System.out.println("Yes");
        else System.out.println("No");
    }	
}





        
    

      
 

Measured memory_bytes: 32732
n = 0
a = []
b = []
c = []

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

sum = 0
tmp = 0
cc = 0

for m in range(n):
    i = a[m]
    if i-1 <=0:
        cc = 0
    elif tmp == i-1:
        cc = c[i-2]
    else:
        cc = 0
    sum += b[i-1]
    sum += cc
    tmp = i

print(sum)


Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
#define maxn 101000

LL a[maxn];
LL mymin(LL x,LL y){return (x<y)?x:y;}
LL myabs(LL x){return (x<0)?-x:x;}
int main()
{
	int n,k,i,l,r;LL sum=0,ans;
	scanf("%d%d",&n,&k);
	for (i=1;i<=n;i++) 
	{
		scanf("%lld",&a[i]);
		if (i>1 && i<=k) sum+=a[i]-a[i-1];
	}
	l=1;r=k;
	ans=sum+mymin(myabs(a[l]),myabs(a[r]));
	for (i=k+1;i<=n;i++)
	{
		l++;r++;
		sum=sum-(a[l]-a[l-1])+(a[r]-a[r-1]);
		ans=mymin(ans,sum+mymin(myabs(a[l]),myabs(a[r])));
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int n,m,k;
int main()
{
	n=read(),m=read(),k=read();
	bool check=false;
	for (int i=0;i<=n;i++)
		for (int j=0;j<=m;j++)
			if ((n-2*i)*(m-2*j)==m*n-2*k) check=true;
	if (check) cout << "Yes" << endl; else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
n,m,c = map(int,input().split())
b = list(map(int, input().split()))
cnt = 0
for i in range(n):
    s = c
    a = list(map(int, input().split()))
    for j in range(m):
        s += a[j]*b[j]
    if s>0:cnt+=1
print(cnt)

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


#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define pii pair<int,int>
#define ll long long
#define el '\n'

using namespace std;


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

    int n,k;
    cin >> n >> k;

    int maks=((n-1)*(n-2)/2);
    if (k>maks){
        cout << -1 << el;
        return 0;
    }

    vector <pii> v;
    int cnt=maks,len=0;
    for (int i=2;i<=n;i++){
        v.pb(mp(1,i));
        len++;
    }

    vector <pii> bisa;
    for (int i=2;i<n;i++){
        for (int j=i+1;j<=n;j++){
            bisa.pb(mp(i,j));
        }
    }

    int id=0,blen=bisa.size();
    while (cnt>k && id<blen){
        v.pb(bisa[id]);
        cnt--;
        len++;
        id++;
    }

    cout << len << el;
    for (auto x : v){
        cout << x.fi << " " << x.se << el;
    }

    return 0;
}

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

using namespace std;

int main()
{
    string s;
    cin >> s;
    bool TF = false;
    for(int i=0;i<s.size()-1;i++)
    {
        if(s.at(i)==s.at(i+1))
        {
            TF = true;
            break;
        }
    }

    if(TF) cout << "Bad" << endl;
    else   cout << "Good" << endl;
    return 0;
}

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

int main()
{
    int n, s[1000];

    while (cin >> n, n) {
        for (int i = 0; i < n; i++) {
            cin >> s[i];
        }
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum += s[i];
        }
        double m = 1.0 * sum / n;

        double t = 0;
        for (int i = 0; i < n; i++) {
            t += (s[i] - m) * (s[i] - m);
        }

        double a = sqrt(t / n);
        printf ("%.6f\n", a);
    }

    return 0;
}

Measured memory_bytes: 3212
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n, W, w[100], v[100];
ll dp[100][100001] = {}, mx = -1;
int main()
{
    /*freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);*/
    cin >> n >> W;
    for(int i=0; i<n; ++i)
        cin >> w[i] >> v[i];
    dp[0][0] = 0;
    dp[0][w[0]] = v[0];
    for(int i=1; i<n; ++i)
    {
        for(int j=0; j<=W; ++j)
        {
            if(j+w[i] <= W)
                dp[i][j+w[i]] = max(dp[i-1][j+w[i]], dp[i-1][j]+v[i]);
            dp[i][j] = max(dp[i][j], dp[i-1][j]);
        }
    }
    for(int i=0; i<=W; ++i)
        mx = max( mx, dp[n-1][i]);
    cout << mx;
}

Measured memory_bytes: 77568
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

h, w = inintm()
C = []

for _ in range(h):
    C.append(input())

for c in C:
    print(c)
    print(c)


Measured memory_bytes: 63160
#include "iostream"
#include <vector>
#include <array>

int main()
{
    uint32_t N, K, R, S, P;
    std::string T;
    std::cin >> N >> K >> R >> S >> P >> T;

    uint32_t score = 0;
    std::vector<bool> isWin;
    for (uint32_t i = 0; i < N; i++) {
        if (i >= K) {
            if (T[i] == T[i - K] && isWin[i - K]){
                isWin.push_back(false);
                continue;
            }
        }

        isWin.push_back(true);

        switch (T[i])
        {
        case 'r':
            score += P;
            break;
        case 's':
            score += R;
            break;
        case 'p':
            score += S;
            break;
        default:
            break;
        }
    }

    std::cout << score << std::endl;

    return 0;
}



Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.InputStreamReader;



public class Main {
	public static void main(String[] args){
		StringBuilder sb = new StringBuilder();
		try{
		sb.append(new BufferedReader(new InputStreamReader(System.in)).readLine());
		} catch (Exception e){}
		sb.reverse();
		System.out.println(sb.toString());
	}
}

Measured memory_bytes: 16844
//A,Elebereth Gilthoniel mantae!
//For Temeria!
#include<iostream>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<cstdio>
#include<map>
#include<stack>
#include<queue>
#include<cstring> 
using namespace std;
int n;int a[80];
int xabs(int x) 
{
	return max(x,-x);
}
int main()
{
 	//freopen("","r",stdin);
	//freopen("","w",stdout);
	int ma=-1,mi=0;
	cin>>n;for(int i=1;i<=n;i++) 
	{
		cin>>a[i];if(xabs(a[i])>ma) ma=xabs(a[i]),mi=i;
	}cout<<n*2<<"\n";
	if(a[mi]>0) 
	{
		cout<<mi<<" "<<n<<"\n";cout<<n<<" "<<n<<"\n";
		for(int i=2;i<=n;i++)
		{
			cout<<n<<" "<<n<<"\n";
			cout<<n<<" "<<i<<"\n";
		}
	}
	else
	{
		cout<<mi<<" "<<1<<"\n";cout<<1<<" "<<1<<"\n";
		for(int i=n-1;i>=1;i--)
		{
			cout<<1<<" "<<1<<"\n";
			cout<<1<<" "<<i<<"\n";
		}
	}
	return 0;
}

Measured memory_bytes: 256
class UnionFind():
    def __init__(self, N):
        self.rank = [0] * N
        self.par = [i for i in range(N)]
        self.counter = [1] * N

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            z = self.counter[x] + self.counter[y]
            self.counter[x], self.counter[y] = z, z
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def size(self, x):
        x = self.find(x)
        return self.counter[x]

    def same(self, x, y):
        return self.find(x) == self.find(y)

n,m = map(int,input().split())
p = list(map(int,input().split()))
uf = UnionFind(n)
for i in range(m):
    x,y = map(int,input().split())
    uf.unite(x-1,y-1)
ans = 0
for i in range(n):
    if p[i]-1 == i or uf.same(i,p[i]-1):
        ans += 1
print(ans)


Measured memory_bytes: 97260
# ANSHUL GAUTAM
# IIIT-D

from math import *
from copy import *
from string import *				# alpha = ascii_lowercase
from random import *				# l.sort(key=lambda l1:l1[0]-l1[1]) => ex: sort on the basis difference
from sys import stdin
from sys import maxsize
from operator import *				# d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter		# d = dict(Counter(l))
from collections import defaultdict # d = defaultdict(list)

'''

'''

def solve(l):
	n = len(l)
	minn = 999999999999
	for spot in range(min(l),max(l)+1):
		curr = 0
		for i in range(n):
			curr += (l[i] - spot)**2
		minn = min(minn,curr)
	return minn


N = int(stdin.readline())
l = list(map(int, stdin.readline().rstrip().split()))
ans = solve(l)
print(ans)


Measured memory_bytes: 4688
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll, ll> lltpl;



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


const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;



template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}

int main() {
	
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	int ans = 0;
	for (int i = 0; i < k; i++)
	{
		ans += a[i];
	}

	cout << ans << endl;

}


Measured memory_bytes: 256
#include<cstdio>
int n,k,i,j,l,a[1<<20];int main(){scanf("%d%d",&k,&n);if(k&1){while(j<n)a[j++]=k+1>>1;for(j=n;i<n-1;i+=2)if(--a[--j])while(++j<n)a[j]=k;while(l<j)printf("%d ",a[l++]);}else{for(;i<n;i++)printf("%d ",k/(1+!i));}}

Measured memory_bytes: 3328
<?php
list($h, $w) = ints();
if ($h === 1 || $w === 1) exit('1');
echo (intdiv($h, 2) + $h % 2) * (intdiv($w, 2) + $w % 2) + intdiv($h, 2) * intdiv($w, 2);
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 16220
n = int(input())
m = [int(i) for i in input().split()] 

i = 0
max_h = m[0]
count = 0

while i < n:
  if m[i] >= max_h:
    count += 1
  max_h = max(max_h, m[i])
  i += 1
  
print(count)
  
  


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <bitset>
using namespace std;

int n,i,j,k,sum,A;

bitset<4000005> B;

int main()
{
	scanf("%d",&n);
	B[0]=1;
	for(i=1;i<=n;++i)
	{
		scanf("%d",&A);sum+=A;
		B|=B<<A;
	}
	for(i=sum/2+sum%2;!B[i];++i);
	printf("%d\n",i);
}

Measured memory_bytes: 1664
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(int argc, char *argv[])
{
  int n, q, m, i, j;
  int *A;
  int sum[40000], p, bits, tmp;

  scanf("%d", &n);
  A = (int *)malloc(sizeof(int) * n);
  for (i = 0; i < n; i++) scanf("%d", &A[i]);

  for (i = 0; i < 40000; i++) sum[i] = 0;

  p = (int)pow(2, n);

  for (i = 1; i < p; i++) {
    bits = i;
    tmp = 0;
    for (j = 0; j < n; j++, bits = bits >> 1) {
      if ((bits & 0x00000001) == 1) tmp += A[j];
    }
    sum[tmp] = 1;
  }

  scanf("%d", &q);

  for (i = 0; i < q; i++) {
    scanf("%d", &m);
    if (sum[m] == 1) printf("yes\n");
    else printf("no\n");
  }

  return 0;
}

Measured memory_bytes: 776
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        h: usize,
        w: usize,
        n: usize
    }
    println!("{}", (n - 1) / max(h, w) + 1);
}


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

int main() {
    int n, m; cin >> n >> m;
    int sum = 0;
    for (int i = 0; i < m; i++) {
        int a; cin >> a;
        sum += a;
    }
    int ans = max(-1, n - sum);
    cout << ans << endl;
}

Measured memory_bytes: 3160
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# 初項s, 交差dのn個の数列の和
def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def main():
    K, X = map(int, input().split())
    ans = []
    for i in range(X, X + K):
        ans.append(i)

    for i in range(X - K + 1, X):
        ans.append(i)

    print(*sorted(ans))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3944
import math,sys
sys.setrecursionlimit(1000000)
def mygcd(x,y):
    if x<y:x,y=y,x
    if y==0:return x
    return mygcd(y,x%y)
def is_prime(n):
    if n==1:return True
    for i in range(2,int(math.sqrt(n))+1):
        if n%i==0:return False
    return True
A,B = map(int,input().split())
gcd = mygcd(A,B)
C = []
for i in range(1,gcd+1):
    if i*i>gcd:break
    if gcd%i==0:
        C.append(i)
        if i!=gcd//i:
            C.append(gcd//i)
cnt = 0
for c in C:
    if is_prime(c):cnt+=1
print(cnt)

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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var hs = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var memo = new List<int>(Enumerable.Range(0,N).Select(s=>int.MaxValue));
            Action<List<int>, int, int> chmin =
                (ls, index, val) =>
            {
                if (val < ls[index]) ls[index] = val;
            };
            memo[0] = 0;
            for (var i=1;i<N;i++)
            {
                chmin(memo, i, Math.Abs(hs[i - 1] - hs[i]) + memo[i - 1]);
                if(1<i)
                    chmin(memo, i, Math.Abs(hs[i - 2] - hs[i]) + memo[i - 2]);
            }
            Console.WriteLine(memo[N-1]);
        }
    }
}


Measured memory_bytes: 18784
#include <bits/stdc++.h>
#define prt_cs                  printf("Case %lld: ",cs)
#define sqr(x)                  (x)*(x)
#define ms(a,b)                 memset(a, b, sizeof(a))
#define db                      double
#define ll                      long long int
#define MOD                     100000007
#define PI                      acos(-1.0)
#define pii                     pair< int, int >
#define READ                    freopen("in.txt","r",stdin)
#define WRITE                   freopen("out.txt","w",stdout)
#define gcd(a, b)               __gcd(a, b)
#define lcm(a, b)               (((a)*(b))/gcd(a,b))
#define MAX                     100005

using namespace std;

char graph[1001][1001];
int dx[]={1,-1,0,0,1,1,-1,-1,2,2,-2,-2,2,2,-2,-2,1,1,-1,-1,-2,2,0,0};
int dy[]={0,0,1,-1,1,-1,1,-1,2,-2,2,-2,1,-1,-1,1,2,-2,2,-2,0,0,-2,2};
int vis[1001][1001];

int h,w;

int bfs(int sx,int sy,int tx,int ty)
{
    priority_queue<pair<int,pair<int,int>>> pq;
    pq.push({0,{sx,sy}});
    while(!pq.empty())
    {
        pii u = pq.top().second;
        int dd=-pq.top().first;
        pq.pop();
        for(int i=0;i<24;i++)
        {
            int ttx = u.first+dx[i];
            int tty = u.second+dy[i];
            if(ttx<=0 || ttx>h || tty<=0 || tty>w || graph[ttx][tty]=='#')continue;
            if(vis[ttx][tty]==-1 || dd+(i>=4)<vis[ttx][tty])//continue;
            {
                vis[ttx][tty]=dd+(i>=4);
//                if(i>=4)vis[ttx][tty]=dd+1;
                pq.push({-vis[ttx][tty],{ttx,tty}});
            }
        }
    }
    return vis[tx][ty];
}


int main()
{
//    READ;
//    WRITE;
    ms(vis,-1);
    int ch,cw;
    int dh,dw;
    scanf("%d %d",&h,&w);
    scanf("%d %d",&ch,&cw);
    scanf("%d %d",&dh,&dw);
    for(int i=1;i<=h;i++)
        for(int j=1;j<=w;j++)
        {
            cin>>graph[i][j];
        }
    int ans=bfs(ch,cw,dh,dw);
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 8720
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
char a[105];
int n,x=0,d=0;
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d%s",&n,a+1);
    for(int i=1;i<=n;++i)
    {
        if(a[i]=='I')  ++x;
        else    --x;
        d=max(d,x);
    }
    cout<<d;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;
int main(){
  ll n;
  cin>>n;
  vector<char> c(n);
  rep(i,n) cin>>c[i];
  ll red=0;
  rep(i,n){
    if(c[i]=='R') red++;
  }
  ll ans=0;
  rep(i,red){
    if(c[i]=='W') ans++;
  }
  cout<<ans;
return 0;
}

Measured memory_bytes: 3624
from bisect import bisect_left
q=int(input())
query=[input() for _ in range(q)]
l,r=-pow(10,9),pow(10,9)
ary=[-float('inf')]
for qq in query:
    if qq[0]=='1':
        _,a,b=map(int,qq.split())
        ary.append(a)
ary.append(float('inf'))
ary.sort()

class SegmentTree():
    def __init__(self,size,segfunc=lambda x,y:x+y,default=0):
        self.segfunc=segfunc
        self.default=default
        self.size=pow(2,(size-1).bit_length())
        self.data=[default]*(self.size*2)
    def update(self,i,v):
        i+=self.size
        self.data[i]=v
        while i:
            i>>=1
            self.data[i]=self.segfunc(self.data[2*i],self.data[2*i+1])
    # 区間[l,r)に対するクエリ
    def query(self,l,r):
        l+=self.size
        r+=self.size
        lres,rres=self.default,self.default
        while l<r:
            if l&1:
                lres=self.segfunc(lres, self.data[l])
                l += 1
            if r&1:
                r-=1
                rres=self.segfunc(self.data[r],rres)
            l>>=1
            r>>=1
        res=self.segfunc(lres,rres)
        return res
    def get(self,i):
        return self.data[self.size+i]
    def add(self,i,v):
        self.update(i,self.get(i)+v)
    
#ary[0],ary[-1]
ml,mr=0,len(ary)+1
mv=0
st=SegmentTree(len(ary))
for qq in query:
    if qq[0]=='2':
        print(ary[ml],mv)
    else:
        _,a,b=map(int,qq.split())
        a=bisect_left(ary,a)
        st.add(0,-1)
        st.add(a,2)
        if ml<=a<mr:
            mv+=b
            ml,mr=a,a+1
        else:
            l,r=0,len(ary)+1
            mv+=b
            while r-l>1:
                x=(l+r)//2
                chk=st.query(0,x)
                if chk>=0:
                    l,r=l,x
                else:
                    l,r=x,r
            l0,r0=l,r
            l,r=ml,len(ary)+1
            while r-l>1:
                x=(l+r)//2
                chk=st.query(0,x)
                if chk>0:
                    l,r=l,x
                else:
                    l,r=x,r
            mv+=min(abs(ary[ml]-ary[l0]),abs(ary[mr]-ary[l0]))+abs(ary[a]-ary[l0])
            mr=l if st.query(0,l+1)>0 else l+1
            ml=l0 if st.query(0,l0+1)>=0 else l0+1



Measured memory_bytes: 116732
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

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

int main(int argc, const char * argv[]) {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int A, B, C;
    
    cin >> A >> B >> C;
    
    int ans = max(C - (A-B), 0);
    
    cout << ans << endl;
    
    
    return 0;
}

Measured memory_bytes: 888