akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
struct Edge {
  int to;
  LL diff;

  Edge(int to, LL diff) : to(to), diff(diff) {}
};
struct Dist {
  LL dist;
  int pos;
  Dist() : dist(0), pos(0){};
  Dist(LL dist, int pos) : dist(dist), pos(pos) {}
};
bool operator<(const Dist &a, const Dist &other) {
  if (other.dist != a.dist) return a.dist > other.dist;
  return true;
}
const LL MOD = 1000000007;
void dijkstra(vector<LL> &dist, vector<LL> &ans, int s,
              vector<vector<Edge>> edges) {
  int N = edges.size();

  ans.resize(N);
  priority_queue<Dist> pq;
  pq.push(Dist(0, s));
  vector<int> used(N, 0);
  // vector<LL> dist(N, 0);
  LL INF = 100000000;
  INF *= INF;
  dist = vector<LL>(N, INF);
  dist[s] = 0;
  while (!pq.empty()) {
    Dist d = pq.top();
    pq.pop();
    int v = d.pos;
    if (used[v] == 1) continue;
    if (dist[v] != d.dist) continue;
    used[v] = 1;
    for (auto e : edges[v]) {
      int u = e.to;
      LL update = e.diff + d.dist;
      if (dist[u] > update) {
        dist[u] = update;
        pq.push(Dist(dist[u], u));
      }
    }
  }

  vector<Dist> result(N);
  for (int i = 0; i < N; i++) result[i] = Dist(dist[i], i);
  sort(result.begin(), result.end());
  reverse(result.begin(), result.end());

  ans = vector<LL>(N, 0);
  ans[s] = 1;
  for (auto res : result) {
    int v = res.pos;
    for (auto e : edges[v]) {
      if (dist[e.to] + e.diff != dist[v]) continue;
      ans[v] += ans[e.to];
      ans[v] %= MOD;
    }
  }
}

int main() {
  int N, M, s, t;
  cin >> N >> M >> s >> t;
  s--;
  t--;
  vector<vector<Edge>> edges(N);
  for (int i = 0; i < M; i++) {
    int v, u, dist;
    cin >> v >> u >> dist;
    v--;
    u--;
    dist *= 2;
    edges[v].push_back(Edge(u, dist));
    edges[u].push_back(Edge(v, dist));
  }
  vector<LL> res1, res2, dist, distA;
  dijkstra(distA, res1, s, edges);
  dijkstra(dist, res2, t, edges);

  for (int i = 0; i < N; i++) {
    // cout << i << "  " << dist[i] << " " << res1[i] << " " << res2[i] << endl;
  }

  LL med = -1;
  LL maxdist = dist[s];

  if (maxdist % 2 == 0) med = maxdist / 2;

  LL ans = 0;
  ans = res2[s] * res2[s] % MOD;
  assert(res2[s] == res1[t]);
  // cout << ans << endl;
  LL sum = 0;
  for (int v = 0; v < N; v++) {
    if (dist[v] + distA[v] > maxdist) continue;
    if (dist[v] == med && distA[v] == med) {
      LL tmp = res1[v] * res1[v] % MOD;
      tmp = tmp * res2[v] % MOD;
      tmp = tmp * res2[v] % MOD;
      ans -= tmp;
      ans %= MOD;
      sum += res2[v] * res1[v];
    }
    if (dist[v] >= med) continue;
    for (auto e : edges[v]) {
      if (maxdist < distA[e.to] + dist[v] + e.diff) continue;
      if (dist[e.to] != dist[v] + e.diff) continue;
      if (dist[e.to] > med) {
        sum += res2[v] * res1[e.to] % MOD;
        LL tmp = res1[e.to] * res2[v] % MOD;
        tmp *= tmp;
        tmp %= MOD;
        ans -= tmp;
        ans %= MOD;
      }
    }
  }
  assert(sum % MOD == res2[s]);
  ans += MOD;
  ans %= MOD;
  assert(ans >= 0);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 29556
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;
 
int main(){
    string a,b,c;
    cin>>a>>b>>c;
    if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0]) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}

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

int main(){
	string s;
	int n;

	cin >> n >> s;

	const char* an = s.c_str();
	const char* ans = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";

	int len = s.length();
	string answer="";
	rep(i,len){
		rep(j,52){
			if(ans[j] == an[i]){
				answer += ans[j+n];
				break;
			}
		}
	}
	cout << answer <<endl;

	return 0;

}

Measured memory_bytes: 256
process.stdin.resume();
process.stdin.setEncoding('utf8');
// 自分の得意な言語で
// Let's チャレンジ！！

var lines = [];
var reader = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on('line', (line) => {
  lines.push(line);
});
reader.on('close', () => {
  const readLines = (input) => input.split('\n')
  var c = (value) => console.log(value)
var N = parseInt(lines[0].split(' ')[0]);
var D = parseInt(lines[0].split(' ')[1]);
  
var count =0;
  for(var i=1;i<=N;i++){
   if(parseInt(lines[i].split(' ')[0])**2 + parseInt(lines[i].split(' ')[1])**2 <= D**2 ){
   	count++;
   }
  }
  
  c(count);

  
});

