akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for(int i = a; i < b; i++)

const ll MOD = 1e9 + 7;
const char *AGCT = "AGCT";
int N;

// dp[N][i][j][k] := 長さNの文字列について、最後の文字が後ろから順にi,j,kとなっている文字列の数
ll dp[110][4][4][4];

ll rec(int n, int i, int j, int k){
    if(dp[n][i][j][k] != -1) return dp[n][i][j][k];
    if(n == 3){
        if(k == 0 && j == 1 && i == 2) return dp[n][i][j][k] = 0;
        if(k == 1 && j == 0 && i == 2) return dp[n][i][j][k] = 0;
        if(k == 0 && j == 2 && i == 1) return dp[n][i][j][k] = 0;
        return dp[n][i][j][k] = 1;
    }

    ll SUM = 0;
    rep(l, 0, 4){
        if(k == 0 && j == 1 && i == 2) continue;
        if(k == 1 && j == 0 && i == 2) continue;
        if(k == 0 && j == 2 && i == 1) continue;
        if(l == 0 && j == 1 && i == 2) continue;
        if(l == 0 && k == 1 && i == 2) continue;
        SUM += rec(n-1, j, k, l);
        SUM %= MOD;
    }
    //cerr << SUM << endl;

    return dp[n][i][j][k] = SUM;
}

