akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
    if(c == '-') f = -1;
    c = getchar();
    }
    while(c >= '0' && c <= '9') {
    res = res * 10 + c - '0';
    c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
    out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 998244353;
int N,M;
int a[MAXN],b[MAXN],c[MAXN],dp[MAXN][2];
int d[MAXN][4][4];
map<pii,int> zz;
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
int fpow(int x,int c) {
    int res = 1,t = x;
    while(c) {
        if(c & 1) res = mul(res,t);
        t = mul(t,t);
        c >>= 1;
    }
    return res;
}
void Init() {
    read(N);read(M);
    for(int i = 1 ; i <= N ; ++i) memset(d[i],-1,sizeof(d[i]));
    for(int i = 1 ; i <= M ; ++i) {
        read(a[i]);read(b[i]);read(c[i]);
        zz[mp(a[i],b[i])] = c[i];
        if(abs(a[i] - b[i]) <= 2) {
            int s = a[i],t = b[i];
            if(s > t) swap(s,t);
            for(int k = s - 1 ; k <= t + 1 ; ++k) {
                if(k < 0 || k > N) continue;
                if(abs(a[i] - k) <= 1 && abs(b[i] - k) <= 1) {
                    d[k][2 - (k - a[i])][2 - (k - b[i])] = c[i];
                }
            }
        }
    }

}
void Solve() {
    int64 cnt = 1LL * N * N;
    if(N == 2) cnt = 0;
    else cnt -= (N - 3) * 5 + 9;
    cnt /= 2;
    for(int i = 1 ; i <= M ; ++i) {
        if(abs(b[i] - a[i]) <= 2) continue;
        if(zz.count(mp(b[i],a[i]))) {
            if((zz[mp(b[i],a[i])] + c[i]) & 1) {puts("0");return;}
            if(a[i] < b[i]) --cnt;
        }
        else --cnt;
    }
    int ans = fpow(2,cnt % (MOD - 1));
    if(zz.count(mp(1,1))) dp[1][zz[mp(1,1)]] = 1;
    else dp[1][0] = dp[1][1] = 1;
    for(int i = 2 ; i <= N ; ++i) {
        int t = 1;
        if(d[i][1][2] == -1 && d[i][2][1] == -1) t = mul(t,2);
        if(d[i][1][3] == -1 && d[i][3][1] == -1 && i != N) t = mul(t,2);
        for(int k = 0 ; k <= 1 ; ++k) {
            if(d[i][2][2] != -1 && d[i][2][2] != k) continue;
            if(d[i][1][3] != -1 && d[i][3][1] != -1 && (d[i][1][3] ^ d[i][3][1]) != k) continue;
            for(int h = 0 ; h <= 1 ; ++h) {
                if(!dp[i - 1][h]) continue;
                if(d[i][1][2] != -1 && d[i][2][1] != -1 && (d[i][2][1] ^ d[i][1][2]) != (k ^ h)) continue;
                dp[i][k] = inc(dp[i][k],mul(t,dp[i - 1][h]));
            }
        }
    }
    ans = mul(ans,inc(dp[N][0],dp[N][1]));
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Init();
    Solve();
    return 0;
}

Measured memory_bytes: 11520
# include <iostream>

const int MAX_H = 100;
const int MAX_W = 100;

int h, w;
int c[MAX_H][MAX_W];
int board[MAX_H][MAX_W];

int main() {
	char ch;
	std::cin >> h >> w;
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			std::cin >> ch;
			if (ch == 'c') {
				c[i][j] = 0;
				board[i][j] = 0;
			}
			else {
				c[i][j] = -1;
				board[i][j] = -1;
			}
		}
	}
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			if (c[i][j] == 0) {
				int a = 0;
				for (int k = j; k < w; ++k) {
					board[i][k] = a;
					++a;
				}
			}
		}
	}
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			if (j == 0)
				std::cout << board[i][j];
			else
				std::cout << ' ' << board[i][j];
		}
		std::cout << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1236
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
int N,K;
int main(){
    cin>>N>>K;
    int n=1;
    for(int i=0;i<N;i++){
        if(n<K){
            n+=n;
        }else{
            n+=K;
        }
    }
    cout<<n;
    return 0;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n, a[101010];
void solve(){
	cin >> n;
	int cnt = 0;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
		cnt += abs(a[i]-a[i-1]);
	}
	cnt += abs(a[n]);
	
	for(int i = 1; i <= n; i++){
		cout << cnt-(abs(a[i]-a[i-1])+abs(a[i]-a[i+1]))+abs(a[i-1]-a[i+1]) << endl;
	}
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 1664
#include<stdio.h>
#define MOD 1000000007

typedef long long int lli;


#define kake(a,b) ( (a) *(b)%MOD)

int main(void){
  int n,i;
  scanf("%d",&n);
  char s[n];
  scanf("%s",s);
  int a[26]={};

  for(i=0;i<n;i++)
    a[s[i]-'a']++;
  lli num=1;
  for(i=0;i<26;i++){
    num=kake(num,a[i]+1);
  }

  printf("%ld",num-1);
 
  return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

long long gcd(long long a, long long b) {
    for(;;) {
        if(a == 0)
            return b;
        b %= a;
        if(b == 0)
            return a;
        a %= b;
    }
}
long long lcm(long long a, long long b) {
    long long temp = gcd(a, b);
    return temp ? (a / temp * b) : 0;
}

int main() {
    long long A, B, C, D;
    cin >> A >> B >> C >> D;
    long long E = lcm(C, D);
    long long ac = (A - 1) / C;
    long long ad = (A - 1) / D;
    long long acd = (A - 1) / E;

    long long bc = B / C;
    long long bd = B / D;
    long long bcd = B / E;
    // cout << bc << bd << bcd << endl;
    cout << B - A + 1 - (bc + bd - bcd - (ac + ad - acd)) << endl;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      	int p = sc.nextInt();
      	int q = sc.nextInt();
      	int r = sc.nextInt();
      
      	int[] hoge = {p, q, r};
      	Arrays.sort(hoge);
      	System.out.println(hoge[0] + hoge[1]);
    }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(long long i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
const int INF = 1e18;

signed main(){
    int n, q; cin >> n >> q;
    vector<pair<int,int>> event;
    multiset<int> loc;
    REP(i,n){
        int s, t, x; cin >> s >> t >> x;
        event.eb(s-x, x);
        event.eb(t-x,-x);
    }
    int ans[q];
    REP(i,q){
        int d; cin >> d;
        event.eb(d,INF+i);
    }
    sort(all(event));
    for(auto p:event){
        if(p.second > 0 and p.second < INF) loc.insert(p.second);
        if(p.second < 0) loc.erase(loc.lower_bound(-p.second));
        if(p.second >= INF) ans[p.second-INF] = (*loc.begin() != 0 ? *loc.begin() : -1);
    }
    REP(i,q) cout << ans[i] << '\n';
}

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

#define int long long

main()
{
  int n, p;
  int odd = 0, ab = 0;
  
  cin >> n >> p;
  
  for(int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if(a & 1) odd++;
    else ab++;
  }
  
  int sum = 1 - p;
  for(int i = 1; i <= n; i++) {
    for(int j = p; j <= min(i, odd); j += 2) {
      if(ab < (i - j)) continue;
      int g = 1, d = 2;
      for(int k = odd, cnt = 0; k >= 1 && cnt < j; k--, cnt++) {
	g *= k;
	while(d <= j && g % d == 0) {
	  g /= d, d++;
	}
      }
      d = 2;
      for(int k = ab, cnt = 0; k >= 1 && cnt < i - j; k--, cnt++) {
	g *= k;
	while(d <= i - j && g % d == 0) {
	  g /= d, d++;
	}
      }
      sum += g;
    }
  }

  cout << sum << endl;

  return (0);
}


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

struct SCC {
  vector< vector<int> > graph, rgraph, dag;
  vector< pair<int, int> > edges;
  vector<int> cmp, selfloop;
  SCC(int V):graph(V), rgraph(V), cmp(V, -1), selfloop(V, 0){}
  void add_edge(int from, int to) {
    graph[from].push_back(to);
    rgraph[to].push_back(from);
    edges.emplace_back(from, to);
  }
  void dfs(int u, vector<int>& ord, vector<int>& used) {
    if(used[u]) return;
    used[u] = 1;
    for(int v : graph[u]) dfs(v, ord, used);
    ord.push_back(u);
  }
  void rdfs(int u, int& id) {
    if(~cmp[u]) return;
    cmp[u] = id;
    for(int v : rgraph[u]) rdfs(v, id);
  }
  int build() {
    vector<int> ord, used(graph.size(), 0);
    for(int u = 0; u < (int)graph.size(); u++) dfs(u, ord, used);
    reverse(ord.begin(), ord.end());
    int sz = 0;
    for(int u : ord) if(cmp[u] == -1) rdfs(u, sz), sz++;

    dag.resize(sz);
    set< pair<int, int> > st;
    for(auto e : edges) {
      int u = cmp[e.first], v = cmp[e.second];
      if(u == v) {
	selfloop[u] = 1;
	continue;
      }
      if(st.count(make_pair(u, v))) continue;
      dag[u].push_back(v);
      st.emplace(u, v);
    }

    return sz;
  }
};

int N, M, T;
vector<int> p, t, k;

int dp[101][10010];

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  while(cin >> N >> M >> T, N+M+T) {
    resz(p, N), resz(t, N), resz(k, N);
    rep(i, N) cin >> p[i] >> t[i] >> k[i];


    SCC graph(N);
    rep(i, M) {
      int a, b;
      cin >> a >> b;
      --a, --b;
      graph.add_edge(a, b);
    }
    graph.build();


    auto& dag = graph.dag;
    auto& cmp = graph.cmp;
    int n = dag.size();
    vector< vector<int> > cmp_id(n);
    rep(i, N) cmp_id[cmp[i]].push_back(i);


    memset(dp, 0, sizeof(dp));
    rep(id, n) {
      for(int i : cmp_id[id]) {
	int lim = (cmp_id[id].size() > 1 || graph.selfloop[id] ? k[i] : 1);
	for(int l = 0; lim > 0; l++) {
	  int num = min(lim, 1LL<<l);
	  for(int j = T; j >= t[i]*num; j--) chmax(dp[id][j], dp[id][j-t[i]*num]+p[i]*num);
	  lim -= num;
	}
      }
      for(int to : dag[id]) rep(j, T+1) chmax(dp[to][j], dp[id][j]);
    }


    int ans = 0;
    rep(i, n) rep(j, T+1) chmax(ans, dp[i][j]);
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 11168
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=100000+10;
int h[maxn],go[maxn*2],nxt[maxn*2],L[maxn],R[maxn],v[maxn];
bool bz[maxn];
int i,j,k,l,t,n,m,tot;
bool czy;
void add(int x,int y){
	go[++tot]=y;
	nxt[tot]=h[x];
	h[x]=tot;
}
void dfs(int x,int y){
	int t=h[x];
	while (t){
		if (go[t]!=y){
			dfs(go[t],x);
			if (!czy) return;
			bz[x]|=bz[go[t]];
		}
		t=nxt[t];
	}
	if (v[x]!=-1) bz[x]=1;
	if (!bz[x]) return;
	int l,r;
	bool gjx=0;
	if (v[x]!=-1){
		gjx=1;
		l=r=v[x];
	}
	t=h[x];
	while (t){
		if (go[t]!=y&&bz[go[t]]){
			if (!gjx){
				gjx=1;
				l=L[go[t]]-1;
				r=R[go[t]]+1;
			}
			else{
				if (R[go[t]]+1<l||L[go[t]]-1>r||l%2!=(L[go[t]]-1)%2){
					czy=0;
					return;
				}
				l=max(l,L[go[t]]-1);
				r=min(r,R[go[t]]+1);
			}
		}
		t=nxt[t];
	}
	L[x]=l;R[x]=r;
}
void dg(int x,int y){
	if (x!=1){
		if (!bz[x]) v[x]=v[y]+1;
		else if (L[x]<=v[y]+1&&v[y]+1<=R[x]) v[x]=v[y]+1;
		else v[x]=v[y]-1;
	}
	int t=h[x];
	while (t){
		if (go[t]!=y) dg(go[t],x);
		t=nxt[t];
	}
}
int main(){
	scanf("%d",&n);
	fo(i,1,n-1){
		scanf("%d%d",&j,&k);
		add(j,k);add(k,j);
	}
	fo(i,1,n) v[i]=-1;
	scanf("%d",&m);
	fo(i,1,m){
		scanf("%d%d",&j,&k);
		v[j]=k;
	}
	czy=1;
	dfs(1,0);
	if (!czy){
		printf("No\n");
		return 0;
	}
	printf("Yes\n");
	v[1]=L[1];
	dg(1,0);
	fo(i,1,n) printf("%d\n",v[i]);
}

Measured memory_bytes: 8704
#include <iostream>
#include<math.h>
#include <algorithm>
#include<string>
using namespace std;

int main() {
        int A, B, C, X, Y;
        int Min;
        int ans=0;

        cin >> A >> B >> C >> X >> Y;

        Min=min(X,Y);

        ans+=min({X*A+Y*B,Min*2*C+(X-Min)*A+(Y-Min)*B,Min*2*C+(X+Y-2*Min)*2*C});

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	cin >> a >> b >> c;
	for(int i=0;i<101;i++){
		if((a*i)%b==c){
			cout << "YES" << endl;
			return 0;
		}else{
			continue;
		}
	}
	cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
S=input()
if S=='RRR':
    print(3)
if S=='RRS':
    print(2)
if S=='RSR':
    print(1)
if S=='RSS':
    print(1)
if S=='SRR':
    print(2)
if S=='SRS':
    print(1)
if S=='SSR':
    print(1)
if S=='SSS':
    print(0)

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

int main(){
	int n;
	int a[10000];
	while(true){
		cin >> n;
		if(n==0)
			break;

		for(int i=0; i<n; i++){
			cin >> a[i];
		}
		int ave = 0;
		for(int i=0; i<n; i++){
			ave = ave + a[i];
		}
		ave = ave/n;
		int num = 0;
		for(int i=0; i<n; i++){
			if(a[i]<=ave){
				num++;
			}
		}
		cout << num << endl;
	}
	return 0;
}


Measured memory_bytes: 3136
#include<iostream>
#include<string>
#include<queue>
#include<utility>
using namespace std;
#define ii pair<int,int>
const int INF=1e9;
int H,W;
vector<string> S(20);
vector<vector<int> > D(20,vector<int>(20,INF));
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};

int bfs(int y,int x){
    int res=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            D[i][j]=INF;
        }
    }
    D[y][x]=0;
    queue<ii> que;
    que.push(make_pair(y,x));
    while(!que.empty()){
        ii p=que.front();que.pop();
        int sy=p.first,sx=p.second;
        for(int i=0;i<4;i++){
            int ny=sy+dy[i],nx=sx+dx[i];
            if(ny>=0&&ny<H&&nx>=0&&nx<W&&S[ny][nx]=='.'&&D[ny][nx]==INF){
                D[ny][nx]=D[sy][sx]+1;
                que.push(make_pair(ny,nx));
                if(res<D[ny][nx]) res=D[ny][nx];
            }
        }
    }
    return res;
}

int main(){
    cin>>H>>W;
    for(int i=0;i<H;i++){
        cin>>S[i];
    }
    int ans=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(S[i][j]=='.'){
                int res=bfs(i,j);
                if(res>ans) ans=res;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#参照　https://atcoder.jp/contests/abc118/submissions/4292288
n,m = map(int, input().split())
b = [0,2,5,5,4,5,6,3,7,6]
a = [0]+list(map(int, input().split()))
f = [-1]*(n+1)
f[0]=0
for i in range(1,n+1):
    for j in range(1,m+1):
        x = a[j]
        if(i-b[x]<0):
            continue
        f[i] = max(f[i],f[i-b[x]]*10 + x)
        #print(i+1,"番目に,",str(f[i])+","+str(f[i-b[x]]*10 + x),"の最大値を入れると",f)
print(f[n])

Measured memory_bytes: 14516
#include<stdio.h>
int main(){
  long long a,b,x;
  scanf("%lld %lld %lld",&a,&b,&x);
  long long bDIVx = b/x + 1LL; 
  long long aDIVx = a ? ((a-1LL)/x + 1LL) : 0LL;
  printf("%lld\n", bDIVx - aDIVx);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=100000000000000000;


int main() {
    string s;
    cin >> s;
    ll l=s.size();
    map<char,ll> m;
    ll ans=1+(l-1)*l/2;
    rep(i,l){
        m[s[i]]++;
    }
    for (auto it=m.begin();it!=m.end();++it){
        ll r=it->second;
        ans-=(r-1)*r/2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
#define PI 3.14159265358979
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repp(i, s, e) for(int i = (s); i <= (e); ++i)
#define sz(x) ((int)x.size())
#define all(x) x.begin(), x.end()
#define FAST_IO() ios::sync_with_stdio(0); cin.tie(0)
template<typename T>
ostream& operator<<(ostream &os, const vector<T> &v) { for (auto x : v) os << x << " "; return os << "\n"; }
template<class U, class V>
ostream& operator<<(ostream &os, const pair<U, V> &p) { return os << "(" << p.first << "," << p.second << ")";}

int main() {
    FAST_IO();
    int N; cin >> N;
    vector<pii> A(N);
    rep(i, N) cin >> A[i].first >> A[i].second;
    sort(all(A), [](const pii &a, const pii &b){
        return make_pair(a.second, -a.first) < make_pair(b.second, -b.first);
    });
    vector<int> LEFT_S(N), LEFT_E(N), RIGHT_S(N), RIGHT_E(N);
    LEFT_S[0] = A[0].first;
    LEFT_E[0] = A[0].second;
    repp(i, 1, N - 1) {
        LEFT_S[i] = max(LEFT_S[i - 1], A[i].first);
        LEFT_E[i] = LEFT_E[i - 1];
    }
    RIGHT_S[N - 1] = A[N - 1].first;
    RIGHT_E[N - 1] = A[N - 1].second;
    for(int i = N - 2; i >= 0; --i) {
        RIGHT_S[i] = max(RIGHT_S[i + 1], A[i].first);
        RIGHT_E[i] = min(RIGHT_E[i + 1], A[i].second);
    }
    // case 1 : one + others
    int ans = 0;
    rep(i, N - 1) {
        int sum = A[i].second - A[i].first + 1;
        int s = max(LEFT_S[i - 1], RIGHT_S[i + 1]);
        int e = min(LEFT_E[i - 1], RIGHT_E[i + 1]);
        sum += max(0, e - s + 1);
        ans = max(ans, sum);
    }
    // case 2 : LEFT(i) + RIGHT(i + 1)
    rep(i, N - 1) {
        int sum = max(0, LEFT_E[i] - LEFT_S[i] + 1) + max(0, RIGHT_E[i + 1] - RIGHT_S[i + 1] + 1);
        ans = max(ans, sum);
    }
    cout << ans << "\n";
    // cout << LEFT_S << LEFT_E << RIGHT_S << RI
}


Measured memory_bytes: 2560
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int x = sc.nextInt();
    int t = sc.nextInt();
    
    if(n%x != 0){
      int k = n/x+1;
      System.out.println(k*t);
      return;
    }else{
      int l = n/x;
      System.out.println(l*t);
      return;
    }
    
  }
}

Measured memory_bytes: 35624
/****************************************************
*   Template for coding contests                    *
*   Author    :    Sanjeev Sharma                   *
*   Email     :    thedevelopersanjeev@gmail.com    *
*****************************************************/
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >>n;
    vector<int> arr(n);
    for(int i = 0; i < n; i++)
        cin >>arr[i];
    vector<int> l(n+1), r(n+1);
    l[0] = r[n] = 0;
    for(int i = 1; i < n+1; i++)
        l[i] = __gcd(l[i-1], arr[i-1]);
    for(int i = n-1; i >= 0; i--)
        r[i] = __gcd(r[i+1], arr[i]);
    int ans = INT_MIN;
    for(int i = 0; i < n; i++)
        ans = max(ans, __gcd(l[i], r[i+1]));
    cout <<ans;
    return 0;
}


Measured memory_bytes: 1408
n, m, c = [int(i) for i in input().split(' ')]
b = [int(i) for i in input().split(' ')]
 
r = 0
for i in range(n):
  a = [int(i) for i in input().split(' ')]
  s = 0
  for j in range(m):
    s += a[j] * b[j]
  s += c
  if s > 0:
    r += 1
  
print(r)

Measured memory_bytes: 3060
n, m = map(int, input().split())
VW = [tuple(map(int, input().split())) for i in range(n)]
V = [v for v, w in VW]
W = [w for v, w in VW]
# n, m = 4, 8
# V = [4, 5, 2, 8]
# W = [2, 2, 1, 3]
# DP[i][j]=i個の品物で重さj以内で最大価値
DP = [[0 for j in range(m+1)] for i in range(n+1)]
for i in range(n):
    for j in range(m+1):
        if j < W[i]:
            DP[i+1][j] = DP[i][j]
        else:
            DP[i+1][j] = max(DP[i][j], DP[i+1][j-W[i]]+V[i])
print(DP[n][m])



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

int main() {
    ll N;
    cin >> N;
    map<ll,ll> mp;
    for(int i=0;i<N;i++){
        ll a;
        cin >> a;
        mp[a]++;
    }
    ll ans =0;
    for(auto itr = mp.begin();itr != mp.end();++itr){
        if(itr->first < itr->second){
            ans += (itr->second -itr->first);
        }else if(itr->first > itr->second){
            ans += itr->second;
        }
    }
    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 9460
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2")

#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;

#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

inline void setin(string s) {
	freopen(s.c_str(), "r", stdin);
}

inline void setout(string s) {
	freopen(s.c_str(), "w", stdout);
}

template <typename T> inline T range(T l, T r) {
	return uniform_int_distribution <T>(l, r)(rng);
}

template <typename T> void Min(T &a, T b) {
    a = min(a, b);
}
 
template <typename T> void Max(T &a, T b) {
    a = max(a, b);
}

#define int long long

const int inf = 2e9;
const int mod = 1e9 + 7;
const int N = 3e2 + 15;
const int S = 0;
const int T = N - 1;
int n, a[N];

int d[N];

struct edge {
	int v, c;
};

vector <edge> e;
vector <int> g[N];

inline void add_edge(int u, int v, int c) {
	g[u].pb(e.size());
	e.pb({v, c});

	g[v].pb(e.size());
	e.pb({u, 0});
}

int q[N], ql, qr;
bool used[N];

int ptr[N];

inline bool bfs() {
	memset(used, 0, sizeof(used));
	d[S] = 0;
	q[ql = qr = 0] = S;
	used[S] = true;
	while(ql <= qr) {
		int v = q[ql++];
		for(int ind : g[v]) {
			int to = e[ind].v, cap = e[ind].c;
			if(cap <= 0)
				continue;
			if(!used[to]) {
				used[to] = true;
				d[to] = d[v] + 1;
				q[++qr] = to;
			}
		}
	}
	return used[T];
}

int dfs(int v, int cmin) {
	if(v == T || cmin == 0)
		return cmin;
	for(; ptr[v] < g[v].size(); ++ptr[v]) {
		int ind = g[v][ptr[v]];
		int to = e[ind].v, cap = e[ind].c;
		if(cap <= 0)
			continue;
		if(d[to] == d[v] + 1) {
			int flow = dfs(to, min(cmin, cap));
			if(flow) {
				e[ind].c -= flow;
				e[ind ^ 1].c += flow;
				return flow;
			}
		}
	}
	return 0;
}

main() {
	ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
	// setin("input.txt");
	cin >> n;
	for(int i = 1; i <= n; ++i)
		cin >> a[i];
	int ans = 0;
	for(int i = 1; i <= n; ++i) {
		if(a[i] >= 0) {
			ans += a[i];
			add_edge(i, T, a[i]);
		}
		else {
			add_edge(S, i, -a[i]);
			for(int j = i + i; j <= n; j += i)
				// if(a[j] >= 0)
					add_edge(i, j, inf);
		}
	}
	while(bfs()) {
		memset(ptr, 0, sizeof(ptr));
		while(int flow = dfs(S, inf))
			ans -= flow;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
def resolve():
    n = int(input())
    a = list(map(int, input().split()))

    ans = 0
    mod = (10 ** 9) + 7
    csum = sum(a)

    for i in range(n):
        csum -= a[i]
        ans += a[i] * csum

    ans = int(ans % mod)
    print(ans)
 
resolve()


Measured memory_bytes: 31488
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int a,b,c;cin >> a >> b >>c;
  int sum = a+b+c;
  YesNo(max(a,max(b,c)) == sum - max(a,max(b,c)));
  return 0;
}


Measured memory_bytes: 256
n=int(input())
sps=dict()
for i in range(n):
    s,p=input().split()
    if not s in sps:
        sps[s]=[]
    sps[s].append([int(p),i+1])
for k in sorted(list(sps.keys())):
    for _,v in sorted(sps[k], reverse=True):
        print(v)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e11;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
  public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

void solve(long long A, long long B, long long Q, std::vector<long long> s, std::vector<long long> t, std::vector<long long> x)
{
    for (ll i = 0; i < Q; i++)
    {
        ll q = x[i];

        int posA = lower_bound(s.begin(), s.end(), q) - s.begin();
        int posB = lower_bound(t.begin(), t.end(), q) - t.begin();
        ll ans = INF;

        ans = min(ans, abs(min(s[posA - 1], t[posB - 1]) - q));
        ans = min(ans, abs(max(s[posA], t[posB]) - q));

        ans = min(ans, abs(s[posA] - q) + abs(s[posA] - t[posB - 1]));
        ans = min(ans, abs(t[posB - 1] - q) + abs(s[posA] - t[posB - 1]));

        ans = min(ans, abs(s[posA - 1] - q) + abs(s[posA - 1] - t[posB]));
        ans = min(ans, abs(t[posB] - q) + abs(s[posA - 1] - t[posB]));

        cout << ans << endl;
    }
}

int main()
{
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    long long Q;
    scanf("%lld", &Q);
    std::vector<long long> s(A + 2);
    s[0] = (-1 * INF);
    s[A + 1] = INF;
    for (int i = 1; i <= A; i++)
    {
        scanf("%lld", &s[i]);
    }

    std::vector<long long> t(B + 2);
    t[0] = (-1 * INF);
    t[B + 1] = INF;
    for (int i = 1; i <= B; i++)
    {
        scanf("%lld", &t[i]);
    }

    std::vector<long long> x(Q);
    for (int i = 0; i < Q; i++)
    {
        scanf("%lld", &x[i]);
    }
    solve(A, B, Q, std::move(s), std::move(t), std::move(x));
    return 0;
}


Measured memory_bytes: 3712
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <time.h>
#include <complex>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
using ld = long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
typedef long long ll;

typedef char         Char;
typedef const Char*  String;

bool compare_str(const char* lhs, const char* rhs)
{
	return std::strcmp(lhs, rhs) < 0;
}

int int_sort(const void * a, const void * b) {
	return strcmp((char *)a, (char *)b);
}

int qsort_cmp(const void* p1, const void* p2) {
	const String &s1 = *(const String *)p1;
	const String &s2 = *(const String *)p2;
	return strcmp(s1, s2);
}
int compare_c(const void *chr1, const void *chr2)
{
	char **c1 = (char **)chr1;
	char **c2 = (char **)chr2;
	return strcmp(*c1, *c2);
}

int main(){

	//int N, M, *A, *B, i, j, *W, *flag, sum=0, start, end, length, tmp;
	int i, N, K, H, W, A, B, **ans, flag = 0, j, ans_0 = 0, ans_W = 0, len, max_i=0, ten, eight;
//	int A[200000];


	scanf("%d %d", &A, &B);

	for (i = 0; i < 10000; i++){
		eight = i * 8 / 100;
		ten = i / 10;
		if (eight == A && ten == B){
			printf("%d\n", i);
			return 0;
		}
	}

	printf("-1\n");

	return 0;

}
    


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

using namespace std;

bool isPrime[(int)1e7 + 1];

int main()
{
    fill_n(isPrime, 1e7 + 1, true);
    isPrime[0] = isPrime[1] = false;
    for (int i = 2; i <= 1e4; i++)
    {
        if(!isPrime[i]) continue;
        for (int j = 2; i * j <= 1e7; j++)
        {
            isPrime[i * j] = false;
        }
    }
    int N;
    while (cin >> N, N)
    {
        for (int i = N; i >= 8; i--)
        {
            if (isPrime[i] && isPrime[i - 2] && isPrime[i - 6] && isPrime[i - 8])
            {
                printf("%d\n", i);
                break;
            }
        }
    }
    return 0;
}

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

int main( void ) {
    
    int n, m;
    cin >> n >> m;
    
    for( int i = 1; i <= n; i ++ ) {
        for( int j = 1; j <= m; j ++ ) {
            string str;
            cin >> str;
            
            if( str == "snuke" ) {
                cout << (char) (j - 1 + 'A') << i << endl;
                return 0;
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
	int n;
	while(cin >> n && n){
		int l=0, sl=0, d=0, sd=0, m=0, sm=0;
		int hh,mm, MM;
		for(int i=0;i<n;i++){
			cin >> hh;
			cin.ignore(); // for ":"
			cin >> mm >> MM;
			if(mm > MM) MM+=60;
			bool overed;
			MM-mm<=8?overed=false:overed=true;
			if(11 <= hh && hh <= 14){
				sl++;
				if(!overed)l++;
			}else if(18 <= hh && hh <= 20){
				sd++;
				if(!overed)d++;
			}else if((21 <= hh && hh <= 24) ||
			hh <= 1){
				sm++;
				if(!overed)m++;
			}
		}
		cout << "lunch ";
		if(sl == 0){
			cout << "no guest" << endl;
		}else{
			cout << 100*l/sl << endl;
		}
		cout << "dinner ";
		if(sd == 0){
			cout << "no guest" << endl;
		}else{
			cout << 100*d/sd << endl;
		}
		cout << "midnight ";
		if(sm == 0){
			cout << "no guest" << endl;
		}else{
			cout << 100*m/sm << endl;
		}
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

const int MAX_V = 1010;

vector<T> edge;
vector<ll> d1(MAX_V), d2(MAX_V);
int v, e;

void bellman_ford1(int s){
    for(int i=0; i<v; i++) d1[i] = INF;
    d1[s] = 0;
    
    for(int i=0; i<v; i++){
        for(int j=0; j<e; j++){
            int cv, nv, cost;
            tie(cv, nv, cost) = edge[j];

            if(d1[cv] != INF && d1[nv] > d1[cv] + cost){
                d1[nv] = d1[cv] + cost;
            }
        }
    }
}

void bellman_ford2(){
    for(int i=0; i<v; i++) d2[i] = d1[i];
    
    for(int i=0; i<v; i++){
        for(int j=0; j<e; j++){
            int cv, nv, cost;
            tie(cv, nv, cost) = edge[j];

            if(d2[cv] != INF && d2[nv] > d2[cv] + cost){
                d2[nv] = d2[cv] + cost;
            }
        }
    }
}

int main(){
    int r; cin>>v>>e>>r;
    for(int i=0; i<e; i++){
        int s, t, d; cin>>s>>t>>d;
        edge.eb(T(s, t, d));
    }

    bellman_ford1(r);
    bellman_ford2();

    bool negative = false;
    for(int i=0; i<v; i++){
        if(d1[i] != d2[i]){
            negative = true;
        }
    }

    if(negative){
        cout << "NEGATIVE CYCLE" << endl;
    }
    else{
        for(int i=0; i<v; i++){
            if(d1[i] == INF) cout << "INF" << endl;
            else cout << d1[i] << endl;
        }
    }
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
typedef complex<double> P;
double dot(P a, P b){ //内積
    return (a.real() * b.real() + a.imag() * b.imag());
}

double cross(P a, P b){ //外積
    return (a.real() * b.imag() - a.imag() * b.real());
}

bool is_orth(P a1, P a2, P b1, P b2){ //垂直か
    return EQ(dot(a1 - a2, b1 - b2), 0.0);
}

bool is_para(P a1, P a2, P b1, P b2){ //平行か
    return EQ(cross(a1 - a2, b1 - b2), 0.0);
}

bool is_online(P a, P b, P c){ //cが線分上か
    return (abs(a-c) + abs(c-b) < abs(a-b) + EPS);
}

bool distance_lp(P a, P b, P c){ //直線abと点cの距離
    return abs(cross(b-a, c-a)) / abs(b-a);
}

double norm(P a){
  return a.real() * a.real() +a.imag() *a.imag();
}

ll ccw(P p0,P p1,P p2){
  P a = p1-p0;
  P b = p2-p0;
  if(cross(a,b) > EPS) return 1;
  if(cross(a,b) < -EPS) return -1;
  if(dot(a,b) < -EPS) return 2;
  if(abs(a) < abs(b)) return -2;
  return 0;
}

bool is_intersect(P p1, P p2, P p3, P p4){
  return (ccw(p1,p2,p3) * ccw(p1,p2,p4) <= 0 &&
      ccw(p3,p4,p1) * ccw(p3,p4,p2) <= 0 );
}

P intersect_pos(P a1, P a2, P b1, P b2){ //直線同士の交点
    P a = a2 - a1;
    P b = b2 - b1;
    return a1 + a * cross(b, b1 - a1) / cross(b, a);
}

double getDistanceLP(P a1, P a2, P b){
    return abs(cross(a2-a1, b-a1) / abs(a2 - a1));
}

double getDistanceSP(P a1, P a2, P b){
    if(dot(a2 - a1, b - a1) < EPS) return abs(b - a1);
    if(dot(a1 - a2, b - a2) < EPS) return abs(b - a2);
    return getDistanceLP(a1, a2, b);
}
double getDistance(P a1, P a2, P b1, P b2){
    if(is_intersect(a1, a2, b1, b2)) return 0.0;
    double v1 = min(getDistanceSP(a1, a2, b1), getDistanceSP(a1, a2, b2));
    double v2 = min(getDistanceSP(b1, b2, a1), getDistanceSP(b1, b2, a2));
    return min(v1,v2);
}

#define printP(P) cout << "(" << P.real() << ", " << P.imag() << ")" << endl;




int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll q;
    cin >> q;
    while(q--){
        double x0, y0, x1, y1, x2, y2, x3, y3;
        cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
        P p0(x0,y0), p1(x1, y1), p2(x2, y2), p3(x3, y3);
        double ans = getDistance(p0, p1, p2, p3);
        cout << setprecision(16) << ans << endl;
    }
}


Measured memory_bytes: 3372
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define ll long long
#define P pair<ll, ll>
const ll MOD = 1e9 + 7;
int main() {
	int n;
	cin >> n;
	vector<pair<pair<string, int>, int>> sp(n);
	for (int i = 0; i < n; i++) {
		cin >> sp[i].first.first >> sp[i].first.second;
		sp[i].first.second = -sp[i].first.second;
		sp[i].second = i + 1;
	}
	sort(ALL(sp));
	for (int i = 0; i < n; i++) {
		cout << sp[i].second << '\n';
	}
}

Measured memory_bytes: 256
from sys import stdin
from collections import defaultdict as dd
from collections import deque as dq
import itertools as it
from math import sqrt, log, log2
from fractions import Fraction

# t = int(input())
# for _ in range(t):
# n, m = map(int, input().split())
# nums = list(map(int, stdin.readline().split()))
a = int(input())
print(a + a**2 + a**3)

Measured memory_bytes: 77332
///   Journey to the End of earth   ///
/// Gunjan Kumar ///
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// #include <functional> // for less 
// using namespace __gnu_pbds; 
using namespace std;
#define ll  long long
#define s(n) scanf("%d",&n)
#define ls(n) scanf("%lld",&n)
#define p(n) printf("%d",n)
// #define ln() printf("\n")
#define pln(n) printf("%d\n",n)
#define lpln(n) printf("%lld\n",n)
#define rep(i,a,n) for(int i=a;i<n;i++)
#define rev(i,a,n) for(int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define tc           ll t1; cin>>t1; while(t1--)
#define inp         ll n; cin>>n; ll arr[n]; rep(i,0,n) cin>>arr[i];
#define vect vector<ll>
#define sortv(v)       sort(v.begin(),v.end())
#define lower(v,n)    lower_bound(v.begin(),v.end(),n)-v.begin()
#define upper(v,n)    upper_bound(v.begin(),v.end(),n)-v.begin()
#define bitcount(n) __builtin_popcount(n)
#define ln <<endl
#define inf          LONG_MAX
#define ninf         LONG_MIN
#define fast         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const   ll mod=1e9+7;
const ll N=3e2+5;

double dp[N][N][N];

double solve(int one,int two,int three,int& n)
{
  if(one<0 || two<0 || three<0)
    return 0;
  if (one==0 && two==0 && three==0)
  {
    return 0;
  }
  if(dp[one][two][three]>0)
    return dp[one][two][three];
  int rem=one+two+three;
  
  double expected_value=n+one*solve(one-1,two,three,n)+two*solve(one+1,two-1,three,n)+three*solve(one,two+1,three-1,n);
  return dp[one][two][three]=expected_value/rem;
}

int main()
{

         
         int n;
         cin >> n;
        int  freq[4]={0};
         rep(i,0,n)
         {
           int x;
           cin >> x;
           freq[x]++;
         } 
         memset(dp,-1,sizeof(dp));
         cout<<fixed<<setprecision(10)<<solve(freq[1],freq[2],freq[3],n);

     return 0;
}



Measured memory_bytes: 225484
def is_OK(i, not_dislike):
    dig_OK = []
    tmp = str(i)
    i_list = [int(tmp[j]) for j in range(len(tmp))]
    for l in i_list:
        if l in not_dislike:
            dig_OK.append(True)
        else:
            dig_OK.append(False)
    return all(dig_OK)

N, K = list(map(int, input().split()))
D = [int(a) for a in input().split()]
not_dislike = []
for i in range(10):
    if i not in D:
        not_dislike.append(i)
for i in range(N, 10 * N + 1):
    if is_OK(i, not_dislike):
        print(i)
        break

Measured memory_bytes: 42204
def get_digit(n : int) -> int:
    count = 0
    while n != 0:
        count += 1
        n //= 10
    return count

N = int(input())

i = 1
candidate = 0
while i * i <= N:
    if N % i == 0:
        candidate = N // i
    i += 1

#print(candidate)
print(get_digit(candidate))

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


    
int main(){
  string S,S0,S1,S2,S3, answer = "Yes";
  cin >> S;
  S0 = S;
  reverse(S.begin(),S.end());
  S1 = S;
  reverse(S.begin(),S.end());
  reverse(S.begin(),S.begin() + (S.size()-1)/2);
  S2 = S;
  reverse(S.begin(),S.begin() + (S.size()-1)/2);
  reverse(S.begin() + (S.size()+3)/2 - 1, S.end());
  S3 = S;
  //reverse(S.begin() + (S.size()+3)/2 - 1, S.end());
  if(S0 != S1) answer = "No";
  if(S0 != S2) answer = "No";
  if(S0 != S3) answer = "No";
  
  cout << answer << endl;
}

Measured memory_bytes: 256
N = int(input())
A = []
for i in range(2):
    A.append([int(i)for i in input().split()])
ans = 0
for i in range(N):
    ans += A[0][i]
ans += A[1][N-1]
max = ans

for i in range (N-1):
    ans = ans + A[1][N-i-2] - A[0][N-i-1]
    if ans > max:
        max = ans

print(max)

Measured memory_bytes: 3188
#include<vector>
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iostream>
#include <algorithm>
#include <map>
#include <cmath>
#include<queue>
#include <sstream>
#include <set>

const long long MOD = 1000000007;
using namespace std;
typedef long long llong;

//int isalpha(char ch): ch がアルファベットなら true を返す
//int isdigit(char ch): ch が数字なら true を返す
//int islower(char ch): ch が小文字なら true を返す
//int isupper(char ch): ch が大文字なら true を返す
//int tolower(char ch): ch の小文字を返す
//int toupper(char ch): ch の大文字を返す

//string型
//size()	文字数を返す
//Insert()	（指定した場所に）文字・文字列を挿入する
//erase()	（指定した場所の）文字・文字列を削除する
//clear()	すべての文字を削除する
//substr()	文字列の（指定した）部分文字列を返す
//replace()	（指定した）部分文字列を新しい文字列に置換する
//c_str()変換
//文字列の比較は、<=や==などを使え
//replace関数を使い、簡単に文字列を置換
//リバース関数：reverse(str.begin(), str.end());
//map<type, type> dict;で宣言
//グラフ理論用変数
//vector<vector<llong> > graph(N);

//ソート
//降順sort(v.begin(), v.end(), std::greater<Type>());

//大文字から小文字へんかん
//w[i] = w[i]-'A'+'a';

//vector
//assignメソッド　引数：サイズ、値
//与えられたサイズと値でvectorを初期化する

//queueクラス
//find()次に取り出す値の表示をする。
//pop()値を取り出す。戻り値はなし
//push()キューに値をプッシュする

//priority_queueクラス

//切り上げ
//ceil
//floor

int main(){
    llong X;
    cin >> X;
    llong maxv=-1;
    llong exp;
    llong temp;
    if(X==1){
        cout << 1 << endl;
        exit(0);
    }
    for(int i=2; i<=1000; i++){
        exp = 2;
        temp = pow(i, exp);
        while(temp<=X){
            maxv = max(temp, maxv);
            exp++;
            temp = pow(i, exp);
        }
    }
    cout << maxv << endl;
    return 0;
}


Measured memory_bytes: 3500
from copy import deepcopy

N = int(input())
A = list(map(int, input().split()))
B = deepcopy(A)
mod = 10**9+7

"""
普通に最小公倍数を計算すると桁数が莫大になって
桁溢れor多倍長整数を使っても計算が一気に遅くなるのがこの問題のミソ

桁数の大きい数は素因数分解の形で保持すると高速にmod計算が可能なので、これを用いる。
まずは1000以下の素数テーブルを用意。
"""
prime = [i for i in range(2, 10**3)]
for p in prime:
    prime = [x for x in prime if (x == p or x % p != 0)]

def div(a, n):
    """
    自然数aがnで何回割れるかと、割り尽くした残りを返す
    """
    num = 0
    while a % n == 0:
        num += 1
        a = a // n
    return num, a

"""
素数pごとに、各A[i]がpで何回割れるかを求め、iでループを回した中での最大値をe_pとすると
A[0],...A[N-1]の最小公倍数はL = ¥Prod_p p^{e_p}になる。
これならmodで桁数削減が可能。

ただし素数テーブルは1000までしか用意してないので、それ以上の素数はリストAの中に吐き出させ、
あとでそれをLに組み込む。
"""
L = 1
for p in prime:
    e = 0
    for i in range(N):
        cand, A[i] = div(A[i], p)
        e = max(e, cand)
    L *= pow(p, e, mod)
    L %= mod
for a in set(A):
    L *= a
    L %= mod

"""
あとは答えを求めるのみ。
ただしLをmodで算出しているので、単純にL/A[i]を加算すると答えが狂う。
そこでA[i]^{-1}をmodで求めてLに乗算する。
"""
ans = 0
for i in range(N):
    inv = pow(B[i], mod - 2, mod)
    ans += L * inv
    ans %= mod
print(ans)


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

using ll = long long;
using namespace std;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;

int main(){
  int N,M;
  cin>>N;
  vector<int> D(N);
  for(int i(0);i<N;i++) cin>>D[i];
  cin>>M;
  vector<int> T(M);
  for(int i(0);i<M;i++) cin>>T[i];
  if(M > N){
    cout << "NO" << endl;
    return 0;
  }
  map<int,int> m;
  for(int i(0);i<N;i++){
    m[D[i]]++;
  }
  for(int i(0);i<M;i++){
    if (m[T[i]] > 0){
      m[T[i]]--;
    }else{
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 11136
from collections import defaultdict
n=int(input())
h=list(map(int,input().split()))
dp=defaultdict(lambda:0)
# dp[i]:足場iに到達するための最小コスト。はじめカエルは足場1にいるのでdp[1]=0
dp[1]=0
dp[2]=abs(h[0]-h[1])
for i in range(3,n+1):
      dp[i]=min(dp[i-1]+abs(h[i-1]-h[i-2]),dp[i-2]+abs(h[i-1]-h[i-3]))
print(dp[n])


Measured memory_bytes: 23612
h,w = map(int,input().split())
s = [["."]+list(input())+["."] for i in range(h)]

for i in range(h):
  for j in range(1,w+1):
    if i == 0:
      if s[i][j]=="#" and s[i][j+1]=="." and s[i][j-1]=="." and s[i+1][j]==".":
        print("No")
        exit()
    elif i == h-1:
      if s[i][j]=="#" and s[i][j+1]=="." and s[i][j-1]=="." and s[i-1][j]==".":
        print("No")
        exit()
    else:
      if s[i][j]=="#" and s[i][j+1]=="." and s[i][j-1]=="." and s[i+1][j]=="." and s[i-1][j]==".":
        print("No")
        exit()
        
print("Yes")
      

Measured memory_bytes: 3064
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <string.h>

using namespace std;

int main()
{
    char s[15], t[15];
    scanf("%s%s", s, t);
    int n = strlen(s);
    t[n] = 0;
    if(strcmp(s, t) == 0)
        printf("Yes\n");
    else
        printf("No\n");
}


Measured memory_bytes: 1576
check=dict()
N,b,d=0,[],0
#ttfは235、chaはabc

def dfs_sub(n,ttf,cha):
    global check,d
    
    check[0]=min(check[n]+n*d,check[0])

    if n//ttf in check:
        if check[n//ttf]>check[n]+(n%ttf)*d+cha:
            check[n//ttf]=check[n]+(n%ttf)*d+cha
            dfs(n//ttf)
    else:
        check[n//ttf]=check[n]+(n%ttf)*d+cha
        dfs(n//ttf)
    if 1+n//ttf in check:
        if check[1+n//ttf]>check[n]+(ttf-n%ttf)*d+cha:
            check[1+n//ttf]=check[n]+(ttf-n%ttf)*d+cha
            dfs(1+n//ttf)
    else:
        check[1+n//ttf]=check[n]+(ttf-n%ttf)*d+cha
        dfs(1+n//ttf)


def dfs(n):
    global b,check,d
    for i,j in zip([2,3,5],b):
        dfs_sub(n,i,j)

t=int(input())
for i in range(t):
    N,*b,d=map(int,input().split())
    check={N:0,0:N*d}
    dfs(N)
    print(check[0])


Measured memory_bytes: 125048