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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int N, K;

int main() {
    //cout.precision(10);
    cin >> N >> K;
    vector<int> h(N);
    for(int i = 0; i < N; i++) cin >> h[i];
    sort(h.begin(), h.end());
    int ans = INF;
    for(int i = 0; i + K - 1 < N; i++) {
        int now = h[i+K-1] - h[i];
        ans = min(now, ans);
    }
    cout << ans << endl;
    return 0;
}


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



int main(void) {
  int n;
  cin >> n;
  int v[n];
  rep (i, n) cin >> v[i];
  sort(v, v + n);
  double ans = v[0];
  for (int i = 1; i < n; i++) {
    ans = (double)(ans + v[i]) / 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace CP
{
    class Atria
    {
        static void Main(string[] args)
        {
            double a = 100;
            long x = long.Parse(ReadLine());
            long ans = 0;
            while (a <x)
            {
                a *= 1.01;
                a = (long)a;
                ans++;
            }
            WriteLine(ans);
        }
    }
}

Measured memory_bytes: 27536
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

int main() {
  int N, M;
  std::cin >> N >> M;
  std::vector<int> A(M);
  for (int &x: A) {
    std::cin >> x;
  }
  int sum = std::accumulate(A.begin(), A.end(), 0);
  if (sum > N) {
    std::cout << "-1\n";
  }
  else {
    std::cout << N - sum << '\n';
  }
  return 0;
}


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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	string st;
	cin>>st;
	vector<int> vi;
	vi.push_back(0);
	string wotx;
	for(int i=0; i<st.length(); i++){
		if(st[i]!='x'){
			vi.push_back(i);
			wotx.push_back(st[i]);
		}
	}
	vi.push_back(st.length()-1);
	int len = vi.size();
	int ans = 0;
// 	cout<<len;
	string w = wotx;
	reverse(w.begin(),w.end());
	if(w!=wotx){
	   cout<<-1;
	   return 0;
	}
	if(len==2){
		cout<<0;
	}
	else{
		if(len%2){
			int mid1 = (len>>1),mid2=(len>>1);
			int cnt = mid2;
			for(int i=0; i<cnt; i++){
				ans += abs((vi[mid1]-vi[mid1-1])-(vi[mid2+1]-vi[mid2]));
				mid1--;
				mid2++;
			}
		}
		else{
			int mid1 = (len>>1)-1,mid2=(len>>1);
			int cnt = mid2;
			for(int i=0; i<cnt-1; i++){
				ans += abs((vi[mid1]-vi[mid1-1])-(vi[mid2+1]-vi[mid2]));
				mid1--;
				mid2++;
			}
		}
		cout<<ans;
	}
	return 0;
}


Measured memory_bytes: 1100
#include <cstdio>
#include <string>
#include <algorithm>
#define rep(i,st,ed) for (int i=st;i<=ed;++i)
#define lowbit(x) (x&-x)

typedef long long LL;
const int MOD=1e9+7;
const int N=18;

LL f[1<<N],g[N][1<<N],bin[155];

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

int main(void) {
	bin[0]=1; rep(i,1,125) bin[i]=bin[i-1]*2LL%MOD;
	int n=read(),m=read();
	rep(i,1,m) {
		int x=read()-1,y=read()-1;
		++g[x][1<<y];
	}
	rep(i,0,n-1) {
		for (int j=1;j<(1<<n);++j) {
			g[i][j]=g[i][j-lowbit(j)]+g[i][lowbit(j)];
		}
	}
	for (int S=1;S<(1<<n);++S) {
		if ((S&1)!=((S>>1)&1)) continue;
		f[S]=1;
		for (int a=S,b,w;a;a=(a-1)&S) {
			if ((a&1)!=((a>>1)&1)) continue;
			b=S-a; w=f[b];
			rep(i,0,n-1) {
				if ((b>>i)&1) w=(bin[g[i][a]]-1)*w%MOD;
				if ((a>>i)&1) w=bin[g[i][b]]*w%MOD;
			}
			f[S]=(f[S]+w)%MOD;
		}
	}
	LL ans=(bin[m]+MOD-f[(1<<n)-1])%MOD;
	printf("%lld\n", ans);
	return 0;
}

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

int n, d, mn=1e9, x[105];
int main() {
	int i, k;
	cin >> n;
	for(i=0; i<n; i++) cin >> x[i];
	for(k=0; k<=100; k++) {
		for(i=d=0; i<n; i++) d += (x[i]-k) * (x[i]-k);
		mn = min(mn, d);
	}
	cout << mn;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n,a,b; unsigned long long int len=0,wid=0,squ,c,area;
    long long int arr[100000];
    scanf("%lld",&n);
    for(a=0;a<n;a++)
        scanf("%lld",&arr[a]);
    sort(arr,arr+n);
    for(a=n-1;a>=0;a--)
    {
        c=arr[a];
        if(c==arr[a-1]&&c==arr[a-2]&&c==arr[a-3]&&len==0)
        {
            squ=c*c;
            printf("%llu",squ);
            return 0;
        }
        else if(c==arr[a-1]&&len==0)
        {
            len=c;
            a--;
        }
        else if(c==arr[a-1]&&len!=0)
        {
            wid=c;
            break;
        }
    }
    area=len*wid;
    printf("%llu",area);


}

Measured memory_bytes: 1024
#include<stdio.h>

int main(void)

{

 long long int a[10000],min=1000000,max=-1000000,sum=0;

 int n,i;

 scanf("%d",&n);

 for(i=0;i<n;i++){

    scanf("%lld",&a[i]);

    if(a[i]>=max){

       max=a[i];

     }

     if(a[i]<=min){

        min=a[i];

     }

     sum+=a[i];

   }

   printf("%lld %lld %lld\n",min,max,sum);

   return 0;

}

Measured memory_bytes: 676
using System.Collections.Generic;
using System.Linq;
using System;

public class C
{
    public const int INF = 999999999;
}

public class P
{
    public int x { get; set; }
    public int y { get; set; }
}

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            string[] line = Console.ReadLine().Trim().Split(' ');
            var w = int.Parse(line[0]);
            var h = int.Parse(line[1]);
            if (w == 0 && h == 0) break;
            var map = new List<P>[5];
            var sp = new P(); var gp = new P();
            for (int i = 0; i < 5; i++) map[i] = new List<P>();
            for (int i = 0; i < h; i++)
            {
                var s = Console.ReadLine().Trim();
                for (int j = 0; j < w; j++)
                    if (s[j] == 'S') { sp.x = i; sp.y = j; }
                    else if (s[j] == 'G') { gp.x = i; gp.y = j; }
                    else if (s[j] != '.')
                    {
                        var a = int.Parse(s[j].ToString()) - 1;
                        map[a].Add(new P { x = i, y = j });
                    }
            }
            var maxc = 0;
            foreach (var x in map)
                maxc = Math.Max(maxc, x.Count());
            var minret = C.INF;  var minc = -1;
            for (int i = 0; i < 5; i++)
            {
                var dp = new int[5, maxc];
                for (int j = 0; j < 5; j++)
                    for (int k = 0; k < maxc; k++) dp[j, k] = C.INF;
                var ret = GoDP(map, dp, sp, gp, i);
                if (ret < minret) { minret = ret; minc = i; }
            }
            if (minret == C.INF) Console.WriteLine("NA");
            else Console.WriteLine("{0} {1}", minc + 1, minret);
        }
    }
    public static int GoDP(List<P>[] map, int[,] dp, P sp, P gp, int sc)
    {
        var goal = C.INF;
        var t = (sc + 1) % 5;
        for (int i = 0; i < map[t].Count(); i++)
            dp[t, i] = getMD(sp, map[t][i]);
        var nt = (t + 1) % 5;
        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < map[t].Count(); j++)
                for (int k = 0; k < map[nt].Count(); k++)
                    dp[nt, k] = Math.Min(dp[nt, k], dp[t, j] + getMD(map[nt][k], map[t][j]));
            t = (t + 1) % 5;
            nt = (nt + 1) % 5;
        }
        for (int i = 0; i < map[t].Count(); i++)
            goal = Math.Min(goal, dp[t, i] + getMD(gp, map[t][i]));
        return goal;
    }
    public static int getMD(P a, P b)
    {
        return Math.Abs(a.x - b.x) + Math.Abs(a.y - b.y);
    }
}

