akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}
constexpr int INF = 1100000000;
constexpr long long LLINF = 1100000000000000000LL;
constexpr long long MOD = 1000000007;

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


int main()
{
  int N;
  cin >> N;
  vector<pair<string, pair<int, int>>> v;
  REP(i, N) {
    string s;
    int P;
    cin >> s >> P;
    v.PB(MP(s, MP(-P, i + 1)));
  }
  sort(ALL(v));
  REP(i, N) {
    cout << v[i].SE.SE << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define R register int
#define AC 400
#define LL long long

int n;
LL ans;
LL f[AC][AC], g[AC][AC];
bool z = true;

inline int read()
{
	int x = 0;char c = getchar();
	while(c > '9' || c < '0') c = getchar();
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x;
}

void pre()
{
	n = read();
	for(R i = 1; i <= n; i ++) 
		for(R j = 1; j <= n; j ++) 
			f[i][j] = g[i][j] = read();
}

void work()
{
	for(R k = 1; k <= n; k ++)
		for(R i = 1; i <= n; i ++)
			for(R j = 1; j <= n; j ++)
			{
				if(i == k || j == k) continue;
				if(f[i][j] > f[i][k] + f[k][j]) z = false;//如果可以凑出更短的路，那这就不是最短路了。。。。
				else if(f[i][j] == f[i][k] + f[k][j]) g[i][j] = g[j][i] = 0;
			}
	for(R i = 1; i <= n; i ++)
		for(R j = 1; j <= n; j ++) ans += g[i][j];
	if(z) printf("%lld\n", ans / 2);//因为双向边会被统计2次
	else printf("-1\n");
}

int main()
{
	//freopen("in.in", "r", stdin);
	pre();
	work();
	//fclose(stdin);
	return 0;
}

Measured memory_bytes: 2176
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())
    SI = lambda : sys.stdin.readline().rstrip()

    n = NI()
    a = [0] * (n+1)
    b = [0] * (n+1)

    for i,p in enumerate(LI()):
        a[p-1] += i
        b[0] += i
        b[p] -= i

    ans_a = []
    ans_b = []
    cnt_a = 0
    cnt_b = 0
    for i in range(n):
        cnt_a += a[i]
        cnt_b += b[i]
        ans_a.append(cnt_a+i+1)
        ans_b.append(cnt_b+(n-i))
    print(*ans_a,sep=' ')
    print(*ans_b,sep=' ')






if __name__ == '__main__':
    main()

Measured memory_bytes: 46636
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;
vector<int> i2g;          // i2g[i] := アイテム i の所属するグループの番号(find)
vector<vector<int>> g2i;  // g2i[g] := グループ g に所属するアイテムたち

void union_init(int n) {
  i2g.resize(n);
  g2i.resize(n);
  for (int i = 0; i < n; ++i) {
    // 最初はアイテム i はグループ i に所属
    i2g[i] = i;
    g2i[i].assign(1, i);
  }
}

int find(int i){
  return i2g[i];
}

// アイテム ia の所属するグループとアイテム ib の所属するグループを 1 つにする
void merge(int ia, int ib) {
  if(i2g[ia]==i2g[ib])return;
  // ia の所属するグループが ib の所属するグループより小さくならないようにする
  if (g2i[i2g[ia]].size() < g2i[i2g[ib]].size()) {
    swap(ia, ib);
  }
  int ga = i2g[ia], gb = i2g[ib];
  // グループ gb に所属する全てのアイテムをグループ ga に移す
  for (int j : g2i[gb]) i2g[j] = ga;
  g2i[ga].insert(g2i[ga].end(), g2i[gb].begin(), g2i[gb].end());
  g2i[gb].clear();
}

// アイテム ia とアイテム ib は同じグループに所属しているか？
bool is_same_group(int ia, int ib) {
  return i2g[ia] == i2g[ib];
}
typedef pair<int,pair<int,int>> pr;

int main(){
	int n,a[311][311]={},na[311][311]={};
	priority_queue<pr> pq;
	cin>>n;
	union_init(n);
	FOR(i,0,n){
		FOR(j,0,n){
			int b;
			cin>>b;
			a[i][j]=b;
			a[j][i]=b;
			na[i][j]=b;
			na[j][i]=b;
			if(i<j)pq.push(make_pair(b,make_pair(i,j)));
		}
	}
  for (int i = 0; i < n; i++)      // 経由する頂点
    for (int j = 0; j < n; j++)    // 開始頂点
      for (int k = 0; k < n; k++)  // 終端
        na[j][k] = min(na[j][k], na[j][i] + na[i][k]);
	LL ans=0;
	FOR(i,0,n){
		FOR(j,i+1,n){
			if(a[i][j]>na[i][j]){
				cout<<-1<<endl;
				return 0;
			}else if(a[i][j]==na[i][j]){
				int f=1;
				FOR(k,0,n){
					if(i==k||j==k)continue;
					if(a[i][k]+a[k][j]==a[i][j])f=0;
				}
				ans+=f*a[i][j];
			}else{
				cout<<-1<<endl;
			}
		}
	}
	cout<<ans<<endl;

    return 0;
}


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

int main() {
    string str;
    cin >> str;
    if(str <= "2019/04/30") cout << "Heisei" << endl;
    else cout << "TBD" << endl;
}

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

using namespace std;
typedef long long ll;

int n;
map<int, int> vals;
ll sol;

int main()
{

    cin.tie(0);
    ios_base::sync_with_stdio(0);

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

        if(vals.find(i - x) == vals.end()) vals.insert({i - x, 0});
        sol += 1LL * vals[i - x];

        if(vals.find(i + x) == vals.end()) vals.insert({i + x, 0});
        ++vals[i + x];
    }

    cout << sol;

    return 0;
}