Measured memory_bytes: 79652
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

void inp_str(int*);

int main(void) {

int input1[150];
inp_str(input1);

int input2[150];
inp_str(input2);

int temp=10000;

int sum=0;

int i;
for(i=0;i<input1[0];i=i+1){
 sum=sum+input2[i];
}

int diff;
int j;
int sum2;
for(j=0;j<input1[0];j=j+1){
	sum2=0;
	for(i=j;i<input1[0];i=i+1){
	 sum2=sum2+input2[i];
	}
	diff=abs((sum-sum2)-sum2);
	if(diff<temp) {temp=diff;}
}



printf("%d\n",temp);

    return 0;

}


void inp_str(int instr[]){
char *ptr;
int z,i,count;
char str[20000]={'\0'};
char *ln;

fgets(str, 20000, stdin); // 入力："123456\n"
ln = strchr(str, '\n'); /* 改行文字を検索 */
if (ln != NULL) { /* 改行が読み取られていたかどうか */
   *ln = '\0';    /* 改行文字を終端文字に置き換える */
}
else {            /* 入力ストリーム上に文字が残ってる場合 */
   while (1) {    /* 改行文字が読み取られるまで空読みする */
       z = getchar();
      if (z == '\n' || z == EOF) break;
   }
}
	count=0;
    ptr = strtok(str, " ");
    i = atoi(ptr);
    instr[count]=i;
    count=count+1;
    // 2回目以降
    while(ptr != NULL) {
        // strtok関数により変更されたNULLのポインタが先頭
        ptr = strtok(NULL, " ");
        // ptrがNULLの場合エラーが発生するので対処
        if(ptr != NULL) {
		    i = atoi(ptr);
    instr[count]=i;
    		count=count+1;
        }
    }
}



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

int main()
{
    int x;
    int ans;
    cin >> x;
    ans=x/500*1000+x%500/5*5;
    cout << ans << endl;
    return 0;
}

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

int N;

int main(){
  cin >> N;
  int dp[N],data[N];
  int k,K,kk;
  for(int i=0;i<N;i++){
    cin >> data[i];
  }
  for(int i=0;i<N;i++){
    if(i==0){
      dp[i]=0; continue;
    }
    if(i==1){
      dp[i]=abs(data[0]-data[1]); continue;
    }
    K=dp[i-2]+abs(data[i-2]-data[i]);
    k=dp[i-1]+abs(data[i-1]-data[i]);
    dp[i]=min(K,k);
  }
  cout << dp[N-1]<<endl;
}

