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

#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SUM(a, b) accumulate(all(a), b)
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define FOR(i, m, n) for(int (i)=(m); (i)<(n); i++)
#define FORR(i, m, n) for(int (i)=(n)-1; (i)>=(m); i--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
#define debug(x) cerr << #x << " = " << x << endl
//#define int long long

typedef long long ll;
typedef unsigned long long ull;
//ll const MOD = 998244353;
ll const MOD = 1e9+7;
ll const INF = 1e18;

template<typename T> int size(const T& a){return (int)a.size();}
template<typename T> T Div(T a, T b){return (a + b - 1) / b;}
template<typename T> bool chmin(T& a, const T& b){if(a > b){a = b; return true;} return false;}
template<typename T> bool chmax(T& a, const T& b){if(a < b){a = b; return true;} return false;}




template<typename T, class Fn> T BinarySearch(T ng, T ok, Fn judge){
    while(abs(ok - ng) > 1){
        T mid = (ok + ng) / 2;
        if(judge(mid)) ok = mid;
        else ng = mid;
    }
    return ok;
}


signed main(){
    int n, q;
    string s;
    cin >> n >> q >> s;

    vector<pair<char,char>> query(q);
    for(auto& i : query) cin >> i.first >> i.second;

    auto left = [n, s, &query](int m){
        if(m < 0) return false;
        else if(m >= n) return true;
        int i = m;
        for(auto e : query){
            if(s[i] == e.first){
                if(e.second == 'L') i--;
                else i++;
            }
            if(i < 0) return false;
            else if(i >= n) return true;
        }
        return true;
    };

    auto right = [n, s, &query](int m){
        if(m >= n) return false;
        else if(m < 0) return true;
        int i = m;
        for(auto e : query){
            if(s[i] == e.first){
                if(e.second == 'L') i--;
                else i++;
            }
            if(i >= n) return false;
            else if(i < 0) return true;
        }
        return true;
    };

    int l = BinarySearch(-1, n, left);
    int r = BinarySearch(n, -1, right);

    cout << max(0, r - l + 1) << endl;

    return 0;
}


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

#define ll long long int

using namespace std;

void dfs(ll i, vector<ll> graph[], ll dp[], bool visit[]) {
    
    visit[i] = true;

    for (ll j = 0 ; j < graph[i].size() ; j++) {
        if (!visit[graph[i][j]]) {
            dfs(graph[i][j], graph, dp, visit);
        }
        dp[i] = max(dp[i], 1 + dp[graph[i][j]]);
    }
}

