akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#define maxx 2000000000
#define maxn 200009
using namespace std;
priority_queue<int>q;
int to[maxn],f[maxn],n,wei[maxn],f1[maxn][20],f2[maxn][20];
vector<int>g[maxn];
void dfs(int lef,int righ,int fa)
{
  int w1,w2,len;
  if (lef>=righ) return;
  len=trunc(log(righ-lef+1)/log(2));
  if ((lef%2)==1) w1=min(f1[lef][len],f1[righ-(1<<len)+1][len]);
  else  w1=min(f2[lef][len],f2[righ-(1<<len)+1][len]);
  len=trunc(log(righ-wei[w1]+1)/log(2));
  if ((lef%2)==1) w2=min(f2[wei[w1]][len],f2[righ-(1<<len)+1][len]);
  else w2=min(f1[wei[w1]][len],f1[righ-(1<<len)+1][len]);
  dfs(lef,wei[w1]-1,fa);
  dfs(wei[w2]+1,righ,fa);
  dfs(wei[w1]+1,wei[w2]-1,w1);
  f[w1]=fa; to[w1]=w2;
  g[fa].push_back(w1);
}
int main()
{
  scanf("%d",&n);
  int x;
  for (int i=1;i<=n;i++) f1[i][0]=f2[i][0]=maxx;
  for (int i=1;i<=n;i++) 
  {
    scanf("%d",&x);
    wei[x]=i;
    if (i%2==1) f1[i][0]=x;
    else f2[i][0]=x;
  }
  for (int j=1;(1<<j)<=n;j++)
  for (int i=(n-(1<<j)+1);i>=1;i--)
  {
   f1[i][j]=min(f1[i][j-1],f1[i+(1<<(j-1))][j-1]);
   f2[i][j]=min(f2[i][j-1],f2[i+(1<<(j-1))][j-1]);
  }
  dfs(1,n,0);
  for (int i=0;i<g[0].size();i++) q.push(-g[0][i]);
  bool fg=1;
  while (!q.empty())
  {
    int now=-q.top();q.pop();
	if (fg) printf("%d %d",now,to[now]);
	else printf(" %d %d",now,to[now]);
	fg=0;
	for (int i=0;i<g[now].size();i++)
	q.push(-g[now][i]);	
  } 
  return 0;
}

Measured memory_bytes: 49152
class SegmentTree

  def initialize n, arr = [], init = 0, &block
    block = -> (a, b) { a + b } unless block_given?
    @fun = block
    @n = 1
    @n *= 2 while @n < n
    @init = init
    @tree = Array.new(@n*2-1) { init }
    arr.each.with_index do |a, i| put(i, a) end
  end

  def put i, e
    i += @n - 1
    @tree[i] = e
    while i > 0
      i = (i-1) / 2
      @tree[i] = @fun.(@tree[i*2+1], @tree[i*2+2])
    end
  end

  def query a, b
    @a = a
    @b = b
    _query 0, 0, @n
  end

  private

  def _query i, l, r
    return @init if r <= @a || @b <= l
    return @tree[i] if @a <= l && r <= @b
    @fun.(_query(i*2+1, l, (l+r)/2), _query(i*2+2, (l+r)/2, r))
  end
end

n, q = gets.split.map(&:to_i)
segt = SegmentTree.new(n+1)
q.times do
  c, x, y = gets.split.map(&:to_i)
  if c == 0
    o = segt.query x, x+1
    segt.put x, o+y
  else
    puts segt.query(x, y+1)
  end
end


Measured memory_bytes: 8940
#include "cstdio"
int xxx(int x,int y)
{
    if(x<=y) return y-x;
        else return x-y+2;
} 
int min(int x,int y){
	return x<y?x:y;
}
int x,y;
int main(){
	scanf("%d%d",&x,&y);
	printf("%d",min(xxx(x,y),min(xxx(-x,y)+1,min(xxx(x,-y)+1,xxx(-x,-y)+2))));
}

Measured memory_bytes: 128
tate, yoko = map(int, input().split())
s  = [input()  for i in range(tate)]
dxy = [(-1, 0), (0, -1), (0, 1), (1, 0),]
for i in range(tate):
    for j in range(yoko):
        if s[i][j] == "#":
            save = []
            for dx, dy in dxy:
                if i + dy < 0 or i + dy > tate - 1 or j + dx < 0 or j + dx > yoko - 1: continue
                if s[i + dy][j + dx] == "#": 
                    save.append("#")
                    break
            if "#" in save: continue
            else:
                print("No")
                exit()
print("Yes")

Measured memory_bytes: 3064
import queue
num=int(input())
q=queue.Queue()
for i in range(1,10):
  q.put(i)
for j in range(num):
  ans=q.get()
  if ans%10!=0:
    q.put(10*ans+(ans%10)-1)
  q.put(10*ans+(ans%10))
  if ans%10!=9:
    q.put(10*ans+(ans%10)+1)
print(ans)

Measured memory_bytes: 12452
import sys
input = sys.stdin.buffer.readline

n,k = map(int,input().split())
a = list(map(int,input().split()))




for _ in range(k):
    b = [0]*n
    for i in range(n):
        if i-a[i] < 0:
            b[0] += 1
        else:
            b[i-a[i]] += 1

        if i+a[i]+1 < n:
            b[i+a[i]+1] -= 1
    
    judge = True
    tmp = 0
    for i in range(n):
        tmp += b[i]
        a[i] = tmp
        if tmp != n:
            judge = False
    if judge:
        break
print(*a)


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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

struct Edge { int to, c; };

struct State {
	int v, r, c;
	bool operator > (const State& o) const { return c > o.c; }
};

int n, m, c, dst[110][1010];
vector< vector< Edge > > adj;