Measured memory_bytes: 1024
#include<cstdio>
using namespace std;
int main(){
  int n,m,flag;
  char a[51][51],b[51][51];
  scanf("%d %d",&n,&m);
  for(int i=0;i<n;i++)
    scanf("%s",a[i]);
  for(int i=0;i<m;i++)
    scanf("%s",b[i]);
  for(int i=0;i<n-m+1;i++)
    for(int j=0;j<n-m+1;j++){
      flag=1;
      for(int k=0;k<m;k++)
        for(int l=0;l<m;l++)
          if(a[i+k][j+l]!=b[k][l])
            flag=0;
      if(flag){
        printf("Yes\n");
        return 0;
      }
    }
  printf("No\n");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int n;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  int x=*max_element(a,a+n);
  int y=*min_element(a,a+n);
  if(x-y>1){
    cout<<"No"<<endl;
    return 0;
  }
  if(x==y){
    if(2*x<=n||n==x+1){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
    return 0;
  }
  int cnt=0;
  for(int i=0;i<n;i++){
    if(a[i]==y) cnt++;
  }
  if(cnt>=x){
    cout<<"No"<<endl;
    return 0;
  }
  if((x-cnt)*2<=(n-cnt)) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


Measured memory_bytes: 1024
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

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

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define trav(x,A) for(auto &x:A)
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
typedef vector<int> veci;
typedef vector<long long> vecl;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
	if (y == 0) 
		return 1; 
	ll p = power(x, y/2) % MOD; 
	p = (p * p) % MOD; 
  
	return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

int main()
{
	#ifndef ONLINE_JUDGE
	if (fopen("INPUT.txt", "r"))
	{
		freopen ("INPUT.txt" , "r" , stdin);
		//freopen ("OUTPUT.txt" , "w" , stdout);
	}
	#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	clock_t clk;
	clk = clock();
//-----------------------------------------------------------------------------------------------------------//

	string S;
	cin>>S;
	S="0"+S;
	ll N=S.length();
	reverse(S.begin(),S.end());
	vector<ll> dp(N+2,inf);
	dp[0]=0;
	ll carry=0;
	FORI(i,0,N)
	{
		ll x=(ll)S[i]-(ll)'0'+carry;
		carry=0;
		if(x<5 || x==5 && S[i+1]<'5')
		{
			dp[i+1]=dp[i]+x;
		}
		else if(x<10)
		{
			carry=1;
			dp[i+1]=dp[i]+10-x;
		}
		else
		{
			carry=x/10;
			x=x%10;
			if(x<5 || x==5 && S[i+1]<'5')
			{
				dp[i+1]=dp[i]+x;
			}
			else if(x<10)
			{
				carry++;
				dp[i+1]=dp[i]+10-x;
			}
		}
	}
	cout<<dp[N]<<endl;

//-----------------------------------------------------------------------------------------------------------//


	clk = clock() - clk;
	cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

	return 0;
}

Measured memory_bytes: 9160
#include <algorithm>
#include <cassert>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <numeric>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define int long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(), (x).end()
#define capi(x) int x;cin>>x
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using vi = vector<int>;
using pi = pair<int, int>;
using vp = vector<pi>;
using Graph = vector<vector<int>>;

template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}

#define P (1'000'000'007)

// With size

class UnionFind {
public:
    UnionFind(int n) {
        for (int i = 0; i < n; i++) {
            _parent.push_back(i);
            _size.push_back(1);
        }
    }

    int find(int index) {
        if (is_root(index)) return index;
        return _parent[index] = find(_parent[index]);
    }

    bool is_root(int index) {
        return _parent[index] == index;
    }

    bool has_same_root(int lhs, int rhs) {
        return find(lhs) == find(rhs);
    }

    void unite(int lhs, int rhs) {
        int l = find(lhs);
        int r = find(rhs);
        if (has_same_root(l, r)) return;
        _size[l] += _size[r];
        _parent[r] = l;
    }

    int size(int index) {
        return _size[find(index)];
    }

private:
    vector<int> _parent;
    vector<int> _size;
};

signed main() {
    int n, m;
    cin >> n >> m;

    UnionFind uf(n);

    int ans = n;

    rep(i, m) {
        int x, y, z;
        cin >> x >> y >> z;
        --x; --y;

        if (!uf.has_same_root(x, y)) {
            --ans;
            uf.unite(x, y);
        }
    }

    cout << ans;

    return 0;
}


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

bool isPrime(int n){
 bool sosuu = true;
for(int i=2;i*i<=n;i++){
if (n % i == 0){
 sosuu=false;
  break;
}
}
  return sosuu;
}
int main(){
  int x;
  cin >> x;
  while (isPrime(x)==false){
    x+=1;
  }
  cout << x << endl;
}


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

int main() {
    using worker = tuple<int, int, string>;
    int N;
    cin >> N;
    set<worker> working;
    set<worker, greater<worker>> idle;
    map<string, worker> info;
    for(int i = 0; i < N; ++i) {
        string s;
        int a;
        cin >> s >> a;
        idle.insert(make_tuple(a, i, s));
        info[s] = make_tuple(a, i, s);
    }
    while(working.size() < N / 5) {
        working.insert(*idle.begin());
        idle.erase(idle.begin());
    }
    int now = N;

    int M;
    cin >> M;
    for(int i = 0; i < M; ++i, ++now) {
        char f;
        cin >> f;
        if(f == '+') {
            N++;
            string s;
            int a;
            cin >> s >> a;
            auto t = make_tuple(a, now, s);
            info[s] = t;

            bool need_swap = N / 5 == working.size() && working.size() != 0;
            if(need_swap && *working.begin() < t) {
                auto t2 = *working.begin();
                cout << s << " is working hard now." << endl;
                cout << get<2>(t2) << " is not working now." << endl;
                idle.insert(t2);
                working.erase(t2);
                working.insert(t);
            } else if(working.size() < N / 5) {
                if(*idle.begin() < t) {
                    cout << s << " is working hard now." << endl;
                    working.insert(t);
                } else {
                    auto t2 = *idle.begin();
                    idle.erase(idle.begin());
                    idle.insert(t);
                    working.insert(t2);
                    cout << s << " is not working now." << endl;
                    cout << get<2>(t2) << " is working hard now." << endl;
                }
            } else {
                idle.insert(t);
                cout << s << " is not working now." << endl;
            }
        } else {
            N--;
            string s;
            cin >> s;
            auto t = info[s];
            info.erase(s);

            if(working.count(t) == 1) {
                working.erase(t);
            } else {
                idle.erase(t);
            }

            if(working.size() > N / 5) {
                auto t2 = *working.begin();
                cout << get<2>(t2) << " is not working now." << endl;
                working.erase(working.begin());
                idle.insert(t2);
            } else if(working.size() < N / 5) {
                auto t2 = *idle.begin();
                cout << get<2>(t2) << " is working hard now." << endl;
                idle.erase(idle.begin());
                working.insert(t2);
            }
        }
    }
}


Measured memory_bytes: 11940
# -*- coding: utf-8 -*-
import sys
import math
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import itertools
import random
from collections import deque
from decimal import *
import queue
from functools import reduce

input = sys.stdin.readline

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
def inputStr(): return input()[:-1]

inf = float('inf')
mod = 1000000007

#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-

def main():
	S = inputStr()
	ans = 0

	if "RRR" in S:
		print(3)
	elif "RR" in S:
		print(2)
	elif "R" in S:
		print(1)
	else:
		print(0)


#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
#-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
if __name__ == "__main__":
	main()


Measured memory_bytes: 76864
#include <bits/stdc++.h>
#define op_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define fo(i,a,b) for(int i=a; i <b; i++)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef map<int,int> mpii;
typedef map<ll,ll> mpll;
typedef map<int,ll> mpil;
typedef map<ll,int> mpli;

const int maxn = 2e5+10;
pii k_cnt[maxn];

void dfs(int u, int currkcnt, vi &A){
  if(k_cnt[u].first == -1){
    k_cnt[u].first = currkcnt;
    dfs(A[u], currkcnt + 1, A);
  }else{
    k_cnt[u].second = currkcnt;
    return;
  }
}

int solve(vi &A, int n ,ll k){
  fo(i,1,n+1){
    k_cnt[i].first = -1;
    k_cnt[i].second = -1;
  }
  dfs(1, 0, A);
  
  int currindex = 1;
  while(true){
    if(k == 0LL){
      break;
    }
    if(k_cnt[currindex].second != -1){
      ll diff = (ll)(k_cnt[currindex].second - k_cnt[currindex].first);
      if(diff == 0){
	k = 0;
      }else{
	ll div = k/diff;
        k -= (div*diff);
      }
    }
    if(k != 0LL){
      k--;
      currindex = A[currindex];
    }
  }
  return currindex;
}

int main(){
  op_io;
  int n;
  ll k;
  cin>>n>>k;
  vi A(n+1);
  fo(i,1,n+1){
    cin>>A[i];
  }
  cout<<solve(A, n, k)<<endl;
  return 0;
}


Measured memory_bytes: 5576
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] P = new int[N+1]; // P[i]:整数ｉがある場所（ｉにある整数、ではない）
        for (int i = 1; i <= N; i++){
            int p = sc.nextInt();
            P[p] = i;
        }
        DJSet2 ds = new DJSet2(N+1);
        for (int i = 0; i < M; i++) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            ds.union(x, y);
        }
        int ans = 0;
        for (int i = 1; i <= N; i++) {
            if(ds.same(i, P[i]) || i == P[i]) ans++;
        }

        System.out.println(ans);
        sc.close();

    }

}

