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

int main() {
	int N;
  	cin >> N;
  	vector<int> X(N);
  	for (int i=0; i<N; i++) cin >> X.at(i);
     
  int ans = 1001001001;
  	for(int i=0; i< 100; i++){
      int now = 0;
        for(int j=0; j< N; j++){
        now += pow((X.at(j) - i),2);
        }
        ans = min(now, ans);
    }	
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>
#include <cstdio>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
const double EPS = 1e-6;
template<typename X>
struct Graph
{
  int node;
  vector<vector<pair<int,X>>> edge;
  vector<X> d;

  Graph(int _node)
  {
    node = _node;
    edge.resize(node);
    d.resize(node);
  }

  void add(int from,int to,X cost)
  {
    edge[from].push_back(make_pair(to,cost));
  }

  void dijkstra(int s,X inf)
  {
    priority_queue<pair<X,int>,vector<pair<X,int>>,greater<pair<X,int>>> pq;
    rep(i,node) d[i] = inf;
    d[s] = 0;
    pq.push(make_pair(0,s));
    while(!pq.empty()){
      pair<X,int> p = pq.top();pq.pop();
      int v = p.second;
      if(d[v]<p.first) continue;
      for(auto &w:edge[v]){
	if(d[w.first]>d[v]+w.second){
	  d[w.first] = d[v] + w.second;
	  pq.push(make_pair(d[w.first],w.first));
	}
      }
    }
  }
};

int main()
{
  double xs,ys,xt,yt;
  cin >> xs >> ys >> xt >> yt;
  int n;
  cin >> n;
  vector<double> x(n),y(n),r(n);
  rep(i,n) cin >> x[i] >> y[i] >> r[i];

  Graph<double> gp(n+2);

  rep(i,n) rep(j,n){
    if(i==j) continue;
    gp.add(i,j,max(0.,sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]))-r[i]-r[j]));
  }
  
  rep(i,n){
    gp.add(n,i,max(0.,sqrt((xs-x[i])*(xs-x[i])+(ys-y[i])*(ys-y[i]))-r[i]));
    gp.add(i,n+1,max(0.,sqrt((xt-x[i])*(xt-x[i])+(yt-y[i])*(yt-y[i]))-r[i]));    
  }

  gp.add(n,n+1,max(0.,sqrt((xs-xt)*(xs-xt)+(ys-yt)*(ys-yt))));

  const double inf = 1e+15;

  gp.dijkstra(n,inf);

  printf("%.10f\n", gp.d[n+1]);


  return 0;
}


Measured memory_bytes: 22532
package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, c, d float64
	fmt.Scan(&a, &b, &c, &d)

	if math.Abs(c-a) <= d {
		fmt.Println("Yes")
		return
	}

	if math.Abs(b-a) <= d && math.Abs(c-b) <= d {
		fmt.Println("Yes")
		return
	}

	fmt.Println("No")
}


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

int main() {
  string S;
  cin >> S;
  int N = S.size();
  if (S[0] != 'A' || S[1] < 97 || S[N-1] < 97) {
    cout << "WA" << endl;
    return 0;
  }
  int c = 0;
  for (int i = 2; i < N-1; i++) {
    if (S[i] == 'C') {
      c++;
    } else if (S[i] < 97) {
      cout << "WA" << endl;
      return 0;
    }
    if (1 < c) {
      cout << "WA" << endl;
      return 0;
    }
  }
  if (c == 1) {
    cout << "AC" << endl;
  } else {
    cout << "WA" << endl;
  }
}

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

int main() {
    int n;
    cin >> n;
    int iarr[n] = {0};
    for (int i = 1; i < n; ++i) {
        int num;
        cin >> num;
        ++iarr[num-1];
    }
    for (int i : iarr) cout << i << endl;
    return 0;
}

Measured memory_bytes: 4412
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vd = vector<double>;
using vvi = vector<vector<int>>;
using vii = vector<pair<int, int>>;

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

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
//int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
//int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

int main() {
	string s; cin >> s;
	cout << s.front() << s.size() - 2 << s.back() << endl;
}

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();
      if(n % 2 == 0)
        System.out.println(n);
      else if (2 % n == 0)
        System.out.println(2);
      else 
        System.out.println(2*n);
  }
}

Measured memory_bytes: 22996
#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef unsigned long long llu;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
const ll MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

struct node {
	int u, v, c;
	bool operator< (const node &v2) const {
		return c > v2.c;
	}
};

priority_queue<node> pq;

int mat[300][300];
int temp[300][300];
bool al[300][300];

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

	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			scanf("%d", &mat[i][j]);
	memcpy(temp, mat, sizeof(temp));

	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			for (int k = 0; k < n; k++) {
				if (i == j || i == k || j == k) continue;
				if (mat[j][k] == mat[j][i] + mat[i][k]) al[k][j] = al[j][k] = 1;
				mat[j][k] = min(mat[j][k], mat[j][i] + mat[i][k]);
			}

	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			if (mat[i][j] != temp[i][j]) return !printf("-1");

	memcpy(mat, temp, sizeof(mat));

	ll ans = 0;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			if (al[i][j] == 0) ans += mat[i][j];

	printf("%lld", ans / 2);
}

