akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;


class Program
{
    static void Main(string[] args)
    {
        // 入力
        //var s = Console.ReadLine();
        //var n = int.Parse(Console.ReadLine());
        int[] nk = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nk[0];
        var k = nk[1];
        int[] p = Console.ReadLine().Split().Select(int.Parse).ToArray();
        Array.Sort(p);

        var ans = 0;
        for (int i = 0; i < k; i++)
        {
            ans += p[i];
        }

        // 出力
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 28644
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int A, B, C, D, N;
  	cin >> N;
  	A=0;
    B=0;
  	C=0;
  	D=0;
  	for (int i = 0; i < N; i++) {
    		string S;
        	cin >> S;
      		if(S=="AC"){
        	  	A++;
        	}
      		else if(S=="WA"){
        	  	B++;
        	}
      		else if(S=="TLE"){
        	  	C++;
        	}
      		else if(S=="RE"){
        	  	D++;
        	}
    }
  	
  	cout << "AC x " << A <<endl;
    cout << "WA x " << B <<endl;
    cout << "TLE x " << C <<endl;
    cout << "RE x " << D <<endl;
  
  	return 0;
  	
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

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


int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1LL << 60;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())
#define rSORT(v) std::sort(v.begin(), v.end(),std::greater<int>())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    string s;
    cin >> n >> s >> k;
    for (size_t i = 0; i < s.size(); ++i) {
        if (s[i] != s[k - 1]) cout << '*';
        else cout << s[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
/**
 * 解説の方法を試す
 * priority_queueで1個ずつ管理するのではなく、vectorで高さごとの数を管理してみる
 */

#include <iostream>
#include <stack>
#include <unordered_map>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <functional>
#include <iterator>
#include <tuple>
#include <set>

using namespace std;

vector<int> groupby(vector<int> ss) {
  vector<int> ss_counts; // 同じ数値をひとまとめに
  int count = 0;
  int old_s = ss[0];
  for (const auto& s : ss) {
    if (s == old_s) {
      count++;
    } else {
      ss_counts.emplace_back(count);
      count = 1;
    }

    old_s = s;
  }
  ss_counts.emplace_back(count);

  return ss_counts;
}

int main() {
  int n;
  cin >> n;
  vector<int> ss(pow(2,n));

  for (int i = 0; i < pow(2,n); i++) {
    cin >> ss[i];
  }
  sort(ss.begin(), ss.end(), greater<>()); // 大きい順に並べる

  const vector<int>& ss_counts = groupby(ss);

  vector<int> slims(n+1,0); // 連結成分の数。キーはは完全二分木の木の高さ
  slims[n] = 1; // 最初は完全2分木の根。
  int slims_count = 1;

  bool result = true;

  for (const auto& ss_count : ss_counts) {
    if (slims_count < ss_count) {
      // 同じ数値を処理しきれない
      result = false;
      break;
    }

    vector<int> new_slims(slims.size(),0);
    int tmp_ss_count = ss_count;
    for (int i = slims.size()-1; tmp_ss_count > 0; i--) {
      // 今あるところから処理するため、いったん結果をnew_slimsに保存
      int current_slimis_count = min(slims[i], tmp_ss_count);
      tmp_ss_count -= current_slimis_count;
      slims[i] -= current_slimis_count;
      slims_count -= current_slimis_count;

      // 子ツリーに分割して、再度候補とする
      for (int j = 0; j < i; j++) {
        new_slims[j] += current_slimis_count;
      }
    }

    // new_slimsの結果をもとに戻す
    for (int i = new_slims.size() - 1; i >= 0; i--) {
      slims[i] += new_slims[i];
      slims_count += new_slims[i];
    }

    for (int i = slims.size() - 1; i >= 0; i--) {
      if (slims[i] == 0) {
        slims.pop_back();
      } else {
        break;
      }
    }
  }

  cout << (result ? "Yes" : "No") << endl;
}


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

int main()
{
    int k;
    int A[5];
    cin >> A[0];
    cin >> A[1];
    cin >> A[2];
    cin >> A[3];
    cin >> A[4];
    cin >> k;

    bool flag = true;
    for(int i = 0; i < 5; i++)
    {
        for(int j = 0; j < 5; j++)
        {
            if(i != j and abs(A[i] - A[j]) > k)
            {
                flag = false;
            }
        }
    }

    if(flag)
    {
        cout << "Yay!" << endl;
    }
    else
    {
        cout << ":(" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
using System;
class _0025
{
    public static void Main()
    {
        string str1, str2;
        string[] a, b;
        int hit,blow;
        while ((str1 = Console.ReadLine()) != null)
        {
            hit = 0; blow = 0;
            str2 = Console.ReadLine();
            a = str1.Split(); b = str2.Split();
            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    if (b[i] == a[j] && i == j) hit++;
                    else if (b[i] == a[j]) blow++;
                }
            }
            Console.WriteLine(hit + " " + blow);
        }
    }
}

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

using namespace std;
typedef long long ll;

#define INF (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

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



int main(void)
{
  ll a, b, c;
  cin >> a >> b >> c;
  ll d = c - a - b;
  if(d >= 0 && 4 * a * b < d * d) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
    
}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define _GLIBCXX_DEBUG

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=3.141592653589793;
const ll MOD=1e9+7;

int n;
ll a[200010];
ll dp[200010][3];
ll flag[200010][3];

ll ddpp(int x,int y){
    if (flag[x][y]){
        return dp[x][y];
    }
    else{
        flag[x][y]=1;
        if (n%2==0){
            if (y==1){
                if (x==1){
                    dp[x][y]=a[1];
                }
                else{
                    dp[x][y]=ddpp(x-2,y)+a[x];
                }
            }
            else{
                if (x==2){
                    dp[x][y]=max(a[1],a[2]);
                }
                else{
                    dp[x][y]=max(ddpp(x-2,y)+a[x],ddpp(x-1,1));
                }
            }
            return dp[x][y];
        }
        else{
            if (y==2){
                if (x==1){
                    dp[x][y]=a[x];
                    return a[x];
                }
                else{
                    dp[x][y]=ddpp(x-2,y)+a[x];
                    return dp[x][y];
                }
            }
            else if (y==1){
                if (x==2){
                    dp[x][y]=max(a[x],a[x-1]);
                    return dp[x][y];
                }
                else{
                    dp[x][y]=max(ddpp(x-2,y)+a[x],ddpp(x-1,y+1));
                    return dp[x][y];
                }
            }
            else{
                if (x==1){
                    dp[x][y]=0;
                    return 0;
                }
                else if (x==3){
                    dp[x][y]=max(a[1],max(a[2],a[3]));
                    return dp[x][y];
                }
                else{
                    dp[x][y]=max(ddpp(x-2,y)+a[x],max(ddpp(x-1,y+1),ddpp(x-2,y+2)));
                    return dp[x][y];
                }
            }
        }
    }
}


int main() {
    cin>>n;
    rep(i,n){
        cin>>a[i+1];
    }
    ddpp(n,0);
    cout<<dp[n][0]<<endl;
    return 0;
}

Measured memory_bytes: 23936
import java.util.*;

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

    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int x = sc.nextInt();

    int am = Math.min (x / 500, a);
    int bm = Math.min (x / 100, b);
    
    int cnt = 0;
    for (int i = am; i >= 0; i--) {
      int n = x;
      if (n == 500 * i) cnt++;
      for (int j = bm; j >= 0; j--) {
        n = x - (500 * i);
        if (n > 0 && n == 100 * j) cnt++;
        n = x - (500 * i) - (100 * j);
        if (n > 0 && n <= 50 * c) cnt++;
      }
    }

    System.out.println(cnt);
  }
}

Measured memory_bytes: 21716
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
#define N 200010
const int inf=0x3f3f3f3f;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,a[N],b[N],head[N],cnt,ia[N],ib[N],tot,S,T,dep[N],pre[N];
struct Edge{
	int to,nxt,val;
}edge[N<<2];
void Add(int a,int b,int c){
	edge[++cnt]={b,head[a],c};
	head[a]=cnt;
}
void adde(int a,int b,int c){
	Add(a,b,c),Add(b,a,0);
}
queue<int> q;
bool bfs(){
	memset(dep,0,sizeof(dep));
	dep[S]=1;
	q.push(S);
	while(!q.empty()){
		int u=q.front();
		q.pop();
		for(int i=head[u];i;i=edge[i].nxt){
			int v=edge[i].to;
			if(edge[i].val&&!dep[v]){
				dep[v]=dep[u]+1;
				q.push(v);
			}
		}
	}
	return dep[T]>0;
}
int dfs(int u,int limit){
	if(u==T)return limit;
	int flow=0;
	for(int &i=head[u];i;i=edge[i].nxt){
		int v=edge[i].to;
		if(edge[i].val&&dep[v]==dep[u]+1){
			int k=dfs(v,min(limit,edge[i].val));
			edge[i].val-=k;
			edge[i^1].val+=k;
			flow+=k;
			limit-=k;
		}
		if(!limit)break;
	}
	if(!flow)dep[u]=inf;
	return flow;
}
int Dinic(){
	int maxflow=0;
	for(int i=1;i<=tot;++i){
		pre[i]=head[i];
	}
	while(bfs()){
		maxflow+=dfs(S,inf);
		for(int i=1;i<=tot;++i){
			head[i]=pre[i];
		}
	}
	return maxflow;
}
int main(){
	n=read(),cnt=1,S=++tot,T=++tot;
	for(int i=1;i<=n;++i){
		a[i]=read()+1;
	}
	for(int i=1;i<=n;++i){
		b[i]=read()+1;
	}
	for(int i=1;i<=n;++i){
		if(ia[i])continue;
		int u=i;
		++tot;
		while(!ia[u]){
		   ia[u]=tot;
		   u=a[u];
		}
	}
	for(int i=1;i<=n;++i){
		if(ib[i])continue;
		int u=i;
		++tot;
		while(!ib[u]){
		   ib[u]=tot;
		   u=b[u];
		}
	}
	int same=0;
	for(int i=1;i<=n;++i){
		if(a[i]==i&&b[i]==i){
			++same;
		}
		else if(a[i]==i){
			adde(ib[i],T,1);
		}
		else if(b[i]==i){
			adde(S,ia[i],1);
		}
		else{
			adde(ib[i],ia[i],1);
			if(a[i]==b[i])adde(ia[i],ib[i],1);
		}
	}
	same+=Dinic();
	printf("%d\n",n-same);
	return 0;
}



Measured memory_bytes: 13920
program ABC063C
    implicit none
    integer(8)::N,i,result
    integer(8)::flg=0
    integer(8),allocatable,dimension(:)::S
    read(5,*)N
    allocate(S(N))
    read(5,*)(S(i),i=1,N)
    S=iqsort(S)
    result=sum(S)

