akhauriyash/Code-Regression huggingface dataset:
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll a,b,c;cin>>a>>b>>c;
  ll ans=0;
  if(a%2!=b%2&&a%2==c%2){
    ans++;
    a++;c++;
  }
  else if(a%2!=c%2&&a%2==b%2){
    ans++;
    a++;b++;
  }
  else if(a%2!=c%2&&b%2==c%2){
    ans++;
    b++;c++;
  }
  ll MAX=max({a,b,c});
  ans+=(MAX-a+MAX-b+MAX-c)/2;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll a,b;
	cin >> a >> b;
	if(a==1)a+=13;
	if(b==1)b+=13;
	if(a<b){
		cout << "Bob" << endl;	
	}else if(a>b){
		cout << "Alice" << endl;
	}else{
		cout << "Draw" << endl;
	}
}


Measured memory_bytes: 256
import sys

def debug(x, table):
    for name, val in table.items():
        if x is val:
            print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
            return None

def solve():
    a = [int(i) for i in input().split()]
    a.sort()

    if a == [5,5,7]:
        ans = 'YES'
    else:
        ans = 'NO'

    print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#define INFTY 2147483647

int mergeSort(int *,int,int);
int merge(int *,int,int,int);

int main(){
  int i,n,*S,count;

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

  count = mergeSort(S,0,n);
  for(i = 0;i < n;i++){
    printf("%d",S[i]);
    if(i != n - 1) printf(" ");
  }
  printf("\n%d\n",count);
  
  free(S);
  return 0;
}

int merge(int *A,int left,int mid,int right){
  int *L,*R,i,j,k,n1,n2;
  static int count;
  n1 = mid - left;
  n2 = right - mid;
  // L[0...n1], R[0...n2] を生成
  L = (int *)malloc((n1 + 1) * sizeof(int));
  R = (int *)malloc((n2 + 1)* sizeof(int));
  for(i = 0;i < n1;i++) L[i] = A[left + i];
  for(i = 0;i < n2;i++) R[i] = A[mid + i];
  L[n1] = INFTY;
  R[n2] = INFTY;
  i = 0;
  j = 0;
  for(k = left;k < right;k++){
    count++;
    if(L[i] <= R[j]){
      A[k] = L[i];
      i = i + 1;
    }
    else{
      A[k] = R[j];
      j = j + 1;
    }
  }
  return count;
}

int mergeSort(int *A,int left,int right){
  int count,mid;
  if(left + 1 < right){
    mid = (left + right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    count = merge(A, left, mid, right);
  }
  return count;
}



Measured memory_bytes: 64020
#include <bits/stdc++.h>
    #define ALL(v) v.begin(), v.end()
    using namespace std;
    typedef long long ll;
     //Compiler version g++ 6.3.0
     
   
     int main()
     {
     	ll n,m,ans=0;
     	cin >> n>>m;
     	ll a=__gcd(n,m);
       	for(ll i=2;i<sqrt(a);i++){
        	if(a%i==0){
            	while(a%i==0){
            		a/=i;
            	}
              ans++;
            }
        }
       	if(a!=1)ans++;
     	cout <<ans+1 << endl;
     }

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
inline int read(){
	int x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
	return x*f;
}
inline ll readll(){
	ll x;
	char c;
	int f=1;
	while((c=getchar())!='-' && (c>'9' || c<'0'));
	if(c=='-') c=getchar(),f=-1;
	x=c^'0';
	while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
	return x*f;
}
const int maxn=1e5+10;
char s[maxn];
int n;
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	int ans1=n,ans2=n;
	REP(i,1,n){
		if(s[i]=='1') ans1=min(ans1,max(n-i,i-1));
		else if(s[i]=='0') ans2=min(ans2,max(n-i,i-1));
	}
	printf("%d\n",max(ans1,ans2));
//	int L=1,R=n;
//	while(L<=R){
//		int Mid=(L+R)>>1;
//		if(check(Mid)) L=Mid+1;
//		else R=Mid-1;
//	}
//	printf("%d\n",L-1);
	return 0;
}

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

int p;
string exp;

int term();
int expression();
int factor();


int expression(){
     int value;
	 value=term();
	 while(exp[p]=='+' || exp[p]=='-'){
		 if(exp[p]=='+'){
			 p++;
			 value+=term();
		 }
		 else{
			 p++;
			 value-=term();
		 }
	 }
	 return value;
}


int term(){
	int value;
	value=factor();
	while(exp[p]=='*' || exp[p]=='/'){
		if(exp[p]=='*'){
			p++;
			value*=factor();
		}
		else{
			p++;
			value/=factor();
		}
	}

	return value;
}

int factor(){
	int value=0;
	if(exp[p]=='('){
		p++;
		value=expression();
		p++;
	}
	else{
		while(isdigit(exp[p])){
			value=value*10+exp[p++]-'0';
		}
	}
	return value;
}



