akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001; //check the limits, dummy
 
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N; cin >> N;
    N %= 1000;
    N = 1000 - N; 
    N %= 1000;
    cout << N << nl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll=long long;
using vi = vector<int>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;

int main(){
    int n;
    cin >> n;
    vector<tuple<int,int,int>> a(n);
    rep(i,n){
        int t,x,y;
        cin >> t >> x >> y;
        a[i] = make_tuple(t,x,y);
    }
    bool ok = true;
    rep(i,n){
        int t,x,y;
        tie(t,x,y) = a[i];
        if((t%2 - (abs(x) + abs(y) - 0)%2)==0 && (abs(x)+abs(y) <= t)){
           continue;
        }else{
            ok = false;
        }
    }
    cout << (ok?"Yes":"No") << endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
#define MSG(a) cout << #a << " " << a << "\n";


int main(){
int a,b,k = 0; cin >> a >> b;
  if(a > b){
      if((a-b)%2 == 1){
          cout << "IMPOSSIBLE"<< endl;
      }
    else {
        k = (a - b) / 2;
    cout << b + k << endl;
    }
}

  if(b > a){
      if((b-a)%2 == 1){
          cout << "IMPOSSIBLE"<< endl;
      }
      else{
    k = (b - a) / 2;
    cout << a + k << endl;
      }
}
}

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

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

	int p=0;
	rep(i,n){
		if(p==1){ cout<<i<<endl; return 0; }
		p=a[p];
	}
	cout<<-1<<endl;

	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define _abs(x)((x) < 0 ? (x) * -1 : (x))
#define _max(x, y)(max(0, max((x), (y))))
#define _min(x, y)(max(0, min((x), (y))))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x, y) for ((x) = (y).begin(); (x) != (y).end(); (x)++)
#define all(x) (x).begin(),(x).end()
#define _end '\n'
template<typename T> inline bool __max__(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool __min__(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using vvec = vector<vector<T> >;

#define pb push_back
#define mp make_pair

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    //freopen("debug.txt", "w", stderr);

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;

    cin >> n;

    cout << (24 - n) + 24 << _end;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int A,B;
  cin >> A >> B;
  if(A==1 && B==2){
    cout << 3 << endl;
  }
  else if(A==2 && B==1){
    cout << 3 << endl;
  }
  else if(A==1 && B==3){
    cout << 2 << endl;
  }
  else if(A==3 && B==1){
    cout << 2 << endl;
  }
  else if(A==2 && B==3){
    cout << 1 << endl;
  }
  else if(A==3 && B==2){
    cout << 1 << endl;
  }
}

Measured memory_bytes: 256
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    a = list(map(int, readline().split()))
    for v in a:
        if v % 2 == 0:
            if v % 3 != 0 and v % 5 != 0:
                print("DENIED")
                exit()
    print("APPROVED")


if __name__ == '__main__':
    solve()


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repiins(x, y, z, s) for ((x) = (z); (x) <= (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define repit2(x) for (__typeof((x).begin()) it2 = (x).begin(); it2 != (x).end(); it2++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

#define All(x) (x).begin(),(x).end()

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

// can be applied to string type
#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
template<typename T>
void Debug(const T &val) { cerr << val << End; }
template<typename T, typename... Args>
void Debug(const T &val, Args... args) {
    cerr << val << ' ';
	Debug(std::forward<Args>(args)...);
}

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

// can be applied to string type
#define Sort(v) sort(All(v))
#define SortR(v) sort(All(v), std::greater<__typeof(v[0])>())
// array sorters
#define Sart(a) sort(a, a + sizeof(a) / sizeof(__typeof(a[0])));
#define SartR(a) sort(a, a + sizeof(a) / sizeof(__typeof(a[0])), std::greater<__typeof(a[0])>())

#define pb push_back
#define mp make_pair
#define a first
#define b second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

    long n;
	string s;

	cin >> n;
	cin >> s;

    long table[26];
	ll ans = 1;

	Mem0(table);

	long i;

	rep(i, n) table[s[i] - 'a']++;

	rep(i, 26) if (0 < table[i]) ans = ((table[i] + 1) * ans) % MOD;

	Out(ans - 1);
	
	return 0;
}


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

using namespace std;
typedef long long LL;

#define MAXN 50
#define MOD 1000000007
#define mp make_pair


int main(int argc, char **argv)
{
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);

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

    if (a + b == 15)
        cout << "+";
    else if (a * b == 15)
        cout << "*";
    else 
        cout << "x";

    cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define null NULL
#define mp make_pair
#define pb(a) push_back(a)
#define sz(a) ((int)(a).size())
#define all(a) a.begin() , a.end()
#define fi first
#define se second
#define relaxMin(a , b) (a) = min((a),(b))
#define relaxMax(a , b) (a) = max((a),(b))
#define SQR(a) ((a)*(a))
#define PI 3.14159265358979323846
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

const int MAXN = 100010;
const int UP = 0;
const int DOWN = 1;

int n, in[MAXN];
int dp[MAXN][2];

int main(){
  scanf("%d", &n);
  for(int i = 0;i < n;++i)
    scanf("%d", &in[i]);

  dp[0][UP] = dp[0][DOWN] = 1;
  for(int i = 1;i < n;++i){
    dp[i][UP] = dp[i][DOWN] =
        1 + min(dp[i - 1][UP], dp[i - 1][DOWN]);
    if(in[i - 1] <= in[i])
      relaxMin(dp[i][UP], dp[i - 1][UP]);
    if(in[i - 1] >= in[i])
      relaxMin(dp[i][DOWN], dp[i - 1][DOWN]);
  }

  printf("%d\n", min(dp[n - 1][UP], dp[n - 1][DOWN]));

  return 0;
}


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

int main() {
  int x, y;
  cin >> x >>y;
  
  vector<int> a, b;
  a = {1, 3, 5, 7, 8, 10, 12};
  b = {4, 6, 9, 11};
  
  bool finished1 = false;
  
  for (int i = 0; i < 7; i++) {
    for (int j = 0; j < 7; j++) {
      if (x == a[i] && y == a[j]) {
        cout << "Yes" << endl;
        finished1 = true;
        break;
      }
    }
    if (finished1)
      break;
  }
  
  bool finished2 = false;
  
  for (int i = 0; i < 4; i++) {
    for (int j = 0; j < 4; j++) {
      if (x == b[i] && y == b[j]) {
        cout << "Yes" << endl;
        finished2 = true;
        break;
      }
    }
    if (finished2)
      break;
  }
  
  if (finished1 == finished2)
    cout << "No" << endl;
}

Measured memory_bytes: 256
use std::collections::HashSet;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() -> () {
    input!{
        n: usize,
        info: [(i32, i32, i32); n],
    }
    if n == 1 {
        println!("{} {} {}", info[0].0, info[0].1, info[0].2);
        return;
    }
    let mut info = info;
    info.sort_by(|a, b| b.2.cmp(&a.2));
    let mut candidate = calc(&info[0], &info[1]);
    for x in 0..n {
        if info[x].2 == 0 {
            continue;
        }
        for y in x + 1..n {
            if info[y].2 == 0 {
                continue;
            }
            candidate = candidate
                .intersection(&calc(&info[x], &info[y]))
                .cloned()
                .collect();
        }
    }
    for i in 0..n {
        if info[i].2 != 0 {
            continue;
        }
        //candidate.retain(|c| );
        let mut del = Vec::new();
        for c in candidate.iter() {
            if c.2 - (info[i].0 - c.0).abs() - (info[i].1 - c.1).abs() > 0 {
                del.push(c.clone());
            }
        }
        for d in del.iter() {
            candidate.remove(d);
        }
    }
    for c in candidate.drain() {
        println!("{} {} {}", c.0, c.1, c.2);
    }
}

fn calc(p1: &(i32, i32, i32), p2: &(i32, i32, i32)) -> HashSet<(i32, i32, i32)> {
    let mut candidate = HashSet::new();
    for x in 0..101 {
        for y in 0..101 {
            let h1 = p1.2 + (p1.0 - x).abs() + (p1.1 - y).abs();
            let h2 = p2.2 + (p2.0 - x).abs() + (p2.1 - y).abs();
            if h1 == h2 {
                candidate.insert((x, y, h1));
            }
        }
    }
    return candidate;
}


Measured memory_bytes: 4352
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int ans=0;
  int maxx=-1;
  for(int i=0;i<n;i++){
    maxx=max(maxx,a[i]);
    if(maxx==a[i])ans++;
  }
  cout<<ans<<endl;
}

  

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n,m,k;
	cin>>n>>m>>k;
	for(int i=0;i<m;++i)
		cout<<k<<' ';
	for(int i=m;i<n;++i)
		if(k==1000000000)
			cout<<1<<' ';
		else
			cout<<k+1<<' ';
	return 0;
}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define P pair<ll, ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
constexpr ll mod = 1000000007;
constexpr ll INF = (1ll << 60);
constexpr double pi = 3.14159265358979323846;
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;}

int main(){
    ll x,k,d;cin>>x>>k>>d;
    if(abs(x)/d>=k){
        cout<<abs(x)-k*d<<endl;
        return 0;
    }

    ll ans1=abs(x%d);
    ll ans2=(x%d>=0?abs(x%d-d):abs(x%d+d));

    if((k-abs(x)/d)%2==0) cout<<ans1<<endl;
    else cout<<ans2<<endl;

    return 0;
}

Measured memory_bytes: 3628
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

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

#define MOD 1000000007

void solve(int test_case) {//221
	int a,b,c,x;
	cin>>a>>b>>c>>x;
	int cnt=0;
	REP(i,0,a) {
		REP(j,0,b) {
			REP(k,0,c) {
				if(i*500+j*100+k*50==x)cnt++;
			}
		}
	}
	cout<<cnt;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3584
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace ABC171
{
    class D
    {
        static void Main(string[] args)
        {
            //var NK = Console.ReadLine().Split().Select(long.Parse).ToArray();
            //var p = Console.ReadLine().Split().Select(long.Parse).OrderBy(x => x).ToArray();
            // var CA = Enumerable.Repeat(0, (int)N).Select(_ => Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray();
            //var AB = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var N = long.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var Q = long.Parse(Console.ReadLine());
            var BC = Enumerable.Repeat(0, (int)Q).Select(_ => Console.ReadLine().Split().Select(long.Parse).ToArray()).ToArray();

            var count = new long[100010];
            for (int i = 0; i < A.Length; i++)
            {
                count[A[i]]++;
            }

            var sum = new long[100010];
            for (int i = 0; i < count.Length; i++)
            {
                sum[i] = count[i] * i;
            }

            var Asum = A.Sum();

            for (int i = 0; i < Q; i++)
            {
                Asum = Asum - sum[BC[i][0]] + count[BC[i][0]] * BC[i][1];
                sum[BC[i][0]] = 0;
                sum[BC[i][1]] += count[BC[i][0]] * BC[i][1];
                count[BC[i][1]] += count[BC[i][0]];
                count[BC[i][0]] = 0;

                Console.WriteLine(Asum);
            }

        }
    }
}


Measured memory_bytes: 53060
#include<bits/stdc++.h>
using namespace std;
const int INF=1e9;
const int MOD=1e9+7;
template<typename A,size_t N,typename T>
void Fill(A (&array)[N],const T &val)
{
    std::fill( (T*)array,(T*)(array+N),val );
}
int main(void)
{
    int N,K;
    cin >> N >> K;
    int num=1;
    while((N/K)>0)
    {
        N/=K;
        num++;
    }
    cout << num << endl;

}

Measured memory_bytes: 256
N = int(input())

ls = [i for i in range(1,N+1)]
import itertools
plist = list(itertools.combinations(ls,2))
ls = []
cnt=0
all_pattern = len(plist)
if N % 2== 0:
    print(all_pattern-(N//2))
    idx_x = N
else:
    print(all_pattern-(N-1)//2)
    idx_x = N-1
idx_y = 1
for p in plist:
    if p[0] == idx_y and p[1]==idx_x:
        idx_x = idx_x -1
        idx_y = idx_y +1
    else:
        print(p[0],p[1])

Measured memory_bytes: 3996
n = int(input())
s = input()

alphabet = ["A", "B", "C", "D", "E", "F", "G", "H", "I",
            "J", "K", "L", "M", "N", "O", "P", "Q", "R",
            "S", "T", "U", "V", "W", "X", "Y", "Z"]

new_s = []
for i in range(len(s)):
    i_num = alphabet.index(s[i])
    if i_num + 1 + n <= 26:
        new_num = i_num + n
    else:
        new_num = n + i_num  - 26
    new_s.append(alphabet[new_num])

print("".join(new_s))


Measured memory_bytes: 40048
# -*- coding: utf-8 -*-

import numpy as np

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

adjacent = np.zeros((N, N))
for l in L:
    adjacent[l[0] - 1, l[1] - 1] = 1
    adjacent[l[1] - 1, l[0] - 1] = 1
# print(adjacent, end='\n\n')

pre = [-1 for _ in range(N)]
low = [-1 for _ in range(N)]
v = k = 0
ans = 0


def dfs(v, pre, low, k, parent):
    global ans
    pre[v] = k
    k += 1
    low[v] = pre[v]
    for to, n in enumerate(adjacent[v, :]):
        if n == 1:
            if pre[to] == -1:
                # destination has not been visited
                # visit destination and update low[v]
                # print('-----', v, '-------')
                # print(pre, low)
                low[v] = min(low[v], dfs(to, pre, low, k, v))
                if low[to] == pre[to]:
                    ans += 1
                    # print(v + 1, to + 1)
            else:
                # visited
                if to == parent:
                    pass
                else:
                    low[v] = min(low[v], low[to])

    return low[v]


dfs(v, pre, low, k, -1)
# print(pre, low)
print(ans)

Measured memory_bytes: 12476
// ABC108_C
#include <iostream>
#include <string>
#include <vector>
#include <iterator>
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値

int main() {
    // input
    ll x_1, y_1, x_2, y_2;
    cin >> x_1 >> y_1 >> x_2 >> y_2;
    
    ll diff_y = y_2 - y_1, diff_x = x_2 - x_1;
    
    ll x_3 = x_2 - diff_y, y_3 = y_2 + diff_x;
    ll x_4 = x_1 - diff_y, y_4 = y_1 + diff_x;  
    
    cout << x_3 << " " << y_3 << " " << x_4 << " " << y_4 << "\n";
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(ll i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cout << "[" << #var << "] " << var << endl
const ll mod = 1000000007;


int main(){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) {
        cin >> a[i];
        a[i]--;
    }

    ll ans = 0;
    vector<bool> used(n);

    ll id = 0;
    ll id2 = 0;
    ll num = 0;
    vector<ll> now;
    while (!used[id]) {
        now.push_back(id);
        used[id] = true;
        id = a[id];
        num++;
        if (num==k) {
            cout << id + 1 << endl;
            return 0;
        }
    }
    rep(i, now.size()) {
        if (id==now[i]) {
            id2 = i;
            break;
        }
    }
    
    ll loop = now.size() - id2;
    //debug(loop);
    //debug(num);
    k -= num;
    k %= loop;
    ans = now[id2+k]+1;
    
    
    
    cout << ans << endl;
    return 0;
}


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


void solve(long long N, string S){
    int cnt = 0;
    for(int i = 0;i < 10;i++){
        for(int j = 0;j < 10;j++){
            for(int k = 0;k < 10;k++){
                int u = 0;
                for(auto a : S){
                    if(u == 0){
                        if(a - '0' == i){
                            u++;
                        }
                    }else if(u == 1){
                        if(a - '0' == j){
                            u++;
                        }
                    }else if(u == 2){
                        if(a - '0' == k){
                            u++;
                        }
                    }
                    if(u == 3){
                        break;
                    }
                }
                if(u == 3){
                    cnt++;
                }
            }
        }
    }
    cout<<cnt<<endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    string S;
    cin >> S;
    solve(N, S);
    return 0;
}


Measured memory_bytes: 512
card = []
numbers = []
flag = true
3.times do |i|
  card.push(gets.split().map(&:to_i))
end

gets.to_i.times do |i|
  numbers.push(gets.to_i)
end

#横の判定 
3.times do |i|
  flag = true
  3.times do |j|
    unless numbers.include?(card[i][j])
      flag = false
      break
    end  
  end
  if flag
    puts "Yes"
    exit
  end
end

#縦の判定
3.times do |i|
  flag = true
  3.times do |j|
    unless numbers.include?(card[j][i])
      flag = false
      break
    end  
  end
  if flag
    puts "Yes"
    exit
  end
end

#斜めの判定1
1.times do 
  flag = true
  3.times do |i|
    unless numbers.include?(card[i][i])
      flag = false
      break
    end
  end
  if flag
    puts "Yes"
    exit
  end
end

#斜めの判定2
1.times do 
  flag = true
  3.times do |i|
    unless numbers.include?(card[i][2-i])
      flag = false
      break
    end
  end
  if flag
    puts "Yes"
    exit
  end
end

puts "No"

Measured memory_bytes: 1788
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 2000100;
const int mod = (int)pow(10,9) + 7;
const ll INF = 1LL << 60;
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define ppp pair<ll,pp>
#define fi first
#define se second
#define pb push_back
#define fix(n) fixed<<setprecision(n)
#define itr vector<ll>::iterator
#define print(s) cout<<s<<endl
#define inp(s) cin>>s
int par[100100];  // リーダーの値を格納 
int find(int x) { if (par[x] == x)return x; par[x] = find(par[x]); return par[x]; }
void unite(int x, int y) { x = find(x); y = find(y); if (x == y)return; par[x] = y; }
bool same(int x, int y) { return find(x) == find(y); }
ll n, m,v[100010],ans;
int main() {
	rep(i, 100010)par[i] = i;
	inp(n>> m);
	rep(i, n)inp(v[i]);
	ll a, b;
	rep(i, m) {
		inp(a >> b);
		unite(a, b);
	}
	rep(i, n) {
		ans += same(i+1, v[i]);
	}
	print(ans);
	return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define sort(s) sort(s.begin(),s.end())
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<int>>
constexpr auto mod = 1000000007;


//2のn乗を求めるよ！！！
int ni(int n) {
	if (n == 0)return 1;
	int x = ni(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;
}

//フィボナッチ数列のx番目を求めるよ！
int f(int x,vector<int> s) {
	if (x == 0)return 0;
	if (x == 1)return 1;
	if (s[x] != 0)return s[x];
	s[x] = f(x - 1,s) + f(x - 2,s);
	return s[x];
}

//aとｂの最大公約数を求めるよ！
llint gcd(llint a, llint b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a % b);
}



// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long 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;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b,ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}

//m進数のn桁を全列挙やで
void dfs(int m, int n) {

	stack<string> st;
	st.push("");
	while (!st.empty()) {
		string now = st.top();
		st.pop();
		if (now.size() == n) {
			cout << now << endl;
		}
		else {
			for (int i = m-1; i >= 0; i--) {
				string next = now + to_string(i);
				st.push(next);
			}
		}
	}
}

int main(){
	int n,x;
	cin >> n;
	hei(int) a(n);
	int ans = 0;
	rep(i, 0, n) {
		cin >> a[i];
		if (ans < a[i]) {
			ans = a[i];
			x = i;
		}
	}
	sort(a);
	rep(i, 0, n) {
		if (i == x)cout << a[n - 2] << endl;
		else cout << ans << endl;
	}
	

	return 0;
}




  


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

using namespace std;

int GCD(int x, int y) {
	if (x % y == 0)
		return y;

	return GCD(y, x % y);
}

int main() {

	int x, y;
	scanf("%d %d", &x, &y);

	cout << GCD(x, y) << endl;
	return 0;
}

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

template<class T>
ostream& operator<<(ostream& os,vector<T> const& v){for(auto itr=v.begin();itr!=v.end();++itr){if(itr!=v.begin())os<<' ';os<<*itr;}return os;}

signed main(){

  int n;
  cin>>n;
  vector<int> a(n);
  for(auto& ai:a)cin>>ai;

  int q;
  cin>>q;
  while(q--){
    int k;
    cin>>k;
    cout<< lower_bound(a.begin(),a.end(),k)-a.begin() <<endl;
  }

}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
int main() {
  string S,T;
  cin >> S >> T;
  int ssize=S.size();
  int tsize=T.size();
  if(tsize=ssize+1&&S.substr(0,ssize)==T.substr(0,ssize)){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  
}

Measured memory_bytes: 3632
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int getminodd(int n)
{
	int res = 3;
	while(n >= res && n % res > 0) res += 2;
	return res;
}

int main()
{
	int n;
	cin >> n;
	if(n == 3){
		cout << 2 << " " << 5 << " " << 63 << endl;
		return 0;
	}
	vector<int> res;
	for(int i = 1; i <= 15000 && i <= n - 2; i++){
		res.push_back(2 * i);
	}
	for(int i = 3; i <= 15000; i++){
		if(getminodd(i) >= 10000 && getminodd(i + 1) >= 10000)
		cout << i << " " << getminodd(i) << endl;
	}
	int minodd = min(getminodd(res.size()), getminodd(res.size() + 1));
	if((n - res.size()) % 2 == 1) res.pop_back();
	for(int i = 0; res.size() < n; i++){
		res.push_back((2 * i + 1) * minodd);
	}
	for(int i = 0; i < n; i++){
		cout << res[i];
		if(i == n - 1) cout << endl;
		else cout << " ";
	}
}

Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            //var exStdIn = new System.IO.StreamReader("stdin.txt");
            //System.Console.SetIn(exStdIn);

            long N = long.Parse(Console.ReadLine());

            string[] s = new string[N];
            Dictionary<string,long> h = new Dictionary<string, long>();
            long hit = 0;
            for (long i = 0; i < N; i++)
            {
                s[i] = Console.ReadLine();
                s[i] = sort(s[i]);
                if (h.ContainsKey(s[i]))
                {
                    hit += h[s[i]];
                    h[s[i]] = h[s[i]] + 1; ;
                }
                else
                {
                    h.Add(s[i],1);
                }
            }
            Console.WriteLine(hit);
        }
        static string sort(string s)
        {
            string[] c= new string[10];
            for (int i = 0; i < 10; i++)
            {
                c[i] = s.Substring(i, 1);
            }
            StringComparer cmp = StringComparer.OrdinalIgnoreCase;
            Array.Sort(c, cmp);
            s = "";

            for (int i = 0; i < 10; i++)
            {
                s += c[i];
            }
            return s;
        }
    }
}


Measured memory_bytes: 29468
import java.util.Scanner;

public class Main {
    static final int mod = 1000000007;
    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        long ans = 0;
        long[] a = new long[n + 1];
        for (int i = 1 ; i < n + 1 ; i++) {
            a[i] = (long) a[i - 1] + i;
        }

        for (int i = k ; i <= n ; i++) {
            ans += (a[n] - a[n - i] - a[i - 1] + 1 + mod) % mod;
        }
        System.out.println((ans + 1) % mod);

        }

}

Measured memory_bytes: 37288
#include<bits/stdc++.h>
using namespace std;
int n;
string s;
map<string, int> mp;
vector<pair<int, string> > v;
bool cmp(pair<int, string> a, pair<int, string> b)
{
	if(a.first != b.first)
		return a.first > b.first;
	return a.second < b.second;
}
int main()
{
	cin>>n;
	for(int i = 0; i < n; i++)
	{
		cin>>s;
		mp[s]++;
	}
	for(map<string, int>::iterator it = mp.begin(); it != mp.end(); it++)
	{
		v.push_back(make_pair(it->second, it->first));
	}
	sort(v.begin(), v.end(), cmp);
	for(int i = 0; i < v.size(); i++)
	{
		if(v[i].first != v[0].first)
		{
			break;
		}
		cout<<v[i].second<<endl;
	}
	return 0;
}

Measured memory_bytes: 29684
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
			try(Scanner sc = new Scanner(System.in)){
				final String[] patterns = {"S","H","C","D"};
				int length = sc.nextInt();
				boolean[][] cards = new boolean[4][13];
				for(int i = 0; i < 52; i++) {
					cards[i/13][i%13] = true;
				}
				for(int i = 0; i < length; i++) {
					String pattern = sc.next();
					int num = sc.nextInt();

					if(pattern.equals("S")) {
						cards[0][num-1] = false;
					}
					else if(pattern.equals("H")) {
						cards[1][num-1] = false;
					}
					else if(pattern.equals("C")) {
						cards[2][num-1] = false;
					}
					else if(pattern.equals("D")) {
						cards[3][num-1] = false;
					}
				}
				for(int i = 0; i < 52; i++) {
					if(cards[i/13][i%13])
						System.out.println(String.format("%s %d", patterns[i/13],i%13+1));
			}
		}
	}

}



Measured memory_bytes: 26400
import java.util.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Collections;

public class Main {
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        //ArrayList<Integer> list;
        List<Integer> list = new ArrayList<>();
        long hp = sc.nextLong();

        long count = 1;
        long at_count = 0;

        while(hp > 0){
            hp = hp/2;
            at_count += count;
            count = count*2;
        }
        System.out.println(at_count);
    
	}
}

Measured memory_bytes: 21844
#[allow(unused_imports)]
use std::cmp;
use std::io::Write;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    let s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

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

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

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

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

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

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

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

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

const INF: i64 = 1 << 60;

fn main() {
  let out = std::io::stdout();
  let mut out = std::io::BufWriter::new(out.lock());
  macro_rules! puts {
    ($($format:tt)*) => (write!(out,$($format)*).unwrap());
  }
  input! {
    n: usize,
    k: usize,
    hs: [i64; n],
  }
  let mut vs = hs.clone();
  vs.push(0);
  vs.sort();
  vs.dedup();
  let mut dp = vec![vec![vec![INF; vs.len()]; k + 1]; n + 1];
  for cc in 0 .. k + 1 {
    dp[0][cc][0] = 0;
  }
  for (i, &h) in hs.iter().enumerate() {
    for cc in 0 .. k + 1 {
      let mut acc = INF;
      for (j, &v) in vs.iter().enumerate() {
        acc = cmp::min(acc, dp[i][cc][j] - v);
        if v == h {
          dp[i+1][cc][j] = cmp::min(dp[i+1][cc][j], acc + v);
        } else if cc + 1 <= k {
          dp[i+1][cc+1][j] = cmp::min(dp[i+1][cc+1][j], acc + v);
        }
      }
      let mut acc = INF;
      for (j, &v) in vs.iter().enumerate().rev() {
        acc = cmp::min(acc, dp[i][cc][j]);
        if v == h {
          dp[i+1][cc][j] = cmp::min(dp[i+1][cc][j], acc);
        } else if cc + 1 <= k {
          dp[i+1][cc+1][j] = cmp::min(dp[i+1][cc+1][j], acc);
        }
      }
    }
  }

  let mut ans = INF;
  for cc in 0 .. k + 1 {
    for j in 0 .. vs.len() {
      ans = cmp::min(ans, dp[n][cc][j]);
    }
  }
  puts!("{}\n", ans);
}


Measured memory_bytes: 237820
N = int(input())
A = [int(_) for _ in input().split()]

def calc(A, y):
    result = abs(A[0] - y)
    t = y
    if t == 0:
        return 10**30
    for a in A[1:N]:
        tt = t + a
        if t * tt >= 0:
            m =  -t // abs(t)
            result += abs(m - tt)
            tt = m
        t = tt
    return result

result = min(calc(A, A[0]), calc(A, -1),  calc(A, +1))

print(result)


Measured memory_bytes: 14468
import sys
def input():
	return sys.stdin.readline()[:-1]
n = int(input())
seg = [list(map(int, input().split())) for _ in range(n)]
a = [x[0] for x in seg]
b = [x[1] for x in seg]
a.sort()
b.sort()

if n%2 == 1:
	print(b[n//2] - a[n//2] + 1)
else:
	print(b[n//2] - a[n//2] + b[n//2-1] - a[n//2-1] + 1)

Measured memory_bytes: 126020
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
const int MOD = 1E9 + 9;
const int INF = 1 << 29;

int main() {
  string S;
  cin >> S;
  int l = S.length() - 1;
  long ans = 0;
  for (int bit = 0; bit < (1 << l); ++bit) {
    vector<int> ix;
    for (int i = 0; i < l; ++i) {
      if (bit & (1 << i)) ix.push_back(i);
    }
    int begin = 0;
    for (int i = 0; i < ix.size(); ++i) {
      ans += stol(S.substr(begin, ix[i] + 1 - begin));
      begin = ix[i] + 1;
    }
    ans += stol(S.substr(begin));
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
// atcoder/abc158/A/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

int di[] = {0, 1, -1, 0, 1, -1, 1, -1};
int dj[] = {1, 0, 0, -1, 1, -1, -1, 1};
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  str s;
  while (cin >> s) {
    sort(s.begin(), s.end());
    cout << (s.front() == s.back() ? "No" : "Yes") << endl;
  }

  return 0;
}


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

int main() {
    // your code goes here
    ll a[5][5];
    bool c[5][5]={0},ok=false,memo;
    rep(i,1,3) rep(j,1,3) cin >> a[i][j];
    ll r;
    cin >> r;
    rep(q,1,r){
        ll b;
        cin >> b;
        rep(i,1,3) rep(j,1,3) if(a[i][j]==b) c[i][j]=true;
    }
    rep(i,1,3){
        memo=true;
        rep(j,1,3) if(!c[i][j]) memo=false;
        if(memo) ok=true;
    }
    rep(j,1,3){
        memo=true;
        rep(i,1,3) if(!c[i][j]) memo=false;
        if(memo) ok=true;
    }
    if(c[1][1]&&c[2][2]&&c[3][3]) ok=true;
    if(c[1][3]&&c[2][2]&&c[3][1]) ok=true;
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define INF INT_MAX
#define MAX_W 30
#define MAX_H 60
char field[MAX_H][MAX_W];

struct P
{
    int x,y,cost,w;
    bool operator >(const P &p) const{
        return cost>p.cost;
    }
};

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

int main() {
    int w, h;
    while(cin >> w >> h, w|h){
        fill_n((char *)field, MAX_W*MAX_H, 'X');

        priority_queue<P, vector<P>, greater<P> >que;

        REP(y,h)REP(x,w){
            cin >> field[y][x];
            if(field[y][x]=='S'){
                que.push({x, y, 0, 1});
                que.push({x, y, 0,-1});
            }
        }

        vvi GL(h, vi(w, INF));
        vvi GR(h, vi(w, INF));

        int res=-1;
        while(!que.empty()){
            P p=que.top(); que.pop();

            if(field[p.y][p.x]=='T'){
                res=p.cost;
                break;
            }

            REP(i, 9){
                int sx=p.x+dx[i]*p.w;
                int sy=p.y+dy[i];
                if(0<=sx&&sx<w&&0<=sy&&sy<h){
                    int cost=p.cost;
                    switch(field[sy][sx]){
                    case 'T':
                    case 'S':
                        break;
                    case 'X':
                        continue;
                    default:
                        cost+=field[sy][sx]-'0';
                        break;
                    }
                    bool t=true;
                    if(p.w>0&&GL[sy][sx]>cost){
                        GL[sy][sx]=cost;
                        t=false;
                    }else if(p.w<0&&GR[sy][sx]>cost){
                        GR[sy][sx]=cost;
                        t=false;
                    }
                    if(t)continue;
                    que.push({sx, sy, cost, -p.w});
                }
            }
        }

        cout << res << endl;
    }
}
 

Measured memory_bytes: 1252
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n;
string ans;
int main(){
	cin>>n;
	char c[27];for(char ch='a';ch<='z';ch++)c[ch-'a'+1]=ch;
	while(n){
		ll t=(n-1)%26ll+1ll;
		n=(n-1)/26ll;
		ans+=c[t];
	}
	int len=ans.length();
	for(int i=len-1;i>=0;i--)printf("%c",ans[i]);
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;

template <typename T>
ostream& operator <<(ostream& out, const vector<T>& vec) {
    out << "[";
    for (int x : vec) out << x << ", ";
    out << "]";
    return out;
}



void grida(string t){
    cout << "! " << t << endl;
    exit(0);
}

int cntask = 0;
int ask(string t){
    assert(cntask < 850);
    cntask++;
    cout << "? " << t << endl;
    int ans;
    cin >> ans;
    if(ans == 0) grida(t);
    return ans;
}


int nl;
vector<char> letters;
vector<int> quant(100, 0);

int len;

string solve(int l, int r){
    if(l == r){
        string s = "";
        char c = letters[l];
        for(int i=0; i<quant[l]; i++) s += c;
        return s;
    }else{
        string a = solve(l, (l+r)/2);
        string b = solve((l+r)/2+1, r);
        string c = "";
        unsigned int i=0, j=0;
        while(i < a.size() or j < b.size()){
            if(i == a.size()){
                c = c + b[j];
                j++;
            }else if(j == b.size()){
                c = c + a[i];
                i++;
            }else{
                string d = c + a[i] + b.substr(j);
                if(ask(d) > len - (int)d.size()){
                    c += b[j];
                    j++;
                }else{
                    c += a[i];
                    i++;
                }
            }
        }
        return c;
    }
}

int main() {
    //~ for(char c = 'a'; c<= 'c'; c++) letters.push_back(c);
    for(char c='0'; c<='9'; c++) letters.push_back(c);
    for(char c='a'; c<='z'; c++) letters.push_back(c);
    for(char c='A'; c<='Z'; c++) letters.push_back(c);
    srand ( unsigned ( std::time(0) ) );
    random_shuffle(letters.begin(), letters.end());
    
    nl = letters.size();
    
    len = 128;
    
    for(int i=0; i<nl; i++){
        string s = "";
        for(int j=0; j<len; j++) s += letters[i];
        quant[i] = len - ask(s);
    }
    len = 0;
    for(int i=0; i<nl; i++) len += quant[i];
    
    //~ cerr << letters << endl;
    //~ cerr << quant << endl;

    
    grida(solve(0, nl-1));
    
    return 0;
}


Measured memory_bytes: 3752
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<map>
using namespace std;

int main()
{
	long long int p = 0;
	long long int q = 0;
	long long int k;
	int flag = 0;
	int fin = 0;
	int head = 0;
	string s, t;

	cin >> s >> k;
	for (int i = 0;i < s.length();i++)
	{
		if (s[i] == s[0])
			head++;
		else
			break;
	}
	if (head == s.length())
	{
		cout << s.length() * k / 2;
		return 0;
	}
	for (int i = 0;i < s.length();)
	{
		if (s[i] != s[i + 1])
		{
			i++;
		}
		else if (s[i] == s[i + 1])
		{
			if (i + 1 == s.length() - 1)
				fin = 1;
			p++;
			i += 2;
		}

	}
	if (k > 1)
	{
		if (fin == 0 && s[0] == s[s.length() - 1])
		{
			t = s[s.length() - 1] + s;
			for (int i = 0;i < t.length();)
			{
				if (t[i] != t[i + 1])
				{
					i++;
				}
				else if (t[i] == t[i + 1])
				{
					q++;
					i += 2;
				}

			}
			flag = 1;
		}
		if (flag == 1)
			cout << p + q * (k - 1);
		else
			cout << p * k;
	}
	else
		cout << p * k;

	return 0;
}

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

#define ll long long
#define pb push_back
#define eb emplace_back
//#define st first
#define sc second

using namespace std;

const ll mod = 1e9 + 7;
const int e = 1e6 + 69;
const int base = 311;

// dung inverse module de tinh nCk
// beginer 82
// mbeginer 162
// cach tao hoan vi tu n so : n*(n+1)/2;

//vector<pair<ll,ll>>adj[e];
//vector<ll>adj[e];

/*ll Pow(ll n, ll dem)
{
    if(dem == 0) return 1;
    if(dem == 1) return n ;
    ll t = Pow(n, dem/2);
    if(dem % 2 == 0) return (t*t);
    else return ((t * t) * n);
}*/

/*ll C(ll k, ll n)
{
    if(k == 0) return 1;
    if(n < k) return 0;
    return (gt[n]%mod * (igt[k]%mod * igt[n-k]%mod)%mod)%mod;
}*/


int main()
{
    string s;
    cin >> s;
    ll minn = s.size();
    ll n = s.size();
    s = ' ' + s;
    for(ll i=1; i<n; i++)
    {
        if(s[i] != s[i+1])
        {
            minn = min(minn, max(n - i, i));
        }
    }
    cout << minn ;
}
/*

*/


Measured memory_bytes: 512
import sys
a=[0]*5
a[0]=int(input())
a[1]=int(input())
a[2]=int(input())
a[3]=int(input())
a[4]=int(input())
k=int(input())
for i in range(5):
  for j in range(i+1,5):
    if a[j]-a[i]>k :
      print(":(")
      sys.exit()
print("Yay!")

Measured memory_bytes: 9212