    if(mod(result,10)==0)then
        do i=1,N
            if(mod(S(i),10)/=0)then
                flg=1
                result=result-S(i)
                exit
            end if
        end do

        if(flg==0)then
            print'(i0)',0
        else
            print'(i0)',result
        end if
    else
        print'(i0)',result
    end if

contains
    recursive function iqsort(ix) result(ires)
      integer(8), allocatable :: ires(:)
      integer(8), intent(in)  :: ix(:)
      integer :: k
      if (size(ix) <= 1) then 
        ires = ix
      else  
        k = ix(size(ix) / 2)
        ires = [iqsort(pack(ix, ix < k)), pack(ix, ix == k), iqsort(pack(ix, ix > k))] 
      end if
    end function iqsort
end program ABC063C

Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <utility>
using namespace std;
typedef long long ll;

deque<pair<double,double> > que;

int main()
{
	//freopen("F.in","r",stdin);
	int n,L;
	scanf("%d%d",&n,&L);
	
	pair<ll,ll> offset = make_pair(0,0);
	for (int i=1;i<=n;i++)
	{
		ll t,v;
		scanf("%lld%lld",&t,&v);
		if (i==1)
		{
			que.push_back(make_pair(0,0));
			que.push_back(make_pair((double)v,(double)v*(double)t));
			printf("%.8f\n",(double)t);
			continue;
		}
		
		double slope;
		while (!que.empty() && que[que.size()-1].first + offset.first > (double)(L-v))
		{
			slope = (double)(que[que.size()-1].second - que[que.size()-2].second) / (double)(que[que.size()-1].first - que[que.size()-2].first);
			que.pop_back();
		}
		pair<double,double>  tmp;
		if (que[que.size()-1].first + offset.first != (double)(L-v))
		{
			tmp = make_pair((double)(L-v) - offset.first, ((double)(L-v) - (que[que.size()-1].first+offset.first)) * slope + que[que.size()-1].second);
			que.push_back(tmp);
		}
		else tmp = que[que.size()-1];
		offset.first += (double)v;
		offset.second += (double)(v*t);
		printf("%.8f\n", (tmp.second + offset.second) / (tmp.first + offset.first));
		
		int lb = 0, ub = que.size()-1, mid;
		while (ub > lb)
		{
			mid = (lb + ub)/2;
			if ((que[mid+1].second + offset.second) / (que[mid+1].first + offset.first) >= (que[mid].second + offset.second) / (que[mid].first + offset.first)) lb = mid+1;
			else ub = mid;
		}
		for (int i=0;i<lb;i++) que.pop_front();
		que.push_front(make_pair(-offset.first,-offset.second));
	}
	return 0;
}


Measured memory_bytes: 17684
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
#define endl '\n'
typedef long long ll;


int main()
{
	int n;
	cin >> n;
	if (n % 1000 != 0)
		cout << 1000 - (n % 1000);
	else cout << 0;

	
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007

int a, b, c, d, e, k;

int main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        cin >> a>> b>> c>> d>>e>> k;
        if (e - a > k) {
                cout << ":(";
        } else cout << "Yay!";
return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<math.h>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(),(x).end()

using namespace std;

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


template<typename T>
void dump(T *arr, int h, int w){
	rep(i,h){
		rep(j,w) cout << arr[i][j] << "\t";
		cout << "\n";
	}
}

template<typename T>
void dump(T *arr, int a){
	rep(i,a) cout << arr[i] << "\t";
	cout << "\n";
}

template<typename T>
void dump(vector<T> arr, int a){
	rep(i,a) cout << arr[i] << "\t";
	cout << "\n";
}

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

bool compare(P a, P b){
	if(a.second != b.second) return a.second > b.second;
	else	return a.first > b.first;
}


int digits(ll num){
	ll d=0;
	while(num >= 1){
		num/= 10;
		d++;
	}
	return d;
}

ll pow_kai(ll a, int n){//aのn乗を計算します。
  ll x = 1;
  while(n > 0){//全てのbitが捨てられるまで。
    if(n&1){//1番右のbitが1のとき。
      x = x*a;
    }
    a = a*a;
    n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
  }
  return x;
}

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

	ll n;
	cin >> n;
	
	int depth = log2(n);
	cout << pow_kai(2LL, depth+1)  - 1 << "\n";

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#define lp(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n;
  double x[101],y[101],ans1=0,ans2=0,ans3=0,ans4=0;
  cin>>n;
  lp(i,n){
    cin>>x[i];
  }
  lp(i,n){
    cin>>y[i];
  }
  lp(i,n){
    ans1+=fabs(x[i]-y[i]);
    ans2+=pow(fabs(x[i]-y[i]),2);
    ans3+=pow(fabs(x[i]-y[i]),3);
    ans4=max(ans4,fabs(x[i]-y[i]));
    
  }
  ans2=pow(ans2,1.0/2);
  ans3=pow(ans3,1.0/3);

  cout<<setprecision(10)<<ans1<<endl<<ans2<<endl<<ans3<<endl<<ans4<<endl;

  
  return 0;
  
}


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

using namespace std;

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

  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    p[i]--;
  }

  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    int v = p[i];
    a[v] = 1 + v * n + i;
    b[v] = 1 + (n - 1 - v) * n;
  }

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

  return 0;
}

