akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define vi vector<int>
#define vstr vector<string>
#define vdb vector<double>
#define vbool vector<bool>
#define vvi vector<vector<int> >
#define mii map<int,int>
#define pb push_back
#define pii pair<int,int>
#define vpair vector<pii > 
#define mkp make_pair
#define scan(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) {cout<<a[i]<<' ';}cout<<'\n'
#define mem(a,v) memset(a,v,sizeof(a))
#define loop(i,a,b) for (int i = a; i < b; i++)
#define loope(i,a,b) for (int i = a; i <= b; i++)
#define bloop(i,a,b) for(int i = a;i>=b;i--)
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION std::cout.unsetf ( std::ios::fixed );std::cout.precision(9)
#define PI 3.14159265
#define S second
#define F first
#define CHECK cout<<"CHEDEDWB"
#define CHECK1(a) cout<<a<<endl
#define CHECK2(a,b) cout<<a<<' '<<b<<endl;
#define br '\n'
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(),x.end()
using namespace std;
int mod = 1e9+7;
int inf = 1e18;
int m_inf = INT_MIN;
// int extendedgcd(int a,int b,int &x,int &y){
	// if(a == 0){
		// x = 0; y = 1;
		// return b;
	// }
	// int x1,y1;
	// int d = extendedgcd(b%a,a,x1,y1);
	// x = y1 - (b/a)*x1;y = x1;
	// return d;
// }
// int expmod(int a,int b) {
// 	if(b == 1) return a;
// 	if(b == 0) return 1;
// 	int m1 = expmod(a,b/2)%mod;
// 	if(b%2) return ((m1*m1)%mod*a%mod)%mod;
// 	return (m1*m1)%mod;
// }
// int power(int a,int b) {
// 	if(b == 1) return a;
// 	if(b == 0) return 1;
// 	int m1 = power(a,b/2);
// 	if(b%2) return m1*m1*a;
// 	return m1*m1;
// }
// int logn(int n, int r) 
// { 
//     return (n > r - 1) ? 1 + logn(n / r, r) : 0; 
// } 

// int nCr(int n,int r)
// {
	// r = min(r,n-r);
	// if(r<0)
		// return 0;
	// if(r == 0)
		// return 1;
	// int ans = 1;
	// for(int i = 1;i<=r;i++)
	// {
		// ans = ans*(n-i+1)/i;
	// }
	// return ans;
// 		
// }
// vi factmod(int n)
// {
	// vi ans(n+1);
	// ans[0] = 1;
	// loop(i,1,n+1)
	// {
		// ans[i] = (ans[i-1]*i)%mod;
	// }
	// return ans;
// }
// int nCrmod(int n,int r,vi &fact)
// {
	// int x1,y1;
	// extendedgcd(fact[r],mod,x1,y1);
	// int x2,y2;
	// extendedgcd(fact[n-r],mod,x2,y2);
	// int ans = (fact[n]*((x1+mod)%mod))%mod;
	// ans = (ans*((x2+mod)%mod))%mod;
	// return ans;
// }
// void dfs(vector<vector<int> > &adj,int root,bool vis[])
// {
// 	vis[root] = true;
// 	for(int i = 0;i<adj[root].size();i++){
// 		int v = adj[root][i];
// 		if(!vis[v])		
// 			dfs(adj,v,vis);
// 	}
// }

int32_t main() 
{
	FastIO; PRECISION;
	int t = 1;
	// cin>>t;
	while(t--)
	{
		long double a;
		long double b;
		cin>>a>>b;
		
		cout<<(int)floor(a*b)<<'\n';	
	}
}

Measured memory_bytes: 3748
N=int(input())
X=list(map(int,input().split()))

x=[]
for i in range(N):
  x.append(X[i])
x.sort()