int main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> graph[n + 1];
    for (ll i = 1 ; i <= m ; i++) {
        ll x, y;
        cin >> x >> y;
        graph[x].push_back(y);
    }

    ll dp[n + 1];
    memset(dp, 0, sizeof dp);
    bool visit[n + 1];
    memset(visit, false, sizeof visit);
    for (ll i = 1 ; i <= n ; i++) {
        if (!visit[i]) {
            dfs(i, graph, dp, visit);
        }
    }
    ll max = 0;
    for (ll i = 1 ; i <= n ; i++) {
        if (dp[i] > max) max = dp[i];
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 9984
NM = list(map(int, input().split()))
AB = []
for i in range(NM[0]):
    AB.append(tuple(map(int, input().split())))
AB.sort()
M = 0
index=0
ans = 0
while M != NM[1]:
    if M + AB[index][1]>NM[1]:
        ans += (NM[1] - M)* AB[index][0]
        M = NM[1]
    else :
        ans += AB[index][0] * AB[index][1]
        M += AB[index][1]
    index += 1
print(ans)

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int calc(int X,int B){
    int lb=0,ub=X+114;
    while(ub-lb>1){
        int mid=(ub+lb)/2;
        int tmp=X/(B+mid);
        if(mid<=tmp)lb=mid;
        else ub=mid;
    }

    return lb;
}

signed main(){


    int Q;cin>>Q;


    while(Q--){
        int A,B;
        cin>>A>>B;
        if(A>B)swap(A,B);
        int X=A*B;

        int lb=0,ub=1001001001;
        while(ub-lb>1){
            int mid=(ub+lb)/2;
            if(mid*mid<=X-1)lb=mid;
            else ub=mid;
        }
        int a=1001001001;
        for(int i=-1000;i<=1000;i++){
            int x=lb+i;
            if(x<=A)continue;
            if((X-1)<x)continue;
            chmin(a,x-A+(X-1)/x-1);
        }
       if(a==1001001001)a=0;
        int b=A-1;


        int ans=a+b;
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;
#define INF 100000000
typedef long long ll;

int main(void) {
    int n;
    while (cin >> n) {
        ll ans = 0;
        for (int a = 0; a <= 1000; a++) {
            for (int b = 0; b <= 1000; b++) {
                if (a + b > n || n - (a+b) > 2000) continue;
                ans += min((n-a-b), 2000-(n-a-b)) + 1;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

int main() {
    int N,K,Q;
    cin >> N >> K >> Q;

    vector<int> A(N);
    vector<int> B(Q);

    for (int i = 0; i < N; i++) {
        A.at(i) = K - Q;

    }

    for (int i = 0; i < Q; i++) {
        cin >> B.at(i);
    }

    for (int i = 0; i < Q; i++) {
        A.at(B.at(i) - 1) ++;
    }

    string Y = "Yes";
    string No = "No";

    for (int i = 0; i < N; i++) {
        if (A.at(i) <= 0) {
            cout << No << endl;
        }

        else {
            cout << Y << endl;
        }
    }

}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  if(0<N && N<1000) cout << "ABC" << endl;
  else cout << "ABD" << endl;
}

Measured memory_bytes: 256
m,e,j,s;main(n){for(;--n||scanf("%d",&n)*n;puts(m>99|e>99|j>99|m+e>179|s>239?"A":s<210&&s<150|m<80?"C":"B"))scanf("%d%d%d",&m,&e,&j),s=m+e+j;}

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

int main() {
    int y, m, d;
    char c1, c2;  cin >> y >> c1 >> m >> c2 >> d;
    cout << (m > 4 ? "TBD" : "Heisei") << endl;
}

Measured memory_bytes: 256
S = str(input())
cnt = 0
cnt1 = 0
for i in range(len(S)):
    if S[i] == "R":
        cnt += 1
    if S[i] == "S":
        cnt1 = max(cnt,cnt1)
        cnt = 0
if cnt > cnt1:
    print(cnt)
else:
    print(cnt1)


Measured memory_bytes: 9032
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

typedef long long ll;

using namespace std;

int solve(int n){
    char in[1000001];
    int m,count=-1,ans=0;
    
    scanf("%d%s",&m,in);
    
    if(in[0]=='I')
        count=0;
    
    for(int i=1;i<m;i++){
        if(in[i]=='I'){
            if(in[i-1]=='I'){
                ans+=max(0,count-n+1);
                count=0;
            }else
                count++;
        }else if(in[i-1]!='I'){
            ans+=max(0,count-n+1);
            count=-1;
        }
    }
    ans+=max(0,count-n);
    
    printf("%d\n",ans);
    
    return 0;
}

int main(){
    int n;
    
    while(1){
        scanf("%d\n",&n);
        if(n==0)
            break;
        solve(n);
    }
    
    return 0;
}

Measured memory_bytes: 2168
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

typedef long long ll;

using namespace std;

ll INF = (ll)1 << 62;
ll getLIS(vector<ll> a, ll N)
{
	vector<ll> dp(N, INF);
	for (ll i = 0; i < N; ++i) {
		*upper_bound(dp.begin(), dp.begin() + N, a[i]) = a[i];
	}
	return lower_bound(dp.begin(), dp.begin() + N, INF) - dp.begin();
}

int main(int argc, const char * argv[]) {
  ll N;
  cin >> N;
  vector<ll> A(N);
  ll i;
  for(i=N-1;i>=0;i--){
    cin >> A[i];
  }
  cout << getLIS(A,N);

  return 0;
}


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

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int a, b;
  cin >> a >> b;
  int ans = a + b;
  ans = max(ans, a * b);
  ans = max(ans, a - b);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace _1367
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] ret = new int[x[0]]; int[] a = new int[x[0]];
            for (int i = 0; i < x[0]; i++) { ret[i] = i + 1; a[i] = i + 1; }
            for (int i = 0; i < x[1]; i++) a[int.Parse(Console.ReadLine()) - 1] = -i;
            Array.Sort(a,ret);
            foreach (int item in ret) Console.WriteLine(item);
        }
    }
}


Measured memory_bytes: 12576
#include <stdio.h>
 
int main (void) {
	long long int a = 0, b = 0, c = 0, tmp = 0, r = 0;
	while ( scanf("%d %d",&a,&b) != EOF){
		r=a*b;
		if(b>a){tmp=b;b=a;a=tmp;}
		while(b>0){c=b;b=a%b;a=c;}printf("%d %d\n",a,(r/a));}
	return 0;
}

Measured memory_bytes: 596
import sys
import itertools
sys.setrecursionlimit(10000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

a,b,c = map(int,input().split())
k = int(input())
cnt = 0
while True:
    if cnt == k:
        break
    if c<=b:
        c = 2*c
    elif b<=a:
        b = 2*b
    cnt+=1
if a<b and b<c:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#include <time.h>
//#include <random>
//#ifndef _LOCAL
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#endif
#define sz(x) int(x.size())
#define in(x) freopen(x, "r", stdin)
#define out(x) freopen(x, "w", stdout)
#define N 100500
#define oo ll(1e16)
#define pii pair <int, int>
#define pll pair <ll, ll>
#define ft first
#define sd second
#define pb push_back
#define ppb pop_back
#define el '\n'
#define elf endl
#define base ll(1e9 + 7)
#define re return
#define nins 4294967295
using namespace std;
typedef long long ll;
typedef long double ld;

//mt19937 rnd(0);

void solve() {
    ld r;
    cin >> r;
    cout.precision(2); cout << fixed;
    cout << r * ld(6.28) << el;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #ifdef _LOCAL
//        in("input.txt");

        int t = 1;
//        cin >> t;
        for (int i = 1; i <= t; i++) {
            cout << "Test #" << i << elf;

            clock_t start_time = clock();

            solve();

            cerr.precision(4); cerr << fixed;
            cerr << elf;
            cerr << "Time :: " << ld(clock() - start_time) / CLOCKS_PER_SEC << elf;

            cout << elf;
        }
    #else
        int t = 1;
//        cin >> t;

        while (t--) {
            solve();
            cout << el;
        }
    #endif
}


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

int keta( int N ){
    int count = 0;
    while(1){
        count++;
        N /= 10;
        if(N==0){
            break;
        }
    }
    return count;
}

int main(){
    int N;
    cin >> N;

    int tmp, count;
    count = 0;
    for( int n=1 ; n<=N ; n++){
        tmp = keta(n);
        count += tmp%2;
    }

    cout << count << endl;
} 

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e13 + 5);

const int MAX_N = (int)(3e2 + 5);

int n, m;
ll l;

ll path[MAX_N][MAX_N];

ll jump[MAX_N][MAX_N];

int q;

void calc_shortest_paths() {
  for (int k = 1; k <= n; ++k) {
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; ++j) {
        if (path[i][j] > path[i][k] + path[k][j]) {
          path[i][j] = path[i][k] + path[k][j];
        }
      }
    }
  }
}