Measured memory_bytes: 896
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

ll n_x[55], m_x[55], n_y[55], m_y[55];
int main()
{
  ll n, m;
  int j;
  scanf("%lld%lld", &n, &m);
  for (int i = 0; i < n; i++)
  {
    scanf("%lld%lld", &n_x[i], &n_y[i]);
  }
  for (int i = 0; i < m; i++)
  {
    scanf("%lld%lld", &m_x[i], &m_y[i]);
  }
  for (int i = 0; i < n; i++)
  {
    ll tmp = INF, ans;
    for (j = 0; j < m; j++)
    {
      ll Manhattan = llabs(n_x[i] - m_x[j]) + llabs(n_y[i] - m_y[j]);
      if (tmp > Manhattan)
      {
        tmp = Manhattan;
        ans = j + 1;
      }
    }
    printf("%lld\n", ans);
  }

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
//#define int long long  
int main(){
    int a,b;
    cin >> a >> b;
    if(a==1)a=14;
    if(b==1)b=14;
    if(a>b){cout << "Alice" << endl;}else if(a==b){cout << "Draw" << endl;}else{cout << "Bob" << endl;} 
	return 0;
}


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

using namespace std;

const long mod = 1e9 + 7;

signed main()
{
    string s;
    cin >> s;
    reverse(s.begin(), s.end());

    int n = s.size();
    // dp[i][j]: 下からi桁目(10^iの桁の値)までを考慮した時の, 13で割ったあまりがjになるパターンの数
    vector<vector<long>> dp(n + 1, vector<long>(13, 0));
    dp[0][0] = 1;
    // 10のi乗を13で割った値
    long p_mod = 1;
    for(int i = 0; i < n; ++i){
        for(int j = 0; j < 13; ++j){
            for(int k = 0; k < 10; ++k){
                // ?でない, 数字が合ってない場合には処理しない
                if(s[i] != '?' && s[i] != '0' + k)
                    continue;
                // (今までのjの値 + k * のi乗) % 13 に遷移する
                int add_mod = p_mod * k;
                dp[i + 1][(j + add_mod) % 13] += dp[i][j];
                dp[i + 1][(j + add_mod) % 13] %= mod;
            }
        }
        p_mod = (p_mod * 10) % 13;
    }
    cout << dp[n][5] << endl;
    return 0;
}


Measured memory_bytes: 13696
import java.util.*;

public class Main{
    
    static final int MOD = (int)1e9+7;
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        
        long sum = mod_pow(2, n, MOD);
        sum = (sum + MOD - 1)%MOD;
        
        long am = 1;
        long bm = 1;
        for(int i=1; i<=a; i++){
            am *= n-i+1;
            am %= MOD;
            am *= mod_pow(i, MOD-2, MOD);
            am %= MOD;
        }
        for(int i=1; i<=b; i++){
            bm *= n-i+1;
            bm %= MOD;
            bm *= mod_pow(i, MOD-2, MOD);
            bm %= MOD;
        }
        
        sum = ((sum+MOD-am)%MOD+MOD-bm)%MOD;
        
        System.out.println(sum);
    }
    
    public static long mod_pow(long x, long p, long m){
        long a = 1;
        while(p>0){
            if(p%2==1){
                a = a*x%m;
            }
            x = x*x%m;
            p /= 2;
        }
        return a;
    }
}


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



