akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int nums[50];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N,A;
    cin>>N>>A;
    
    rep(i,N) cin>>nums[i];
    
    ll cnt=0;
    rep1(n,N){
        int num=A*n;
        ll dp[n+1][num+1];
        mem(dp,0);
        dp[0][0]=1;
        rep(i,N)for(int k=min(i+1,n);k>0;k--){
            for(int j=nums[i];j<=num;j++){
                if(dp[k-1][j-nums[i]]){
                    dp[k][j]+=dp[k-1][j-nums[i]];
                }
            }
        }
        cnt+=dp[n][num];
    }
    cout1(cnt);
}

Measured memory_bytes: 1280
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();
		int N = Integer.parseInt(W);

		HashMap<String,Integer> map = new HashMap<>();

		for (int i = 0; i < N; i++) {
			W = in.readLine();
			if(map.containsKey(W)){
				map.put(W, map.get(W)+1);
			}else{
				map.put(W, 1);
			}
		}

		int most = 0;


		for(Iterator<String> itor = map.keySet().iterator();itor.hasNext();){
			String key = itor.next();
			most = Math.max(most,map.get(key));
		}
		ArrayList<String> list = new ArrayList<>();
		for(Iterator<String> itor = map.keySet().iterator();itor.hasNext();){
			String key = itor.next();
			if(most==map.get(key)){
				list.add(key);
			}

		}
		Collections.sort(list);
		for(String ans:list)
			System.out.println(ans);

	}

}


Measured memory_bytes: 64468
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        if (s.length() + 1 == t.length() && t.startsWith(s)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

}


Measured memory_bytes: 35796
n,y = [int(i)  for i in input().split()]
for i in range(2001):
  for j in range(0,n-i+1):
      if 10000*(i)+5000*(j)+1000*(n-i-j) == y:
        print(i,j,n-i-j)
        exit()
print(-1,-1,-1)

Measured memory_bytes: 3060
var
	N,i:Longint;
	A:Array[1..100000]of Longint;
	ans,now,sum:int64;
begin
	read(N);
	for i:=1 to N do read(A[i]);
	now:=0;
	sum:=0;
	for i:=1 to N do begin
		inc(sum,A[i]);
		if(i mod 2=1)and(sum<=0)then begin
			inc(now,1-sum);
			sum:=1;
		end else if(i mod 2=0)and(sum>=0)then begin
			inc(now,sum+1);
			sum:=-1;
		end;
	end;
	ans:=now;
	now:=0;
	sum:=0;
	for i:=1 to N do begin
		inc(sum,A[i]);
		if(i mod 2=0)and(sum<=0)then begin
			inc(now,1-sum);
			sum:=1;
		end else if(i mod 2=1)and(sum>=0)then begin
			inc(now,sum+1);
			sum:=-1;
		end;
	end;
	if ans>now then ans:=now;
	writeln(ans);
end.


Measured memory_bytes: 512
N = int(input())
aa = []
bb = []
for i in range(N):
    a,b = [int(x) for x in input().split()]
    aa.append(a)
    bb.append(b)
