akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long ll;
struct ee{
	int fi,se;
}p[524290];
int n,a[524290],N,ans;
void f(int x,int y)
{
	if(x==p[y].fi||x==p[y].se) return;
	if(a[x]>a[p[y].fi]) p[y].se=p[y].fi,p[y].fi=x;
	else if(a[x]>a[p[y].se]) p[y].se=x;
}
int main()
{
	scanf("%d",&n);
	N=1<<n;
	for(int i=0;i<N;i++) scanf("%d",&a[i]),p[i].fi=i,p[i].se=N;
	for(int i=1,j,ls,now;i<N;i++)
	{
		ls=i;
		j=(i-1)&i;
		for(;ls;)
		{
				int k=i^(ls-j);
				f(p[k].fi,i);
				f(p[k].se,i);
				ls=j;
				j=(j-1)&j;
		}
	}
	for(int i=1;i<N;i++)
	{
		ans=max(ans,a[p[i].fi]+a[p[i].se]);
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 8192
N = int(input())
A = list(map(int, input().split()))

B = {}

for i in range(N):
    # B.append(A[i] - i - 1)
    c = i + 1 - A[i]
    if c not in B.keys():
        B[c] = 1
    else: B[c] += 1
# print(A)
# print(B)

ans = 0
for i in range(N):
    c = A[i] + i + 1
    if c in B.keys():
        ans += B[c]
print(ans)







Measured memory_bytes: 40356
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<(n);i++)
typedef long long ll;

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

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

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <stack>

using namespace std;

string x;
stack<char> stk;

int main(void)
{
	cin >> x;
	for(int i = 0; i < x.size(); i++){
		if(stk.size() && stk.top() == 'S' && x[i] == 'T') stk.pop();
		else stk.push(x[i]);
	}
	cout << stk.size() << endl;
	return 0;
}

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

int n,l,rope[100007],I;

void search()
{
    for(int i=1;i<n;++i) if(rope[i]+rope[i+1]>=l) {I=i; break;}
    if(I!=-1)
    {
        printf("Possible\n");
        for(int i=1,j=n-1;i<I || j>I;++i,--j)
        {
            if(i<I) printf("%i\n",i);
            if(j>I) printf("%i\n",j);
        }
        printf("%i\n",I);
    }
    else printf("Impossible\n");
}

void prepare()
{
    scanf("%i%i",&n,&l); I=-1;
    for(int i=1;i<=n;++i) scanf("%i",&rope[i]);
}

int main()
{
    prepare();
    search();
    return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;

public class Main {
   public static void main(String args[]){
      Scanner keyboard = new Scanner(System.in);
      int x = keyboard.nextInt();
      int y, h, m, s;
      s = x % 60;
      x = x - s;
      y = x / 60;
      m = y % 60;
      y = y - m;
      h = y / 60;
      System.out.print(h);
      System.out.print(":");
      System.out.print(m);
      System.out.print(":");
      System.out.println(s);
   }
}


Measured memory_bytes: 26340
import sys
import numpy as np
import itertools

p,q,r = input().split()
p = int(p)
q = int(q)
r = int(r)
dest_min = p + q + r
dest = np.array(list(itertools.combinations([p,q,r],2)))


for dest_sample in dest:
    dest_min = min(dest_min, np.sum(dest_sample))

print(dest_min)

Measured memory_bytes: 27184
#include<bits/stdc++.h>
using namespace std;
template<class T>inline void Rd(T &x){
	x=0;char c=getchar();bool f=0;
	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();
	if(f)x=-x;
}
int n,K;
vector<pair<int,int> >M;

int main(){
	Rd(n);Rd(K);
	if(K>(n-1)*(n-2)/2){
		puts("-1");
		return 0;
	}
	int tot=(n-1)*(n-2)/2;
	for(int i=2;i<=n;++i)M.push_back(make_pair(1,i));
	if(tot==K){
		int a=M.size();
		printf("%d\n",a);
		for(int i=0;i<a;++i)
			printf("%d %d\n",M[i].first,M[i].second);
		return 0;
	}
	for(int i=2;i<=n;++i){
		for(int j=i+1;j<=n;++j){
			M.push_back(make_pair(i,j));
			tot--;
			if(tot==K){
				int a=M.size();
				printf("%d\n",a);
				for(int i=0;i<a;++i)
					printf("%d %d\n",M[i].first,M[i].second);
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	int flag=1;
	int n,t=0,x=0,y=0,tt,tx,ty;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>tt>>tx>>ty;
		if((abs(tx-x)+abs(ty-y))%2!=(tt-t)%2||abs(tx-x)+abs(ty-y)>(tt-t))flag=0;
		t=tt;x=tx;y=ty;
	}
	if(flag)cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.*;

public class Main {

  public static void main(String[] args) {
    solve(System.in, System.out);
  }

  private static final long MOD = 1000000007L;


  static void solve(InputStream is, PrintStream os) {
    Scanner sc = new Scanner(is);

    /* read */
    int n = sc.nextInt();
    int m = sc.nextInt();

    Set<Integer> broken = new HashSet<>(m);

    for (int i = 0; i < m; i++) {
      broken.add(sc.nextInt());
    }

    long[] route = new long[n + 1];

    route[0] = 1;

    for (int i = 0; i < n; i++) {
      if (i + 1 <= n) {
        if (!broken.contains(i + 1)) {
          route[i + 1] = (route[i + 1] + route[i]) % MOD;
        }
      }
      if (i + 2 <= n) {
        if (!broken.contains(i + 2)) {
          route[i + 2] = (route[i + 2] + route[i]) % MOD;
        }
      }
    }

    os.println(route[n]);
  }
}

Measured memory_bytes: 66592
import java.util.Scanner;

public class Main {

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

}


Measured memory_bytes: 25848
from sys import stdin
#, setrecursionlimit, stdout
#setrecursionlimit(1000000)
#from collections import deque
#from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
def ii(): return int(stdin.readline())
def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def fmi(): return map(float, stdin.readline().split())
def li(): return list(mi())
def si(): return stdin.readline().rstrip()
def lsi(): return list(si())
#mod=1000000007
res=['Yes', 'No']
############# CODE STARTS HERE #############


test_case=1
while test_case:
    test_case-=1



    n=ii()
    a=[]
    z=26
    while n:
        x=n%26
        n//=z
        if not x:
            p='z'
            n-=1
        else:
            p=chr(96+x)
        a.append(p)
    print(*a[::-1], sep='')

Measured memory_bytes: 61988
def slove():
    import sys, heapq
    input = sys.stdin.readline
    n, m = list(map(int, input().rstrip('\n').split()))
    ab = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    heapq.heapify(ab)
    s_q = []
    heapq.heapify(s_q)
    r = 0
    for d in range(1, m + 1):
        while True:
            if len(ab) != 0:
                p = heapq.heappop(ab)
                if p[0] <= d:
                    heapq.heappush(s_q, -p[1])
                else:
                    heapq.heappush(ab, p)
                    break
            else:
                break
        if len(s_q) != 0:
            mr = -heapq.heappop(s_q)
            r += mr
        d -= 1
    print(r)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 106588
#include<map>
#include<set>
#include<list>
#include<cmath>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<complex>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<numeric>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
#include<cctype>
 
#define mp make_pair
#define pb push_back
#define REP(i,a,n) for(int i = a;i < (n);i++)
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(s) s.begin(), s.end()
#define rall(s) s.rbegin(), s.rend()
#define range(x,min,max) ((min) <= (x) && (x) <= (max)) 
 
using namespace std;
 
typedef long long LL;
typedef vector<int> VI;
typedef vector<vector<int> > VII;
typedef pair<int,int> PII;
 
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};
 
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    while(1){
        int n,ans_k,ans_sum = INT_MAX,m = 0;
        cin >> n;
        if(n == 0) break;
        VI a(n),b(n),c(n);
        rep(i,n){
            cin >> a[i] >> b[i] >> c[i];
            if(m < a[i] || m < b[i])
                m = a[i] > b[i]? a[i]:b[i];
        }
        VI cost(m + 1);
        priority_queue<PII,vector<PII >,greater<PII> > que;
        rep(k,cost.size()){
            int res = 0;
            fill(all(cost), INT_MAX);
            que.push(mp(0,k));
            cost[k] = 0;
            while(!que.empty()){
                int d = que.top().first, u = que.top().second;
                que.pop();
                if(cost[u] < d) continue;
                rep(i,n){
                    if(u == a[i] && cost[u] + c[i] < cost[b[i]]){
                        cost[b[i]] = cost[u] + c[i];
                        que.push(mp(cost[b[i]], b[i]));
                    }
                    if(u == b[i] && cost[u] + c[i] < cost[a[i]]){
                        cost[a[i]] = cost[u] + c[i];
                        que.push(mp(cost[a[i]], a[i]));
                    }
                }
            }
            rep(i,cost.size()){
                res += cost[i];
            }
            if(res < ans_sum){
                ans_k = k;
                ans_sum = res;
            }
        }
        cout << ans_k << " " << ans_sum << endl;
    }
    return 0;
}

Measured memory_bytes: 3116
import sys
 
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

H,W,K = IL()
a = [list(S()) for i in range(H)]

nnn = 0
for i in range(H):
  for j in range(W):
    nnn += int(a[i][j])
else:
  if nnn <= K:
    print(0)
    exit()

rui = [[0]*(W+1) for i in range(H)]
for i in range(H):
  for j in range(W):
    rui[i][j+1] = rui[i][j] + int(a[i][j])
#print(rui)
ans = MAX_INT
for x in range(1<<(H-1)):
  l = 0
  num = 0
  for h in range(H-1):
    if (x >> h) & 1 == 1: # 割る
      num += 1

  for w in range(W):
    # 1行で割れるか判定
    judge = int(a[0][w])
    for h in range(H-1):
      if (x >> h) & 1 == 0: # 割らない
        judge += int(a[h+1][w])
      else: # 割る
        judge = 0
        judge += int(a[h+1][w])
      if judge > K: #どうやって割ってもダメ
        break
    else:
      continue
    break
  else:
    cnt = 0
    for w in range(W):
      #print("w:",w)

      cnt = rui[0][w+1] - rui[0][l]
      if cnt > K:
        num += 1
        l = w
        #print("break1")
        continue
      for h in range(H-1):
        #print("cnt",cnt)
        if (x >> h) & 1 == 0: # 割らない
          cnt += rui[h+1][w+1] - rui[h+1][l]
        else: # 割る
          cnt = rui[h+1][w+1] - rui[h+1][l]
        #print(rui[h+1][w+1],rui[h+1][l])

        if cnt > K:
          num += 1
          l = w
          #print("break")
          break
      #print("--")
    else:
      ans = min(ans, num)
      #print(num)
print(ans)

Measured memory_bytes: 46300
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#define MAXN 100001
#define LL long long
using namespace std;
LL n,a[MAXN],s[MAXN],l,r,f[MAXN*2+10],b[MAXN],c[MAXN*2+10];
void add(LL x)
{
	while(x<=2*MAXN) f[x]++,x+=x&-x;
	return ;
}
LL query(LL x)
{
	LL tot=0;
	while(x>0) tot+=f[x],x-=x&-x;
	return tot;
}
bool check(LL x)
{
	memset(f,0,sizeof f);
	for(LL i=1;i<=n;i++)
	{
		if(a[i]>=x) c[i]=1;
		else c[i]=-1;
		c[i]+=c[i-1];
	}
	LL ans=0;
	for(LL i=0;i<=n;i++) 
	ans+=(query(c[i]+MAXN)),add(c[i]+MAXN);
	//for(LL i=2;i<=n;i++) if
	//ans=n*(n-1)/2-ans;
	return ans>=n*(n+1)/4?true:false;
}
void slove()
{
	l=1,r=n;LL mid;
	while(l<=r)
	{
		mid=l+r>>1;
		if(check(s[mid])) l=mid+1;
		else r=mid-1;
	}
	cout<<s[r];
	return;
}
int main()
{
	cin>>n;
	for(LL i=1;i<=n;i++) cin>>a[i],s[i]=a[i];
	sort(s+1,s+n+1);
	slove();
	return 0;
}

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

static const long long INF=1e9+5;

int main(){
    int n;
    cin>>n;
    vector<long long> a(n);
    for(int i=0;i<n;++i) cin>>a[i];
    reverse(a.begin(),a.end());
    vector<long long> dp(n,INF);

    for(int i=0;i<n;++i) *upper_bound(dp.begin(),dp.end(),a[i])=a[i];
    int res=lower_bound(dp.begin(),dp.end(),INF)-dp.begin();

    cout<<res<<endl;
}

Measured memory_bytes: 4852
#include <iostream>
using namespace std;
 
int main(){
  long a, b, k;

  cin >> a >> b >> k;

  if(k > a+ b){
    a = 0;
    b = 0;
  }else if( k > a ){
    b = b+a-k;
    a = 0;
  }else
  {
    a = a-k;
  }

  cout << a << " " << b << endl;
  


}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int a[6], b[4], i;
    for (i = 0; i < 4; i++) b[i] = 0;
    for (i = 0; i < 6; i++) {
        scanf("%d", &a[i]);
        b[a[i] - 1]++;
    }
    a[0] = 1;
    for (i = 0; i < 4; i++) a[0] *= b[i];

    if (a[0] == 4)
        puts("YES");
    else
        puts("NO");

    return 0;
}


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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  for(int i = 0; i<n-2;i++){
    if(s.at(i) == 'A' && s.at(i+1) == 'B'){
      if(s.at(i+2) == 'C'){
        ans++;
      }
    }
  }
  cout << ans;
  return 0;
}

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

#define ll long long int

int main()
{
    ll k;
    cin>>k;
    ll num=0,ans=-1;
    for(ll i=1;i<=1000009;i++)
    {
        num=10*num+7;
        num%=k;
        if(num==0)
        {
            ans=i;
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3584
N = gets.to_i
M = 10 ** 9 + 7

a_list = gets.strip.split(/ /).collect(&:to_i)

total = a_list.inject(:^)

zero_counts = []

x = 0
zero_count = 0
x_table = { 0=> [] }
a_list.each_with_index{|a, i|
	x ^= a
	if x == 0
		zero_count += 1
	end
	zero_counts << zero_count
	if l = x_table[x]
		l << i
	else
		x_table[x] = [i]
	end
}

r = x

count = 0

if r == 0
	count += (2 ** (x_table[0].length - 1)) % M
	x_table.each{|x, list|
		if x > 0
			cx = 1
			cz = 1
			prev = zero_counts[list[0]]
			list[1..-1].each{|i|
				z = zero_counts[i] - prev
				new_cx = (cz * z + cx) % M
				new_cz = (cz * (z + 1) + cx) % M
				cx = new_cx
				cz = new_cz
				prev = zero_counts[i]
			}
			count = (count + cz) % M
		end
	}
else
	if list = x_table[r]
		cx = 1
		cz = 1
		prev = zero_counts[list[0]]
		list[1..-1].each{|i|
			z = zero_counts[i] - prev
			new_cx = (cz * z + cx) % M
			new_cz = (cz * (z + 1) + cx) % M
			cx = new_cx
			cz = new_cz
			prev = zero_counts[i]
		}
		count = (count + cx) % M
	else
		count = 1
	end
end
puts count


Measured memory_bytes: 60812
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int N,W;
  cin>>N>>W;
  long long int w[N],v[N];
  for(long long int i=0;i<N;i++) cin>>w[i]>>v[i];
  long long int dp[N+1][W+1];
  for(int i=0;i<N;i++)
    for(int j=0;j<=W;j++)
      dp[i][j]=0;
  for(int i=0;i<=N;i++)
    for(int j=0;j<=W;j++){
      if(i==0 || j==0) dp[i][j]=0;
      else if(w[i-1]<=j) dp[i][j]=max(dp[i-1][j],v[i-1]+dp[i-1][j-w[i-1]]);
      else dp[i][j]=dp[i-1][j];
    }
  cout<<dp[N][W];
    
}

Measured memory_bytes: 79104
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n; cin >> n;
    string s[n];
    rep(i, n){
        cin >> s[i];
    }

    ll ans = 0;

    // inner count
    rep(i, n){
        rep(j, s[i].size()-1){
            if(s[i][j] == 'A' && s[i][j+1] == 'B'){
                ans++;
            }
        }
    }

    // bhead, atail, both
    ll bhead = 0, atail = 0, both = 0;
    rep(i, n){
        int jlast = s[i].size() - 1;

        if(s[i][0] == 'B' && s[i][jlast] == 'A'){
            both++;
        }
        else if(s[i][0] == 'B'){
            bhead++;
        }
        else if(s[i][jlast] == 'A'){
            atail++;
        }
    }

    // cout << both << " " << bhead << " " << atail << endl;

    // ans += min(bhead, atail);
    // ans += both;

    // if(bhead == 0 && atail == 0){
    //     ans--;
    // }

    // cout << ans << endl;

    if(both == 0){
        ans += min(bhead, atail);
    }
    else if(atail + bhead > 0){
        ans += min(bhead, atail) + both;
    }
    else{
        ans += both - 1;
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	string s; cin >> s;
	int cnt = 0;
	for (int i = 0; i < s.length(); i++) if (s[i] != 'x') cnt++;
	if (cnt == 0) {
		cout << 0 << endl;
		return 0;
	}
	for (int i = 0, j = 0; i < s.length(); i++) {
		if (s[i] != 'x') j++;
		if (j == (cnt + 1) / 2) {
			vector<pair<int, char>> L, R;
			int cur = 0;
			for (int k = 0; k <= i - (cnt & 1); k++) {
				if (s[k] != 'x') {
					L.emplace_back(cur, s[k]);
					cur = 0;
				} else cur++;
			}
			int tmp = 0;
			for (int k = s.length() - 1; k >= i + 1; k--) {
				if (s[k] != 'x') {
					R.emplace_back(tmp, s[k]);
					tmp = 0;
				} else tmp++;
			}
			if (L.size() != R.size()) {
				cout << -1 << endl;
				return 0;
			}
			for (int i = 0; i < L.size(); i++) if (L[i].second != R[i].second) {
				cout << -1 << endl;
				return 0;
			}
			int ans;
			if (cnt & 1) {
				ans = abs(cur - tmp);
			} else {
				ans = 0;
			}
			for (int i = 0; i < L.size(); i++) ans += abs(L[i].first - R[i].first);
			cout << ans << endl;
			return 0;
		}
	}
	return 0;
}



Measured memory_bytes: 4420
#include<stdio.h>
int main()
{
	int n;
	long int a, ans = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%ld", &a);
		while (!(a&1))
		{
			ans++;
			a = a >> 1;
		}
	}
	printf("%ld", ans);
	return 0;
}

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

namespace AtCoder.abc075 {
    export class A {
        public main(args: string): void {

            let ans: number = 0;
            args.split('').reduce((prev: string, cur: string, idx: number) => {
                if (cur === 'S') return cur;
                if (ans === 0 && cur === 'R') {
                    ans++
                } else if (prev === 'R' && cur === 'R') {
                    ans++;
                }
                return cur;
            }, 'R');
            console.log(ans);
        }
    }

    const args: string = fs.readFileSync('/dev/stdin', 'utf8').trim();
    const task: AtCoder.abc075.A = new A();
    task.main(args);
}

Measured memory_bytes: 29592
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int N;
  cin >> N;
  
  vector<vector<int>>man(N,vector<int>(2,0));
  
  for(int i=0;i<N;i++){
    cin >> man[i][0];
    cin >> man[i][1];
  }
  
  int ans = 0;
  
  for(int i=0;i<N;i++){
    ans += man[i][1] - man[i][0] + 1;
  }
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 256
A, V= map(int,input().split())
B, W = map(int,input().split())
T = int(input())

def hantei(A,B,V,W,T):
    if V <= W:
        return('NO')
    else:
        if abs(B - A)/(V - W) <= T:
            return('YES')
        else:
            return('NO')
    
print(hantei(A,B,V,W,T))

Measured memory_bytes: 9192
#include <iostream>

using namespace std;

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

    long long P[M];
    for(int i=0; i<M; ++i) {
        long long temp;
        cin >> temp;
        P[i]=temp-1;
    }

    long long A[N-1],B[N-1],C[N-1];
    for(int i=0; i<N-1; ++i) cin >> A[i] >> B[i] >> C[i];

    long long cnt[N-1];

    fill(cnt,cnt+N-1,0);

    for(int i=0; i<M-1; ++i)
        for(int j=min(P[i],P[i+1]); j<max(P[i],P[i+1]); ++j)
            ++cnt[j];

    long long ans=0;

    for(int i=0; i<N-1; ++i) {
        ans+=(cnt[i]!=0?min(cnt[i]*A[i],cnt[i]*B[i]+C[i]):0);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 6984
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include <numeric>
#include<map>
#include<queue>
#include<math.h>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD=1000000007;
//scanf("%d", &a) '\n'


int main() {
	string s; cin >> s;
	int n = s.size();
	vector<int> arr(n + 1, 0);
	for (int i = 0; i < n; ++i) {
		if (s[i] == '<')
			arr[i + 1] = max(arr[i + 1], arr[i] + 1);
	}
	for (int i = n - 1; i >= 0; --i) {
		if (s[i] == '>')
			arr[i] = max(arr[i], arr[i + 1] + 1);
	}
	long long ans = accumulate(arr.begin(), arr.end(), 0LL);
	cout << ans << endl;
	return 0;
}
	

Measured memory_bytes: 2820
import sys
from bisect import bisect_left

def solve():
    input = sys.stdin.readline
    N, Q = map(int, input().split())
    A = [int(a) for a in input().split()]
    X = [int(input()) for _ in range(Q)]
    cont = [0] * N
    cont[N-1] = A[N-1]
    for i in reversed(range(N-1)): cont[i] = cont[i+1] + A[i]
    change = [0] * N
    change[0] = A[0]
    change[1] = A[1]
    for i in range(2, N): change[i] = change[i-2] + A[i]
    upperBound = [-1] * N
    for i in range((N + 1)// 2): #上からi+1個連続でとれるxの最大値
        target = A[N-i-1]
        lower = A[(N-i-1) - i]
        upperBound[N-i-1] = (target + lower) // 2
    upperBound[N-1] = 10 ** 10
    Ans = [0] * Q
    for i, x in enumerate(X):
        pos = bisect_left(upperBound, x)
        Ans[i] += cont[pos] #連続で取れる数
        if N - (N - pos) * 2 - 1 >= 0: Ans[i] += change[N - (N - pos) * 2 - 1]
    print(*Ans, sep="\n")

    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 30832
#include<iostream>
using namespace std;
int n, grid[3][3], num[12], mark[3][3] = {0}; 


int  main()
{
	
	//input
	for(int i = 0; i < 3; i++)
		for(int j = 0; j < 3; j++)
			scanf("%d", &grid[i][j]);
	
	scanf("%d", &n);
	
	for(int i = 0; i < n; i++)
		scanf("%d", &num[i]);
	
	//solve
	for(int p = 0; p < n; p++)
	{
		for(int i = 0; i < 3; i++)
			for(int j = 0; j < 3; j++)
				if(num[p] == grid[i][j])
				{mark[i][j] = 1;	break;}				
	}
	
	if(mark[0][0]+mark[0][1]+mark[0][2]==3 || mark[1][0]+mark[1][1]+mark[1][2]==3 || mark[2][0]+mark[2][1]+mark[2][2]==3 || mark[0][0]+mark[1][0]+mark[2][0]==3 || mark[0][1]+mark[1][1]+mark[2][1]==3|| mark[0][2]+mark[1][2]+mark[2][2]==3 || mark[0][0]+mark[1][1]+mark[2][2]==3 || mark[0][2]+mark[1][1]+mark[2][0]==3)
		printf("Yes\n");
	else
		printf("No\n");	
}

Measured memory_bytes: 256
// by newbiechd
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>

// DELETE the debugging information!
#define debug(x) std::cerr << #x << " = " << (x) << std::endl

const int N_MAX = 100003;
int a[N_MAX];

int main() {
  int n, L;
  scanf("%d%d", &n, &L);
  for (int i = 1; i <= n; ++i)
    scanf("%d", a + i);
  for (int i = 1; i < n; ++i)
    if (a[i] + a[i + 1] >= L) {
      printf("Possible\n");
      for (int j = 1; j < i; ++j)
        printf("%d\n", j);
      for (int j = n - 1; j > i; --j)
        printf("%d\n", j);
      printf("%d\n", i);
      return 0;
    }
  printf("Impossible\n");
  return 0;
}


Measured memory_bytes: 1152
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


class Main{

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		double xa = 0;
		double ya = 0;
		double ra = 0;
		double xb = 0;
		double yb = 0;
		double rb = 0;
		int n = Integer.parseInt(in.readLine());
		for(int i= 0; i < n;i++){
			String ss[] =in.readLine().split(" ");
			xa = Double.parseDouble(ss[0]);
			ya = Double.parseDouble(ss[1]);
			ra = Double.parseDouble(ss[2]);
			xb = Double.parseDouble(ss[3]);
			yb = Double.parseDouble(ss[4]);
			rb = Double.parseDouble(ss[5]);
			double dist = Math.sqrt(Math.pow(xa-xb,2)+Math.pow(ya-yb,2));
			if(ra > rb + dist){
				//a?????\??£?????????
				System.out.println("2");
			}
			else if(rb > ra + dist){
				//b
				System.out.println("-2");
			}
			else if(dist <= ra+rb){
				//????????£?????????
				System.out.println("1");
			}
			else{
				//???????????????
				System.out.println("0");
			}
		}
		

	}

}

Measured memory_bytes: 16940
import math
#input = raw_input

a, b, h, m = map(int, input().split(" "))
ltheta = (h + m / 60.)* 30
mtheta = m * 6
#print("ltheta", ltheta, "mtheta", mtheta)

theta_diff = abs(ltheta-mtheta)
theta_diff = min(360-theta_diff, theta_diff)
#print(theta_diff)
theta_diff = math.pi / 180 * theta_diff
theta = theta_diff

x = a - b * math.cos(theta)
y = b * math.sin(theta)
out = math.sqrt( (x ** 2) + (y ** 2))

print(out)

Measured memory_bytes: 9516
//????????????????????????0611
#include<stdio.h>
long long int z[1001][1001];
int main(void)
{
	int n,m,d[1001],c[1001],i,j;
	long long int min,s;
	s=9223372036854775806; 
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++) scanf("%d",&d[i]);
	for(i=0;i<m;i++) scanf("%d",&c[i]);
	for(i=0;i<=m;i++){
		for(j=0;j<=n;j++) z[i][j]=s;
	}
	z[0][0]=0;
	for(i=0;i<m;i++){
		for(j=0;j<=n;j++){
			if(z[i][j]!=s){
				if(z[i+1][j]>z[i][j]) z[i+1][j]=z[i][j];
				if(z[i+1][j+1]>z[i][j]+d[j]*c[i]) z[i+1][j+1]=z[i][j]+d[j]*c[i];	
			}	
		}
	}
	min=s;
	for(i=0;i<=m;i++){
		if(min>z[i][n]){
			min=z[i][n];
		}
	}
	printf("%lld\n",min);
}

Measured memory_bytes: 10420
using System;

class ABC
{
    static void Main()
    {
        string input = Console.ReadLine();
        string[] inputA = input.Split(' ');
        string A = inputA[0];
        string B = inputA[1];
        System.Text.StringBuilder sbA = new System.Text.StringBuilder();
        System.Text.StringBuilder sbB = new System.Text.StringBuilder();


        for (int i = 0; i < int.Parse(B); i++)
        {

            sbA.Append(A);
        }
        for (int i = 0; i < int.Parse(A); i++)
        {

            sbB.Append(B);
        }
        string AA = sbA.ToString();
        string BB = sbB.ToString();
        string[] Ans = new[] { AA, BB };
        Array.Sort(Ans);

        Console.WriteLine(Ans[0]);
    }
}

Measured memory_bytes: 13280
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
const double PI = 3.141592653589793238;
const double EPS = 1e-10;
typedef pair<ll, ll> Pos;
typedef pair<Pos, int> P;
ll x[100000], y[100000];
set<int> S;
set<P> V, RV;
vector<Pos> Vec, RVec;
ll D;
void dfs(int v) {
	S.insert(v);
	V.erase(P(Pos(x[v], y[v]), v));
	RV.erase(P(Pos(y[v], x[v]), v));
	while (1) {
		auto l = V.lower_bound(P(Pos(x[v] + D, y[v] - D), 0));
		auto r = V.upper_bound(P(Pos(x[v] + D, y[v] + D), 1 << 30));
		if (l != r) {
			dfs(l->second);
			continue;
		}
		l = V.lower_bound(P(Pos(x[v] - D, y[v] - D), 0));
		r = V.upper_bound(P(Pos(x[v] - D, y[v] + D), 0));
		if (l != r) {
			dfs(l->second);
			continue;
		}
		l = RV.lower_bound(P(Pos(y[v] + D, x[v] - D), 0));
		r = RV.upper_bound(P(Pos(y[v] + D, x[v] + D), 0));
		if (l != r) {
			dfs(l->second);
			continue;
		}
		l = RV.lower_bound(P(Pos(y[v] - D, x[v] - D), 0));
		r = RV.upper_bound(P(Pos(y[v] - D, x[v] + D), 0));
		if (l != r) {
			dfs(l->second);
			continue;
		}
		break;
	}
}
int main() {
	int N, a, b;
	cin >> N >> a >> b;
	a--; b--;
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i];
		ll X = x[i] - y[i];
		ll Y = x[i] + y[i];
		x[i] = X;
		y[i] = Y;
		V.insert(P(Pos(x[i], y[i]), i));
		RV.insert(P(Pos(y[i], x[i]), i));
		Vec.emplace_back(x[i], y[i]);
		RVec.emplace_back(y[i], x[i]);
	}
	sort(Vec.begin(), Vec.end());
	sort(RVec.begin(), RVec.end());
	D = max(abs(x[a] - x[b]), abs(y[a] - y[b]));
	dfs(a);
	ll ans = 0;
	for (int v : S) {
		ll cnt = 0;
		auto l = lower_bound(Vec.begin(), Vec.end(), Pos(x[v] + D, y[v] - D));
		auto r = upper_bound(Vec.begin(), Vec.end(), Pos(x[v] + D, y[v] + D));
		cnt += r - l;
		l = lower_bound(Vec.begin(), Vec.end(), Pos(x[v] - D, y[v] - D));
		r= upper_bound(Vec.begin(), Vec.end(), Pos(x[v] - D, y[v] + D));
		cnt += r - l;
		l = upper_bound(RVec.begin(), RVec.end(), Pos(y[v] + D, x[v] - D));
		r = lower_bound(RVec.begin(), RVec.end(), Pos(y[v] + D, x[v] + D));
		cnt += r - l;
		l = upper_bound(RVec.begin(), RVec.end(), Pos(y[v] - D, x[v] - D));
		r = lower_bound(RVec.begin(), RVec.end(), Pos(y[v] - D, x[v] + D));
		cnt += r - l;
		ans += cnt;
	}
	ans /= 2;
	cout << ans << endl;
}

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