int main(){
    ll N; cin >> N;
    vector<ll> A(N);
    map<ll, ll> M;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        M[i+A[i]]++;
    }
    ll ans = 0;
    for(int i = 0; i < N; i++){
        ll temp = i-A[i];
        ans+=M[temp];
    }
    cout << ans << endl;
}

Measured memory_bytes: 27420
list1 = [1,3,5,7,8,10,12]
list2 = [4,6,9,11]
list3 = [2]
x, y  = map(int, input().split())
 
if (x in list1)==(y in list1)==1 or(x in list2)==(y in list2)==1 or (x in list3)==(y in list3)==1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <regex>
#include <numeric>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define MOD 1000000007
#define SQ(x) ((x)*(x))

LL a[50];

int main() {
	int n;
	cin >> n;
	REP(i, n)cin >> a[i];
	LL ret = 0;
	while (1) {
		bool flag = false;
		REP(i, n) {
			LL x = a[i] / n;
			if (x != 0)flag = true;
			ret += x;
			REP(j, n) {
				a[j] += x;
			}
			a[i] = (a[i] - x) % n;
		}
		if (!flag)break;
	}
	cout << ret << endl;
	return 0;
}

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

namespace _0046
{
    class Program
    {
        static void Main(string[] args)
        {
            string temp = "";
            List<double> mountain = new List<double>();
            double answer = 0;
            while ((temp = Console.ReadLine()) != null)
            {
                mountain.Add(double.Parse(temp));
            }
            answer = mountain.Max() - mountain.Min();
            Console.WriteLine(answer);
        }
    }
}



Measured memory_bytes: 14176
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long i,j,k,n,m;
    while(cin>>n>>m)
    {
        for(i=1;i<=10000;i++)
        {
            if((i*n)%m!=0)
                {cout<<i*n<<endl;
                return 0;
                }
                
        }
        cout<<"-1"<<endl;
        
    }
}


Measured memory_bytes: 256
//package solution;

import java.io.*;
import java.util.*;
import java.math.*;
import java.text.*;
import java.awt.Point;

public final class Main {
    BufferedReader br;
    StringTokenizer stk;

    public static void main(String[] args) throws Exception {
        //new Thread(null, new Runnable() {
            //@Override
            //public void run() {
                //try {
                    new Main().run();
                //} catch(Exception ex) {ex.printStackTrace();}
            //}
        //}, "solution", 1<<26).start();
    }
    