Measured memory_bytes: 20712
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    ll a,b,k;
    cin >> a >> b >> k;

    if (k >= a) {
        k -= a;
        a = 0;
    } else {
        a -= k;
        k = 0;
    }

    b = max(b-k,0LL);

    cout << a << " " << b << endl;

    return 0;
}

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


int main() {

    char x, y;
    cin >> x >> y;
    char ans;
    if (x < y) ans = '<';
    else if (x == y ) ans = '=';
    else ans = '>';
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// Problem Code: abc176_c

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

long long step(int N, vector<int>& A) {
	int max_h = 0;
	long long cnt = 0;
	for (int& h: A) {
		max_h = max(h, max_h);
		cnt += max_h - h;
	}
	return cnt;
}

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++)
		cin >> A[i];
	cout << step(N, A);
	return 0;
}

Measured memory_bytes: 4036
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int N = sc.nextInt();
	    String line = sc.next();
	    String[] s = line.split("");
	    int sum = 1;
	    for(int i = 1; i < N; i++) {
	        if(s[i].equals(s[i-1])) {
	            continue;
	        }else {
	            sum++;
	        }
	    }
	    System.out.println(sum);
	}
}

Measured memory_bytes: 33920
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

public static class P
{
    public static void Main()
    {
        int[] reses = new int[114514];
        for (int i = 1; i <= 100; i++)
        {
            for (int j = 1; j <= 100; j++)
            {
                for (int k = 1; k <= 100; k++)
                {
                    reses[i * i + j * j + k * k + i * j + j * k + k * i]++;
                }
            }
        }
        int n = int.Parse(Console.ReadLine());
        for (int i = 1; i <= n; i++)
            Console.WriteLine(reses[i]);
    }
}


Measured memory_bytes: 27848
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define INF (ll)1e18+4
#define md (ll)1e9+7
#define mx 10000000
#define mk make_pair
#define __builtin_popcountll(x) one(x)
#define pi pair<int,int>
#define ss second
#define ff first
#define pb emplace_back 
#define all(s) s.begin(),s.end()
#define rall(x) (x).rbegin(), (x).rend()
#define trav(x, a) for (auto& x: a)
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>b;i--)
#define rf(i,a,b) for(int i=a;i>=b;i--)
#define sz(x) ((long long)x.size())
#define mez(s) memset(s,0,sizeof s)
#define mex(s) memset(s,-1,sizeof s)
#define metr(s) memset(s,true, sizeof s)
typedef vector<int> vi; 
typedef vector<ll>vl;
typedef map<int,int> mp;
typedef queue<int> que;
typedef vector<pi> vp;


void solve(){
	ll n,x,y,z,m,k;
	cin>>n>>z;
	ll d=0;
	while(n--){
	cin>>x>>y;
	if(sqrt(x*x+y*y)<=z)
	d++;
	}
	cout<<d;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t=1;
   //cin>>t;
  while(t--){
  	solve();
  }
  return 0;
}

Measured memory_bytes: 3656
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: String
    }

    let arr = vec!["SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"];
    let v = arr.iter().position(|&x| x == s).unwrap();
    println!("{}", 7 - v);
}


Measured memory_bytes: 4352
N = int(input()) 
# 約数取って全探索で良い？
def f(a,b):
    x = max(a,b)
    cnt = 1
    while x//10 > 0:
        x //= 10
        cnt += 1
    return cnt

# 約数
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