for i in range(N):
  if X[i]<x[N//2]:
    print(x[N//2])
  else:
    print(x[N//2-1])

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

long long N, A, B;

bool isOK(long long t, vector<long long> tmp){
  for(int i = 0; i < N; i++) {
    tmp[i] -= t * B;
  }
  
  long long cnt = 0;
  for(auto e: tmp) {
    if(e > 0) {
      cnt += (e - 1) / (A - B) + 1;
    }
  }
  if(cnt <= t)
    return true;
  else
    return false;
}

int main(){
  cin >> N >> A >> B;
  vector<long long> h(N);
  
  long long sum = 0LL;
  long long ma = 0LL;
  for(int i = 0; i < N; i++){
    cin >> h[i];
    sum += h[i];
    ma = max(ma, h[i]);
  }
  long long low = sum / (A + B * (N-1)) - 1;
  long long high = ma / B + 1;
  
  while(high - low > 1){
    long long mid = (high + low) / 2;
    if(isOK(mid, h)) high = mid;
    else low = mid;
  }
  cout << high;
}

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

using namespace std;

int main()
{
	string S, T;
	cin >> S >> T;
	int answer = 0;

	for (int i = 0; i < 3; i++)
		if (S.at(i) == T.at(i)) answer++;

	cout << answer << endl;

	return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]

def main():
	N,K = MI()
	hh = LI()
	ans = 0
	for h in hh:
		if h >= K:
			ans+=1
	print(ans)

main()

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

int main(){
    double x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    
    double ans;
    ans = sqrt(pow(abs(x2-x1),2) + pow((abs(y2-y1)), 2));
    cout << fixed << setprecision(10) << ans << endl;
}




Measured memory_bytes: 3292
#include<iostream>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int count=3;
    if(a==b){
        count--;
    }
    if(a==c)
    count--;
    if(b==c)
    count--;
    if(count==0){
        count=1;
    }
    cout<<count;
}

Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {

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

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int k = sc.nextInt();
		int num = 0;

		for (int i = 0; i < k; i++) {
			if (a > 0) {
				num++;
				a--;
			} else if (b > 0) {
				b--;
			} else if (c > 0) {
				num--;
				c--;
			}
		}

		System.out.println(num);

	}

}

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

char str[2000][2000];

typedef struct {
	int J;
	int O;
	int I;
} ARRAY;

ARRAY array[2000][2000];

int main()
{
	int M, N;
	int K;
	
	scanf("%d %d", &M, &N);
	scanf("%d", &K);
	
	for (int i = 0; i < M; i++){
		for (int j = 0; j < N; j++){
			scanf(" %c", &str[i][j]);
			
			switch (str[i][j]){
				case 'J':
				array[i][j].J++;
				break;
				
				case 'O':
				array[i][j].O++;
				break;
				
				case 'I':
				array[i][j].I++;
				break;
			}
			
			if (i > 0){
				array[i][j].J += array[i - 1][j].J;
				array[i][j].O += array[i - 1][j].O;
				array[i][j].I += array[i - 1][j].I;
			}
			if (j > 0){
				array[i][j].J += array[i][j - 1].J;
				array[i][j].O += array[i][j - 1].O;
				array[i][j].I += array[i][j - 1].I;
			}
			if (i > 0 && j > 0){
				array[i][j].J -= array[i - 1][j - 1].J;
				array[i][j].O -= array[i - 1][j - 1].O;
				array[i][j].I -= array[i - 1][j - 1].I;
			}
		}
	}
	
	for (int i = 0; i < K; i++){
		int si, sj, ei, ej;
		scanf("%d %d %d %d", &si, &sj, &ei, &ej);
		
		si--;
		sj--;
		ei--;
		ej--;
		
		int J = array[ei][ej].J;
		int O = array[ei][ej].O;
		int I = array[ei][ej].I;
		if (si > 0){
			J -= array[si - 1][ej].J;
			O -= array[si - 1][ej].O;
			I -= array[si - 1][ej].I;
		}
		if (sj > 0){
			J -= array[ei][sj - 1].J;
			O -= array[ei][sj - 1].O;
			I -= array[ei][sj - 1].I;
		}
		if (si > 0 && sj > 0){
			J += array[si - 1][sj - 1].J;
			O += array[si - 1][sj - 1].O;
			I += array[si - 1][sj - 1].I;
		}
		
		printf("%d %d %d\n", J, O, I);
	}
	
	return 0;
}

Measured memory_bytes: 29008
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<stack>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<int,int> P; 

const int maxn = 100010;

int n,m,s,u,v;
int dis[maxn],vis[maxn];

priority_queue<P,vector<P>,greater<P> > q;

int h[maxn],siz;
struct E{
	int to , next;
	ll cost;
}e[maxn*2];
void add(int u,int v,ll w){
	e[++siz].to = v;
	e[siz].cost = w;
	e[siz].next = h[u];
	h[u]=siz;
}

void dij(){
	memset(dis,0x3f,sizeof(dis));
	dis[1]=0;
	q.push(P(0,1));
	
	while(!q.empty()){
		int u = q.top().second; q.pop();
		
		if(vis[u]) continue;
		vis[u]=1;
		
		for(int i = h[u];i != -1;i = e[i].next){
			int v = e[i].to;
			if(dis[v] > dis[u] + e[i].cost){
				dis[v] = dis[u] + e[i].cost;
				q.push(P(dis[v],v));
			}
		}
	}
	
}

ll read(){ ll s=0,f=1; char ch=getchar(); while(ch<'0' || ch>'9'){ if(ch=='-') f=-1; ch=getchar(); } while(ch>='0' && ch<='9'){ s=s*10+ch-'0'; ch=getchar(); } return s*f; }

int main(){
	memset(h,-1,sizeof(h));
	memset(vis,0,sizeof(vis));
	n=read();
	for(int i = 1;i <= n;i++){
		v=read();
		add(i,v,1);
	}

	dij();

	if((h[2] == -1)||vis[2] == 0){
		printf("-1\n");
		return 0; 
	}
	
	printf("%d\n",dis[2]);
	
	return 0;
}

Measured memory_bytes: 6468
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
const int N=2504,INF=0x3f3f3f3f;
struct Edge {
	int v,nxt,w;
}e[N<<1],re[N<<1];
int head[N],rhead[N],etot,retot;
int n,m,P;
bool ok[N],vis[N];
int dis[N],tim[N];
inline void adde(int u,int v,int w) {
	e[++etot].nxt=head[u],e[etot].v=v,e[etot].w=w,head[u]=etot;
}
inline void addr(int u,int v,int w) {
	re[++retot].nxt=rhead[u],re[retot].v=v,re[retot].w=w,rhead[u]=retot;
}
inline int read() {
	int x=0;char c=getchar();
	while (c<'0'||c>'9') c=getchar();
	while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x;
}
inline void prebfs() {
	queue<int> q;
	q.push(n);
	ok[n]=true;
	while (!q.empty()) {
		int p=q.front();
		q.pop();
		for (int i=rhead[p];~i;i=re[i].nxt) {
			int v=re[i].v;
			if (!ok[v]) {
				ok[v]=true;
				q.push(v);
			}
		}
	}
}
inline bool Spfa() {
	queue<int> q;
	memset(vis,false,sizeof(vis));
	memset(dis,-INF,sizeof(dis));
	dis[1]=0;
	q.push(1);
	++tim[1];
	vis[1]=true;
	while (!q.empty()) {
		int p=q.front();
		q.pop();
		vis[p]=false;
		for (int i=head[p];~i;i=e[i].nxt) {
			int v=e[i].v;
			if (ok[v]&&dis[v]<dis[p]+e[i].w) {
				dis[v]=dis[p]+e[i].w;
				if (!vis[v]) {
					vis[v]=true;
					q.push(v);
					++tim[v];
					if (tim[v]>n) return false;
				}
			}
		}
	}
	return true;
}
int main() {
	memset(rhead,-1,sizeof(rhead));
	memset(head,-1,sizeof(head));
	memset(ok,false,sizeof(ok));
	scanf("%d%d%d",&n,&m,&P);
	for (int i=0;i<m;++i) {
		int u=read(),v=read(),w=read();
		adde(u,v,w-P);
		addr(v,u,w-P);
	}
	prebfs();
	if (!Spfa()) puts("-1");
	else printf("%d\n",max(dis[n],0));
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using i128 = boost::multiprecision::int128_t;
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using ld = long double;
using V = vector<int>;
using Vll = vector<ll>;
using Vld = vector<ld>;
using Vbo = vector<bool>;
using VV = vector<V>;
using VVll = vector<Vll>;
using VVld = vector<Vld>;
using VVbo = vector<Vbo>;
using VVV = vector<VV>;
using VVVll = vector<VVll>;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
using Pld = pair<ld, ld>;
#define rep2(i, m, n) for(ll i=int(m); i<int(n); ++i)
#define drep2(i, m, n) for(ll i=int(m)-1; i>=int(n); --i)
#define rep(i, n) rep2(i, 0, n)
#define drep(i, n) drep2(i, n, 0)
#define all(a) a.begin(), a.end()
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
template<typename T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<typename T> istream &operator>>(istream &is, vector<T> &v) { for (auto &e : v) is >> e; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto &e : v) os << e << "\n"; return os; }
template<typename T> inline int count_between(vector<T> &a, T l, T r) { return lower_bound(all(a), r) - lower_bound(all(a), l); } // [l, r)
inline int Log2(ll x) { int k; for (k = 0; x > 0; ++k) x >>= 1; return k; } // number of binary digits
const int INF  = 1<<30;
const ll INFll = 1ll<<62;
const ld EPS   = 1e-10;
const ld PI    = acos(-1.0);
const int MOD  = int(1e9)+7;
// const int MOD  = 998244353;


int main() {
  int n, m; cin >> n >> m;
  VV G(n);
  rep(_, m) {
    int u, v; cin >> u >> v;
    --u, --v;
    G[u].push_back(v);
    G[v].push_back(u);
  }

  vector<array<int, 3>> Q;
  int q; cin >> q;
  rep(_, q) {
    int a, b, c; cin >> a >> b >> c;
    --a;
    Q.push_back({a, b, c});
  }
  reverse(all(Q));

  int x, y, c, u, d;

  V cl(n), mx(n, -1);
  for (auto &qq : Q) {
    x = qq[0], y = qq[1], c = qq[2];
    if (!chmax(mx[x], y)) continue;
    queue<P> que;
    que.emplace(x, y);
    if (cl[x] == 0) cl[x] = c;
    while (!que.empty()) {
      tie(u, d) = que.front(); que.pop();
      for (auto v : G[u]) {
        if (chmax(mx[v], d-1)) {
          que.emplace(v, d-1);
          if (cl[v] == 0) cl[v] = c;
        }
      }
    }
  }

  cout << cl;
  return 0;
}


Measured memory_bytes: 9328
#include <iostream>
#include <cstdio> 　　　　 //定义输入／输出函数
#include <stack>　　　　　 //STL 堆栈容器
#include <map>　　　　　　 //STL 映射容器
#include <vector>　　　　　//STL 动态数组容器
#include <string>　　　　　//字符串类
#include <iterator>        //STL迭代器
#include <cstdlib> 　　　　//定义杂项函数及内存分配函数
#include <cstring> 　　　　//字符串处理ed
#include<algorithm>
#include<queue>
#include<cmath>
#include<ctime>
#include<climits>
#include<iomanip>
#include<sstream>
using namespace std;
#define FOR(ITER,BEGIN,END)  for(int  ITER=BEGIN;ITER<END;ITER++)
#define PER(ITER,TIMES) FOR(ITER,0,TIMES)
#define TIME(TIME_NUMBER) PER(_PETER_MRSCO_ITER_,TIME_NUMBER)	
#define  ll  long long
#define close_stdin  ios::sync_with_stdio(false)
#define inf 0x3f3f3f3f
const int maxn = 200005;
const int mod = 1000000007;
long long  a[maxn];
void solve() {
	int n,k;
	cin >> n>>k;
	ll ans = 1;
	int posive_num = 0, negative_num = 0;
	for (int i = 1;i <= n;i++) {
		cin >> a[i];
		if (a[i] >= 0) { posive_num++; }
		else if (a[i] < 0){negative_num++;}
	}
	if (!posive_num && k % 2 == 1) {
		sort(a + 1, a + 1 + n, greater<int>());
		for (int i = 1;i <= k;i++) {
			ans = ans * a[i] % mod;
		}
	}
	else {
		sort(a+1, a + 1 + n,greater<int>());
		int m = k;
		int l = 1, r = n;
		while (m > 0) {
			if (m & 1) { ans = ans * a[l++] % mod; m--; }
			else if(m>=2) {
					m -= 2;
					if (a[l] * a[l + 1] >= a[r] * a[r - 1]) {
						ans = ans * a[l] % mod;
						ans = ans * a[l + 1] % mod;
						l += 2;
					}
					else {
						ans = ans * a[r] % mod;
						ans = ans * a[r - 1] % mod;
						r -= 2;
					}
				}

			
		}
	}
	cout << (ans%mod+mod)%mod << "\n";

}
int main() {
	close_stdin;
	solve();
}

Measured memory_bytes: 5124
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>

int main(){
  long  n;unsigned long long tmp;unsigned long long m=0;
  std::vector<std::pair<unsigned long long,unsigned long long> > ls;
  std::cin >> n;
  std::vector<unsigned long long> ans(n);
  ls.reserve(n+1);
  for(long i=0; i<n; ++i) {std::cin >> tmp;ls.emplace_back(std::make_pair(tmp,i));}
  ls.emplace_back(std::make_pair(0,n));
  std::stable_sort(ls.begin(),ls.end(),[](auto a,auto b){return a.first>b.first;});
  auto target=ls.begin();
  for(auto it=ls.begin();it!=ls.cend()-1;++it){
    if(target->second>it->second)target=it;
    ans[target->second]+=(it->first-(it+1)->first)*(++m);
  }
  for(unsigned long long x : ans) std::cout<< x <<std::endl;  
  return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define MOD 1000000007

int main(){
  ll X,Y;
  cin>>X>>Y;
  if(abs(X-Y)<=1) cout<<"Brown"<<endl;
  else cout<<"Alice"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
signed main() {
ll n,total=0;
cin>>n;
vector<string> s(n);
for(int i=0;i<n;i++)
{ string ss;

  cin>>ss;
  sort(ss.begin(),ss.end());
  s[i]=ss;
}
//cout<<endl<<endl;
//string str="dcba";
//sort(str.begin(),str.end());
//cout<<"str "<<str<<endl;
sort(s.begin(),s.end());
int temp=0;
for(int i=1;i<n;i++)
{
  //cout<<s[i]<<endl;
  if(s[i]==s[i-1])
  {
    temp++;
    total+=temp;
  }
  else
  {
    temp=0;
  }
  

}
cout<<total<<endl;
}

Measured memory_bytes: 5760
#include<iostream>
#include<vector>
#include<deque>
#include<queue>
#include<algorithm>
using namespace std;
int N,M,T;
vector<pair<long,long> >f(int S,const vector<vector<pair<int,int> > >&G)
{
	vector<vector<long> >d(M+1,vector<long>(N,(long)1e18));
	d[0][S]=0;
	priority_queue<pair<long,pair<int,int> > >P;
	P.push(make_pair(0L,make_pair(0,S)));
	while(!P.empty())
	{
		long c=-P.top().first;
		int u=P.top().second.second,w=P.top().second.first;
		P.pop();
		if(d[w][u]<c)continue;
		for(pair<int,int>e:G[u])
		{
			int v=e.first;
			if(e.second==-1)
			{
				if(w<M&&d[w+1][v]>c)
				{
					d[w+1][v]=c;
					P.push(make_pair(-c,make_pair(w+1,v)));
				}
			}
			else
			{
				if(d[w][v]>c+e.second)
				{
					d[w][v]=c+e.second;
					P.push(make_pair(-c-e.second,make_pair(w,v)));
				}
			}
		}
	}
	deque<pair<long,long> >Q;
	for(long e=M;e>=0;e--)
	{
		long f=d[e][T];
		if(f==(long)1e18)continue;
		while(Q.size()>=2)
		{
			long a=Q[Q.size()-2].first,b=Q[Q.size()-2].second;
			long c=Q.back().first,d=Q.back().second;
			if((c-a)*(f-b)+(d-b)*(a-e)>=0)Q.pop_back();
			else break;
		}
		Q.push_back(make_pair(e,f));
	}
	return vector<pair<long,long> >(Q.begin(),Q.end());
}
main()
{
	int S1,S2;
	while(cin>>N>>M>>S1>>S2>>T,N)
	{
		S1--,S2--,T--;
		vector<vector<pair<int,int> > >G(N);
		for(int i=0;i<M;i++)
		{
			int a,b;string w;
			cin>>a>>b>>w;
			a--,b--;
			if(w=="x")
			{
				G[a].push_back(make_pair(b,-1));
				G[b].push_back(make_pair(a,-1));
			}
			else
			{
				int W=0;
				for(char c:w)W=W*10+c-'0';
				G[a].push_back(make_pair(b,W));
				G[b].push_back(make_pair(a,W));
			}
		}
		vector<pair<long,long> >d1=f(S1,G);
		vector<pair<long,long> >d2=f(S2,G);
		long ans=9e18;
		long pre=0;
		int i1=0,i2=0;
		while(true)
		{
			long t1=1e15,t2=1e15;
			if(i1+1<d1.size())
			{
				long a=d1[i1].first,b=d1[i1].second;
				long c=d1[i1+1].first,d=d1[i1+1].second;
				t1=(d-b+(a-c)-1)/(a-c);
			}
			if(i2+1<d2.size())
			{
				long a=d2[i2].first,b=d2[i2].second;
				long c=d2[i2+1].first,d=d2[i2+1].second;
				t2=(d-b+(a-c)-1)/(a-c);
			}
			long l=pre,r=t1<t2?t1:t2;
			pre=max(pre,r--);
			long a=d1[i1].first,b=d1[i1].second;
			long c=d2[i2].first,d=d2[i2].second;
			while(r-l>3)
			{
				long m1=(l+l+r)/3,m2=(l+r+r)/3;
				if(abs(a*m1+b-(c*m1+d))<abs(a*m2+b-(c*m2+d)))r=m2;
				else l=m1;
			}
			for(long t=l;t<=r;t++)ans=min(ans,abs(a*t+b-(c*t+d)));
			if(t1<=t2)i1++;
			else i2++;
			if(i1==d1.size()||i2==d2.size())break;
		}
		cout<<ans<<endl;
	}
}



Measured memory_bytes: 67696
#include<iostream>
using namespace std;
int main(){
	int h,w;
	cin >> h >> w;
	int n;
	cin >> n;
	int a[10000];
	int c[100][100];
	for(int i=0;i<n;i++) cin >> a[i];
	int p=0;
	int j=0;
	int count=a[p];
	int ori=1;
	for(int i=0;i<h;i++){
		while(count--){
			c[i][j]=p+1;
			j+=ori;
			if(count==0){
				count=a[++p];
			}
			if(i%2==0 && j==w){
				j--;
				break;
			}
			else if(i%2!=0 && j==-1){
				j++;
				break;
			}
		}
		if(count==-1){
			count=a[++p];
		}
		ori*=-1;
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cout << c[i][j] << ' ';
		}
		cout << endl;
	}
}


Measured memory_bytes: 384
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
 
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;

#define  ff          first
#define  ss          second
#define  pb          push_back
#define  IOS         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define  lb          lower_bound
#define  ub          upper_bound
#define  D2(x)       { cerr << "[" << #x << ": "; for(auto it:x) cerr << it << " "; cerr << "]\n"; }
#define  all(x)      (x).begin(), (x).end()
#define  mem(a)      memset(a , 0 ,sizeof a)
#define  deb(x)      cout << #x << " - " << x << "\n";
#define  ps(x,y)     fixed<<setprecision(y)<<x
#define  setbit(x)   __builtin_popcount(x)
#define  deb2(x,y)   cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n"
#define  rep(i,a,b)  for(int i=a ; i<b ; ++i)
 
#define PI 3.141592653589793
const ll p = 5;
const ll INF = 1000000000;
const ll MAX_N = 2e5 + 2;

int main() {
    IOS;
    int n; cin >> n;
    string s; cin >> s;
    int stop,cnt=0;
    set<int>st;
    rep(i,0,n){
        st.insert(s[i]);
        if(cnt == 1){
            stop = i;
            cnt++;
        }
        if(s[i] == 'R') cnt++;
    }
    
    if(st.size() == 1) cout << "0";
    else if(cnt == 1) cout << "1";
    else{
        cnt = 0;
        int l = 0, r = n-1;
        while(1){
            if(l > r) break;
            if(l>=n || r<0) break;
            while(l<n && (s[l] != 'W')) {
                l++;
            }
            while(r>=0 && (s[r] != 'R')) {
                r--;
            }
            swap(s[l],s[r]);
            cnt++;
        }
        cout << max(0,cnt-1);    
    }
}

Measured memory_bytes: 3756
// D - Alter Altar
#include <bits/stdc++.h>
using namespace std;
#define irep(i,s) for(int i=(int)(s);i>=0;--i)

int main(){
	int N; string C; cin>>N>>C;
	int r = 0;
	irep(i, N-1) if(C[i] == 'R') r++;
	irep(i, r-1) if(C[i] == 'R') r--;
	cout<< r <<endl;
}


Measured memory_bytes: 3768
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val h = sc.nextInt()
    val w = sc.nextInt()
    println("#".repeat(w + 2))
    repeat(h) {
        println("#" + sc.next() + "#")
    }
    println("#".repeat(w + 2))
}

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

using namespace std;

int main()
{
    
   long long int x;
   cin>>x;
   int flag=0;
   int c=0,d=0;
   for(int i=-1000;i<=1000;i++)
   {
       for(int j=-1000;j<=1000;j++)
       {
           if(pow(i,5)-pow(j,5)==x)
           {
               d=i;
               c=j;
               flag=1;
               break;
           }
       }
   }
   if(flag==1)
   cout<<d<<" "<<c<<endl;
   
    
    return 0;
}


Measured memory_bytes: 3996
#include <array>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <tuple>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define PB push


#define MOD 1000000007LL
#define EPS 1e-10

int main()
{
    int H, W, h, w;
    cin >> H >> W >> h >> w;
    cout << (H * W - h * W - w * H + h * w) << endl;
    return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }

  vector<vector<int>> L(H + 1, vector<int>(W + 1, 0));
  vector<vector<int>> R(H + 1, vector<int>(W + 1, 0));
  vector<vector<int>> U(H + 1, vector<int>(W + 1, 0));
  vector<vector<int>> D(H + 1, vector<int>(W + 1, 0));

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '#') continue;
      U[i][j] = i == 0 ? 1 : U[i - 1][j] + 1;
      L[i][j] = j == 0 ? 1 : L[i][j - 1] + 1;
    }
  }

  for (int i = H - 1; i > -1; i--) {
    for (int j = W - 1; j > -1; j--) {
      if (S[i][j] == '#') continue;
      D[i][j] = i == H - 1 ? 1 : D[i + 1][j] + 1;
      R[i][j] = j == W - 1 ? 1 : R[i][j + 1] + 1;
    }
  }

  int res = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      res = max(res, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3);
    }
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 67328
def min_day(A,K,T):
    if T == 1:
        return K-1
    else:
        A_max = max(A)
        if A_max <= K - A_max:
            return 0
        else:
            return K-2*(K-A_max)-1