void calc_shortest_jumps() {
  for (int k = 1; k <= n; ++k) {
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= n; ++j) {
        if (jump[i][j] > jump[i][k] + jump[k][j]) {
          jump[i][j] = jump[i][k] + jump[k][j];
        }
      }
    }
  }
}

int main(void) {
  // Here your code !
  scanf("%d %d %lld", &n, &m, &l);

  // initialize
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      path[i][j] = INF;
      path[j][i] = INF;
    }
    path[i][i] = 0L;
  }

  for (int i = 0; i < m; ++i) {
    int a, b;
    ll c;

    scanf("%d %d %lld", &a, &b, &c);

    if (c > l) continue;  // not able to use this edge even with maximum fuel

    path[a][b] = c;
    path[b][a] = c;
  }

  calc_shortest_paths();

  // prepare jump graph
  for (int i = 1; i <= n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      jump[i][j] = INF;
      jump[j][i] = INF;

      if (path[i][j] <= l) {
        jump[i][j] = 1L;
        jump[j][i] = 1L;
      }
    }
    jump[i][i] = 0L;
  }

  calc_shortest_jumps();

  scanf("%d", &q);

  for (int i = 0; i < q; ++i) {
    int s, t;
    scanf("%d %d", &s, &t);

    if (path[s][t] == INF) {
      printf("%d\n", -1);
      continue;
    }

    ll ans = jump[s][t] - 1L;

    printf("%lld\n", ans);
  }

  return 0;
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef double db;
typedef vector <ll> vll;
typedef pair <ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