divs = make_divisors(N)
ans = 10**10
for div in divs:
    if div > N/div:
        continue
    else:
        ans = min(ans, f(div,N//div))
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <fstream>

using namespace std;

int dfs (const int depth, const int sum, int currs, int currd, int j)
{
	int count = 0;
	int i;

	if (currd == depth ){
		if (sum == currs ){
			return 1;
		}else{
			return 0;
		} // end if
	} // end if
	
	for (i = j; i <= min(9, sum ); ++i){
		currs += i;
		count += dfs (depth, sum, currs, currd + 1, i + 1 );
		currs -= i;
	} // end for

	return count;
}

int main()
{
//	cut here before submit 
//	freopen("testcase.si", "r", stdin);
	string str = "";

	while (getline (cin, str ) ){
		int n, sum;
		int res = 0;
		stringstream ss(str);
		ss >> n >> sum;

		if (n == 0 && sum == 0){
			break;
		} // end if
		
		res = dfs (n, sum, 0, 0, 0 );

		cout << res << endl;
	} // end while
	
	return 0;
}

Measured memory_bytes: 0
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
#include <functional>
#include <random>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vvvl> vvvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
typedef vector<vvpl> vvvpl;
const int INF = 1001001001;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    sort(ALL(vec));
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
//friend bool operator<(const stc& lhs, const stc& rhs){
//    return std::tie(lhs.l, lhs.r) < std::tie(rhs.l, rhs.r);
//}



int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N, M; cin >> N >> M;
    vvl dist(N, vl(N, LINF));
    rep(i, N) dist[i][i] = 0;
    vpl edg(M); vl C(M);
    rep(i, M){
        ll a, b, c; cin >> a >> b >> c; a--; b--;
        dist[a][b] = c;
        dist[b][a] = c;
        edg[i] = {a, b}; C[i] = c;
    }
    
    rep(k, N) rep(i, N) rep(j, N){
        chmin(dist[i][j], dist[i][k] + dist[k][j]);
    }
    
    ll ans = 0;
    rep(i, M){
        ll a = edg[i].ff, b = edg[i].ss;
        if(dist[a][b] < C[i]) ans++;
    }
    cout << ans << endstr;
    return 0;
}


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

int N, M;
int v[8][8];
int used[8];

bool check() {
	for (int i = 0; i < N; i++) {
		if (!used[i]) {
			return false;
		}
	}
	return true;
}

int dfs(int now) {
	used[now] = 1;

	if (check()) {
		used[now] = 0;
		return 1;
	}

	int res = 0;
	for (int i = 0; i < N; i++) {
		if (!used[i] && v[now][i]) {
			res += dfs(i);
		}
	}
	used[now] = 0;

	return res;
}

int main() {
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int x, y;
		cin >> x >> y;
		x--;
	   	y--;
		v[x][y] = v[y][x] = 1;
	}

	cout << dfs(0) << endl;

	return 0;
}


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

#define int long long
#define INT int
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}
typedef long long ll;
const long long INF = 1LL << 60;

signed main()
{
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n), b(m);
    rep(i, n)
    {
        cin >> a[i];
    }
    rep(i, m)
    {
        cin >> b[i];
    }

    vector<int> sum_a, sum_b;
    sum_a.pb(0);
    sum_b.pb(0);

    int A = 0;
    rep(i, n)
    {
        A += a[i];
        if (A > k)
        {
            break;
        }
        sum_a.pb(A);
    }
    int B = 0;
    rep(i, m)
    {
        B += b[i];
        if (B > k)
        {
            break;
        }
        sum_b.pb(B);
    }

    int ans = 0;

    rep(i, sum_a.size())
    {
        int temp = i;
        int K = k - sum_a[i];
        int temp2 = upper_bound(all(sum_b), K) - (sum_b.begin()) - 1;
        temp += temp2;
        ans = max(ans, temp);
    }

    cout << ans << endl;

    return 0;
}


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

typedef long long int ll;
ll n, w, dp[100007];

int main() {
    cin >> n >> w;
    for(ll i = 0; i < n; ++i) {
        ll weight, value;
        cin >> weight >> value;

        for(ll j = w - weight; j >= 0; --j) {
            dp[j + weight] = max(dp[j + weight], dp[j] + value); 
        }
    }

    cout << dp[w] << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_N 100010

int func(int ai, int ao, int aj, int al, int n) {
    int K = ao;
    // ai, aj, al のコンビぶんを加算
    REP(i, n) {
        if(ai > 0 && aj > 0 && al > 0) {
            K += 3;
            ai -= 1;
            aj -= 1;
            al -= 1;
        }
    }
    auto Add = [](int& k, int& a) {
        if(a % 2 == 0) {
            k += a;
            a = 0;
        } else {
            k += (a - 1);
            a = 1;
        }
    };
    Add(K, ai);
    Add(K, aj);
    Add(K, al);
    return K;
}

signed main()
{
    int ai, ao, at, aj, al, as, az;
    cin >> ai >> ao >> at >> aj >> al >> as >> az;

    int K = func(ai, ao, aj, al, 0);
    K = max(K, func(ai, ao, aj, al, 1));

    printf("%lld\n", K);
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
using namespace std;
const int MAXN=1e5+1;
int n,m,u,v;
int dist[MAXN];
int Queue[MAXN],head,tail;
bool flag[MAXN];
struct edge{
	int v,len;
	edge *nex;
	edge() {v=len=0;nex=NULL;}
}*con[MAXN];
inline void ins(int Start,int End,int key){
	edge *p=new(edge);
	p->v=End;p->len=key;
	p->nex=con[Start];con[Start]=p;
}
inline void spfa(){
	for(int i=2;i<=n;++i) dist[i]=-2147483647;
	dist[1]=0;flag[1]=true;
	Queue[head=tail=1]=1;
	while((head-1)!=(tail%(MAXN-1))){
		int nv=Queue[head];
		for(edge *p=con[nv];p;p=p->nex){
			int vv=p->v;
			if(dist[vv]<dist[nv]+p->len){
				dist[vv]=dist[nv]+p->len;
				if(flag[vv]==false){
					tail=(tail==MAXN-1)?1:tail+1;
					Queue[tail]=vv;flag[vv]=true;
				}
			}
		}
		head=(head==MAXN-1)?1:head+1;
		flag[nv]=false;
	}
}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<n;++i){
		ins(i+1,i,-1);ins(i,i+1,0);
	}
	while(m--){
		scanf("%d%d",&u,&v);
		ins(u,v,1);
	}
	spfa();
	printf("%d",dist[n]);
	return 0;
}

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