class DJSet2 {
    /**
     * 各要素の親を保持する配列。
     * 自信が根である要素は負の数を持つ。
     * （負の数の場合、絶対値がその集合の要素数）
     */
    public int[] upper;

    /**
     * コンストラクタ。
     * @param n 対象となる要素数
     */
    public DJSet2(int n) {
        upper = new int[n];
        Arrays.fill(upper, -1);
    }

    /**
     * 要素xが含まれる集合のrootを求める。
     * rootを求める過程で経路圧縮しrootが親になるようにする。
     * @param x 要素x
     * @return 要素xが含まれる集合のroot
     */
    public int root(int x) {
        return upper[x] < 0 ? x : (upper[x] = root(upper[x]));
    }

    /**
     * 要素xと要素yが同じ集合か判定する。
     * @param x 要素x
     * @param y 要素y
     * @return 要素xと要素yが同じ集合であればtrue、そうでなければfalseを返す。
     */
    public boolean same(int x, int y) {
        return root(x) == root(y);
    }

    /**
     * 要素xと要素yを含むそれぞれの集合を合併する。
     * 要素数の多い集合のrootを残し、少ないほうのrootをその下に合併する。
     * @param x 要素x
     * @param y 要素y
     * @return 要素xと要素yを含むそれぞれの集合を合併できたらtrue、もともと同じ集合で合併しなかったらfalseを返す。
     */
    public boolean union(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            if (upper[y] < upper[x]) {
                int t = x;
                x = y;
                y = t;
            }
            upper[x] += upper[y];
            upper[y] = x;
        }
        return x != y;
    }

    /**
     * 集合の数を数える。
     * @return 集合の数
     */
    public int countSet() {
        int c = 0;
        for (int u : upper) {
            if (u < 0)
                c++;
        }
        return c;
    }

    /**
     * 要素ｘが含まれる集合の要素数を数える。
     * @param x 要素ｘ
     * @return 要素ｘが含まれる集合の要素数
     */
    public int countElement(int x) {
        return root(x) * -1;
    }
}

Measured memory_bytes: 88444
#include <iostream>

//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s)
{
    int v;
    istringstream sin(s);
    sin >> v;
    return v;
}
template <class T>
inline string toString(T x)
{
    ostringstream sout;
    sout << x;
    return sout.str();
}

//math
//-------------------------------------------
template <class T>
inline T sqr(T x) { return x * x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0, sizeof(a))

//debug
// #define dump(x) cerr << #x << " = " << (x) << endl;
// #define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
//                       << " " << __FILE__ << endl;

int main()
{

    long n;
    cin >> n;

    vector<long> R = vector<long>();

    REP(i, n)
    {
        int r;
        cin >> r;
        R.push_back(r);
    }

    long max_v = -20000000000;
    long min_v = -1;

    REP(i, n)
    {
        //i以上のindexで最大の数字を見つけ、自分との差をとる
        if (i == 0)
        {
            min_v = R[i];
        }
        else
        {
            max_v = max(max_v, R[i] - min_v);
            min_v = min(R[i], min_v);
        }
    }

    cout << max_v << '\n';

    return 0;
}