def main():
    K,T = map(int,input().split())
    A = list(map(int,input().split()))

    print(min_day(A,K,T))

if __name__ == "__main__":
    main()


Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int 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()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

ll factorial(ll n) {
  ll answer = 1;
  while (n > 1) {
    answer *= n;
    answer %= mod;
    n--;
  }
  return answer;
}

ll combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

ll permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

template <typename T>
void remove(std::vector<T>& vector, unsigned int index) {
  vector.erase(vector.begin() + index);
}

map<ll, ll> prime_factor(ll n) {
  map<ll, ll> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1) ret[n] = 1;
  return ret;
}
// for (auto p : prime_factor(n)) {
//	while (p.second--) {
//		cout << p.first << endl;
//	}
//}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main() {
  string s;
  cin >> s;
  int n = s.size();
  vector<int> a(n + 1);
  REP(i, n) {
    if (s[i] == '<') {
      a[i + 1] = a[i] + 1;
    }
  }
  RREP(i, n) {
    if (s[i] == '>') {
      a[i] = max(a[i], a[i + 1] + 1);
    }
  }
  ll ans = 0;
  REP(i, n + 1) { ans += a[i]; }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2820
#include <iostream>
#include <stdio.h>
#include <vector>
#include <functional>
#include <unordered_set>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <string>
#include <cstring>
#include <ctime>
#include <cassert>
#include <queue>
#include <stack>
#include <bitset>