aa.sort()
bb.sort()
if N % 2 != 0:
    print(bb[N//2]-aa[N//2]+1)
else:
    print(bb[N//2]+bb[N//2-1]-aa[N//2]-aa[N//2-1]+1)

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

using namespace std;

int main()
{
    int n,a;
    cin>>n;
    vector<int>v;
    for(int i=0;i<n;i++)
    {
        cin>>a;
        v.push_back(a);
    }
    sort(v.begin(),v.end());
    int s=0;
    for(int i=0;i<n-1;i++)
    {
        s+=v[i];
    }
    if(v[n-1]<s)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
return 0;
}


Measured memory_bytes: 256
import sys
n = int(input())
a = [int(input()) for i in range(n)]

f = [0 for i in range(n)]

b = a[0]
f[0] = 1
while(True):
    if(b == 2):
        print(f.count(1))
        sys.exit()
    ni = b-1
    b = a[ni]
    if(f[b-1] == 1):
        print(-1)
        sys.exit()
    else:
        f[b-1] = 1

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

int main()
{
    int a[5],ans;
    while(cin>>a[0])
    {
        if(a[0]<40) a[0] = 40;
        for(int i=1;i<5;i++) {scanf("%d",&a[i]);if(a[i]<40) a[i] = 40;}
        ans = a[0]+a[1]+a[2]+a[3]+a[4];
        cout<<ans/5<<endl;
    }
    return 0;
}

Measured memory_bytes: 1244
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N, X, Y;
  while (cin >> N >> X >> Y) {
    vector<int> res(N, 0);
    for (int a = 1; a <= N; a++) {
      for (int b = a + 1; b <= N; b++) {
        int k = b - a;
        chmin(k, min(abs(X - a), abs(Y - a)) + min(abs(X - b), abs(Y - b)) + 1);
        ++res[k];
      }
    }
    for (int i = 1; i < N; i++) cout << res[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
//CPU的循环调度：多个任务排成一列，每个任务最多被处理 q ms(时间片），
//如果 q ms之后任务尚未完成，那么该任务将被移动至队伍最末尾，
//CPU随即开始处理下一个任务
#include<iostream>
using namespace std;

#define maxx 100005
typedef struct node{
	char name[100];
	int time;
}p;
p queue[maxx];

int head,tail;
int cnt=0;
void enqueue(p qq)
{
	queue[tail]=qq;
	//queue[tail].name=qq.name;
	//queue[tail].time=qq.time;
	tail=(tail+1)%maxx;
}

p dequeue()
{
	p ttq=queue[head];
	head=(head+1)%maxx;
	return ttq;
}

bool isEmpty()
{
	return tail==head;
}

//为区分满与空，规定head与tail相隔一个空位为队列满 
 
bool ifFull()
{
	return head==(tail+1)%maxx;
}

int main()
{
	head=0;
	tail=0;
	int n,q;
	cin>>n>>q;
	p ttt;
	for(int i=0;i<n;i++)
	{
		cin>>ttt.name>>ttt.time;
		enqueue(ttt);
		//cout<<head<<" "<<tail;
	}
	while(!isEmpty())
	{
		p qq=dequeue();
		
		if(qq.time<=q)
		{
			//cout<<"...."<<endl;
			cnt+=qq.time;
			cout<<qq.name<<" "<<cnt<<endl;
		
			
		}
		else
		{
			//cout<<"!!!!"<<endl;
			cnt+=q;
			qq.time-=q;
			enqueue(qq);
		}
		//cout<<head<<" "<<tail<<endl;
	}
	return 0;
}


Measured memory_bytes: 13196
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M = map(int, input().split())
uf = UnionFind(N)

ans = 0
for i in range(M):
    A, B = map(int, input().split())
    uf.union(A-1, B-1)

for i in range(uf.group_count()):
    if ans < uf.size(i):
        ans = uf.size(i)
print(ans)


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

const int INF  = 1e9;
const long long INFLL = 1e18;
const int NMAX = 100005;
const int MMAX = 100005;
const int KMAX = 1005;
const int MOD  = 1e9 + 7;
using namespace std;

// comment to disable debug functions
#define DEBUG

// frequently used macros

#define FORi(N) for(ll i = 0; i < N; ++i)
#define FORj(N) for(ll j = 0; j < N; ++j)
#define FORk(N) for(ll k = 0; k < N; ++k)

#if __cplusplus >= 201103L
#define ALL(v) begin(v),end(v)
#define SORT(v) sort(begin(v), end(v))
#define FIND(v,x) find(begin(v), end(v), (x))
#else
#define ALL(v) (v).begin(),(v).end()
#define SORT(v) sort(v.begin(), v.end())
#define FIND(v,x) find(v.begin(), v.end(), (x))
#endif

#define fi first
#define se second

#define MEMNEXT(from, to) do{ memmove((to), (from), sizeof(from)); \
memset((from), 0, sizeof(from)); } while(0)
#ifdef DEBUG
#define DUMP(x) do{ std::cerr << (#x) << ": " << x << std::endl; }while(0)
#else
#define DUMP(x) do{}while(0)
#endif

// frequent used aliases
typedef long long ll;
typedef pair<int, int> p;
typedef pair<ll, int> lp;
typedef pair<ll, ll> llp;
typedef vector<int> vec;
typedef vector<ll> vecll;
typedef vector<vec> mat;
typedef vector<vecll> matll;

// frequently used constants
static const int di[] = {-1, 0, 1, -1, 1, -1, 0, 1};
static const int dj[] = {-1, -1, -1, 0, 0, 1, 1, 1};

// frequently used structs
struct edge{
  int to,cost;
};

// printf for debug
#ifndef DEBUG
void debug(const char* format, ...){}
#else
void debug(const char* format, ...){
  va_list arg;
  va_start(arg, format);
  vprintf(format, arg);
  va_end(arg);
}
#endif

// dump vector
#ifdef DEBUG
#define DUMPV(v, c) do{       \
  printf("%s: ", #v);         \
  for (int i = 0; i < (c); ++i) \
  {                           \
  cout << (v)[i] << " ";      \
  }                           \
  cout << endl;               \
} while(0)
#else
#define DUMPV(v,c)
#endif

// std::fill of multi dimensions
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
  std::fill( reinterpret_cast<T*>(array),
             reinterpret_cast<T*>(array+N),
             val );
}

// binary search
ll BSearch(ll ok, ll ng, bool (*f)(ll)){
  ll mid;
  while(abs(ok - ng) > 1LL) {
    mid =  (ok + ng) / 2LL;
    if(f(mid)) {
      debug("BSearch: f(%d) == true\n", mid);
      ok = mid;
    }
    else
    {
      debug("BSearch: f(%d) == false\n", mid);
      ng = mid;
    }
  }
  return ok;
}

ll NUM_TEST_CASE = 1;

ll N,M,K,A,B,C,D,E;
int dp[NMAX] = {};

string S;
vec v;

string ans = {};

void solve(){
  // main algorithm
  ll sum = 0;
  for (auto &&ch : S)
  {
    sum += ch - '0';
  }
  ans = sum % 9 ? "No" : "Yes";
  
}
void debug(){
  // output debug information

}
void answer(){
  // output answer
  cout << ans << endl;
}
void init(){
  // initialize for each test case
  // Fill(dp, -1);
}
int main(int argc, char const *argv[])
{
  // operate inputs

  // cin >> NUM_TEST_CASE;

  for (int test_case = 0; test_case < NUM_TEST_CASE; ++test_case)
  {
    init();

    cin >> S;
    solve();
    #ifdef DEBUG
    debug();
    #endif
    answer();
  }

  return 0;
}

Measured memory_bytes: 3720
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

int N, M;
int a[100], b[100];
bool used[100];

vector<int> Graph[100];

void initgraph() {
  rep(i, 0, 100) {
    Graph[i] = vector<int>();
    used[i] = false;
  }
}

void bfs() {
  queue<int> que;

  que.push(1);
  used[1] = true;

  while (!que.empty()) {
    int cv = que.front();
    que.pop();

    for (auto nv : Graph[cv]) {
      if (!used[nv]) {
        que.push(nv);
        used[nv] = true;
      }
    }
  }
}

bool is_connected() {
  repe(i, 1, N) {
    if (!used[i]) {
      return false;
    }
  }
  return true;
}

int main() {
  cin >> N >> M;
  repe(i, 1, M) { cin >> a[i] >> b[i]; }

  int ans = 0;
  repe(i, 1, M) {
    initgraph();
    repe(j, 1, M) {
      if (j == i) continue;

      int aa = a[j];
      int bb = b[j];
      Graph[aa].push_back(bb);
      Graph[bb].push_back(aa);
    }
    bfs();

    if (!is_connected()) {
      ++ans;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 3636
// 基本テンプレート

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

typedef pair<int, int> pii;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

signed main() {
    int N; cin >> N;
    repq(i,1,3500) repq(j,1,3500) {
        int n = i, w = j;

        int ub = 3500, lb = 0;
        while(ub - lb > 1) {
            int mid = (ub + lb) / 2;
            int lexpr = 4 * mid * n * w;
            int rexpr = N * (n * w + mid * (n + w));
            if(lexpr > rexpr) ub = mid;
            else lb = mid;
        }

        int lexpr = 4 * lb * n * w;
        int rexpr = N * (n * w + lb * (n + w));
        if(lexpr == rexpr) {
            printf("%lld %lld %lld\n", n, w, lb);
            return 0;
        }
    }
    return 0;
}

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

int main(void){

	int a,b,c;
	cin >> a >> b >> c;
	int count = 0;
	if (a != b)
		count++;
	if (b != c)
		count++;
	if (c != a)
		count++;
	if (a==b and b==c)
		count = 1;

	cout << count << endl;
}

Measured memory_bytes: 256
function main()
	lines=readlines()
	N=parse(Int,shift!(lines))
	T=10^5
	parent=collect(1:T)
	S=ones(Int,T)
	function find(u)
		if u==parent[u]
			u
		else
			parent[u]=find(parent[u])
		end
	end
	A=[((x,y)=split(s);(parse(Int,x),parse(Int,y))) for s in lines]
	sort!(A)
	px,py=-1,-1
	for (x,y)=A
		if px==x
			s=find(py)
			t=find(y)
			if s==t
			elseif S[s]>S[t]
				parent[t]=s
				S[s]+=S[t]
			else
				parent[s]=t
				S[t]+=S[s]
			end
		end
		px,py=x,y
	end
	ans=-N
	px=-1
	for (x,y)=A
		if px!=x
			ans+=S[find(y)]
		end
		px=x
	end
	println(ans)
end
main()

Measured memory_bytes: 171160
import * as fs from 'fs';

function gcd(a: number, b: number, c: number) {
    const min = Math.min(a, b, c);
    let gcd = 1;
    for (let i = 2; i <= min; i++) {
        if (a % i === 0 &&
            b % i === 0 &&
            c % i === 0) {
            gcd = i;
        }
    }
    return gcd;
}

function Main(input: string) {
    const constraintK = parseInt(input);
    let sum = 0;

    for (let a = 1; a <= constraintK; a++) {
        for (let b = 1; b <= constraintK; b++) {
            for (let c = 1; c <= constraintK; c++) {
                sum += gcd(a, b, c);
            }
        }
    }

    //output
    console.log(sum);
}

Main(fs.readFileSync("/dev/stdin", "utf8"));


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

using namespace std;

#define MOD 10000

int a[101];

int dp[101][4][4];

int n, k;

int rec(int day, int pp, int p)
{
	if (day > n) return 1;

	if (dp[day][pp][p] >= 0) return dp[day][pp][p];

	int res = 0;

	if (a[day]) {
		if (a[day] != pp || a[day] != p) {
			res = rec(day + 1, p, a[day]);
			res %= MOD;
		}
	} else {
		for (int i = 1; i <= 3; ++i) {
			if (pp == p && p == i) continue;
			res += rec(day + 1, p, i);
			res %= MOD;
		}
	}

	return dp[day][pp][p] = res;
}

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

	for (int i = 0; i < k; ++i) {
		int day; cin >> day;
		cin >> a[day];
	}

	memset(dp, -1, sizeof(dp));

	printf("%d\n", rec(1, 0, 0));
}

Measured memory_bytes: 1152
from itertools import accumulate

n, m = map(int, input().split())
cnts = [0] * (n + 1)
cities = map(int, input().split())
prev = next(cities)
for cur in cities:
    if prev < cur:
        cnts[prev] += 1
        cnts[cur] -= 1
    else:
        cnts[cur] += 1
        cnts[prev] -= 1
    prev = cur
cnts = list(accumulate(cnts))
ans = 0
for i in range(1, n):
    a, b, c = map(int, input().split())
    bep = c // (a - b)
    cnt = cnts[i]
    if cnt > bep:
        ans += b * cnt + c
    else:
        ans += a * cnt
print(ans)

Measured memory_bytes: 16452
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int r,c,a[101][101]={{}};
  cin >> r >> c;
  for(int i=0; i<r; i++) {
      for(int j=0; j<c; j++) {
          cin >> a[i][j];
      }
  }
  for(int i=0; i<r; i++) {
      for(int j=0; j<c; j++) {
          a[i][c]+=a[i][j];
      }
  }
  for(int i=0; i<=c; i++) {
      for(int j=0; j<r; j++) {
          a[r][i]+=a[j][i];
      }
  }
  for(int i=0; i<=r; i++) {
      for(int j=0; j<c; j++) {
          cout << a[i][j] << " ";
      }
      cout << a[i][c] << endl;
  }
  return 0;
}


Measured memory_bytes: 3148
// 2011/08/21 Tazoe

#include <iostream>
#include <string>
using namespace std;

int main()
{
	while(true){
		string clr;
		cin >> clr;
		if(clr=="0")		// ツ閉カツ篠堋療ア
			break;

		if(clr[1]>='0'&&clr[1]<='7')
			if(clr[3]>='0'&&clr[3]<='7')
				if(clr[5]>='0'&&clr[5]<='7')
					cout << "black" << endl;
				else
					cout << "blue" << endl;
			else
				if(clr[5]>='0'&&clr[5]<='7')
					cout << "lime" << endl;
				else
					cout << "aqua" << endl;
		else
			if(clr[3]>='0'&&clr[3]<='7')
				if(clr[5]>='0'&&clr[5]<='7')
					cout << "red" << endl;
				else
					cout << "fuchsia" << endl;
			else
				if(clr[5]>='0'&&clr[5]<='7')
					cout << "yellow" << endl;
				else
					cout << "white" << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    cout << (n+999)/1000*1000 - n << '\n';
    return 0;
}

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

using namespace std;

void solve()
{
  int x1, x2, y1, y2, r1, r2;
  cin >> x1 >> y1 >> r1;
  cin >> x2 >> y2 >> r2;
  int dist2 = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
  int rrrr2 = (r1 + r2) * (r1 + r2);

  if(dist2 > rrrr2) {
    cout << 4 << endl;
  } else if(dist2 == rrrr2) {
    cout << 3 << endl;
  } else if(dist2 > (r1 - r2) * (r1 - r2)) {
    cout << 2 << endl;
  } else if(dist2 == (r1 - r2) * (r1 - r2)) {
    cout << 1 << endl;
  } else {
    cout << 0 << endl;
  }
}

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

Measured memory_bytes: 3156
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <iomanip>
#include <functional>
#include <queue>
#include <stack>
#include <map>
#include <vector>
#include <cmath>
#include <cctype>
#include <cstdio>
#define ll long long
#define INF 1e+7
#define MOD 1000000007
using namespace std;



int main(){
    int N;
    cin >> N;
    int p[N];
    for(int i=0; i<N; i++){
        cin >> p[i];
    }
    
    sort(p,p+N);
    int ans=0;
    for(int i=0; i<N-1;i++){
        ans+=p[i];
    }
    ans+=p[N-1]/2;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.InputStreamReader;
import java.io.BufferedReader;


public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nq = br.readLine().split(" ");
        int n = Integer.parseInt(nq[0]);
        int q = Integer.parseInt(nq[1]);
        String s = br.readLine();
        int[] count = new int[n];
        
        int cnt = 0;
        for (int i = 0; i < n-1; i++) {
            if (s.charAt(i)=='A' && s.charAt(i+1)=='C') {
                cnt++;
            }
            count[i+1] = cnt;
        }
        
        //System.out.println(count[2]);
        
        for (int i = 0; i < q; i++) {
            String[] lr = br.readLine().split(" ");
            int l = Integer.parseInt(lr[0])-1;
            int r = Integer.parseInt(lr[1])-1;
            
            System.out.println(count[r]-count[l]);
        }
        
        
    }
}





Measured memory_bytes: 48272
import java.io.File;
import java.io.FileInputStream;
import java.util.Scanner;
import java.util.Map.Entry;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
import java.util.HashMap;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.PriorityQueue;

public class Main {
	
	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		
		String S = sc.next();
		System.out.println(S.substring(0, S.length()-8));
	}
}

class FastScanner {
    private InputStream in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    public FastScanner(InputStream in) {
		this.in = in;
	}
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
    	if (hasNextByte()) return buffer[ptr++];
    	else return -1;
    }
    private static boolean isPrintableChar(int c){
    	return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
    	while(hasNextByte() && !isPrintableChar(buffer[ptr]))
    		ptr++; return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
    	return Double.parseDouble(next());
    }
}

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n, k;
  cin >> n >> k;
  mint ans = 0;
  for(ll i = k; i <= n+1; ++i) {
    ll min_sum = (i-1)*i/2;
    ll max_sum = (2*n-i+1)*i/2;
    ans += max_sum-min_sum+1;
  }
  cout << ans.x << endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

const int MAX_N = 2e5;
ll fac[MAX_N+1], ifac[MAX_N+1], inv[MAX_N+1];

//mpow(x,n)で(x^n)をO(log(n))で計算
ll mpow(ll x, ll n){
    ll res = 1, now = x;
    while(n > 0){
        if(n & 1) res *= now, res %= MOD;
        now *= now, now %= MOD;
        n >>= 1;
    }
    return res;
}

//setcomb()でfac,ifac,invを全て計算
void setcomb(){
    rep2(i, 1, MAX_N){
        inv[i] = mpow(i, MOD-2);
    }
    //i!とi!の逆元
    fac[0] = 1, ifac[0] = 1;
    rep2(i, 1, MAX_N){
        fac[i] = (fac[i-1]*i) % MOD;
        ifac[i] = (ifac[i-1]*inv[i]) % MOD;
    }
}

//comb(n, k)でnCk
ll comb(int n, int k){
    ll c = fac[n];
    c *= ifac[n-k], c %= MOD;
    c *= ifac[k], c %= MOD;
    return c;
}

//perm(n, k)でnPk
ll perm(int n, int k){
    return(fac[n]*ifac[n-k])%MOD;
}

ll N, K;
vector<ll> ds, ps;

//n文字で複数の同じ文字列に分解できない回分の数
ll num(ll n){
    vector<ll> p;
    for(auto &e: ps) if(n%e == 0) p.pb(e);
    ll sum = 0;
    int N = p.size();
    rep(i, 1<<N){
        int c = __builtin_popcount(i);
        //n個をj文字ずつの回文に区切れる場合
        ll j = 1;
        rep(k, N) if(i & (1<<k)) j *= p[k];
        j = n/j;
        ll tmp = mpow(K, (j+1)/2);
        if(c&1) sum += MOD-tmp;
        else sum += tmp;
        sum %= MOD;
    }
    return sum;
}

int main(){
    cin >> N >> K;
    rep2(i, 1, N){
        if(i*i > N) break;
        if(i*i == N) ds.pb(i);
        elif(N%i == 0) ds.pb(i), ds.pb(N/i);
    }
    ll sub = N;
    rep2(i, 2, N){
        if(sub == 1) break;
        if(i*i > sub) {ps.pb(sub); break;}
        if(sub%i == 0) ps.pb(i);
        while(sub%i == 0) sub /= i;
    }
    ll sum = 0;
    //e文字ずつで区切れる場合
    //for(auto &e: ps) cout << e << endl;
    for(auto &e: ds){
        //cout << e << ' ' << num(e) << endl;
        if(e&1) sum += e*num(e), sum %= MOD;
        else sum += (e/2)*num(e), sum %= MOD;
    }
    cout << sum << endl;
}

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

namespace _02_ABC081A
{
    class Program
    {
        static void Main(string[] args)
        {
            int A = int.Parse(Console.ReadLine());
            int B = int.Parse(Console.ReadLine());
            int C = int.Parse(Console.ReadLine());
            int X = int.Parse(Console.ReadLine());
            int count = 0;

            for (int i = 0; i <= A; i++)
            {
                for (int l = 0; l <= B; l++)
                {
                    for (int k = 0; k <= C; k++)
                    {

                        if (500 * i + 100 * l + 50 * k == X)
                        {
                            count++;
                        }
                    }
                }
            }

            Console.WriteLine(count);
            Console.Read();

        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
const int MAX = (1<<20);
const int mod = 100000;
#define rep(i,n) for(int i = 0;i < n;i++)

int cur[2][MAX], nex[2][MAX], msk = MAX-1;
char str[22][22], ss[] = "JOI";

void print(int k){
	if(k == 0)printf("0");
	while(k){
		printf("%d", k&1);
		k >>= 1;
	}
	printf("\n");
}

int solve(int y, int x, int s, char c){
	if(str[y][x] != c && str[y][x] != '?')return 0;
	if(c == 'I' && (s & (1<<x)))return 0;
	int mask = (1<<x)^msk;
	if(1 <= x && c == 'O')nex[0][(s|(1<<(x-1)))&mask] += cur[1][s];
	if(x == 0 && c == 'O')nex[0][s&mask] += cur[1][s];
	if(c == 'J')nex[1][s&mask] += cur[0][s]+cur[1][s];
	if(c == 'O')nex[0][s&mask] += cur[0][s];
	if(c == 'I')nex[0][s&mask] += cur[0][s]+cur[1][s];
	nex[0][s&mask] %= mod;
	nex[1][s&mask] %= mod;
	//if(s == 0)printf(" *%c %d* ", c, cur[1][s]);
	return 0;
}

int main(){
	int h, w;
	scanf("%d%d", &h, &w);
	for(int i = 0;i < h;i++)scanf("%s", str[i]);
	
	cur[0][0] = 1;
	rep(y,h)rep(x,w){
		fill((int*)nex, (int*)(nex+2), 0);
		rep(s,(1<<w))rep(i,3){
			solve(y, x, s, ss[i]);
		}
		//printf("%d\n", nex[0][0]);
		swap(cur, nex);
	}
	
	int ans = 1;
	rep(i,h)rep(j,w)if(str[i][j] == '?')ans = (ans*3)%mod;
	rep(i,2)rep(j,(1<<w))ans = (ans-cur[i][j]+mod)%mod;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 19616
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007

using namespace std;

long long N, A, B;
string S;

int main(){
	cin >> N >> A >> B;
	cin >> S;
	long long a = 0;
	long long b = 0;
	for(int i = 0; i < S.size(); i++){
		if(S[i] == 'a'){
			if(a + b < A + B){
				a++;
				cout << "Yes" << endl;
			}else{
				cout << "No" << endl;
			}
		}else if(S[i] == 'b'){
			if(a + b < A + B && b < B){
				b++;
				cout << "Yes" << endl;
			}else{
				cout << "No" << endl;
			}
		}else{
			cout << "No" << endl;
		}
	}

}



Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
#-------------------------------------

n,k = map(int,input().split())
h = list(map(int,input().split()))

h = sorted(h,reverse=True)
# print(h)
for i,v in enumerate(h):
    # print(i,v,k)
    if v<k:
        print(i)
        break
else:
    print(n)

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

const int mod=1000000007;
int t[100010],A[100010],B[100010],n,m,p,cnt,nw,cntt;
pair<int,int> valy[100010];
struct node{int x,y;}a[100010],aa[100010];
bool cmp(node a,node b) {return a.x<b.x||a.x==b.x&&a.y>b.y;}

void add(int x,int v) {for (; x<=nw; x+=(x&-x)) t[x]=(t[x]+v>=mod?t[x]+v-mod:t[x]+v);}
int query(int x) {int r=0; for (; x; x-=(x&-x)) r=(t[x]+r>=mod?t[x]+r-mod:t[x]+r); return r;}

int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1; i<=n; i++) scanf("%d",&A[i]);
	for (int i=1; i<=m; i++) scanf("%d",&B[i]);
	p=0;
	for (int i=1; i<=n; i++)
	{
		while (p<m&&B[p+1]<A[i]) p++;
		if (p&&p<m) a[++cnt]=(node){A[i]-B[p],B[p+1]-A[i]};
	}
	if (!cnt) return puts("1"),0;
	sort(a+1,a+1+cnt,cmp),aa[cntt=1]=a[1];
	for (int i=2; i<=cnt; i++) if (a[i].x!=a[i-1].x||a[i].y!=a[i-1].y) aa[++cntt]=a[i];
	cnt=cntt;
	for (int i=1; i<=cnt; i++) a[i]=aa[i];
	for (int i=1; i<=cnt; i++) valy[i]=make_pair(a[i].y,i);
	sort(valy+1,valy+1+cnt),nw=1;
	for (int i=1; i<=cnt; i++)
	{
		if (i==1||valy[i].first!=valy[i-1].first) nw++;
		a[valy[i].second].y=nw;
	}
	memset(t,0,sizeof(t)),add(1,1);
	for (int i=1; i<=cnt; i++) add(a[i].y,query(a[i].y-1));
	printf("%d\n",query(nw));
	return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>

#define ll long long

using namespace std;

const long long mod = 1e9 + 7;

int main() {
	int n, m;
    int* ans;
    cin >> n >> m;
    ans = new int[n];
    memset(ans, 0, sizeof(int)*n);

    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        ans[a-1]++;
        ans[b-1]++;
    }

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

Measured memory_bytes: 256
n,m=map(int,input().split())
l=[]
for i in range(n):
  l1=list(input())
  b=True
  for j in l1:
    if j=="#":
      b=False
  if b==False:
    l.append(l1)
for i in range(m):
  b=True
  for j in range(len(l)):
    if l[j][m-1-i]=="#":
      b=False
  if b:
    for j in range(len(l)):
      del l[j][m-1-i]
for i in range(len(l)):
  print("".join(l[i]))

Measured memory_bytes: 3188
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;


public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        List<Integer> listA = Stream.iterate(1 , i -> i+1)
                .limit(k)
                .collect(Collectors.toList());
        int[] ar1 = new int[listA.size()];
        int[] ar2 = new int[listA.size()];
        int[] ar3 = new int[listA.size()];
        ar1 = toArray(listA);
        ar2 = toArray(listA);
        ar3 = toArray(listA);
        long sum = 0;
        for(int n1 : ar1){
            for(int n2 : ar2){
                for(int n3 : ar3){
                    int[] array = {n1, n2, n3};
                    sum +=gcd(array);
                }
            }
        }
        System.out.println(sum);


    }

    private static int gcd(int[] args){
        return IntStream.of(args)
                .mapToObj(BigInteger::valueOf) // 型変換
                .reduce(BigInteger::gcd) // Python版のreduce(math.gcd)とほぼ同じですね
                .orElse(BigInteger.ZERO) // ↑はOptional<BigInteger>を返すので
                .intValue();
    }

    public static int[] toArray(List<Integer> target) {

        final int[] result = new int[target.size()];
        for (int i=0; i<result.length; i++) {
            result[i] = target.get(i);
        }

        return result;
    }
}


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

typedef pair<int, int> P;

int main() {
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    
	int n, q;
	while(cin >> n >> q && (n || q)){
		map<string, P> m;
		string s;
		int b, w, y;
		for(int i = 0; i < n; ++i){
			cin >> s >> b >> w;
			m[s] = P(w - b + 1, w);
		}
		for(int i = 0; i < q; ++i){
			cin >> y;
			bool ok = false;
			for(auto& v : m){
				if(v.second.first <= y && y <= v.second.second){
					cout << v.first << " " << y - v.second.first + 1 << endl;
					ok = true;
				}
			}
			if(!ok)
				cout << "Unknown" << endl;
		}
		m.clear();
	}
	return 0;
}

Measured memory_bytes: 1332
#include <iostream>
#include<iomanip>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#include<ctime>
#include<cstdlib>
#define INF long long int(1e18+1)
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;

int main() {
	int n;
	cin >> n;
	int a, b;
	cin >> a >> b;
	vector<int>p(n);
	rep(i, 0, n)cin >> p[i];
	sort(p.begin(), p.end());

	int fst = upper_bound(p.begin(), p.end(), a) - p.begin();
	int snd = upper_bound(p.begin(), p.end(), b) - upper_bound(p.begin(), p.end(), a);
	int trd = p.end() - upper_bound(p.begin(), p.end(), b);
	int ans;
	ans = min(fst, snd);
	ans = min(ans, trd);
	cout << ans << endl;
} 
 

Measured memory_bytes: 3600
#include <bits/stdc++.h>
 
using namespace std;
 
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long int
#define FF first
#define SS second
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long int,long long int>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d\n",x)
#define plld(x) printf("%lld\n",x)
#define pss printf
#define MOD 1000000007
#define INF 1e18
#define eps 0.00001
#define endl '\n'
#define debug(n1) cout<<n1<<endl
ll n;
ll a[200005];
 
int main() {
slld(n);
ll s=0;
for(int i=1;i<=n;i++)
	slld(a[i]),s+=a[i];
ll ans=INF,b=0;
for(int i=1;i<n;i++)
{
	b+=a[i];
	ans=min(ans,abs(2*b-s));
}
plld(ans);
	return 0;
           }


Measured memory_bytes: 1792
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.util.*;
class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		IN:while(true) {
			int x1 = sc.nextInt();
			int y1 = sc.nextInt();
			double minx = x1;
			double maxx = x1;
			double miny = y1;
			double maxy = y1;
			Point2D.Double p1 = new Point2D.Double(x1, y1);
			if(x1 == 0 && y1 == 0) break;
			int x2 = sc.nextInt();
			int y2 = sc.nextInt();
			minx = Math.min(x2, minx);
			miny = Math.min(y2, miny);
			maxx = Math.max(x2, maxx);
			maxy = Math.max(y2, maxy);
			Point2D.Double p2 = new Point2D.Double(x2, y2);
			int x3 = sc.nextInt();
			int y3 = sc.nextInt();
			minx = Math.min(x3, minx);
			miny = Math.min(y3, miny);
			maxx = Math.max(x3, maxx);
			maxy = Math.max(y3, maxy);
			Point2D.Double p3 = new Point2D.Double(x3, y3);
			int x4 = sc.nextInt();
			int y4 = sc.nextInt();
			minx = Math.min(x4, minx);
			miny = Math.min(y4, miny);
			maxx = Math.max(x4, maxx);
			maxy = Math.max(y4, maxy);
			Point2D.Double p4 = new Point2D.Double(x4, y4);
			double r = sc.nextDouble();
			
			Line2D.Double a = new Line2D.Double(p2,p3);
			Line2D.Double b = new Line2D.Double(p3,p1);
			Line2D.Double c = new Line2D.Double(p1,p2);
			
			if(p1.distance(p4) <= r && p2.distance(p4) <= r && p3.distance(p4) <= r) {
				System.out.println("b");
				continue IN;
			}
			else if(a.ptSegDist(p4) >= r && b.ptSegDist(p4) >= r && c.ptSegDist(p4) >= r) {

				Line2D.Double da = new Line2D.Double(p1,p4);
                Line2D.Double db = new Line2D.Double(p2,p4);
                Line2D.Double dc = new Line2D.Double(p3,p4);
                if(minx<x4 && x4<maxx && miny<y4 && y4<maxy && !a.intersectsLine(da) && !b.intersectsLine(db) && !c.intersectsLine(dc)){
                    System.out.println("a");
                }
                else {
                    if(a.ptSegDist(p4) == r || b.ptSegDist(p4) == r || c.ptSegDist(p4) == r) {
                        System.out.println("c");
                    }
                    else{
                        System.out.println("d");
                    }
                }
            }
			else {
				System.out.println("c");
			}
			
			
			
		}
	}
}

Measured memory_bytes: 23192
import sys
input = sys.stdin.readline
L,R = map(int, input().split())
ans = 2020
for i in range(L,R+1):
	for j in range(i+1,R+1):
		if j % 2019 == 0:
			print(0)
			exit()
		if (i*j)%2019 < ans:
			ans = (i*j)%2019
print(ans)

Measured memory_bytes: 40684
a = gets.chomp.chars.map(&:to_i).reverse
n = a.size
dp = Array.new(n+1)
dp[0] = 0
MOD = 2019

n.times do |i|
  dp[i+1] = a[i] * 10.pow(i, MOD) + dp[i]
  dp[i+1] %= MOD
end
ans = dp.tally.values.map { |v| v*(v-1)/2 }.sum
puts ans


Measured memory_bytes: 29556
import java.util.*;
 
class Main {
    public static void main(String[] args) {
                Scanner sc = new Scanner(System.in);
                int i = sc.nextInt();
                int j = sc.nextInt();
        System.out.println(getGDC(i, j));
    }
 
    private static int getGDC(int i, int j) {
        if (j == 0) return i;
        return getGDC(j, i % j);
    }
}

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

#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD = 1000000007;



int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n), b(2001, 0);
    rep(i, n){
        cin >> a[i];
        b[a[i]]++;
    }
    ll ans = 0;
    rep(i, n){
        for (int j = i + 1; j < n; ++j) {
            if(a[i] > a[j]) ans++;
        }
    }
    ans *= k;
    ans %= MOD;
    rep(i, 2000){
        b[i+1] += b[i];
    }
    ll tmp = 0;
    rep(i, n){
        tmp = 0;
        tmp += (k - 1) * k / 2;
        tmp %= MOD;
        tmp *= b[a[i] - 1];
        tmp %= MOD;
        ans += tmp;
        ans %= MOD;
    }
    cout << ans % MOD << endl;


}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while (true) {
			final int n = sc.nextInt();
			
			if(n == 0){
				break;
			}
			
			TreeSet<Integer> set = new TreeSet<Integer>();
			int[][] post = new int[n][3];
			
			for(int i = 0; i < n; i++){
				post[i][0] = sc.nextInt();
				post[i][1] = sc.nextInt();
				post[i][2] = sc.nextInt();
			
				set.add(post[i][1]);
				set.add(post[i][2]);
			}
			
			ArrayList<Integer> list = new ArrayList<Integer>(set);
			int[] array = new int[set.size()];
			
			//System.out.println(set);
			
			int max = 0;
			for(int i = 0; i < n; i++){
				final int end = Collections.binarySearch(list, post[i][2]);
				
				for(int j = Collections.binarySearch(list, post[i][1]); j < end; j++){
					array[j] += post[i][0];
					max = Math.max(max, array[j]);
				}
			}
			
			System.out.println(max > 150 ? "NG" : "OK");
		}
	}

}