void solve() {
	for_(i,0,n) for_(j,0,m+1) dst[i][j] = (int)1e9;	
	
	priority_queue< State, vector< State >, greater< State > > que;
	que.push(State{0, 0, 0});
	dst[0][0] = 0;
	
	while (!que.empty()) {
		State s = que.top(); que.pop();
		
		if (dst[s.v][s.r] < s.c) continue;
		
		for (Edge e : adj[s.v]) {
			if (dst[e.to][s.r] > s.c + e.c) {
				dst[e.to][s.r] = s.c + e.c;
				que.push(State{e.to, s.r, s.c + e.c});
			}
			
			if (dst[e.to][s.r + 1] > s.c) {
				dst[e.to][s.r + 1] = s.c;
				que.push(State{e.to, s.r + 1, s.c});
			}
		}
	}
	
	for_(i,0,m+1) {
		if (dst[n - 1][i] <= c) {
			cout << i << endl;
			break;
		}
	}
}

int main() {
	while (cin >> n >> m >> c, n) {
		adj.assign(n, vector< Edge >());
		
		for_(i,0,m) {
			int f, t, c;
			cin >> f >> t >> c;
			--f; --t;
			adj[f].push_back(Edge{t, c});
		}
		
		solve();
	}
}

Measured memory_bytes: 5796
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 998244353;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main(){
    int N;
    cin >> N;
    vector<P>A(N);
    for(int i = 0; i < N; i++) {
        cin >> A[i].first;
        A[i].second = i;
    }
    sort(A.begin(),A.end());
    int res = 0;
    for(int i = 0; i < N; i++) {
        if(A[i].second%2 != i%2) {
            res++;
        }
    }
    cout << res/2 << endl;
}


Measured memory_bytes: 4844
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <ctime>
#include <map>
#include <queue>
#include <cstdlib>
#include <string>
#include <climits>
#include <set>
#include <vector>
#define int long long
using namespace std;
inline int read(){
	int k=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}
	return k*f;
}
inline void write(int x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);putchar(x%10+'0');
}
inline void writeln(int x){
	write(x);puts("");
}
int f[3][100010],a[3][100010];
signed main()
{
	int n=read();
	for(int i=0;i<3;i++)
		for(int j=1;j<=n;j++)a[i][j]=read();
	for(int i=0;i<3;i++)sort(a[i]+1,a[i]+n+1);
	for(int i=1;i<=n;i++)f[0][i]=i;
	int ans=0;
	for(int j=1;j<3;j++)
		for(int i=1;i<=n;i++){
			int p=lower_bound(a[j-1]+1,a[j-1]+n+1,a[j][i])-a[j-1]-1;
			f[j][i]=f[j][i-1]+f[j-1][p];
		}
	writeln(f[2][n]);
}

