akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

char map[255][255];

int dire4[][2] = {
    {1, 0}, {-1, 1}, {0, 1}, {1, 1}, 
    //{-1, -1}, {0, -1}, {1, -1}, {-1, 0}
};

int main(){
    int n;
    while(1){
        cin >> n;
        if(n == 0) break;

        for(int y = 0;y < n;y++) {
            for(int x = 0;x < n;x++) {
                cin >> map[y][x];
            }
        }

        int ans = 0;
        for(int y = 0;y < n;y++) {
            for(int x = 0;x < n;x++) {
                for(int z = 0;z < 4;z++) {
                    int dx = dire4[z][0], dy = dire4[z][1];
                    int cx = x, cy = y, c = 0;
                    for(;map[cy][cx] == '1' && 0 <= cx && cx < n && 0 <= cy && cy < n;cx += dx, cy += dy, c++);
                    ans = max(ans, c);
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1224
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    ll q, h, s, d;
    cin >> q >> h >> s >> d;
    int n;
    cin >> n;
    ll num1 = min({q*8, h*4, s*2, d});
    ll num2 = min({q*4, h*2, s});
    ll ans;
    if ( n&1 ) {
        cout << num1 * ( n / 2 ) + num2 << endl;;
    }
    else {
        cout << num1 * ( n / 2 ) << endl;
    }
    return 0;
}


Measured memory_bytes: 256
package main

import (
  "fmt"
  "sort"
)

func main() {
  a := make([]int, 3)
  for i := 0; i < 3; i++ {
    fmt.Scan(&a[i])
  }
  sort.Ints(a)
  fmt.Println(a[0] * a[1] / 2)
}


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

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}

int main() {
	string s, t; cin >> s >> t;
	map<char, char> m, n;
	for(int i=0;i<int(t.size());i++){
		if(m.find(t[i])==m.end()){
			m[t[i]] = s[i];
		}else{
			if(m[t[i]]!=s[i]){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	for(int i=0;i<int(s.size());i++){
		if(n.find(s[i])==n.end()){
			n[s[i]] = t[i];
		}else{
			if(n[s[i]]!=t[i]){
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 776
#include <iostream>
#include <stdlib.h>
using namespace std;

int main() {
  int N;
  int A[100002];
  cin >> N;
  A[0] = 0;
  A[N + 1] = 0;
  for (int i = 1; i <= N; i++) {
    cin >> A[i];
  }
  long long int tot_cost;
  for (int i = 0; i <= N; i++) {
    tot_cost += abs(A[i] - A[i + 1]);
  }
  for (int i = 1; i <= N; i++) {
    long long int cost;
    cost = tot_cost - abs(A[i] - A[i - 1]) - abs(A[i] - A[i + 1])
     + abs(A[i - 1] - A[i + 1]);
     cout << cost << endl;
  }
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define pq priority_queue
#define mp make_pair
#define cauto const auto &

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#define clr(ar, val) memset(ar, val, sizeof(ar))

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

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

using namespace std;

typedef long long int64;
typedef long long lint;
typedef long long lli;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

int main() {
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;
    if(a+b>2*c){cout<<min(2*c*max(x,y),2*c*min(x,y)+a*(x-min(x,y))+b*(y-min(x,y)))<<endl;}
    else{cout<<a*x+b*y<<endl;}
    return 0;
}



Measured memory_bytes: 256
// finish date: 2018/01/11
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

#define bigmod 1000000007
using namespace std;

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

int mul(int a, int b) {
    return (int) (((ll) (a % bigmod) * (b % bigmod)) % bigmod);
}

int factorial(int n) {
    int ans = 1;
    FOR(i, 1, n + 1) {
        ans = ans * i;
    }
    return ans;
}

int tousa(int n) {
    return n * (n + 1) / 2;
}

int main() {
    int N, Z, W;
    cin >> N >> Z >> W;
    vector<int> a(N);
    rep(i, N) cin >> a[i];
    if(N==1) cout<<abs(a[a.size()-1]-W)<<endl;
    else cout << max(abs(a[a.size() - 1] - W), abs(a[a.size() - 2] - a[a.size() - 1])) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int i,j,v,n,u;
  scanf("%d",&n);
  int A[n];
  for(i=0;i<n;i++)
    {
      scanf("%d",&A[i]);
    }

  for(u=0;u<n;u++){
    if(u==n-1){
      printf("%d\n",A[u]);
    }
    else{
      printf("%d ",A[u]);
    }
  }

  // N個の要素を含む0-オリジンの配列A
  for(i=1;i<=n-1;i++)
    {
      v = A[i];
      j = i - 1;
      while(j >= 0 && A[j] > v)
        {
          A[j+1] = A[j];
          j--;
          A[j+1] = v;
        }
      for(u=0;u<n;u++){
             if(u==n-1){
                printf("%d\n",A[u]);
            }
            else{
                printf("%d ",A[u]);
            }   
        }
    }
    return 0;
}


Measured memory_bytes: 2036
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            // 解答はココに書く
            string s = cin.Read;
            int ans = 0;
            if (s[0] == '1') ans++;
            if (s[1] == '1') ans++;
            if (s[2] == '1') ans++;
            WriteLine(ans);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 11220
uses math;
var N,X,Y,i,j:Longint;
cnt:Array[1..2000]of Longint;
begin
read(N,X,Y);
for i:=1 to N do for j:=i+1 to N do inc(cnt[min(j-i,abs(X-i)+abs(Y-j)+1)]);
for i:=1 to N-1 do writeln(cnt[i]);
end.

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

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

	if (A + B >= A - B && A + B >= A * B)
	{
		cout << A + B;
	}

	else if (A - B >= A + B && A - B >= A * B)
	{
		cout << A - B;
	}

	else if (A * B >= A - B && A * B >= A + B)
	{
		cout << A * B;
	}

}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define MAX_N 100000
const int INF = 1e9;

int dp [MAX_N];

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

Measured memory_bytes: 1024
N=int(input())
A=map(int,input().split())
B=list(map(int,input().split()))
C=list(map(int,input().split()))
ANS=0
BC=-99
for a in A:
  if BC == a - 1:
    ANS += C[a-2]
  BC = a
  ANS += B[a - 1]
  #print(ANS, a-1, B[a-1])
#print('----')
print(ANS)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstring>
#include<vector>
 
using namespace std;
 
#define long long long
#define ft(i, a, b) for (long i = (long)a ; i <= (long)b ; i++)
#define fd(i, a, b) for (long i = (long)a ; i >= (long)b ; i--)
 
const int mxN = 1e5 + 5;
const long oo = 1e15;
const long MOD = 1e9 + 7;
const int base = 311;
 
string s;
 
void Solve() {
    if (s == "ABC") cout << "ARC";
    else cout << "ABC";
}
 
void FastInput() {
    ios_base::sync_with_stdio(NULL);
    cin.tie(NULL);
    cout.tie(NULL);
    //freopen(".inp", "r", stdin);
    //freopen(".out", "w", stdout);
}
 
void Input() {
    cin >> s;
}
 
int main() {
    FastInput();
    Input();
    Solve();
}

Measured memory_bytes: 3652
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
int main(void){
  string s;
  string s2="CODEFESTIVAL2016";
  int i;
  int res=0;
  cin>>s;

  for(i=0;i<16;i++){
    if(s[i]!=s2[i]) res++;
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 384
import sys

N = int(input())
H = list(map(int, input().split()))

for i in range(1, N):
    if H[i] + 1 == H[i-1]:
        H[i] += 1
    elif H[i] + 1 < H[i-1]:
        print("No")
        sys.exit()
        
print("Yes")

Measured memory_bytes: 14276
N = int(input())
S = input()

acc = 0
l = 0
for i in range(N):
    if S[i] == '(':
        acc += 1
    else:
        acc -= 1

    if acc == -1:
        l += 1
        acc += 1

L = '(' * l
R = ')' * acc
print (L + S + R)

Measured memory_bytes: 3060
#![allow(unused_mut, unused_macros, unused_variables, unused_assignments, non_snake_case)]

macro_rules! get {
    ($($s:tt : $t:ty),*) => {
        let stdin = std::io::stdin();
        let mut buf = String::new();
        stdin.read_line(&mut buf).unwrap();
        let mut iter = buf.split_whitespace();
        $(let $s:$t = iter.next().unwrap().parse().unwrap();)*
    };
}

macro_rules! get_v {
    ($s:tt : $t:ty) => {
        let stdin = std::io::stdin();
        let mut buf = String::new();
        stdin.read_line(&mut buf).unwrap();
        let iter = buf.split_whitespace();
        let $s:Vec<$t> = iter.map(|x| x.parse::<$t>().unwrap()).collect();
    };
}

macro_rules! get_vv {
    ($s:tt[$n:tt] : $t:ty) => {
        let mut t:Vec<$t> = Vec::new();

        let stdin = std::io::stdin();
        for _ in 0..$n {
            let mut buf = String::new();
            stdin.read_line(&mut buf).unwrap();
            t.push(buf.trim().parse().unwrap());
            //get_v!{a:usize}
            //t.push(a);
        }
        let $s = t;
    };
}


fn main() {
    get! {
        N : usize,
        M : usize
    }
    get_vv! {
        A[M]: usize
    }
    let MOD = 1_000_000_007;
    let mut steps = vec!(0; N + 1);
    for a in A {
        steps[a] = -1;
    }
    steps[0] = 1;
    for n in 1..N + 1 {
        if -1 == steps[n] {continue;}
        if -1 == steps[n - 1] && -1 == steps[n - 2] {
            println!("0");
            return;
        }
        if -1 != steps[n - 1] {
            steps[n] += steps[n - 1] % MOD;
        }
        if 1 < n && -1 != steps[n - 2] {
            steps[n] += steps[n - 2] % MOD;
        }
    }
    println!("{:?}", steps[N] % MOD);
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    multiset<ll> s;
    rep(i,n){
        ll a; cin>>a;
        if (s.empty()){
            s.ins(a);
            continue;
        }
        auto itr = s.lower_bound(a);
        if (itr==s.begin()) s.ins(a);
        else{
            s.erase(--itr);
            s.ins(a);
        }
    }
    cout<<s.size()<<endl;
    return 0;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;

void solve(long long N, std::vector<long long> A, std::vector<long long> B){
    sort(A.begin(),A.end());
    sort(B.begin(),B.end());
    if(N%2==1){
        cout << (B[N/2]) -(A[N/2])+ 1 << endl;
        return;
    }else{
        P b = make_pair(A[N/2],B[N/2]);
        P a = make_pair(A[(N/2)-1],B[(N/2)-1]);
        cout << b.second+a.second-a.first-b.first+1<<endl;
    }

}

// Generated by 1.1.7.1 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);
    std::vector<long long> A(N);
    std::vector<long long> B(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
        scanf("%lld",&B[i]);
    }
    solve(N, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 6336
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <cstring>
 
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define MP make_pair
#define X first
#define Y second
 
using namespace std;
 
typedef vector<int> vi;
typedef pair<int, int> P;

const int INF = 1<<29;

int field[100][100];
int visit[100][100];

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

int w, h;
int dfs(int x, int y){
	int res = 0;
	rep(i, 4){
		int nx = x+dx[i], ny = y+dy[i];
		if(nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
		if(!field[ny][nx]) continue;
		if(visit[ny][nx]) continue;
		visit[ny][nx] = 1;
		res = max(res, dfs(nx, ny));
		visit[ny][nx] = 0;
	}

	return res+1;
}

int main(){
	while(cin >> w >> h, w|h){
		rep(i, h) rep(j, w) cin >> field[i][j];
		int ans = 0;
		rep(i, h) rep(j, w){
			if(field[i][j]){
				memset(visit, 0, sizeof(visit));
				visit[i][j] = 1;
				ans = max(ans, dfs(j, i));
			}
		}
		cout << ans << endl;
	}
 
    return 0;
}

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

// syntax sugar: `for (int i = 0; i < N; ++i)`
#define rep(i, N) for (int i = 0; i < (int)(N); ++i)
// syntax sugar: `for (int i = 0; i < N; ++i)`
#define REP(type, name, beginValue, endCondValue) \
  for (type name = beginValue; name < endCondValue; ++name)
// syntax sugar: 多次元vector
#define VECTOR_DIM3(T, name, d1, d2, d3, initValue) \
    std::vector<std::vector<std::vector<T>>> name(d1, std::vector<std::vector<T>>(d2, std::vector<int>(d3, initValue)));
#define VECTOR_DIM2(T, name, d1, d2, initValue) \
    std::vector<std::vector<T>> name(d1, std::vector<T>(d2, initValue));
#define VECTOR_DIM1(T, name, d1, initValue) \
    std::vector<T> name(d1, initValue);
#define ll long long
#define ld long double


// AGC010A - Addition
int main(){
  int N, a; // 2 <= N <= 1e5
  cin >> N;
  int even = 0, odd = 0; // 偶数、奇数
  rep(i, N) {
    cin >> a;
    if (a % 2 == 0) {
      ++even;
    } else {
      ++odd;
    }
  }
  bool can = true;
  if (odd % 2 == 1) {
    // 奇数がき数個あると不可能
    can = false;
  } else {
    even += odd / 2;
  }

  cout << (can ? "YES" : "NO") << endl;
  return 0;
}



Measured memory_bytes: 256
'''
Pythonの知っておくと良い細かい処理速度の違い8個
https://www.kumilog.net/entry/python-speed-comp
'''

# sys.stdin.readline()
import sys
input = sys.stdin.readline

n = int(input())

csum = [0]#0を入れておくとcsum[i] = iまでの総和になる
i = 1
b = 0
while b < n:
    b += i
    csum.append(b)
    i += 1

while n > 0:
    for i in range(n + 1):
        if csum[i] >= n:
            print(i)
            n -= i
            break

Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,-1,1,1,-1};
int dy[]={0,1,0,-1,-1,-1,1,1};


int main(){
    int n;cin >> n;
    LL ans = 0;
    for (LL i = 1; i <= n; i++) {
        ans += i * (i + 1) / 2;
    }
    for (int i = 0; i < n - 1; i++) {
        LL u,v;cin >> u >> v;
        if(u > v) swap(u, v);
        v--;
        ans -= u * (n - v);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define INF (1LL << 60)
#define int long long
#define magic 100000
using namespace std;

// no directed cycle -> can be sorted

int dp[100000];
vector<vector<int>> graph(100000);

bool visited[100000];
vector<int> tps;

void dfs(int st){
	visited[st] = 1;
	for(auto i : graph[st]){
		if(visited[i])
			continue;
		dfs(i);
	}
	tps.push_back(st);
}

int32_t main(){
	int n, m;
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int v1, v2;
		cin >> v1 >> v2;
		v1--; v2--;
		graph[v1].push_back(v2);
	}
	for(int i = 0; i < n; i++){
		if(!visited[i]){
			dfs(i);
		}
	}
	// i < j ==> No tps[i] -> tps[j]
	dp[tps[0]] = 0;
	for(int i = 1; i < n; i++){
		for(auto j : graph[tps[i]]){
			dp[tps[i]] = max(dp[tps[i]], dp[j] + 1);
		}
	}
	int _max = 0;
	for(int i = 0; i < n; i++){
		_max = max(_max, dp[i]);
	}
	cout << _max;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------


int ok[1010101];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	ok[0]=1;
	FOR(i,101010) if(ok[i]) {
		ok[i+100]=1;
		ok[i+101]=1;
		ok[i+102]=1;
		ok[i+103]=1;
		ok[i+104]=1;
		ok[i+105]=1;
	}
	
	cin>>x;
	cout<<ok[x]<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 640
import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Char8 as B

import           Control.Monad.ST
import           Data.Array.IArray
import           Data.Array.MArray
import           Data.Array.ST
import           Data.List
import           Data.STRef

readi :: B.ByteString -> Int
readi b | Just (n, _) <- B.readInt b = n

solve :: Array Int [Int] -> [Int]
solve graph = runST $ do
    prenum <- newArray (0, v) (-1)
    parent <- newArray (0, v) (-1)
    lowest <- newArray (0, v) (-1)
    visited <- newArray (0, v) False
    timer <- newSTRef 1
    dfs graph prenum parent lowest visited timer 0 (-1)

    np <- newSTRef 0
    ret <- newSTRef []
    forM_ [1 .. v] $ \i -> do
        p <- readArray parent i
        if p == 0
            then modifySTRef' np (+ 1)
            else do
                pp <- readArray prenum p
                li <- readArray lowest i
                when (pp <= li) $ modifySTRef' ret (p :)

    npv <- readSTRef np
    when (npv > 1) $ modifySTRef' ret (0 :)

    readSTRef ret
  where
    (_, v) = bounds graph

dfs :: Array Int [Int]
    -> STUArray s Int Int
    -> STUArray s Int Int
    -> STUArray s Int Int
    -> STUArray s Int Bool
    -> STRef s Int
    -> Int
    -> Int
    -> ST s ()
dfs graph prenum parent lowest visited timer current prev = do
    t <- readSTRef timer
    modifySTRef' timer (+ 1)
    writeArray prenum current t
    writeArray lowest current t

    writeArray visited current True

    forM_ (graph ! current) $ \next -> do
        isVisited <- readArray visited next
        case () of
            _ | not isVisited -> do
                writeArray parent next current
                dfs graph prenum parent lowest visited timer next current
                lc <- readArray lowest current
                ln <- readArray lowest next
                writeArray lowest current (min lc ln)
              | next /= prev -> do
                lc <- readArray lowest current
                ln <- readArray prenum next
                writeArray lowest current (min lc ln)
              | otherwise -> return ()

main :: IO ()
main = do
    [v, e] <- fmap readi . B.words <$> B.getLine
    xs <- fmap concat . replicateM e $ do
        [a, b] <- fmap readi . B.words <$> B.getLine
        return [(a, b), (b, a)]
    let graph = accumArray (flip (:)) [] (0, v-1) xs
    mapM_ print (sort . nub $ solve graph)



Measured memory_bytes: 33304
n=int(input())
s=input()
r=input()
t=s+r
f=0
for i in range(n):
    if(s[i:]==r[:n-i]):
        t=s[:i]+r
        f=1
        break
if(f==1):
    print(len(t))
else:
    print(2*n)


Measured memory_bytes: 61740
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mp(x,y)     make_pair(x,y) 
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,a,n)   for(ll i=a;i<n;i++)
#define frr(i,a,n)  for(ll i=n-1;i>=a;i--)


const ll N   =  500005;
const ll mod = 1e9 + 7;

using namespace std;


void solve()
{
// string s;
  ll a,b,d,x=0,y=0,c=0,q,ans=0,k;
  cin>>a>>b>>c>>d;
  x = (b)/c  - (a-1)/c;
  y=  b/d  - (a-1)/d;
  q =(c*d)/ __gcd(c,d);
  k = b/q - (a-1)/q;
ans  = b - a+ 1 -  (x+y -k);

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

signed main(){

      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      ll T=1;
      //cin>>T;
      while(T--)
      {
      solve();
      }
      return 0;
    }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,a[1000011],sum;
long long read()
{
	long long ans=0;
	char last=' ',ch=getchar();
	while(ch<'0'||ch>'9')last=ch,ch=getchar();
	while(ch>='0'&&ch<='9')ans=ans*10+ch-'0',ch=getchar();
	if(last=='-')ans=-ans;
	return ans;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		sum^=a[i]=read();
	for(int i=1;i<=n;i++)
		cout<<(sum^a[i])<<" ";
}

Measured memory_bytes: 4288
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<(int)(n);i++)
#define N 200000

int main() {
	vector<int>a;
	vector<int>b;
	int n, k;
	int x, y, z;
	int s, ans;
	scanf("%d %d", &n, &k);
	z = (n - 1)*(n - 2);
	z = z / 2;
	if (k > z) {
		printf("-1\n");
		return 0;
	}
	f(i, n - 1) {
		a.push_back(1);
		b.push_back(i + 2);
	}
	k = z - k;
	for(int i=2;i<=n;i++){
		for (int j = i + 1; j <= n; j++) {
			if (k > 0) {
				a.push_back(i);
				b.push_back(j);
				k--;
			}
		}
	}
	printf("%d\n", a.size());
	f(i, a.size()) {
		printf("%d %d\n", a[i], b[i]);
	}

	return 0;
}


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

int main()
{
    string a,b,c,d,f,g;
    cin>>a>>b>>c;
    d = a[0] - 32;
    f = b[0] - 32;
    g = c[0] - 32;
    cout<<d<<f<<g<<endl;

    return 0;
}


Measured memory_bytes: 256
import sys


def solve(inp):
    (N, M) = map(int, inp.readline().strip().split(' '))
    PS = [inp.readline().strip().split(' ') for i in range(M)]

    total_penalty = 0
    total_ac = 0
    pena = {}
    ac = {}
    for (P, S) in PS:
        P = int(P) - 1
        if S == "WA":
            if P not in pena:
                pena[P] = 0
            pena[P] += 1
        elif S == "AC":
            if P not in ac:
                total_ac += 1
                ac[P] = 1
                if P in pena:
                    total_penalty += pena[P]
    return "{} {}".format(total_ac, total_penalty)


def main():
    result = solve(sys.stdin)
    if result:
        print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 44300
N,M = map(int,input().split())
A = [[0 for j in range(N)] for i in range(N)]
for i in range(M):
    a,b = map(int,input().split())
    A[a-1][b-1]=1
    A[b-1][a-1]=1
flag = True
ans = 0
while(flag):
    flag = False
    for i in range(N):
        if A[i].count(1) == 1:
            flag = True
            ans += 1
            j = A[i].index(1)
            A[i][j] = 0
            A[j][i] = 0
print(ans)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int max=0;
		int a=Integer.parseInt(scan.next()); max=Math.max(max, a);
		int b=Integer.parseInt(scan.next()); max=Math.max(max, b);
		int c=Integer.parseInt(scan.next()); max=Math.max(max, c);

		int ans=0;
		while ((a+b+c)+2*ans<max*3 || ((a+b+c)+2*ans)%3!=0)++ans;

		System.out.print(ans);


	}
}
//end

Measured memory_bytes: 23764
// Created by Nandu Vinodan
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN
#define TC 0

using namespace std;
using ll = long long;

void testcase() {
    int n; cin >> n;
    map <string, int> mp;

    while (n--) {
    	string s; cin >> s;
    	mp[s]++;
    }

    vector<pair<int, string> >  v;
    for (auto it = mp.begin(); it != mp.end(); it++) {
    	v.push_back({it->second, it->first});
    }

    sort(v.begin(), v.end());
    int m = v.size();
    int val = v[m-1].first;
    int j = m-1;
    vector<string> res;
    while (j >= 0 && v[j].first == val) {
    	res.push_back(v[j].second);
    	j--;
    }
    sort(res.begin(), res.end());
    for (string s : res) cout << s << "\n";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    if (TC)
        cin>>t;
    while(t--) {
        testcase();
    }
    return 0;
}

Measured memory_bytes: 31340
/// sultanov

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
     
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
 
using namespace std;
using namespace __gnu_pbds;

template<typename T> 
using ordered_set = tree<T, null_type,   
less<T>, rb_tree_tag,
tree_order_statistics_node_update>;

using ll = long long;
using pii = pair<int, int>;                                   

const int INF32 = INT_MAX;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<int> a(--n);
    for (int& x : a)
        cin >> x;
    ll sum = a.front() + a.back();
    for (int i = 0; i < n - 1; i++) 
        sum += min(a[i], a[i + 1]);
    cout << sum;
    return false;                                                       
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#include <chrono>
using namespace std;
 
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;
 
//container util
//------------------------------------------
#define PB emplace_back
#define MP make_pair 
#define SZ(a) int((a).size())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define ALL(a)  (a).begin(),(a).end()
//constant
//--------------------------------------------
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

vector<int>G[(int)1e5+3];
int used[(int)1e5+3];
int main(){
    int N,M;
    cin>>N>>M;
    REP(i,N)used[i]=-1;
    REP(i,M){
        int A,B;
        cin>>A>>B;
        A--;B--;
        G[A].PB(B);
        G[B].PB(A);
    }
    queue<int>pos;
    pos.push(0);
    used[0]=0;
    while(!pos.empty()){
        int now=pos.front();pos.pop();
        REP(i,SZ(G[now])){
            int next=G[now][i];
            if(used[next]==-1){
                used[next]=now;
                pos.push(next);
            }
        }
    }
    bool flag=true;
    REP(i,N)if(used[i]==-1)flag=false;
    if(!flag){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
        FOR(i,1,N){
            cout<<used[i]+1<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 10408
import numpy as numpy 
import bisect as bisect
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
a.insert(0,0)
ali = numpy.cumsum(a)
bli = numpy.cumsum(list(map(int,input().split())))
a = [0]
for i in range(n+1):
    if ali[i] > k:
        break
    b = bisect.bisect_right(bli,k-ali[i])
    a.append(i+b)
print(max(a))

Measured memory_bytes: 61704
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
char s[303][303];
int cnt[303][303];
bool dp[2][303][303];
int n;
void calc(int x,int y)
{
	cnt[x][y]=0;
	for(int i=0;i<n;i++)
		if(s[x][(y+i)%n]==s[(x+i)%n][y])
			cnt[x][y]++;
		else
			break;
}
int main()
{
	scanf("%d",&n);
	for(int i=0;i<n;i++)
		scanf("%s",s[i]);
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			calc(i,j);
	int now=0,to=1;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			dp[now][i][j]=true;
	for(int t=2;t<=n;t++)
	{
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				if(dp[now][(i+1)%n][(j+1)%n]&&cnt[i][j]>=t)
					dp[to][i][j]=true;
		for(int i=0;i<n;i++)
			for(int j=0;j<n;j++)
				dp[now][i][j]=false;
		swap(now,to);
	}
	int ans=0;
	for(int i=0;i<n;i++)
		for(int j=0;j<n;j++)
			ans+=dp[now][i][j];
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
vi seg;
ll N;
void init(ll n){
    N=1;
    while(N<n)N*=2;
    seg=vi(N*2-1,-inf);
}
void update(ll i,ll x){
    i=N+i-1;
    seg[i]=x;
    while(i>0){
        i=(i-1)/2;
        seg[i]=max(seg[i*2+1],seg[i*2+2]);
    }
}
ll getma(ll a,ll b,ll k,ll l,ll r){
    if(r<=a||b<=l)return -inf;
    if(a<=l&&r<=b)return seg[k];
    ll c1=getma(a,b,k*2+1,l,(l+r)/2);
    ll c2=getma(a,b,k*2+2,(l+r)/2,r);
    return max(c1,c2);
}
int main(){
    ll n;cin>>n;
    vi h(n),v(n);
    init(n);
    rep(i,n)cin>>h[i];
    rep(i,n)cin>>v[i];
    vp a(n);
    rep(i,n)a[i]=P(h[i],i);
    sort(all(a));
    rep(i,n){
        ll x=a[i].se;
        update(x,max(0ll,getma(0,x,0,0,N))+v[x]);
    }
    ll ans=0;
    rep(i,n)chmax(ans,seg[i+N-1]);
    out(ans);
}

Measured memory_bytes: 10624
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

signed main() {
  ll A, B;
  cin >> A >> B;
  if (A - B * 2 < 0) {
    COUT(0);
  } else {
    COUT(A - B * 2);
  }
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(x) for x in input().split()]
p = 10 ** 9 + 7

ans = 0
sq = 0
twoinv = pow(2, p - 2, p)

for i in range(n):
    ans += a[i]
    ans %= p
    sq += a[i] * a[i]
    sq %= p

ans = (ans * ans % p - sq) * twoinv % p
print(ans)

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

using namespace std;

int main(void){
    int an, bn, m;

    cin >> an >> bn >> m;
    int a_min, b_min, c_min;
    a_min = b_min = c_min = 1000000;

    vector<int> a(an), b(an);
    for (int i = 0; i < an; i++) {
        cin >> a[i];
        if (a_min > a[i]) {
            a_min = a[i];
        }
    }
    for (int i = 0; i < bn; i++) {
        cin >> b[i];
        if (b_min > b[i]) {
            b_min = b[i];
        }
    }
    for (int i = 0; i < m; i++) {
        int x, y, c;
        cin >> x >> y >> c;
        int p = a[x-1] + b[y-1] - c;
        if (c_min > p) {
            c_min = p;
        }
    }

    if (c_min < a_min + b_min) {
        cout << c_min << endl;
    } else {
        cout << a_min + b_min << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1024
import math
import sys


def input():
    return sys.stdin.readline()[:-1]

# N = int(input())
# A = [int(x) for x in input().split()]
# a, b, c = map(int, input().split())
# name1 = str(input())
# alph = {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}


x = int(input())
a = int(input())
b = int(input())

print((x-a) % b)


Measured memory_bytes: 2940
// https://atcoder.jp/contests/abc150/tasks/abc150_c
#include <bits/stdc++.h>

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}


int main()
{
	int n;
	cin>>n;
	vector<int> p(n),q(n);
	rep(i,n)cin>>p[i];
	rep(i,n)cin>>q[i];

	vector<int> num(n);
	iota(all(num),1);

	int a=0,b=0,cnt=0;
	do{
		if(p==num)a=cnt;
		if(q==num)b=cnt;
		cnt++;
	}while(next_permutation(all(num)));
	cout<<abs(a-b)<<endl;
	return 0;
}

Measured memory_bytes: 3620
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
  // "math"
)

// 行単位で読み込む場合
var sc = bufio.NewScanner(os.Stdin)

func main() {
  sc.Scan()
  A, _ := strconv.Atoi((strings.Split(sc.Text(), " "))[0])
  B, _ := strconv.Atoi((strings.Split(sc.Text(), " "))[1])

  count := 0

  for i := A; i <= B; i++ {
    num := strconv.Itoa(i)
    if num[0] == num[4] && num[1] == num[3] {
      count++
    }
  }

  fmt.Println(count)
}

Measured memory_bytes: 1152
#include <iostream>
#include <math.h>
//#include <numeric>
#include <vector>
//#include <map>
#include <algorithm>
//#include <queue>

using namespace std;
#define n_max 10000
#define INF 10001000

#define rep(i, a, n) for(int i = a; i < n; i++)
#define rep2(i, a, n) for(int i = a; i <= n; i++)
#define rrep(i, a, n) for(int i = a; i > n; i--)
#define rrep2(i, a, n) for(int i = a; i >= n; i--)
#define lrep(i, a, n) for(long int i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl

int main()
{
    unsigned int N, K, Q;
    cin >> N >> K >> Q;
    int A[N] = {0};

    rep(i, 0, Q) { 
        int tmp;
        cin >> tmp; 
        A[tmp-1]++;
    }

    rep(i, 0, N) { 
        if((Q - A[i]) >= K) { cout << "No" << endl; }
        else { cout << "Yes" << endl; } 
    }

    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define DEBUG(x) cout << (#x) << ": " << (x) << endl
#define DEBUG_VEC(v)            \
    cerr << #v << ": ";         \
    REP(__i, (v).size())        \
    cerr << ((v)[__i]) << ", "; \
    cerr << endl

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

int main()
{
    ios::sync_with_stdio(false);
    int A, B;
    cin >> A >> B;

    int res;
    if (A == B) {
        res = A + A;
    } else {
        A = max(A, B);
        res = A + A - 1;
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

int main()
{
    long long N;
    cin >> N;
    vector<char> name(100000);
    int count = 0;
    while (true)
    {
        if(N%26 != 0){
            name[count] = char((N % 26) + 96);
        }else{
            name[count] = 'z';
        }
        N = (N-1)/26;
        if (N == 0)
        {
            break;
        }
        count++;
    }
    for (int i = count; i >= 0; i--){
        cout << name[i];
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3720
gets
s = gets.split.map(&:to_i)

swap_count = 0
s.size.times do |i|
	mini = i
	(i + 1).upto(s.size - 1) do |j|
		mini = j if s[j] < s[mini]
	end

	if i != mini
		s[i], s[mini] = s[mini], s[i]
		swap_count += 1
	end
end

puts s.join(' ')
puts swap_count



Measured memory_bytes: 8884
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

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

func main() {
	defer stdout.Flush()
	n := readInt()
	k := readInt()
	a := readIntSlice(n)
	g := a[0]
	for i := range a {
		g = gcd(g, a[i])
	}

	for i := range a {
		if a[i] == k {
			println("POSSIBLE")
			return
		}
		if k < a[i] && (a[i]-k)%g == 0 {
			println("POSSIBLE")
			return
		}
	}
	println("IMPOSSIBLE")
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

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


Measured memory_bytes: 3072
#include <stdio.h>

int main(void){
  int n,p1,p2,p3,c;
  c=0;
  scanf("%d %d %d",&n,&p1,&p2);

  n-=2;
  
  while(n>0){
    scanf("%d",&p3);
    if((p1<p2&&p2<p3)||(p1>p2&&p2>p3))
      c++;
    p1=p2;
    p2=p3;
    n--;
  }

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

  return 0;
}
	 


Measured memory_bytes: 128
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
bool is_ok(double x, double y, double d){

    double ans = sqrt(x*x + y*y);

    if(ans<=d)
        return true;
    return false;

}
int main() {
    int n, a, b, ans=0, d;
    cin >> n >> d;
    for(int i=0;i<n;i++){
        
        cin >> a>> b;
        
        if(is_ok(a,b,d)) ans ++;
    
    }
    cout << ans;
	return 0;
}

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


int main()
{
	long long N, D, K, R = 1, M = 1e9 + 7, c[1001] = {};
	cin >> N;
	while (N)
	{
		D = N;
		for (int i = 2; D != 1; i++)
		{
			while (D % i == 0)
			{
				c[i]++;
				D /= i;
			}
		}
		N--;
	}
	for (int i = 0; i < 1001; i++)
	{
		if (c[i] != 0)
		{
			R = (R * (c[i] + 1)) % M;
		}
	}
	cout << R << '\n';
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define dbl double
#define pi acos(-1)
#define sc1(a) scanf("%lld",&a)
#define sc2(a,b) scanf("%lld%lld",&a,&b)
#define sc3(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define pb push_back

ll ara[1000005][10];

map<ll,ll>vis;
map<ll,ll>vis1;
map<ll,ll>pos;
map<ll,ll>high;
map<ll,ll>low;
map<string,ll>mp;
vector<ll>vec;
//vector<ll>v;
stack<ll>q;
string str1[100];
string str2[100];
priority_queue<ll>pq;
ll dp[105][100005],t,k,wt;
ll mn=1000000;
ll w[100005];
ll v[100005];

ll call(ll id,ll wet)
{
    if(dp[id][wet]!=-1)
        return dp[id][wet];
    if(id==t+1)
        return 0;
    ll p=0,q;
    if(wet+w[id]<=wt)
    {
        p=v[id]+call(id+1,wet+w[id]);
        q=call(id+1,wet);
        return dp[id][wet]=max(p,q);

    }
    else
    {
        return call(id+1,wet);
    }
    return dp[id][wet];
}
int main()
{

    // ll t;
    memset(dp,-1,sizeof(dp));
    sc2(t,wt);
    ll k=0;
    for(ll i=1; i<=t; i++)
    {
        sc2(w[i],v[i]);
    }
    cout<<call(1,0)<<endl;
    return 0;
}


Measured memory_bytes: 82688
#include<bits/stdc++.h>
using namespace std;
typedef long long int64;
const string temp = "+-*";

string S;
int level[256];

bool inc(int depth, char c)
{
  return(temp.find(c) != string::npos && level[c] == depth);
}

int64 F(int& idx, int depth)
{
  int64 val;
  if(depth == 3) {
    if(isdigit(S[idx])) {
      val = 0;
      while(idx < S.size() && isdigit(S[idx])) {
        val = val * 10 + S[idx++] - '0';
      }
    } else {
      ++idx;
      val = F(idx, 0);
      ++idx;
    }
  } else {
    val = F(idx, depth + 1);
    while(idx < S.size() && inc(depth, S[idx])) {
      char op = S[idx++];
      int64 y = F(idx, depth + 1);
      if(op == '+') val += y;
      else if(op == '-') val -= y;
      else val *= y;
    }
  }
  return(val);
}


int main()
{ 
  cin >> S;
  int64 ret = LLONG_MIN;
  for(int& i = level['+'] = 0; i < 3; i++) {
    for(int& j = level['-'] = 0; j < 3; j++) {
      for(int& k = level['*'] = 0; k < 3; k++) {
        int idx = 0;
        ret = max(ret, F(idx, 0));
      }
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
#define fi first
#define se second
const ll inf = 9e18;
const ll mod = 1e9 + 7;

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y, ll M = inf){
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2, mod);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

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

	ll a, b;
	cin>>a>>b;
	ll ans=0;
	if(a <= 5){
		ans=0;
	}
	else if(a>=13){
		ans = b;
	}
	else if(a>=6 && a<=12)ans=b/2;
	
	cout<<ans<<"\n";
	return 0;
}


Measured memory_bytes: 256