Measured memory_bytes: 4872
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 10000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


signed main() {
	int a;
	string s;
	cin >> a >> s;
	if (a >= 3200) {
		cout << s << endl;
	}
	else {
		cout << "red" << endl;
	}

	return 0;
}


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

using namespace std;

int main(void)
{
	string str;
	int n, s;
	cin >> n >> s;
	cin >> str;
	int offset = 'a' - 'A';
	str[s - 1] = str[s - 1] + offset;
	cout << str;

	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Queue;

public class Main {

	public static void main(String[] args) {
		new Main().run();
	}

	FastScanner sc;

	void run() {
		sc = new FastScanner();
		String A = sc.next();
		String B = sc.next();
		String C = sc.next();
		
		String[] ws = {A,B,C};
		boolean flg = false;
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if (i == j) {
					continue;
				}
				for (int j2 = 0; j2 < 3; j2++) {
					if (i == j2 || j == j2) {
						continue;
					}
					String ans = ws[i] + ws[j] + ws[j2];
					if ("575".equals(ans)) {
						flg = true;
						break;
					}
					if (flg) {
						break;
					}
				}
				if (flg) {
					break;
				}
			}
		}
		
		if (flg) {
			System.out.println("YES");
			
		}else{
			System.out.println("NO");
		}
	}
}

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: 7892
#include<iostream>
#include<string>
#include<cstring>
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<queue>
#include<list>
#include<stdio.h>
#include<stdlib.h>
#include<map>
#include<cstdio>
#include <iomanip>

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)

int N, A, B;
vector<int>h;

//k回で殲滅できるか。
//まず全体にB*kのダメージ。
//残ったモンスターに(A-B)の単体攻撃をk回すると考える。

bool check(ll k) {

	ll cnt = 0;
	for (int i = 0; i < N; i++) {
		ll ret = h[i] - (ll)B*k;

		if (ret > 0) {
			cnt += (ret + (A - B) - 1) / (A - B);
		}

	}

	if (k >= cnt)return true;
	else return false;
}

ll bs() {

	ll ng = -1;
	ll ok = 1e9 + 1;

	while (abs(ok - ng) > 1) {
		ll mid = (ok + ng) / 2;

		if (check(mid)) {
			ok = mid;
		}
		else {
			ng = mid;
		}
	}

	return ok;
}

int main() {
	cin >> N >> A >> B;

	h.resize(N);

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



	cout << bs() << endl;

	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

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

        int n = sc.nextInt();

        int tou1[][] = new int[n][10];
        int tou2[][] = new int[n][10];
        int tou3[][] = new int[n][10];
        int tou4[][] = new int[n][10];

        for (int i = 0; i < n; i++) {
            int b = sc.nextInt();
            int f = sc.nextInt() - 1;
            int r = sc.nextInt() - 1;
            int v = sc.nextInt();

            for (int j = 0; j < 10; j++) {
                tou1[i][j] = 0;
                tou2[i][j] = 0;
                tou3[i][j] = 0;
                tou4[i][j] = 0;

            }

            switch (b) {
                case 1:
                    tou1[f][r] = tou1[f][r] + v;
                    break;
                case 2:
                    tou2[f][r] = tou2[f][r] + v;
                    break;
                case 3:
                    tou3[f][r] = tou3[f][r] + v;
                    break;
                case 4:
                    tou4[f][r] = tou4[f][r] + v;
                    break;
            }

        }

        for (int k = 0; k <= 2; k++) {
            for (int l = 0; l <= 9; l++) {
                System.out.print(" " + tou1[k][l]);
            }
            System.out.println();
        }

        System.out.println("####################");

        for (int k = 0; k <= 2; k++) {
            for (int l = 0; l <= 9; l++) {
                System.out.print(" " + tou2[k][l]);
            }
            System.out.println();
        }

        System.out.println("####################");

        for (int k = 0; k <= 2; k++) {
            for (int l = 0; l <= 9; l++) {
                System.out.print(" " + tou3[k][l]);
            }
            System.out.println();
        }

        System.out.println("####################");

        for (int k = 0; k <= 2; k++) {
            for (int l = 0; l <= 9; l++) {
                System.out.print(" " + tou4[k][l]);
            }
            System.out.println();
        }

    }

}

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

using namespace std;

int main()
{
  int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  if(a==0)
  {
    cout<<1<<endl;
  }
  if(b==0)
  {
    cout<<2<<endl;
  }
  if(c==0)
  {
    cout<<3<<endl;
  }
  if(d==0)
  {
    cout<<4<<endl;
  }
  if(e==0)
  {
    cout<<5<<endl;
  }
  return 0;
}

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

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