int main()
{
    ios_base :: sync_with_stdio(false);
    cin.tie(NULL), cout.tie(NULL);
    string s;
    ll n, k;
    cin >> n >> k >> s;
    s[k - 1] = tolower(s[k - 1]);
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>
using namespace std;
typedef vector <int> vi;

int main(void){
	int n=5;
	vi a(n);
	for (int i=0; i<n; i++){
		cin>>a[i];
	}
	sort(&a[0], &a[n], greater <int>());

	for (int i=0; i<n; i++){
		if (i==n-1) cout<<a[i]<<endl;
		else cout<<a[i]<<" ";
	}
	return 0;
}

Measured memory_bytes: 1212
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main() {
    ll H,W,h,w;
    std::cin >> H>>W;
    std::cin >> h>>w;
    std::cout << H*W - h*W - w*H + h*w << std::endl;
}

Measured memory_bytes: 256
import math
a,b,x=map(int,input().split())
x_2d = x/a
if a*a*b == x:
    print(0)
    exit()
if x/a > (a*b)/2:
    print(90-math.degrees(math.atan(a/(2*b-2*x/(a*a)))))
else:
    print(math.degrees(math.atan(b/(2*x/(a*b)))))

Measured memory_bytes: 38384
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define all(x) (x).begin(),(x).end()

int main()
{
	int N, K;
	cin >> N >> K;

	string S;
	cin >> S;

	S[K - 1] += 'a' - 'A';

	cout << S << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 200005
const int mod=1e9+7;

int n,m,tot,T;
int now[maxn],pre[maxn*2],son[maxn*2],fuck[maxn],cnt[maxn],h[maxn];
int vis[maxn];

vector<int> f[maxn],g[maxn];

inline int read(){
	int x=0,f=1; char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

void add(int a,int b){son[++tot]=b,pre[tot]=now[a],now[a]=tot;}
void link(int a,int b){add(a,b);}

int power(int a,int k){
	int ret=1;
	for (;k;k>>=1,a=1ll*a*a%mod) if (k&1) ret=1ll*ret*a%mod;
	return ret;
}

int top,stack[maxn];

void tree_dp(int x,int d){
	int pps=-1; ++cnt[d];
	for (int p=now[x];p;p=pre[p]){
		tree_dp(son[p],d+1);
		if (pps<0||f[fuck[son[p]]].size()>f[fuck[pps]].size()) pps=son[p];
	}
	if (pps<0){fuck[x]=x,f[x].push_back(1),g[x].push_back(1); return;}
	fuck[x]=fuck[pps]; int pp=fuck[x];
	++T;
	for (int p=now[x];p;p=pre[p])
		if (son[p]!=pps){
			int size=f[fuck[son[p]]].size(),fuckpps=f[pp].size()-size;
			for (int i=0;i<size;i++){
				if (vis[i+fuckpps]!=T){
					vis[i+fuckpps]=T,h[i+fuckpps]=0;
					stack[++top]=i+fuckpps;
				}
				int a=f[fuck[son[p]]][i],b=g[fuck[son[p]]][i];
				int c=f[pp][i+fuckpps],d=g[pp][i+fuckpps],e=h[i+fuckpps];
				f[pp][i+fuckpps]=(1ll*a*d+1ll*b*c)%mod;
				g[pp][i+fuckpps]=1ll*b*d%mod;
				h[i+fuckpps]=(1ll*e*a+1ll*e*b+1ll*a*c)%mod;
			}
		}
    while (top){
		g[pp][stack[top]]=(g[pp][stack[top]]+h[stack[top]])%mod;
		top--;
	}
	f[pp].push_back(1),g[pp].push_back(1);
}

int main(){
	n=read()+1;
	for (int i=2,x;i<=n;i++) x=read()+1,link(x,i);
	tree_dp(1,0); int ans=0,pp=fuck[1];
	reverse(f[pp].begin(),f[pp].end());/*
	for (int i=0,size=f[pp].size();i<size;i++)
	printf("%d %d %d\n",f[pp][i],i+1,cnt[i]);*/
	for (int i=0,size=f[pp].size();i<size;i++)
		ans=(ans+1ll*f[pp][i]*power(2,n-cnt[i]))%mod;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 43380
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	s := r.nextString()

	ans := "No"
	if s != "AAA" && s != "BBB" {
		ans = "Yes"
	}
	fmt.Fprintln(stdout, ans)
}


Measured memory_bytes: 640
n=gets.to_i
ab=$<.map{|s|s.split.map &:to_i}

ab.sort_by!{|a,b|-a-b}

s=0
t=true
ab.map{|a,b|
  if t
    s+=a
  else
    s-=b
  end
  t=!t
}
p s

Measured memory_bytes: 12536
def main():
    n=int(input())
    a=list(map(int,input().split()))
    cnt=1
    now=[0,0,0]
    mod=10**9+7
    for i in a:
        cnt=(cnt*now.count(i))%mod
        for j in range(3):
            if now[j]==i:
                now[j]+=1
                break
    print(cnt)
main()


Measured memory_bytes: 14092
#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
using ll = long long;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define VIEW(x) do {cerr << #x << ": "; for(auto i : x) cerr << i << " "; cerr << endl;} while(0)
#define ALL(x) (x).begin(),(x).end()
template<class T>bool umax(T &a, const T &b) {if(a<b){a=b;return 1;}return 0;}
template<class T>bool umin(T &a, const T &b) {if(b<a){a=b;return 1;}return 0;}

template<typename A,size_t N,typename T> void FILL(A (&array)[N],const T &val){fill((T*)array,(T*)(array+N),val);}
template<typename T> void FILL(vector<T> &v, const T &x) {fill(v.begin(), v.end(), x);}
template<typename T> void FILL(vector<vector<T>> &v, const T &x) {for(auto &i:v)fill(i.begin(), i.end(), x);}

int main() {
  int k; cin >> k;
  rep(i,k) cout << "ACL";
  cout << endl;
}


Measured memory_bytes: 3664
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
typedef long long ll;
ll k,n,h[200005],sum;
ll read()
{
	ll x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<3)+(x<<1)+ch-'0';
		ch=getchar();
	}
	return f*x;
}
bool cmp(int x,int y)
{
	return x>y;
}
int main()
{
	n=read();
	k=read();
	for(int i=1;i<=n;++i){
		h[i]=read();
		sum+=h[i];
	}
	sort(h+1,h+1+n,cmp);
	if(n<=k) printf("0");
	else
	{
		for(int i=1;i<=k;++i) sum-=h[i];
		printf("%lld",sum);
	}
	return 0;
}

Measured memory_bytes: 1792
#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() {
  int64_t a, b, k;
  cin >> a >> b >> k;
  if(a < k){
    b = max(b - (k-a), (int64_t)0);
    a = 0; 
  }
  else{
    a -= k;
  }

  cout << a << " " << b << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
ll mod = 1e09 + 7;

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

	ll n;
	cin >> n;
	vll t(n), v(n);
	REP(i, n) cin >> t[i];
	REP(i, n) cin >> v[i];

	ll T = 0;
	// f[i] : 最高速度の条件(時刻[f[i][0], f[i][1]]においてはv[i])
	vvll f(n + 2, vll(3));
	REP(i, n){
		f[i][0] = T;
		f[i][1] = T + t[i];
		f[i][2] = v[i];
		T += t[i];
	}
	f[n] = {0, 0, 0};
	f[n + 1] = {T, T, 0};
	double cur = 0, res = 0;
	REP(i, 2 * T + 1){
		double vm = 1e10, tmp;
		REP(j, n + 2){
			if(2 * f[j][0] <= i && 2 * f[j][1] >= i) tmp = f[j][2];
			else if(i < 2 * f[j][0]) tmp = f[j][2] + (2 * f[j][0] - i) * 0.5;
			else tmp = f[j][2] + (i - 2 * f[j][1]) * 0.5;
			vm = min(vm, tmp);
		}
		res += (vm + cur) * 0.5 * 0.5;
		cur = vm;
	}
	printf("%.5lf\n", res);
}


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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t n, d, a;
  std::cin >> n >> d >> a;
  std::vector<std::pair<int64_t, int64_t>> xh(n);
  std::cin >> xh;

  std::sort(xh.begin(), xh.end());

  int64_t ans = 0;

  int64_t acc = 0;
  std::vector<int64_t> data(n, 0);
  int64_t index = 0;

  for (int64_t i = 0; i < n; i++) {
    while (xh[index].first + 2 * d < xh[i].first) {
      acc -= data[index];
      index++;
    }

    xh[i].second = std::max<int64_t>(0, xh[i].second - acc * a);
    if (xh[i].second == 0) {
      data[i] = 0;
      continue;
    }

    const auto count = (xh[i].second - 1) / a + 1;
    ans += count;

    acc += count;
    data[i] = count;
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
int H[255];
int main()
{
	int n; cin>>n;
	for(int i=1;i<=n;i++)
		scanf("%d",&H[i]);
	for(int i=1;i<=n;i++){
		printf("node %d: key = %d, ",i,H[i]);
		if(i/2) printf("parent key = %d, ",H[i/2]);
		if(i*2<=n) printf("left key = %d, ",H[i*2]);
		if(i*2+1<=n) printf("right key = %d, ",H[i*2+1]);
		puts("");
	}
	return 0;
}



Measured memory_bytes: 3212
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
ll gcd(ll a, ll b){
	if(b==0) return a;
	return gcd(b, a%b);
}
int main()
{
	int n;
	cin>>n;
	vector<P> v1, v2;
	for(int i=0; i<n; i++){
		ll a, b;
		cin>>a>>b;
		if(b>=a) v1.push_back({b, a});
		else v2.push_back({a, b});
	}
	sort(v1.begin(), v1.end());
	sort(v2.begin(), v2.end());
	int n1=v1.size(), n2=v2.size();
	vector<ll> sc1(n1+1), sa1(n1+1), sa2(n2+1), mnb2(n2+1), mxb2(n2+1);
	mnb2[0]=1e9+7, mxb2[0]=0;
	for(int i=0; i<n2; i++) mnb2[i+1]=min(mnb2[i], v2[i].second), mxb2[i+1]=max(mxb2[i], v2[i].second);
	for(int i=0; i<n1; i++){
		sc1[i+1]=sc1[i]+v1[i].first-v1[i].second;
		sa1[i+1]=sa1[i]+v1[i].second;
	}
	for(int i=0; i<n2; i++) sa2[i+1]=sa2[i]+v2[i].first;
	auto check=[&](int m){
		for(int i=0; i<=min(m, n2); i++){
			if(m-i>n1) continue;
			ll s=-sa2[i]-sa1[m-i]+sc1[n1]-sc1[m-i];
			if(s>=0) return true;
		}
		return false;
	};
	int l=0, r=n;
	while(r-l>1){
		int mid=(l+r)/2;
		if(check(mid)) l=mid;
		else r=mid;
	}
	vector<ll> mxs(n2+2);
	mxs[0]=-1;
	using lll=__int128_t;
	P ans=P(0, 1);
	for(int i=0; i<=min(l, n2); i++){
		ll s=-1;
		if(l-i<n1) s=-sa2[i]-sa1[l-i]+sc1[n1]-sc1[l-i];
		mxs[i+1]=max(mxs[i], s);
		if(s<0) continue;
		if((lll)ans.first*v1[l-i].first<=(lll)s*ans.second) ans=P(s, v1[l-i].first);
	}
	for(int i=min(l, n2)+1; i<=n2; i++) mxs[i+1]=mxs[i];
	for(int i=0; i<n2; i++){
		ll s=mxs[i+1]+v2[i].second-v2[i].first;
		if(s<0) continue;
		if((lll)ans.first*v2[i].second<=(lll)s*ans.second) ans=P(s, v2[i].second);
	}
	for(int i=1; i<=n2 && i-1<=l; i++){
		ll s=-1;
		bool neg=0;
		if(l-i+1<=n1){
			if(-sa2[i]-sa1[l-i+1]+sc1[n1]-sc1[l-i+1]>=0) s=-sa2[i]-sa1[l-i+1]+sc1[n1]-sc1[l-i+1]+mnb2[i];
			else neg=1, s=-sa2[i]-sa1[l-i+1]+sc1[n1]-sc1[l-i+1]+mxb2[i];
		}
		if(s<0) continue;
		if(neg){
			if((lll)ans.first*mxb2[i]<=(lll)s*ans.second) ans=P(s, mxb2[i]);
		}else{
			if((lll)ans.first*mnb2[i]<=(lll)s*ans.second) ans=P(s, mnb2[i]);
		}
	}
	for(int i=0; i<=min(l, n2); i++){
		ll s=-1;
		bool neg=0;
		if(l-i+1<=n1){
			if(-sa2[i]-sa1[l-i+1]+sc1[n1]-sc1[l-i+1]>=0) s=-sa2[i]-sa1[l-i+1]+sc1[n1]-sc1[l-i+1]+v1[0].first;
			else neg=1, s=-sa2[i]-sa1[l-i+1]+sc1[n1]-sc1[l-i+1]+v1[l-i].first;
		}
		if(s<0) continue;
		if(neg){
			if((lll)ans.first*v1[l-i].first<=(lll)s*ans.second) ans=P(s, v1[l-i].first);
		}else{
			if((lll)ans.first*v1[0].first<=(lll)s*ans.second) ans=P(s, v1[0].first);
		}
	}
	ans=P(ans.first+l*ans.second, ans.second*n);
	ll g=gcd(ans.first, ans.second);
	cout<<ans.first/g<<" "<<ans.second/g<<endl;
	return 0;
}


Measured memory_bytes: 4976
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <random>
#include <assert.h>
#include <memory.h>
#include <time.h>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

using namespace std;

inline void setmin(int &x, int y) { if (y < x) x = y; }
inline void setmax(int &x, int y) { if (y > x) x = y; }
inline void setmin(ll &x, ll y) { if (y < x) x = y; }
inline void setmax(ll &x, ll y) { if (y > x) x = y; }

const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 52;

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    ll k, a, b;
    cin >> k >> a >> b;
    ll cnt = 1;
    ll d = min(a - 1, k);
    cnt += d;
    k -= d;
    if (cnt < a) {
        cout << cnt << "\n";
        return 0;
    }
    if (b - a >= 2) {
        cnt += (b - a) * (k / 2);
        k %= 2;
    }
    cnt += k;
    cout << cnt << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;

const long long M = 1000000007;

LL C[1001][1001];
LL S[1001][21];
void solve(long long N, long long K, std::vector<long long> a){
	for(int i=0;i<1001;i++){
		C[i][0]=1;
		for(int j=1;j<=i;j++){
			C[i][j]=(C[i-1][j-1]+C[i-1][j])%M;
		}
	}
	S[0][0]=1;
	for(int k=1;k<=K;k++){
		int d=a[k-1];
		S[0][k]=S[0][k-1]*C[N][d]%M;
		for(int n=1;n<=N;n++){
			for(int c=0;c<=min(d,n);c++){
				S[n][k]+=S[n-c][k-1]*C[n][c]%M*C[N-c][d-c]%M;
				S[n][k]%=M;
			}
			//cerr << n << ", " << k << ": " << S[n][k] << endl;
		}


	}
	cout << S[N][K] << endl;

}

int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::vector<long long> a(K);
    for(int i = 0 ; i < K ; i++){
        scanf("%lld",&a[i]);
    }
    solve(N, K, std::move(a));
    return 0;
}


Measured memory_bytes: 7552
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<map>
#define maxn 200005
using namespace std;
typedef long long ll;
ll n,a[maxn],sum[maxn];
map <ll,ll> m;
map <ll,ll> :: iterator ite;
ll ans;
int main(){
	scanf("%lld",&n);
	m[0]++;
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		sum[i] = sum[i-1] + a[i];
		m[sum[i]]++;
	}
	for(ite=m.begin();ite!=m.end();ite++){
		ans += ((*ite).second) * ((*ite).second - 1) >> 1;
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define ll long long
#define INF 1e9
#define pb push_back
#define mp  make_pair
#define loop(a,n) for(long long i=a;i<n;i++)
#define vil vector<long long int>
#define vi vector<int>
#define sz(v) v.size()
#define setbits(x)          __builtin_popcountll(x)
#define ff first
#define ss second
using namespace std;


ll gcd(ll a, ll b) {
  if (a == 0)return b;
  return gcd(b % a, a);
}
bool isperfect(ll n) {
  ll y = sqrt(n);
  if (n % y == 0 && y * y == n)return true;
  return false;
}
bool comp(pair<int,int> a, pair<int,int> b) {
    if(a.first == b.first) return a.second>b.second;
  return a.first < b.first;
}
 ll powi(ll a, ll b) {
  ll ans = 1;
  while (b > 0) {
    if (b & 1)ans = (ans * a);
    b = b >> 1;
    a = (a * a);
  }
  return ans;
}
bool isprime(ll n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0)return false;
  }
  return true;
}
bool prime[10000000];
void seive() {

  prime[1] = true;
  for (int i = 2; i * i < 10000000; i++) {

    if (prime[i])continue;
    for (int j = i * i; j < 10000000; j += i) {
      prime[j] = true;
    }

  }
}
int main()
{
  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  ll n,m;
  cin>>n>>m;
  ll sum=0;
  for(int i=0;i<m;i++){
      ll x;cin>>x;
      sum+=x;
  }
  ll ans=n-sum;
  if(ans<0) ans=-1;
  cout<<ans;
}



  


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