    {
        stk = null;
        br = new BufferedReader(new InputStreamReader(System.in));
    }
    
    //long mod = 1000000007L;
    void run() throws Exception {
        char[] c = nt().toCharArray();
        if(c.length < 6) {
            pl("No");
            return;
        }
        if(c[2] == c[3] && c[4] == c[5]) {
            pl("Yes");
        } else {
            pl("No");
        }
    }
    
    //Reader & Writer
    String nextToken() throws Exception {
        if (stk == null || !stk.hasMoreTokens()) {
            stk = new StringTokenizer(br.readLine(), " ");
        }
        return stk.nextToken();
    }

    String nt() throws Exception {
        return nextToken();
    }

    String ns() throws Exception {
        return br.readLine();
    }

    int ni() throws Exception {
        return Integer.parseInt(nextToken());
    }

    long nl() throws Exception {
        return Long.parseLong(nextToken());
    }

    double nd() throws Exception {
        return Double.parseDouble(nextToken());
    }

    void p(Object o) {
        System.out.print(o);
    }

    void pl(Object o) {
        System.out.println(o);
    }
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
using namespace std;
typedef pair <int,int> pii;
int N, M;
string S;
int dp[100005];
int nxt[100005];
pii tree[400005];
int INF = 0x3f3f3f3f;

void update(int node, int s, int e, int idx, int val){
    if (s == e){
        tree[node].first = val;
        tree[node].second = idx;
    } else {
        int m = (s+e)/2;
        if (s <= idx && idx <= m) update(node<<1, s, m, idx, val);
        else update(node<<1|1, m+1, e, idx, val);
        if (tree[node<<1].first <= tree[node<<1|1].first){
            tree[node] = tree[node<<1];
        } else {
            tree[node] = tree[node<<1|1];
        }
    }
}

pii query(int node, int s, int e, int l, int r){
    if (r < s || l > e) return {INF,INF};
    else if (l <= s && e <= r) return tree[node];
    else {
        int m = (s+e)/2;
        pii p = query(node<<1, s, m, l, r);
        pii q = query(node<<1|1, m+1, e, l, r);
        if (p.first <= q.first){
            return p;
        } else {
            return q;
        }
    }
}

int main() {
    cin >> N >> M >> S;
    bool works = true;
    int cont = 0;
    for (int i=0; i<=N; i++){
        if (S[i] == '1'){
            cont++;
        } else {
            cont = 0;
        }
        if (cont >= M) works = false;
    }
    if (S[0] == '1' || S[N] == '1') works = false;
    if (!works) {
        cout << "-1\n" << endl;
        return 0;
    }
    memset(dp, INF, sizeof(dp));
    memset(nxt, INF, sizeof(nxt));
    fill(tree, tree+4*N, make_pair(INF,INF));
    dp[N] = 0;
    update(1, 0, N, N, dp[N]);
    for (int i=N-1; i>=0; i--){
        if (S[i] == '0') {
            pii result = query(1, 0, N, i+1, min(i+M, N));
            dp[i] = 1+result.first;
            nxt[i] = result.second;
            update(1, 0, N, i, dp[i]);
        }
    }
    int idx = 0;
    while (idx != N){
        if (nxt[idx] <= idx) {
            cout << "FALSE" << endl;
            return 0;
        }
        printf("%d ", nxt[idx]-idx);
        idx = nxt[idx];
    } cout << endl;
    return 0;
}

Measured memory_bytes: 4608
#include <cstdio>
#include <cmath>
 
using namespace std;
 
 
int main() {
    unsigned long long x, y;
    scanf("%llu %llu", &x, &y);
    unsigned int i{0};
 
    for (; x <= y; i++) {
        x = x * 2;
    }
    printf("%u",i);
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cctype>
#include <array>
using namespace std;

#define si static inline
#define gcu getchar_unlocked
si int in() {
	int n = 0, c = gcu();
	// bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	return n; }
	// return minus ? -n : n; }
si void scan(char *s) {while (!isspace(*s++ = gcu()));}
#define pcu putchar_unlocked
#define svo si void out
template <typename T>
svo(T n) {
	static char buf[20];
	char *p = buf;
	//if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
svo(const char *s){while(*s)pcu(*s++);}
svo(char *s){while(*s)pcu(*s++);}
svo(char c){pcu(c);}
//template <typename T>
//svo(vector<T> &v){for(T &x:v)out(' '),out(x);out('\n');}
//svo(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
template <typename head, typename... tail>
svo(head&& h, tail&&... t){out(h);out(move(t)...);}
#undef svo
#undef si

struct board {
	array<array<int, 8>, 8> b = {};

	void print() {
		for (auto r : b) {
			for (int c : r)
				//out(c == 2 ? 'Q' : c == 1 ? 'X' : '.');
				out(c == 2 ? 'Q' : '.');
			out('\n');
		}
	}

	board put(int r, int c) {
		board t = *this;
		auto cross = [&](int r, int c) {
			if (0 <= r && r < 8 && 0 <= c && c < 8)
				t.b[r][c] = 1;
		};
		for (int i = 0; i < 8; i++) {
			t.b[i][c] = t.b[r][i] = 1;
			cross(r + i, c + i);
			cross(r - i, c - i);
			cross(r + i, c - i);
			cross(r - i, c + i);
		}
		t.b[r][c] = 2;
		return t;
	}

	bool solver(int r) {
		if (r >= 8) {
			print();
			return true;
		}
		for (int i = 0; i < 8; i++) {
			if (!b[r][i]) {
				board t = put(r, i);
				if (t.solver(r + 1))
					return true;
			} else if (b[r][i] == 2)
				return solver(r + 1);
		}
		return false;
	}
};

int main() {
	board b;
	int k = in();
	while (k--) {
		int r = in();
		b = b.put(r, in());
	}
	b.solver(0);
}



Measured memory_bytes: 2624
#include <iostream>
#include <vector>
#include <climits>
#include <unordered_map>

using namespace std;

typedef long long ll;

int main(void) {
  int N; cin >> N;
  int A[100000];
  unordered_map<int, int> counter;

  int count = 0;
  for (int i = 0; i < N; i++) {
    int ai; cin >> ai;

    if (counter.find(ai) == counter.end()) {
      counter[ai] = 1;
    } else {
      counter[ai]++;
    }

    if (counter[ai] > ai)
      count++;
  }

  for (auto kv : counter) {
    if (kv.first > kv.second) {
      count += kv.second;
    }
  }

  cout << count << endl;
}


Measured memory_bytes: 4260
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define FOR(i, r, n) for (int i=(int)(r); i<=(int)(n); i++)
#define all(v) v.begin(), v.end()
#define INF 2147483647
#define INF64 9223372036854775807
#define MOD 1000000007

int main(){

    int n, k;
    cin>>n>>k;
    vector<int> a(n);
    rep(i, n) cin>>a[i];

    FOR(i, k, n-1){
        if(a[i-k]>=a[i]) cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }

}

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

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
	if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
	if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define SZ(x) ((int) ((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define INF 998244353
#define MAXN 400013

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

int N;
bitset<MAXN> arr;
bitset<MAXN> would;
ll dp[MAXN];
ll pw2[MAXN];
ll ans;

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	cout << fixed << setprecision(12);
	cerr << fixed << setprecision(4);
	cin >> N; string temps; cin >> temps;
	FOR(i, 0, N)
	{
		arr[i] = (temps[i] == '1');
	}
	pw2[0] = 1;
	FOR(i, 1, 2 * N + 1)
	{
		pw2[i] = pw2[i - 1] + pw2[i - 1]; if (pw2[i] >= INF) pw2[i] -= INF;
	}
	FOR(j, 1, 2 * N + 1)
	{
		if ((2 * N) % j) continue;
		FOR(k, 1, (j >> 1) + 1)
		{
			if (j % k) continue;
			dp[j] -= dp[k];
		}
		if (N % j == 0) continue;
		dp[j] += INF;
		//lol it has to be a factor of 2N but not N.
		//now try matching everythign up to here.
		//it's actually only up to the gcd(N, j) = j/2 that we need to check.
		//a[i] != a[i + j / 2]
		// cerr << "TRY PERIOD " << j << endl;
		FOR(i, 0, j / 2)
		{
			//this is the first place where it differs.
			if (arr[i])
			{
				dp[j] += pw2[(j / 2) - i - 1]; if (dp[j] >= INF) dp[j] -= INF;
				// cerr << "+" << pw2[(j / 2) - i - 1] << endl;
			}
			//is it ok for this to be the first place where it differs?
		}
		bool ok = true;
		FOR(i, 0, j / 2)
		{
			would[i] = arr[i];
		}
		FOR(i, j / 2, N)
		{
			would[i] = would[i - (j / 2)] ^ 1;
			if (would[i] ^ arr[i])
			{
				if (would[i]) ok = false;
				break;
			}
		}
		// if (ok) cerr << "OK " << j << endl;
		//check if following all the way is ok too.
		dp[j] += ok;
		// cerr << "RES " << j << " = " << dp[j] << endl;
		ans += dp[j] * j; ans %= INF;
	}
	cout << ans << '\n';
	return 0;
	//it's the period of inv(s)+s
	//lol. how about count: how many have a period of s?
}


Measured memory_bytes: 6804
#include<bits/stdc++.h>
using namespace std;
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);}

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool find(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  int size(int x) { return -data[root(x)]; }
};

int main() {
  int n, m; cin >> n >> m;
  vector<int> a(m), b(m);
  rep(i,m) {
    cin >> a[i] >> b[i];
    --a[i], --b[i];
  }

  UnionFind uf(n);
  vector<ll> ans(m);
  ans[m-1] = (ll)n * (n-1) / 2;
  for(int i=m-1; i>0; i--) {
    int x=a[i], y=b[i];
    if(uf.find(x,y)) {
      ans[i-1] = ans[i];
      continue;
    }
    ans[i-1] = ans[i] - ((ll)uf.size(x) * (ll)uf.size(y));
    uf.unite(x,y);
  }
  for(auto i : ans) cout << i << endl;
}


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

int main() {
	int N ,M;
	cin >>N>>M;
	int s,t;
	s=0;
	t=0;
	vector<int> a(N+1);
	for(int i=1;i<=N;i++){
		cin >>a.at(i);
		s+=a.at(i);
	}
	double u;
	u=(double)0.25*s/M;
	for(int i=1;i<=N;i++){
		if(a.at(i)>=u){
			t++;
		}
	}
	if(t>=M){
		cout <<"Yes";
	}
	else{
		cout << "No";
	}

}

Measured memory_bytes: 256
MAX = 2*10**5+5
def resolve():
    n = int(input())
    a = []
    leftmax = [0]*MAX
    rightmax = [0]*MAX
    for i in range(1,n+1):
        x=int(input())
        a.append(x)
        leftmax[i]=max(x,leftmax[i-1])
    for i in range(1,n+1):
        x = a[n-i]
        rightmax[n-i+1]=max(x,rightmax[n-i+2])

    for i in range(1,n+1):
        print(max(rightmax[i+1],leftmax[i-1]))

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 15640
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx2,tune=native")
//#pragma comment(linker, "/stack:200000000")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
 
#define X first
#define Y second
 
//#include <boost/unordered_map.hpp>
//using namespace boost;
 
/*
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> rbtree;
rbtree T;
*/
 
using i32 = int;
using i64 = long long;
using u8 = unsigned char;
using u32 = unsigned;
using u64 = unsigned long long;
using f64 = double;
using f80 = long double;
//using i128 = __int128_t;
//using u128 = __uint128_t;
using i128 = i64;
using u128 = u64;
 
ll power(ll a, ll b, ll p)
{
	if (!b) return 1;
	ll t = power(a, b/2, p);
	t = t*t%p;
	if (b&1) t = t*a%p;
	return t;
}
 
ll exgcd(ll a, ll b, ll &x, ll &y)
{
	if (b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	ll px, py;
	ll d = exgcd(b, a%b, px, py);
	x = py;
	y = px-a/b*py;
	return d;
}
 
template<class T>
inline void freshmin(T &a, const T &b)
{
	if (a > b) a = b;
}
 
template<class T>
inline void freshmax(T &a, const T &b)
{
	if (a < b) a = b;
}
 
//#define getchar getchar_unlocked
//#define putchar putchar_unlocked
 
int inp() {
	int x = 0, f = 0; char ch;
	for(ch = getchar(); !isdigit(ch); ch = getchar())
		if(ch == '-') f = 1;
	for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
	return f ? -x : x;
}
 
ll inp_ll() {
	ll x = 0; int f = 0; char ch;
	for(ch = getchar(); !isdigit(ch); ch = getchar())
		if(ch == '-') f = 1;
	for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
	return f ? -x : x;
}
 
template<class T>
bool read(T &x)
{
	x = 0;
	char ch = getchar();
	if (ch == EOF) return 0;
	for(; !isdigit(ch); )
	{
		ch = getchar();
		if (ch == EOF) return 0;
	}
	for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
	return 1;
}
 
template<class T>
void write(T x)
{
	static char s[22];
	static char *it = s+20;
	static char *end = s+20;
	if (!x)
		*-- it = '0';
	while (x)
	{
		*-- it = x%10+'0';
		x /= 10;
	}
	for (; it < end; ++ it)
		putchar(*it);
}
 
template<class T>
void writeln(T x)
{
	write(x);
	putchar('\n');
}
 
const int MAXN = 200010;
const int INF = 1000000000;
const int MOD = 1000000007;

int n;
char s[MAXN];
i64 F[MAXN][13];

int main()
{
	
	scanf("%s", s+1);
	n = strlen(s+1);
	F[0][0] = 1;
	for (int i = 0; i < n; ++ i)
		for (int j = 0; j < 13; ++ j)
		{
			if (isdigit(s[i+1]))
				(F[i+1][(j*10+s[i+1]-'0')%13] += F[i][j]) %= MOD;
			else
			{
				for (int k = 0; k < 10; ++ k)
				{
					(F[i+1][(j*10+k)%13] += F[i][j]) %= MOD;
				}
			}
		}
	cout << F[n][5] << endl;

	return 0;
}


Measured memory_bytes: 12544
package main

import (
	"fmt"
	"math"
)

func main() {
	var N, K int
	fmt.Scan(&N, &K)

	pwin := 0.0
	for i := 1; i <= N; i++ {
		coin := 0
		if i < K {
			for j := 1; ; j++ {
				if i*pow(2, j) >= K {
					coin = j
					break
				}
			}
		}
		pwin += (1 / float64(N)) * (1 / float64(pow(2, coin)))
	}
	fmt.Println(pwin)
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}


Measured memory_bytes: 512
def factoring(n):
    for i in range(2, n+1):
        while n % i == 0:
            n //= i
            d[i] += 1

N = int(input())

d = [0]*(N+1)

for n in range(2,N+1):
    factoring(n)

def num(n):
    return len([e for e in d if e >= n])

ans = num(74) + num(14)*(num(4)-1) + num(24)*(num(2)-1) + num(4)*(num(4)-1)*(num(2)-2)//2
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int n;
  cin>>n;
  vector<long long int>arr(n,0);
  for(int i=1;i<n;i++)
  {
    long long int x;
    cin>>x;
    arr[x-1]++;
  }
  for(int i=0;i<n;i++)
    cout<<arr[i]<<"\n";
}

Measured memory_bytes: 4764
#include <bits/stdc++.h>
using namespace std;
const double pi=acos(-1.0);
double a,b,x;
int main () {
	scanf("%lf%lf%lf",&a,&b,&x);
	if (a*a*b<=x*2.0) {
		x=a*a*b-x;
		double d=x*2.0/a/a;
		printf("%.10f\n",atan2(d,a)/pi*180.0);
		return 0;
	} else {
		double d=x*2.0/b/a;
		printf("%.10f\n",90-atan2(d,b)/pi*180.0);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    int k, t;
    cin >> k >> t;
    vector<int> a(t);
    for(int i = 0; i < t; i++) {
        cin >> a[i];
    }
    int mxa = *max_element(a.begin(), a.end());
    int ans = max(mxa-1-(k-mxa), 0);
    cout << ans << endl;
}

Measured memory_bytes: 256
def f(m):
    return (((N+1)*((m*(m+1))//2))%p-((m*(m+1)*(2*m+1))//6)%p+m%p)%p
p = 10**9+7
N,K = map(int,input().split())
cnt = (f(N+1)-f(K-1))%p
print(cnt)

Measured memory_bytes: 61772
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		while(true){
			String r = sc.next();
			String a = sc.next();
			if(r.equals("0") && a.equals("0"))break;
			
			int hit = 0;
			int blow = 0;
			
			for(int i = 0; i < 4; i++)
				if(Integer.parseInt(String.valueOf(r.charAt(i))) == 
				   Integer.parseInt(String.valueOf(a.charAt(i))))
					hit++;
			
			for(int i = 0; i < 4; i++)
				for(int u = 0; u < 4; u++)
					if(Integer.parseInt(String.valueOf(r.charAt(i))) == 
					   Integer.parseInt(String.valueOf(a.charAt(u))))
						blow++;
				
			System.out.println(hit + " " + (blow - hit));
		}sc.close();
	}
}

Measured memory_bytes: 64244
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,x,y) for(int i=(int)(x);i<(int)(y);++i)
#define FORE(i,x,y) for(int i=(int)(x);i<=(int)(y);++i)
#define FORD(i,x,y) for(int i=(int)(x);i>=(int)(y);--i)
#define PB push_back
#define ST first
#define ND second
#define db(v...) cerr<<#v<<"="<<v<<"\n";
#define dbr(v,x,y) FORE(_I,x,y){cerr<<#v<<"["<<_I<<"]="<<v[_I]<<"\n";}
#define dba(v) int _I=0;for(auto _it:v)cerr<<#v<<"["<<_I++<<"]="<<_it<<"\n";
typedef long long ll;
typedef pair<int,int> pii;
const int INF=2e9;
const int MOD=1e9+7;
const int MAXN=1e6+7;

int ans=0;
ll n,m,k,q;

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
    cin>>n>>k;
    n%=k;
    cout<<min(n,k-n)<<"\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstring>
#include <stack>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int dp[1 << 8][8];

int f(int mask, int last, VEC(VEC(int))& edges)
{
    const int n = edges.size();
    if (mask == (1 << n) - 1)
        return 1;

    int& ans = dp[mask][last];
    if (ans >= 0)
        return ans;

    ans = 0;
    for(int next : edges[last])
        if (!(mask & (1 << next)))
            ans += f(mask | (1 << next), next, edges);
    return ans;
}

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N, M;
    cin >> N >> M;
    VEC(VEC(int)) edges(N);
    FOR(i, 0, M) {
        int a, b;
        cin >> a >> b;
        a--;b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }

    memset(dp, -1, sizeof dp);
    cout << f(1, 0, edges) << endl;
    return 0;
};


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
using namespace std;

#define DIDITS 11

bool isNot753(int x,int zero) {
    if (x == 7 || x == 5 || x == 3)return false;
    if (x == 0 && zero == 0)return false;
    return true;
}

//N以下の整数の数を桁DPによって求める
long long solve(string N) {
    int L = N.size();
    //dp[決めた桁数][未満flag][問題による条件...]
    //dp[決めた桁数][未満flag][7,5,3 are included][他の数字が含まれている][左の桁に0以外の数字があるか]
    //             i     j  s  f  t  o  z
    long long dp[DIDITS][2][2][2][2][2][2] = {0};
    dp[0][0][0][0][0][0][0] = 1;

    //桁
    for (int i = 0; i < L; i++) {
        int D = N[i] - '0';
        //未満flag
        for (int j = 0; j < 2; j++) {
            //7flag
            for (int s = 0; s < 2; s++) {
                //5flag
                for (int f = 0; f < 2; f++) {
                    //3flag
                    for (int t = 0; t < 2; t++) {
                        //ほかの数字
                        for (int o = 0; o < 2; o++) {
                            //ゼロ以外の数字
                            for (int z = 0 ;z < 2; z++) {
                                //未満が確定(j==1)していたら0~9まで見れる
                                //確定していなければ0~Dまで
                                for (int d = 0; d <= (j ? 9 : D); d++) {
                                    dp[i + 1][j || (d < D)][s || d == 7][f || d == 5][t || d == 3][o || isNot753(d,z)][z||d!=0] 
                                        += dp[i][j][s][f][t][o][z];
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    return dp[L][0][1][1][1][0][1] + dp[L][1][1][1][1][0][1];
}

int main() {
    string N;
    cin >> N;
  
    cout << solve(N) << endl;

}

Measured memory_bytes: 256
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))


n , m = MI()
a = []
b = []
for i in range(n):
    a.append(IS())
for i in range(m):
    b.append(IS())
for i in range(n - m + 1):
    for j in range(n - m + 1):
        for k in range(m):
            if b[k] != a[i+k][j:j+m]:
                break
            if k == m - 1:
                print('Yes')
                exit()
print('No')


Measured memory_bytes: 71788
n,m=map(int,input().split())
d=[None]*n
for i in range(n):
  a,b=map(int,input().split())
  d[i]=[a,b]
  
d=sorted(d,key=lambda x:x[0])

ans=0
for i in range(len(d)):
  a=d[i][0]
  b=d[i][1]
  if b<m:
    m-=b
    ans+=a*b
  else:
    ans+=a*m
    break
print(ans)

Measured memory_bytes: 21992