int main(){
    cin >> N;
    memset(dp, -1, sizeof(dp));
    //dp[0][0][0][0] = 1;

    cout << rec(N+3, 3, 3, 3) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<vector>
#include<deque>
#include<map>
#include<set>

using namespace std;

int N;
long K, a[100007], b[100007];

int input(){
  cin >> N >> K;
  for( int i = 0; i < N; i++ ){
    cin >> a[i] >> b[i];
  }
  return 0;
}

int outputBit(long k){
  int f = 0;
  for( int i = 30; i >= 0; i-- ){
    if( k & (1<<i) ){
      cout << "1";
      f = 1;
    }else if( f ){
      cout << "0";
    }
  }
  cout << endl;
  return 0;
}

long check(long k){
  long res = 0;
  //outputBit(k);
  for( int i = 0; i < N; i++ ){
    if( (a[i] | k) == k ){
      res += b[i];
    }
  }
  return res;
}

int main(){
  long res, tmp;
  input();
  res = check(K);
  for( int i = 0; i <= 30; i++ ){
    long k = K;
    long m = 1 << i;
    if( (k&m) != m ){ continue; }
    for( int j = 0; j < i; j++ ){
      k |= 1 << j;
    }
    k -= m;
    tmp = check(k);
    res = (res >= tmp ? res : tmp);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	int a,b,c,x; cin >> a >> b >> c >> x;
	int count = 0;
	rep(i,a+1)rep(j,b+1)rep(k,c+1){
		if (x == 500*i + 100*j + 50*k) count++;
	}
	cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  cin >> N >> K;
  
  vector<char> vec(K);
  for (int i = 0; i < K; i++) {
    cin >> vec.at(i);
  }
  
  for (int x = N; x < 100000; x++) {
    int tmp = x;
    string s = to_string(tmp);
    bool flag = true;
    vector<char> pop(s.size());
    
    for (int i = 0; i < s.size(); i++) {
      pop.at(i) = s.at(i);
    }

    for (int i = 0; i < K; i++) {
      if(count(pop.begin(), pop.end(), vec.at(i))) {
        flag = false;
      }
    }
    
    if(flag) {
      cout << x << endl;
      break;
    }
  }

}

Measured memory_bytes: 3668
MOD = 998244353
list_size = 200001

f_list = [1] * list_size
f_r_list = [1] * list_size

for i in range(list_size - 1):
	f_list[i + 1] = int((f_list[i] * (i + 2)) % MOD)

f_r_list[-1] = pow(f_list[-1], MOD - 2, MOD)

for i in range(2, list_size + 1):
	f_r_list[-i] = int((f_r_list[-i + 1] * (list_size + 2 - i)) % MOD)

def comb(n, r):
	if n < r:
		return 0
	elif n == 0 or r == 0 or n == r:
		return 1
	else:
		return (((f_list[n - 1] * f_r_list[n - r - 1]) % MOD) * f_r_list[r - 1]) % MOD 

n, m, k = map(int, input().split())
ans = 0
for i in range(k+1):
	ans += comb(n-1, i) * m * pow(m-1, n-1-i, MOD)
	ans %= MOD
print(ans)

Measured memory_bytes: 74420
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

int main(void){
    ll X;
    
    cin >> X;
    
    if (X == 3 || X == 5 || X == 7) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

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

int main(){
    string s;
    cin >> s;
    for (int i = s.size()-2; i > 0; i -= 2){
        bool flag = true;
        for (int j = 0; j < i / 2; j++){
            if (s[j] != s[i/2+j]){
                flag = false;
                break;
            }
        }
        if (flag){
            cout << i << endl;
            return 0;
        }
    }
    
}

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

int main(){
    string S;cin>>S;int L=S.size();
    long N[L];
    for(int i=0;i<L;i++){
        N[i]=S.at(i)-'0';
    }long temp,count;long sum=0;
    for(int i=0;i<(1<<L-1);i++){
        count=1;
        temp=N[L-1];
        for(int j=L-2;j>=0;j--){
            if(i&(1<<j)){
                count=1;
            }else{
                count*=10;
            }temp+=N[j]*count;
        }sum+=temp;
    }cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <map>
#include <string>
#include <math.h>
#include <vector>
#include <cstdlib>
#include <queue>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

using namespace std;

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

    int ans = 1;
    REP(i, N)
    {
        if (ans < K)
        {
            ans += ans;
        }
        else
        {
            ans += K;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
void Swap(int x[ ], int i, int j)
{
    int temp;
    
    temp = x[i];
    x[i] = x[j];
    x[j] = temp;
}

void QSort(int x[ ], int left, int right)
{
    int i, j;
    int pivot;
    
    i = left;
    j = right;
    
    pivot = x[(left + right) / 2];
    
    while (1) {
        
        while (x[i] > pivot)
            i++;
        
        while (pivot > x[j])
            j--;
        if (i >= j)
            break;
        
        Swap(x, i, j);
        i++;
        j--;
    }
    
    
    if (left < i - 1)
        QSort(x, left, i - 1);
    if (j + 1 <  right)
        QSort(x, j + 1, right);
}

int main(){
    int N,p[11];
    scanf("%d",&N);
    for (int i=0; i<N; i++) {
        scanf("%d",&p[i]);
    }
    QSort(p,0,N-1);
    int sum=0;
    sum+=p[0]/2;
    for (int i=1; i<N; i++) {
        sum+=p[i];
    }
    
    printf("%d\n",sum);
  
    return 0;
}

Measured memory_bytes: 128
h,w=map(int,input().split())
m=[[1 if c=="#" else 0 for c in input()] for i in range(h)]

n=[i[:] for i in m]


for i in range(1,h):
    n[i][0]=n[i-1][0]+int(m[i-1][0]-m[i][0]==-1)
for j in range(1,w):
    n[0][j]=n[0][j-1]+int(m[0][j-1]-m[0][j]==-1)

for i in range(1,h):
    for j in range(1,w):
        n[i][j]=min(n[i-1][j]+int(m[i-1][j]-m[i][j]==-1),n[i][j-1]+int(m[i][j-1]-m[i][j]==-1))

print(n[-1][-1])

Measured memory_bytes: 3188
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
using namespace std;
typedef long long ll;

int N,K;
string S;
pair<int,int> t[100000];

int main(){
    cin>>N>>K>>S;
    
    int num=S[0]-'0';
    t[0].second=num;
    int index=0;
    rep(i,N){
        if(num==S[i]-'0') t[index].first++;
        else{
            t[++index].first++;
            num=(num+1)%2;
            t[index].second=num;
        }
    }
    index++;
    //rep(i,index) cout<<t[i].first<<' ';
    //cout<<endl;

    int sum=0;
    if(t[0].second==0){
        rep(i,min(2*K,index)){
            sum+=t[i].first;
        }
    }else{
        rep(i,min(2*K+1,index)){
            sum+=t[i].first;
        }
    }
    //cout<<"0:"<<sum<<endl;

    int ans=sum;
    int n=t[index-1].second==0?index-2*K:index-2*K-1;
    repn(i,n){
        if(t[i].second==0){
            sum-=t[i-1].first;
        }else{
            sum-=t[i-1].first;
            sum+=t[i+2*K-1].first+t[i+2*K].first;
        }
        ans=max(ans,sum);
        //cout<<i<<":"<<sum<<endl;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 1280
N, C = map(int, input().split())
sch = sorted([list(map(int, input().split())) for _ in range(N)], key=lambda x: x[0])
rec = [[0, 0] for _ in range(C+1)]
num_rec = 1

for i in range(N):
    s, t, c = sch[i]
    start = False
    for j in range(1, num_rec + 1):
        if rec[j][0] - int(rec[j][1] == c) < s:
            rec[j] = [t, c]
            start = True
            break
    if not start:
        num_rec += 1
        rec[num_rec] = [t, c]
    
print(num_rec)

Measured memory_bytes: 29492
#include <stdio.h>

int main(void)
{
	int a,b,d,r;
	double a1,b1,f;

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

	a1=a;
	b1=b;
	d = a / b;
	r = a % b;
	f = a1 / b1;

	printf("%d %d %f\n",d,r,f);

	return 0;
}

Measured memory_bytes: 636
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
m = map(int,read().split())
A,B = zip(*zip(m,m))

# 末尾から

add = 0
for a,b in zip(A[::-1],B[::-1]):
    a += add
    add += (-a) % b

print(add)

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

#define EPS 1e-10

struct Point{double x,y,d;};
int n;
Point hero,demon;
vector<Point>crystal;
bool ok;

double dist(Point a,Point b)
{
  return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
void solve(int now,double time,vector<bool>visited){
  int i;
  bool f=true;
  if(time-crystal[now].d>-EPS)return;
  for(i=0;i<n;i++){
    if(visited[i])continue;
    if(time+dist(crystal[now],crystal[i])-crystal[i].d>EPS)return;
  }
  for(i=0;i<n;i++){
    if(visited[i])continue;
    visited[i]=true;
    solve(i,time+dist(crystal[now],crystal[i]),visited);
    visited[i]=false;
    f=false;
  }
  if(f)ok=true;
  return;
}

int main()
{
  vector<bool>visited;
  int i;
  double hx,hy,dx,dy,x,y;
  double time;
  while(cin>>n>>hx>>hy>>dx>>dy,hx||hy||dx||dy){
    hero.x=hx;
    hero.y=hy;
    demon.x=dx;
    demon.y=dy;
    crystal.clear();
    visited.resize(n);
    fill(visited.begin(),visited.end(),false);
    for(i=0;i<n;i++){
      cin>>x>>y;
      Point p={x,y,0};
      p.d=dist(p,demon);
      crystal.push_back(p);
    }
    ok=false;
    for(i=0;i<n;i++){
      time=dist(hero,crystal[i]);
      visited[i]=true;
      solve(i,time,visited);
      visited[i]=false;
      if(ok)break;
    }
    puts(ok?"YES":"NO");
  }
}

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

int main()
{
    long test;
    test=1;
    // cin>>test;
    while(test--){
    long i,j,a,b,n,x,ans,most,index,c,maxi=0;
    cin>>n>>c;
    vector<pair<long,long>> stu,che;
    for(i=0;i<n;i++)
    {
        cin>>a>>b;
        stu.push_back(make_pair(a,b));
    }
    for(i=0;i<c;i++)
    {
        cin>>a>>b;
        che.push_back(make_pair(a,b));
    }
    
    // for(i=0;i<n;i++)
    // {
    //     cout<<stu[i].first<<" "<<stu[i].second<<endl;
    // }
    // for(i=0;i<c;i++)
    // {
    //     cout<<che[i].first<<" "<<che[i].second<<endl;    
        
    // }
    
    
    
    for(i=0;i<n;i++)
    {
        long mini=LONG_MAX;
        for(j=0;j<c;j++)
        {
            if((abs(stu[i].first-che[j].first)+abs(stu[i].second-che[j].second))<mini)
            {
                ans=j+1;
                // cout<<"here";
                mini=abs(stu[i].first-che[j].first)+abs(stu[i].second-che[j].second);
                // cout<<mini<<endl;
            }
        }
        cout<<ans<<endl;
    }
    
    }
}

Measured memory_bytes: 256
#include <vector>
#include <algorithm>
namespace {
struct MinCostFlow {
	struct Edge {
		int dst, cap, cost, rev;
		Edge(){}
		Edge(int dst, int cap, int cost, int rev): dst(dst), cap(cap), cost(cost), rev(rev){}
	};
	
	typedef std::vector<Edge> Edges;
	typedef std::vector<Edges> Graph;
	
	static const int INF = 1 << 28;
	
	MinCostFlow(){}
	MinCostFlow(int v): g(v){}
	
	void addEdge(int src, int dst, int cap, int cost)
	{
		g[src].push_back(Edge(dst, cap, cost, g[dst].size()));
		g[dst].push_back(Edge(src, 0, -cost, g[src].size() - 1));
	}
	
	int solve(int s, int t, int f)
	{	
		std::vector<int> dist(g.size()), prevv(g.size()), preve(g.size());
		
		int res = 0;
		
		while (f > 0){
			std::fill_n(dist.begin(), dist.size(), INF);
			dist[s] = 0;
			
			bool update = true;
			while (update){
				update = false;
				for (int v = 0; v < g.size(); v++){
					if (dist[v] == INF) continue;
					for (int i = 0; i < g[v].size(); i++){
						Edge &e = g[v][i];
						if (e.cap > 0 && dist[e.dst] > dist[v] + e.cost){
							dist[e.dst] = dist[v] + e.cost;
							prevv[e.dst] = v;
							preve[e.dst] = i;
							update = true;
						}
					}
				}
			}
			if (dist[t] == INF) return INF;
			int d = f;
			for (int v = t; v != s; v = prevv[v]){
				d = std::min(d, g[prevv[v]][preve[v]].cap);
			}
			f -= d;
			res += d * dist[t];
			for (int v = t; v != s; v = prevv[v]){
				Edge &e = g[prevv[v]][preve[v]];
				e.cap -= d;
				g[v][e.rev].cap += d;
			}
		}
		return res;
	}
	
private:
	Graph g;
};
}

#include <bits/stdc++.h>
using namespace std;

#define BIT(x) (1 << (x))

int n, m, b;
int ax[100], ay[100];
int bx[5], by[5], c[5], f[5];

long long calc(int bit, int d)
{
	long long resB = 0;
	for (int i = 0; i < m; i++){
		if (bit & BIT(i)){
			resB += f[i];
			resB += d * b;
		}
	}
	
	MinCostFlow flow(n + m + 2);
	// [0, N) : ????¨?????????¶
	// [N, N + M) : ?????´
	// [N + M] : ?§????
	// [N + M + 1] : ??????
	
	int S = n + m, T = n + m + 1;
	
	// N ???????????????????????¶???????????????
	for (int i = 0; i < n; i++){
		flow.addEdge(S, i, 1, 0);
	}
	
	// ?????¶????????????????????§?????????????????¨????±???????
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			if ((~bit) & BIT(j)) continue;
			int dist = max(0, abs(ax[i] - bx[j]) + abs(ay[i] - by[j]) - d);
			flow.addEdge(i, n + j, 1, dist);
		}
	}
	
	// ?????´ m ??? c[m] ???????????\??????
	for (int i = 0; i < m; i++){
		if (bit & BIT(i)) flow.addEdge(n + i, T, c[i], 0);
	}
	
	return resB + flow.solve(S, T, n);
}

int main()
{
	while (scanf("%d %d %d", &n, &m, &b), n){
		for (int i = 0; i < n; i++){
			scanf("%d %d", ax + i, ay + i);
		}
		for (int i = 0; i < m; i++){
			scanf("%d %d %d %d", bx + i, by + i, c + i, f + i);
		}
		
		long long res = 1ll << 50;
		for(int bit = 1; bit < BIT(m); bit++){
			int left = -1, right = 4010;
			while (left + 1 < right){
				int mid = (left + right) / 2;
				long long r1 = calc(bit, mid);
				long long r2 = calc(bit, mid + 1);
				long long df = r2 - r1;
				if (df >= 0) right = mid;
				else left = mid;
			}
			res = min(res, calc(bit, right));
		}
		
		printf("%lld\n", res);
	}
}

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

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v;
	stringstream ss(s);
	string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}

#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }

void err(vector<string>::iterator it) {}

template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> inline T tabs(T a) { return (a > 0) ? a : -a; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

const ll MX = 1000000001;
typedef pair<int, int> P;
vector<P> pts;

#define X first
#define Y second

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

	int h, w, n;

	map<ll, int> vis, mp;

	cin >> h >> w >> n;
	pts.resize(n);
	REPU(i, 0, n) {
		cin >> pts[i].X >> pts[i].Y;
		ll id = MX * pts[i].X + pts[i].Y;
		vis[id] = 1;
	}
	vector<ll> ans(10, 0);
	REPU(i, 0, n) {
		REPU(dx, 0, 3) REPU(dy, 0, 3) {
			int nx = pts[i].X + dx, ny = pts[i].Y + dy;
			if (nx < 1 || nx > h || ny < 1 || ny > w) continue;
			ll id = MX * nx + ny;
			if (nx < 3 || ny < 3 || mp.count(id) > 0) continue;
			mp[id] = 1;
			int cnt = 0;
			REPU(_x, -2, 1) REPU(_y, -2, 1) {
				int mx = nx + _x, my = ny + _y;
				ll nid = MX * mx + my;
				if (vis.count(nid) > 0) cnt++;
			}
			ans[cnt]++;
		}
	}
	ans[0] = (h - 2) * 1LL * (w - 2) - accumulate(ans.begin() + 1, ans.end(), 0LL);
	REPU(i, 0, 10) printf("%lld\n", ans[i]);

	return 0;
}


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

int main(){
    using namespace std;
    size_t N;
    cin >> N;
    unordered_map<unsigned long, size_t> mp;
    for(unsigned long i = 0, a; i < N; ++i){
        cin >> a;
        ++mp[a];
    }
    if(mp.size() > 3)return 0 & puts("No");
    if(mp.size() == 1)return 0 & puts(mp[0] == N ? "Yes" : "No");
    if(mp.size() == 2)return 0 & puts(mp[0] * 3 == N ? "Yes" : "No");
    if(mp.size() == 3){
        vector<unsigned long> a;
        for(const auto& i : mp){
            if(i.second * 3 != N)return 0 & puts("No");
            a.push_back(i.first);
        }
        puts(a[0] ^ a[1] ^ a[2] ? "No" : "Yes");
    }
    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include<functional>
#include<queue>
#include<regex>
#include<time.h>

using namespace std;


#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl

#define Tof(x) (x) ? Yes : No
#define TOF(x) (x) ? YES : NO
#define tof(x) (x) ? yes : no

using ll = long long;

constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;


/*vectorの要素を全部確認するやつだよ。普通に拡張for文したほうがいいよ。

for (vector<int>::iterator itr = ans.begin(); itr != ans.end(); ++itr) {
	cout << *itr << " ";
}

*/


/*for文でx,yを上下左右確認するやつだよ。正直使いづらいよ。

int dy[] = { 0, 1, 0, -1 };
int dx[] = { 1, 0, -1, 0 };


for (int i = 0; i < 4; i++) {
	int ny = y + dy[i];
	int nx = x + dx[i];
}

*/


/*繰り返し二乗法だよ。modもとってくれるよ。n^kをmodで割った余りでやってくれるよ。

ll POW_MOD(ll n, ll k, ll mod) {
	ll r = 1;

	for (; k > 0; k >>= 1) {
		if (k & 1) {
			r = (r * n) % mod;
		}
		n = (n * n) % mod;
	}
	return r;
}

*/




/*2重for文書くのめんどくなった時用だよ。

for (int i = 0; i < h; ++i) {
	for (int j = 0; j < w; ++j) {

	}
}

*/


int main() {
	
	while (1) {
		string s, t; cin >> s;
		if (s == ".") { return 0; }
		cin >> t;

		if (s == t) {
			cout << "IDENTICAL" << endl;
			continue;
		}

		auto split = [](string s, char c) {//かっこつけてラムダ式書いた
			vector<string> ans;
			int x, count = 0;
			while ((x = s.find(c)) != s.npos) {
				ans.push_back(s.substr(0, x));
				s = s.substr(x + 1);
			}
			if (s.size()) ans.push_back(s);
			return ans;
		};

		vector<string> ss = split(s, '"');
		vector<string> st = split(t, '"');

		if (ss.size() == st.size()) {
			int even = 0, odd = 0;//偶奇判断

			for (int i = 0; i < ss.size(); i++) {
				if (ss[i] != st[i]) {
					if (i & 1) { odd++; }
					else { even++; }
				}
			}
			if (odd == 1 && even == 0) {
				cout << "CLOSE" << endl;
				continue;
			}
		}
		cout << "DIFFERENT" << endl;
	}

	return 0;
}




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

using namespace std;

int main()
{
    int n;
    
    scanf("%d", &n);
    
    while (n--){
        char s[128], tmp[128];
        string t;
        scanf("%s", s);
        scanf("%s", tmp);
        
        t = (string)tmp;
        
        for (int i = strlen(s) - 1; i >= 0; i--){
            if (s[i] ==  'J')
                t = t[t.size() - 1] + t.substr(0, t.size() - 1);
            else if (s[i] == 'C')
                t = t.substr(1, t.size() - 1) + t[0];
            else if (s[i] == 'E'){
                string t1 = t.substr(0, t.size() / 2), t2 = t.substr((t.size() + 1) / 2, t.size() / 2);
                string e = "";
                t = t2 + ((t.size() & 1) ? string(1, t[t.size() / 2]) : e) + t1;
            }
            else if (s[i] == 'A')
                reverse(t.begin(), t.end());
            else if (s[i] ==  'P'){
                for (int j = 0; j < t.size(); j++){
                    if (isdigit(t[j])){
                        if (t[j] == '0') t[j] = '9';
                        else t[j]--;
                    }
                }
            }
            else {
                for (int j = 0; j < t.size(); j++){
                    if (isdigit(t[j])){
                        if (t[j] == '9') t[j] = '0';
                        else t[j]++;
                    }
                }
            }
        }
        printf("%s\n", t.c_str());
    }
    
    return (0);
}

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

using namespace std;

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

  int n, k, x;
  cin >> n >> k;
  int res = 0;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    res += min(k-x, x);
  }
  cout << 2*res << endl;

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll x, n; cin >> x >> n;
    set<ll> allow;

    for(ll i=-1; i<=101; i++) allow.insert(i);
    rep(i, n){
        ll tmp; cin >> tmp;
        allow.erase(tmp);
    }

    ll ans = -1;
    ll min_v = INFLL;

    for(auto c: allow){
        if(abs(x-c) < min_v){
            min_v = abs(x-c);
            ans = c;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3616
from random import *
D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(D)]
X=[0]*26
XX=X[:]
Y=X[:]
YY=X[:]
P=[]
SC=0
N,M,L,O=0,0,0,0
for i in range(D):
  for j in range(26):
    X[j]+=C[j]
    XX[j]+=X[j]
  N,M=-1,-10**20
  L,O=N,M
  for j in range(26):
    if Y==-1:
      N,M=0,X[0]+S[i][0]
    if M<X[j]+S[i][j]:
      L,O=N,M
      N,M=j,X[j]+S[i][j]
    elif O<X[j]+S[i][j]:
      L,O=j,X[j]+S[i][j]
  XX[N]-=X[N]
  X[N]=0
  P.append([N,L])
  SC+=X[N]
SC2=0
for i in range(10**5):
  SC2=SC
  d,q=randrange(0,D),randrange(0,26)
  SC2-=S[d][P[d][0]]
  SC2+=S[d][q]
  for j in range(26):
    Y[j]=0
  YY[P[d][0]],YY[q]=0,0
  for j in range(D):
    if j==d:
      Z=q
    else:
      Z=P[j][0]
    Y[P[d][0]]+=C[P[d][0]]
    Y[q]+=C[q]
    Y[Z]=0
    YY[P[d][0]]+=Y[P[d][0]]
    YY[q]+=Y[q]
  if SC2-sum(YY)>=SC-sum(XX):
    P[d][0]=q
    XX=YY[:]
    SC=SC2
  elif randrange(0,10000)==0:
    if randrange(0,2):
      P[d][0]=q
      XX=YY[:]
      SC=SC2
    else:
      P[d][1]=q
for d in range(D):
  for q in range(26):
    SC2=SC
    SC2-=S[d][P[d][0]]
    SC2+=S[d][q]
    for j in range(26):
      Y[j]=0
    YY[P[d][0]],YY[q]=0,0
    for j in range(D):
      if j==d:
        Z=q
      else:
        Z=P[j][0]
      Y[P[d][0]]+=C[P[d][0]]
      Y[q]+=C[q]
      Y[Z]=0
      YY[P[d][0]]+=Y[P[d][0]]
      YY[q]+=Y[q]
    if SC2-sum(YY)>=SC-sum(XX):
      P[d][0]=q
      XX=YY[:]
      SC=SC2
for i in range(10**5):
  SC2=SC
  d,q=randrange(0,D),randrange(0,26)
  SC2-=S[d][P[d][0]]
  SC2+=S[d][q]
  for j in range(26):
    Y[j]=0
  YY[P[d][0]],YY[q]=0,0
  for j in range(D):
    if j==d:
      Z=q
    else:
      Z=P[j][0]
    Y[P[d][0]]+=C[P[d][0]]
    Y[q]+=C[q]
    Y[Z]=0
    YY[P[d][0]]+=Y[P[d][0]]
    YY[q]+=Y[q]
  if SC2-sum(YY)>=SC-sum(XX):
    P[d][0]=q
    XX=YY[:]
    SC=SC2
  elif randrange(0,10000)==0:
    if randrange(0,2):
      P[d][0]=q
      XX=YY[:]
      SC=SC2
    else:
      P[d][1]=q
for d in range(D):
  for q in range(26):
    SC2=SC
    SC2-=S[d][P[d][0]]
    SC2+=S[d][q]
    for j in range(26):
      Y[j]=0
    YY[P[d][0]],YY[q]=0,0
    for j in range(D):
      if j==d:
        Z=q
      else:
        Z=P[j][0]
      Y[P[d][0]]+=C[P[d][0]]
      Y[q]+=C[q]
      Y[Z]=0
      YY[P[d][0]]+=Y[P[d][0]]
      YY[q]+=Y[q]
    if SC2-sum(YY)>=SC-sum(XX):
      P[d][0]=q
      XX=YY[:]
      SC=SC2
for i in range(D):
  SC2=SC
  d,q=i,P[i][1]
  SC2-=S[d][P[d][0]]
  SC2+=S[d][q]
  for j in range(26):
    Y[j]=0
  YY[P[d][0]],YY[q]=0,0
  for j in range(D):
    if j==d:
      Z=q
    else:
      Z=P[j][0]
    Y[P[d][0]]+=C[P[d][0]]
    Y[q]+=C[q]
    Y[Z]=0
    YY[P[d][0]]+=Y[P[d][0]]
    YY[q]+=Y[q]
  if SC2-sum(YY)>=SC-sum(XX):
    P[d]=P[d][::-1]
    XX=YY[:]
    SC=SC2
for i in range(D):
  print(P[i][0]+1)


Measured memory_bytes: 87984
// Problem : A - Serval vs Monster
// Contest : AtCoder Beginner Contest 153
// URL : https://atcoder.jp/contests/abc153/tasks/abc153_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

#include<bits/stdc++.h>
using namespace std;
int main()
{
        int n,a;
        cin >> n >> a;
        cout << (n%a==0 ? n/a : n/a+1) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#define N 65000
using namespace std;
typedef long long ll;

int main(){
  ll n,p,j[N],ans,cal;
  while(1){
    cin>>n;
    if(!n) break;
    cal=0;
    for(int i=0;i<n;i++) cin>>p,cal+=p;
    for(int i=0;i<n-1;i++) cin>>j[i],cal+=j[i];
    sort(j,j+n-1);
    ans=cal;
    for(int i=0;i<n-1;i++) cal-=j[i],ans=max(ans,cal*(i+2));
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1676
# D - Div Game
from collections import defaultdict
from math import sqrt
from typing import ValuesView


def prime_factorize_indices(n: int) -> ValuesView[int]:
    """Prime factorization of n (trial division)."""
    if n < 1:
        raise ValueError

    prime_factors = defaultdict(int)
    while n % 2 == 0:
        n //= 2
        prime_factors[2] += 1

    for i in range(3, int(sqrt(n)) + 1, 2):
        while n % i == 0:
            n //= i
            prime_factors[i] += 1
        if n == 1:
            break

    if n > 2:  # n is prime
        prime_factors[n] += 1

    return prime_factors.values()


def main():
    N = int(input())
    calc = lambda n: (sqrt(8 * n + 1) - 1) // 2
    print(int(sum(calc(e) for e in prime_factorize_indices(N))))


if __name__ == "__main__":
    main()


Measured memory_bytes: 10344
S = input()
mod = 10 ** 9 + 7
abc = 0
bc = 0
c = 0
q = 0

for i in S[::-1]:
    if i == 'A':
        abc = (bc + abc) % mod
        
    if i == 'B':
        bc = (c + bc) % mod
        
    if i == 'C':
        c = (pow(3, q, mod) + c) % mod
        
    if i == '?':
        abc = (bc + abc * 3) % mod
        bc = (c + bc * 3) % mod
        c = (pow(3, q, mod) + c * 3) % mod
        q += 1
        
print(abc)

Measured memory_bytes: 3188
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF (1 << 30) - 1
#define LLINF (1LL << 61) - 1
// #define int ll
using namespace std;
const int MOD = 1000000007;
const int MAX = 510000;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h,w,cnt1=0,cnt2=0,cnt4=0;
    cin>>h>>w;
    map<ll,ll> mp;
    rep(i,h){
        string s;
        cin>>s;
        rep(i,w){
            mp[s[i]-'a']++;
        }
    }
    if(h%2==0 && w%2==0){
        cnt4=h*w/4;
        rep(i,26){
            cnt4-=mp[i]/4;
            mp[i]%=4;
            cnt2-=mp[i]/2;
            cnt1-=mp[i]%2;
        }
    }
    else if(h%2==1 && w%2==1){
        cnt4=(h/2)*(w/2);
        cnt2=h/2+w/2;
        cnt1=1;
        rep(i,26){
            cnt4-=mp[i]/4;
            mp[i]%=4;
            cnt2-=mp[i]/2;
            cnt1-=mp[i]%2;
        }
    }
    else{
        if(h%2==1){
            swap(h,w);
        }
        cnt4=(h/2)*(w/2);
        cnt2=h/2;
        rep(i,26){
            cnt4-=mp[i]/4;
            mp[i]%=4;
            cnt2-=mp[i]/2;
            cnt1-=mp[i]%2;
        }
    }
    if(cnt4<=0 && cnt4*4+cnt2*2==0 && cnt1==0){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = input()

digit = len(n)
num = int(n)

min = 0
if digit == 3:
  min = int(n[0] + '00')
elif digit == 4:
  min = int(n[0] + n[1] + '00')
elif digit == 5:
  min = int(n[0] + n[1] + n[2] + '00')
elif digit == 6:
  min = int(n[0] + n[1] + n[2] + n[3] + '00')
else:
  min = 9999999999
  
max = min * 1.05
if num >= min and num <= max:
  print(1)
else:
  print(0)

Measured memory_bytes: 3064
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    K = int(readline())
    X = int(readline())
    Y = int(readline())
    if N <= K:
        ans = X * N
    else:
        ans = X * K + Y * (N - K)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9208
INF = 10 ** 10
N, M, P = map(int, input().split())
edge = []
for i in range(M):
    a, b, c = map(int, input().split())
    edge.append((a - 1, b - 1, c - P))

d = [-INF] * N
d[0] = 0

for i in range(N - 1):
    for a, b, c in edge:
        if d[a] != -INF and d[b] < d[a] + c:
            d[b] = d[a] + c

ans = d[-1]

for i in range(N - 1):
    for a, b, c in edge:
        if d[a] != -INF and d[b] < d[a] + c:
            d[b] = INF

if ans != d[-1]:
    print(-1)
else:
    print(max(0, d[N - 1]))


Measured memory_bytes: 50540
template<class T> inline void chmin(T & a, T b) { if (a > b) a = b; }

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

void solve() {
	llong N, K; cin >> N >> K; // 木の本数と電飾の数
	vector<llong> h(N); // 木の高さ
	rep(i, N) scanf("%lld", &h[i]);

	sort(h.begin(), h.end()); // 昇順

	llong res = (1LL << 60); // 疑似INF
	for (int i = 0; i + K - 1 < N; i++) chmin(res, h[i + K - 1] - h[i]);
	cout << res << endl;
}

int main(void) {
	solve();

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
using namespace std;
//using namespace __gnu_pbds;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long 
#define rep(i,n) for(int i=0;i<n;i++)
#define repa(i,arr,n) for(int i=arr;i<=n;i++)
#define repd(i,arr,n) for(int i=arr;i>=n;i--)
#define trav(arr,x) for(auto& arr:x)
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(arr) arr.size()
#define pi 3.14159265358979323846
#define MAX 500003
#define vi vector<int>
#define pii pair<int,int>
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int,vi,greater<int> >
//#define endl "\n"
 
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
const int mod=998244353;
int power(int a,int b)
{
    int ans=1;
    while(b)
    {
        if(b&1)
        {
            ans=(ans*a);
        }
        a=(a*a);
        b>>=1;
    }
    return ans;
}

int32_t main()
{
    fast;
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        int n,val;
        cin>>n;
        map<int,int> mpp;
        repa(i,1,100)
        {
            repa(j,1,100)
            {
                repa(k,1,100)
                {
                    val=i*i+j*j+k*k;
                    val+=(i*k+k*j+i*j);

                    mpp[val]++;
                }
            }
        }

        repa(i,1,n)
        {
            cout<<mpp[i]<<endl;
        }
    }
}   


Measured memory_bytes: 6108
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>
#include<cmath>
#include<string>
#include<cstring>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define prin(arg) std::cout<<arg<<"\n"
#define prin2(arg1,arg2) std::cout<<arg1<<" "<<arg2<<"\n"
#define fill(arg,n) memset(arg,n,sizeof(arg))
using std::cin;
typedef long long ll;
typedef std::pair<int,int> pi;
typedef std::vector<int> vi;
const int INF=1e+9;
const ll INFLL=1e+17;
std::string S;
bool f[26];
void solve(){
  fill(f,0);
  std::string res;
  int ss=S.size();
  rep(i,ss){
    f[(int)(S[i]-'a')]=true;
  }
  if(ss!=26){
    rep(i,26){
      if(!f[i]){
	res=S+(char)('a'+i);
	prin(res);
	return ;
      }
    }
  }
  char max=S[ss-1];
  std::vector<char> v;
  v.push_back(max);
  rep(i,ss-1){
    char c=S[ss-2-i];
    if(c<max){
      std::sort(v.begin(),v.end());
      rep(j,v.size()){
	if(c<v[j]){
	  S[ss-2-i]=v[j];
	  res=S.substr(0,ss-1-i);
	  prin(res);
	  return ;
	}
      }
    }
    else{
      max=c;
      v.push_back(c);
    }
  }
  prin(-1);
  return ;
}
int main(){
  cin>>S;
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <stdint.h>
#include <set>

using namespace std;

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

  //multiset<uint64_t> nums = {1,0,0};
  uint64_t nums[3] = {0,0,0};

  uint64_t count = 1;
  
  for (uint64_t n=0; n<N; ++n) {
    uint64_t a;
    cin >> a;

    // if (n==0)
    //   continue;

    uint cnt = 0;
    int id = -1;
    for (int ii=0; ii<3; ++ii) {
      if (nums[ii]==a) {
	++cnt;
	id = ii;
      }
    }
    
    count *= cnt;//nums.count(a);

    // for (auto n : nums)
    //   cerr << n << ' ';
    // cerr << endl;
    // cerr << nums.count(a) << ' ' << count << endl;
    
    if (count == 0)
      break;
    
    if (count >= 1000000007)
      count %= 1000000007;
    
    // for (auto it=nums.begin(); it!=nums.end(); ++it) {
    //   if (*it==a) {
    // 	nums.erase(it);
    // 	break;
    //   }
    // }
    // nums.insert(a+1);
    nums[id]++;
  }
  
  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;

int main()
{
    int n, ws;
    cin >> n >> ws;
    int w[102];
    ll v[102];
    for(int i = 0; i < n; i++){
        cin >> w[i] >> v[i];
    }
    ll dp[100002] {0};
    for(int i = 0; i < n; i++){
        for(int j = ws; j >= w[i]; j--){
            dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
        }
    }
    cout << dp[ws] << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int ans;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int d[10001];
    for(int i=1;i<=a;++i){
    cin>>d[i];
    if(d[i]<b||d[i]>=c){
        ans++;
    }
}
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque
from collections import  Counter
import statistics
import math
stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

a, b = na()
li = [1]
d = b - a
for i in range(2, 1000):
    li.append(li[-1] +i)
print(li[d-2] - a)

Measured memory_bytes: 5140
#include <bits/stdc++.h>
#define int long long 
#define uint unsigned long long 
#define double long double 
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define sz(a) (int)(a).size()
#define hell 1000000007
#define vi vector<int> 
#define vb vector<bool> 
#define vpi vector<pair<int,int>> 
#define x first 
#define y second 
#define endl '\n'

using namespace std;


void solve(){
	int n;
	cin >> n;
	int ans = -1;
	int root = sqrt(n)+1;
	for(int i = root ; i>=1 ; i--){
		if(n%i==0){
			ans = i + (n/i)-2;
			break;
		}
	}
	
	cout << ans << endl;
}

int32_t main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(10);

	int t = 1;
	//cin >> t ;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define ll long long
#define ld long double
#define sz(a) ((int)(a).size())
#define clr(a,v) memset(a, v, sizeof(a))
#define all(a) (a).begin(),(a).end()
#define pii pair<int,int>
#define pdd pair<ld,ld> 
#define rep(i,a,b) for(int i=a; i<b; i++)
#define dec(i,a,b) for(int i=a; i>=b; i--)
#define ler freopen("inspection.in","r",stdin);freopen("inspection.out","w",stdout)
#define fastio ios::sync_with_stdio(0), cin.tie(0)
#define debug cout<<"!!?!!\n"
using namespace std;
#define MAXN 600005
#define maxn 200005
#define INF 2000000000000000000LL
#define inf 1000010000
#define int ll
class cart_tree {
	typedef struct _Node {
		ll x, y, cnt;
		_Node *l, *r;

		_Node(int _x) : x(_x), y((rand() << 16) ^ rand()), cnt(1), l(NULL), r(NULL) {}
		~_Node() { delete l; delete r; }
		void recalc() {
			cnt = 1;
			if (l) cnt += l->cnt;
			if (r) cnt += r->cnt;
		}
	} *Node;

	Node merge(Node l, Node r){
		if (!l || !r) return l ? l : r;
		if (l->y < r->y){
			l->r = merge(l->r, r);
			l->recalc();
			return l;
		}else{
			r->l = merge(l, r->l);
			r->recalc();
			return r;
		}
	}

	void split(Node v, int x, Node &l, Node &r){
		l = r = NULL;
		if (!v) return;
		if (v->x < x) {
			split(v->r, x, v->r, r);
			l = v;
		} else {
			split(v->l, x, l, v->l);
			r = v;
		}
		v->recalc();
	}
	int menos(Node v, int x){
		if(!v) return 0;
		if(v->x >= x) return menos(v->l,x);
		return (v->l?v->l->cnt:0) + 1 + menos(v->r,x);
	}
	int mais(Node v, int x){
		if(!v) return 0;
		if(v->x <= x) return mais(v->r,x);
		return (v->r?v->r->cnt:0) + 1 + mais(v->l,x);
	}
	int position(Node v, int q, int pos){
		if(v->l) q+= v->l->cnt;
		if(q==pos) return v->x;
		if(q<pos) return position(v->r,q+1,pos);
		return position(v->l, q-v->l->cnt,pos);
	}
	
	Node root;
	public:
	cart_tree() : root(NULL) {}
	~cart_tree() { delete root; }
	void insert(int x) {
		Node l, r;
		split(root, x, l, r);
		root = merge(merge(l, new _Node(x)), r);
	}
	void erase(int x) { //remove todos os x, (para remover apenas 1, modificar)
		Node l, m, r;
		split(root, x, l, m);
		split(m, x + 1, m, r);
		assert(m && m->cnt == 1 && m->x == x);
		delete m;
		root = merge(l, r);
	}
	int menor(int x){ return menos(root,x);}
	int maior(int x){ return mais(root,x);}
	int igual(int x){ return size() - maior(x) - menor(x);}
	int size() const { return root ? root->cnt : 0; }
	int pos(int x){ return (x>size()?-1:position(root, 1, x));}
};

ll n, v[MAXN], k;
cart_tree T;

 main(){
	cin >> n >> k;
	rep(i,0,n){
		cin >> v[i];
		v[i]-=k;
		if(i>0) v[i]+=v[i-1];
	}
	ll ans=0;
	
	T.insert(0);

	rep(i,0,n){
		ll x= v[i];
		ans+= T.menor(x+1);
		T.insert(x);
	}
	cout << ans << endl;
}







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

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

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

  ll ans = n-1;
  rep(i, sqrt(n)){
    if(n % (i+1) == 0){
      ll j = n / (i+1) - 1;
      if(i + j < ans) ans = i + j;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define RFOR(i, m, n) for (ll i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
//#define print(ele) cout << (ele) << "\n"
#define print10(ele) cout << fixed << setprecision(10) << (ele) << "\n"

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) != 0) cout << " ";
  print(forward<Tail>(tail)...);
}

int main() {
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  double l = h * 30 + m * 0.5;
  double s = m * 6;

  double d = min(abs(l - s), abs(s - l));
  double rad = d * M_PI / 180;
  double ans = sqrt(b * b + a * a - 2 * a * b * cos(rad));
  print10(ans);
  return 0;
}

Measured memory_bytes: 4196
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		char[] S = sc.next().toCharArray();

		int current = 0;

		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < S.length; i++) {
			if (S[i] == '(') {
				current++;
			} else {
				current--;
				if (current < 0) {
					sb.insert(0, '(');
					current = 0;
				}
			}
			sb.append(S[i]);
		}

		for (int i = 0; i < current; i++) {
			sb.append(')');
		}

		System.out.println(sb.toString());
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	public static class Scanner {
		private BufferedInputStream inputStream;

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;

			int read = skip();
			do {
				num = num * 10 + (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			StringBuilder builder = new StringBuilder();

			int read = skip();
			do {
				builder.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			return builder.toString();
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}

Measured memory_bytes: 21204
import java.util.BitSet;
import java.util.NoSuchElementException;
import java.util.PrimitiveIterator.OfInt;
import java.util.Scanner;
import java.util.TreeSet;
import java.util.stream.IntStream;

public class Main{
	static Scanner s=new Scanner(System.in);
	public static void main(String[] __){
		TreeSet<Integer> set=new TreeSet<>();
		new PrimeIterator(1000000).forEach(set::add);
		while(true){
			int a=s.nextInt(),d=s.nextInt(),n=s.nextInt();
			if(a+d+n==0) return;
			System.out.println(IntStream.iterate(a,i->i+d).filter(set::contains).skip(n-1).findFirst().getAsInt());
		}
	}
}
class PrimeIterator implements Iterable<Integer>,OfInt{
	private BitSet	bs;
	private int		next,lim;
	public PrimeIterator(int limit){
		lim=limit;
		bs=new BitSet(lim+1);
		next=lim<2?-1:2;
	}
	@Override
	public boolean hasNext(){
		return next>0;
	}
	@Override
	public int nextInt(){
		if(!hasNext()) throw new NoSuchElementException();
		int r=next;
		if(1L*r*r<=lim)
			IntStream.iterate(r*r,i->i+r).limit(lim/r-r+1).forEach(bs::set);
		if((next=bs.nextClearBit(r+1))>lim) next=-1;
		return r;
	}
	@Override
	public OfInt iterator(){
		return this;
	}
}

Measured memory_bytes: 42644
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	var number int
	if scanner.Scan() {
		number, _ = strconv.Atoi(scanner.Text())
	}
	var numbers = make([]string, number)
	if scanner.Scan() {
		numbers = strings.Split(scanner.Text(), " ")
	}

	var evens = make([]int, 0)
	for _, num := range (numbers) {
		intnum, _ := strconv.Atoi(num)
		if intnum%2 == 0 {
			evens = append(evens, intnum)
		}
	}

	for _, even := range (evens) {
		if even % 5 == 0 || even % 3 ==0{
			continue
		} else {
			fmt.Println("DENIED")
			os.Exit(0)
		}
	}
	fmt.Println("APPROVED")
}


Measured memory_bytes: 640
function Main(arg)
{
  var a = `1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
`.split(", ");
  var N = arg.split("\n")[0]-0;


  console.log(a[N-1]);
  return;
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include<stdio.h>
int min(int a, int b)
{
    if (a < b)
        return a;
    else
        return b;
}
int main()
{
    int a, b, c, x, y;
    scanf("%d %d %d %d %d", &a, &b, &c, &x, &y);
    int ans[3];
    ans[0] = (x*a) + (y*b);
    ans[1] = 2 * x*c;
    if (x < y)
        ans[1] += (b*(y - x));
    ans[2] = 2 * y*c;
    if (y < x)
        ans[2] += (a*(x - y));
    printf("%d\n", min(min(ans[0], ans[1]), ans[2]));
    return 0;
}

Measured memory_bytes: 128