Measured memory_bytes: 10424
#include <iostream>
#include <functional>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

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

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

typedef pair <ll,ll> P;

bool pairCompareF(const P& firstElof, const P& secondElof)
{
    return firstElof.first < secondElof.first;
}

bool pairCompareS(const P& firstElof, const P& secondElof)
{
    return firstElof.second < secondElof.second;
}

int main()
{
    ll N;
    cin >> N;
    vector<ll> a(N,0);
    rep(i, N) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    ll ans = 40000000;
    for(int i = -100; i <= 100; i++)
    {
        ll cost = 0;
        rep(j, N) {
            ll diff = i - a[j];
            cost += diff * diff;
        }
        ans = min(ans, cost);
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
using std::size_t;

struct Node
{
   int key;
   Node *prev, *next;
   Node(): Node(0) {}
   Node(int k): key(k), prev(nullptr), next(nullptr) {}
};
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
class List
{
private:
   Node *nil;

public:
   List(): nil(new Node) {
      nil->prev = nil->next = nil;
   }

   const Node* const begin()const { return(nil -> next); }
   const Node* const end()  const { return(nil); }

   const Node* const search(int k) const;
   void push_front(int k);
   void erase(const Node* const u);
   void erase_key(int k);
};
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
void List::push_front(int k)
{
   Node *u = new Node(k);
   nil->next->prev   = u;
   u->next           = nil->next;
   nil->next         = u;
   u->prev           = nil;
}

const Node* const List::search(int k) const
{
   Node *i = nil -> next;
   while(i != nil && i->key != k)
      i = i->next;
   return(i);
}

void List::erase(const Node* const u)
{
   if( u == nil )return;
   u->next->prev = u->prev;
   u->prev->next = u->next;
   delete u;
}

void List::erase_key(int k)
{
   erase( search(k) );
}
//;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


static List ls;

int main()
{
   int N;
   char s[32];
   scanf("%d", &N);

   while(N--){
      scanf("%s", s);
      if(strlen(s) == 6){
         int n; scanf("%d", &n);
         if(*s == 'd')
            ls.erase_key(n);
         else
            ls.push_front(n);
      }
      else {
         if(s[6] == 'F')
            ls.erase( ls.begin() );
         else
            ls.erase( ls.end() -> prev );
      }
   }

   printf("%d", ls.begin() -> key);
   for(auto i = ls.begin() -> next; i != ls.end(); i = i->next){
      printf(" %d", i -> key);
   }
   printf("\n");
}




Measured memory_bytes: 33864
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner stdIn = new Scanner(System.in);
        String s = stdIn.next();
        String t = stdIn.next();
        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        String u = stdIn.next();
        
        if(s.equals(u)){
            System.out.println(a - 1 + " " + b);
        }else{
            System.out.println(a + " " + (b - 1));
        }
        
    }
}


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

