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

int main(){
    double pai=3.141592653589;
    int n,taro=0,hanako=0;
    char t[100],h[100];
    string tarostr,hanakostr;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%s %s",&t,&h);
        tarostr=t;
        hanakostr=h;
        if(tarostr==hanakostr){
            taro++;
            hanako++;
        }else if(tarostr<hanakostr){
            hanako+=3;
        }else{
            taro+=3;
        }
    }
    printf("%d %d\n",taro,hanako);
    return 0;
}


Measured memory_bytes: 3272
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
   for (int i = 0; i < N; i++) {
     cin >> vec.at(i);
   }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int x = 0;
   for (int i = 0; i < N; i++) {
     x ++;
     if (i > 0 && vec.at(i) == vec.at(i-1))
       x--;
   }
  cout << x << endl;
}

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

string s;

int main() {
    cin >> s;
    long long ans = 0;
    int cur = 0, pos = 0;
    while (pos < s.length()) {
        if (s[pos] == 'A') {
            cur++, pos++;
        } else if (pos + 1 < s.length() && s[pos] == 'B' && s[pos + 1] == 'C') {
            ans += cur, pos += 2;
        } else {
            cur = 0, pos++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const long long INFL=1LL << 60;
const long long INF=1<<30;

int main() {
    int n;
    cin >> n;
    vector<int> R(n);
    for(int i=0;i<n;i++){
        cin >> R.at(i);
    }    
    int minr=R.at(0);
    int maxv=-INF;
    for(int i=1;i<n;i++){
        maxv=max(maxv,R.at(i)-minr);
        minr=min(R.at(i),minr);
    }
    cout << maxv<<endl;
    return 0;
}


Measured memory_bytes: 3552
using System;

namespace ABC148
{
    class Program
    {
        static void Main(string[] args)
        {
            var answers = new int[] { 1, 2, 3 };

            var inputs = new int[2];
            for (int i = 0; i < 2; i++)
            {
                inputs[i] = int.Parse(Console.ReadLine());
            }

            foreach(var answer in answers)
            {
                if (Array.IndexOf(inputs,answer) < 0)
                {
                    Console.WriteLine(answer);
                    break;
                }
            }
            //Console.ReadLine();
        }
    }
}


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

int main() {
  vector<char> a(3);
  cin >> a.at(0) >> a.at(1) >> a.at(2);
  vector<char> b(3);
  cin >> b.at(0) >> b.at(1) >> b.at(2);
  if(a.at(0) == b.at(2) && a.at(1) == b.at(1) && a.at(2) == b.at(0)){
    cout << "YES" <<endl;
  }
  else{
    cout << "NO" <<endl;
  }
}



Measured memory_bytes: 256
gets
r=1
v=nil
gets.scan(/((.)\2?)/).map{|a,b|
  x=a.size
  x==1 ? (
    r*=1 if v==2
    r*=2 if v==1
    r*=3 if v==nil
  ) : (
    r*=2 if v==1
    r*=3 if v==2
    r*=6 if v==nil
  )
  v=x
  r%=10**9+7
}
p r

Measured memory_bytes: 3836
table=[[[0]*10 for a in range(3)] for b in range(4)]

n=int(input())

for c in range(n):
    house,floor,room,add=map(int, input().split())
    table[house-1][floor-1][room-1] += add

for d in range(4):
    if d != 0:
        print("#"*20)
    for e in range(3):
        for f in range(10):
            print(" %d" %(table[d][e][f]), end="")
        print()



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

int main()
{
    string S;
    cin >> S;

    if (S[0] != S[1] || S[1] != S[2])
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


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

template <typename T>
T sum_of_floor_of_linear(const T &n, const T &m, T a, T b) {
    T ret = 0;
    if (a >= m) ret += (n - 1) * n * (a / m) / 2, a %= m;
    if (b >= m) ret += n * (b / m), b %= m;
    T y = (a * n + b) / m;
    if (y == 0) return ret;
    T x = y * m - b;
    ret += (n - (x + a - 1) / a) * y;
    ret += sum_of_floor_of_linear(y, a, m, (a - x % a) % a);
    return ret;
}

using i64 = int64_t;

void solve() {
    i64 n, m, a, b;
    cin >> n >> m >> a >> b;
    cout << sum_of_floor_of_linear(n, m, a, b) << '\n';
}

int main() {
    int t;
    cin >> t;
    while (t--) solve();
}

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

const int MOD = 1000000007;

// begin() end()
#define all(x) (x).begin(),(x).end()

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

//最小公倍数
int lcm(int number1,int number2){
	return number1 * number2 / gcd(number1,number2);	
}
  
void add(long long &a, long long b) {
  a += b;
  if (a >= MOD) a -= MOD;
}

int main(){
string S;
cin >> S;

long long dp[210000][5];
dp[0][0] = 1;
REP(i,S.size()){
    REP(j, 5){
        if(S[i] != '?') add(dp[i+1][j], dp[i][j]);
        else add(dp[i+1][j], dp[i][j] * 3 % MOD);
    }
if(S[i] == 'A' || S[i] == '?') add(dp[i + 1][1], dp[i][0]);
if(S[i] == 'B' || S[i] == '?') add(dp[i + 1][2], dp[i][1]);
if(S[i] == 'C' || S[i] == '?') add(dp[i + 1][3], dp[i][2]);



}

cout << dp[S.size()][3] << endl; 
}

Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<typename T> using v2 = vector<vector<T>>;
template<typename T> using v3 = vector<vector<vector<T>>>;
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
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; }
const int MOD = 1e9 + 7;
const int INF = 1e9 + 200;
const ll INFLL = 2e18 + 200;

int main() {
    int L, R, d;
    cin >> L >> R >> d;
    int cnt = 0;
    for (int i = L; i <= R; i++) {
        if (i % d == 0) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3624
#include <stdio.h>

int main(void){
	char s[3];
  int i=0;
  scanf("%s",s);
  
  int count = 0;
  for(i=0;i<3;i++){
	if(s[i] == '1'){
		count++;
    }
  }
	printf("%d",count);	
	
  
return 0;

}

Measured memory_bytes: 128
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        int n = Integer.parseInt(bf.readLine());
        int[] a = new int[2*n];
        String s = bf.readLine();
        for(int i=0; i<2*n; i++) a[i] = (s.charAt(i)=='B')?1:0;
        for(int i=1; i<2*n; i+=2) a[i] = 1-a[i];
        int count = 0;
        int mod = 1000000007;
        long ans = 1;
        for(int i=0; i<2*n; i++) {
          if(a[i] == 1) count++;
          else {
            ans *= count;
            count--;
            ans %= mod;
          }
        }
        for(int i=1; i<=n; i++) {
          ans *= i;
          ans %= mod;
        }
        if(count != 0) out.println(0);
        else out.println(ans);
        // StringTokenizer st = new StringTokenizer(bf.readLine());
        // int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());
        // int n = Integer.parseInt(st.nextToken());

        out.close(); System.exit(0);
    }
}


Measured memory_bytes: 27924
n = gets.to_i
a = gets.split.map &:to_i; b = Array.new
n.times do |now|
  if n % 2 == 0
    now % 2 == 0 ? b.push(a[now]) : b.unshift(a[now])
  else
    now % 2 == 0 ? b.unshift(a[now]) : b.push(a[now])
  end
end
puts b.join(" ")


Measured memory_bytes: 25440
package main

import (
	"bufio"
	"fmt"
	"log"
	"math"
	"os"
	"sort"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)
var buff []byte

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buff, bufio.MaxScanTokenSize*1024)
	log.SetFlags(log.Lshortfile)
}

var RED int = 1
var GREEN int = 2
var RESPECT int = 4

func main() {
	X := nextInt()
	Y := nextInt()
	A := nextInt()
	B := nextInt()
	C := nextInt()
	apples := make([]Pair, A+B+C)
	for i := 0; i < A; i++ {
		apples[i].a = nextInt()
		apples[i].b = RED
	}
	for i := A; i < A+B; i++ {
		apples[i].a = nextInt()
		apples[i].b = GREEN
	}
	for i := A + B; i < A+B+C; i++ {
		apples[i].a = nextInt()
		apples[i].b = RESPECT
	}
	sort.Sort(Pairs(apples))
	var happy int
	var a, b, c int
	for i := 0; i < A+B+C; i++ {
		switch apples[i].b {
		case RED:
			if a < X {
				happy += apples[i].a
				a++
			}
		case GREEN:
			if b < Y {
				happy += apples[i].a
				b++
			}
		case RESPECT:
			if a+b+c < X+Y {
				happy += apples[i].a
				c++
			}
		}
		if a+b+c >= X+Y {
			break
		}
	}
	fmt.Println(happy)
}

func reverse(ints []int, n int) []int {
	for i := 0; i < n/2; i++ {
		ints[i], ints[n-1-i] = ints[n-i-1], ints[i]
	}
	return ints
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextFloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextInts(n int) (r []int) {
	r = make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b > p[j].b
	}
	return p[i].a > p[j].a
}


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

using namespace std;

#define ll long long

//iostream::sync_with_stdio(false);

int main()
{
    ll n;
    int p = 26,i = 0, s[10005];
    cin >> n;
    while (n != 0)
    {
        n--;
        s[i] = n % p;
        i++;
        n = n / p;
    }
    i--;
    while(i >= 0)
    {
        printf("%c",s[i] + 'a');
        i--;
    }
    cout << endl;
    return 0;
}






Measured memory_bytes: 3656
#include<iostream>
#include<vector>
#include<sstream>
#include<string>
#include<numeric>
#include <algorithm>
#include<math.h>
#include<cstdio>
#include<string.h>
#include<unistd.h>
#include <array>
#include <map> 




using namespace std;
typedef long long ll;
struct point{
  int x;
  int y;

};
int gcd(int a, int b)
{
	return a == 0 ? b : gcd(b % a, a);
}
int lcm( int m, int n )
{
	// 引数に０がある場合は０を返す
	if ( ( 0 == m ) || ( 0 == n ) )
		return 0;
	
	return ((m / gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}//lcm
int input(){
  int x;
  cin>>x;
  return x;
}

int moji(char in)
{
    int ans = (int)in-(int)'a';
    if((ans < 0) || (ans > 25)){
        ans = 26;
    }
    return ans;
}
const int VV=10;//場合に応じてVVの値のみ変更する必要あり
//dijkstra(s)sがスタート地点でそこからの最短距離を配列dで表す。正の重みのみ使用可能
int cost[VV][VV];
int d[VV];
bool used[VV];
void dijkstra(int s){
  fill(d,d+VV,100000);
  fill(used,used+VV,false);
  d[s]=0;
  while(true){
    int v=-1;
    for(int u=0;u<VV;u++){
      if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
    }
    if(v==-1)break;
    used[v]=true;
    for(int u=0;u<VV;u++){
      d[u]=min(d[u],d[v]+cost[v][u]);
    }
  }

}

int compare_int(const void *a, const void *b)//qsort(quick sort利用時に使用)
{
    return *(int*)a - *(int*)b;
}

int binary_searchh(long long x,long long k[],int n){
  int l=0;
  int r=n;
  while(r-l>=1){
    int i=(l+r)/2;
    if(k[i]==x)return i;
    else if(k[i]<x)l=i+1;
    else r=i;
  }
  return -1;
}

struct File {
    int aa;
    int bb;

    File(const int& aa, const int& bb)
        : aa(aa), bb(bb) {}
};

bool operator<(const File& a, const File& b)
{
    // ファイル種別、ファイル名の順番で優先順位を付けて比較
    return std::tie(a.aa, a.bb) < std::tie(b.aa, b.bb);
}

long long kaijo(long long x){
  long long l=10*10*10*10*10*10*10*10*10+7;
  long long sum=1;
  for(int i=x;i>0;i--){
    sum*=i;
    if(sum>l){
      sum%=l;
    }
  }
  return sum;
}






int main(){
  long long x;
  cin>>x;
  long long sum=0;
  if(x%11>6){
    sum+=x/11;
    cout<<2*sum+2<<endl;
  }else if(x%11>0){
    sum+=x/11;
    cout<<2*sum+1<<endl;
  }else{
    cout<<2*x/11<<endl;
  }
  



}


Measured memory_bytes: 256
#include <iostream>
#include<algorithm>
#include<vector>
#include<string>
#include <cmath>
#include <iomanip>
#include <math.h>
#include <numeric>
#include <utility>
using namespace std;

int main() {
	int n;
	cin >> n;
	cout << 180 * (n - 2) << endl;
	return 0;
}

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

int main(){
    
    int n;
    cin >> n;
    while(n!=0){
        
        double st[n] ={};
        double sum=0,a=0;

        for (int i=0;i<n;i++){
            cin >> st[i];
            sum += st[i];
        }
        for (int j=0;j<n;j++){
            a += (st[j] - (sum/n))*(st[j] - (sum/n))/n;
        }
        
        

        printf("%.5f\n",sqrt(a));
        cin >> n;
        
    }
    
    return 0;
}


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

const int N = 1 << 17;
int cnt[N];

int main()
{
    int n, c;
    long long ans = 0;
    cin >> n >> c;
    for (int i = 1; i <= n; i++)
        for (int j = 0; j <= n; j += i)
        {
            if (j + i - 1 <= n)
                ans += max(i - c, 0);
            else
                ans += max(n + 1 - j - c, 0);
        }
    if (c == 0) ans -= n;
    // for (int i = 1; i <= n; i++) cout << cnt[i] << endl;

    cout << ans << endl;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n,k=map(int, input().split())
    l=list(map(int,input().split()))
    cnt=0
    while True:
        if n<=k:
            cnt+=1
            print(cnt)
            break
        n -= k
        n += 1
        cnt += 1
resolve()

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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> city( N, 0 );
  int a, b;
  for ( int i = 0; i < M; i++ ) {
    cin >> a >> b;
    city.at( a - 1 )++;
    city.at( b - 1 )++;
  }
  for ( int i = 0; i < N; i++ )
    cout << city.at( i ) << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int n,b;
    int ans=0;
    cin>>n;
    while(n>0) {
      b=n%10;
      if(b==7)  { ans=1; break; }
      n=n/10;  
    }
    if(ans==0) cout<<"No";
    else cout<<"Yes";
}


Measured memory_bytes: 3596
#include<stdio.h>
#include <stdlib.h>
#include <math.h>
int main(){
	
	int X;
	scanf("%d",&X);
	
	int maximum = 0;
	for(int i=1;i<33;i++){
		for(int j=2;j<11;j++){
			int a = 1;
			for(int k=0;k<j;k++){
				a*=i;
			}
			
			
			
			if(a<=X&&a>=maximum){
				maximum = a;
			}
		}
	}
	
	
	printf("%d",maximum);
	
	
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<queue>
#include<string>
using namespace std;
struct Kaeru { char b[10][10]; int px, py, dir; string F; };
int dx[4] = { -1,0,1,0 }, dy[4] = { 0,1,0,-1 };
queue<Kaeru>Q; int H, W; char x[10][10]; int cx, cy, cd = 0;
char CC[5] = "URDL";
int main() {
	cin >> H >> W;
	while (!Q.empty())Q.pop(); int CNT = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cin >> x[i][j]; if (x[i][j] == 'o')CNT++;
			if (x[i][j] == 'U') { cx = i; cy = j; cd = 0; x[i][j] = '.'; }
			if (x[i][j] == 'R') { cx = i; cy = j; cd = 1; x[i][j] = '.'; }
			if (x[i][j] == 'D') { cx = i; cy = j; cd = 2; x[i][j] = '.'; }
			if (x[i][j] == 'L') { cx = i; cy = j; cd = 3; x[i][j] = '.'; }
		}
	}
	Kaeru D; for (int i = 0; i < 100; i++)D.b[i / 10][i % 10] = x[i / 10][i % 10];
	D.px = cx; D.py = cy; D.dir = cd; D.F = ""; Q.push(D);
	while (!Q.empty()) {
		Kaeru a1 = Q.front(); Q.pop();
		Kaeru a2 = a1;
		if (a2.F.size() == CNT) { cout << a2.F << endl; break; }

		for (int i = 0; i < 4; i++) {
			a2 = a1; char y[10][10]; for (int j = 0; j < 100; j++)y[j / 10][j % 10] = a2.b[j / 10][j % 10];
			if (i == (a1.dir + 2) % 4)continue;
			int ex = a2.px, ey = a2.py;
			while (true) {
				ex += dx[i]; ey += dy[i];
				if (ex < 0 || ey < 0 || ex >= H || ey >= W)break;
				if (y[ex][ey] == 'o') {
					y[ex][ey] = '.';
					for (int j = 0; j < 100; j++)a2.b[j / 10][j % 10] = y[j / 10][j % 10];
					a2.px = ex; a2.py = ey; a2.dir = i; a2.F += CC[i];
					Q.push(a2); break;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 4224
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 1e18;
const double PI = acos(-1);
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }

typedef pair<int, int> P;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	int DN = N - (N % 2);
	vector<P> ans;
	REP(i, N) {
		FOR(j, i + 1, N) {
			if (j == DN - i - 1) {
				continue;
			}
			ans.push_back(P(i, j));
		}
	}
	cout << SZ(ans) << endl;
	REP(i, SZ(ans)) {
		cout << ans[i].first + 1 << " " << ans[i].second + 1 << endl;
	}
	return 0;
}


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

const int maxn=2e6,p=1e9+7;
int x,y;
long long fac[maxn],inv[maxn];

long long poww(long long x,long long y)
{
	long long ans=1,tmp=x;
	while(y) {
		if(y&1) ans=ans*tmp%p;
		tmp=tmp*tmp%p;
		y>>=1;
	}
	return ans;
}

long long c(int x,int y)
{
	return (((fac[x]*inv[y])%p)*inv[x-y])%p;
}

int main()
{
	scanf("%d %d",&x,&y);
	if((
	x+y)%3!=0) {
		printf("0");
		return 0;
	}
	int n=(2*x-y)/3,m=(2*y-x)/3;
	if(n<0||m<0) {
		printf("0");
		return 0;
	}
	fac[0]=1;inv[0]=1;
	for(int i=1;i<maxn;++i) fac[i]=fac[i-1]*i%p;
	inv[maxn-1]=poww(fac[maxn-1],p-2);
	for(int i=maxn-2;i>=1;--i) inv[i]=inv[i+1]*(i+1)%p; 
	printf("%lld",c(n+m,n)); 
}

Measured memory_bytes: 31488
N, K, Q = map(int, input().split())
A = [None] + [0] * N
for _ in range(Q):
    ai = int(input())
    A[ai] += 1

p = [K - (Q - ai) for ai in A[1:]]

for pi in p:
    print('YNeos'[pi < 1::2])

Measured memory_bytes: 8932
import sys
l = []
max_c = 0
n = []
for i in sys.stdin.readlines():
  l.append(int(i))
  if l.count(int(i)) == max_c:
    n.append(int(i))
  elif l.count(int(i)) > max_c:
    n = [int(i)]
    max_c = l.count(int(i))
n.sort()
for i in n:
  print(i)

Measured memory_bytes: 7500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	int n;
	cin >> n;
	int mx, ans = 0;
	vector<int> a(n);
	forn(i, n) cin >> a[i];
	sort(all(a));
	mx = a.back();
	vector<char> pr(mx+1, true);
	for(int i = 0; i < n; i++) {
		if(pr[a[i]]) {
			for(int j = 1; j * a[i] <= mx; j++) {
				pr[a[i]*j] = false;
			}
			if(i == n-1 || a[i] != a[i+1]) ans++;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 5104
/*input
3 1 8
*/
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
using ll = long long;
using ld = long double;
using pii = pair<ll,ll>;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const ll INF64=4e18;
const int INF=1e6+1;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
ll sub(ll a,ll b){
    ll x=a-b;
    while(x<0) x+=MOD;
    while(x>MOD) x-=MOD;
    return x;
}
ll mult(ll a,ll b){
    return ((a%MOD)*(b%MOD))%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=(res*a);
        if(res>1e10) return 1e11;
        a=(a*a);
        b>>=1;
    }
    return res;
}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
ll arr[maxn],f[maxn];
int main(){
    double a,b,x;
    cin>>a>>b>>x;
    if(x<(a*a*b)/2) cout<<fixed<<setprecision(10)<<90-atan(2.0*x/(a*b*b))/PI*180;
    else cout<<fixed<<setprecision(10)<<(atan(2.0*(a*a*b-x)/(a*a*a))/PI)*180;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

ll compute(vector<ll> &a){
	int n = a.size();
	ll sum = 0; ll ret = 0;
	for(int i = 0; i < n; i++){
		sum += a[i];
		if(i&1){
			if(sum >= 0){
				ret += sum + 1;
				sum = -1;
			}
		}else{
			if(sum <= 0){
				ret += abs(sum) + 1;
				sum = 1;
			}
		}
	}
	return ret;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n; cin>>n;
	vector<ll> a(n);
	for(auto &x : a){
		cin>>x;
	}
	ll ans = compute(a);
	for(auto &x : a){
		x = -x;
	}
	ans = min(ans, compute(a));
	cout<<ans<<endl;


	return 0;
}

Measured memory_bytes: 1024
while True: 
    n, k = map(int, input().split())
    if n == 0: break
    a = [int(input()) for _ in range(n)]

    cs = [0]*(n+1)
    for i in range(n):
        cs[i+1] = cs[i] + a[i]

    ans = -10**16
    for i in range(n-k+1):
        ans = max(ans, cs[i+k]-cs[i])

    print(ans)


Measured memory_bytes: 13420
#include <iostream>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <algorithm>
#include <cassert>
#include <string>
#include <climits>
#include <numeric>

using namespace std;
using ll = long long;

int main()
{
	int n;
	double a, t;
	cin >> n >> t >> a;
	int h[n];
	for (int i = 0; i < n; ++i)
		cin >> h[i];

	double min = 999999;
	int p = -1;
	for (int i = 0; i < n; i++) {
		double tmp = t - a - h[i] * 0.006;
		if (tmp < 0) tmp = -tmp;
		if (tmp < min) {
			min = tmp;
			p = i+1;
		}
	}

	assert(p != -1);
	cout << p << endl;
}



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

int main(){
  string s,t;
  cin >> s >> t;
  sort(s.begin(),s.end());
  sort(t.begin(),t.end());
  reverse(t.begin(),t.end());
  if(s<t){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as B
import Data.Maybe
import Data.List
f _ _ _ [] _ = 0
f x y (a:as) bs@(b:_) cs | a < b = f (x+1) y as bs cs
f x y as bs@(b:_) (c:cs) | c <= b = f x (y-1) as bs cs
f x y as (b:bs) cs = x * y + f x y as bs cs
main = do
  n <- readLn
  let s = sort . map (fst . fromJust . B.readInt) . B.words <$> B.getLine
  print =<< f 0 n <$> s <*> s <*> s

Measured memory_bytes: 47484
#include<stdio.h>

int main(void){
    int n,x,i,l,sum=0,ans=1;
    scanf("%d %d",&n,&x);
    for(i=0;i<n;i++){
        scanf("%d",&l);
        sum+=l;
        if(sum<=x){
            ans++;
        }
    }
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 128
n = int(input())
h = [int(hi) for hi in input().split()]

inf = float('inf')

dp = [inf] * n

dp[0] = 0

for i in range(n):
  dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
  dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]))

print(dp[-1])



Measured memory_bytes: 13928
#include <iostream>
#include <cmath>
using namespace std;
int main(){
	int num=0;
	string s;
	while(getline(cin,s)){
		for(int i=s.size()-1,n=0;i>=0;--i){
			if('0'<=s[i]&&s[i]<='9') num+=(s[i]-'0')*pow(10,n++);
			else n=0;
		}
	}
	cout<<num<<endl;
	return 0;
}

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

ll gcd(ll a, ll b){
  return a%b ? gcd(b, a%b) : b;
}

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

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <sstream>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef vector <int> vi;
typedef vector <vector <int>> vii;
typedef vector <long long> vll;
typedef vector <string> vs;
typedef vector <char> vc;
typedef set <int> si;
typedef set <string> ss;
typedef queue <int> qi;
typedef queue <long long> qll;
typedef queue <string> qs;
typedef queue <char> qc;
typedef struct board board;
typedef pair <int, int> pi;
typedef pair <long long, long long> pll;
typedef pair <int, pair<int, int>> pii;

#define eb emplace_back
#define ppb pop_back
#define clr(a) a.clear()
#define F first
#define S second
#define mkp make_pair

#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()

#define left(x) x * 2
#define right(x) x * 2 + 1

#define meme(a, b, c) fill(a + 1, a + 1 + b, c)

#define max(a, b) (a > b ? a : b)
#define min(a, b) (a > b ? b : a)
#define abs(a) (a > 0? a : -(a))

#define move(s) s += "#"

#define eprintf(...) fprintf(stderr, __VA_ARGS__);

template <typename T>
void printArr(const T * arr, int s, int fn) {
    for (int i = s; i <= fn; ++ i) cout << arr[i] << " ";
    cout << '\n';
}

template <typename T>
long long minArr(const T * arr, int s, int fn) {
    ll res = 1e16 + 1;
    for (int i = s; i <= fn; ++ i) {
        res = min(res, arr[i]);
    }
    return res;
}

template <typename T>
void printVec(const T * arr) {
    for (int i = 0; i < sz(arr); ++ i) cout << arr[i] << " ";
    cout << '\n';
}

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

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

void to_pray() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cerr << "Ready\n";
}

const int N = 1e5 + 10;
const int NN = 1e3 + 10;
const int NNN = 2e3 + 9;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll LLINF = 1e12 + 7;
const int EPS = 1e-9 - 8;
const int vN = 2e4 + 10;
const int sz = (1 << 22) - 1;
const double PI = acos(-1);

int main () {
    to_pray();

    ll n;
    cin >> n;

    ll ans = (n * (n - 1)) / 2;

    cout << ans;

    //eprintf("%.18lf seconds\n", (double)clock() / CLOCKS_PER_SEC);

    cout << '\n';
    
    return 0;
}

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

#define MAX 100000

int main() {
	int N;
	cin >> N;
	int t[MAX + 1], x[MAX + 1], y[MAX + 1];
	t[0] = 0;
	x[0] = 0;
	y[0] = 0;
	for (int i = 1; i <= N; i++) {
		cin >> t[i] >> x[i] >> y[i];
	}
	bool flg = true;
	for (int i = 1; i <= N; i++) {
		int dt = abs(t[i] - t[i - 1]);
		int dx = abs(x[i] - x[i - 1]);
		int dy = abs(y[i] - y[i - 1]);
		if (dx + dy > dt || (dx + dy) % 2 != dt % 2) {
			flg = false;
			break;
		}
	}
	cout << (flg ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 1408
function main(lines) {
  const N = +lines[0];
  
  let res;
  
  for (let i = 1000; i <= 10000; i += 1000) {
    if (i >= N) {
      res = i - N;
      break;
    }
  }
  
  console.log(res);
}


main( require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n") );



function splitN(s) {
  return s.split(' ').map(Number);
}


Measured memory_bytes: 29692
# 問題：https://atcoder.jp/contests/abc136/tasks/abc136_b

n = int(input())
ln_n = len(str(n))
if ln_n % 2 == 0:
    n = 10 ** (ln_n - 1) - 1

res = 0
for i in range(1, ln_n):
    if i % 2 == 1:
        res += 10 ** i - 10 ** (i - 1)
res += n + 1 - 10 ** (ln_n - 1)

print(res)


Measured memory_bytes: 9208
#include<bits/stdc++.h>
using namespace std;
#define fine cout<<"fine"<<endl;
#define ll long long int
#define pb push_back
#define FASTIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
const ll inf=(ll)2e18;
const int mod=1e9+7;
bool overflow(ll a,ll b){
    if (a <= (inf+b-1)/b) return false;
    return true;
}
int h,w;
int visited[20][20];
int dist[20][20];
int xi[]={1,-1,0,0};
int yi[]={0,0,1,-1};
string s[20];
bool isvalid(int i,int j){
    return (i<h&&j<w&&i>=0&&j>=0&&s[i][j]!='#');
}
int maxi=0;
void bfs(int k,int srci,int srcj,int desti,int destj){
    queue<pair<int,int> > q;
    q.push({srci,srcj});
    dist[srci][srcj]=0;
    while(q.size()){
        int x=q.front().ff;
        int y=q.front().ss;
        if(x==desti&&y==destj){
            maxi=max(maxi,dist[x][y]);
            break;
        }
        for(int j=0;j<4;j++){
            if(isvalid(x+xi[j],y+yi[j])&&visited[x+xi[j]][y+yi[j]]!=k){
                visited[x+xi[j]][y+yi[j]]=k;
                dist[x+xi[j]][y+yi[j]]=dist[x][y]+1;
                q.push({x+xi[j],y+yi[j]});
            }
        }
        q.pop();
    }
}
int main(){
FASTIO;
int i,j,k=1,p,q;
cin>>h>>w;
for(i=0;i<h;i++){
    cin>>s[i];
}
for(i=0;i<h;i++){
    for(j=0;j<w;j++){
        if(s[i][j]=='.'){
            for(p=i;p<h;p++){
                for(q=0;q<w;q++){
                    if(s[p][q]=='.')
                        bfs(k++,i,j,p,q);
                }
            }
        }
    }
}
cout<<maxi<<endl;
}


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

int main(){
    int X, ans = 0;
    cin >> X;
    while(1){
      for (int i = 2; i <=X; i++){
        if (X % i != 0) continue;
        if (i == X) ans = X; break;
      }
      if (ans == X) break;
      else X++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define A first
#define B second
using namespace std;
typedef pair <int,int> pii;
int H, N;
pii spells[1005];
int dp[20005];
int main() {
    cin >> H >> N;
    for (int i=0; i<N; i++){
        scanf("%d %d", &spells[i].A, &spells[i].B);
    }
    memset(dp, 0x3f3f3f3f, sizeof(dp));
    for (int i=0; i<=10000; i++) dp[i] = 0;
    for (int i=0; i<N; i++){
        for (int j=10000; j <= 10000+H; j++){
            dp[j] = min(dp[j], dp[j-spells[i].A] + spells[i].B);
        }
    }
    cout << dp[10000+H] << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int n, w;
    cin >> n >> w;

    vector<int> wt(n+1),v(n+1);
    //max val 
    for(int i=1;i<=n;++i)
    cin>>wt[i]>>v[i];

    vector<vector<ll>> dp(n+1,vector<ll>(w+1,0));

    for(int i=1;i<=n;++i)
    {
        for(int j=0;j<=w;++j)
        {
            if(j==0 || i==0)dp[i][j]=0;
            else if(j-wt[i]>=0)
            dp[i][j]=max(dp[i-1][j],v[i]+ dp[i-1][j-wt[i]]);
            else dp[i][j]=dp[i-1][j];
        }
    }

    cout<<dp[n][w];
    return 0;
}

Measured memory_bytes: 80256
#include <bits/stdc++.h>
#define int long long
using namespace std;
main(){
    int n;
    scanf("%lld",&n);
    int a[n];
    int p[n];
    for (int i =0; i < n; i++) {
        scanf("%lld",&a[i]);
        p[a[i]-1] = i;
    }
    int l[n];
    int r[n];
    int ll[n];
    int rr[n];
    set<int> s; s.insert(-1);
    for (int j = n-1; j >= 0; j--){
        int i = p[j];
        set<int>::iterator k = s.lower_bound(i);
        if (k != s.begin()){
            k = prev(k);
            l[i] = *k;
        }
        else l[i] = -1;
        if (k != s.begin()){
            k = prev(k);
            ll[i] = *k;
        }
        else ll[i] = -1;
        s.insert(i);
    }
    s.clear(); s.insert(n);
    for (int j = n-1; j >= 0; j--){
        int i = p[j];
        set<int>::iterator k = s.lower_bound(i);
        if (k != s.end()){
            r[i] = *k;
        }
        else r[i] = n;
        k = next(k);
        if (k != s.end()){
            rr[i] = *k;
        }
        else rr[i] = n;
        s.insert(i);
    }
    int ans = 0;
    for (int i = 0; i < n; i++){
        int l1 = l[i] - ll[i];
        int l2 = i - l[i];
        int r1 = r[i] - i;
        int r2 = rr[i] - r[i];
        ans += a[i]*(l1*r1 + l2*r2);
    }
    printf("%lld",ans);
}


Measured memory_bytes: 9600
let () =
  let f x =
    let x3 = if x > 30 then x-30 else 0 in
    let x2 = if x > 20 then x - x3 -20 else 0 in
    let x1 = if x > 10 then x - x3 - x2 - 10 else 0 in
    4280 - (1150 + x1*125 + x2*140 + x3*160) in
  let rec read () =
    let w = read_int () in
    if w = (-1) then ()
    else
      begin
        Printf.printf "%d\n" (f w);
        read ()
      end
  in read ()
;;

Measured memory_bytes: 2240
N, K, Q = map(int, input().split())
N_dict = {i:0 for i in range(1, N+1)}
for i in range(1, Q+1):
    A = int(input())
    N_dict[A] += 1
for j in range(1, N+1):
    if K - Q + N_dict[j] > 0:
        print('Yes')
    elif K - Q + N_dict[j] <= 0:
        print('No')


Measured memory_bytes: 15084
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
const ll INF=100000000000000001;
const double PI=3.141592653589;


int main(){
  vector<int> a(3);
  rep(i,3) cin>>a[i];
  sort(a.begin(),a.end());
  int ans=a[2]*10+a[1]+a[0];
  cout<<ans<<endl;


  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> my;
typedef pair<int ,my> mypair;
int main(){
	int n;
	cin>>n;
	vector<mypair> a ;
	for(int i=0;i<n;i++){
		int x,y,h;
		cin>>x>>y>>h;
	//	if(h!=0)
		a.push_back( mypair(h,my(x,y)));
	}
	//n=a.size();
	sort(a.begin(),a.end());
	int H;
	for(int i=0;i<=100;i++)
	{
		for(int j=0;j<=100;j++){
			bool flag = true;
			H = a[n-1].first +abs(a[n-1].second.first-i)+abs(a[n-1].second.second-j);
			for(int k=0;k<n-1;k++){
				//if((H!=a[k].first+abs(a[k].second.first-i)+abs(a[k].second.second-j))&&max(H-abs(a[k].second.first-i)-abs(a[k].second.second-j),-1)!=-1){
				if((a[k].first!=max(H-abs(a[k].second.first-i)-abs(a[k].second.second-j),0) )){
				flag = false;
				break;
				}
			}
			if(flag) {
				cout<<i<<' '<<j<<' '<<H<<endl;
				return 0;
			}	

		}

	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include <sstream>
#include <iomanip>

using namespace std;

int main(int argc, char* argv[]) {

	int A,B,C;

	cin >> A >> B >> C;

	if((A==5 && B==5) || (B==5 && C==5) || (C==5 && A==5)){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}

	return 0;

}

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

int main(){
  int n,m,c;
  cin >> n >> m>> c;
  vector<int> b(m);
  rep(i,m){
    cin>>b[i];
   }
  int ans=0;
  rep(i,n){
    int sum=c;
    rep(j,m){
      int x;
      cin>>x;
      sum+=x*b[j];
    }
    if(sum>0){
      ans++;
    }
  }
  cout<<ans;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int a,b,c,d,e;
    cin>>a>>b>>c>>d>>e;
    if (a==0) {
        cout<<1<<endl;
    } else if (b==0) {
        cout<<2<<endl;
    } else if (c==0) {
        cout<<3<<endl;
    } else if (d==0) {
        cout<<4<<endl;
    } else if (e==0) {
        cout<<5<<endl;
    }
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int[] h = new int[n];

		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}

		int count = 0;

		loop: for (int i = 0; i < n; i++) {
			for (int j = i ; j >= 0; j--) {
				if (h[i] < h[j]) {
					continue loop;
				}
			}
			count++;
		}

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

Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

template<typename T = double, bool is_min = true>
class ConvexHullTrick {
    using P = pair<T, T>;
    deque<P> L;

    T getY(const P &a, const T &x) {
        return a.first * x + a.second;
    }

    bool check(const P &a, const P &b, const P &c) {
        return (b.first - a.first) * (c.second - b.second) >= (b.second - a.second) * (c.first - b.first);
    }

    bool empty() const {
        return L.empty();
    }

public:
    void add_line(T a, T b) {
        if (!is_min) {
            a *= -1;
            b *= -1;
        }
        P line(a, b);
        if (!L.empty() && L.back().first == a) {
            line.second = min(line.second, L.back().second);
            L.pop_back();
        }
        while (L.size() >= 2 && check(L[L.size() - 2], L[L.size() - 1], line)) {
            L.pop_back();
        }
        L.emplace_back(line);
    }

    T query(T x) {
        assert(!empty());
        int l = -1, r = L.size() - 1;
        while (l < r - 1) {
            int m = (l + r) / 2;
            if (getY(L[m], x) >= getY(L[m + 1], x)) {
                l = m;
            } else {
                r = m;
            }
        }
        return (!is_min ? -1 : 1) * getY(L[r], x);
    }

    T queryMonotone(T x) {
        assert(!empty());
        while (L.size() >= 2 &&& getY(L[0], x) >= getY(L[1], x)) {
            L.pop_front();
        }
        return (!is_min ? -1 : 1) * getY(L[0], x);
    }
};

int main() {
    i64 n, C;
    cin >> n >> C;
    vi hs(n);
    for (int i = 0; i < n; i++) {
        cin >> hs[i];
    }

    vi dp(n);
    ConvexHullTrick<> cht;
    cht.add_line(-2 * hs[0], C + hs[0] * hs[0]);
    for (int i = 1; i< n; i++) {
        i64 r = cht.query(hs[i]) + hs[i] * hs[i];
        dp[i] = r;
        cht.add_line(-2 * hs[i], C + hs[i] * hs[i] + r);
    }

    cout << dp.back() << endl;
}

Measured memory_bytes: 6656
#include <stdio.h>
#include <string.h>
#include <vector>

#define lli long long int
#define pb push_back
#define bigmod 1000000007

using namespace std;

lli memo[100010][5];
bool visited[100010];
vector<lli> anak[100010], adjlist[100010];

void dfs(lli pos) {
	lli nxt;
	visited[pos] = true;
	for (lli j = 0; j < (lli) adjlist[pos].size(); j++) {
		nxt = adjlist[pos][j];
		if (visited[nxt])
			continue;
		anak[pos].pb(nxt);
		dfs(nxt);
	}
}

lli dp(lli id, lli col) {
	lli sum = 1, temp, hasil;
	if (anak[id].size() < 1)
		return 1;
	if (memo[id][col] != -1)
		return memo[id][col];
	for (lli k = 0; k < (lli) anak[id].size(); k++) {
		temp = anak[id][k];
		hasil = dp(temp, 0);
		if (col == 0) {
			hasil += dp(temp, 1);
			hasil %= bigmod;
		}
		sum *= hasil;
		sum %= bigmod;
	}
	memo[id][col] = sum;
	return sum;
}

int main() {
	lli n, x, y, ans;
	scanf("%lld", &n);
	for (lli i = 1; i < n; i++) {
		scanf("%lld %lld", &x, &y);
		adjlist[x].pb(y);
		adjlist[y].pb(x);
	}
	dfs(1);
	memset(memo, -1, sizeof memo);
	ans = (dp(1, 0) + dp(1, 1)) % bigmod;
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 22144
use std::io::{stdin, stdout, Write};

fn main() {
    let mut line = String::new();
    stdin().read_line(&mut line).ok();
    let n: i32 = line.trim().parse().ok().unwrap();
    println!("{}", if n%1000==0 { 0 }else{ (n/1000 + 1) * 1000 - n });
}

Measured memory_bytes: 2132
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define INF	123456789

int N, A[11234];
int memo_A[11234];
int bound[11234][3][2];
int ans = INF;

int how_same(int num, int color) {
	int s1 = 0, s2 = 0;
	for (int i = num + 1; i < N; ++i) {
		if (A[i] == color) { ++s1; }
		else if (A[i] != -1) {
			bound[num][color][0] = i - 1;
			break;
		}
	}
	for (int i = num - 1; i >= 0; --i) {
		if (A[i] == color) { ++s2; }
		else if (A[i] != -1) {
			bound[num][color][1] = i + 1;
			break;
		}
	}
	return s1 + s2 + 1;
}

int solve(int num, int color) {
	int res = 0;
	res += how_same(num, color);
	if (res >= 4) {
		for (int i = bound[num][color][1]; i <= bound[num][color][0]; ++i) { A[i] = -1; }
		if (A[bound[num][color][1] - 1] == A[bound[num][color][0] + 1]) {
			res += solve(bound[num][color][0] + 1, A[bound[num][color][0] + 1]);
		}
		else {
			int tmp = 0;
			tmp += how_same(bound[num][color][0] + 1, A[bound[num][color][0] + 1]);
			if (tmp < 4) { tmp = 0; }
			tmp += how_same(bound[num][color][1] - 1, A[bound[num][color][1] - 1]);
			if (tmp < 4) { tmp = 0; }
		}
	}
	if (res < 4) { res = 0; }
	return res;
}

int main(void) {
	while (true) {
		scanf("%d", &N);
		if (N == 0) { break; }
		memset(bound, 0, sizeof(bound));
		ans = INF;
		for (int i = 0; i < N; ++i) { scanf("%d", &A[i]); }

		for (int i = 0; i < N; ++i) { memo_A[i] = A[i]; }
		for (int i = 1; i < N - 1; ++i) {
				for (int j = 1; j <= 3; ++j) {
					ans = std::min(ans, N - solve(i, j));
					for (int k = 0; k < N; ++k) {
						A[k] = memo_A[k];
					}
				}
		}
		printf("%d\n", ans);
	}
	return 0;
}

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


double x[1010],y[1010];

void init(){
	x[0]=y[0]=0.0;
	x[1]=1.0,y[0]=0.0;
	range(i,2,1010){
		double dx=x[i-1]-x[0],dy=y[i-1]-y[0];
		if(dx*(-dx)-dy*dy < 0.0 ) dy*=-1.0,dx*=-1.0;
		swap(dx,dy);
		double d=sqrt(dx*dx+dy*dy);
		y[i]=y[i-1]-dy/d;
		x[i]=x[i-1]+dx/d;
	}
}

int main(void){
	int n;
	init();
	cout.precision(10);
	while(cin >> n){
		if(n==-1) break;
		cout << fixed << x[n] << endl;
		cout << fixed << y[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 1244
#include <stdio.h>

void rectangle(int length, int height);

int main(){
	int height, width;
	int length;

	while(1){
		scanf("%d", &height);
		scanf("%d", &width);
		if(height==0 && width==0) break;
		length = height*height + width*width;
		rectangle(length, height);
	}

	return 0;
}

void rectangle(int length, int height){
	int i = height + 1;
	int j = 0;
	int len;

	while(length>2*i*i){
		do{
			j++;
			len = i*i + (i+j)*(i+j);
		} while (length>len);
		if(length==len){
			printf("%d %d\n", i, i+j);
			return;
		}
		i++;
		j = 0;
	}
	rectangle(length+1, 0);
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;

int n, k;
vector <int> a;

int min_cut(int len) {
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		cnt += (a[i]-1)/len; // add min number of cuts
	}
	return cnt;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> k;
	a.resize(n, 0);
	int r = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		r = max(r, a[i]);
	}
	int l = 1, mid, ans = r;
	while (l <= r) {
		mid = (l+r)/2;
		//cout << mid << '\n';
		if (min_cut(mid) <= k) {
			ans = mid;
			r = mid - 1;
		} else {
			l = mid + 1;
		}
	}
	cout << ans;
}

Measured memory_bytes: 3880
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
//#define REP(i,a,b) for(int i=a;i<=b;i++)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
long long MOD=1e9+7;
int new1[3][3];
int main()
{	
	ios_base:: sync_with_stdio(0);
	cin.tie(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	int a,b,c,d,n,i,j;
	string s1,s2;
	cin>>s1;
	s2=s1;
	reverse(s1.begin(),s1.end());
	a=s1.size();
	if(s1!=s2){
		cout<<"No";
		return 0;
	}
	b=(a-3)/2;
	for(i=0,j=b;i<=b,j>=0;i++,j--){
		if(s1[j]!=s2[i]){
			cout<<"No";
			return 0;
		}
	}
	c=(a+1)/2;
	for(i=c,j=a-1;i<=a-1,j>=c;i++,j--){
		if(s1[j]!=s2[i]){
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
}


Measured memory_bytes: 256
import sys
while 1:
    n=int(input())
    if n==0:
        sys.exit()
    l=[0]*n
    ma=0
    mi=1000
    s=0
    for i in range(n):
        l[i]=int(input())
        s+=l[i]
        if l[i]>ma:
            ma=l[i]
        if l[i]<mi:
            mi=l[i]
        
    print ((s-ma-mi)//(n-2))

Measured memory_bytes: 7608
#include<bits/stdc++.h>
#define V vector
#define VI vector<int>
#define VVI vector<vector<int>>
#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 MOD 1000000007
#define INF 1e9
#define F first
#define S second
#define All(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;

int main(void){
    int N;
    cin>>N;
    double ans=0.0;
    VI a(N);
    REP(i,N)cin>>a[i];
    sort(All(a));
    int m1=a[N-1],m2=a[N-2],m3=a[N-3],m4=a[N-4];

    FOR(i,1,N-2){
        int C=a[i],D=a[i-1];
        ans=max(ans,1.0*(m1+m2)/(C-D));
    }
    ans=max(ans,1.0*(m1+m4)/(a[N-2]-a[N-3]));
    ans=max(ans,1.0*(m3+m4)/(a[N-1]-a[N-2]));
    printf("%lf\n",ans);
}


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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
const LL INF = 1e15;

int naive(vector<PLL> xs){
  LL res = 0;
  SORT(xs);
  do{
	LL crt = 0, ans = 0;
	REP(i,SZ(xs)){
	  if(xs[i].FF >= crt){
		++ans;
		crt += xs[i].SS;
	  }
	}
	maxi(res, ans);
  }while(next_permutation(ALL(xs)));
  return res;
}

LL dp[5010];

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

  int N;
  cin >> N;
  vector<PLL> xs(N);
  REP(i,N) cin >> xs[i].FF >> xs[i].SS;

  auto comp = [](const PLL& p1, const PLL& p2){
	return p1.FF + p1.SS < p2.FF + p2.SS;
  };
  sort(ALL(xs), comp);

  fill((LL*)dp, (LL*)dp+5010, INF);
  dp[0] = 0;
  for(int i=0;i<N;++i){
	for(int n=i;n>=0;--n){
	  if(dp[n] <= xs[i].FF)
		mini(dp[n+1], dp[n] + xs[i].SS);
	}
  }
  int ans1 = 0;
  REP(i,N+1) if(dp[i] < INF) ans1 = i;
  //int ans2 = naive(xs);
  cout << ans1 << endl;
  //cout << ans2 << endl;
  //if(ans1 != ans2) return 1;

  return 0;
}


Measured memory_bytes: 512