using namespace std;

const int N = 1e3 + 1;
const int MOD = 1e9 + 7;

void add(int &a, int b) {
	a += b;
	if (a >= MOD)
		a -= MOD;
}

int dp[N][N];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, m;
	cin >> n >> m;
	dp[0][0] = 1;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < m; ++j) {
			char ch;
			cin >> ch;
			if (ch != '#') {
				add(dp[i + 1][j], dp[i][j]);
				add(dp[i][j + 1], dp[i][j]);
			}
		}
	}
	cout << dp[n - 1][m - 1] << "\n";
	return 0;
}

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

using namespace std;

const int N = 123456;

int n, m, degree[N];
vector<int> adj[N];
bool visit[N];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1, x, y; i <= m; ++i) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
    ++degree[x];
    ++degree[y];
  }
  for (int i = 1; i <= n; ++i) {
    if (degree[i] & 1) {
      cout << "No" << '\n';
      exit(0);
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (degree[i] >= 6) {
      cout << "Yes" << '\n';
      exit(0);
    }
  }
  int total = 0;
  for (int i = 1; i <= n; ++i) {
    if (degree[i] >= 4) {
      ++total;
    }
  }
  if (total >= 3) {
    cout << "Yes" << '\n';
    exit(0);
  } else if (total == 2) {
    int foo = -1, bar = -1;
    for (int i = 1; i <= n; ++i) {
      if (degree[i] >= 4) {
        if (!~foo) {
          foo = i;
        } else {
          bar = i;
        }
      }
    }
    int t = 0;
    function<void (int)> dfs = [&] (int x) {
      visit[x] = true;
      if (x == bar) {
        ++t;
        return;
      }
      for (auto y : adj[x]) {
        if (!visit[y] || y == bar) {
          dfs(y);
        }
      }
    };
    dfs(foo);
    if (t != 4) {
      cout << "Yes" << '\n';
      exit(0);
    }
  }
  cout << "No" << '\n';
  return 0;
}