using namespace std;
#define ll long long
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define PRINT(item) cout << (item) << endl;
#define PRINT_VEC(V)                                                           \
    for (auto v : (V))                                                         \
        cout << v << ' ';
const int MOD = 1000000007;
/* cout << fixed << setprecision(10) << decimal << endl; */

int main() {
    /* code */
    ll X;
    cin >> X;
    ll yen = 100;
    ll year = 0;
    while (true) {
        yen *= 1.01;
        year++;
        if (yen >= X) {
            cout << year << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3636
use std::io;
use std::str::FromStr;

fn input_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn main() {
    let (m1, d1) = input_tuple();
    let (m2, d2) = input_tuple();
    if m1 != m2 {
        println!("1");
    } else {
        println!("0")
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
using namespace std;
vector<int> vec;
int main(void){
    // Your code here!
    string str;
    getline(cin, str);
    int num = 0;
    for (int i = 0; i < str.length(); i++) {
        if (str[i] == ' ')  {
            if (num != 0) {
                vec.push_back(num);
                num = 0;
            }
        } else if (str[i] == '+' || str[i] == '-' || str[i] == '*') {
            int a, b;
            b = vec.back(); vec.pop_back();
            a = vec.back(); vec.pop_back();
            if (str[i] == '+') vec.push_back(a + b);
            if (str[i] == '-') vec.push_back(a - b);
            if (str[i] == '*') vec.push_back(a * b);
        } else {
            num = num * 10 + str[i] - '0';
        }
    }
    int res = vec.back();
    cout << res << endl;
}



Measured memory_bytes: 3176
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int W = sc.nextInt();
		int H = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();

		if(y >= r && y <= H-r && x >=r && x <= W-r){
			System.out.printf("Yes\n");
		}else{
			System.out.printf("No\n");
		}
	}
}




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

int main(){
    string S,T;
    cin>>S>>T;
    vector<int> v(26,-1);
    vector<int> r(26,-1);
    for(int i=0;i<S.size();i++){
        int a = S[i] - 'a';
        int b = T[i] - 'a';
        if(v[a]!=-1||r[b]!=-1){
            if(v[a]!=b||r[b]!=a){
                cout<<"No"<<endl;
                return 0;
            }
        }else{
            v[a] = b;
            r[b] = a;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(int i=s;i<t;i++)
#define pii pair<int,int>
typedef long long ll;
int n,k;
vector<pii> v;
int main()
{
    scanf("%d%d",&n,&k);
    if(k>(n-1)*(n-2)/2){printf("-1\n");return 0;}
    rep(i,2,n+1)v.emplace_back(1,i);
    int r=(n-1)*(n-2)/2;
    rep(i,2,n+1)rep(j,i+1,n+1)
    {
        if(r==k)goto end;
        v.emplace_back(i,j),r--;
    }
    end:
    printf("%d\n",v.size());
    for(pii p:v)printf("%d %d\n",p.first,p.second);
}


Measured memory_bytes: 384
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {
	
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        
        int[] map = new int[100];
        for (int i = 0; i < N; i++) {
        	String s = sc.next();
        	map[(int)s.charAt(0)]++;
        }
        
        int ans = 0;
        for (int count: map) {
        	if (count != 0) {
        		ans++;
        	}
        }
        
        
        System.out.println(ans == 3 ? "Three" : "Four");
    }
}




Measured memory_bytes: 22996
import sys
import os
import math

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M = il()
    R = [set(il()[1:]) for _ in range(N)]
    ret = R[0]
    for r in R:
        ret &= r
    print(len(ret))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define reps(X,O,Y) for(int X=O;X<(Y);++X)
#define rep(X,Y) reps(X,0,Y)
#define rreps(X,O,Y) for(int X=(Y)-1;X>=(O);--X)
#define rrep(X,Y) rreps(X,0,Y)
#define all(X) begin(X),end(X)
#define X first
#define Y second
#define pb push_back

using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const ll INF=1e12;

const int nn=512345;
ll bit[nn];
void add(int i,ll val){
  ++i;
  while(i<nn){
    bit[i]+=val;
    i+=i&-i;
  }
  return;
}
ll sum(int i){
  ++i;
  ll s=0;
  while(i>0){
    s+=bit[i];
    i-=i&-i;
  }
  return s;
}

int main(){
  string str;
  cin>>str;
  int n=str.size();
  vector<int> cnt(200);
  for(char c:str) ++cnt[c];
  ll re=0;
  char center=0;
  reps(c,'a','z'+1) if(cnt[c]%2){
    if(center){
      cout<<-1<<endl;
      return 0;
    }
    center=c;
    pll mn(INF,INF);
    rep(i,n) if(str[i]==center) mn=min(mn,pll(abs(i-n/2),i));
    re=mn.X;
    str.erase(mn.Y,1); --n; --cnt[c];
  }
  vector<int> usd(200);
  string a,b;
  rep(i,n){
    if(usd[str[i]]<cnt[str[i]]/2){
      a+=str[i];
      re+=i;
      ++usd[str[i]];
    }else{
      b+=str[i];
    }
  }
  rep(i,n/2) re-=i;
  reverse(all(b));
  //cout<<a<<","<<b<<":"<<re<<endl;
  
  vector<int> r[200];
  rep(i,n/2){
    r[b[i]].pb(i);
  }
  rep(i,200) reverse(all(r[i]));
  rep(i,n/2){
    assert(r[a[i]].size());
    int x=r[a[i]].back();
    r[a[i]].pop_back();
    re+=x-sum(x);
    add(x,1);
  }
  cout<<re<<endl;
  return 0;
}

Measured memory_bytes: 6736
from collections import deque
H,W = map(int,input().split())
maze = []
dx = [1,0,-1,0]
dy = [0,1,0,-1]
ls = []
count = 0
for i in range(H):
    tmp = list(input())
    maze.append(tmp)
    for j in range(W):
        if tmp[j] != "#":
            ls.append([i,j])
            count += 1
def bfs(sx,sy):
    INF = -1
    cost = [[INF]*W for _ in range(H)]
    P = deque()
    P.append([sx,sy])
    cost[sx][sy] = 0
    while len(P) != 0:
        p = P.popleft()
        for i in range(4):
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] != "#" and cost[nx][ny] == INF:
                P.append([nx,ny])
                cost[nx][ny] = cost[p[0]][p[1]]+1
    return cost
def solve():
    ans = 0
    for i in ls:
        sx,sy = i[0],i[1]
        cs = bfs(sx,sy)
        for k in range(len(cs)):
            if ans == count:
                break
            if max(cs[k]) > ans:
                ans = max(cs[k])
    return ans
print(solve())

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

int main(){
	int n,x,count;
	while(1){
		cin >> n >> x;
		if(n==0&&x==0){
			break;
		}
		count=0;
		for(int i=1;i<=n;i++){
			for(int j=i+1;j<=n;j++){
				for(int k=j+1;k<=n;k++){
					if((i+j+k)==x){
						count++;
					}
				}
			}
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 3060
package main

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

type Pair struct {
	a, b int
}

func main() {
	N := ReadInt()
	m := make(map[Pair]Pair)
	zeros := 0
	for i := 0; i < N; i++ {
		x, y := ReadInt(), ReadInt()
		if x == 0 && y == 0 {
			zeros++
			continue
		}
		gcd := GCD(x, y)
		x /= gcd
		y /= gcd
		if y < 0 {
			x, y = -x, -y
		}
		if y == 0 && x < 0 {
			x, y = -x, -y
		}
		rot90 := x <= 0
		if rot90 {
			x, y = y, -x
		}
		p := m[Pair{x, y}]
		if rot90 {
			p.a++
		} else {
			p.b++
		}
		m[Pair{x, y}] = p
	}
	ans := 1
	for _, p := range m {
		s, t := p.a, p.b
		now := 1
		now += ModPow(2, s) + Mod - 1
		now += ModPow(2, t) + Mod - 1
		now %= Mod
		ans *= now
		ans %= Mod
	}
	ans = ans + zeros + Mod - 1
	ans %= Mod
	fmt.Println(ans)
}

func GCD(a, b int) int {
	if b == 0 {
		return a
	}
	return GCD(b, a%b)
}

const Mod = int(1e9) + 7

func ModPow(a, b int) (x int) {
	for x = 1; b > 0; b >>= 1 {
		if b&1 == 1 {
			x = x * a % Mod
		}
		a = a * a % Mod
	}
	return
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int) { Scan(&i); return }


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

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }

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

  int X;
  cin >> X;
  int sum = 0;
  sum += X/500*1000;
  sum += (X%500)/5*5;
  cout << sum << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define tns 1000000007

inline long long  pow(long long n, long long i) {
	long long r = 1, t = n;
	for(; i != 0; i >>= 1) {
		if (i&1) r = r * t % tns;
		t = t * t % tns;
	}
	return r;
}

long long fact(long long n) {
	long long r = 1;
	for(; n > 0; n--)
		r = r * n % tns;
	return r;
}

inline long long nct(long long n, long long t) {
	long long a = 1, b = 1;
	while(t > 0) {
		a = a * n % tns;
		b = b * t % tns;
		n--;
		t--;
	}
	return a * pow(b, tns-2) % tns;
}

inline long long inv(long long t) {
	return pow(t, tns - 2);
}

long long dp[200000];
long long f(long long n, long long k) {
	if (n <= k) {
		return nct(2*n-1, n);
	}
	long long s = 0;
	long long p;
	for(int t = 0; t <= k; t++) {
		if (t == 0) {
			p = 1;
		} else {
			long long invt = inv(t);
			p = p * (n-t+1)%tns * (n-t) % tns * invt%tns * invt %tns;
		}
		s = (s + p) % tns;
	}
	return s;
}



int main() {
	long long n, k;
	cin >> n >> k;
	cout << f(n, k) << endl;
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N=2e5+5;
const ll mod=1e9+7;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll k,x;cin>>k>>x;
    cout<<(k*500>=x?"Yes":"No");
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<iostream>
#include<map>
using namespace std;
int main()
{
	string a,b;
	int n,m,i,j,h=0;
	map<string,int>f;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		cin>>a;
		f[a]++;
	}
	scanf("%d\n",&m);
	for(i=0;i<m;i++)
	{
		cin>>a;
		f[a]--;
	}
	map<string,int>::iterator it;
	for(it=f.begin();it!=f.end();it++)
	{
		h=max(it->second,h);
	}
	printf("%d\n",h);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9+7;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string n;
  cin >> n;
  cout << "ABC"<< n << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

int main() {
    int N, ans = 0;
    cin >> N;
    int T = pow(2, N);
    vector<vector<int>> A(N), U(N);
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        for (int j = 0; j < a; j++) {
            int x, y;
            cin >> x >> y;
            if (y == 0) {
                A.at(i).emplace_back(x - 1);
            }
            else{
                U.at(i).emplace_back(x - 1);
            }
        }
    }
    for (int i = 0; i < T; i++) {
        int b = i;
        vector<int> B;
        set<int> S;
        for (int j = 0; j < N; j++) {
            if (b & 1) {
                B.emplace_back(j);
                S.insert(j);
            }
            b >>= 1;
        }
        for (int j = 0; j < B.size(); j++) {
            bool Y = false, H = false;
            for (int k = 0; k < A.at(B.at(j)).size(); k++) {
                if (S.count(A.at(B.at(j)).at(k))){
                    Y = true;
                    break;
                }
            }
            if (Y) {
                break;
            }
            for (int k = 0; k < U.at(B.at(j)).size(); k++) {
                if (!S.count(U.at(B.at(j)).at(k))){
                    H = true;
                    break;
                }
            }
            if (H) {
                break;
            }
            if (j == B.size() - 1) {
                int c = B.size();
                ans = max(ans, c);
            }
        }
    }
    cout << ans << endl;
}


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

using namespace std;
#define ll long long
#define ull unsigned long long
#define i128 __int128
#define mp make_pair
#define ld long double
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
const int N = 1e6 + 100;
int T;
int n;
char str[N];

int main() {
    scanf("%d%s", &n, str + 1);
    vector<int> v;
    v.push_back(0);
    int sum = 0;
    for (int i = 1; i <= n; i++) {
        if (str[i] == 'R')sum++, v.push_back(i);
    }
    int pos = lower_bound(v.begin(), v.end(), sum + 1) - v.begin();
    printf("%d\n", v.size() - pos);
    return 0;
}

Measured memory_bytes: 4488
using System;

namespace std
{
    class Test 
    {
      static void Main(string[] args) {
          int d, r;
          double f;
          var input = Console.ReadLine().Split(' ');
          var a = int.Parse(input[0]);
          var b = int.Parse(input[1]);
          
          d = a / b;
          r = a % b;
          f = (double)a / (double)b;
         string text = f.ToString("F5"); // 小数点以下を5桁表示する指示
          Console.WriteLine("{0} {1} {2}",d ,r, text);
      }
    }
}




Measured memory_bytes: 17940
#include<stdio.h>
int main()
{
  int n,x;
  int k,j,l;
  int count;
 while(1){
  scanf("%d%d",&n,&x);
  if(n==0 && x==0)
     break;

  for(k=1;k<=n;k++)
    for(j=k+1;j<=n;j++)
      for(l=j+1;l<=n;l++)
        if(k+j+l == x) 
           count++;
    printf("%d\n",count);
    count=0;
}
return 0;
}

Measured memory_bytes: 1724
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)
#define be(v) (v).begin(), (v).end()
ll INF = 1LL << 60;
ll mod = 1e9 + 7;
ll lim=1e18;

int main() {
	int n; cin >> n;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	sort(be(a));
	if(a[0]==0) {
		cout << 0 << endl;
		return 0;
	}
	ll ans=1;
	rep(i,n) {
		ans*=a[i];
		if(i<n-1&&ans>1e9) {
			if(a[i+1]>lim/ans) {
				cout << -1 << endl;
				return 0;
			}
		}
		if(ans>lim) {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 4052
while True:
    a, op, b = input().split()
    if op == '?':
        break
    
    a, b = int(a), int(b)
    if op == '+':
        print(a + b)
    elif op == '-':
        print(a - b)
    elif op == '*':
        print(a * b)
    elif op == '/':
        print(a // b)

Measured memory_bytes: 7720
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, a, n) for (ll i = a; i < (ll)n; ++i)
const int MOD = 1000000007;
using namespace std;

int main(void)
{
    ll d;
    cin >> d;
    string ans = "Christmas ";
    rep(i, 0, 25 - d) ans += "Eve ";
    cout << ans << endl;
}


Measured memory_bytes: 3608
def solve():
    from sys import stdin
    f_i = stdin
    q = f_i.readline()
    d = 0
    
    from collections import deque
    L = deque()
    
    for l in f_i:
        if l[0] == '0':
            L.append(l[2:])
        elif l[0] == '1':
            r = int(l[2:])
            L.rotate(r)
            d -= r
        else:
            L.pop()
    L.rotate(d)
    L.reverse()
    print(''.join(L), end='')

solve()


Measured memory_bytes: 42964
#include "bits/stdc++.h"
using namespace std;
#define OUT(x)                cout << #x << " = " << x << endl; 
#define rep(i, n)             for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r)          for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r)          for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define each(i, v)            for (auto i : v)
#define all(x)                (x).begin(), (x).end()
#define rall(x)               (x).rbegin(), (x).rend()
#define pb(x)                 push_back(x)
#define bp(x)                 __builtin_popcount(x)
#define mp(x, y)              make_pair((x), (y))
#define fi                    first
#define se                    second
#define setp(x)               setprecision(x)
#define mset(m, v)            memset(m, v, sizeof(m))
#define sz(x)                 (int)(x.size())
static const int INF        = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const int MOD        = 1000000007;
static const double PI      = 3.14159265358979;

//#define int                   long long

typedef vector<double>        vd;
typedef vector<string>        vs;
typedef vector<bool>          vb;
typedef vector<int>           vi;
typedef pair<int, int>        pii;
typedef vector<pii>           vpii;

template<typename T> void pv(T a, T b) { for (T i = a; i != b; i ++) cout << *i << " "; cout << endl; }
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }
int in() { int _x; scanf("%d", &_x); return _x; }
long long lin() {long long _x; scanf("%lld", &_x); return _x; };

signed main() { 
        int n, k;
        cin >> n >> k;
        string s;
        cin >> s;
        if (k > 2 * n) k = 2 * n + (k % 2);
        int rev = 0;
        deque<int> dq;
        rep(i, n) dq.pb(s[i] == 'A');
        rep(i, k) {
                if (dq.front() ^ rev) {
                        dq.pop_front();
                        dq.push_front(rev);
                } else {
                        rev ^= 1;
                        dq.pop_front();
                        dq.pb(1 ^ rev);
                }
        }
        rep(i, n) {
                if (rev ^ dq.front()) cout << "A";
                else cout << "B";
                dq.pop_front();
        }
        cout << endl;
        return 0;
}               


Measured memory_bytes: 1540
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
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(a > b){ a = b; return 1; } return 0; }
int main()
{
  int n; cin >> n;
  vector<int> d(n);
  rep(i,n) cin >> d[i];

  int res = 0;
  rep(i,n) {
    rep(j,n) {
      if(i >= j) continue;
      res += d[i]*d[j];
    }
  }
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define FORUL(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
#define FORULE(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define FOREACH(it, X) for(__typeof((X).begin()) it = (X).begin(); it != (X).end(); it++)
#if defined(_MSC_VER) || __cplusplus > 199711L
#define AUTOVAR(newvar,v) auto newvar = (v)
#else
#define AUTOVAR(newvar,v) __typeof(newvar) r = (v)
#endif
#define PB(x) push_back(x)
#define MP(x,y) make_pair((x),(y))
#define MEMSET(m,v) memset(m,v,sizeof(m))

typedef long long				 ll;
typedef unsigned long long		ull;

#define DEBUG 1

#if DEBUG
#define DOUT cout<<"["<<__LINE__<<"]:"
#else
#define DOUT 0 && cout
#endif

using namespace std;

int N;
string S;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false);

	cin >> N;
	cin >> S;

	int ans = 0;
	FOR(n,N) {
		ans++;
		while(n<N) {
			if(S[n]!=S[n+1]) {
				break;
			}
			n++;
		}
	}

	cout << ans << endl;

	return 0;
}




Measured memory_bytes: 512
N, P = map(int, input().split())

def factorize(n):
    fct = []
    b, e = 2, 0
    while b * b <= n:
        while n % b == 0:
            n = n // b
            e = e + 1
        if e > 0:
            fct.append((b, e))
        b, e = b + 1, 0
    if n > 1:
        fct.append((n, 1))
    return fct

fct = factorize(P)
fct.sort(key=lambda x:x[1], reverse=True)
res = 1
for el in fct:
    if el[1] >= N:
        res = res * el[0] ** (el[1] // N)

print(res)

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
	int N, M; cin >> N >> M;
	vector<int> A(N);
	rep(i, N) cin >> A[i];
	sort(all(A));

	vector<pair<int, int>> vp(M);
	rep(i, M) {
		int b, c; cin >> b >> c;
		vp[i] = make_pair(c, b);
	}
	sort(all(vp), greater<pair<int, int>>());

	int min_a = 0;
	rep(i, M) {
		rep (j, vp[i].second) {
			if (A[min_a] >= vp[i].first) break;
			A[min_a] = vp[i].first;
			min_a++;
		}
	}

	ll ans = 0;
	rep(i, N) ans += A[i];
	cout << ans << endl;
}


Measured memory_bytes: 1408
A, B, C = map(int, input().split(" "))

count = 0
oe = [A%2, B%2, C%2]

if sum(oe) == 2:
    count += 1
    if A%2 == 0:
        B += 1
        C += 1
    elif B%2 == 0:
        A += 1
        C += 1
    else:
        A += 1
        B += 1
elif sum(oe) == 1:
    count += 1
    if A%2 == 1:
        B += 1
        C += 1
    elif B%2 == 1:
        A += 1
        C += 1
    else:
        A += 1
        B += 1
lst = sorted([A, B, C])
count += int((lst[1] - lst[0]) / 2)
count += int(lst[2] - lst[1])
print(count)

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

using namespace std;

int main() {
	int n, q;
	vector<int> S, T;

	cin >> n;
	S.resize(n);
	for (auto &Si: S) {
		cin >> Si;
	}

	cin >> q;
	T.resize(q);
	for (auto &Ti: T) {
		cin >> Ti;
	}

	int ans = 0;
	for (int i = 0; i < q; ++i) {
		for (int j = 0; j < n; ++j) {
			if (S[j] == T[i]) {
				++ans;
				break;
			}
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3120
module IO = struct

  (* @since 4.04.0 *)
  let split_on_char sep s =
    let open String in
    let r = ref [] in
    let j = ref (length s) in
    for i = length s - 1 downto 0 do
      if get s i = sep then begin
        r := sub s (i + 1) (!j - i - 1) :: !r;
        j := i
      end
    done;
    sub s 0 !j :: !r

  let read_ns () = read_line () |> split_on_char ' ' |> List.map int_of_string

end

let solve h w c =
  let s = Array.make w 0 in
  let t = Array.make w 0 in
  let r = ref 0 in
  for j = 0 to w - 1 do
    if c.(0).(j) then begin
      s.(j) <- 1;
      r := 1;
    end
  done;
  if !r = 0 then begin
    let rec doit i =
      if i = h then ()
      else if c.(i).(0) then r := 1
      else doit (i + 1) in
    doit 0
  end;
  for i = 1 to h - 1 do
    if c.(i).(0) then t.(0) <- 1;
    for j = 1 to w - 1 do
      if not c.(i).(j) then t.(j) <- 0
      else begin
        let d = if s.(j) < t.(j-1) then s.(j) else t.(j-1) in
        t.(j) <- 1 + if s.(j-1) < d then s.(j-1) else d;
        if t.(j) > !r then r := t.(j)
      end
    done;
    Array.iteri (fun i e -> s.(i) <- e) t
  done;
  !r * !r

let () =
  match IO.read_ns () with
  | [h; w] ->
    let c = Array.make_matrix h w false in
    for i = 0 to h - 1 do
      IO.read_ns () |> List.iteri (fun j e -> c.(i).(j) <- e = 0);
    done;
    solve h w c |> Printf.printf "%d\n"
  | _ -> assert false

Measured memory_bytes: 25364
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,k,ind,d;
    int diff =0;
    bool used[102]={0};
    cin>>n>>k;
    for(int i=0;i<k;i++)
    {
        cin>>d;
        for(int j=0;j<d;j++)
        {
            cin>>ind;
            if(used[ind]==0)
            {
                used[ind] = 1;
                diff++;
            }
        }
    }
    cout<<n-diff<<endl;
    return 0;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;

int main() {
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	int ans = 0;
	if(a <= k) {
		ans += a;
		if(a + b < k) {
			ans -= k - a - b;
		}
	}else {
		ans+= k;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3608
// C - Synthetic Kadomatsu
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;

int main(){
	int N; cin>>N;
	vi A(3); for(int i=0; i<3; ++i) cin>>A[i];
	vi L(N); for(int i=0; i<N; ++i) cin>>L[i];

	int ans = INT_MAX, E = 1<<(N*2);
	for(int i=0; i<E; ++i){

		vi sum(3), count(3);
		for(int j=0; j<N; ++j){
			int b = (i>>(j*2)) & 3;
			if(b==3) continue;// not use
			++count[b];
			sum[b] += L[j];
		}

		if(min({count[0], count[1], count[2]})!=0){//each requires at least one
			int s = 0;
			for(int j=0; j<3; ++j){
				s += abs(A[j] - sum[j]);
				if(count[j]>1) s += (count[j] - 1) * 10;
			}
			ans = min(ans, s);
		}

	}
	cout<< ans <<endl;
}

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

int main() {
  string a;
  string ans="No";
  cin >> a;

  if(a[2]==a[3]) {
    if(a[4]==a[5]) {
      ans="Yes";
    } 
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define res(i,n) for(int i=n;;i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(long long x, long long y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(long long x, long long y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N; cin >> N;
    vector<int>A(N);
    vector<int>B(9);
    int ans = 0;
    rep(i, N) {
        cin >> A[i];
        if (A[i] < 400)B[0]=1;
        else if (A[i] < 800)B[1]=1;
        else if (A[i] < 1200)B[2]=1;
        else if (A[i] < 1600)B[3]=1;
        else if (A[i] < 2000)B[4]=1;
        else if (A[i] < 2400)B[5]=1;
        else if (A[i] < 2800)B[6]=1;
        else if (A[i] < 3200)B[7]=1;
        else B[8]++;
    }
    rep(i, 9) ans += B[i];
    cout << (ans-B[8]==0? 1:ans - B[8]) << " " << ans << endl;
}

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

int main(){
    string s;
    cin>>s;
    if(s.size()>=4 && s[0]=='Y' && s[1]=='A' && s[2]=='K' && s[3]=='I'){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

# 全て-Kして，和が0以上かどうかを判定する
# 累積和の座圧→bitで出来る

from operator import itemgetter
def compress(A,reduction=True,start=0):
    if reduction:
        d = {}
        A_sort = sorted(list(set(A)))
        for i,a in enumerate(A_sort):
            d[a] = i+start
        return [d[a] for a in A]
    else:
        A_sort = sorted(enumerate(A),key=itemgetter(1,0))
        A_compress = [0]*len(A)
        for i,(j,_) in enumerate(A_sort):
            A_compress[j] = i+start
        return A_compress

class BIT:
    """
    a[1]~a[n]の数列を想定
    """

    def __init__(self,n):
        self.size = n
        self.tree = [0]*(n+1)
 
    def add(self,index,x):
        """
        a[index]にxを加算
        """
        while index <= self.size:
            self.tree[index] += x
            index += index & (-index)
 
    def sum(self,index):
        """
        a[1]~a[index]の和
        """
        s = 0
        while index:
            s += self.tree[index]
            index -= index & (-index)
        return s
 
    def search(self,value):
        """
        sum(index) >= value を満たす最小のindex
        sum(n) < value のとき n+1 を返す
        """
        i = 0
        s = 0
        step = 1 << (self.size.bit_length() - 1)
        while step:
            if i+step <= self.size and s + self.tree[i+step] < value:
                i += step
                s += self.tree[i]
            step >>= 1
        return i + 1


N,K = LI()
a = LIR(N,1)
a = list(map(lambda x: x-K, a))
ca = [0]
for i in range(N):
    ca.append(ca[-1]+a[i])

A = compress(ca,start=1)
bit = BIT(max(A))

ans = 0
for i in range(N+1):
    ans += bit.sum(A[i])
    bit.add(A[i],1)

print(ans)

Measured memory_bytes: 87976
import collections
N = int(input())
S = []
for _ in range(N):
  S.append(input())

counter = collections.Counter(S)
AC = counter['AC']
WA = counter['WA']
TLE = counter['TLE']
RE = counter['RE']

print("AC x {}".format(AC))
print("WA x {}".format(WA))
print("TLE x {}".format(TLE))
print("RE x {}".format(RE))

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

int main()
{
  vector<int> a(3);
  cin >> a[0] >> a[1] >> a[2];
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  int sum = a[0]*10 + a[1] + a[2];
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define MOD 1000000007
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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 main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	string s;
	ll k;
	cin >> s >> k;

	ll num[3];

	char pre = -1;
	ll n = 0;

	bool flag2 = true;
	REP(i, s.size()) {
		if (s[i] != s[0]) flag2 = false;
	}
	if (flag2) {
		cout << (s.size()* k) / 2 << endl;
		return 0;
	}

	bool flag = true;
	

	REP(j, 3) {
		REP(i, s.size()) {
			//cout << pre << s[i] << endl;
			if (pre == s[i]&&flag==true) {
				n++;
				flag = false;
			}
			else {
				flag = true;
			}
			pre = s[i];
			
		}
		num[j] = n;
		//cout << num[j] << endl;
		n = 0;
	}


	if (k == 1) {
		cout << num[0] << endl;
	}
	else if (k == 2) {
		cout << num[0] + num[2] << endl;
	}
	else {
		cout << num[0] + (k - 2)* num[1] + num[2] << endl;
	}

	return 0;
}


Measured memory_bytes: 256
H, W = gets.split.map(&:to_i)
ary = []
black_cnt = 0
H.times do |n|
    ary << gets.chomp.chars
    black_cnt += ary[-1].count('#')
end
queue = [[0,0]]
dist = Array.new(H){Array.new(W, nil)}
dist[0][0] = 0
until queue.empty?
    x, y = queue.shift
    if x == H-1 && y == W-1
        break
    end
    [[-1,0],[0,-1],[1,0],[0,1]].each do |i, j|
        next if !(x+i).between?(0, H-1) || !(y+j).between?(0, W-1) || ary[x+i][y+j] == '#' || dist[x+i][y+j] != nil
        dist[x+i][y+j] = dist[x][y] + 1
        queue << [x+i, y+j]
    end
end
puts dist[H-1][W-1] ? H*W - black_cnt - dist[H-1][W-1] - 1 : -1

Measured memory_bytes: 2172
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(ll V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

int n, w;
ll weight[100001], value[100001], dp[102][100001];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n >> w;
	forl(i, 0, n) cin >> weight[i] >> value[i];
	forl(i, 0, 102) forl(j, 0, 100001) dp[i][j] = INT_MAX;
	dp[0][0] = 0;
	ll ans = 0;
	forl(i, 0, n) {
		forl(j, 0, 100001) {
			if(dp[i][j] == INT_MAX) continue;
			dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
			if(dp[i][j] + weight[i] <= w) dp[i+1][j+value[i]] = min(dp[i+1][j+value[i]], dp[i][j]+weight[i]);
		}
	}
	forl(i, 0, 100001) if(dp[n][i] != INT_MAX) ans = max(ans, i);
	println(ans);
}


Measured memory_bytes: 80256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <sstream>
#include <istream>

using namespace std;

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

int main(){
	int n;
	cin >> n;
	
	int cnt = 1;
	if(n==1){
		cout << 4 << endl;
		return 0;
	}
	else if (n == 2)
	{
		cout << 4 << endl;
		return 0;
	}
		while (n != 4)
		{
			if (n % 2 == 0)
				n /= 2;
			else
				n = 3 * n + 1;
			cnt++;
		}

	cout << cnt+3 << endl;

	return 0;
}


Measured memory_bytes: 256