void solve() {
  int h, n, a, p = 0;
  cin >> h >> n;
  REP(i, n) {
    cin >> a;
    p += a;
  }
  if (h <= p) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

signed main() {
  solve();

  return 0;
}

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

using namespace std;

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

	int d = a / b;
	int r = a%b;
    double f = (double)a /(double) b;
	

	printf("%d %d %lf",d,r,f);

	return 0;
}

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

//C++14 (GCC 5.4.1)

#define LLINF (1LL<<60)
typedef long long ll;
#define mod 1000000007

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define rrepd(i,a,b) for(int i=(a);i>=(b);i--)

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

template<typename T> inline T divrup(T a, T b) { if (a % b) return a/b+1; else return a/b;}

#define dbg_v1(i,V) do{cout<<"-v1----\n";rep(i,V.size())cout<<" "<<i<<"\t:"<<V[i]<<endl;cout<<endl;}while(0)
#define dbg_v2(i,k,V) do{cout<<"-v2----\n";rep(i,V.size()){rep(k,V[0].size())cout<<" "<<V[i][k];cout<<endl;}}while(0)

int main() {
    ios::sync_with_stdio(false);//stdoutとcoutの同期解除
    cin.tie(nullptr);//cinとcoutの同期解除
    
    int N,M,x;
    cin >>N>>M;

    priority_queue<pair<ll,ll>> A;
    rep(i,N){
        cin >> x;
        A.push(make_pair(x,1));
    }
    int b,c,d;
    rep(i,M){
        cin>>b>>c;
        A.push(make_pair(c,b));
    }
    ll ans=0;
    pair<ll,ll> nw;
    int K=N,gt;
    while(K>0){
        nw=A.top();
        gt=nw.second;
        if(K<gt){
            ans+=nw.first*K;
            K=0;
        }else{
            ans+=nw.first*nw.second;
            A.pop();
            K-=gt;
        }
        //cout<<"e;"<<ans<<endl;
    }
    cout << ans <<endl;
    return (0);
}

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

using namespace std;

#define int long long

const int inf = 1LL<<55;

using vint = vector<int>;
using Pi = pair<int, int>;
using Graph1 = vector<vint>;
using Graph2 = vector<set<int>>;

struct UnionFind {
  vint data;
  UnionFind(int N):data(N, -1){}
  int find(int x) {
    return data[x] < 0 ? x : data[x] = find(data[x]);
  }
  int size(int x) {
    return -data[find(x)];
  }
  bool same(int x, int y) {
    return find(x) == find(y);
  }
  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if(x == y) return false;
    if(data[x] < data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return true;
  }
};

#define MAX_N 100000

int N, M;
vint c;
Graph1 graph;
Graph2 dag;

int dp[MAX_N];

map<int, int> convmap(vint c) {
  map<int, int> res;
  int n = c.size();
  vector<Pi> vec;
  for(int i = 0; i < n; i++) vec.emplace_back(c[i], i);
  sort(vec.begin(), vec.end());
  for(int i = 0; i < n; i++) res[vec[i].second] = i;
  return res;
}