Measured memory_bytes: 13000
S = input()
N = len(S)
i = 0
T = []
while i <= N-2:
    if S[i] == 'B' and S[i+1] == 'C':
        T.append('D')
        i += 1
    else:
        T.append(S[i])
    i += 1

N = len(T)
ans = 0
l = 0
while l < N:

    if T[l] == 'B' or T[l] == 'C':
        l += 1
        continue
    
    r = l
    tmp = []
    while r < N and (T[r] == 'A' or T[r] == 'D'):
        tmp.append(T[r])
        r += 1
    
    M = len(tmp)
    D_count = [0]*(M+1)
    for i in range(M-1, -1, -1):
        D_count[i] = D_count[i+1]
        if tmp[i] == 'D':
            D_count[i] += 1
    
    for i in range(M):
        if tmp[i] == 'A':
            ans += D_count[i]
    
    if r == N:
        break
    else:
        l = r+1

print(ans)





Measured memory_bytes: 62972
#include <iostream>
using namespace std;
int main()
{
	int k, s, ans = 0;
	cin >> k >> s;
	for (int i = 0; i <= k; i++)
	{
		for (int j = 0; j <= k; j++)
		{
			int l = s - i - j;
			int sum = i + j + k;
			if (l <= k && l >= 0)
			{
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0; 
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush, heapify
import math
import itertools
import random
 
# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
INF = float('inf')
def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    N1,N2,N3,N4 = inputMap()
    inp = []
    inp.append(N1)
    inp.append(N2)
    inp.append(N3)
    inp.append(N4)
    flgs = [False, False, False, False]
    
    if 1 in inp:
        flgs[0] = True
    else:
        print("NO")
        sys.exit()
        
    if 7 in inp:
        flgs[1] = True
    else:
        print("NO")
        sys.exit()
        
    if 9 in inp:
        flgs[2] = True
    else:
        print("NO")
        sys.exit()
        
    if 4 in inp:
        flgs[3] = True
    else:
        print("NO")
        sys.exit()
    
    for i in flgs:
        if i == False:
            print("NO")
            ys.exit()
            
    print("YES")
    
if __name__ == "__main__":
	main()


Measured memory_bytes: 40560