akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int n,k;cin >> n >> k;
    int a[n];
    rep(i,n)cin >> a[i];
    int ans = 0;
    rep(i,n){
        ans += 2*min(k-a[i],a[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3676
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
h = list(map(int, input().split()))

dp = [0]*n
for i in range(1,n):
    dp[i] = dp[i-1] + abs(h[i]-h[i-1])
    if i>=2:
        dp[i] = min(dp[i], dp[i-2]+abs(h[i]-h[i-2]))
print(dp[-1])

Measured memory_bytes: 84812
a, b = map(int, input().split())

import fractions
c = fractions.gcd(a, b)

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
print(len(set(prime_factorize(c))) + 1)


Measured memory_bytes: 5304
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<utility>
#include<string.h>
#include<queue>
#include<stack>
using namespace std;

typedef long long ll; 
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(void)
{
    long long int n,m,d;
    scanf("%lld %lld %lld",&n,&m,&d);
    long long int a;
    if(d==0)
    {
        double ans=(double)(m-1)/(double)n;
        printf("%.10f\n",ans);
        return 0;
    }
    else a=2*(n-d);
    double ans=(double)(m-1)*a/(double)(n*n);
    printf("%.10f\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
using namespace std;
#define MAXN 100005
int Set[MAXN];
int Root(int x)
{return Set[x]==x?x:Set[x]=Root(Set[x]);}
int N,Q;
int fa[MAXN];
int Que[MAXN][2];
int marked[MAXN];
int main()
{
	char op[3];
	int id;
	long long ans;
	while(~scanf("%d%d",&N,&Q)&&N&&Q)
	{
		memset(Que,0,sizeof Que);
		memset(fa,0,sizeof fa);
		memset(Set,0,sizeof Set);
		memset(marked,0,sizeof marked);
		ans=0;
		Set[1]=1;fa[1]=1;
		for(int i=2;i<=N;i++)
		{
			scanf("%d",fa+i);
			Set[i]=fa[i];
		}
		for(int i=1;i<=Q;i++)
		{
			scanf("%s%d",op,&id);
			if(op[0]=='Q')Que[i][0]=1;
			else {Que[i][0]=2;Set[id]=id;marked[id]++;}
			Que[i][1]=id;
		}
		for(int i=Q;i>=1;i--)
		{
			if(Que[i][0]==1)
				ans+=1LL*Root(Que[i][1]);
			else
			{
				marked[Que[i][1]]--;
				if(!marked[Que[i][1]])
					Set[Que[i][1]]=fa[Que[i][1]];
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 4840
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)

int N;
vector<int>A;

int check(int k){
	stack<pair<int, int>>st;
	for (int i = 0; i < N - 1; i++) {
		if (A[i] >= A[i + 1]) {
			while (st.size() && st.top().first > A[i + 1])st.pop();
			if (st.size() && st.top().first == A[i + 1]) {
				st.top().second++;
			}
			else {
				st.push({ A[i + 1],1 });
			}

			while (st.top().second == k) {
				int d = st.top().first;
				if (d == 1)return 0;
				st.pop();
				if (st.size() && st.top().first == d - 1) {
					st.top().second++;
				}
				else {
					st.push({d-1,1});
				}
			}
		}
	}
	return 1;
}

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

	cin >> N;
	A.resize(N);
	for (int i = 0; i < N; i++)cin >> A[i];

	int f = 1;
	for (int i = 1; i < N; i++)if (A[i] <= A[i - 1])f = 0;
	if (f) {
		puts(1);
		return 0;
	}

	int ng = 1, ok = N;
	while (ok - ng > 1) {
		int mid = (ok + ng) / 2;
		(check(mid) ? ok : ng) = mid;
	}
	puts(ok);

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;
#include <string>
typedef long long int ll;

int main(){
  int N;
  cin >> N;
  int d[N];
  for(int i=0;i<N;i++){
    scanf("%d", &d[i]);
  }

  int sum=0;

  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
      sum += d[i]*d[j];
    }
  }

  cout << sum;


  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String n = scan.next();
		int[] x = new int[1000002];
		String[] sliced = n.split("");
		int digits = 0;
		for(int i = sliced.length - 1; i >= 0; i--) {
			x[digits++] = Integer.parseInt(sliced[i]);
		}
		x[digits] = 0;
		long output = 0;
		for(int i = 0; i < digits + 1; i++) {
			if(x[i] < 5) {
				output += x[i];
			} else if( x[i] == 5) {
				if(x[i+1] < 5) {
					output += x[i];
				} else {
					output += 10 - x[i];
					x[i+1]++;
				}
			} else {
				output += 10 - x[i];
				x[i+1]++;
			}
		}
		System.out.println(output);
		scan.close();
	}

}

Measured memory_bytes: 117740
n,m = map(int,input().split()) #ｎは展望台の数、ｍは展望台を結ぶ道の数
c = [[] for _ in range(n)] #結ばれている展望台を格納する
h = [int(i) for i in input().split()] #展望台の高さ
for i in range(m):
    a,b = map(int,input().split())
    c[a-1].append(b)
    c[b-1].append(a)

count = 0
for i,j in enumerate(c): #iがメインの展望台でｊがつながっている展望台を格納されている
    flag = True
    for l in j:
        if h[i]<=h[l-1]:
            flag = False
            continue
    if flag:
        count += 1
print(count)

Measured memory_bytes: 90952
#include<cstdio>
#include<vector>
using namespace std;
int n;
int main()
{
	scanf("%d", &n);
	int x = (n & 1) ? n : (n + 1);
	vector<pair<int, int>> edges;
	for (int i = 1; i <= n; i++)
	{
		for (int j = i + 1; j <= n; j++)
		{
			if (i + j != x)
			{
				edges.push_back(make_pair(i, j));
			}
		}
	}
	printf("%d\n", edges.size());
	for (auto& p : edges) printf("%d %d\n", p.first, p.second);
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
typedef long long ll;
using namespace std;
ll T[110],P[110], X[110];
int main()
{
	int n,m,i,j;
	ll tsum = 0;
	cin >> n;
	for(i=1;i<=n;i++){
		cin >> T[i];
		tsum+=T[i];
	}
	cin >> m;
	for(i=1;i<=m;i++){
		cin >> P[i] >> X[i];
		cout << tsum - T[P[i]] + X[i] << endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll a, b;
  cin >> a >> b;
  if (a <= b)
    cout << a << endl;
  else
    cout << a - 1 << endl;
  return 0;
}

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

int main() {
    string s,t;
    cin>>s>>t;
    int n=s.length();
    int m=t.length();
    int dp[n+1][m+1];
    for(int i=0;i<=m;i++){
        dp[0][i]=0;
    }
    for(int i=0;i<=n;i++){
        dp[i][0]=0;
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(s[i-1]==t[j-1]){
                dp[i][j]=1+dp[i-1][j-1];   
            }
            else{
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    int i=n;
    int j=m;
    string ans="";
    int len=dp[n][m];
    while(len>0){
        if(s[i-1]==t[j-1]){
        	ans=s[i-1]+ans;
            i--;
            j--;
            len--;
        }
        else{
        if(dp[i][j-1]>dp[i-1][j]){
            j--;
        }
        else{
            i--;
        }
        }
    }
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 38796
#include<bits/stdc++.h>
	using namespace std;
	
	
	main()
	{
		long long a,b,x;
		cin >> a >> b >> x;
		long long sum=b/x - a/x;
		if(a==b&&a%x==0) sum++;
		else if(a%x==0) sum++;
		cout << sum;
	}

Measured memory_bytes: 256
W = []
judge = True
a = ""
N = int(input())
for i in range(N):
    s = input()
    if i == 0:
        a = s[len(s)-1]
    else:
        if a != s[0] or s in W:
            judge = False
            break
        else:
            a = s[len(s)-1]
    W.append(s)
if judge:
    print("Yes")
else:
    print("No")

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

using namespace std;
const int INF = 1e9;

int minCost(int N, int K, vector<int>& h) {
	vector<int> dp(N, INF);
	dp[0] = 0;
	
	for(int i = 0; i < N; ++i) {
		for(int j = i+1; j <= i+K; ++j) {
			if(j < N) {
				dp[j] = min( dp[j], dp[i] + abs(h[i] - h[j]) );
			}
		}
	}
	return dp[N - 1];
}
int main() {
	// your code goes here
	int N;
	cin >> N;
	int K;
	cin >> K;
	
	vector<int> h(N, 0);
	for(int i = 0; i < N; ++i) {
		cin >> h[i];
	}
	
	cout << minCost(N, K, h) << endl;
	return 0;
}
	

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

int main() {
 int a, b, c, d;
  cin >> a >> b >> c >> d;
  while (true) {
    c = c - b;
    if(c <= 0) {
      cout << "Yes" << endl;
      return 0;
    }
    a = a - d;
    if(a <= 0) {
      cout << "No" << endl;
      return 0;
    }
 }
  
}
  


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define rp(i,n) for(int i=0; i<n; i++)
using namespace std;
using ll=long long;
using P=pair<int,int>;
using G=vector<vector<int>>;

int main(){
    int n;
    cin >> n;
    vector<P> mani(n);
    rp(i,n){
        int x,l;
        cin >> x >> l;
        mani[i]=make_pair(x+l,x-l);
    }
    sort(mani.begin(),mani.end());
    int ctr=0;
    int where;
    ctr=1;
    where=mani[0].first;
    for(int i=1; i<n; i++){
        if(mani[i].second<where) continue;
        else{
            ctr++;
            where=mani[i].first;
        }
    }
    cout << ctr << endl;
    return 0;
}

Measured memory_bytes: 1024
import numpy as np
N = int(input())
S = np.array(list('-'+input()),dtype='U1')
Q = int(input())
query = map(int,input().split())

isD = S == 'D'
isM = S == 'M'
isC = S == 'C'

cumD = isD.cumsum(dtype=np.int64)
cumM = isM.cumsum(dtype=np.int64)

for K in query:
    x = cumD.copy(); x[K:] -= cumD[:-K]
    x *= isM
    x[K+1:] -= isD[1:-K] * (cumM[K:-1] - cumM[:-K-1])
    print((x.cumsum() * isC).sum())


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

ll n, m, ans, a[200005];
int main() {
	ll i;
	cin >> n;
	for(i=0; i<n; i++) scanf("%lld", &a[i]);
	sort(a, a+n);
	m = n/2;
	for(i=0; i<m-1; i++) ans += (a[n-1-i] - a[i]) * 2;
	if(n%2) ans += max(2*a[m+1]-a[m]-a[m-1], a[m+1]+a[m]-2*a[m-1]);
	else ans += a[m] - a[m-1];
	cout << ans;
	return 0;
}

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

int main() {
  int a,c,d;
  char b;
  cin >> a >> b >> c;

  // ここにプログラムを追記
  if (b == '+') {
    d = a + c;
  }
  else {
    d = a - c;
  }
  cout << d << endl;
}

Measured memory_bytes: 256
A=input()
B=input()
if A==B:
    print("EQUAL")
if len(A)>len(B):
    print("GREATER")
elif len(B)>len(A):
    print("LESS")
else:
    for i in range(len(A)):
        if A[i]>B[i]:
            print("GREATER")
            break
        elif B[i]>A[i]:
            print("LESS")
            break

Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
//typedef __int64 LL;
//typedef long long int LL;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef pair<int,int> P;
//typedef pair<LL,LL> PL;

const int MOD=1000000007;

int main(){
	int a,b;cin>>a>>b;
	if(a<10 && b<10)cout<<a*b<<"\n";
	else cout<<-1<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define mk make_pair
#define pi pair<int, int>
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i,a,b) for(int i=a;i>=(b);--i)
using namespace std;
int dt[][2]= {{1,0},{-1,0},{0,1},{0,-1},{0,0}};
//typedef pair<int, int> P;
//priority_queue<int, vector<int>, greater<int> > q;

const int N = 3e5+5;
int n,m;
int tr[N];
struct node
{
   int l,r,len;
   bool operator < (const node& b)const
   {
      return len < b.len;
   }
}s[N];
vector<int>v[N];

int lowbit(int x)
{
   return x&-x;
}

void add(int x,int c)
{
   for(int i=x;i<=m;i+=lowbit(i))tr[i]+=c;
}

int sum(int x)
{
   int res = 0;
   for(int i=x;i;i-=lowbit(i))res += tr[i];
   return res;
}

int main()
{
   IOS;
   cin >> n >> m;
   rep(i,1,n)
   {
      int l,r;
      cin >> l >> r;
      s[i] = {l,r,r-l+1};
   }
   sort(s+1,s+1+n);//区间长度从小到大排序
   for(int i=1,j=1;i<=m;++i)//m种停车间隔
   {
      while(j<=n&&s[j].len<i)
      {
         add(s[j].l,1);
         add(s[j].r+1,-1);
         ++j;
      }
      int ans = n-j+1;
      for(int k=i;k<=m;k+=i)ans += sum(k);
      cout << ans <<endl;
   }
}

Measured memory_bytes: 14580
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=110;

set<VI> grid[N][N];
queue<VI> q;
char g[N][N];
int h,w;

// f,b,u,d,l,r
const int F=0,B=1,U=2,D=3,L=4,R=5;

void add(int x,int y,VI s) {
	if (grid[x][y].count(s)) return;
	grid[x][y].insert(s);
	s.pb(x); s.pb(y);
	q.push(s);
}

int main() {
	scanf("%d%d",&h,&w);
	rep(i,0,h) scanf("%s",g[i]);
	add(0,0,VI{2,5,1,6,4,3});
	while (!q.empty()) {
		auto v=q.front(); q.pop();
		VI d(v.begin(),v.begin()+6);
		int x=v[6],y=v[7];
		if (x==h-1&&y==w-1) { puts("YES"); return 0; }
		if (y<w-1&&g[x][y+1]!='#') {
			VI newd{d[F],d[B],d[L],d[R],d[D],d[U]};
			if (newd[D]==g[x][y+1]-'0') {
				add(x,y+1,newd);
			}
		}

		if (y>0&&g[x][y-1]!='#') {
			VI newd{d[F],d[B],d[R],d[L],d[U],d[D]};
			if (newd[D]==g[x][y-1]-'0') {
				add(x,y-1,newd);
			}
		}

		if (x<h-1&&g[x+1][y]!='#') {
			VI newd{d[U],d[D],d[B],d[F],d[L],d[R]};
			if (newd[D]==g[x+1][y]-'0') {
				add(x+1,y,newd);
			}
		}

		if (x>0&&g[x-1][y]!='#') {
			VI newd{d[D],d[U],d[F],d[B],d[L],d[R]};
			if (newd[D]==g[x-1][y]-'0') {
				add(x-1,y,newd);
			}
		}
	}
	puts("NO");
}



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

int main()
{
	int A,B;

	cin >> A >> B;

	if (A <= 8 && B <= 8){
		cout << "Yay!" << endl;
	}

	else {
		cout << ":(" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#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 unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MOD (1000000007)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << endl
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; }

ll dp[1000][1000];
int main() {
	int H,W;
    cin >> H;
	cin >> W;
	string a[H];
	REP(i, H) {
		cin >> a[i];
	}
	REP(i, H){
		REP(j, W){
            dp[i][j] = 0;
        }
	}
	dp[0][0] = 1;
	REP(i, H+W-1){
		REP(j, i+1){
			int h = j;
			int w = i - j;
			if (0 <= h && h < H && 0 <= w && w < W){
				if (h != 0 && a[h-1][w] == '.'){
						dp[h][w] += dp[h-1][w];
                        dp[h][w] %= MOD;
				}
				if (w != 0 && a[h][w-1] == '.'){
						dp[h][w] += dp[h][w-1];
                        dp[h][w] %= MOD;
				}
			}
		}
	}
    cout << dp[H-1][W-1] << endl;
}

Measured memory_bytes: 9088
import java.util.*;

public class Main {

    public static void main(String[] arg) {

        Scanner scanner = new Scanner(System.in);
        long a1 = scanner.nextLong();
        long a2 = scanner.nextLong();
        long a3 = scanner.nextLong();

        if (a1+a2+a3 >= 22) {
            System.out.println("bust");
        } else {
            System.out.println("win");
        }

    }
}

Measured memory_bytes: 23892
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
int main(){

  long long int n,k,a,b,i;

  cin>>n>>k;
  pair<long long int,long long int> pairs[n];
  for(i=0;i<n;i++){
    cin>>a>>b;
    pairs[i]=make_pair(a,b);
  }
  sort(pairs,pairs+n);
  for(i=0;k>0&&i<n;i++) k-=pairs[i].second;
  if(i==0) i++;
  cout<<pairs[i-1].first<<endl;
  return 0;
}


















Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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;}


int main() {
  string o, e;
  cin >> o >> e;
  rep (i, o.size()) {
    cout << o[i];
    if (e.size() > i) cout << e[i];
  }
  cout << endl;
  return 0;
}

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

int main(){
  
  int a, p;
  cin >> a >> p;

  int m = a * 3 + p;

  cout << m / 2 << endl;

}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int totalScore = 0;
		List<Integer> jogaiKohoList= new ArrayList<Integer>();
		for(int i =0;i < n;i++) {
			int score = sc.nextInt();
			totalScore += score;
			if(score % 10 !=0) {
				jogaiKohoList.add(score);
			}
		}
		Collections.sort(jogaiKohoList);
		if(totalScore %10 !=0) {
			System.out.println(totalScore);
		}else {
			if(jogaiKohoList.isEmpty()) {
				System.out.println(0);
			}else {
				totalScore -= jogaiKohoList.get(0);
				System.out.println(totalScore);
			}
		}

	}

}

Measured memory_bytes: 22996
def f(n, k):
    return ((2 * n - k + 1) * k) // 2 - (k * (k - 1)) // 2 + 1


def g(n, k):
    return sum([f(n, ki) for ki in range(k, n + 2)])


n, k = map(int, input().split())
print(g(n, k) % (10 ** 9 + 7))

Measured memory_bytes: 20088
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int X, Y, A, B, C;
ll p[100004], q[100004], r[100004]; 
priority_queue<ll, vector<ll>, greater<ll>> que;

int main() {
  INCANT;
  cin >> X >> Y >> A >> B >> C;
  rep(i, A) cin >> p[i];
  rep(i, B) cin >> q[i];
  rep(i, C) cin >> r[i];
  sort(p, p+A);
  sort(q, q+B);
  sort(r, r+C, greater<ll>());
  ll sm=0ll;
  rep(i, X) {
    sm+=p[A-1-i];
    que.push(p[A-1-i]);
  }
  rep(i, Y) {
    sm+=q[B-1-i];
    que.push(q[B-1-i]);
  }
  ll q=que.top();
  int idx = 0;
  while(idx<C && !que.empty()) {
    q = que.top();
    if (r[idx]<=q) idx++;
    else {
      sm-=q;
      sm+=r[idx];
      idx++;
      que.pop();
    }
  }
  cout << sm << endl;
  return 0;
}

Measured memory_bytes: 4724
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++) //for文マクロ
using namespace std;

typedef unsigned long ul;
typedef long long ll;
typedef pair<ul, ul> P; //ペア　タイプでふ

int main()
{
    int a, b;
    cin >> a >> b;
    if (a == 1)
    {
        if (b == 1 || b == 3)
        {
            cout << "Yes";
        }
        else
        {
            cout << "No";
        }
    }
    else if (a % 2 == 0 || b % 2 == 0)
    {
        cout << "No";
    }
    else
    {
        cout << "Yes";
    }
}

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

using namespace std;
typedef long long ll;
int n;

ll gcd(ll x, ll y) {
  if(x % y == 0) return y;
  return gcd(y,x % y);
}

int main() {
  
  cin >> n;
  
  ll t;
  cin >> t;
  for(int i = 0; i < n - 1; i++) {
    ll tmp;
    cin >> tmp;
    t = t / (gcd(t,tmp)) * tmp;
  }

  cout << t << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
typedef unsigned long long ull;
typedef long double ldouble;
const ll INF=1e18;

int main(){
    ll d, g;
    ll min = INF;
    cin >> d >> g;
    vector<ll> p(d);
    vector<ll> c(d);
    for(int i = 0; i < d; i++) {
        cin >> p.at(i) >> c.at(i);
    }
    // {0, 1, ..., n-1} の部分集合の全探索
    for (int bit = 0; bit < (1<<d); ++bit)
    {
        int max_index = -1;
        ll score = 0, problem = 0;
        /* bit で表される集合の処理を書く */
        bitset<10> tmp(bit);
        /* bit で表される集合の処理を書く */
        for(int i = 0; i < d; i++){
            if(tmp.test(i)) {
                score += p.at(i) * (i+1) * 100 + c.at(i);
                problem += p.at(i);
            }
            else max_index = i;
        }

        if(score < g) {
            int s1 = 100 * (max_index + 1);
            int need = (g - score + s1 - 1) / s1;
            if(need >= p.at(max_index)) continue;
            problem += need;
        }
        
        if(problem < min) min = problem;
    }
    cout << min << endl;
}

Measured memory_bytes: 3640
fun main(args: Array<String>) {
    agc038a()
}


fun agc038a() {
    val (h, w, a, b) = readLine()!!.split(" ").map { it.toInt() }

    val answer = (1..h).map { currH ->
        (1..w).map { it <= w - a }.joinToString(separator = "") { if (it == currH <= h - b) "0" else "1" }
    }

    println(answer.joinToString(separator = System.lineSeparator()))
}


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

inline int rd() {
  int x = 0;
  bool f = 0;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + (c ^ 48);
    c = getchar();
  }
  return f ? -x : x;
}

int n, f[N];

int main() {
  n = rd();
  f[n] = 1;
  for (int i = n; i >= 0; --i)
    for (int j = 3; i + j <= n; ++j)
      f[i] = (f[i] + f[i + j]) % mod;
  printf("%d\n", f[0]);
  return 0;
}


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

#pragma region Macro
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#pragma endregion

#pragma region Debug
void debug_out() { cout << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cout << H << " ";
	debug_out(T...);
}

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
#pragma endregion

// コンパイル時、エイリアス「debug」を使用 --> マクロが使えるように

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル
	
	int n;
	cin >> n;
	vi l(n);
	rep(i,n){
		cin >> l[i];
	}

	int ans = 0;

	rep(i,n-2){
		FOR(j,i,n-1){
			FOR(k,j,n){
				if(l[i] != l[j] && l[j] != l[k] && l[k] != l[i]){
					if(l[i] + l[j] > l[k] && l[j] + l[k] > l[i] && l[i] + l[k] > l[j]){
						debug(l[i], l[j], l[k]);
						ans++;
					}
				}
			}
		}
	}

	cout << ans << endl;

}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	
	solve();
	return 0;
}

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

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


int main() {

  int n;
  cin >> n;
  int l[2000];
  rep(i, n) {
    cin >> l[i];
  }

  int ans = 0;
  rep(i, n) {
    for (int j = i+1; j < n; j++) {
      for (int k = j+1; k < n; k++) {
        if (l[i] < l[j] + l[k] &&
            l[j] < l[i] + l[k] &&
            l[k] < l[i] + l[j]) {
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}


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

typedef int_fast32_t int32;
typedef int_fast64_t int64;

const int32 inf = 1e9+7;
const int32 MOD = 1000000007;
const int64 llinf = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define all(obj) (obj).begin(),(obj).end()
#define rall(obj) (obj).rbegin(),(obj).rend()
#define fi first
#define se second
#define pb(a) push_back(a)
typedef pair<int32,int32> pii;
typedef pair<int64,int64> pll;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  cout << s;
  if(*--s.end() == 's'){
    cout << 'e';
  }
  cout << 's' << endl;
  return 0;
}

Measured memory_bytes: 3648
import sys
a = []
for l in sys.stdin:
    if l == "":
        break
    a.append(list(map(lambda x: int(x), l.split(" "))))

N = a[0][0]
D = a[0][1]
coo = a[1:]

import math

count = 0
for c in coo:
    l = math.sqrt(c[0]**2 + c[1]**2)
    if l <= D:
        count += 1

print(count)

Measured memory_bytes: 46912
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int x;
	cin >> x;
	REP(i, INF) {
		if (i*(i + 1) / 2 >= x) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cctype>
#include <climits>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <memory>
#include <functional>

using namespace std;

#define ALL(a) (a).begin(),(a).end()
#define REP(index, begin, end) for (int (index) = (begin); (index) < (end); (index)++)
#define RE(index, end) REP(index, 0, end)
#define INF INT_MAX / 3
#define DINT(x) printf(#x " = %d\n", x);
#define GETINT(x) scanf("%d", &x)
#define GETSTR(x) scanf("%s", x)

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;

struct column_num
{
	int white,
		blue,
		red;
};

int main()
{
	int h, w;
	array<column_num, 50> row;
	GETINT(h);
	GETINT(w);
	RE(i, h)
	{
		char temp[51] = {};
		GETSTR(temp);
		column_num col = {};
		RE(j, w)
		{
			switch (temp[j])
			{
			case 'W':
				col.white++;
				break;
			case 'B':
				col.blue++;
				break;
			case 'R':
				col.red++;
				break;
			}
		}
		row[i] = col;
	}
	int result = 0;
	REP(w_len, 0, h - 2)
	{
		int w_sum = 0;
		REP(i, 0, w_len + 1)
		{
			w_sum += row[i].white;
		}
		REP(b_len, w_len + 1, h - 1)
		{
			int b_sum = 0;
			REP(i, w_len + 1, b_len + 1)
			{
				b_sum += row[i].blue;
			}
			{
				int r_sum = 0;
				REP(i, b_len + 1, h)
				{
					r_sum += row[i].red;
				}
				int sum_all = w_sum + b_sum + r_sum;
				if (result < sum_all)
				{
					result = sum_all;
				}
			}
		}
	}
	printf("%d\n", (w * h) - result);
	return 0;
}

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

const double pi = 3.14159265358979323846;
const ll mod = 1000000007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	ll ans = 1;
	int n; cin >> n;
	ll tmp = 1001001001001001001;
	bool ok = true;
	rep(i,n){
		ll a; cin >> a;
		if(a == 0){
			ans = 0;
			ok = true;
			break;
		}
		if(tmp < a){
			ok = false;
			continue;
		}
		ans *= a;
		tmp = (1000000000000000000 + ans - 1) / ans;

	}
	if(ok && ans <= 1000000000000000000) cout << ans << endl;
	else cout << -1 << endl;
} 


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

ll read()
{
	ll s=0;
	char c=getchar(),lc='+';
	while (c<'0'||'9'<c) lc=c,c=getchar();
	while ('0'<=c&&c<='9') s=s*10+c-'0',c=getchar();
	return lc=='-'?-s:s;
}
void write(ll x)
{
	if (x<0)
	{
		putchar('-');
		x=-x;
	}
	if (x<10) putchar(x+'0');
	else
	{
		write(x/10);
		putchar(x%10+'0');
	}
}
void print(ll x,char c='\n')
{
	write(x);
	putchar(c);
}
ll count(ll n,ll m)
{
	ll ans=0;
	for (ll i=m;i<=n;i*=m) ans+=n/i/2;
	return ans;
}

int main()
{
	ll n=read();
	if (n&1) print(0);
	else
	{
		ll cnt2=count(n,2);
		ll cnt5=count(n,5);
		print(min(cnt2,cnt5));
	}

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;
int main() {
    int n;
    int k;
    cin>>k>>n;
    vector<int> num(2*n);
    for (int i = 0; i < n; ++i) {
        cin>>num[i];
        num[n+i]=num[i]+k;
    }
    int max = num[1]-num[0];
    for (int i = 1; i < 2 * n; ++i) {
        max = max>num[i]-num[i-1]?max:num[i]-num[i-1];
    }
    cout<<k-max;
    return 0;
}


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

string s;
ll ans=0,k=0;

int main() {
  cin >> s;
  int n=s.size();
  for(int i=0; i<n; i++){
    if(s[i]=='B'){
      k++;
    } else {
      ans+=k;
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define C getchar()
#define ll long long
#define Violet inline
#define N 2050
//#pragma GCC optimize("O3")
using namespace std;
Violet int read()
{
	int x=0,l=1;char c=C;
	for (;c<'0'||c>'9';c=C) if (c=='-') l=-1;
	for (;c>='0'&&c<='9';c=C) x=x*10+c-48;
	return x*l;
}

struct Vio { int next,x,y; }e[N<<1];

int n,k,maxx,cut,ans=1e9;
int lin[N],L;
int size[N];

Violet void fnp(int x,int y) { e[++L]=(Vio){lin[x],x,y},lin[x]=L; }

Violet void dfs(int x,int sum,int par)
{
	size[x]=1;
	for (int i=lin[x],y;i,y=e[i].y;i=e[i].next)
		if (y!=par)
			{
				dfs(y,sum+1,x);
				size[x]+=size[y];
			}
	if (sum==k/2) cut+=size[x]-1;
}

int main()
{
	n=read();k=read();
	for (int i=1;i<n;i++)
		{
			int x=read(),y=read();
			fnp(x,y);fnp(y,x);
		}
	if (k%2==0)
		for (int i=1;i<=n;i++)
			cut=0,dfs(i,0,0),ans=min(ans,cut);
	else
		for (int i=1;i<=n;i++)
			for (int j=lin[i],y;j,y=e[j].y;j=e[j].next)
				cut=0,dfs(i,0,y),dfs(y,0,i),ans=min(ans,cut);
	printf("%d\n",ans);
	return 0;
}















Measured memory_bytes: 384
program atcoder_contest_scheduling
  implicit none
  integer, parameter :: maxday = 365, maxtype = 26
  integer :: d, c(maxtype), s(maxtype, maxday), t(maxday), u(maxday)
  integer :: m, n, p, i
  real(8) :: t1, t2
  call cpu_time(t1)
  call random_seed_clock()
  read(*,*) d
  read(*,*) c
  read(*,*) (s(:, i), i = 1, d)
  t = (/(maxloc(s(:, i), 1), i = 1, d)/)
  m = score()
  u = t
  do
    p = next_int(d)
    do i = 1, maxtype
      t(p) = i
      n = score()
      if (m < n) then
        m = n
        u(p) = i
      else
        t(p) = u(p)
      end if
      call cpu_time(t2)
      if (t2 - t1 > 1.979d0) goto 100
    end do
  end do
  100 write(*,'(i0)') (u(i), i = 1, d)
contains
  integer function score() result(res)
    integer :: last(maxtype), i
    last = 0
    res = 0
    do i = 1, d
      last(t(i)) = i
      res = res + s(t(i), i) + dot_product(c, last - i)
    end do
  end
  subroutine random_seed_clock()
    integer :: nseed, clock, seed(100)
    call system_clock(clock)
    call random_seed(size = nseed)
    seed(1:nseed) = clock
    call random_seed(put = seed(1:nseed))
  end
  integer function next_int(m) result(res)
    integer, intent(in)  :: m
    real(8) :: r
    call random_number(r)
    res = int(m * r) + 1
  end
end program atcoder_contest_scheduling

Measured memory_bytes: 2992
N = int(input())
ans = 0
for i in range(1, (4 ** 9)+1):
    tmp = ""
    now = i
        
    while now != 0:
        if now % 4 == 0:
            tmp += "0"
        elif now % 4 == 1:
            tmp += "3"
        elif now % 4 == 2:
            tmp += "5"
        else:
            tmp += "7"

        now //= 4

    
    tmp = str(int(tmp[::-1]))
    if "3" in tmp and "5" in tmp and "7" in tmp:
        tmp = int(tmp)
        if tmp <= N and "0" not in str(tmp):
            ans += 1
print(ans)            


Measured memory_bytes: 42732
/*
  Contest 096
  B - Maximum Sum
  Rakesh Kumar --> 23/09/2020
 */

#include <bits/stdc++.h>

int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(0); std::cout.tie(0);

    int a = 0, b = 0, c = 0;
    std::cin >> a >> b >> c;
    int k = 0;
    std::cin >> k;
    int v = std::max(std::max(a, b), c);
    int total = a + b + c - v;
    while (k--) {
        v <<= 1;
    }
    total += v;
    std::cout << total << std::endl;

    return 0;
}


Measured memory_bytes: 3608
use std::io::*;
use std::str::*;

fn scan_token<T: FromStr>() -> T {
    stdin().bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>()
        .parse::<T>().ok().unwrap()
}

fn scan_line<T: FromStr>() -> Vec<T> {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace().map( |token| token.parse::<T>().ok().unwrap() ).collect()
}

fn add(acc: &mut Vec<Vec<i32>>, frx: usize, fry: usize, tox: usize, toy: usize, v: i32) {
    acc[frx][fry] += v;
    acc[frx][toy] -= v;
    acc[tox][fry] -= v;
    acc[tox][toy] += v;
}

fn main() {
    let max_n = 505;
    let n: i32 = scan_token();
    let m: i32 = scan_token();
    let q: i32 = scan_token();

    let mut acc: Vec<Vec<i32>> = vec![vec![0; max_n]; max_n];

    for i in 0..m {
        let l: usize = scan_token();
        let r: usize = scan_token();
        add(&mut acc, 0, r, l + 1, max_n - 1, 1)
    }

    for i in 0..max_n {
        for j in 0..(max_n - 1) {
            acc[i][j + 1] += acc[i][j];
        }
    }

    for j in 0..max_n {
        for i in 0..(max_n - 1) {
            acc[i + 1][j] += acc[i][j];
        }
    }

    for i in 0..q {
        let p: usize = scan_token();
        let q: usize = scan_token();
        println!("{}", acc[p][q]);
    }
}

Measured memory_bytes: 4988
#include<stdio.h>
#include<stdlib.h>


typedef long long llong ;

typedef struct
{
	llong size ;
	llong value ;

} Data ;

#define N_MAX 500000
Data art[ N_MAX ] ;

int cmp( const Data *a ,const Data *b )
{
	int ret = a->size == b->size ? a->value - b->value : -( a->size < b->size ) ;

	return ret ? ret : 1 ;
}

inline llong max( llong a ,llong b )
{
	return a > b ? a : b ;
}


int main( void )
{
	int N ;
	scanf( "%d" ,&N ) ;

	int i ;
	for( i = 0 ; i < N ; ++i )
	{
		scanf( "%lld %lld" ,&art[ i ].size ,&art[ i ].value ) ;
	}

	qsort( art ,N ,sizeof( Data ) ,cmp ) ;

	llong min_size	= art[ 0 ].size		;
	llong sum_value	= art[ 0 ].value	;

	llong ans = art[ 0 ].value ;
	for( i = 1 ; i < N ; ++i )
	{
		llong value	= art[ i ].value	;
		llong size	= art[ i ].size		;

		llong tmp =  sum_value + value  - ( size -  min_size ) ;
		if( tmp < value )
		{
			ans = max( ans ,value ) ;

			sum_value	= value	;
			min_size	= size	;
		}

		else
		{
			ans = max( ans ,tmp ) ;

			sum_value += value ;
		}
	}

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

	return 0 ;
}


Measured memory_bytes: 17180
//Pantyhose(black) + glasses = infinity

#include <bits/stdc++.h>
using namespace std;
 
#define debug(x) cerr << #x << " = " << x << '\n';
#define BP() cerr << "OK!\n";
#define PR(A, n) {cerr << #A << " = "; for (int _=1; _<=n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define PR0(A, n) {cerr << #A << " = "; for (int _=0; _<n; ++_) cerr << A[_] << ' '; cerr << '\n';}
#define FILE_NAME "data"

const int MAX_N = 200007;
const int64_t INF = 1e18;

class segmentTree {
public:

	struct node {
		int64_t val, lazy;

		node() {
			val = lazy = 0;
		}
	};

	int n;
	vector<node> st;

	segmentTree(int n): n(n) {
		st.resize(4*n);
	}

	void down(int id) {
		int64_t tmp = st[id].lazy;
		st[id].lazy = 0;
		st[id*2].val += tmp;
		st[id*2].lazy += tmp;
		st[id*2+1].val += tmp;
		st[id*2+1].lazy += tmp;
	}

	void upd(int u, int v, int64_t delta, int l, int r, int id) {
		if (v<l || u>r)
			return;
		if (u<=l && r<=v) {
			st[id].val += delta;
			st[id].lazy += delta;
			return;
		}
		down(id);
		int mid = (l + r) / 2;
		upd(u, v, delta, l, mid, id*2);
		upd(u, v, delta, mid+1, r, id*2+1);
		st[id].val = min(st[id*2].val, st[id*2+1].val);
	}

	int64_t get(int u, int v, int l, int r, int id) {
		if (v<l || u>r)
			return INF;
		if (u<=l && r<=v)
			return st[id].val;
		down(id);
		int mid = (l + r) / 2;
		return min(get(u, v, l, mid, id*2), get(u, v, mid+1, r, id*2+1));
	}

	void upd(int u, int v, int64_t delta) {
		upd(u, v, delta, 1, n, 1);
	}

	int64_t get(int u, int v) {
		if (u>v)
			return 0;
		return get(u, v, 1, n, 1);
	}
};

int n, m;
vector<pair<int, int> > L[MAX_N];
int64_t s, ps[MAX_N];

void readInput() {
	cin >> n >> m;
	for (int i=1; i<=m; ++i) {
		int l, r, w;
		cin >> l >> r >> w;
		L[l].push_back({r, w});
		s += w;
	}
}

void solve() {
	for (int i=1; i<=n; ++i)
		sort(L[i].begin(), L[i].end());
	int64_t res = s;
	segmentTree tr(n);
	for (int i=n; i>=1; --i) {
		for (auto v : L[i]) {
			tr.upd(v.first, n, v.second);
			// cerr << v.first << ' ' << n << ' ' << v.second << '\n';
		}
		tr.upd(i, i, ps[i+2]);
		int64_t tmp = tr.get(i, n);
		res = max(res, s - tmp);
		ps[i] = min(ps[i+1], tmp);
	}
	cout << res;
}

int main() {
	#ifdef GLASSES_GIRL
		freopen(FILE_NAME".inp", "r", stdin);
		freopen(FILE_NAME".out", "w", stdout);
	#endif
	ios::sync_with_stdio(0); cin.tie(0);
	readInput();
	solve();
}

Measured memory_bytes: 25216
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////

int main() {
	ll n, x; cin >> n >> x;
	vector<ll>a(n);
	ll sum = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		sum += a[i];
	}
	sort(a.begin(), a.end());
	int ans = 0;
	ll key = x;
	for (int i = 0; i < n; ++i) {
		if (key >= a[i]) {
			key -= a[i];
			ans++;
		}
		else {
			break;
		}
	}
	if (sum < x) {
		cout << n - 1 << endl;
	}
	else {
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
from collections import deque


def make_state(N):
    state = [[-1 for j in range(N+1)] for i in range(N+1)]
    min_state = 0
    s = min_state
    for i in range(1, N+1):
        for j in range(1, i):
            state[i][j] = s
            state[j][i] = s
            s += 1
    return state


def solve(N, A):
    state = make_state(N)
    max_state = N * (N-1) // 2
    n_prev_states = [0 for i in range(max_state)]
    next_states = [set() for i in range(max_state)]
    for i in range(1, N+1):
        for k in range(N-2):
            ps = state[i][A[i][k]]
            ns = state[i][A[i][k+1]]
            n_prev_states[ns] += 1
            next_states[ps].add(ns)
    
    today_states = deque()
    for s in range(max_state):
        if n_prev_states[s] == 0:
            today_states.appendleft(s)
    
    n_days = 0
    n_states_left = max_state
    while len(today_states) > 0:
        n_days += 1
        if len(today_states) == 0:
            break
        n_states_left -= len(today_states)
        for _ in range(len(today_states)):
            s = today_states.pop()
            for ns in next_states[s]:
                n_prev_states[ns] -= 1
                if n_prev_states[ns] == 0:
                    today_states.appendleft(ns)
    return n_days if n_states_left == 0 else -1


def main():
    N = int(input())
    A = list()
    A.append([])
    for i in range(N):
        a = list(map(int, input().strip().split()))
        A.append(a)
    print(solve(N, A))


if __name__ == "__main__":
    main()


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

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

  if (N > M) swap(N, M);

  if (M == 1) {
    cout << 1 << endl;
  } else if (N == 1) {
    cout << M - 2 << endl;
  } else if (N == 2) {
    cout << 0 << endl;
  } else {
    cout << (M-2)*(N-2) << endl;
  }

  return 0;

}

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

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

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

class P
{
    static void Main()
    {
        string s = Console.ReadLine();
        int[][] p = new int[26][];
        bool[][] b = new bool[26][];
        for (int i = 0; i < 26; i++)
        {
            b[i] = new bool[s.Length];
        }
        for (int i = 0; i < s.Length; i++)
        {
            b[s[i] - 'a'][i] = true;
        }
        for (int i = 0; i < 26; i++)
        {
            p[i] = new int[s.Length];
            if (!b[i][s.Length - 1]) p[i][s.Length - 1] = 1;
            for (int j = s.Length - 2; j >= 0; j--)
            {
                if (b[i][j]) p[i][j] = 0;
                else p[i][j] = p[i][j + 1] + 1;
            }
        }
        Console.WriteLine(p.Select(x => x.Max()).Min());
    }
}

Measured memory_bytes: 13524
//0297
#include <iostream>
using namespace std;
int main(void){
    int n,a,K,P;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> K>> P;
        a=K%P;
        if(a==0)
        cout << P << endl;
        else
        cout << a << endl;
        
    }
    
}



Measured memory_bytes: 3096
#include <iostream>
#include <string>

using namespace std;

int main() {
  string s;
  cin >> s;
  
  int start = 0;
  int end = s.size() - 1;
  int count = 0;
  while (start < end) {
    if (s[start] != s[end])
      ++count;
    ++start;
    --end;
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256