using namespace std;

int main() {
   int n;
   string s;
   cin>>n>>s;
   string t,tt;
   int a[26];
   int ans=0,tans;
   for(int i=1;i<n;i++){
       for(int j=0;j<26;j++)a[j]=0;
       tans=0;
        t=s.substr(0,i);
        tt=s.substr(i,n-i);
        for(int j=0;j<i;j++){
            a[t[j]-'a']++;
                    }
        for(int k=0;k<n-i;k++){
            if(a[tt[k]-'a']>0){tans++;a[tt[k]-'a']=0;}
       }
       ans=max(ans,tans);
   }
   cout<<ans<<endl;
    return 0;
}                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          

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

using namespace std;

#define MAX_V 26

int res;
bool found;
vector<int> G[MAX_V];
int visited[MAX_V],num[MAX_V];

void dfs(int v,int c){
  visited[v] = 0; num[v] = c;
  for(int i = 0 ; i < (int)G[v].size() ; i++){
    int to = G[v][i];
    if(visited[to] == -1){
      dfs(to,c+1);
    }else if(visited[to] == 0){
      res = max(res,num[v]-num[to]+1);
    }
  }
  visited[v] = 1;
}

int getLargestCycle(){
  res = 0;
  memset(num,-1,sizeof(num));
  memset(visited,-1,sizeof(visited));
  for(int i = 0 ; i < 26 ; i++){
    if(visited[i] == -1){
      dfs(i,1);
    }
  }
  return res;
}