int X;

int main(){
  cin >> X;

  int n = X / 100;  //最も商品が買える時の個数
  int d = X % 100; //端数

  if(d > 5 * n) cout << 0 << endl;
  else cout << 1 << endl;
  return 0;
}
  

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if((a==5&&b==5&&c==7)||(a==5&&b==7&&c==5)||(a==7&&b==5&&c==5)){
		cout<<"YES";
	}
	else cout<<"NO";
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
int main(){
	int w1,w2,w3,k1,k2,k3;
	int a;
	w1=w2=w3=k1=k2=k3=0;
	for(int i=0;i<10;i++){
		scanf("%d",&a);
		if(a>w1){
			w3=w2;
			w2=w1;
			w1=a;
		}else if(a>w2){
			w3=w2;
			w2=a;
		}else if(a>w3){
			w3=a;
		}
	}
	for(int i=0;i<10;i++){
		scanf("%d",&a);
		if(a>k1){
			k3=k2;
			k2=k1;
			k1=a;
		}else if(a>k2){
			k3=k2;
			k2=a;
		}else if(a>k3){
			k3=a;
		}
	}

	printf("%d %d\n",w1+w2+w3,k1+k2+k3);

	return 0;
}

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

int main()
{
    long n;
    cin>>n;
    long i,pow=1;
    for(i=1;i<=n;i++)
    {
        pow=(pow*i)%1000000007;
    }
    cout<<pow<<endl;
    return 0;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

struct TwoSatLight {
  TwoSatLight(int n) : n(n), graph(n << 1), rev_graph(n << 1), used(n << 1, false), id(n << 1, -1) {}

  int negate(int x) const { return (n + x) % (n << 1); }

  void add_or(int x, int y) {
    graph[negate(x)].emplace_back(y);
    graph[negate(y)].emplace_back(x);
    rev_graph[y].emplace_back(negate(x));
    rev_graph[x].emplace_back(negate(y));
  }

  void add_if(int x, int y) { add_or(negate(x), y); }

  void add_nand(int x, int y) { add_or(negate(x), negate(y)); }

  void set_true(int x) { add_or(x, x); }

  void set_false(int x) { set_true(negate(x)); }

  vector<bool> build() {
    REP(i, n << 1) {
      if (!used[i]) dfs(i);
    }
    int now = 0;
    for (int i = (n << 1) - 1; i >= 0; --i) {
      if (id[order[i]] == -1) rev_dfs(order[i], now++);
    }
    vector<bool> res(n);
    REP(i, n) {
      if (id[i] == id[negate(i)]) return {};
      res[i] = id[negate(i)] < id[i];
    }
    return res;
  }

private:
  int n;
  vector<vector<int>> graph, rev_graph;
  vector<bool> used;
  vector<int> id, order;

  void dfs(int ver) {
    used[ver] = true;
    for (int e : graph[ver]) {
      if (!used[e]) dfs(e);
    }
    order.emplace_back(ver);
  }

  void rev_dfs(int ver, int now) {
    id[ver] = now;
    for (int e : rev_graph[ver]) {
      if (id[e] == -1) rev_dfs(e, now);
    }
  }
};

int main() {
  int n, d; cin >> n >> d;
  vector<int> x(n), y(n); REP(i, n) cin >> x[i] >> y[i];
  TwoSatLight ts(n);
  REP(i, n) FOR(j, i + 1, n) {
    if (abs(x[i] - x[j]) < d) ts.add_nand(i, j);
    if (abs(x[i] - y[j]) < d) ts.add_nand(i, ts.negate(j));
    if (abs(y[i] - x[j]) < d) ts.add_nand(ts.negate(i), j);
    if (abs(y[i] - y[j]) < d) ts.add_nand(ts.negate(i), ts.negate(j));
  }
  vector<bool> ans = ts.build();
  if (ans.empty()) {
    cout << "No\n";
    return 0;
  }
  cout << "Yes\n";
  REP(i, n) cout << (ans[i] ? x[i] : y[i]) << '\n';
  return 0;
}


Measured memory_bytes: 3864
export class Main {
  static main(input): string {
    const [a, b]: number[] = input.split("\n")[0].split(" ").map(Number);
    return `${
      a <= 5  ? 0 :
      a <= 12 ? b / 2
              : b
    }`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)

void getZarr(string str, vi& Z) {
    int n = str.length();
    int L, R, k;

    L = R = 0;
    REP (i, n) {
        if (i > R) {
            L = R = i;
            while (R < n && str[R-L] == str[R]) R++; 
            Z[i] = R-L;
            R--;
        } else {
            k = i-L;
            if (Z[k] < R-i+1) Z[i] = Z[k];
            else {
                L = i;
                while (R<n && str[R-L] == str[R]) R++;
                Z[i] = R-L;
                R--;
            }
        }
    }
}

vi search(string text, string pattern) {
    string concat = pattern + "$" + text;
    int l = concat.length();

    vi Z(l);
    getZarr(concat, Z);

    vi ret;
    REP (i, l) if (Z[i] == pattern.length()) {
        ret.push_back(i-pattern.length()-1);
    }
    return ret;
}

string S, T;

ll solve() {
    S += S;
    while (S.size() <= 2 * T.size()) S += S;

    set<ll> indices;
    FORE (i, search(S, T)) if (i < S.size()/2) {
        indices.insert(i);
    }

    ll ret = 0;
    vi check(S.size(), 0);
    FORI (iter, indices) {
        int index = *iter;
        if (check[index] != 0) continue;
        stack<int> s;

        int i = index;
        while (1) {
            s.push(i);
            int next = (i + T.size()) % (S.size()/2);
            if (next == index) return -1;
            if (indices.find(next) == indices.end()) break;
            i = next;
        }
        ll size = 0;
        while (!s.empty()) {
            check[s.top()] = ++size;
            s.pop();
        }
        CHMAX(ret, size);
    }

    return ret;
}

int main() {
    cin >> S >> T;
    cout << solve() << endl;
}

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

int main(void){
	while(1){
		string str;
		cin >> str;
		if(str=="#")break;
		int n=1,dir=0,k=str.size(),pl=90,nn=1;
		while(k!=0){
			if(k>=5 && str.substr(k-5,5)=="north"){
				k-=5;
				dir*=nn/n;
				n=nn;
				if(dir>0)dir-=pl;
			}else{
				dir*=nn/n;
				n=nn;
				if(dir<90*n)dir+=pl;
				k-=4;
			}
			if(pl%2==0)pl/=2;
			else nn*=2;
		}
		while(dir%2==0 && n%2==0){
			dir/=2;
			n/=2;
		}
		if(n!=1)printf("%d/%d\n",dir,n);
		else printf("%d\n",dir);
	}
	return 0;
}

Measured memory_bytes: 1208
from collections import deque

n = int(input())
g = [[] for _ in range(n)]
ab = []
for _ in range(n-1):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    g[a].append(b)
    g[b].append(a)
    ab.append((a, b))

q = deque([0])

chk = [False] * n
chk[0] = True

res = [0] * n
par = [0] * n
while q:
    x = q.popleft()
    cnt = 1
    for y in g[x]:
        if chk[y]:
            continue
        if res[x] == cnt:
            cnt += 1
        res[y], par[y], chk[y] = cnt, x, True
        cnt += 1
        q.append(y)

ans = []
for a, b in ab:
    if par[a] == b:
        ans.append(res[a])
    else:
        ans.append(res[b])

print(max(ans), *ans, sep="\n")


Measured memory_bytes: 81824
// inputに入力データ全体が入る
function Main(input) {
  	var a = input;
    var odd = (a % 2 === 0) ? (a / 2) : Math.ceil((a / 2));
	//出力
	console.log(odd / a);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
H, W = map(int, input().split())
A = [input() for _ in range(H)]
A = list(filter(lambda a: any(x == '#' for x in a), A)) 
A = list(filter(lambda a: any(x == '#' for x in a), zip(*A)))
for a in zip(*A):
    print(''.join(a))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair<int,int >
#define iiii pair<int,pii >
#define mp make_pair
#define INF 1000000000
#define MOD 998244353
#define rep(i,x) for(int (i)=0;(i)<(x);(i)++)
inline int getint(){
    int x=0,p=1;char c=getchar();
    while (c<=32)c=getchar();
    if(c==45)p=-p,c=getchar();
    while (c>32)x=x*10+c-48,c=getchar();
    return x*p;
}
using namespace std;
//ruogu
const int N=2e5+5;
int n,pw[N],X[N],Y[N],id[N],res;
int d0[N],d1[N];
vector<int>vx;
//
inline void add(int &x,int y){x+=y;if(x>=MOD)x-=MOD;}
inline int mul(int x,int y){ll ans=1ll*x*y;return ans%MOD;}
bool cmp(int x,int y){
	return X[x]<X[y];
}
inline int modpow(int x,int y){
	int ans=1;
	while(y){
		if(y&1)ans=mul(ans,x);
		x=mul(x,x);
		y>>=1;
	}
	return ans;
}
inline int qry(int *dat,int x){
	++x;
	int ans=0;
	while(x){
		ans+=dat[x];
		x-=x&-x;
	}
	return ans;
}
inline void update(int *dat,int x,int y){
	++x;
	int ans=0;
	while(x<N){
		dat[x]+=y;
		x+=x&-x;
	}
}
inline int qry(int mask,int id){
	int ans=1;
	if(mask&1)ans=mul(ans,pw[qry(d0,Y[id]-1)]);
	if(mask>>1&1)ans=mul(ans,pw[qry(d0,N-2)-qry(d0,Y[id])]);
	if(mask>>2&1)ans=mul(ans,pw[qry(d1,Y[id]-1)]);
	if(mask>>3&1)ans=mul(ans,pw[qry(d1,N-2)-qry(d1,Y[id])]);
	return ans;
}
int main(){
	n=getint();
	rep(i,n)X[i]=getint(),Y[i]=getint(),id[i]=i;
	pw[0]=1;for(int i=1;i<N;i++)pw[i]=mul(pw[i-1],2);
	rep(i,N){
		pw[i]--;
		if(pw[i]<0)pw[i]+=MOD;
	}
	sort(id,id+n,cmp);
	rep(i,n)vx.push_back(Y[i]);
	sort(vx.begin(),vx.end());
	rep(i,n)Y[i]=lower_bound(vx.begin(),vx.end(),Y[i])-vx.begin();
	for(int i=1;i<n;i++)update(d1,Y[id[i]],1);
	rep(ii,n){
		int i=id[ii];
		rep(msk,1<<4){
			bool flag=false;
			if((msk>>1&1)&&(msk>>2&1))flag=true;
			if((msk&1)&&(msk>>3&1))flag=true;
			if(!flag)continue;
			add(res,qry(msk,i));
		}
		update(d0,Y[i],1);
		update(d1,Y[id[ii+1]],-1);
	}
	add(res,mul(n,modpow(2,n-1)));
	cout<<res<<endl;
	return 0;
}


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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

int main() {
    int h, w, d;
    cin >> h >> w >> d;
    vector<ll> basyo(h*w+1);
    REP(i, h) REP(j, w) {
        int a;
        cin >> a;
        basyo[a] = i * w + j;
    } 

    vector<ll> ruiseki[d];
    REP(i, d) ruiseki[i].push_back(0);

    REPN(i, 1, h*w+1) {
        if(i+d > h*w) continue;
        int x = basyo[i] / w, y = basyo[i] % w;
        int x2 = basyo[i+d] / w, y2 = basyo[i+d] % w;
        int cost = abs(x-x2) + abs(y-y2);
        int mae = ruiseki[i%d][ruiseki[i%d].size()-1];
        ruiseki[i%d].push_back(cost + mae);
        //cout << i << " " <<  i+d << " " << cost << endl;
    }

    REP(i, ruiseki[0].size()) {
        //cout << ruiseki[0][i] << endl;
    }

    int q;
    cin >> q;
    REP(query, q) {
        int a, b;
        cin >> a >> b;
        if(a == b) cout << "0" << endl;
        else if(a%d != 0) cout << ruiseki[a%d][b/d] - ruiseki[a%d][a/d] << endl;
        else cout << ruiseki[a%d][b/d-1] - ruiseki[a%d][(a-d)/d] << endl;
    }

    return 0;
}

Measured memory_bytes: 6016
#include <bits/stdc++.h>
using namespace std;
int main() {
  int H, W;
  cin >> H >> W;
  while (H != 0 || W != 0) {
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        cout << "#";
      }
      cout << endl;
    }
    cout << endl;
    cin >> H >> W;
  }
  return 0;
}



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

#define PI 3.14159265

using namespace std;

int main(){
    long double a, b, x, c, t;
    cin >> a >> b >> x;
    if(a*b <= 2*x/a){
        c = 2*b - 2*x/a/a;
        t = atan(c/a);
    }
    else{
        c = 2*x/a/b;
        t = atan(b/c);
    }
    printf("%Lf\n", t*180/PI);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
 
    public static void main(String[] args) {
 
        Scanner sc = new Scanner(System.in);
 
        double r = sc.nextDouble();
 
        System.out.printf("%.10f %.10f\n",r*r*Math.PI,(2*r)*Math.PI);
    }
}


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

int main() {

  int N;
  cin >> N;
  
  int  Y = 0; 
  
  for (int i = 0; i < N; i++) {
    string S;
    cin >> S;
    

    if ( S == "Y")
      Y++;
    
  }
  
  if (Y >= 1)
    cout << "Four" << endl;
  else
    cout << "Three" << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int N, M, K;
vector<int> A, B;
string S, T;

void input() {
  int x, y, z;
  cin >> N;
  ;
}
void solve() {
  bool ans = false;
  if (N % 10 == 9) ans = true;
  N /= 10;
  if (N % 10 == 9) ans = true;
  cout << (ans ? "Yes" : "No") << endl;
  ;
  ;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<b;i++)
int main(){
    int n,a,b;
    cin>>n>>a>>b;
    int cnt1=0,cnt2=0,cnt3=0;
    rep(i,0,n){
        int p;
        cin>>p;
        if (p<=a) cnt1++;
        else if (p>b) cnt3++;
        else cnt2++;
    }
    cout<<min({cnt1,cnt2,cnt3});
}

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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    int cnt = 0;
    rep(i, n-1) {
        if (s[i] != s[i+1]) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <array>
#include <map>
#include <iomanip>
#include <vector>
#include <set>
#include <cctype>

#define repeat_range(i,a,b) for (int i=(a);i<(b);i++)
#define repeat(i,n) repeat_range(i,0,n)
typedef long long ll;

using namespace std;

template <typename T>
void puts(const T &v){
    cout << v << endl;
}

template <typename T>
void puts(const set<T> &v) {
    for(const auto &e: v) {
        puts(e);
    }
}

template <typename T>
void puts(const vector<T> &v) {
    for(const auto &e: v) {
        puts(e);
    }
}

// graph related algorithms


int main() {
    long n;
    cin >> n;
    vector<long> a;
    repeat(i, n) {
        long v;
        cin >> v;
        a.push_back(v);
    }
    
    sort(a.begin(), a.end());
    
    long the_max = a.back();
    a.pop_back();
    
    long target = the_max / 2;
    
    auto gt_or_eql_ptr = lower_bound(a.begin(), a.end(), target);
    
    
    if(gt_or_eql_ptr == a.end()) {
        cout << the_max << " " << a.back() << endl;
        return 0;
    }
    long greater_candidate = *gt_or_eql_ptr;
    
    if(greater_candidate == target) {
        cout << the_max << " " << target << endl;
        return 0;
    }
    if (gt_or_eql_ptr == a.begin()) {
        cout << the_max << " " << a.front() << endl;
        return 0;
    }
    gt_or_eql_ptr--;
    long lesser_candidate = *gt_or_eql_ptr;
    
//    puts("lesser:");
//    puts(lesser_candidate);
//    
//    puts("gerater:");
//    puts(greater_candidate);
    
    if(the_max >= lesser_candidate + greater_candidate) {
        cout << the_max << " " << greater_candidate << endl;
    } else {
        cout << the_max << " " << lesser_candidate << endl;
    }
}


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


int main(){
  int n, y;
  cin >> n >> y;
  rep(i,n+1){
    rep(j,n+1-i){
      int k = n - i - j;
      if(i*10000+j*5000+k*1000==y){
        cout << i << " " << j << " " << k << endl;
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
	cin >> N;
	vector<pii> A;
	REP(i, N) {
		int a, b;
		cin >> a >> b;
		A.push_back(pii(a, b));
	}
	SORT(A);
	double sum = 0;
	do {
		REP(i, N - 1) {
			int dx = A[i].first - A[i + 1].first;
			int dy = A[i].second - A[i + 1].second;
			sum += pow((double)(dx*dx + dy * dy), 0.5);
		}
	} while (std::next_permutation(A.begin(), A.end()));
	int B = 1;
	eFOR(i, 1, N)B *= i;

	printf("%.8f\n", sum / B);



	return 0;
}



Measured memory_bytes: 256
#include <iostream>

int main()
{
	int a[ 3 ] = { 0 }, k;
	std::cin >> a[ 0 ] >> a[ 1 ] >> a[ 2 ] >> k;

	int mx = 0;
	int mi = 0;
	for( int i = 0; i < 3; i++ ) {
		if( mx < a[ i ] ) {
			mx = a[ i ];
			mi = i;
		}
	}

	for( int i = 0; i < k; i++ ) {
		a[ mi ] = a[ mi ] * 2;
	}

	std::cout << a[ 0 ] + a[ 1 ] + a[ 2 ] << std::endl;
	return 0;
}



Measured memory_bytes: 888