Measured memory_bytes: 7936
;; ----

(defmacro defsolver (name vars &body body)
  `(defun ,name ()
     (let (,@(mapcar #'list
            vars
            (mapcar (constantly '(read))
                vars)))
       ,@body)))

;; --- solution C

(defsolver sol-c (l r)
  (if (> (- r l) 673)
      (princ 0)
      (let ((nums (loop for x from l to r collect x))
	    (result 2019))
	(loop for i below (length nums) do
	     (loop for j below (length nums)
		when (> j i)
		do
		  (let ((n (mod (* (nth i nums)
				   (nth j nums))
				2019)))
		    (when (> result n)
		      (setf result n)))))
	(princ result))))

(sol-c)

Measured memory_bytes: 16100
#include <stdio.h>
#include <memory.h>
int main(void){
	int t,d,l,x,f[300000],i,sum;
	while(1){
		scanf("%d %d %d",&t,&d,&l);
		if(!t) break;
		memset(f,0,sizeof(f));
		for(i=0;i<t;i++){
			scanf("%d",&x);
			if(x>=l&&i!=t-1){
				f[i]++;
				f[i+d]--;
			}
		}
		sum=0;
		for(i=1;i<=t;i++)
			f[i]+=f[i-1];
		for(i=0;i<t-1;i++){
			if(f[i])
				sum++;
		}
		printf("%d\n",sum);
	}
	return 0;
}

Measured memory_bytes: 1780
from itertools import groupby

s1=input()
k=int(input())

s2=[[h, len(list(g))] for h, g in groupby(s1)] #…(*)

c=0
if len(s2)!=1:
    #接合していない部分の数え上げ
    for i in range(len(s2)):
        #i==0またはlen(s2)-1は接合部なので一旦数えない
        if i!=0 and i!=len(s2)-1:
            c+=(s2[i][1]//2)*k
    #接合部が同じ文字でできているかどうか数え上げの仕方が変わる
    if s2[0][0]==s2[-1][0]:
        c+=((s2[0][1]+s2[-1][1])//2)*(k-1)
        c+=(s2[0][1]//2+s2[-1][1]//2)
    else:
        c+=(s2[0][1]//2+s2[-1][1]//2)*k

else:
    #len(s2)=1の場合は全て同じ文字の文字列になる
    c+=(s2[0][1]*k)//2

print(c)

'''
配列について前から順に要素をまとめていく関数
def groupby(a):
    a2=[[a[0],1]]
    for i in range(1,len(a)):
        if a2[-1][0]==a[i]:
            a2[-1][1]+=1
        else:
            a2.append([a[i],1])
    return a2
s2=groupby(s1)


from itertools import groupby
# チーム番号が割り振られたメンバーリスト
# {'team': チーム番号, 'name': 名前}
members = [{'team': 1, 'name': 'A'},
           {'team': 3, 'name': 'B'},
           {'team': 2, 'name': 'C'},
           {'team': 1, 'name': 'D'},
           {'team': 2, 'name': 'E'}]
# groupbyを使うには、まずはグルーピングしたいキーでソートする必要がある
members.sort(key=lambda m: m['team'])
# チーム番号でグルーピング
for key, group in groupby(members, key=lambda m: m['team']):
    print("key:", key) # キーとして指定したチーム番号を出力
    for member in group:
        print(member) # 同じキー（チーム番号）のメンバーを出力
$ python3 groupby.py
key: 1
{'team': 1, 'name': 'A'}
{'team': 1, 'name': 'D'}
key: 2
{'team': 2, 'name': 'C'}
{'team': 2, 'name': 'E'}
key: 3
{'team': 3, 'name': 'B'}
'''

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

int main() {
	int n, m;
	map<string, int> s, t;
	cin >> n;
	rep(i, n) {
		string tmp;
		cin >> tmp;
		s[tmp]++;
	}
	cin >> m;
	rep(i, m) {
		string tmp;
		cin >> tmp;
		t[tmp]++;
	}
	int ans = 0;
	for (auto tmp: s) {
		int now = tmp.second - t[tmp.first];
		ans = max(ans, now);
	}
	
	cout << ans << endl;
	return 0;
}

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

vector<int> to[200005];
long long int mp[200005];
long long int ans[200005];

void dfs(int v,int p=-1) {
  ans[v]+=mp[v];  
  for (int u : to[v]) {
    if (u != p){
    ans[u]+=ans[v];
    dfs(u,v); 
  }}}

int main(){
    int N,Q;
    cin >> N >> Q;
    long long int x;
    int a,b,p,i;
    for(i=0;i<N-1;i++){
        cin >> a >> b;
        to[a-1].push_back(b-1);
        to[b-1].push_back(a-1);
    }
    for(i=0;i<Q;i++){
        cin >> p >> x;
        mp[p-1]+=x;
    }
    dfs(0);
    for(i=0;i<N-1;i++)cout << ans[i] << " ";
    cout << ans[N-1] << endl;
}

Measured memory_bytes: 25600
package main

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

func main() {
	X := sc.nextInt()
	// var tmp int
	if X%2 == 0 {
		// tmp = 1
	}

	var ans int
	for {
		if isPrime(X) {
			ans = X
			break
		}
		X++
	}
	// for i := X; i <= math.MaxInt64; i += 2 + tmp {
	// 	if isPrime(i) {
	// 		ans = i
	// 		break
	// 	}
	// }
	fmt.Println(ans)
}

func isPrime(X int) bool {
	sqrX := int(math.Sqrt(float64(X)))
	if X == 2 {
		return true
	}
	if X%2 == 0 {
		return false
	}
	for i := 3; i <= sqrX; i += 2 {

		if X%i == 0 {
			return false
		}
	}
	return true
}

/* template functions */
var (
	sc scanner
)

func init() {
	sc = scanner{
		buf: make([]string, 0, 0),
		cur: 0,
		r:   bufio.NewReader(os.Stdin),
	}
}

type scanner struct {
	buf []string
	cur int
	r   *bufio.Reader
}

func (s *scanner) readln() {
	rbuf := make([]byte, 0, 0)
	for {
		line, prefix, err := s.r.ReadLine()
		if err != nil {
			panic(err)
		}
		rbuf = append(rbuf, line...)
		if prefix == false {
			break
		}
	}
	s.cur = 0
	s.buf = strings.Split(*(*string)(unsafe.Pointer(&rbuf)), " ")
}
func (s *scanner) isFull() bool {
	if s.cur == len(s.buf) {
		return true
	}
	return false
}
func (s *scanner) resetCur() {
	s.cur = 0
}
func (s *scanner) next() string {
	if s.cur == 0 {
		s.readln()
	}
	res := s.buf[s.cur]
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nexts() []string {
	s.readln()
	s.resetCur()
	return s.buf
}
func (s *scanner) nextInt() int {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.Atoi(s.buf[s.cur])
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextInts() []int {
	s.readln()
	res := make([]int, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.Atoi(s.buf[i])
	}
	s.resetCur()
	return res
}
func (s *scanner) nextFloat() float64 {
	if s.cur == 0 {
		s.readln()
	}
	res, _ := strconv.ParseFloat(s.buf[s.cur],
		64)
	s.cur++
	if s.isFull() {
		s.resetCur()
	}
	return res
}
func (s *scanner) nextFloats() []float64 {
	s.readln()
	res := make([]float64, len(s.buf))
	for i := range s.buf {
		res[i], _ = strconv.ParseFloat(s.buf[i],
			64)
	}
	s.resetCur()
	return res
}
func digits(x int) int {
	return len(strconv.Itoa(x))
}
func powInt(x, p int) (result int) {
	result = 1
	for i := 0; i < p; i++ {
		result *= x
	}
	return
}
func max(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}
func min(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}
func abs(x int) int {
	return int(math.Abs(float64(x)))
}
func varDump(value ...interface{}) {
	for _, v := range value {
		fmt.Fprintf(os.Stderr, "%#v\n", v)
	}
}
func yes() {
	fmt.Println("Yes")
}
func no() {
	fmt.Println("No")
}


Measured memory_bytes: 640
n=int(input())
cnt=0
for i in range(2,int(n**0.5)+2):
    if n%i==0:
        expo=0
        while n%i==0:
            n//=i
            expo+=1
        j=1
        while expo-j>=0:
            cnt+=1
            expo-=j
            j+=1
if n>1:
    cnt+=1
print(cnt)



Measured memory_bytes: 9276
use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();

    let words: Vec<char> = s
        .trim()
        .chars()
        .filter(|&x| x != ' ')
        .collect();

    let mut ans: [String; 2] = [String::new(), String::new()];

    for _ in 0..words[1].to_digit(10).unwrap() {
        ans[0].push(words[0]);
    }
    for _ in 0..words[0].to_digit(10).unwrap() {
        ans[1].push(words[1]);
    }
    ans.sort();

    println!("{}", ans[0]);
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<memory>

// 基本的には引くべきではない
// 必要なときのみ引くべきだ
// 途中で減少可能かどうかをフラグ管理
//
// いや、差が1だったら常に引いておく、でどうだ
// 差が2の場所を潰せるかどうか問題になる

// 2以上跳ねたときにベースが変わるとしてベースのみ管理

int main(void)
{
        int A, B, C;
        std::cin >> A;
        std::cin >> B;
        std::cin >> C;

        if(C - (A - B) > 0)
        {
                std::cout << C - (A - B) << std::endl;
        }
        else
        {
                std::cout << 0 << std::endl;
        }

        return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#define int long long
using namespace std;
int i,n,m;
signed main()
{
	scanf("%lld%lld",&n,&m);
	if(n==1&&m==1)
	{
		puts("1");
	}else
	if(n==1)
	{
		printf("%lld\n",m-2);
	}else
	if(m==1)
	{
		printf("%lld\n",n-2);
	}else printf("%lld\n",(n-2)*(m-2));
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int q = sc.nextInt();
        String s = sc.next();
        char[] arr = s.toCharArray();

        int[][] lr = new int[q][2];
        for (int i=0; i<q; i++) {
            lr[i][0] = sc.nextInt()-1;
            lr[i][1] = sc.nextInt()-1;
        }

        int[] flag = new int[n+1];

        for (int i=0; i<n-1; i++){
            if (arr[i]=='A'){
                if (arr[i+1]=='C'){
                    flag[i+1] = 1;
                }
            }
        }

        int[] cnt = new int[n+2];
        for (int i=0; i<n; i++){
            cnt[i+1] = cnt[i]+flag[i];
        }

//        for (int i=0; i<n+1; i++)System.out.print(cnt[i]);

        StringBuilder sb = new StringBuilder();

        for (int i=0; i<q; i++){
            int l = lr[i][0];
            int r = lr[i][1];

            sb.append((cnt[r+1]-cnt[l+1])+"\n");
        }

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

    }
}


Measured memory_bytes: 98836
def judge(t,x,y,t0,x0,y0):
  minT=abs(x-x0)+abs(y-y0)
  return (t-t0-minT)>=0 and (t-t0-minT)%2==0
n=int(input())
lst=[tuple(int(i) for i in input().split()) for i in range(n)]
t0=0;x0=0;y0=0
num=0;bool=False
while num<=n-1:
  t,x,y=lst[num]
  if judge(t,x,y,t0,x0,y0):
    t0=t;x0=x;y0=y
    num+=1
    bool=True
  else:
    bool=False
    break
if bool:
  print('Yes')
else:
  print('No')


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

void solver() {
  string s;
  cin >> s;

  vector<int> cnts(2019);
  cnts[0] = 1;

  long long  res = 0;
  long long d = 1;
  for (long long i = s.size()-1; i >= 0; i--) {
    res = res + (s[i] - 48) * d;
    d *= 10;
    d %= 2019;
    res %= 2019;
    cnts[res]++;
  }

  long long ans = 0;
  for (int i = 0; i < cnts.size(); i++) {
    ans += (cnts[i] * (cnts[i] - 1)) / 2;
  }

  cout << ans << "\n";

}

int main() {
  solver();
  return 0;
}


Measured memory_bytes: 3704
import java.util.*;

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

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

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

public class Hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            var bx = new int[n]; var by = new int[n];
            for (int i = 0; i < n; i++)
            {
                string[] line = Console.ReadLine().Trim().Split(' ');
                var id = int.Parse(line[0]) - 1;
                bx[id] = int.Parse(line[1]);
                by[id] = int.Parse(line[2]);
            }
            var dp = new double[n, n];
            var next = new int[n, n];
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++)
                {
                    next[i, j] = j;
                    if (i == j) dp[i, j] = 0;
                    else
                    {
                        var t = checkBuilding(bx, by, i, j);
                        dp[i, j] = t == -1 ? C.INF : Math.Sqrt(t);
                    }
                }
            goWarshall(dp, next);
            var m = int.Parse(Console.ReadLine().Trim());
            for (int i = 0; i < m; i++)
            {
                string[] line2 = Console.ReadLine().Trim().Split(' ');
                var s = int.Parse(line2[0]) - 1;
                var g = int.Parse(line2[1]) - 1;
                putAnswer(dp, next, s, g);
            }
        }
    }
    public static void putAnswer(double[,] dp, int[,] next, int s, int g)
    {
        if (s == g) { Console.WriteLine(s + 1); return; }
        var ret = new List<int>();
        ret.Add(s +1);
        while (true)
        {
            var ns = next[s, g];
            if (dp[s,ns] > 50d) { Console.WriteLine("NA"); return; }
            else
            {
                ret.Add(ns +1);
                if (ns == g) break;
                else s = ns;
            }
        }
        for (int i = 0; i < ret.Count(); i++)
        {
            if (i == ret.Count() - 1) Console.WriteLine(ret[i]);
            else Console.Write("{0} ", ret[i]);
        }

    }
    public static int checkBuilding(int[] bx, int[] by, int a, int b)
    {
        var w = (bx[a] - bx[b]) * (bx[a] - bx[b]) + (by[a] - by[b]) * (by[a] - by[b]);
        return w <= 2500 ? w : -1;

    }
    public static void goWarshall(double[,] dp, int[,] next)
    {
        var n = dp.GetLength(0);
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                for (int k = 0; k < n; k++)
                {
                    if (dp[j, i] + dp[i, k] < dp[j, k])
                    {
                        dp[j, k] = dp[j, i] + dp[i, k];
                        next[j, k] = next[j, i];
                    }
                }
    }
}

Measured memory_bytes: 9532
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define mod2 998244353 
#define PI 3.14159265
#define ll long long
#define ld long double
#define pi pair<ll,ll>
#define pb push_back
#define vi vector<ll>
#define sz size()
#define fi first
#define se second
#define lz length()
#define all(x) (x).begin(),(x).end()
#define scf(x) scanf("%lld",&x)
#define rep(i,n) for(ll i=0;i<n;i++)
const int INF = (int)1e9;
const ll IINF=1LL<<62;
const int maxn=10000005;
//int divr[maxn];
/**/
/*void divisor()
{for(int i=2;i<sqrt(maxn);i++)
     {
          if(!divr[i])
          {
               for(int j=i*i;j<maxn;j+=i)if(!divr[j])divr[j]=i;     
          }
     }
     for(int i=1;i<maxn;i++)if(!divr[i])divr[i]=i;
}*/
 
/*const int N=1000005;
ll n;
struct line {
    long long m, c;
    long long eval(long long x) { return m * x + c; }
    long double intersectX(line l) { return (long double) (c - l.c) / (l.m - m); }
};
vector<pair<pi,ll>> rect;
deque<line> dq;
*/
ll modexpo(ll a,ll b)
{
     ll res=1LL;
     while(b>0)
     {
          if(b&1)res=(res*a)%mod;
          a=(a*a)%mod;
          b>>=1;
     }
     return res;
}













vector<pair<int,int>> adj[100005];
ll dist[100005];
void dfs(int node,int par){
     for(auto child:adj[node])
     {
          if(child.first==par)continue;
          dist[child.fi]=dist[node]+child.se;
          dfs(child.fi,node);
     }
}
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<n;i++){
         int a,b,c;
         cin>>a>>b>>c;
         adj[a].push_back({b,c});
         adj[b].push_back({a,c});
    }
    int q,k;
    cin>>q>>k;
    dist[k]=0;
    dfs(k,-1);
    while(q--){
         int x,y;
         cin>>x>>y;
         cout<<dist[x]+dist[y];
         cout<<"\n";
    }
}



















 
 
 
 
 

 
 
 
 
 
 
 
 
 
 
 
 
 



Measured memory_bytes: 12800
#include <iostream>
#include<string>
#include<set>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<iomanip>
#include<cmath>
#include<stack>
#include <cctype>
#include <cstdio>
#define endl '\n'
#define Bedoazim ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

const long long N = 1e5 + 5, mod = 1e9 + 7;
 
pair<long long, long long>bag[N];

long long dp[105][N];
    
int main() {

    Bedoazim

    int bagsize, n;

    cin >> n >> bagsize;

    

    for (int i = 1; i <= n; i++) {

        cin >> bag[i].first >> bag[i].second;

    }
    
    
    for (int i = 1; i <= n; i++) {

        for (int j = 0; j <= bagsize; j++) {

            long long a = 0, b = 0;

            if (i-1>=0)
                a = dp[i-1][j];

            if (j >= bag[i].first) {

                b = dp[i-1][j - bag[i].first]+bag[i].second;
            
            }

            dp[i][j] = max(a, b);
        }
    }
   
    cout << dp[n][bagsize];

}

Measured memory_bytes: 79360
#include<iostream>
using namespace std;
int main() {
  int N;
  cin >> N;
  long long cnt = 2*N-3;
  int i;
  for(i=2;i*i<N;i++) {
    cnt += 1 + 2*((N-1)/i-i);
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3584
import java.util.*;
import java.io.*;

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

        int[] antenna = new int[5];
        for (int i = 0; i < 5; i++) {
            antenna[i] = Integer.parseInt(sc.next());
        }
        int k = Integer.parseInt(sc.next());

        boolean result = true;
        for (int i = 0; i < 5; i++) {
            for (int j = i + 1; j < 5; j++) {
                if (Math.abs(antenna[i] - antenna[j]) > k) {
                    result = false;
                    break;
                }
            }
            if (result == false) {
                break;
            }
        }
        if (result) {
            out.printf("Yay!\n");
        } else {
            out.printf(":(\n");
        }
        out.flush();
    }
}


Measured memory_bytes: 21844
#include<stdio.h>

int main(void){
int n,x,stack[11],i;
while(scanf("%d",&n),n){

for(i=0;n>0;i++){
x=n%8;
stack[i]=(x==4)?5:(x<4)?x:x+2;
n=n/8;
}
for(;i>0;i--)printf("%d",stack[i-1]);
printf("\n");
}
return 0;
} 

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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    int N;
    ll X[1000],Y[1000],U[1000],V[1000];
    
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> X[i] >> Y[i];
        U[i]=X[i]+Y[i];
        V[i]=X[i]-Y[i];
    }
    for(int i=1;i<N;i++){
        if(((X[i]+Y[i])%2==0)!=((X[0]+Y[0])%2==0)){
            cout << -1 << endl;
            return 0;
        }
    }

    int m=31;
    if((X[0]+Y[0])%2==0) m++;
    cout << m << endl;
    cout << ((X[0]+Y[0])%2==0?"1 1":"1");
    for(int i=1;i<31;i++) cout << " " << (1LL<<i);
    cout << endl;
    for(int i=0;i<N;i++){
        string w="";
        if((X[0]+Y[0])%2==0){
            w="R";
            U[i]--;
            V[i]--;
        }
        ll u=((1LL<<31)-1-U[i])/2;
        ll v=((1LL<<31)-1-V[i])/2;
        for(int j=0;j<=30;j++){
            ll m=1LL<<j;
            if((u&m)==0 && (v&m)==0) w=w+"R";
            if((u&m)==0 && (v&m)!=0) w=w+"U";
            if((u&m)!=0 && (v&m)==0) w=w+"D";
            if((u&m)!=0 && (v&m)!=0) w=w+"L";
        }
        cout << w << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256