int main()
{
	int i,c;
	cin>>c;
	for(i=0;i<c;i++){
		cin>>exp;
		p=0;
		cout<<expression()<<"\n";
		}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;
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 cnt=1;
      for(int i=N-1;i>0;i--){
        for(int j=i-1;j>=0;j--){
			if(H[j]>H[i]){
            cnt--;
          	break;
        	}
        }
        cnt++;
      }
		System.out.println(cnt);
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 
 
int main() {
	ll a,b,c;
	cin>>a>>b>>c;
	ll ma=max({a,b,c});
	cout <<a+b+c-ma;
	// your code goes here
	return 0;
}

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

int main() {
  vector<int> a(9);
  vector<bool> ans(9,false);
  rep(i,9) cin >> a[i];
  int n;
  cin >> n;
  vector<int> b(n);
  rep(i,n) cin >> b[i];
  bool answer = false;
  
  rep(i,n){
    rep(j,9){
      if(a[j]==b[i])
        ans[j]=true;
    }
  }
  
  rep(i,3)
    if((ans[3*i]&&ans[3*i+1]&&ans[3*i+2]) || (ans[i]&&ans[i+3]&&ans[i+6]))
      answer=true;
  if(((ans[0]&&ans[8]) || (ans[2]&&ans[6]))&&ans[4])
    answer=true;
  
  if(answer) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


int main()
{
	ll a, b, x;
	cin >> a >> b >> x;

	if (a > x)
	{
		println("NO");
	}
	else
	{
		println((a + b >= x ? "YES" : "NO"));
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>

#include <map>
#include <math.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <bitset>
#include <math.h>

#define INF 100100100

typedef long long int llint;

using namespace std;

typedef pair<int, int>Pii;

#define pi 3.141592653589793)
#define mod 1000000007

int main() {
	vector<string>c(3);
	for (int i = 0; i < 3; i++)cin >> c[i];
	for (int i = 0; i < 3; i++)cout << c[i][i];
	cout << endl;
	return 0;
}


Measured memory_bytes: 768
//----------BHAVIK DIWANI(PICT_COMP)---------------
#include<bits/stdc++.h>
#define test ll t; cin>>t; while(t--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define mod 1000000007
#define ll long long
#define int long long
#define ull unsigned long long
#define MAX 1000005
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define endl '\n'
#define vs vector<string>
#define mii map<int,int>
#define msi map<string,int>
#define vpii vector< pair<int, int > >
#define vpsi vector< pair< string ,int > >
#define forci(p,q) for(int i=p;i<q;i++)
ll gcd(ll a,ll b){ if(b==0) return a;    return gcd(b,a%b);}
ll lcm(ll a,ll b) { return (a/gcd(a,b)*b);}
ull power(ull a, ull b) {a %= mod;  ull res = 1;  while (b > 0) { if (b & 1) res = res * a % mod;  a = a * a % mod;  b >>= 1; }  return res%mod; }
ll modmul(ll x, ll y){return (x*y)%mod;}
ll modadd(ll x, ll y){return (x+y)%mod;}
ll modsub(ll x, ll y){return (x-y+mod)%mod;}
ll fact[1000007]={0};
void facto() {fact[0]=1;fact[1]=1;for(int i=2;i<1000007;i++)fact[i]=(fact[i-1]*i)%mod;}
ll ncr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[r],mod-2)))%mod; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
ll npr(ll n,ll r) {ll res=1; res=fact[n]; res=(res*(power(fact[n-r],mod-2)))%mod; return res;}
inline long long toint(const std::string &s) {std::stringstream ss; ss << s; long long x; ss >> x; return x;}
inline std::string tostring(long long number) {std::stringstream ss; ss << number; return ss.str();}
inline std::string tobin(long long x) {return std::bitset<63>(x).to_string();}
/*bool prime[MAX];
ull sieve(){memset(prime,true,sizeof(prime));for(ull p=2;p*p<MAX;p++){if(prime[p]==true){for(ull i=2*p;i<MAX;i+=p){prime[i]=false;}}}prime[0]=0;prime[1]=0;
}*/
/*int inv[1000001]={0};
void findinverse(){inv[1] = 1;for(int i = 2; i <=1e6 ; ++i)	inv[i] = (mod - (mod/i) * inv[mod%i] % mod) % mod;}
*/
using namespace std;
int dp[100005][13];
int solve()
{
	string s;
	cin>>s;
	dp[0][0]=1;
	for(int i=0;i<s.length();i++){
		for(int j=0;j<13;j++){
			if(s[i]!='?'){
				int c=s[i]-'0';
				(dp[i+1][(10*j+c)%13]+=dp[i][j])%=mod;
			}
			else{
				for(int k=0;k<10;k++){
					(dp[i+1][(10*j+k)%13]+=dp[i][j])%=mod;
				}
			}
		}
	}
	cout<<dp[s.length()][5]<<endl;
	return 0;
}
signed main()
{
	fastio;
//	test
		solve();
}







Measured memory_bytes: 13912
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
typedef long long ll;
using namespace std;
int main()
{
  int a, b, c;
  cin >> a >> b >>c;
  string ans = (a + b >= c) ? "Yes" : "No";
  cout <<  ans<< endl;
}


Measured memory_bytes: 256
solve :: [Int] -> [String]
solve (m:f:r:xs)
  | null xs = []
  | m == -1 || f == -1 = "F" : solve xs
  | m + f >= 80 = "A" : solve xs
  | m + f >= 65 && 80 > m + f = "B" : solve xs
  | m + f >= 50 && 65 > m + f = "C" : solve xs
  | m + f >= 30 && 50 > m + f = (if r >= 50 then "C" else "D") : solve xs
  | otherwise =	"F" : solve xs

main = getContents >>= mapM_ putStrLn . solve . map read	. words	

Measured memory_bytes: 4124
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    return divisors

def walk_on_multiplication_table(n):

    ans = 10**13
    yaku = make_divisors(n)
    yaku.sort()
    count = len(yaku)
    for i in range(int(count//2)):
        ans = min(ans, (yaku[i]+yaku[count-i-1]-2))

    if count % 2 == 0:
        return ans
    return min(ans, (yaku[int(count//2)]*2)-2)

def main():
    n = int(input())
    print(walk_on_multiplication_table(n))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3264
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		String n = sc.next();

		for (int i = 0; i < 3; i++) {
			if ( n.charAt(i) == '1') {
				System.out.print("9");
			} else if ( n.charAt(i) == '9' ) {
				System.out.print("1");
			}
		}
	}
}

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

using namespace std;
using ll = long long;

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

const int INF = 1001001001;

ll gcd(ll a, ll b) {
  if (a == INF) return b;
  if (b == INF) return a;
  if (a % b == 0) return b;
  return gcd(b, a % b);
}

int main() {
  int n;
  cin >> n;
  ll a[n];
  rep(i, n) cin >> a[i];

  ll l[n + 1], r[n + 1];
  l[0] = r[0] = INF;
  rep(i, n) {
    l[i + 1] = gcd(l[i], a[i]);
    r[i + 1] = gcd(r[i], a[n - 1 - i]);
  }

  ll ans = 1;
  rep(i, n) ans = max(ans, gcd(l[i], r[n - i - 1]));
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 5960
n = int(input())
a = list(map(int,input().split()))

b = [0] * n

if n % 2 == 0 :
    c = n//2 - 1
else :
    c = n // 2

b[c] = a[0]

for i in range(1,n) :
    if i % 2 == 1 :
        b[c + i] = a[i]
        c += i
    else :
        b[c - i] = a[i]
        c -= i

if c != 0 :
    b.reverse()
    print(*b,sep=" ")
else :
    print(*b,sep=" ")


Measured memory_bytes: 31016
H,W,K = (int(x) for x in input().split())

c = []
for i in range(H):
    c.append(input())

counter = 0
for h in range(1<<H):
    for w in range(1<<W):
        hmask = format(h, 'b').zfill(H)
        wmask = format(w, 'b').zfill(W)

        bcounter = 0
        for i in range(H):
            for j in range(W):
                if hmask[i] == '0' and wmask[j] == '0' and c[i][j] == '#':
                     bcounter += 1
        if bcounter == K:
            counter += 1

print(counter)


Measured memory_bytes: 9208
#include<stdio.h>
int main(void) {
    long a, b, x, count;
    scanf("%ld%ld%ld", &a, &b, &x);
    count = b/x - a/x;
    
    if(a % x == 0) count++;
    
    printf("%ld\n", count);
    
    return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = 0;
        for (int i = 0; i < 5; i++) {
            int x = sc.nextInt();
            if(x == 0){
                a = i+1;
                break;
            }
        }
        System.out.println(a);
        sc.close();

    }

}


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

#define rep(i, n) REP(i, 0, n)
#define REP(i,k,n) for(int i = k; i < n; i++)
#define mmax(start, end) *max_element(start, end)
#define mmin(start, end) *min_element(start, end)
#define argmax max_element
#define argmin min_element
#define ALL(x) (x).begin(), (x).end()

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

int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
int dx8[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy8[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

template<class T = ll> T in() {
    T _in;
    cin >> _in;
    return _in;
}

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

    int A, B, C, X;
    int ans = 0;
    cin >> A >> B >> C >> X;
    rep(i, A+1) {
        rep(j, B+1) {
            rep(k, C+1) {
                if(500*i + 100*j + 50*k == X) {
                    // cout << i << " " << j << " " << k << endl;
                    ans++;
                }
            }
        }
    }

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


Measured memory_bytes: 256
//#include "debug.h"
#include <string.h>
#include <limits.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;

#define MAXN 100000

long x, y;

int input() {
	if (scanf("%ld %ld", &x, &y) < 0) return 0;
	return 1;
}

void init() {
}

long solve() {
	return abs(x-y)>1;
}

void output(long ans) {
	printf("%s\n", ans? "Alice": "Brown");
}

void cleanup() {
}

int main() {
	while (input()) {
		init();
		output(solve());
		cleanup();
		//break;
	}
}





Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

abc = [a,b,c]
abc.sort()

aa = abc[0]
bb = abc[1]
cc = abc[2]

diff = bb-aa
ans = 0
if diff %2==0:
    ans += diff//2
    aa = bb
else:
    ans += diff//2 + 1
    aa = bb
    cc += 1

ans += (cc-bb)*2//2

print(ans)


Measured memory_bytes: 3060
n=int(input())
T,A=map(int, input().split())
H=list(map(int, input().split()))

min_temp_diff=10**5
palace_location=0
for i in range(n):
    if abs(A-(T-H[i]*0.006))<=min_temp_diff:
        min_temp_diff=abs(A-(T-H[i]*0.006))
        palace_location=i+1
print(palace_location)

Measured memory_bytes: 3064
//=template===================================================================//
// include
#include <vector>
#include <list>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>

// namespace
using namespace std;

// define
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define REP(i,n) FOR(i,0,n)
#define MIN_V(v) *min_element(v.begin(), v.end())
#define MAX_V(v) *max_element(v.begin(), v.end())

// typedef
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef long long LL;
typedef unsigned long long ULL;
typedef struct {
  LL cost;
  bool done;
} node_t;

// conversion
inline int
toInt(string s)
{
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline int countChar(string s, char c) {int cnt,i; cnt=0; REP (i,s.size()) {if (s[i]==c) cnt++;} return cnt;}
template<class T> inline string toString(T x) {ostringstream sout; sout<<x; return sout.str();}
//============================================================================//

//=variables==================================================================//

//============================================================================//
int main(void)
{
  // Scan begin.
  int n;
  cin >> n;
  // Scan done.

  // Code begin.
  int approved = 1;
  for (int i = 0; i < n; i++) {
      int a;
      cin >> a;
      if (a%2 == 0) {
          if (a%3 != 0 && a%5 != 0) {
              approved = 0;
              break;
          }
      }
  }

  if (approved == 1) {
      cout << "APPROVED" << endl;
  }
  else {
      cout << "DENIED" << endl;
  }
  // Code done.

      return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.awt.geom.Line2D;

public class Main{
    int n;
    int xa,ya,xb,yb;
    int xs,ys,xt,yt,o,l;
    Line2D a,b;
    Intersection[] inter;

    class Intersection{
	double dist;
	int owner,height;
	public Intersection(double dist,int owner,int height){
	    this.dist = dist;
	    this.owner = owner;
	    this.height = height;
	}
    }

    void solve(){
	Scanner sc = new Scanner(System.in);
	int T = sc.nextInt();
	while(T--!=0){
	    xa = sc.nextInt(); ya = sc.nextInt();
	    xb = sc.nextInt(); yb = sc.nextInt();
	    n = sc.nextInt();

	    inter = new Intersection[n];
	    a = new Line2D.Double(xa,ya,xb,yb);
	    for(int i=0; i<n; i++){
		xs = sc.nextInt(); ys = sc.nextInt();
		xt = sc.nextInt(); yt = sc.nextInt();
		o = sc.nextInt(); l = sc.nextInt();
		b = new Line2D.Double(xs,ys,xt,yt);
		if(a.intersectsLine(b)){
		    double d = calcDist(xa,ya,xb,yb,xs,ys,xt,yt);
		    inter[i] = new Intersection(d,o,l);
		}else{
		    inter[i] = new Intersection(-1,-1,-1);
		}
	    }

	    Comparator<Intersection> cmp = new Comparator<Intersection>(){
		public int compare(Intersection i1, Intersection i2){
		    if(i1.dist<i2.dist) return -1;
		    if(i1.dist>i2.dist) return 1;
		    return 0;
		}
	    };
	    Arrays.sort(inter, cmp);
	    
	    System.out.println(Math.min(countGate(0),countGate(1)));
	}
    }
    
    double calcDist(int x1,int y1,int x2,int y2,int x3,int y3,int x4,int y4){
	double bx = x4-x3;
	double by = y4-y3;
	double d1 = Math.abs(bx*(y1-y3)-by*(x1-x3));
	double d2 = Math.abs(bx*(y2-y3)-by*(x2-x3));
	double t = d1/(d1+d2);	
	double x = x1+(x2-x1)*t;
	double y = y1+(y2-y1)*t;
	
	return (xa-x)*(xa-x)+(ya-y)*(ya-y);
    }
    
    int countGate(int nowHeight){
	int count = 0;
	for(int i=0; i<n; i++){
	    if(inter[i].dist==-1)continue;
	    if(inter[i].owner==0){
		if(inter[i].height==nowHeight){
		    nowHeight = 1 - nowHeight;
		    count++;
		}
	    }else{
		if(inter[i].height!=nowHeight){
		    nowHeight = 1 - nowHeight;
		    count++;
		}
	    }
	}
	return count;
    }
    
    public static void main(String[] args){
	new Main().solve();
    }
}

Measured memory_bytes: 13000
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int main(void) {
	int a[100];
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	reverse(a+0, a+n);
	for (int i = 0; i < n; i++) {
	    if(i)cout<<" ";
		cout << a[i];
	}
	cout<<endl;
}


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

#define INF 2147483647
#define LINF 9223372036854775807
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()

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

int n;
ll a[300000];
priority_queue<ll,vector<ll>,greater<ll> > mi;
priority_queue<ll> ma;
ll front[300000],back[300000];
ll sf,sb,ans=-LINF;

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

	cin>>n;
	REP(i,3*n) {
		cin>>a[i];
		if(i<n) {
			mi.push(a[i]);
			sf+=a[i];
		}
		if(i>=2*n) {
			ma.push(a[i]);
			sb+=a[i];
		}
	}
	front[n-1]=sf;
	FOR(i,n,2*n) {
		mi.push(a[i]);
		sf+=(a[i]-mi.top());
		mi.pop();
		front[i]=sf;
	}
	back[2*n-1]=sb;
	ans=front[2*n-1]-back[2*n-1];
	for(int i=2*n-2;i>=n-1;i--) {
		ma.push(a[i+1]);
		sb+=(a[i+1]-ma.top());
		ma.pop();
		back[i]=sb;
		ans=max(ans,front[i]-back[i]);
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 7796
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;

int N, A[100009], ret;
vector<pair<int, int>> ans;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	sort(A, A + N);
	reverse(A, A + N);

	if (A[0] < 0) {
		int v = A[0];
		for (int i = 0; i < N - 1; i++) {
			int p1 = i, p2 = i + 1;
			ans.push_back(make_pair(v, A[p2]));
			v = v - A[p2];
		}
		ret = v;
	}
	else if (A[N - 1] >= 0) {
		int v = A[N - 1];
		for (int i = 0; i < N - 2; i++) {
			ans.push_back(make_pair(v, A[i]));
			v = v - A[i];
		}
		ans.push_back(make_pair(A[N - 2], v));
		v = A[N - 2] - v;
		ret = v;
	}
	else {
		int a1 = 0, a2 = 0;
		for (int i = 0; i < N; i++) { if (A[i] >= 0) a1++; else a2++; }

		int v = A[N - 1];
		for (int i = 0; i < a1 - 1; i++) {
			ans.push_back(make_pair(v, A[i]));
			v = v - A[i];
		}
		ans.push_back(make_pair(A[a1 - 1], v));
		v = A[a1 - 1] - v;
		for (int i = a1; i < a1 + a2 - 1; i++) {
			ans.push_back(make_pair(v, A[i]));
			v = v - A[i];
		}
		ret = v;
	}
	cout << ret << endl;
	for (int i = 0; i < ans.size(); i++) cout << ans[i].first << " " << ans[i].second << endl;
	return 0;
}

Measured memory_bytes: 3188
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int a,b,c;
    cin>>a>>b>>c;
    if(abs(b-a)<abs(c-a)) {
        cout<<'A'<<'\n';
    } else {
        cout<<'B'<<'\n';
    }


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
int dp[1010][1010];
int main(){
  int q;
  cin >> q;
  for(int i=0;i<q;i++){
    for(int j=0;j<1010;j++){
      fill(dp[j],dp[j]+1010,0);
    }
    string a,b;
    cin >> a >> b;
    for(int j=0;j<a.size();j++){
      for(int k=0;k<b.size();k++){
        if(a[j] == b[k]){
          dp[j+1][k+1] = dp[j][k] + 1;
        }else{
          dp[j+1][k+1] = max(dp[j+1][k] ,dp[j][k+1]);
        }
      }
    }
    cout << dp[a.size()][b.size()] << endl;
  }
  return 0;
}



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

int main() {
    string s = "MARCH";
    long long c[5] = {0};
    
    int N;
    cin >> N;
    
    for (int i = 0; i < N; i++) {
        string t;
        cin >> t;
        for (int j = 0; j < 5; j++) {
            if (t[0] == s[j]) {
                c[j]++;
            }
        }
    }
    
    long long ans = 0;
    for (int i = 0; i < 5; i++) {
        for (int j = i + 1; j < 5; j++) {
            for (int k = j + 1; k < 5; k++) {
                ans += c[i] * c[j] * c[k];
            }
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char s[1111];
int i,j,k,n,m,a,b,c,d;
int main(){
	while (scanf("%d",&n)!=EOF){
		scanf("%s",s);
		for (k=i=j=0;i<n;i++){
			if (s[i]=='I') j++;else j--;
			k=max(j,k);
		}
		printf("%d\n",k);
	}
	return 0;
}

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





int main(){
  while(1){



  
  int n;
  queue<string> a;
  cin>>n;
  if(n==0){break;}
  for(int i=0;i<n;i++){
    string w;
    cin>>w;
    a.push(w);
  }
  int r=0,l=0,count=0;
  pair<int,int> j;
  while(!a.empty()){
    if(r==l){j=make_pair(2,r);}
    string w=a.front();
    a.pop();
    if(w=="lu"){l=1;}
    if(w=="ru"){r=1;}
    if(w=="ld"){l=0;}
    if(w=="rd"){r=0;}
    j.first--;
    if(j.first==0 && r==l && r!=j.second){
      count++;
    }
  }
  cout<<count<<endl;



  }

  
  return 0;
}



Measured memory_bytes: 3140
import java.util.*;
import java.text.*;

public class Main {

    Scanner sc = new Scanner(System.in);

    int MOD = (int)998244353;

    public static void main(String[] args) {
        new Main().run();
    }

    void run() {

        double a = sc.nextDouble();
        double b = sc.nextDouble();
        double h = sc.nextDouble();
        double m = sc.nextDouble();

        double[] sh = {0, a};
        double[] lo = {0, b};

        double mit = 60 * h + m;
        double hourkaku = (360 - (360 * h / 12 + 30 * m / 60)) ;

        double mkaku = ((360 - 360 * m / 60) % 360) ;


        double shx = sh[0] * Math.cos(hourkaku * Math.PI/180) - sh[1] * Math.sin(hourkaku * Math.PI/180);
        double shy = sh[0] * Math.sin(hourkaku * Math.PI/180) + sh[1] * Math.cos(hourkaku * Math.PI/180);

        double lox = lo[0] * Math.cos(mkaku * Math.PI/180) - lo[1] * Math.sin(mkaku * Math.PI/180);
        double loy = lo[0] * Math.sin(mkaku * Math.PI/180) + lo[1] * Math.cos(mkaku * Math.PI/180);

//        System.out.println(hourkaku);
//        System.out.println(mkaku);
//        System.out.println(shx);
//        System.out.println(shy);
//        System.out.println(lox);
//        System.out.println(loy);

        double dis = Math.sqrt(Math.pow(shx - lox, 2) + Math.pow(shy-loy, 2));

        System.out.println(dis);


    }
}



Measured memory_bytes: 37644
#include<iostream>

using namespace std;

int main(){
    int A, B, C, D;
    cin >> A >> B >> C >> D;

    int in = max(A, C);
    int off = min(B, D);

    if(in<off){
        cout << off - in;
    }else{
        cout << "0";
    }
}

Measured memory_bytes: 256
N, M = map(int,input().split())
A = list(list(map(int,input().split()))+[0] for i in range(N))
p = [0]*N
s = [0]*(M+1)
ans = N
for _ in range(M):
    count = [0] * (M+1)
    for i in range(N):
        count[A[i][p[i]]] += 1
    hoge = max(count)
    ans = min(ans,hoge)
    s[count.index(hoge)] = 1
    for i in range(N):
        while s[A[i][p[i]]]:
            p[i] += 1
print(ans)



Measured memory_bytes: 43628
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int n,m;
	int row[30];
	cin >>n>>m;
	for(int i=0; i<n; i++){row[i] = i+1;}
	for(int i=0; i<m; i++){
		int a,b;
		scanf("%d,%d",&a,&b);
		int c = row[a-1];
		row[a-1] = row[b-1];
		row[b-1] = c;
	}
	for(int i=0; i<n; i++){cout <<row[i]<<endl;}
	return 0;
}

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


int main(){
	string s,s2,s3,s4;
	int a,b,c;
	cin >> s;
	s2=s.substr(0,4);
	s3=s.substr(5,2);
	s4=s.substr(8,2);
	
	a=atoi(s2.c_str());
	b=atoi(s3.c_str());
	c=atoi(s4.c_str());
	
	if(a<2019 || a==2019&&b<4 || a==2019&&b==4&&c<=30) cout << "Heisei" << endl;
	else cout << "TBD" << endl;
	
	return 0;
}

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

#define F first 
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 200010, M = 110;

int n;
int cnt[M];
int f[M][M];

int main()
{
	cin >> n;
	for (int i = 2; i <= n; i ++ )
	{
		int t = i;
		for (int j = 2; j <= t / j; j ++ )
			while (t % j == 0)
			{
				cnt[j] ++ ;
				t /= j;
			}
		if (t > 1) cnt[t] ++ ;
	}
	
	f[0][1] = 1;
	for (int i = 0; i < M; i ++ )
		for (int j = 1; j <= 75; j ++ )
			for (int k = 0; k <= cnt[i]; k ++ )
				if ((k + 1) * j > 75) break;
				else f[i + 1][j * (k + 1)] += f[i][j];
	
	cout << f[n][75] << endl;
    return 0;
}


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

using namespace std;

#define INF 1<<30
#define LINF 1ll<<60ll
#define pb(a) push_back(a)
#define vi vector<int>
#define vl vector<long long>
#define vvi vector<vi>
#define P pair<int,int>
#define all(vec) (vec.begin()),(vec.end())
#define ll long long
#define sz(x) ((int)(x).size())
#define in(x) int x;cin>>x
#define bit(n) (1<<(n))

#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REP3(i, m, n) for(int i = m, i##_len=(n);i < i##_len;++i)
#define FORVEC(i, v) for(int i = 0;i < sz(v);++i)

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

#define fil0(i,n) cout<<swet(n)<<setfill('0')<<i<<resetiosflags(ios_base::floatfield)


int main(){
    int n;
    int mi=INF,ma=-(INF);
    cin>>n;
    int a;
    REP(i,n){
        cin>>a;
        chmax(ma,a);
        chmin(mi,a);
    }
    cout<<ma-mi<<endl;
    return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

int main() {
    ll h;
    cin >> h;

    ll r = 0, t = 1;
    while (h) {
        if (h == 1) {
            r += t;
            break;
        }
        r += t;
        h /= 2;
        t *= 2;
    }

    cout << r << endl;

    return 0;
}

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

int main() {
   int a,b,c;
   cin>> a >> b >> c;
   if(a>b){
      swap(a,b);    
    }
    if(b>c){
     swap(b,c);
  }
   if(a>b){
     swap(a,b); 
     }
  cout<< a <<" " << b <<" " << c <<endl;
  return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string>
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int h,w;
    cin>>h>>w;
    char arr[h][w];
    for (int i=0;i<h;i++)
    {
        for (int j=0;j<w;j++)
        {
            cin>>arr[i][j];
        }
    }
    long long mod = 1e9+7;
    int DP[h+1][w+1];

    for (int i=0;i<=h;i++)
        DP[i][0]=0;

    for (int j=0;j<=w;j++)
        DP[0][j]=0;

  /*  for (int i=1;i<=w;i++)
    {
        if(arr[0][i-1]!='#')
          DP[1][i]=1;
         else
            DP[1][i]=0;
    }*/

    for (int i=1;i<=h;i++)
    {
        for (int j=1;j<=w;j++)
        {
            if (arr[i-1][j-1]!='#')
            {
                DP[i][j]=(DP[i][j-1]%mod + DP[i-1][j]%mod)%mod;
            }
            else
                DP[i][j]=0;
            DP[1][1]=1;
        }
    }

    cout<<DP[h][w];
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  ll cnt = 0;
  int mx = 0;
  rep(i,n) {
    mx = max(mx, a[i]);
    cnt += mx - a[i];
  }
  
  cout << cnt << endl;
  
  return 0;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> data(h, vector<char>(w));
  for (int i = 0; i < h; i++) {
  	for (int j = 0; j < w; j++) {
      cin >> data.at(i).at(j);
    }
  }
  for (int i=0; i<w+2; i++) {
  	cout << "#";
  }
  cout << endl;
  for (int i=0; i<h; i++) {
    cout << "#";
  	for (int j=0; j<w; j++) {
      cout << data.at(i).at(j);
    }
    cout << "#" << endl;
  }
  for (int i=0; i<w+2; i++) {
  	cout << "#";
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n, d, x;
	cin>>n>>d>>x;
	vector<int> vec(n, 0);
	for(int i = 0; i < n; ++i){
		cin>>vec[i];
	}
	int cnt = x;
	for(int i = 0; i < n; ++i){
		cnt++;
		for(int j = 1; (j * vec[i]) + 1<= d; ++j){
			int c = j * vec[i] + 1;
			cnt++;
		}
	}
	cout<<cnt<<endl;
	return 0;
}


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

struct Cell {
   double x,y,z,r;
};

//参考: https://competitive-kivantium.hateblo.jp/entry/2016/07/07/230307
//     https://programgenjin.hatenablog.com/entry/2019/03/19/101827

int main(){
   int n;
   while(cin>>n, n){
      Cell cells[n];
      for(int i=0; i<n; i++){
         cin>>cells[i].x>>cells[i].y>>cells[i].z>>cells[i].r;
      }

      double cost[n][n];
      for(int i=0; i<n; i++){
         for(int j=0; j<n; j++){
            cost[i][j] = max(sqrt(pow(cells[i].x-cells[j].x, 2)+pow(cells[i].y-cells[j].y, 2)+pow(cells[i].z-cells[j].z, 2))-cells[i].r-cells[j].r, 0.0);
         }
      }
      //プリム法
      vector<double> minCost(n, 10e9);
      vector<bool> visited(n, false);
      minCost[0] = 0;
      double sum = 0;
      while(true){
         int v = -1;
         for(int i=0; i<n; i++){
            //未到達で、最小のコストの辺を選ぶ
            if(!visited[i] && (v==-1 || minCost[i] < minCost[v])) v = i;
         }
         if(v == -1) break;
         visited[v] = true;
         sum += minCost[v];

         for(int i=0; i<n; i++){
            minCost[i] = min(minCost[i], cost[v][i]);
         }
      }
      cout << fixed << setprecision(3) <<  sum << endl;
   }
}


Measured memory_bytes: 3276
#include <iostream>
#include <vector>
int N;
int count;
std::vector<int> answer;
int find(int* inorder, int c)
{
    for (int i = 0; i < N; i++) {
	if (inorder[i] == c) {
	    return i;
	}
    }
    return 0;
}
void rec(int* preorder, int* inorder, int l, int r)
{
    if (l >= r) {
	return;
    }
    int c = preorder[count++];
    int m = find(inorder, c);
    rec(preorder, inorder, l, m);
    rec(preorder, inorder, m + 1, r);
    answer.push_back(c);
}
int main()
{
    std::cin >> N;
    int* preorder = (int*)malloc(N * sizeof(int));
    int* inorder = (int*)malloc(N * sizeof(int));
    count = 0;
    for (int i = 0; i < N; i++) {
	std::cin >> preorder[i];
    }
    for (int i = 0; i < N; i++) {
	std::cin >> inorder[i];
    }
    rec(preorder, inorder, 0, N);
    for (int i = 0; i < N; i++) {
	std::cout << answer[i];
	if (i + 1 < N) {
	    std::cout << " ";
	}
    }
    std::cout << std::endl;
}

Measured memory_bytes: 3128
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt" > "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\b.answer"

long long int memo[1 << 20];
long long int getans(bitset<20>&bs, vector<int>&nums, vector<vector<int>>&edges) {
	if (memo[bs.to_ulong()] != -1)return memo[bs.to_ulong()];
	if (bs.count()) {
		long long int ans = 0;
		for (int i = 0; i < nums.size(); ++i) {
			if (!nums[i] && !bs[i]) {
				bs[i] = true;
				for (auto e : edges[i]) {
					nums[e]--;
				}
				ans += getans(bs, nums, edges);
				bs[i] = false;
				for (auto e : edges[i]) {
					nums[e]++;
				}
			}
		}
		return memo[bs.to_ulong()] = ans;
	}
	else {
		return memo[bs.to_ulong()]=1;
	}
}
vector<int>topo_sort(const vector<vector<int>>&edges) {
	int size_ = edges.size();
	vector<int>nums(size_);
	for (const auto& es : edges) {
		for (auto e : es) {
			nums[e]++;
		}
	}
	queue<int>que;
	for (int i = 0; i < size_; ++i) {
		if (!nums[i]) {
			que.push(i);
		}
	}
	vector<int>topo;
	while (!que.empty()) {
		int ver(que.front());
		topo.push_back(ver);
		que.pop();
		for (auto e : edges[ver]) {
			nums[e]--;
			if (!nums[e])que.push(e);
		}
	}
	if (topo.size() == size_)return topo;
	else return vector<int>();
}

int main() {
	for (int i = 0; i < (1 << 20); ++i) {
		memo[i] = -1;
	}
	int M, N; cin >> M >> N;
	vector<vector<int>>edges(M);
	vector<int>nums(M);
	for (int i = 0; i < N; ++i) {
		int x, y; cin >> x >> y; x--; y--;
		edges[x].push_back(y);
		nums[y] ++;
	}
	bitset<20>bs((1 << M) - 1);
	long long int ans = getans(bs, nums, edges);
	auto v=topo_sort(edges);
	for (int i = 0; i < v.size(); ++i) {
		cout << v[i] + 1 << endl;
	}
	return 0;
}

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



int main(void){
    
    string S;
    cin >> S;
    deque<char> dS(S.size());
    for(int i = 0; i < S.size();i++)dS[i] = S[i];
    
    int Q;cin >> Q;
    int rev = 0;
    for(int i = 0; i < Q;i++){
        int type;cin >> type;
        if(type == 2){
            int f;char c;
            cin >> f >> c;--f;
            if(rev)f = 1-f;
            if(f==0)dS.push_front(c);
            else dS.push_back(c);
        }
        else rev = 1 - rev;
    }
    
    if(rev)reverse(dS.begin(),dS.end());
    for(auto c:dS)cout << c;
    cout << endl;
    
    
}

Measured memory_bytes: 896
#include <iostream>
//#include <fstream>
#include <vector>
#include <string>
//#include <cstdlib>
//#include <algorithm>
//#include <set>
//#include <conio.h>
using namespace std;
 
int main(){
	int n;
	while(cin >> n&& n!=0){
		int sum=0,pri=1000-n;
		while(pri>=500){
			pri -=500;
			++sum;
		}
		while(pri>=100){
			pri -=100;
			++sum;
		}
		while(pri>=50){
			pri -=50;
			++sum;
		}
		while(pri>=10){
			pri -=10;
			++sum;
		}
		while(pri>=5){
			pri -=5;
			++sum;
		}
		while(pri>=1){
			pri -=1;
			++sum;
		}
		cout << sum << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

struct RollingHash {
    typedef long long ll;
    typedef pair<ll,ll> pll;

    ll base1;
    ll base2;
    ll mod1;
    ll mod2;
    vector<ll> hash1;
    vector<ll> hash2;
    vector<ll> pow1;
    vector<ll> pow2;

    RollingHash() : base1(1009), base2(1007), mod1(1000000007), mod2(1000000009) {}

    void init(const string &s) {
        int n = s.size();

        hash1.assign(n+1,0);
        hash2.assign(n+1,0);
        pow1.assign(n+1,1);
        pow2.assign(n+1,1);

        for(int i=0;i<n;i++) {
            hash1[i+1] = (hash1[i]+s[i]) * base1 % mod1;
            hash2[i+1] = (hash2[i]+s[i]) * base2 % mod2;
            pow1[i+1] = pow1[i] * base1 % mod1;
            pow2[i+1] = pow2[i] * base2 % mod2;
        }
    }
    //[l, r)
    pll get(int l,int r) {
        ll t1 = ((hash1[r] - hash1[l] * pow1[r-l]) % mod1 + mod1) % mod1;
        ll t2 = ((hash2[r] - hash2[l] * pow2[r-l]) % mod2 + mod2) % mod2;
        return make_pair(t1, t2);
    }

    RollingHash::pll concat(pll h1, pll h2, int h2_len) {
        return make_pair((h1.first*pow1[h2_len]+h2.first)%mod1, (h1.second*pow2[h2_len]+h2.second)%mod2);
    }

};

signed main(){
    string s, t;
    cin >> s >> t;
    if(s.size() < t.size()) return 0;
    RollingHash rs, rt;
    rs.init(s);
    rt.init(t);
    P p = rt.get(0, t.size());
    rep(i, 0, s.size() - t.size() + 1){
        P q = rs.get(i, i + t.size() );
        if(p.first == q.first && p.second == q.second){
            cout << i << endl;
        }
    }
}

Measured memory_bytes: 35632
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
signed main(){
  int N,M,O=0,P=0,count=0,count2=0;
  str S,W,T;
  cin>>N>>S;
  rep(0,N){
    if(S.at(i)=='I'){
      O+=1;
      if(O>P)P=O;
    }
    else if(S.at(i)=='D')O-=1;
  }
  cout<<P<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl

int sum_int(vector<int> &a){
  int sum=0;
  rep(i,a.size()) sum+=a.at(i);
  return sum;
}

int main(){
  int s,k;
  cin>>k>>s;
  int count=0;
  rep(x,k+1){
    rep(y,k+1){
      int z=s-x-y;
      if(0<=z && z<=k)
        count++;
    }
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int l = sc.nextInt();
		int ans = 0;
		if(0 <= l) {
			for(int i = 1; i < n; i++) {
				ans += l + i;
			}
		} else if(-n + 1 <= l) {
			for(int i = 0; i < n; i++) {
				ans += l + i;
			}
		} else {
			for(int i = 0; i < n - 1; i++) {
				ans += l + i;
			}
		}
		System.out.println(ans);

	}

}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define int long long
using namespace std;

class RollingHash{
public:
  typedef long long ll;
  ll B, mod;  //B: ハッシュ基数
  int n;
  string s;
  vector<ll> hash;
  vector<ll> k;
  
  RollingHash():n(-1){};
  RollingHash(string s,ll B = 1777771,ll mod = 1e9 + 7):
    B(B),mod(mod),n(s.size()),s(s),hash(n+1),k(n+1)
  {
    for(int i=0;i<n;i++) hash[i+1] = (hash[i] * B % mod + s[i]) % mod;
    k[0] = 1;
    for(int i=1;i<=n;i++) k[i] = (k[i-1] * B) % mod;
  }
  
  ll get(int l,int r)const{ //[l, r)
    assert(0<=l && r<=n && l<=r);
    return (mod + hash[r] - hash[l] * k[r-l] % mod) % mod;
  }
  
  //hash[a]とB.hash[b]からみて何文字一致してるか。
  int count(int a, const RollingHash &B, int b){
    int L = 0, R = min( n - a, B.n - b ) + 1;
    while( L + 1 < R ){
      int M = ( L + R ) / 2;
      get( a, a + M ) != B.get( b, b + M ) ? R = M : L = M;
    }
    return L;
  }
};

class RollingHash2{
public:
  typedef long long ll;
  ll B, mod;  //B: ハッシュ基数
  int n;
  string s;
  vector<ll> hash;
  vector<ll> k;
  
  RollingHash2():n(-1){};
  RollingHash2(string s,ll B = 11111111,ll mod = 1e9 + 7):
    B(B),mod(mod),n(s.size()),s(s),hash(n+1),k(n+1)
  {
    for(int i=0;i<n;i++) hash[i+1] = (hash[i] * B % mod + s[i]) % mod;
    k[0] = 1;
    for(int i=1;i<=n;i++) k[i] = (k[i-1] * B) % mod;
  }
  
  ll get(int l,int r)const{ //[l, r)
    assert(0<=l && r<=n && l<=r);
    return (mod + hash[r] - hash[l] * k[r-l] % mod) % mod;
  }
  
  //hash[a]とB.hash[b]からみて何文字一致してるか。
  int count(int a, const RollingHash &B, int b){
    int L = 0, R = min( n - a, B.n - b ) + 1;
    while( L + 1 < R ){
      int M = ( L + R ) / 2;
      get( a, a + M ) != B.get( b, b + M ) ? R = M : L = M;
    }
    return L;
  }
};



signed main(){
  
  int n;
  cin>>n;
  
  string s;
  cin>>s;
  
  RollingHash r(s);
  RollingHash2 r2(s);
  
  int LL = 0, RR = n / 2 + 1;

  while( LL + 1 < RR ){

    int i = ( LL + RR ) / 2;
    
    unordered_set<int> S;
    queue<int> q;
    
    unordered_set<int> S2;
    queue<int> q2;
    
    int flg = 0;
    
    for(int j=0;j<=n-i;j++){
      
      int L = j, R = j + i;
      int hash = r.get( L, R );
      int hash2 = r2.get( L, R );
      
      if( j >= i ){
	S.insert( q.front() );
	q.pop();
	S2.insert( q2.front() );
	q2.pop();
      }
      
      if( S.count( hash ) && S2.count( hash2) ){
	flg = 1;
	break;
      }
      
      q.push( hash );
      q2.push( hash2 );
      
    }
    
    if( flg ) LL = i;
    else RR = i;
    
  }
  
  cout<<LL<<endl;
  
  return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<numeric>
#include<utility>
#include<unordered_map> //hash map
#include<cmath>
#include<iomanip>

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

#define INF 10000007

typedef  long long ll;

using namespace std;

ll gcd(ll a,ll b){
    if (b==0)return a;
    return gcd(b,a%b);
}

ll deg(int i){
  ll ret = 1;
  while(i != 0){
    if(i/10 == 0){
      break;
    }
    i/=10;
  }
  return i;
}


void solve(){
  double a,b,h,m;
  cin >> a >> b >> h >> m;
  double th = min(abs(30*h-5.5*m), 360-abs(30*h-5.5*m));
  cout << setprecision(10) << sqrt(a*a+b*b-2*a*b*cos(th*M_PI/180)) << endl;
 

}

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


Measured memory_bytes: 4176
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#define FOR(i,s,e) for (int i = int(s); i < int(e); i++)
#define FORIT(i,c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define ISEQ(c) (c).begin(), (c).end()

int SURP = 1000000007;

int main(){
	int N;
	cin >> N;
	int c[N];
	FOR(i,0,N) cin >> c[i];

	sort(c,c+N);

	int min = c[N-1];
	int dan = 1;
	for(int i = N-2; i >=0; i--){
		if (min > c[i]){
			dan++;
			min = c[i];
		}
	}


	cout << dan << endl;
	return 0;

}


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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

bool ok(int x,set<char> blacklist)
{
	string s=to_string(x);
	for(char c:s) if(blacklist.count(c)) return false;
	return true;
}

int main()
{
	for(int n,k;cin>>n>>k && n|k;){
		set<char> blacklist;
		rep(i,k){
			int x; cin>>x;
			blacklist.insert('0'+x);
		}
		for(int x=n;;x++){
			if(ok(x,blacklist)){
				cout<<x<<endl;
				break;
			}
		}
	}
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        long count = 0;
        
        if (k == 0) {
            count = (long)n * n;
        } else {
            for (int i = k + 1; i <= n; i++) {
                count += (long)(n / i) * (i - k);
                if (n % i >= k) {
                    count += (long)n % i - (k - 1);
                }
            }
        }
        
        System.out.println(count);
    }
}


Measured memory_bytes: 21588