// 그리디하게 큰 것부터 지워보자.

Measured memory_bytes: 1024
import math
N, M = map(int,input().split())

P = []
for k in range(1,math.floor(math.sqrt(M))+1):
    if M % k == 0:
        P.append(k)
        P.append(M//k)
ans = 1
for e in P:
    if e*N <= M:
        ans = max(ans,e)
print(ans)


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

int main(){
  int x;
  int a = 0;
  int b = 0;
  cin >> x;
  if(x==2){b=2;}
  while(b == 0){
    if(x%2!=0){
      for(int i=3; i<(x/2); i+=2){
        if(x%i==0){a++;}
      }
      if(a==0){b = x;}
      a = 0;
    }
    x += 1;
  }
  cout << b << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

int main(){
	ll n,a,b; cin >> n >> a >> b;
	if(a > b) swap(a,b);
	if(a%2 == b%2){
		cout << (b-a)/2 << endl;
	}
	else{
		ll ans = min(b-1,n-a);
		ans = min(ans,a-1+(b-a+1)/2);
		ans = min(ans,n-b+(b-a+1)/2);
		cout << ans << endl;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
int main(){
    ll n,k,c;cin>>n>>k>>c;
    string s;cin>>s;
    vector<ll>a(n),b(n);
    rep(i,n){
        if(s[i]=='o')a[i]=(i>=c+1?a[i-c-1]+1:1);
        else a[i]=(i?a[i-1]:1);
    }
    reverse(all(s));
    rep(i,n){
        if(s[i]=='o')b[i]=(i>=c+1?b[i-c-1]+1:1);
        else b[i]=(i?b[i-1]:1);
    }
    reverse(all(b));
    reverse(all(s));
    rep(i,n){
        if(s[i]=='o')if(k>(i?a[i-1]:0)+(i<n-1?b[i+1]:0))cout<<i+1<<endl;
    }
}

Measured memory_bytes: 4996
#include <bits/stdc++.h>
#define REV(v) reverse(v.begin(), v.end());
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, start, stop) for (int i = start; i < stop; i++)
#define FORR(i, start, stop) for (int i = start; i > stop; i--)
#define SORT(v, n) sort(v, v + n);
#define SORTR(v, n) sort(v, v + n,greater<int>());
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.begin(), v.end(),greater<int>());
#define REMOVE(v,n) remove(vector<int> v,v+v.size(),int n)
#define ll long long
#define ull unsigned long long
#define pb(a) push_back(a)
#define INF 999999999
#define V(v,i,j) vector(v.begin() + i, v.begin() + j)
#define INSERT(va,vb) va.insert(va.end(), vb.begin(), vb.end())
using namespace std;
typedef vector<int> vint;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
int dy[] = {0, 0, 1, -1};
int dx[] = {1, -1, 0, 0};
const int MOD = 1000000007;
void chmin(int &a, int b) { if (a > b) a = b; }

//vector< vector<int> > v (size1, vector<int>(size2) );

struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

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

    ll N,M;
    cin>>N>>M;
    UnionFind uf(N+1);
    
    vector<ll> p(N+1);
    FOR(i,0,N) cin>>p[i+1];
    ll x,y;
    FOR(i,0,M){
        cin>>x>>y;
        uf.merge(x,y);
    }

    vector< vector<ll> > p1 (N+1, vector<ll>(0));
    vector< vector<ll> > p2 (N+1, vector<ll>(0));
    

    FOR(i,1,N+1){
        p1[uf.root(i)].pb(i);
        p2[uf.root(i)].pb(p[i]);
    }

    FOR(i,1,N+1){
        VSORT(p2[i]);
    }

    ll ans=0;

    FOR(i,0,N+1){
        for(auto e:p1[i]){
            //cout<<e<<' '<<p2[i][lower_bound(p2[i].begin(), p2[i].end(), e)-p2[i].begin()]<<endl;
            if(e==p2[i][lower_bound(p2[i].begin(), p2[i].end(), e)-p2[i].begin()]){
                ans++;
            }
        }
    }
    
    cout<<ans<<endl;
    
}

Measured memory_bytes: 12416
#include<bits/stdc++.h>
using namespace std;
#define ll                          long long
#define in(a)                       ll a; cin>>a;
#define in2(a,b)                    ll a,b; cin>>a>>b;
#define in3(a,b,c)                  ll a,b,c; cin>>a>>b>>c;
#define in4(a,b,c,d)                ll a,b,c,d; cin>>a>>b>>c>>d;
#define in5(a,b,c,d,e)              ll a,b,c,d,e; cin>>a>>b>>c>>d>>e;
#define lelo(b)                     for(auto &i:b)cin>>i;
#define ff                          first
#define ss                          second
#define call(v)                     v.begin(),v.end()
#define rall(v)                     v.rbegin(),v.rend()
#define show(x)                     for(auto t:x)cout<<t<<" ";
#define pb                          push_back
#define bhar(s,v)                   memset(s,v,sizeof(s))
#define endl                        "\n"                       
#define ce(x)                       cout<<x<<"\n";
#define nl                          cout<<endl;
#define jaldi                       ios_base::sync_with_stdio(false);cin.tie(NULL);
#define dekh_lo                     ce("dekh_lo");
#define sz(x)                       (ll)x.size()
#define re                          return

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

typedef pair<ll,ll> pii;
typedef vector<pii> vii;
typedef vector<ll> vi;

const ll mod=1e9+7;
const ll N=3e5+5;

/*


*/
ll depth;
vi adj[N];
std::vector<bool> vis(N,0);
void dfs(ll x){
	if(vis[x]){
		re;
	}
	depth++;
	vis[x]=1;
	for(auto frnd:adj[x]){
		dfs(frnd);
	}
}
void solve(){
    in2(n,m);
    ll ss=m;
    while(ss--){
    	in2(x,y);
    	adj[x].pb(y);
    	adj[y].pb(x);
    }
    ll ans=0;
    for(ll i=1;i<=n;i++){
    	if(!vis[i]){
    		depth=0;
    		dfs(i);
    		ans=max(ans,depth);
    	}
    }
    ce(ans);
}

int32_t main(){
    // jaldi
    ll t; 
    // cin>>t;
    t=1;     
    while(t--){
        solve();
    }
}

/*


*/

  

Measured memory_bytes: 23116
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<iomanip>
using namespace std;
int main()
{
	int n,k,x,y,m;
	cin>>n>>k>>x>>y;
	if(n>k)
	{
		m=k*x+(n-k)*y;
	}
	else
	{
		m=n*x;
	}
	cout<<m<<endl;
	return 0;
}

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

int main() {
    int N, K;
    cin >> N >> K;
    
    ll ans;
    
    if (N < K) {
        if (K % 2 == 1) {
            cout << 0 << endl;
            return 0;
        }
        else {
            if (K / 2 <= N) {
                cout << 1 << endl;
                return 0;
            }
            else {
                cout << 0 << endl;
                return 0;
            }
        }
    }
    
    
    if (K % 2 == 1) {
        ans = pow((N / K), 3);
        cout << ans << endl;
    }
    else {
        if (N % K >= K / 2) {
            ans = pow((N / K), 3) + pow((N / K) + 1, 3);
            cout << ans << endl;
        }
        else {
            ans = 2 * pow((N / K), 3);
            cout << ans << endl;
        }
    }
}

Measured memory_bytes: 256
def cross(vec1, vec2)
  return vec1[0] * vec2[1] - vec1[1] * vec2[0]
end

def isIn?(c1, c2, c3)
  return (c1 > 0 && c2 > 0 && c3 > 0) || (c1 < 0 && c2 < 0 && c3 < 0) ? true : false
end

while line = gets do
  x1, y1, x2, y2, x3, y3, xp, yp = line.split.map(&:to_f)
  vec1_to_p = [xp - x1, yp - y1]
  vec2_to_p = [xp - x2, yp - y2]
  vec3_to_p = [xp - x3, yp - y3]
  vec1_to_2 = [x2 - x1, y2 - y1]
  vec2_to_3 = [x3 - x2, y3 - y2]
  vec3_to_1 = [x1 - x3, y1 - y3]

  isIn?(cross(vec1_to_p, vec1_to_2), cross(vec2_to_p, vec2_to_3), cross(vec3_to_p, vec3_to_1)) ? (puts "YES") : (puts "NO")
end

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

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

  int dis = 0, ans = 1;

  for (int i = 0; i < N; i++) {
    int L;
    cin >> L;
    dis += L;
    if (dis <= X) ans++;
    else break;
  }

  cout << ans << "\n";
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

ulong[50] solve(ulong x)
{
    ulong[50] r;
    auto y = x;

    size_t i;
    while (y > 0) {
        r[i] = x / 2^^(i+1) * 2^^i;
        if (x % 2^^(i+1) >= 2^^i) r[i] += x % 2^^(i+1) + 1 - 2^^i;
        ++i;
        y >>= 1;
    }

    return r;
}

void main()
{
    auto ab = readln.split.to!(ulong[]);
    auto A = ab[0];
    auto B = ab[1];

    if (A == 0) {
        ulong r, j = 1;
        foreach (i, x; solve(B)) {
            if (x % 2 == 1) r |= (j<<i);
        }
        writeln(r);
        return;
    }

    auto a = solve(A-1);
    auto b = solve(B);
    ulong r, j = 1;
    foreach (i; 0..50) {
        if ((b[i] - a[i]) % 2 == 1) {
            r |= (j<<i);
        }
    }
    writeln(r);
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in);) {
			int X = sc.nextInt();
			int Y = sc.nextInt();
			int Z = sc.nextInt();

			int ans = (X - Z) / (Y + Z);

			System.out.println(ans);

		}
	}
}

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