int main() {
    int N;
    string S, T;
    cin >> N >> S >> T;

    string U = "";
    for (int i = N; i >= 0; i--) {
        if (S.substr(N - i, i) == T.substr(0, i)) {
            U = S + T.substr(i);
            break;
        }
    }

    cout << U.size() << endl;
}

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

int main(void) {

	int r=0,D=0,x[10];
	int i=0;

	scanf("%d %d %d", &r, &D, &x[0]);

	for(i=0;i<10;i++){

		x[i+1] = r * x[i] - D;

	printf("%d\n",x[i+1]);
	}
	return 0;
}


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

#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll mod = 1e9+7;

ll gcdExtended(ll a, ll b, ll *x, ll *y); 

ll modInverse(ll a) 
{ 
    ll x, y; 
    ll g = gcdExtended(a,mod, &x, &y); 
    
    ll res = (x%mod + mod) % mod;
    return res;
} 
  
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
  
    ll x1, y1; 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
    *x = y1 - (b/a) * x1; 
    *y = x1; 
  
    return gcd; 
}

int main()
{
    ll p,n,k,i,d,sum=0;
    cin>>n>>k;

    ll A[n];
    for(i=0;i<n;i++)
        cin>>A[i];
    sort(A,A+n);
    ll B[n],C[n];
    for(i=0;i<n;i++)
        B[i]=C[i]=0;

    B[k-1]=1;
    for(i=k;i<n;i++)
    {
        B[i]=(i*B[i-1])%mod;
        p = modInverse(i+1-k);
        B[i]=(B[i]*p)%mod;
        B[i]=B[i]%mod;
    }

    for(i=n-1;i>=0;i--)
    {
        sum=(sum+((B[i]-B[n-i-1]+2*mod)*A[i])%mod+mod)%mod;
        sum=(sum+mod)%mod;
    }
    
    cout<<sum<<endl;
}


Measured memory_bytes: 2560
import sys
from collections import defaultdict, deque
import bisect
from heapq import *
from math import factorial, ceil, floor
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, M, = map(int, input().split())
# N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# L = [list(input().strip())  for _ in range(N)]
# S = input().strip()

N, = map(int, input().split())
A = [int(v) for v in input().split()]
B = [int(v) for v in input().split()]
m = []

ca = 0
cb = 0
for i in range(N):
    a, b = A[i], B[i]
    if a > b:
        ca += a - b
    elif a < b:
        cb += ceil((b - a) / 2)

t = sum(B) - sum(A)
if ca <= t and cb <= t:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 4852
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)

#define MAX_E 2000
#define MAX_V 1000

// ??????from????????????to???????????????cost??????
struct edge { int from, to, cost; };
edge es[MAX_E]; // ???
int d[MAX_V]; // ???????????¢
int V, E; // V???????????°???E????????°
// s???????????????????????????????????????????????¢????±???????
int shortest_path(int s) {
	for (int i = 0; i < V; i++) d[i] = INF; d[s] = 0;
	for(int loop=0;loop<V;loop++){
		bool update = false;
		for (int i = 0; i < E; i++) {
			edge e = es[i];
			if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
				d[e.to] = d[e.from] + e.cost;
				update = true; }
		}
		if (!update) break;
		if(loop==V-1) return true;	//negative_cycle
	}
	return false;
}