signed main() {
  cin >> N;
  graph.resize(N);
  c.resize(N);
  for(int i = 0; i < N; i++) cin >> c[i];
  auto mp = convmap(c);
  sort(c.begin(), c.end());
  cin >> M;
  for(int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b; --a, --b;
    a = mp[a], b = mp[b];
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  UnionFind uf(N);
  for(int i = 0; i < N; i++) {
    graph[i].push_back(i);
    sort(graph[i].begin(), graph[i].end());
    for(int j = 1; j < (int)graph[i].size(); j++) {
      int u = graph[i][j-1];
      int v = graph[i][j];
      if(c[u] == c[v]) uf.unite(u, v);
    }
  }
  dag.resize(N);
  for(int i = 0; i < N; i++) {
    for(int j = 1; j < (int)graph[i].size(); j++) {
      int u = graph[i][j-1];
      int v = graph[i][j];
      if(!uf.same(u, v)) dag[uf.find(u)].insert(v);
    }
  }
  vint in(N), ord;
  for(int u = 0; u < N; u++) {
    for(int v : dag[u]) in[uf.find(v)]++;
  }
  queue<int> que;
  for(int u = 0; u < N; u++) {
    if(u == uf.find(u) && in[u] == 0) que.push(u);
  }
  while(!que.empty()) {
    int u = que.front(); que.pop();
    ord.push_back(uf.find(u));
    for(int v : dag[uf.find(u)]) {
      in[uf.find(v)]--;
      if(in[uf.find(v)] == 0) que.push(uf.find(v));
    }
  }
  for(int i = 0; i < N; i++) dp[i] = 1;
  for(int u : ord) {
    for(int v : dag[uf.find(u)]) dp[uf.find(v)] = max(dp[uf.find(v)], dp[uf.find(u)]+1);
  }
  int ans = 0;
  for(int i = 0; i < N; i++) {
    if(i != uf.find(i)) continue;
    ans += dp[i]*uf.size(i);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 43808
def main():
    n = int(input())
    maxv = -(10 ** 9)
    minv = int(input())
    for _ in range(n-1):
        i = int(input())
        maxv = max(maxv, i - minv)
        minv = min(minv, i)
    print(maxv)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 5616
/*

    author : s@if

*/

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define 		NIL 			-1
#define		 	fi	 		    first
#define 		sec 			second
#define 		MAX 			INT_MAX
#define			INF 			1e9
#define 		ll 			    long long
#define 		PI 			    acos(-1.0)
#define			MOD 			1000000007
#define 		PLL 			pair<ll,ll>
#define 		PII			    pair<int,int>
#define 		ull 			unsigned long long
#define 		For(i,a,b) 		for(int i=a;i<=(int)b;i++)
typedef tree<int, null_type, less<int>, rb_tree_tag,
            tree_order_statistics_node_update> new_data_set;

//*find_by_order(k)  gives the kth element;
//order_of_key(item)   gives the index(number of element strictly less than item) of item;


inline int in() {int x; scanf("%d", &x); return x; }
bool Check(int N , int pos)	{	return (bool) (N & (1<<pos));}
int Set(int N, int pos) {	return N = N | (1<<pos);}

int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};    // King's move
int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};
int hx[]={-2,-2,-1,+1,+2,+2,-1,+1};    // Knight's move
int hy[]={+1,-1,+2,+2,-1,+1,-2,-2};
int dx[]={+1,-1,+0,+0};
int dy[]={+0,+0,+1,-1};

const int MAXN = (int)3e5+9;

ll fact[MAXN];

ll power(ll a, ll b)
{
    ll ret = 1;

    while(b)
    {
        if(b&1) ret = (ret*a)%MOD;

        a = (a*a)%MOD;

        b>>=1;
    }

    return ret;
}

int main()
{
/*	freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);  */

    ll i,j,k,l,m,n,p,q,x,y,u,v,r,tc,t;

    fact[0] = 1;
    for(i=1; i<MAXN; i++) fact[i] = (fact[i-1]*i)%MOD;
    ll a, b;
    cin>>n>>a>>b;

    ll ans = power(2,n); ans = (ans-1+MOD)%MOD;

    p = max(a, n-a); q = min(a, n-a);
    ll tmp = 1; for(i=n; i>p; i--) tmp = (tmp*i)%MOD;
    tmp = (tmp*power(fact[q],MOD-2))%MOD;

    ans = (ans-tmp+MOD)%MOD;

    p = max(b, n-b); q = min(b, n-b);
    tmp = 1; for(i=n; i>p; i--) tmp = (tmp*i)%MOD;
    tmp = (tmp*power(fact[q],MOD-2))%MOD;

    ans = (ans-tmp+MOD)%MOD;

    cout<<ans<<endl;

   // main();

    return 0;
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?)


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

mint f(int n) {
    if (n == 0) return 1;
    mint x = f(n/2);
    x *= x;
    if (n%2 == 1) x *= 2;
    return x;
}

mint choose(int n, int a) {
    mint x = 1, y = 1;
    rep(i,a) {
        x *= n-i;
        y *= i+1;
    }
    return x / y;
}

int main() {
	ll n, a, b;
	cin >> n >> a >> b;
    mint ans = f(n) - 1;
    ans -= choose(n,a);
    ans -= choose(n,b);
	cout << ans.x << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#define eps 1e-9
#define double long long
using namespace std;
struct point{
	double x,y;
	void read(){scanf("%lld%lld",&x,&y);}
	void write(){printf("%.9f %.9f\n",x,y);}
	point(double X=0.0,double Y=0.0):x(X),y(Y){}
	point operator +(const point a)const{return point(x+a.x,y+a.y);}
	point operator -(const point a)const{return point(x-a.x,y-a.y);}
	point operator *(double a)const{return point(x*a,y*a);}
	point operator /(double a)const{return point(x/a,y/a);} 
};
double dis(point a){return a.x*a.x+a.y*a.y;}
double dot(point a,point b){return a.x*b.x+a.y*b.y;}
double cross(point a,point b){return a.x*b.y-a.y*b.x;}
double cross3(point o,point a,point b){return cross(a-o,b-o);}
bool jiao(point a,point b,point c,point d)
{
	if(min(a.x,b.x)>max(c.x,d.x) || min(a.y,b.y)>max(c.y,d.y)) return false;
	if(min(c.x,d.x)>max(a.x,b.x) || min(c.y,d.y)>max(a.y,b.y)) return false;
	if(cross3(a,b,c)*cross3(a,b,d)>0) return false;
	if(cross3(c,d,a)*cross3(c,d,b)>0) return false;
	return true;
}
point p1,p2,p3,p4;
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		p1.read();p2.read();p3.read();p4.read();
		printf("%d\n",jiao(p1,p2,p3,p4));
	}
	return 0;
}



Measured memory_bytes: 3216
#include <functional>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n;
    cin >> n;

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

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

    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans = max(ans, sum_a[i + 1] + (sum_b[n] - sum_b[i]));
    }

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

Measured memory_bytes: 256
/**
 *    author:  ykaka
 *    created: 01.08.2020 20:54:48       
**/
 
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i<(n);++i)
using namespace std;
using ll = long long;
 