Measured memory_bytes: 4992
#include<iostream>
using namespace std;
int k,s,cnt=0;
int main()
{
	cin>>k>>s;
	for(int x=0;x<=k;x++)
	{
		for(int y=0;y<=k;y++)
		{
			if(s-x-y>=0&&s-x-y<=k) cnt++;
		}
	}
	cout<<cnt<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
count = [0]*n
for i in range(n):
    count[a[i]-1] += 1
ans = 0
for i in range(n):
    ans += count[i]*(count[i]-1)//2
for i in a:
    print(ans-count[i-1]+1)

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

int main()
{

    cin >> N >> a >> b;

    int ans = abs(a - b) % 2;
    // cout << ans << endl;
    if (ans == 0)
    {
        cout << "Alice" << endl;
    }
    else if (ans == 1)
    {
        cout << "Borys" << endl;
    }
    else
    {
        cout << "Draw" << endl;
    }

    return 0;
}


Measured memory_bytes: 3600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            Solve();
        }
        private const int MOD = 1000000007;
        static void Solve()
        {
            var nk = ReadAndParseIntArr();
            int n = nk[0];
            int k = nk[1];
            var h = ReadAndParseIntArr();
            int[] dp = new int[n + 1];
 
            for(int i=1;i<n;++i)
            {
                int curMin = int.MaxValue;
                for(int j=1;j<=k;++j)
                {
                    if( i - j >= 0)
                    {
                        int curdp = dp[i - j] + Math.Abs(h[i] - h[i - j]);
                        curMin = Math.Min(curMin, curdp);
                    }
                }
                dp[i] = curMin;
            }
            int ans = dp[n - 1];
            Console.WriteLine(ans);
        }
        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if (x == 2) { return true; }
            if (x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while (i * i <= x)
            {
                if (x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }
        private static long pow(long x, long n)
        {
            if (n == 0) { return 1; }
            long res = pow(x * x % MOD, n / 2);
            if (n % 2 == 1)
            {
                res = res * x % MOD;
            }
            return res;
        }
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

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

long long N, C;
priority_queue<pair<long long, long long>,
		vector<pair<long long, long long> >,
		greater<pair<long long, long long> > >que[35];

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

	for(long long i = 0; i < N; i++){
		double s, t;
		long long c;
		cin >> s >> t >> c;
		c--;
		que[c].push(make_pair(s, t));
	}

	long long maxi = 0;
	for(long long t = 0; t < 100005; t++){
		long long tmp = 0;
		for(long long i = 0; i < 35; i++){
			if(que[i].size() == 0)
				continue;
			//if( t  == 3){
			//	cout << "t = 3 " << i << ", " << que[i].top().first << " - " << que[i].top().second << endl;
			//}

			if(que[i].top().first <= t && t <= que[i].top().second)
				tmp++;
		}
		maxi = max(maxi, tmp);

		for(long long i = 0; i < 35; i++){
			if(que[i].size() == 0)
				continue;
			if(que[i].top().second < t)
				que[i].pop();
		}
	}
	cout << maxi << endl;

}

Measured memory_bytes: 2688
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#define vector std::vector
#define string std::string
typedef long long ll;
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define min(a, b) std::min(a, b)
#define max(a, b) std::max(a, b)

template <class T = int>
T in() { T x; std::cin >> x; return x; }
#define output(e) std::cout << e << '\n'

#ifdef LOCAL
#define db std::cout << "L" << __LINE__ <<
#define de << "\n"
#define dv(x) << " " << #x << "->" << x
#else
#define db
#define de
#define dv(x)
#endif

//
// Implementation
//

int main() {
  int a = in();
  int b = in();
  int c = in();
  int d = in();
  if (std::abs(c - a) <= d) {
    output("Yes");
  } else if (std::abs(c - b) <= d && std::abs(b - a) <= d) {
    output("Yes");
  } else {
    output("No");
  }
}


Measured memory_bytes: 764
//Kriti Verma
#include<bits/stdc++.h>
#define     ll          long long
#define     MOD         1000000007
#define     pb          push_back
#define     vll         vector<long long>
#define     vi          vector<int>
#define     vl          vector<long>
#define     pii         pair<int, int>
#define     pll         pair<ll,ll>
#define     mp          make_pair
#define     all(a)      (a).begin(),(a).end()
#define     rep(i,a,b)  for(int i=a;i<b;i++)
#define     lcm(a,b)    (a*b)/__gcd(a,b)
#define     MAX         100002 
#define     ios          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

ll n;
ll dp[MAX];
vll a(MAX);

int minCost(ll idx){
    if(idx>=n)return INT_MAX;
    if(idx==n-1)return 0;
    if(dp[idx]!=-1)return dp[idx];
    dp[idx]=min(minCost(idx+1)+abs(a[idx]-a[idx+1]),minCost(idx+2)+abs(a[idx]-a[idx+2]));
    return dp[idx];
}
int main(){
    
    ios
    memset(dp,-1,sizeof dp);
    cin >> n;
    for(ll i=0;i<n;i++)cin >> a[i];
    cout << minCost(0) <<  "\n";    
    return 0;
}



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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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 (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;


int main(){
	ios_base::sync_with_stdio(false);
	ll N;
	deque<int> ans;

	cin >> N;

	//cout << bitset<8>(N) << endl;

	if( N == 1 ){
		cout << 2 << endl;
		cout << "1 1" << endl;
		return 0;
	}

	int idx = 1, sum = 0;
	bool start = false;
	for(ll k=45; k>0; k--){
		if( N & (1ll<<k) ){
			//if(ans.empty()) ans.push_back(idx++);
			if( !start ){
				start = true;
				ans.push_back(idx++);
				sum = sum * 2 + 1;
			}else{
				ans.push_back(idx++);
				//ans.push_front(idx++);
				int f = ans.front();
				ans.pop_front();
				ans.push_front(idx++);
				ans.push_front(f);
				sum = sum * 2 + 1;
				sum += 1;
				sum += 1;
			}
			//cout << k << " " << bitset<8>(sum) << endl;
		}else if( start ){
			ans.push_back(idx++);
			sum = sum * 2 + 1;
			// int b = ans.back();
			// ans.pop_back();
			// ans.push_back( idx++ );
			// ans.push_back( b );
			//cout << k << " " << bitset<8>(sum) << endl;
		}
	}
	ans.push_front(idx++);
	sum += 1;
	// ans.push_front(idx++);
	// sum += 1;
	if( N & 1 ){
		ans.push_front(idx++);
		sum += 1;
	}

	//cout << bitset<8>(sum) << endl;

	vector<int> v;
	for(auto t: ans) v.push_back(t);
	v.push_back(idx);
	ll dp[10005]={};
	rep(i,v.size()){
		rep(j,i) if( v[j] < v[i] ) dp[i] += dp[j];
		dp[i] += 1;
	}
	//cout << "dp = " << dp[ans.size()]-1 << endl;

	cout << ans.size()*2 << endl;
	rep(i,ans.size()){
		cout << i+1 << " ";
	}
	for(auto t: ans){
		cout << t << " ";
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int ,int> pi;
typedef pair<ll ,ll> pl;
typedef map<ll ,ll> ml;
#define modulo 1000000007
#define PI 3.14159265
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N=1e7+1;

void solve()
{
    int n;
    cin >> n;
    vector<int>a(4);
    string s;
    for(int i=0;i<n;i++)
    {
        cin >> s;
        if(s=="AC")a[0]++;
        else if(s=="WA")a[1]++;
        else if(s=="TLE")a[2]++;
        else if(s=="RE")a[3]++;
    }
    cout << "AC x " << a[0] <<endl;
    cout << "WA x " << a[1] <<endl;
    cout << "TLE x " << a[2] <<endl;
    cout << "RE x " << a[3] <<endl;
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    fast;
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}

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


int main() {
	int n;
  	cin>>n;
  	int h[n];
  	for(int i = 0; i < n; i++) cin>>h[i];
  	
  	for(int i = n -1 ; i >= 0; i--) {
     	if(h[i] < h[i-1]) {
         if(abs(h[i] - h[i-1]) > 1) {cout<<"No"<<"\n"; return 0;} 
         else h[i-1]--;
        }
    }
  cout<<"Yes"<<"\n";
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define LINF 1e18
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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


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

int dp[202020];
int N;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin>>N;
    int ans=0;
    REP(i,N){
        int p;cin>>p;
        dp[p]=dp[p-1]+1;
        chmax(ans,dp[p]);
    }
    cout<<N-ans<<endl;
}

Measured memory_bytes: 1024
// #include<iostream>
// #include<vector>
// #include<algorithm>
// #include<map>
// #include<cstring>
// #include<math.h>
// #include<bitset>
// #include<queue>
// #include<set>
// #include<iomanip>
// #include<math.h>
// #include<assert.h>
// #include<string>
// #include<cstdlib>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr ll INF = 1LL << 40;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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;
}
// ----------------------------------------------------------------------------

int main(){
  ll N,M;
  cin >> N >> M;
  if(abs(N-M)>1){
    cout << 0 << endl;
    return 0;
  }
  ll ans=1;
  for(ll i=2; i<=N; i++){
    ans *= i;
    ans %= mod;
  }
  for(ll i=2; i<=M; i++){
    ans *= i;
    ans %= mod;
  }
  if(N==M){
    ans *= 2;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <set>
#include <math.h>
#define pai 3.14159265358979323846264338327950288;
#define keta(n) cout << fixed << setprecision((n));
#define ll long long;
int main()
{

  double r;
  cin >> r;
  double s, l;
  s = r * r * pai;
  l = 2 * r * pai;
  keta(10);
  cout << s << " " << l << " " << endl;
}



Measured memory_bytes: 3276
// luogu-judger-enable-o2
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

template <typename _tp> inline void read(_tp&x){
	char ch=getchar(),ob=0;x=0;
	while(ch!='-'&&!isdigit(ch))ch=getchar();if(ch=='-')ob=1,ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();if(ob)x=-x;
}

#define lson l,mid,x<<1
#define rson mid+1,r,x<<1|1

const ll INF = 1e18;
const int N = 601000;
ll mi0[N], mi1[N], sg[N], tag[N];
int n, Q;

void build(int l, int r, int x) {
	sg[x] = mi0[x] = mi1[x] = INF;
	if(l == r) return ;
	int mid = l + r >> 1;
	build(lson), build(rson);
}

inline void down(int x) {
	const int l = x << 1, r = l | 1;
	ll&v = tag[x];
	sg[l] += v, sg[r] += v,
	mi0[l] += v, mi1[l] += v,
	mi0[r] += v, mi1[r] += v,
	tag[l] += v, tag[r] += v;
	v = 0;
}

void upd(int l, int r, int x, int ps, ll vl) {
	if(l == r) {
		if(sg[x] > vl) {
			sg[x] = vl;
			mi0[x] = vl - l;
			mi1[x] = vl + l;
		}
		return ;
	}
	if(tag[x]) down(x);
	int mid = l + r >> 1;
	if(ps <= mid) upd(lson, ps, vl);
	else upd(rson, ps, vl);
	mi0[x] = min(mi0[x<<1], mi0[x<<1|1]);
	mi1[x] = min(mi1[x<<1], mi1[x<<1|1]);
}

ll get0(int l, int r, int x, int R) {
	if(r <= R) return mi0[x];
	if(tag[x]) down(x);
	int mid = l + r >> 1;
	if(R <= mid) return get0(lson, R);
	return min(get0(lson, R), get0(rson, R));
}

ll get1(int l, int r, int x, int L) {
	if(L <= l) return mi1[x];
	if(tag[x]) down(x);
	int mid = l + r >> 1;
	if(mid < L) return get1(rson, L);
	return min(get1(lson, L), get1(rson, L));
}

ll get(int l, int r, int x) {
	if(l == r) return sg[x];
	if(tag[x]) down(x);
	int mid = l + r >> 1;
	return min(get(lson), get(rson));
}

int main() {
	read(n), read(Q);
	build(1, n, 1);
	int x, y, z;
	read(x), read(y), read(z);
	upd(1, n, 1, x, abs(y - z));
	upd(1, n, 1, y, abs(x - z));
	while(--Q) {
		read(x), y = abs(x - z);
		ll vl = min(get0(1, n, 1, x) + x, get1(1, n, 1, x) - x);
		mi0[1] += y, mi1[1] += y, tag[1] += y;
		upd(1, n, 1, z, vl), z = x;
	}
	printf("%lld\n", get(1, n, 1));
	return 0;
}

Measured memory_bytes: 18816
#include <iostream>
#include <cmath>
using namespace std;
int main(){
    int N , D , cnt = 0;
    cin >> N >> D;
    for (int i = 0 , x , y ; i < N ; i++){
        cin >> x >> y;
        if (ceil(hypot(x , y)) <= D)
            ++cnt;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3660
N, M = gets.split.map(&:to_i)
a = [0] * (N+2)
$<.map {|x| l, r = x.split.map(&:to_i); a[l]+=1;a[r+1]-=1 }
r = 0
p a.map {|x|r+=x}.count {|x|x== M}

Measured memory_bytes: 4220
#include <bits/stdc++.h>
using namespace std;
int main(void){
  int n,x,a,s,ans=0;
  cin >> n;
  for (x=105;x<=n;x+=2){
    s=0;
    a=3;
    while (a*a<x){
      if (x%a==0) s++;
      a+=2;
    }
    if (s==3) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
S = input()
T = ["AKIHABARA", "KIHABARA", "AKIHBARA", "AKIHABRA", "AKIHABAR",
     "KIHBARA", "KIHABRA", "KIHABAR", "AKIHBRA", "AKIHBAR", "AKIHABR",
     "KIHBRA", "KIHBAR", "KIHABR", "AKIHBR",
     "KIHBR"]
if S in T:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 2940
#include<stdio.h>
int main(void){
    char s[4];
    int a,b,c,d;
    scanf("%s",s);
    a=s[0]-'0';
    b=s[1]-'0';
    c=s[2]-'0';
    d=s[3]-'0';
    if(a+b+c+d==7){
        printf("%d+%d+%d+%d=7\n",a,b,c,d);
    }else if(a+b+c-d==7){
        printf("%d+%d+%d-%d=7\n",a,b,c,d);
    }else if(a+b-c+d==7){
        printf("%d+%d-%d+%d=7\n",a,b,c,d);
    }else if(a+b-c-d==7){
        printf("%d+%d-%d-%d=7\n",a,b,c,d);
    }else if(a-b+c+d==7){
        printf("%d-%d+%d+%d=7\n",a,b,c,d);
    }else if(a-b+c-d==7){
        printf("%d-%d+%d-%d=7\n",a,b,c,d);
    }else if(a-b-c+d==7){
        printf("%d-%d-%d+%d=7\n",a,b,c,d);
    }else if(a-b-c-d==7){
        printf("%d-%d-%d-%d=7\n",a,b,c,d);
    }
    return 0;
}



Measured memory_bytes: 128
#include <iostream>
int main(){
  int a,b,r=1;
  char c[12]={};
  std::cin>>a>>b>>c;
  for(int i=0;i<a+b+1;++i){
    if(i==a){r=(c[i]=='-'?r:0);}
    else{r=(c[i]>47&&c[i]<58?r:0);}
  }
  std::cout<<(r?"Yes":"No")<<"\n";
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int length = in.nextInt();
            if (in.nextInt() > 0) {
                System.out.println(-1);
                return;
            }
            long ans = 0;
            int prev = 0;
            for (int i = 1; i < length; i++) {
                int n = in.nextInt();
                if (n == 0) {
                } else if (n - prev > 1) {
                    System.out.println(-1);
                    return;
                } else if (n - prev == 1) {
                    ans++;
                } else if (n - prev <= 0) {
                    ans += n;
                }
                prev = n;
            }
            System.out.println(ans);
        }

    }
}



Measured memory_bytes: 64740
#include <iostream>

int main() {
	int n, m, l;
	std::cin >> n >> m >> l;

	long long** A = new long long*[n]();
	for (int i = 0; i < n; i++) {
		A[i] = new long long[m]();
	}

	long long** B = new long long*[m]();
	for (int j = 0; j < m; j++) {
		B[j] = new long long[l]();
	}

	long long** C = new long long*[n]();
	for (int k = 0; k < n; k++) {
		C[k] = new long long[l]();
	}

	for (int a = 0; a < n; a++) {
		for (int b = 0; b < m; b++) {
			std::cin >> A[a][b];
		}
	}

	for (int c = 0; c < m; c++) {
		for (int d = 0; d < l; d++) {
			std::cin >> B[c][d];
		}
	}

	for (int e = 0; e < n; e++) {
		for (int f = 0; f < l; f++) {
			for (int g = 0; g < m; g++) {
				C[e][f] += A[e][g] * B[g][f];
			}
		}
	}

	for (int o = 0; o < n; o++) {
		for (int p = 0; p < l; p++) {
			if (!(p == 0)) {
				std::cout << ' ';
			}
			std::cout << C[o][p];
		}
		std::cout << std::endl;
	}
}

Measured memory_bytes: 3324
#解説AC

import sys
sys.setrecursionlimit(1000000000)
input = sys.stdin.readline

n,m=map(int,input().split())
es=[[] for i in range(n)]
for i in range(m):
    x,y=map(int,input().split())
    es[x-1].append(y-1)

dp=[-1]*n

def memo(v):
    if dp[v]+1: #更新済 dp[v]!=-1
        return dp[v]
    a=0
    for i in es[v]:
        a=max(a,memo(i)+1)
    dp[v]=a
    return a

ans=0
for i in range(n):
    ans=max(ans,memo(i))

print(ans)

Measured memory_bytes: 59056
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  int n, t; cin >> n >> t;
  vector<int> a(n), b(n);
  for(int i = 0; i < n; i++){
    cin >> a[i] >> b[i];
  }

  vector<int> v;

  vector<int> order(n);
  iota(order.begin(),order.end(),0);
  sort(order.begin(),order.end(),[&](int i, int j){
    if(a[i] == a[j]) return b[i] > b[j];
    return a[i] < a[j];
  });
  for(int i = 0; i < min(n, 10LL); i++){
    v.push_back(order[i]);
  }

  iota(order.begin(),order.end(),0);
  sort(order.begin(),order.end(),[&](int i, int j){
    if(b[i] == b[j]) return a[i] < a[j];
    return b[i] > b[j];
  });
  for(int i = 0; i < min(n, 10LL); i++){
    v.push_back(order[i]);
  }

  int ans = 0;
  for(int u = 0; u < v.size(); u++){
    vector<int> dp(t+10, 0);
    for(int i = 0; i < n; i++){
      if(i == v[u]) continue;
      for(int j = t; j >= 0; j--){
        if(j + a[i] > t) continue;
        dp[j + a[i]] = max(dp[j + a[i]], dp[j] + b[i]);
      }
    }
    ans = max(ans, dp[t-1] + b[v[u]]);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
void yes(){
  cout << "Yes" << endl;
  exit(0);
}

void no(){
  cout << "No" << endl;
  exit(0);
}

struct UnionFind {
  vector<int> par;
  vector<int> sizes;

  UnionFind(int N) : par(N), sizes(N, 1) {
    for(int i = 0; i < N; i++) par.at(i) = i;
  }

  int find(int x) { 
    if (par.at(x) == x) return x;
    return par.at(x) = find(par.at(x));
  }

  void unite(int x, int y) {
    int rx = find(x); 
    int ry = find(y); 
    if (rx == ry) return; 
    if (sizes.at(rx) < sizes.at(ry)) swap(rx,ry);
    par.at(ry) = rx;
    sizes.at(rx) += sizes.at(ry);    
  }

  bool same(int x, int y) {
    return find(x) == find(y);
  }

  int size(int x){
    return sizes.at(find(x));
  }

  int num_of_connected_components(){
    int ret = 0;
    for(int i = 0; i < par.size(); i++){
      if(find(i) == i) ret++;
    }
    return ret;
  }
};

int main(){
  ll n, m; cin >> n >> m;
  UnionFind uft = UnionFind(n);
  vector<int> seen(n,0);
  vector<ll> x(n);
  //x[l] + d = x[r]
  //diff[l] = (r,d),....
  vector<vector<pair<ll,ll>>> diff(n);
  REP(i,m){
    ll l,r,d; cin >> l >> r >> d;
    l--; r--;
    diff[l].push_back({r,d});
    diff[r].push_back({l,-d});
    uft.unite(l,r);
  }

  map<ll,vector<ll>> team;
  REP(i,n){
    ll p = uft.find(i);
    team[p].push_back(i);
  }

  FOREACH(t, team){
    ll p = t.first;
    queue<ll> q;
    x[p] = 0;
    q.push(p);
    seen[p] = 1;
    while(!q.empty()){
      ll cv = q.front();
      q.pop();
      FOREACH(nvinfo,diff[cv]){
        ll nv = nvinfo.first;
        ll d = nvinfo.second;
        if(seen[nv]){
          if(x[cv] + d != x[nv]) no();
        }else{
          x[nv] = x[cv] + d;
          seen[nv] = 1;
          q.push(nv);
        }
      }
    }
   
    //0以上1e9以下の範囲に収まるかチェック
    ll mini = 1e18;
    ll maxi = -1e18;
    ll s = team[p].size();
    REP(i,s){
      ll v = x[team[p][i]];
      mini = min(mini, v);
      maxi = max(maxi, v);
    }
    if(maxi-mini>(ll)1e9) no();
  }
  yes();
}


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

using namespace std;

int main(void) {
  int i, tmp, count;
  int N, X, D;
  vector<int> L;
  // get input ----------------------
  cin >> N;
  cin >> X;
  for(i = 0; i < N; i++) {
    cin >> tmp;
    L.push_back(tmp);
  }
  // bound -------------------------
  D = 0;
  i = 0;
  count = 1;
  while(1) {
    D += L[i];
    if(D > X) break;
    i++;
    count++;
    if(i == N) break;
  }
  cout << count << endl;
  
  return 0;
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class BSortingASegment {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N, K;
        in>>N>>K;
        vc<int> P(N);
        REP(i, N) in>>P[i];
        int ans = N - K + 1;
        deque<int> mn, mx;
        REP(i, K){
            while(not mn.empty() and mn.back()>P[i]) mn.pop_back();
            mn.push_back(P[i]);
            while(not mx.empty() and mx.back()<P[i]) mx.pop_back();
            mx.push_back(P[i]);
        }
        REP(i, N-K){
            if(mn.front()==P[i] and mx.front()<P[i+K]){
                --ans;
                mn.pop_front();
            }
            if(mn.front()==P[i]){
                mn.pop_front();
            }
            if(mx.front()==P[i]){
                mx.pop_front();
            }
            while(not mn.empty() and mn.back()>P[i+K]) mn.pop_back();
            mn.push_back(P[i+K]);
            while(not mx.empty() and mx.back()<P[i+K]) mx.pop_back();
            mx.push_back(P[i+K]);
        }
        int cnt = 0, pre = -1, len = 0;
        REP(i, N){
            if(P[i]>pre) ++len, pre = P[i];
            else{
                if(len>=K) ++cnt;
                len = 1, pre = P[i];
            }
        }
        if(len>=K) ++cnt;
        if(cnt) ans -= cnt - 1;
        out<<ans<<"\n";
    }
};


int main() {
	BSortingASegment solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <unordered_map>
#include <vector>
#include <algorithm>

using namespace std;

struct Point {
  int a;
  int b;
  char axis;
  bool is_minus_a;
  bool is_minus_b;

  int get_a() const {
    return (is_minus_a ? (-1) : 1) * a;
  }
  int get_b() const {
    return (is_minus_b ? (-1) : 1) * b;
  }

  int x() const {
    return axis == 'x' ? get_a() : get_b();
  }
  int y() const {
    return axis == 'x' ? get_b() : get_a();
  }
};

int main() {
  int k,x,y;
  cin >> k >> x >> y;

  vector<Point> result;
  
  // もしkが偶数の場合、偶奇の組み合わせには到達しない
  if (k%2 == 0 && (abs(x)%2 != abs(y)%2)) {
    cout << -1 << endl;
    return 0;
  }

  int a = x;
  int b = y;
  int current_a = 0;
  int current_b = 0;
  char axis = 'x';
  if (abs(a-current_a) < abs(b-current_b)) {
    swap(a,b);
    swap(current_a,current_b);
    axis = 'y';
  }

  // この時点でaのほうが差が大きい

  bool is_minus_a = false;
  bool is_minus_b = false;
  // a,bのマイナスをとって、第1象限内で考える
  if (a < 0) {
    is_minus_a = true;
    a = abs(a);
  }
  if (b < 0) {
    is_minus_b = true;
    b = abs(b);
  }

  // 差がkの倍数でない場合、調整
  int diff, diff_a, diff_b;
  while ((diff = (abs(a-current_a) + abs(b-current_b)) % k) != 0) {
    bool find_a = false;

    if ((k+diff)%2 == 0) {
      // diff_a + diff_b = diff 分だけ縮まる
      diff_a = (k+diff)/2;
      diff_b = -(k-diff)/2;
      if (diff_a <= abs(a-current_a)) {
        // aを飛び越さない場合のみ、対象とする。(飛び越しても倍数にはならないので、いったん引いた場合と同じ回数になるため)
        find_a = true;
      }
    }
    
    if (!find_a && diff%2 == 0){
      // diff_a + diff_b = - k + diff 分だけ縮まる
      diff_a = diff/2;
      diff_b = - (k - diff/2);
      if (diff_a <= abs(a-current_a)) {
        // aを飛び越さない場合のみ、対象とする
        find_a = true;
      }
    }

    if (!find_a) {
      // 条件に一致しない場合は、いったん引く
      // この場合のみもう1回ループ
      diff_a = -k;
      diff_b = 0;
    }

    current_a += diff_a;
    current_b += diff_b;

    result.push_back({current_a, current_b, axis, is_minus_a, is_minus_b});
    // cout << current_a << " " << current_b << " " << axis << endl;
  }

  // 差がkの倍数になったら、適当に詰める
  while ((a != current_a) || (b != current_b)) {
    diff_a = min(k, abs(a-current_a));
    diff_b = k - diff_a;

    current_a += diff_a;
    current_b += diff_b;

    result.push_back({current_a, current_b, axis, is_minus_a, is_minus_b});
  }
 
  cout << result.size() << endl;
  for (const auto& point : result) {
    cout << point.x() << " " << point.y() << endl;
  }
  
  return 0;
}


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

#define ll long long
#define ull unsigned long long 
#define endl '\n'

int main(){
    int n;
    cin >> n;
    int t, x, y;
    int pt=0, px=0, py=0;
    for(int i=0; i<n; ++i){
        cin >> t >> x >> y;
        t -= pt;
        x = abs(x-px);
        y = abs(y-py);

        if(x+y <= t){
            if(t-(x+y)&1){
                cout << "No";
                return 0;
            }
        }
        else{
            cout << "No";
            return 0;
        }
        pt = t;
        px = x;
        py=y;
    }
    cout << "Yes";
}


Measured memory_bytes: 3588
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <array>

using namespace std;

template<typename T>
struct Node {
	Node(const T& value) :value(value), parent(NULL), left(NULL), right(NULL) {}
	Node():Node(T()) {}
	T value;
	Node* parent;
	Node*left;
	Node*right;
};

template<typename T>
class BinarySearchTree
{
public:
	enum VisitOrder {
		ROOT = 0, LEFT = 1, RIGHT = 2
	};
	BinarySearchTree():root(NULL){}
	void insert(const T& value) {
		Node<T>* newNode(new Node<T>(value));
		Node<T>* parent = NULL;
		Node<T>* parentChild = NULL;
		{
			Node<T>* tempRootPtr = root;
			while (tempRootPtr != NULL) {
				parent = tempRootPtr;
				tempRootPtr = value < tempRootPtr->value ? tempRootPtr->left : tempRootPtr->right;
			}
		}
		newNode->parent = parent;
		if (parent == NULL) root = newNode;
		else (value < parent->value ? parent->left : parent->right) = newNode;
	}
	
	void printNodeKeys(const array<int, 3>& order) {
		const array< function< Node<T>*(Node<T>*) >, 3> functionList = {
			  [&](Node<T>* node) {return node; }
			, [&](Node<T>* node) {return node->left; }
			, [&](Node<T>* node) {return node->right; }
		};

		function< void(Node<T>*) > printNodesImpl = [&](Node<T>* node){
			if (node == NULL)return;
			for (const auto& visitTargetIndex : order) {
				Node<T>* visitingNode = (functionList.at(visitTargetIndex))(node);
				if (visitingNode == node) cout << " " << visitingNode->value;
				else printNodesImpl(visitingNode);
			}
		};
		printNodesImpl(root);
	}

	Node<T>* find(const T& val) {
		Node<T>* currentNode = root;
		while (currentNode != NULL && currentNode->value != val) {
			currentNode = (val < currentNode->value ? currentNode->left : currentNode->right);
		}
		return currentNode;
	}

private:
	Node<T>* root;
};

template<typename T>
void execute(T& cin) {
	int n;
	cin >> n;
	string command;
	using Tree = BinarySearchTree<int>;
	Tree tree;
	command.reserve(6);//insertが最長で6
	for (int i = 0; i != n; ++i) {
		command.clear();
		cin >> command;
		if (command == "insert") {
			int key;
			cin >> key;
			tree.insert(key);
		}
		else if (command == "find") {
			int key;
			cin >> key;
			cout << (tree.find(key) != NULL ? "yes" : "no") << endl;
		}
		else if(command =="print"){
			tree.printNodeKeys({ Tree::LEFT, Tree::ROOT, Tree::RIGHT });
			cout << endl;
			tree.printNodeKeys({ Tree::ROOT, Tree::LEFT, Tree::RIGHT });
			cout << endl;
		}
	}

}

int main()
{

	execute(cin);


	return 0;
}


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

int main(){
    
    int r , D , x2000; cin >> r >> D >> x2000;
    
    long long ans_using = x2000;
    
    for(int i = 0; i < 10; i++){
        
        ans_using = (r * ans_using) - D;
        
        cout << ans_using << endl;
        
    }
    return 0;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

#include <vector>

using namespace std;

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

	int a;
	cin >> a;

	cout << a + a * a + a * a * a;
	
	return 0;
}


Measured memory_bytes: 3620
import scala.io.StdIn.readLine

object Main extends App {
  val MOD = 1000000007
  val n = readLine.toInt
  val a = readLine.split(" ").map(_.toInt)

  val one = 0.until(n).filter(_%2==0).map(a(_))
  val two = 0.until(n).filter(_%2==1).map(a(_))

  val ans = if(n % 2 == 0) two.reverse.++(one)
  else one.reverse.++(two)

  println(ans.mkString(" "))
}

Measured memory_bytes: 74948
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <string>
#include <vector>

double calc(std::vector<std::vector<int> > coordinate) {
    int size = coordinate.size();
    double area = 0;
    for (int i = 0; i < size - 1; i++) {
        area += coordinate[i][0] * coordinate[i + 1][1] - coordinate[i + 1][0] * coordinate[i][1]; 
    }
    area += coordinate[size - 1][0] * coordinate[0][1] - coordinate[0][0] * coordinate[size - 1][1]; 
    if (area < 0) {
        area *= (-1);
    }
    return area / 2;
}

int main(void) {
    int n;
    int times = 0;
    std::string ErrorReport;
    try{
        std::cin >> n;    
        while (n != 0) {
            times++;
            if (n < 3 || n > 50) {
                ErrorReport = "n is out of range";
                throw ErrorReport;
            }
            std::vector<std::vector<int> > coordinate(n, std::vector<int> (2, 0));
            for (int i = 0; i < n; i++) {
                std::cin >> coordinate[i][0];
                std::cin >> coordinate[i][1];
            }
            double area = calc(coordinate);

            std::cout << std::fixed << std::setprecision(1);
            std::cout << times << " " << area << std::endl;
            std::cin >> n;    
        }
        return EXIT_SUCCESS;
    } catch (std::string ErrorReport){
        std::cout << ErrorReport << std::endl;
    }
}

Measured memory_bytes: 3180
#include <iostream>
#include <cmath>

using namespace std;

int main() {
    int X;

    cin >> X;

    int result = 0;
    int max = 0;

    for (int i = 2; i <= 10; i++) {
        for (int j = 1; j <= 1000; j++) {
            if (pow(j, i) <= X) {
                result = pow(j, i);
            } else {
                break;
            }
        }

        if (max < result) {
            max = result;
        }
    }

    cout << max << endl;

    return 0;
}

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

using namespace std;

int findsum(int a[],int n)
{
    int product=0;
    for(int i=0;i<n;i++)
    {
        for(int j=i+1;j<n;j++)
        {
            product=product+ a[i]*a[j];
        }
    }

    return product;
}

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

    int A[500];

    int n;
    cin>>n;

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

    cout<<findsum(A,n)<<endl;


    return 0;
}


Measured memory_bytes: 256
n,x = map(int, input().split())
L = list(map(int, input().split()))

H = 0
count = 0
for i in range(n):
  if H > x:
    print(count)
    exit()
  else:
    H += L[i]
    count += 1
  
if H > x:
  print(n)
else:
  print(n+1)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <math.h>
#include <fstream>
#include <string>
#include <time.h>
#include <ctime>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#pragma warning(disable : 4996)
using namespace std;

struct Node{
	int key;
    Node *prev;
	Node *next;
};

Node *nil;

void init(){
	nil = (Node *)malloc(sizeof(Node));
	nil->next=nil;
	nil->prev=nil;
}

void insert(int key){
	Node* x=(Node *)malloc(sizeof(Node));
	x->key=key;
	x->next=nil->next;
	nil->next->prev=x;
	nil->next=x;
	x->prev=nil;
}

Node* listSearch(int key){
	Node* cur = nil->next;
	while(cur != nil&&cur->key != key){
		cur = cur->next;
	}
	return cur;
}

void deleteNode(Node *t){
	if(t==nil)return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst(){
	deleteNode(nil->next);
}

void deleteLast(){
	deleteNode(nil->prev);
}

void deleteKey(int key){
	deleteNode(listSearch(key));
}

void print(){
	Node* cur = nil->next;
	while(cur != nil){
		if(cur != nil->next)printf(" "); 
		printf("%d",cur->key);
		cur = cur->next;
	}
	printf("\n");
}

int main(){

	int key,n;
	int size=0;
	char com[20];
	int np=0,nd=0;
	scanf("%d", &n);
	init();
	for(int i=0;i<n;i++){
		scanf("%s%d", com, &key);
		if(com[0]=='i'){insert(key);np++;size++;}
		else if(com[0]=='d'){
			if(strlen(com)>6){
				if(com[6]=='F')deleteFirst();
				else if(com[6]=='L')deleteLast();
			}
			else{
					deleteKey(key);nd++;
			}
			size--;
		}
	}

	print();

	return 0;
}

Measured memory_bytes: 32360
n,k=map(int,input().split())
x=list(map(int,input().split()))

lis=[]
for i in range(0,n):
  lis.append(abs(x[i]-k))

def gcd(a,b):
  aa=max(a,b)
  bb=min(a,b)
  cc=aa%bb
  aa=bb
  bb=cc
  if bb!=0:
    return gcd(aa,bb)
  else:
    return aa

res=lis[0]
for i in range(1,n):
  res=gcd(res,lis[i])
print(res)
  
  

Measured memory_bytes: 14224
/**
 *  author: Behradm
 *  Created: 2020.06.21 16:15:45
 *  In The Name Of God
**/
#include <bits/stdc++.h>

using namespace std;

int main() {   
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n;
  cin >> n;
  string res = "";
  while (n > 0) {
    int c = (n % 26);
    if (c == 0)
      res += 'z';
    else
      res += (char) ((int) 'a' + c - 1);
    //res += (char) ((int) 'a' + ((n % 26) - 1));
    n /= 26;
    if (c == 0)
      n--;
  }

  reverse(res.begin(), res.end());

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


Measured memory_bytes: 3612
from math import gcd
def main():
  n, k = map(int, input().split())
  a = list(map(int, input().split()))
  g = a[0]
  for i in range(1, n):
    g = gcd(g, a[i])
  if k <= max(a) and k % g == 0:
    print("POSSIBLE")
  else:
    print("IMPOSSIBLE")
if __name__ == "__main__":
  main()

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

long long int n,a[100100],b[100100],c[100100],i,dp[100100][5];

signed main()
{
    ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin>>n;
	for (i=1;i<n+1;i++) cin>>a[i]>>b[i]>>c[i];
	dp[1][1]=a[1];
	dp[1][2]=b[1];
	dp[1][3]=c[1];
	if (n>1) for (i=2;i<n+1;i++)
	{
		dp[i][1]=max(dp[i-1][2],dp[i-1][3])+a[i];
		dp[i][2]=max(dp[i-1][3],dp[i-1][1])+b[i];
		dp[i][3]=max(dp[i-1][1],dp[i-1][2])+c[i];
	}
	cout<<max(dp[n][1],max(dp[n][2],dp[n][3]));
}



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

int main() {
  ll a,b,c,d;
  cin >> a >> b >> c >> d;
  ll ans = b-a+1;
  ll e = c/gcd(c,d)*d;
  ans -= b/c-(a-1)/c+b/d-(a-1)/d-(b/e-(a-1)/e);
  cout << ans << endl;
  return 0;
}

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

typedef long long int ll;
ll MOD = 1000000007;
ll INFL = 1ll << 60;
ll INF = 1 << 30;

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

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

// ====================================================================

int main() {
  ll n;
  cin >> n;
  set<ll> v;
  ll a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    v.insert(a);
  }

  ll ans = 1;
  for (auto x : v) {
    ans = lcm(ans, x);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(ll i=0;i<n;i++)
#define ll long long
using namespace std;
ll n; ll a[114514];
signed main() {
	cin >> n;
	rep(i, n)cin >> a[i];
	ll cnt = a[0], ans = 0;
	if (cnt == 2)cout << 1 << endl;
	else {
		rep(i, 114514) {
			cnt = a[cnt - 1];
			ans++;
			if (cnt == 2) {
				cout << ans + 1 << endl;
				return 0;
			}
		}
		cout << -1 << endl;
	}
	getchar(); getchar(); return 0;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define BiSearchRangeNum(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y)

int main() {
  int N, K;
  cin >> N >> K;
  priority_queue<pair<ll, int>> menu; // <美味しさ, 種類>
  vector<pair<ll, int>> order;
  map<int, int> used;
  ll ans = 0;
  rep(i, 0, N) {
    int tmpt;
    ll tmpd;
    cin >> tmpt >> tmpd;
    menu.push(make_pair(tmpd, tmpt));
  }
  rep(i, 0, K) {
    auto tmp = menu.top();
    menu.pop();
    order.push_back(tmp);
    ans += tmp.first;
    used[tmp.second]++;
  }
  ll sz = (ll)used.size();
  ans += sz * sz;

  ll tmpAns = ans;
  for (int i = K - 1; i >=0; i--) {
    if (used[order[i].second] == 1) continue;
    while(menu.size() > 0) {
      // 交換する候補
      auto tmp = menu.top();
      menu.pop();
      // 交換する候補の種類が今までのorderにあるかいなか
      if (used[tmp.second] == 0) {
        // orderの中で二品以上のものとなっている
        auto tmpOut = order[i];
        used[tmpOut.second]--;
        used[tmp.second]++;
        tmpAns = tmpAns - tmpOut.first + tmp.first + 2 * sz + 1;
        sz++;
        ans = max(ans, tmpAns);
        order[i] = tmp;
        break;
      }
    }
  }

  cout << ans << endl;
};


Measured memory_bytes: 6512