int main(){
	int r;
	cin>>V>>E>>r;
	
	rep(i,E){
		int u,v,d;
		cin>>u>>v>>d;
		es[i] = edge{u,v,d};
	}
	
	bool res = shortest_path(r);
	if(res==true)cout<<"NEGATIVE CYCLE"<<endl;
	else{
		rep(i,V){
			if(d[i]==INF)cout<<"INF"<<endl;
			else cout<<d[i]<<endl;
		}
	}
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
#define N 100020
#define ll long long
using namespace std;
inline ll read(){
  ll x=0,f=1;char ch=getchar();
  while(ch>'9'||ch<'0')ch=='-'&&(f=0)||(ch=getchar());
  while(ch<='9'&&ch>='0')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
  return f?x:-x;
}
ll resolve(ll a, ll b) {
  if (a < b) swap(a, b);
  if (a % b == 0) return 2 * a - b;
  return 2 * b * (a / b) + resolve(b, a % b);
}
int main(int argc, char const *argv[]) {
  ll n = read(), p = read();
  printf("%lld\n", resolve(p, n - p) + n);
  return 0;
}

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

int main() {
    int i, x, y;
    i = 1;
    while (1) {
        cin >> x >> y;
        if (x == 0 && y == 0) break;
        if (x <= y) {
            cout << x << " " << y << "\n";
        }
        if (x > y){
            cout << y << " " << x << "\n";
        }
        i++;
    }

    return 0;
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define out(a) cout<<fixed<<setprecision((a))

ll LIS(vector<ll> a){
	vector<ll> dp;
	const ll infi=1e9+7;
	ll n = a.size();
	dp.resize(n);
	fill(dp.begin(),dp.end(),infi);
	for(int i=0;i<n;i++){
		*upper_bound(dp.begin(),dp.end(),a[i])=a[i];
	}
	ll ans = lower_bound(dp.begin(),dp.end(),infi)-dp.begin();
	return ans;
}


int main(){
	ll N;
	cin >> N;
	vector<ll> A(N);
	FOR(i,0,N)cin>>A[i];
	FOR(i,0,N)A[i]*=-1;
	cout << LIS(A) << endl;
}


Measured memory_bytes: 2560
N = int(input())
minv = int(input())
k = int(input())
maxv = k - minv
minv = min(minv,k)

for i in range(N - 2):
  k = int(input())
  maxv = max(maxv,k - minv)
  minv = min(minv,k)
    
print(maxv)


Measured memory_bytes: 5612
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll a[200009];
ll f(ll x, ll y){
    return x + y - x % y;
}
main(){
    ll n;
    cin >> n;
    for(ll i = 0; i < n; i++){
        cin >> a[i];
    }
    ll l = 2,r = 2;
    for(ll i = n - 1; i >= 0; i--){
        l = f(l - 1, a[i]);
        r = f(r, a[i]) - 1;
        if(l > r){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << l <<" "<<r<<endl;


}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n;
    cin>>n;
    int a[n];
    rep(i,n) cin>>a[i];

    if(a[0]!=0){
        cout<<-1<<endl;
        return 0;
    }
    rep(i,n-1){
        if(a[i+1]-a[i]>1){
            cout<<-1<<endl;
            return 0;
        }
    }
    ll ans=0;
    rep(i,n-1){
        if(a[i]==a[i+1]) ans+=a[i];
        if(a[i]>a[i+1]) ans+=a[i+1];
        if(a[i]<a[i+1]) ans+=1;
    }

    cout<<ans<<endl;
}


 

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

using namespace std;

int main(){
	static int dpA[1000001], dpB[1000001];
	vector<int> v;
	for(int i=0;i<=1000000;i++) dpA[i] = dpB[i] = 10000;
	dpA[0] = dpB[0] = 0;
	for(int i=1;;i++){
		int s = i*(i+1)*(i+2)/6;
		if(s > 1000000) break;
		v.push_back(s);
	}
	for(int i=0;i<=1000000;i++){
		for(int j=0;j<v.size()&&i+v[j]<=1000000;j++){
			dpA[i+v[j]] = min(dpA[i+v[j]], dpA[i]+1);
			if(v[j]%2==1){
				dpB[i+v[j]] = min(dpB[i+v[j]], dpB[i]+1);
			}
		}
	}
	int t;
	while(cin >> t && t){
		cout << dpA[t] << " " << dpB[t] << endl;
	}
}

Measured memory_bytes: 9032
#include <iostream>
#include <list>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <utility>
using namespace std;

int main(){
	int n;
	vector<long long> x, y;
	cin >> n;
	x.resize(n);
	y.resize(n);
	for (int i = 0; i < n; i++){
		cin >> x[i] >> y[i];
	}

	map<string, int> count;

	for (int i = 0; i < n; i++){
		for (int j = 0; j < n; j++){
			if (i == j)continue;
			string s = to_string(x[i] - x[j]) + "," + to_string(y[i] - y[j]);
			count[s]++;
		}
	}

	int c = 0;
	for (pair<string,int> m : count){
		if (m.second > c)c = m.second;
	}
	if (c >= n)c = n - 1;
	cout << n - c;
	return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

string str;
int q, a, b;

void print() {
    for (int i = a; i<=b; i++) {
        cout << str[i];
    }
    cout << endl;
}
void reverse() {
    while (a<b) {
        swap(str[a], str[b]);
        a++;
        b--;
    }
}
void replace(string p) {
    str.replace(a, b - a + 1, p);
}

int main() {
    string order;

    cin >> str;
    cin >> q;

    while (q--) {
        cin >> order >> a >> b;
        if (order == "print") print();
        else if (order == "reverse") reverse();
        else if (order == "replace") {
            string p;
            cin >> p;
            replace(p);
        }
    }

    return 0;
}

Measured memory_bytes: 3208
#include <iostream>
#include <utility>
#include <queue>
#define inf 1e9

using namespace std;
typedef pair<int, int> P;

int h, w;
char map[55][55];
int dist[55][55];
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};

void bfs()
{
	for(int x = 1; x <= w; x++){
		for(int y = 1; y <= h; y++){
			dist[x][y] = inf;
		}
	}
	dist[1][1] = 0;
	
	queue<P> Q;
	Q.push(make_pair(1, 1));
	
	int x, y, nx, ny;
	while(Q.size()){
		x = Q.front().first;
		y = Q.front().second;
		Q.pop();
		for(int d = 0; d < 4; d++){
			int nx = x + dx[d], ny = y + dy[d];
			if(nx <= 0 || nx > w || ny <= 0 || ny > h) continue;
			if(map[nx][ny] == '#') continue;
			if(dist[nx][ny] < inf) continue;
			Q.push(make_pair(nx, ny));
			dist[nx][ny] = dist[x][y] + 1;
		}
	}
}

int main(void)
{
	cin >> h >> w;
	for(int y = 1; y <= h; y++){
		for(int x = 1; x <= w; x++){
			cin >> map[x][y];
		}
	}
	
	bfs();
	
	if(dist[w][h] >= inf){
		cout << -1 << endl;
		return 0;
	}
	
	int ans = h*w - (dist[w][h]+1);
	for(int x = 1; x <= w; x++){
		for(int y = 1; y <= h; y++){
			if(map[x][y] == '#') ans--;
		}
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
#include <iostream>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;

#define pf(n) cout << n << endl
#define ps() cout <<" ";
#define sf(n) cin >> n
#define in(i,n) for (int i = 0; i < n; i++)
#define vi vector<int>
#define vp vector<pair<int, int>>
#define graph vector< vector<int> >
#define vs vector<string>
/**  '' "\n" ^ - = + **/


typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag,
                 tree_order_statistics_node_update>
        new_data_set;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string str;
    cin>>str;
    int count=0;
    for(int i=0,j=str.length()-1;i<str.length()/2;i++,j--)
    {
        if(str[i]!=str[j])count++;
    }
    pf(count);
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;

class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Integer count = Integer.parseInt(br.readLine());
		String[] strNumArrays = br.readLine().split(" ");
		ArrayList<Integer> numArrayList = new ArrayList<Integer>();
		for (int i = 0; i < count; i++) {
			numArrayList.add(Integer.parseInt(strNumArrays[i]));
		}
		Collections.reverse(numArrayList);
		String out = "";
		for (int i = 0; i < numArrayList.size(); i++) {
			if (i == numArrayList.size() - 1) {
				out += numArrayList.get(i);
			} else {
				out += numArrayList.get(i) + " ";
			}
		}
		System.out.println(out);
	}

}

Measured memory_bytes: 17088
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String ans = "";
		for(int i = 0; i < s.length(); i++) {
			ans += "x";
		}
		System.out.println(ans);

	}

}


Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;


signed main() {
  string s; 
  cin >> s;

  int ans = 0;
  int g = 0, p = 0;
  REP(i, s.size()){
    if(s[i] == 'g'){
      if(p < g){
        p++; ans++;
      }else{
        g++;
      }
    }else{
      if(p < g){
        p++;
      }else{
        g++; ans--;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

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

const ll MOD = 1e9+7;

int main(){
    ll h; cin >> h;
    ll l_at = 1LL;
    ll cnt = 0LL;
    if(h ==1){
        cout << 1 << endl;
        return 0;
    }
    while(h){
        if(h == 1) break;
        h /= 2;
        cnt += l_at;
        l_at *= 2;
    }
    cout << l_at+cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using vi = vector<i64>;
using vvi = vector<vi>;

class BIT {
    int n;
    vi data0, data1;

    void add(vi& data, int i, i64 x) {
        while (i <= n) {
            data[i] += x;
            i += i & -i;
        }
    }

    i64 sum(vi& data, int i) {
        i64 s = 0;
        while (i > 0) {
            s += data[i];
            i -= i & -i;
        }
        return s;
    }

public:
    BIT(int n) : n(n) {
        data0 = vi(n + 1);
        data1 = vi(n + 1);
    }

    // [l, r)
    void add(int l, int r, i64 x) {
        l++;
        r++;
        add(data0, l, -x * (l - 1));
        add(data1, l, x);
        add(data0, r, x * (r - 1));
        add(data1, r, -x);
    }

    // [l, r)
    i64 sum(int l, int r) {
        i64 s = 0;
        s += sum(data0, r) + sum(data1, r) * r;
        s -= sum(data0, l) + sum(data1, l) * l;
        return s;
    }
};

int check(vi as, int s, int k, int q) {
    int n = as.size();
    vi dpl(n), dpr(n);

    using ii = pair<int, int>;
    vector<ii> vs;
    for (int i = 0; i < n; i++) {
        if (as[i] >= s) {
            vs.push_back(ii(as[i], i));
        }
    }
    sort(vs.begin(), vs.end());

    for (int i = 1; i < n; i++) {
        if (as[i - 1] >= s) {
            dpl[i] = dpl[i - 1] + 1;
        } else {
            dpl[i] = 0;
        }
    }
    for (int i = n - 2; i >= 0; i--) {
        if (as[i + 1] >= s) {
            dpr[i] = dpr[i + 1] + 1;
        } else {
            dpr[i] = 0;
        }
    }
    
    vi dp(n);
    for (int i = 0; i < n; i++) {
        if (as[i] >= s) {
            dp[i] = dpl[i] + dpr[i] + 1;
        } else {
            dp[i] = 0;
        }
    }

    BIT bit(n);
    for (int i = 0; i < n; i++) {
        bit.add(i, i + 1, dp[i]);
    }

    int cnt = 0;
    i64 nax = 0;
    for (ii& v: vs) {
        int a = v.first;
        int i = v.second;

        if (bit.sum(i, i + 1) >= k) {
            bit.add(i - dpl[i], i, -1);
            bit.add(i, i + dpr[i] + 1, -1);
            cnt++;
            nax = max(nax, as[i]);
            if (cnt == q) {
                return nax - s;
            }
        }
    }
    return -1;
}

int main() {
    int n, k, q;
    cin >> n >> k >> q;
    vi as(n);
    for (int i = 0; i < n; i++) {
        cin >> as[i];
    }

    vi bs(as);
    sort(bs.begin(), bs.end());

    int nin = 1e9;
    for (int b: bs) {
        int res = check(as, b, k, q);
        if (res != -1) {
            nin = min(nin, res);
        }
    }

    cout << nin << endl;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;

#define ALL(a) (a).begin(),(a).end()
#define ZP(a, len) setfill('0') << setw(len) << right << a
const int INF = 1e9;
const int MOD = 1e9 + 7;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
const ll LINF = 1e11;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

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

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

    int a, b;
    cin >> a >> b;

    int ans = 0;
    if (a == b) {
        ans = a * 2;
    } else {
        ans = max(a, b);
        ans *= 2;
        ans -= 1;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
using lli = long long int;
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
const int MOD = 1000000007;
const int MOD1 = 998244353;
const int maxn = 100010;
const int lim = (int)1e9;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n = 0;
	cin >> n;
	vector<vector<int> > d(n, vector<int>(2));
	for (int i = 0; i < n; ++i)
		cin >> d[i][0] >> d[i][1];
	for (int i = 0; i + 2 < n; ++i)
		if (d[i][0] == d[i][1] && d[i + 1][0] == d[i + 1][1] && d[i + 2][0] == d[i + 2][1])
		{
			cout << "Yes" << endl; return 0;
		}
	cout << "No" << endl;
}

Measured memory_bytes: 3588
import sys
sys.setrecursionlimit(10**9)
INF=10**18
def input():
    return sys.stdin.readline().rstrip()

def main():
    N,A,B=map(int,input().split())
    if (A-B)%2==0:
        print(abs(A-B)//2)
    else:
        X=min(max(A,B)-1,N-min(A,B))
        c=min(min(A,B)-1,N-max(A,B))+1
        Y=c+(abs(A-B)-1)//2
        print(min(X,Y))

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
datas = gets.split(" ").map{|n|n.to_i}
n = datas[0]
d = datas[1]

ary = []
n.times{
	ary << gets.split(" ").map{|n|n.to_i}
}
ans = 0

for ii in 0..(n-2) do
  for jj in (ii+1)..(n-1) do
    #/ ary[ii] ary[jj]

    inc = 0
    for idx in 0..(d-1)
      inc += (ary[ii][idx] - ary[jj][idx]) * (ary[ii][idx] - ary[jj][idx])
    end
    if Math.sqrt(inc) % 1 == 0
    ans += 1
    end
  end
end
puts ans.to_s

Measured memory_bytes: 1788
#include <iostream>
#include <limits.h>
#include <vector>
using namespace std;
int main(int argc, char const *argv[])
{
    int n, A[200000];
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> A[i];
    }
    int m = INT_MAX;
    int diff = INT_MIN;
    for(int i=0; i<n-1; i++){
        m = min(m, A[i]);
        diff = max(diff, A[i+1]-m);
    }
    cout << diff << endl;
}



Measured memory_bytes: 3872
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, k, ans;
vector<string> vs;
int m[15];
bool isfirst[30];
bool take[10];
int board[30];
int vl[30], vr[30];

inline void solve(int &p, vector<int> &v) {
    if(p == k) {
        bool ok = true;
        rep(i,0,p) if(v[i] == 0 && isfirst[ m[i] ]) return;
        int l = 0, r = 0;
        rep(i,0,p) l += v[i] * vl[ m[i] ];
        rep(i,0,p) r += v[i] * vr[ m[i] ];
        if(l == r) ans++;
    }
    else {
        rep(i,0,10) {
            if(!take[i]) {
                take[i] = true;
                v[p] = i;
                board[ m[p] ] = v[p];
                p++;
                solve(p, v);
                p--;
                take[i] = false;
            }
        }
    }
}

signed main() {
    while(cin >> N, N) {
        memset(isfirst, false, sizeof(isfirst));
        vs.resize(N);

        k = 0;
        bool used[30] = {};
        rep(i,0,N) {
            cin >> vs[i];
            rep(j,0,vs[i].length()) {
                if(used[ vs[i][j] - 'A' ]) continue;
                used[ vs[i][j] - 'A' ] = true;
                m[k++] = vs[i][j] - 'A';
            }

            if(vs[i].length() != 1) isfirst[ vs[i][0] - 'A' ] = true;
        }

        memset(vl, 0, sizeof(vl));
        memset(vr, 0, sizeof(vr));
        rep(i,0,N) {
            int temp[30] = {};
            rep(j,0,vs[i].length()) {
                rep(k,0,26) temp[k] *= 10;
                int c = vs[i][j] - 'A';
                temp[c]++;
            }
            rep(j,0,26) {
                if(i != N-1) vl[j] += temp[j];
                else vr[j] += temp[j];
            }
        }

        ans = 0;
        int p = 0;
        vector<int> arr(k);
        solve(p, arr);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3152
using System;
using System.Collections.Generic;
using static AtCoderer.Exter;
using static System.Math;
using System.Linq;

namespace AtCoderer
{

    public class App
    {
        public static void Solve()
        {
            int n = readarr[0];
            int[] r = readarr;
            int MinSubst = 1000000;
            int Sum = r.Sum();
            int Suming = 0;
            foreach (int a in r)
            {
                Sum -= a;
                Suming += a;
                if (MinSubst > Abs(Sum - Suming))
                    MinSubst = Abs(Sum - Suming);
            }
            Console.WriteLine(MinSubst);
        }
        public static void Main(string[] args)
        {
            Solve();
            Console.ReadKey();
        }
    }
    public static class Exter
    {
        public static void rep(int loop, Action<int> act)
        {
            for (int i = 0; i < loop; i++)
                act(i);
        }
        public static int Max(params int[] p) => p.Max();
        public static long Max(params long[] p) => p.Max();
        public static int Min(params int[] p) => p.Min();
        public static long Min(params long[] p) => p.Min();
        public static int Gcd(int a, int b) => a > b ? GcdRecursive(a, b) : GcdRecursive(b, a);
        private static int GcdRecursive(int a, int b) => b == 0 ? a : GcdRecursive(b, a % b);
        public static void EnumArr<t>(this IEnumerable<t> v)
        {
            Console.WriteLine(string.Join(",", v));
        }
        public static string ToString(this IEnumerable<char> v)
        {
            return string.Join(",", v);
        }
        public static int[] readarr
        {
            get
            {
                return Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
            }
        }
        public class UnionFind
        {
            private int[] Parent;
            private int GetRoot(int v)
            {
                if (Parent[v] < 0)
                    return v;
                else
                    return Parent[v] = GetRoot(Parent[v]);
            }
            public UnionFind(int size)
            {
                Parent = new int[size];
                for (int i = 0; i < size; i++)
                    Parent[i] = -1;
            }
            public bool AreGrouped(int a, int b)
            {
                return GetRoot(a) == GetRoot(b);
            }
            public void Connect(int a, int b)
            {
                a = GetRoot(a);
                b = GetRoot(b);
                if (a == b) return;
                if(Parent[b]<Parent[a])
                {
                    Parent[b] += Parent[a];
                    Parent[a] = b;
                }
                else
                {
                    Parent[a] += Parent[b];
                    Parent[b] = a;
                }
            }
            public int GetGroupSize(int a)
            {
                return -Parent[GetRoot(a)];
            }
        }
    }
}


Measured memory_bytes: 13396
s = input()
key = "keyence"
l = len(key)
if s[:l] == key or s[-l:] == key:
	print("YES")
	exit()
for i in range(l):
	if s[:i] == key[:i] and s[-(l-i):] == key[-(l-i):]:
		print("YES")
		exit()
else:
	print("NO")

Measured memory_bytes: 38384
from collections import Counter,defaultdict,deque
import sys
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
# mod = 10**9+7
    
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n,k = inpm()
    a = inpl()
    x = [0 for _ in range(41)]
    y = [0 for _ in range(41)]
    index = 0
    while k > 0:
        x[index] += k%2
        k //= 2
        index += 1
    for i in range(n):
        index = 0
        while a[i] > 0:
            y[index] += a[i]%2
            a[i] //= 2
            index += 1
    ans = 0
    key1 = 0
    key2 = 0
    for i in range(40,-1,-1):
        flag = (y[i]>=(n/2))
        if x[i]>0 or y[i]>0:
            key2 = 1
        if x[i] == 1 and flag and key2 and (not key1):
            key1 = True
            ans += pow(2,i)*y[i]
        elif key2:
            if flag or (x[i] == 0 and (not key1)):
                ans += pow(2,i)*y[i]
            else:
                ans += pow(2,i)*(n-y[i])
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 68696