int main() {
  std::vector<int64_t> x(5);
  for (int i = 0; i < 5; i++) {
    cin >> x[i];
  }

  for (int i = 0; i < 5; i++) {
    if (x[i] == 0) {
      cout << i + 1 << endl;
      return 0;
    }
  }

  return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define int ll
#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)	
#define REP(i,b) FOR(i,0,b)
int read(){
	int i;
	scanf("%lld",&i);
	return i;
}
using vi=vector<int>;
#define PB push_back
#define ALL(x) x.begin(),x.end()
using pi=pair<int,int>;

void chmin(int&a,int b){
	a=a<b?a:b;
}
void chmax(int&a,int b){
	a=a>b?a:b;
}

const int Nmax=114514;
const int inf=LLONG_MAX/3;
int n;
vi g[Nmax],w[Nmax];
int FindCentroid(int v,int p){
	int res=1,s=0;
	for(auto to:g[v])if(to!=p){
		int fc=FindCentroid(to,v);
		if(fc<=0)return fc;
		chmax(s,fc);
		res+=fc;
	}
	chmax(s,n-res);
	if(s*2<=n)return -v;
	return res;
}
int ans;
int dfs(int v,int p,int c){
	int res=1;
	REP(i,g[v].size())if(g[v][i]!=p)
		res+=dfs(g[v][i],v,w[v][i]);
	ans+=c*res*2;
	return res;
}

signed main(){
	n=read();
	REP(_,n-1){
		int a=read()-1,b=read()-1,c=read();
		g[a].PB(b);
		w[a].PB(c);
		g[b].PB(a);
		w[b].PB(c);
	}
	int root=-FindCentroid(0,-1);
	vi s;
	REP(i,g[root].size())
		s.PB(dfs(g[root][i],root,w[root][i]));
	REP(i,s.size())
		if(s[i]*2==n){
			cout<<ans-w[root][i]<<endl;
			return 0;
		}
	int p=inf;
	REP(i,s.size())
		chmin(p,w[root][i]);
	cout<<ans-p<<endl;
}


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

#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) REP(i,0,n)
#define INF (1<<30)
#define INFLL (1LL<<62LL)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  int N, M;
  cin >> N >> M;

  if (abs(N - M) > 1) {
    cout << 0 << endl;
    return 0;
  }

  ll fact[max(N,M)+1] = {};
  ll mod = 1e9 + 7;
  fact[0] = 1;

  REP(i, 1, max(N,M)+1)
    fact[i] = (i * fact[i-1]) % mod;

  if (N == M)
    cout << (2 * fact[N] * fact[M]) % mod << endl;
  else
    cout << (fact[N] * fact[M]) % mod << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <cstdio>

const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;

int dp[maxn];
int sum[maxn];

int main()
{
    int n;
    scanf("%d", &n);
    dp[0] = 1;
    sum[0] = 1;
    for (int i = 1; i <= n; ++i)
    {
        dp[i] = dp[i - 1];
        if (i >= 3)
            dp[i] = (dp[i] + sum[i - 3]) % mod;
        sum[i] = (sum[i - 1] + dp[i]) % mod;
    }
    int ans = 0;
    for (int i = 0; i + 1 < n; ++i)
    {
        ans = (ans + 1ll * dp[i] * (n - 1) % mod * (n - 1) % mod) % mod;
        ans = (ans + 1ll * dp[i] * (i >= n - 2 ? n - 1 : i + 2) % mod) % mod;
    }
    ans = (ans + 1ll * dp[n - 1] * n % mod) % mod;
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 7936
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M 1000000007
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pie acos(-1)
#define loop(i,a,n) for(int i=a;i<n;i++)
#define trav(a,x) for(auto &a:x)
#define vi vector<int>
#define vl vector<ll>
#define vii vector<vector<int>>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define endl "\n"
#define all(v) v.begin(),v.end()
#define w 100005

void solve()
{
    ll n;
    cin>>n;
    vl a(n);
    map<ll,ll>m;
    loop(i,0,n)
    {
        cin>>a[i];
        m[a[i]]++;
    }
    ll ans=0;
    for(auto i:m)
    {
        ll p=i.ss;
        ll temp=p*(p-1)/2;
        ans+=temp;
    }
    for(int i=0;i<n;i++)
    {
        ll y=m[a[i]];
        if(y>=2)
        cout<<ans+1-y<<endl;
        else
        cout<<ans<<endl;
    }
    
}
int main() {
	// your code goes here
	io;
	int t ;
	//cin>>t;
	//while(t--)
    solve();
	return 0;
}


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

using namespace std;
using ll = long long;

void solve() {
    int h,w;
    cin>>h>>w;
    vector<vector<char>> d(h,vector<char>(w));
    set<char> st;

    for(int i = 0;i < h;++i) {
        for(int j = 0;j < w;++j) {
            cin>>d[i][j];
            st.insert(d[i][j]);
        }
    }
    st.erase('.');
    int k=st.size();
    if(k==0) {
        cout<<"SAFE"<<endl;
        return;
    }

    map<char,vector<int>> mp;//left,right,up,down
    for(auto c:st) {
        mp[c]={w,-1,h,-1};
    }
    for(int i = 0;i < h;++i) {
        for(int j = 0;j < w;++j) {
            if(d[i][j]=='.')continue;
            mp[d[i][j]][0]=min(mp[d[i][j]][0],j);
            mp[d[i][j]][1]=max(mp[d[i][j]][1],j);
            mp[d[i][j]][2]=min(mp[d[i][j]][2],i);
            mp[d[i][j]][3]=max(mp[d[i][j]][3],i);
        }
    }

    vector<int> perm(k);
    for(int i = 0;i < k;++i) {
        perm[i]=i;
    }

    map<char,int> ind;
    {
        int t=0;
        for(auto c:st){
            ind[c]=t;
            ++t;
        }
    }
    //for(auto i:ind)cout<<i.first<<" "<<i.second<<endl;


    do{
        bool ok=true;
        for(auto dt:mp) {
            char tc=dt.first;
            auto v=dt.second;
            int l=v[0],r=v[1],u=v[2],dw=v[3];

            for(int i = u;i <= dw;++i) {
                for(int j = l;j <= r;++j) {
                    if(d[i][j]==tc)continue;

                    if(d[i][j]=='.') {
                        cout<<"SUSPICIOUS"<<endl;
                        //cout<<"hoge"<<endl;
                        return;
                    }
                    if(perm[ind[d[i][j]]]<perm[ind[tc]]) {
                        ok=false;
                        goto nx;
                    }
                }
            }
        }
        nx:;
        if(ok) {
            cout<<"SAFE"<<endl;
            return;
        }
    }while(next_permutation(perm.begin(),perm.end()));

    cout<<"SUSPICIOUS"<<endl;
    return;
}

int main() {
    int T;
    cin>>T;
    for(int TestSet = 0;TestSet < T;++TestSet) {
        solve();
    }
    return 0;
}



Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#include<numeric>
#include<stack>
#include<queue>
#include<functional>
#include<cassert>
#include<set>
#define rep(a,b) for(ll a=0;a<b;++a)
#define REP(a,b,c,d) for(ll a=b;a<c;a+=d)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define mod 1000000007
using namespace std;
using ll = long long;
using p_i = pair<int, int>;
int main() {
	int N; cin >> N;
	vector<int> L(N);
	rep(i, N)cin >> L[i];
	sort(L.begin(), L.end());
	int a = 0;
	rep(i, N - 1)a += L[i];
	if (L[N - 1] < a)yes;
	else no;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

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


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = INT32_MAX / 3;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/





int main() {

	int p;
	cin >> p;
	int m[] = {10000,5000,1000,500};

	int ans = 0;
	for (int i = 0; i < 4; i++)
	{
		ans += m[i] * (p / m[i]);
		p -= m[i] * (p / m[i]);
	}
	cout << ans << endl;






	return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;

int main(){
  int N, Q;
  string S;
  cin >> N >> Q >> S;
  vi l(Q), r(Q);
  for(int i = 0; i < Q; i++){
    cin >> l.at(i) >> r.at(i);
    l.at(i)--; r.at(i)--;
  }
  int ssize = S.size();
  vector<int> AC(ssize, 0);
  for(int i = 0; i < ssize; i++){
    if(i != 0) AC.at(i) = AC.at(i-1);
    if(i != ssize-1 && S.at(i) == 'A' && S.at(i+1) == 'C') AC.at(i) += 1;
  }
  for(int i = 0; i < Q; i++){
    int result;
    if(l.at(i) == 0) result = AC.at(r.at(i));
    else result =AC.at(r.at(i)) - AC.at(l.at(i)-1);
    result -= AC.at(r.at(i)) - AC.at(r.at(i)-1);
    cout << result << endl;
  }
  
}


Measured memory_bytes: 2304
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

int main(){
	ll n;
	scanf("%lld",&n);
	if(n%2){
		puts("0");
		return 0;
	}
	n/=2;
	//2^n * n!
	ll t2=2*n- __builtin_popcountll(n);
	ll t5=0;
	while(n){
		t5+=n/=5;
	}
	printf("%lld",min(t2,t5));
}

Measured memory_bytes: 128
S = list(input())
ans = [0]*(len(S))
S.append('R')#最後のグループの集計用に便宜上追加
R_start = 0
R_end = 0
L_start = 0
L_end = 0
R_count = 1
L_count = 1
for i in range(0,len(S)-1):
    if S[i]=='R':
        if S[i]==S[i+1]:
            R_count+=1
        else:
            R_end = i
            L_start = i+1
            L_count = 1

    elif S[i]=='L':
        if S[i]==S[i+1]:
            L_count+=1
        else:
            L_end = i
            
            #ここまでの集計
            count = R_count+L_count
            if count%2==0:
                ans[R_end] = int(count/2)
                ans[L_start] = int(count/2)
            else:
                if (R_end-L_end)%2==0 or (R_end-R_start)%2==0:
                    ans[R_end] = int((count+1)/2)
                    ans[L_start] = int((count-1)/2)
                else:
                    ans[R_end] = int((count-1)/2)
                    ans[L_start] = int((count+1)/2)
            R_start = i+1
            R_count = 1
            
for i in range(len(ans)):
    ans[i]=str(ans[i])
print(' '.join(ans))


Measured memory_bytes: 10796
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for (int i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;
TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM V, TNM H> void resize(vector<V>& v, const H h) { v.resize(h); }
TPL<TNM V, TNM H, TNM ... T> inline void resize(vector<V>& v, const H& h, const T ... t) { v.resize(h); for (auto& _v : v) resize(_v, t ...); }
TPL<TNM V, TNM T> void fill(V& x, const T& val) { x = val; }
TPL<TNM V, TNM T> inline void fill(vector<V>& vec, const T& val) { for (auto& v : vec) fill(v, val); }
TPL<TNM T> inline void UNIQUE(vector<T>& vec) { sort(ALL(vec)); vec.erase(unique(ALL(vec)), vec.end()); }

using Int = ll;
map< Int, Int > prime_factor(Int n) {
	map< Int, Int > ret;
	for (Int i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}

int main(void) {
	ll N, P;
	cin >> N >> P;
	map<ll, ll> pf = prime_factor(P);
	
	ll ans = 1;
	for (auto &p : pf) {
		if (p.second >= N) {
			ans *= (ll)pow(p.first, p.second / N);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<long long> A(N);

  for (int i = 0; i < N; i++) {
    long long a;
    cin >> a;
    A[i] = a;
  }

  long long total_diff = 0;

  for (int i = 0; i < N - 1; i++) {
    int j = i + 1;
    long long diff = A[i] - A[j];
    if (diff <= 0) {
      continue;
    }
    A[j] += diff;
    total_diff += diff;
  }

  cout << total_diff << endl;

  return 0;
}


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

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		
		int k = sc.nextInt();
		Queue<Long> que = new ArrayDeque<>();
		for(int i = 1; i < 10; i++) {
			que.offer((long)i);
		}
		
		int cnt = 0;
		long ans = 0;
		while(cnt < k) {
			long num = que.poll();
			cnt++;
			ans = num;
			long amari = num % 10;
			if (amari != 0) { que.offer(num * 10 + amari - 1) ;}
			que.offer(num * 10 + amari);
			if (amari != 9) { que.offer(num * 10 + amari + 1); }
		}
		out.println(ans);

		out.close();
	}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}



Measured memory_bytes: 31188
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 10005
#define PI 	3.14159265358979323846

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,q;
    cin >> n >> q;
    string s;
    cin >> s;
    int r[1000005];
    r[0] = r[1] = 0;
    //cout << endl << "sample" << 1 << ":" << r[1] << endl;
    FOR(i,1,n){
        r[i+1] = r[i];
        if(s[i-1]=='A' && s[i]=='C')r[i+1]++;
        //cout << "sample" << i+1 << ":" << r[i+1] << endl;
    }
    int b[100005],e[1000005];
    REP(i,q){
        cin >> b[i] >> e[i];
    }
    REP(i,q){
        cout << r[e[i]] - r[b[i]] << endl;
    }
    return 0;
}


Measured memory_bytes: 7760
#include<bits/stdc++.h>
#define ll long long int 
using namespace std;
int main()
{
	ll n,x,y,z;
	cin>>n;
	ll arr[n];
	for(int a=0;a<n;a++)
	cin>>arr[a];
	z=arr[0];
	x=1;
	for(y=1;y<n;y++)
	{
		if(arr[y]<=z)
		x++;
		if(z>arr[y])
		z=arr[y];
		
	}
	cout<<x;
	return 0;
}


Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<set<int> > edges(n);
    for(int i=0; i<n-1; ++i){
        int a, b;
        cin >> a >> b;
        -- a;
        -- b;
        edges[a].insert(b);
        edges[b].insert(a);
    }

    queue<int> leaf;
    for(int i=0; i<n; ++i){
        if(edges[i].size() == 1)
            leaf.push(i);
    }

    while(!leaf.empty()){
        int a = *edges[leaf.front()].begin();
        leaf.pop();

        int cnt = 0;
        for(int b : edges[a]){
            if(edges[b].size() == 1)
                ++ cnt;
            edges[b].erase(a);
            if(edges[b].size() == 1)
                leaf.push(b);
        }

        if(cnt >= 2){
            cout << "First" << endl;
            return 0;
        }
    }

    cout << "Second" << endl;
    return 0;
}


Measured memory_bytes: 14464
import sys
n = int(sys.stdin.readline())
H = list(map(int, sys.stdin.readline().split()))

for i in range(n-1, 0,-1):
    if H[i] - H[i-1] ==-1:
        H[i-1]-=1
        
        
if sorted(H) == H:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 14252
// #include <bits/stdc++.h>
#include <map>
#include <set>
#include <ctime>
#include <cstring>
#include <queue>
#include <iostream>
#include <algorithm>
using namespace std;
 
#define mod 1000000009
#define INF 1000000000
#define ll long long
#define dbl double
#define ull unsigned ll
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvvll vector<vector<vector<ll>>>
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define all(x) begin(x), end(x)
#define contains(a, x) (a.find(x) != end(a))
#define F(i,a,b) for(int i = (int)(a); i < (int)(b); ++i)
#define RF(i,a,b)for(int i = (int)(a); i >= (int)(b); --i)
#define fast() {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define log(x) cout << (x) << endl;
 
 
 
int main() {
	fast();
 
	int n, x;
	cin >> n >> x;
	vi a(n);
	REP (i,n) cin>>a[i];

	ll c = max(a[0]-x, 0);
	a[0] = min(a[0], x);
 
	for (int i=0; i<n-1; i+=1) {
		if (a[i]+a[i+1] > x) {
			c += (a[i] + a[i+1]) - x;
			a[i+1] = x - a[i];
		}
	}
 
	log(c);
 
	return 0;
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <db, db> pdd;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;

#define FOR(k,a,b) for(int k=(a); k<=(b); ++k)
#define IFOR(k,a,b) for(int k=(a); k>=(b); --k)
#define REP(k,a) for(int k=0; k<(a);++k)
#define IREP(k,a) for(int k=a-1; k>=(0);--k)
#define SZ(a) int((a).size())
#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define x first
#define y second
#define INF 1000000001
#define INFLONG 1000000000000000000
#define MOD 1000000007
#define MAX 100
#define ITERS 100
#define MAXM 200000
#define MAXN 1000000
#define PI 3.1415926535897932384626
#define ERR -987654321
#define MEM(a,b) memset(a,b,sizeof(a));
#define read1(a) scanf("%d",&a)
#define read2(a,b) scanf("%d%d",&a,&b)
#define read3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define readl1(a) scanf("%lld",&a)
#define readl2(a,b) scanf("%lld%lld",&a,&b)
#define readl3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//	int rn = uniform_int_distribution<int>(0, MAXN)(rng);

	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);

    int n,t, res = INF;
    cin>>n>>t;
    vector<pii> a;
    bool flag = true;
    
    REP(i,n) {
    	int p,q;
    	cin>>p>>q;
    	a.PB(MP(p,q));
	}

    REP(i,n) {
        if(a[i].y <= t) {
            if(a[i].x < res) res = a[i].x;
            flag = false;
        }
    }

    if(flag) cout<<"TLE";
    else cout<<res;
	
	
	return 0;
}






Measured memory_bytes: 256
/*** ??????????????°????????\??\??? ***/

#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

int check(long long n, int count){
	if(n>1){
		if(n%3==0){
			n/=3;
			count++;
			count=check(n, count);
		}
		else{
			n/=3;
			count++;
			count=max(check(n, count), check(n+1, count));
		}
	}
	return count;
}

int main(){
	long long N;
	int count=0;
	
	cin >> N;
	
	cout << check(N, count) << endl;
	
	return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define range(a) a.begin(), a.end()
#define endl "\n"
#define Yes() cout << "Yes" << endl
#define No() cout << "No" << endl
using Graph = vector<vector<int>>;
const unsigned long long mod = 1e9 + 7;
const long long INF = 1LL<<60;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N,a,count=0;	cin>>N;
	FOR(i,1,N+1){
		cin>>a;
		if(i%2){
		if(a%2)	count++;
	}
	}

	cout<<count<<endl;
    return 0;
}




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

#define LINE /*cout << "LINE : "<< __LINE__ << endl*/

const int MAX_N = 101;
const int MAX_C = 21;
const int INF = 1e9;

int cost[MAX_N][MAX_N];
int dist[MAX_N][MAX_N][MAX_C];


int main() {
  int N, M, C, S, G;
  while(cin >> N >> M >> C >> S >> G) {
    if(N == 0 && M == 0 && C == 0 && S == 0 && G == 0) break;
    --S;
    --G;
    vector<int> x(M), y(M), d(M), c(M);
    rep(i, M) {
      cin >> x[i] >> y[i] >> d[i] >> c[i];
      --x[i];
      --y[i];
      --c[i];
    }
    LINE;
    vector<vector<int>> q(C), r(C);
    rep(i, C) {
      int p;
      cin >> p;
      q[i].resize(p);
      r[i].resize(p);
    }
    LINE;
    rep(i, C) {
      rep(j, q[i].size()-1) cin >> q[i][j];
      rep(j, r[i].size()) cin >> r[i][j];
    }
    LINE;
    {
      rep(i, N) rep(j, N) rep(k, C) dist[i][j][k] = (i == j ? 0 : INF);
      rep(i, M) {
	dist[x[i]][y[i]][c[i]] = dist[y[i]][x[i]][c[i]] = min(dist[x[i]][y[i]][c[i]], d[i]);
      }
      rep(l, C) {
	rep(k, N) rep(i, N) rep(j, N) dist[i][j][l] = min(dist[i][j][l], dist[i][k][l] + dist[k][j][l]);
      }
    }
    LINE;
    {
      rep(i, N) rep(j, N) cost[i][j] = (i == j ? 0 : INF);
      rep(c, C) {
	int maxDist = 0;
	rep(i, N) rep(j, N) {
	  if(dist[i][j][c] != INF) maxDist = max(maxDist, dist[i][j][c]);
	}
	LINE;
	vector<int> money(maxDist+1);
	LINE;
	int idx = 0;
	REP(i, 1, maxDist+1) {
	  money[i] = money[i-1] + r[c][idx];
	  if(q[c][idx] == i) ++idx;
	}
	LINE;
	rep(i, N) rep(j, N) if(dist[i][j][c] != INF) {
	  cost[i][j] = cost[j][i] = min(cost[i][j], money[dist[i][j][c]]);
	}
	LINE;
      }
      rep(k, N) rep(i, N) rep(j, N) {
	cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
      }
    }
    if(cost[S][G] == INF) cout << -1 << endl;
    else cout << cost[S][G] << endl;

    // {
    //   rep(c, C) {
    // 	cout << c << endl;
    // 	rep(i, N) {
    // 	  rep(j, N) {
    // 	    int d = dist[i][j][c];
    // 	    if(d == INF) d = -1;
    // 	    cout << " " << d;
    // 	  }
    // 	  cout << endl;
    // 	}
    //   }
    // }
  }
  return 0;
}



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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n - 1); i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

template<typename T>
inline void setmax(T& a, T b) {
    if (a < b) a = b;
}

template<typename T>
inline void setmin(T& a, T b) {
    if (a > b) a = b;
}

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

void fail() {
    cout << "NO\n";
    exit(0);
}

void win() {
    cout << "YES\n";
    exit(0);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    ll a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    ll diff = abs(a - b);
    fore(pos, 0, n - 1) {
        int neg = n - 1 - pos;
        ll mn = pos * c - neg * d;
        ll mx = pos * d - neg * c;
        if (mn <= diff && diff <= mx) win();
    }
    fail();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n; cin >> n;
    int arr[n], ans = 0;
    for(int i = 0 ; i < n ; i ++) cin >> arr[i];
    sort(arr, arr + n);
    for(int i = 0 ; i < n - 2 ; i ++){
        for(int j = i + 1; j < n - 1 ; j ++){
            int cnt = 0;
            for(int k = i + 2; k < n ; k ++){
                if(arr[i] + arr[j] > arr[k]) cnt ++;
                else break;
            }
            ans += cnt + i - j + 1;
        }
    }
    cout << ans << endl;
}

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


int main(){
  long l, r;
  cin >> l >> r;
  long minn=2019;

  if((r-l+1) >= 2019){
    cout << 0 << '\n';
    return 0;
  }else{
    for(long i=l; i<=r-1; i++){
      for(long j=i+1; j<=r; j++){	
        minn = min(minn, ((i%2019)*(j%2019)) % 2019);
      }
    }
  }

  cout << minn << '\n';  
  return 0;
}

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

#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define SIZE(array) (sizeof(array) / sizeof(array[0]))

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

#define MAX_V 100000

#define MOD 1000000007L
#define INF 100000000000

signed main() {
	int n;
	string s;
	cin >> n >> s;
	int m = 0;
	int t = 0;
	for (size_t i = 0; i < n; i++) {
		t += (s[i] == 'I' ? 1 : -1);
		m = max(m, t);
	}
	cout << m << endl;
}


Measured memory_bytes: 256
### main

loop do
  rn, cn = gets.strip.split(' ').map{|s| s.to_i}
  break if (rn | cn) == 0

  sums = cn.times.map{0}
  an = []

  rn.times do
    ak =  gets.strip.split(' ').map{|s| s.to_i}
    an << ak

    for i in (0...cn)
      sums[i] += ak[i]
    end
  end
  #p sums

  max_bits = (1 << (rn - 1)) - 1
  max_ok = 0

  for bits in (0..max_bits)
    sums0 = sums.clone

    for b in (0...(rn - 1))
      if (bits & (1 << b)) != 0
        for i in (0...cn)
          sums0[i] += (an[b][i] == 0 ? 1 : -1)
        end
      end
    end

    ok = sums0.inject(0){|sum, s| sum + [s, rn - s].max}
    max_ok = ok if max_ok < ok
  end

  puts max_ok
end

Measured memory_bytes: 8036