void init(){
    found = false;
    for(int i = 0 ; i < MAX_V ; i++){
        G[i].clear();
    }
}

bool valid(string &a, string &b){
    int A = a.size(),B = b.size();
    if(A <= B) return true;
    for(int i = 0 ; i < B ; i++){
        if(a[i] != b[i]) return true;
    }
    return false;
}

bool check(vector<string> &v){
    int N = v.size();
    for(int i = 0 ; i < N-1 ; i++){
        if(!valid(v[i],v[i+1])) return false;
        int a = v[i].size(),b = v[i+1].size();
        for(int j = 0 ; j < min(a,b) ; j++){
            if(v[i][j] != v[i+1][j]){
                G[v[i][j]-'a'].push_back(v[i+1][j]-'a');
                break;
            }
        }
    }
    return (getLargestCycle() < 2);
}

int main(){
    int N;
    while(cin >> N, N){
        vector<string> v(N);
        for(int i = 0 ; i < N ; i++){
            cin >> v[i];
        }
        init();
        cout << (check(v) ? "yes" : "no") << endl;
    }
    return 0;
}

Measured memory_bytes: 1288
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char s[6];
    int i;
    for(i=0; i<6; i++)
        cin>>s[i];
    if((s[2]==s[3])&&(s[4]==s[5]))
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int much, foot;
  cin >> much >> foot;
  if(much * 4 < foot) {
    cout << "No" << endl;
  }
  else if(much * 2 > foot) {
    cout << "No" << endl;
  }
  else if(foot % 2 != 0) {
    cout << "No" << endl;
  }
  else {
    cout << "Yes" << endl;
  }
  return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n,h;
    cin>>n>>h;
    int amax=-1,b[n+1];
    b[0]=0;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        amax=max(amax,a);
        cin>>b[i+1];
    }
    sort(b+1,b+n+1,greater<int>());
    for(int i=0;i<n;i++){
        b[i+1]+=b[i];
    }
    int ans=INF;
    for(int i=n;i>=0;i--){
        if(b[i]>=h)ans=i;
        else{
            ans=min(ans,i+(h-b[i]+amax-1)/amax);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>
char w[100];
int len;
int n[33];
int main()
{
	scanf("%s",w);
	len=strlen(w);
	int value;
	for(int i=0;i<len;i++)
	{
		value=w[i]-'a';
		if(value>=0) 
			n[value]++;
	}
	int ans=1;
	for(int i=0;i<26;i++)
	{if(n[i]%2==1) ans=0;

	}
	if(ans==1) printf("Yes");
	else printf("No");
}

Measured memory_bytes: 128
from sys import stdin

N = int(stdin.readline().rstrip())
[T, A] = list(map(int, stdin.readline().rstrip().split()))
H = list(map(int, stdin.readline().rstrip().split()))



def temp(t, height):
    return t - height * 0.006

def difference(a, t):
    return max(a, t) - min(a, t)

nearest_point = 0
nearest_diff = 1000000

for i in range(N):
    t = temp(T, H[i])
    diff = difference(A, t)

    if nearest_diff > diff:
        nearest_point = i
        nearest_diff = diff

print(nearest_point+1)


Measured memory_bytes: 3060
from bisect import bisect_left, bisect_right
import sys
INFTY=sys.maxsize

def readinput():
    n=int(input())
    a=list(map(int,input().split()))
    return n,a

def main(n,a):
    # order=[]
    # for i in range(n):
    #     order.append([a[i],i])
    s=sorted(a)
    ai=s[n-1]

    aj0=ai/2
    j=bisect_right(s, aj0)-1
    #print(s,aj0,j) 
    aj=s[j]
    if aj==aj0:
        return ai,aj

    if j+1<n:
        aj1=s[j]
        aj2=s[j+1]
        if aj0-aj1<=aj2-aj0:
            aj=aj1
        else:
            aj=aj2
    return ai,aj


if __name__=='__main__':
    n,a=readinput()
    i,j=main(n,a)
    print(i,j)


Measured memory_bytes: 19852
module Main where

import Control.Applicative
import Numeric
import Data.Char
import Data.List
import Data.Ord
-- import Control.Monad

main :: IO ()
main = do
  { l1 <- getLine
  ; l2 <- getLine
  ; let l1' = l1 ++ l1
  ; if isInfixOf l2 l1' then putStrLn "Yes" else putStrLn "No"
  }



Measured memory_bytes: 3524
import java.util.*;
 
public class Main{
  public static int[] dp;
  public static void main(String[]args){
    Scanner sc =  new Scanner(System.in);
    String[] s = sc.nextLine().split(" ");
    int H = Integer.parseInt(s[0]);
    int W = Integer.parseInt(s[1]);
    
    char[][] maze = new char[H][W];
    for(int i = 0; i < H; i++){
      String t = sc.nextLine();
      for(int j = 0; j < W; j++){
        maze[i][j] = t.charAt(j);
      }
    }
    
    int[][] dp = new int[H][W];
    dp[0][0] = 1;
    for(int i = 0; i < H; i++){
      for(int j = 0; j < W; j++){
        if(i < H-1 && maze[i+1][j] == '.'){
          dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % 1000000007;
        }
        
        if(j < W-1 && maze[i][j+1] == '.'){
          dp[i][j+1] = (dp[i][j+1] + dp[i][j]) % 1000000007;
        }
      }
    }
    System.out.println(dp[H-1][W-1]);
  }
}


Measured memory_bytes: 46832
#n = int(input())
n, x  = map(int, input().split())
#h = list(map(int, input().split()))
#s = list(str(input()))
m = [0]*n
for i in range(n):
  m[i] = int(input())

sum = sum(m)
x = x-sum
num = int(x/min(m))
print(num+n)

Measured memory_bytes: 2940
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read
 
 
n,m = map(int,input().split())

a = list(map(int, input().split()))  # n個の文字列がリストに格納される

ans = n-sum(a)
if ans >= 0:
    print(ans)
else:
    print('-1')

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

LL x,k,d;

int main() {
	cin >> x >> k >> d;
	x = max(x,-x);
	LL divv = x/d;
	if(divv >= k)
		cout << x-k*d;
	else {
		LL rem = x%d;
		if(divv%2 == k%2)
			cout << rem;
		else
			cout << d-rem;
	}
	return 0;
}

Measured memory_bytes: 3600
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;

public class Main {
    public static void main(String args[]){
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try{
            String line;
            int block[]=new int[64];
            while((line=br.readLine())!=null){  //if(line.equals(""))break;
                for(int j=0;j<8;j++)block[j]=Integer.parseInt(line.charAt(j)+"");
                for(int i=1;i<8;i++){
                    line=br.readLine();
                    for(int j=0;j<8;j++)block[j+i*8]=Integer.parseInt(line.charAt(j)+"");
                }
                System.out.println(detect(block));
                if((line=br.readLine())==null)break;
            }
        }catch(Exception e){e.printStackTrace();}        
    }
    static String detect(int[] block){
        ArrayList<Integer>ones = new ArrayList<Integer>();
        for(int i=0; i<64;i++) if(block[i]==1) ones.add(i);
        if(ones.get(3)-ones.get(0)==3)return "C";
        if(ones.get(3)-ones.get(0)==24)return "B";
        if(ones.get(3)-ones.get(0)==1+8)return "A";
        if(ones.get(3)-ones.get(0)==15)return "D";
        if(ones.get(3)-ones.get(0)==10)return "E";
        if(ones.get(3)-ones.get(0)==17)return "F";
        if(ones.get(3)-ones.get(0)==8)return "G";
        
        return null;
    }
}

Measured memory_bytes: 17212
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>

using namespace std;

typedef pair<double,double> P;
double EPS = 1e-8;

double add(double a, double b){
  if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0;
  return a+b;
}

struct point{
  double x, y;
  point(){}
  point(double x,double y) : x(x) , y(y){}

  point operator + (point p){
    return point(add(x,p.x), add(y,p.y));
  }

  point operator - (point p){
    return point(add(x,-p.x), add(y,-p.y));
  }

  point operator * (double d){
    return point(x*d,y*d);
  }

  point operator / (double d){
    return point(x/d,y/d);
  }
};


struct circle{
  point p;
  double r;
};

vector<point> circles_cross(circle a, circle b){
    vector<point> ret;
     
    double x = a.p.x - b.p.x , y = a.p.y - b.p.y;
    double L = x * x + y * y;
    if(L > pow(a.r+b.r,2))return ret;
     
    L = sqrt(L);
    double C = atan2(b.p.y-a.p.y,b.p.x-a.p.x);
    double alpha = acos((L*L+a.r*a.r-b.r*b.r)/(2*L*a.r));
     
    point r1,r2;
    r1.x = a.p.x + cos(C+alpha) , r1.y = a.p.y + sin(C+alpha);
    r2.x = a.p.x + cos(C-alpha) , r2.y = a.p.y + sin(C-alpha);
     
    ret.push_back(r1) , ret.push_back(r2);
     
    return ret;
}

int main(void){
  int n;
  circle a[100];

  while(cin >> n,n){
    vector<P>d;

    for(int i=0;i<n;i++){
      scanf("%lf,%lf",&a[i].p.x,&a[i].p.y);
      a[i].r=1;
    }

    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
	vector<point> p=circles_cross(a[i],a[j]);
	for(int k=0;k<p.size();k++){
	  d.push_back(make_pair(p[k].x,p[k].y));
	}
      }
    }

    int count,ans=1;
    for(int i=0;i<d.size();i++){
      count=0;
      
      for(int j=0;j<n;j++){
	if(pow(d[i].first-a[j].p.x,2)+pow(d[i].second-a[j].p.y,2)<=1+EPS)count++;
      }
	ans=max(ans,count);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 0
package main

// Solution for https://atcoder.jp/contests/abc173/tasks/abc173_b

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

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

func (con *contest) main() error {
	var n int
	con.Scan(&n)
	m := map[string]int{}
	for i := 0; i < n; i++ {
		var s string
		con.Scan(&s)
		m[s]++
	}
	for _, k := range []string{"AC", "WA", "TLE", "RE"} {
		con.Println(k, "x", m[k])
	}
	return nil
}


Measured memory_bytes: 3828
import java.util.*;
public class Main {
	public static void main(String[] args){
	  Scanner sc = new Scanner(System.in);
      String str = sc.next();
      int num = 0;
      int max = 0;
      int length = str.length();
      for(int i=0;i<length;i++){
        switch(str.substring(i,i+1)){
          case "A":
          case "T":
          case "C":
          case "G":
            num++;
            break;
          default:
            num = 0;
        }
        if(num > max)max = num;
      }
      System.out.println(max);
	}
}

Measured memory_bytes: 21844
import Control.Applicative
import Text.Printf

degToRad :: Floating a => a -> a
degToRad d = d * pi / 180

s :: Floating a => a -> a -> a -> a
s a b c = 0.5 * a * b * (sin . degToRad) c

l :: Floating a => a -> a -> a -> a
l a b c = a + b + sqrt (a ^ 2 + b ^ 2 - 2 * a * b * (cos . degToRad) c)

h :: Floating a => a -> a -> a
h b c = b * (sin . degToRad) c

main :: IO ()
main = do
    [a, b, c] <- (map (read :: String -> Double) . words) <$> getLine
    printf "%.8f\n%.8f\n%.8f\n" (s a b c) (l a b c) (h b c)

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

int main(){
  int l,r,d;
  cin>>l>>r>>d;
  int ans=0;
  int left=(int)ceil((l*1.0)/(d));
  int right=(int)floor((r*1.0)/(d));
  ans+=(right-left+1);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3612