int main(){
  int n;
  cin >> n;
  int total = 0;
  while(n--){
    int x, y;
    cin >> x >> y;
    if(x == y){
      total += 1;
    }else{
      if(total == 3){
        total = total;
        break;
      }else{
        total = 0;
      }   
    }  
  }
  if(total >= 3){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}



Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>

#define X first
#define Y second
#define vsort(v) sort((v).begin(), (v).end())
#define vrev(v) reverse((v).begin(), (v).end())

// stoi(s): string to int
// stod(s): string to double

// INT_MAX
// INT_MIN
// LLONG_MAX
// LLONG_MIN
// DBL_MIN
// DBL_MAX
// LDBL_MIN
// LDBL_MAX

// A-Z: 65~90
// a-z: 97~122
// |a-z| = 26

using namespace std;
using ll = long long;

int main(int argc, const char * argv[]) {
    int n, a, b;
    cin >> n >> a >> b;
    
    vector<int> v(3);
    int x;
    for (int i = 0; i < n; i++) {
        cin >> x;
        if (x <= a) {
            v[0]++;
        }else if (x >= a + 1 && x <= b){
            v[1]++;
        }else{
            v[2]++;
        }
    }
    
    vsort(v);
    cout << v[0] << endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"math/rand"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int
var t float64

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	d := intScanner()
	c := intSliceScanner(26)
	s := make([][]int, d)
	for i := 0; i < d; i++ {
		s[i] = intSliceScanner(26)
	}
	best := -mod
	bestSchedule := make([]int, d)
	for x := 0; x < 1; x++ {
		schedule := make([]int, d)
		for i := 0; i < d; i++ {
			schedule[i] = rand.Intn(26)
		}
		score := calcScore(schedule, c, s, d)
		for y := 0; y < 150000; y++ {
			change := rand.Intn(d)
			val := rand.Intn(26)
			pre := schedule[change]
			schedule[change] = val
			nextScore := calcScore(schedule, c, s, d)
			t = float64(score) * 0.5
			if prob(score, nextScore) >= math.Abs(rand.Float64()) {
				score = nextScore
			} else {
				schedule[change] = pre
			}
			if nextScore >= best {
				best = nextScore
				copy(bestSchedule, schedule)
			}
			t *= 0.999
		}
	}
	for i := 0; i < d; i++ {
		fmt.Println(bestSchedule[i] + 1)
	}
}
func calcScore(schedule []int, c []int, s [][]int, d int) int {
	score := 0
	last := make([]int, 26)
	for i, v := range schedule {
		score += s[i][v]
		for j, _ := range last {
			last[j]++
		}
		last[v] = 0
		for j, v := range last {
			score -= c[j] * v
		}
	}
	return score
}
func prob(before int, after int) float64 {
	if before <= after {
		return 1.0
	}
	return math.Exp((float64(after) - float64(before)) / float64(t))
}


Measured memory_bytes: 2040
N, C = gets.chomp.split(" ").map(&:to_i)
S = Array.new(N)
S.map!{gets.chomp.split(" ").map(&:to_i)}

wx, wc = [0, 0]
l = S.map{|x, c|
  wc += (c - x + wx)
  wx = x
  wc
}
wx, wc = [C, 0]
r = S.reverse.map{|x, c|
  wc += (c + x - wx)
  wx = x
  wc
}
ans = [0, l.max, r.max].max
lm = l[0]
(1...N).each{|i|
  lm = l[i-1] if lm < l[i-1]
  wk = lm - C + S[i][0] + r[N-i-1]
  ans = wk if ans < wk
}
rm = r[0]
(1...N).each{|i|
  rm = r[i-1] if rm < r[i-1]
  wk = rm - S[N-1-i][0] + l[N-1-i]
  ans = wk if ans < wk
}

puts ans


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

int main(){
	string s;cin >> s;
	int k;cin >> k;
	int n=(int)s.size();
	vector<string> a;
	for(int i=0;i<min(n,k);++i){
		int x=0,y=1+i;
		while(y<=n){
			string t="";
			for(int j=x;j<y;++j){
				t+=s.at(j);
			}
			a.push_back(t);
			x++;
			y++;
		}
	}
	sort(a.begin(),a.end());
	decltype(a)::iterator c=unique(a.begin(),a.end());
	cout << a.at(k-1) << endl;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,a,n) for(int i=(a); i<(n); i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
// Euclidean Algorithm
int gcd(int a, int b){if (a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a * b / gcd(a, b);}
int ctoi(char c) {if (c >= '0' && c <= '9') {return c - '0';}return 0;}


int main(){
  int N; cin>>N;
  vi a(N);
  int count4 = 0;
  int count2 = 0;
  rep(i,N){
    cin >> a[i];
    if(a[i]%4 == 0) count4++;
    else if(a[i]%2 == 0) count2++;
  }
  int b1 = N-count4 -count2;
  if(count2 <= 1 && count2+b1 <= count4 + 1) cout << "Yes" << endl;
  else if(count2 > 1 && b1 <=count4  ) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3764