akhauriyash/Code-Regression huggingface dataset:
use std::cmp;
use std::collections::HashMap;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iterator = buf.split_whitespace();

    let s: String = iterator.next().unwrap().to_string();

    let q: usize = iterator.next().unwrap().parse().unwrap();

    let mut ans_vec: VecDeque<char> = s.chars().collect();

    let mut reverse: bool = false;
    for i in 0..q {
        let q_type: usize = iterator.next().unwrap().parse().unwrap();
        match q_type {
            1 => {
                reverse = !reverse;
            }
            2 => {
                let f: usize = iterator.next().unwrap().parse().unwrap();
                let c: char = iterator.next().unwrap().chars().next().unwrap();

                match f {
                    1 => {
                        if reverse {
                            ans_vec.push_back(c);
                        } else {
                            ans_vec.push_front(c);
                        }
                    }
                    2 => {
                        if reverse {
                            ans_vec.push_front(c);
                        } else {
                            ans_vec.push_back(c);
                        }
                    }
                    _ => {}
                }
            }
            _ => {}
        }
    }

    let ans: String = if reverse {
        ans_vec.into_iter().rev().collect()
    } else {
        ans_vec.into_iter().collect()
    };

    println!("{}", ans);
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


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

int a,b,c,d,sum=0;
int main(){
	cin>>a>>b>>c>>d;
	if(b<=a)
		sum+=b;
	else
		sum+=a;
	if(d<=c)
		sum+=d;
	else
		sum+=c;
	cout<<sum;
	return 0;
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll N;
vector<ll> A;
map<ll,ll> cnt;
vector<P> ps;

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

  cin>>N;
  A.resize(N);
  rep(i,N)cin>>A[i];
  reverse(all(A));
  rep(i,N){
    cnt[A[i]]++;
    if(cnt[A[i]]>3){
      cout<<0<<endl;
      return 0;
    }
    ps.push_back(P(A[i],i));
  }
  sort(all(ps));
  ll res=1;
  rep(i,ps[N-1].fi){
    vector<ll> id0,id1;
    ll idx0=lower_bound(all(ps),P(i,-1))-ps.begin();
    ll idx1=lower_bound(all(ps),P(i+1,-1))-ps.begin();
    while(idx0<N&&ps[idx0].fi==i) {
      id0.push_back(ps[idx0].se);
      idx0++;
    }
    while(idx1<N&&ps[idx1].fi==i+1) {
      id1.push_back(ps[idx1].se);
      idx1++;
    }
    if(id0.size()==0||id1.size()==0||id0.size()<id1.size()){
      cout<<0<<endl;
      return 0;
    }
    sort(all(id0));
    sort(all(id1));

    set<vector<ll>> st;
    do{
      bool ok=true;
      rep(k,id1.size()){
        if(id0[k]<id1[k])ok=false;
      }
      if(ok){
        vector<ll> tmp;
        rep(k,id1.size())tmp.push_back(id0[k]);
        st.insert(tmp);
      }
    }while(next_permutation(all(id0)));
    ll cnts=st.size();
    (res*=cnts)%=mod;
  }
  if(cnt[ps[0].fi]==1) cout<<res*3%mod<<endl;
  else cout<<res*6%mod<<endl;

  return 0;
}


Measured memory_bytes: 8816
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;



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

  string s;
  cin >> s;
  vector<string> date = {"SUN","MON","TUE","WED","THU","FRI","SAT"};

  ll ans = distance(find(date.begin(), date.end(), s), date.end());
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1LL << 60;

void Main(){
    long long K, A, B;
    scanf("%lld%lld%lld", &K, &A, &B);
    double rate = (B - A) / 2;
    long long ans = 1;
    if(rate <= 1 || K <= A)ans += K;
    else{
        K -= (A - 1);
        ans = A;
        if(K % 2 == 1){
            ans += (B - A) * ((K - 1) / 2);
            ans++;
        }else{
            ans += (B - A) * (K / 2);
        }
    }  
    printf("%lld\n", ans);
    return;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    
}

//48518828842807432
//48518828981938099

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(void)
{
	int S, S1, S2, S3;
	cin >> S;
	S1 = S / 100;
	S2 = (S - (S1 * 100)) / 10;
	S3 = S - (S1 * 100) - (S2 * 10);
	cout << S1 + S2 + S3 << endl;
}

Measured memory_bytes: 3608
import std;

alias sread = () => readln.chomp();
alias lread = () => readln.chomp.to!long();
alias aryread(T = long) = () => readln.split.to!(T[]);

void main()
{
    auto n = lread();
    if (n % 2 == 0)
    {
        writeln((n / 2) - 1);
    }
    else
    {
        writeln((n - 1) / 2);
    }
}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}


Measured memory_bytes: 3696
#include <stdio.h>
struct dice{
    int d[6], tmp[6];
};
struct dice dice1;
struct dice dice2;
struct dice dice3[110];
void copy1(int a){
    int i;
    for (i=0;i<6;i++){
        dice3[a].d[i]=dice2.d[i];
        dice3[a].tmp[i]=dice2.tmp[i];
    }
}
void copy2(int a){
    int i;
    for (i=0;i<6;i++){
        dice2.d[i]=dice3[a].d[i];
        dice2.tmp[i]=dice3[a].tmp[i];
    }
}
void init1(int n[6]){
    int i;
    for (i=0;i<6;i++){
        dice1.d[i]=n[i];
    }
}
void init2(int n[6]){
    int i;
    for (i=0;i<6;i++){
        dice2.d[i]=n[i];
    }
}
void throwdice(char c){
    int i;
    for(i=0;i<6;i++){
        dice1.tmp[i]=dice1.d[i];
    }
    if(c=='N'){
        dice1.d[0]=dice1.tmp[1];
        dice1.d[1]=dice1.tmp[5];
        dice1.d[2]=dice1.tmp[2];
        dice1.d[3]=dice1.tmp[3];
        dice1.d[4]=dice1.tmp[0];
        dice1.d[5]=dice1.tmp[4];
    }
    else if(c=='E'){
        dice1.d[0]=dice1.tmp[3];
        dice1.d[1]=dice1.tmp[1];
        dice1.d[2]=dice1.tmp[0];
        dice1.d[3]=dice1.tmp[5];
        dice1.d[4]=dice1.tmp[4];
        dice1.d[5]=dice1.tmp[2];
    }
    else if(c=='W'){
        dice1.d[0]=dice1.tmp[2];
        dice1.d[1]=dice1.tmp[1];
        dice1.d[2]=dice1.tmp[5];
        dice1.d[3]=dice1.tmp[0];
        dice1.d[4]=dice1.tmp[4];
        dice1.d[5]=dice1.tmp[3];
    }
    else if(c=='S'){
        dice1.d[0]=dice1.tmp[4];
        dice1.d[1]=dice1.tmp[0];
        dice1.d[2]=dice1.tmp[2];
        dice1.d[3]=dice1.tmp[3];
        dice1.d[4]=dice1.tmp[5];
        dice1.d[5]=dice1.tmp[1];
    }
    else if(c=='R'){
        dice1.d[0]=dice1.tmp[0];
        dice1.d[1]=dice1.tmp[3];
        dice1.d[2]=dice1.tmp[1];
        dice1.d[3]=dice1.tmp[4];
        dice1.d[4]=dice1.tmp[2];
        dice1.d[5]=dice1.tmp[5];
    }
}
int compare(){
    int i;
    for(i=0;i<6;i++){
        if(dice1.d[i]!=dice2.d[i]){
            return 0;
        }
    }
    return 1;
}
int main()
{
    int n[6];
    int m;
    int i,j,k,l;
    int ok=0;
    scanf("%d",&m);
    for(i=0;i<6;i++){
        scanf("%d",&n[i]);
    }
    init2(n);
    copy1(0);
    for(i=0;i<m-1;i++){
        for(j=0;j<6;j++){
            scanf("%d",&n[j]);
        }
        init1(n);
        for(j=0;j<i+1;j++){
            copy2(j);
            for(k=0;k<4;k++){
                for(l=0;l<4;l++){
                    throwdice('N');
                    throwdice('E');
                    throwdice('S');
                    if(compare()) ok=1;
                }
                throwdice('N');    
            }
            throwdice('E');
            for(k=0;k<2;k++){
                for(l=0;l<4;l++){
                    throwdice('N');
                    throwdice('E');
                    throwdice('S');
                    if(compare()) ok=1;
                }
                throwdice('W');    
                throwdice('W');    
            }
        }
        copy1(i+1);
    }
    if(!ok) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 2100
#define ll long long int
#include <bits/stdc++.h>

using namespace std;

const int mod = 1e9 + 7;
int main()
 {
//code
         ll n,val,i,j,k;
         cin>>n>>k;
        vector<ll> v(n);
        vector<ll> w(n);
         ll dp[n+1][k+1];
		
		for(i=0;i<n;i++)
		cin>>w[i]>>v[i];
		
		for(i=0;i<=n;i++)
		{
			for(j=0;j<=k;j++)
			{
				if(i==0||j==0)
				dp[i][j]=0;
				else if(w[i-1]<=j)
				{
					dp[i][j]=max(v[i-1]+dp[i-1][j-w[i-1]],dp[i-1][j]);
				}
				else
				{
					dp[i][j]=dp[i-1][j];
				}
				
				
				
			}
			
		}
		
		cout<<dp[n][k];
		
}

Measured memory_bytes: 79104
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>

using namespace std;

map < int , bool > vis;
int n,tq;

int main(){
	scanf("%d",&n);
	while(n--){
		scanf("%d",&tq);
		if(vis[tq]==false)vis[tq]=true;
		else return printf("NO"),0;
	}
	printf("YES");
	return 0;
}

Measured memory_bytes: 9600
'''input
2 1
555 556
'''
from fractions import gcd
n,x = map(int,raw_input().split())
arr = map(int,raw_input().split())
arr.append(x)
arr.sort()
diff = []
for i in range(1,n+1):
	diff.append(arr[i]-arr[i-1])
gc = diff[0]
for i in range(1,len(diff)):
	gc = gcd(gc,diff[i])
print gc


Measured memory_bytes: 46796
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n];
  int count=0;
  for(int i=1;i<=n;i++)
  {
    cin>>a[i-1];
    if(i%2!=0 && a[i-1]%2!=0)count++;
  }
  cout<<count;
  return 0;
}

Measured memory_bytes: 3456
-- https://github.com/minoki/my-atcoder-solutions
import Data.Char (isSpace)
import Data.List (unfoldr)
import qualified Data.ByteString.Char8 as BS

main = do
  [n,a,b] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print $ min b (a * n)


Measured memory_bytes: 380
#include <iostream>

using namespace std;

int main(){
    int a, b, c, k;

    cin >> a >> b >> c >> k;

    int sum = 0;
    if(a <= k){
        // 1をすべて使う
        sum += a;
        k -= a;

        if(b <= k){
            // 0をすべて使う
            k -= b;

            if(k == c){
                sum += -1 * c;
            }
            else{
                sum += -1 * k;
            }
        }
        else{
            sum += 0;
        }
    }
    else{
        sum += k;
    }

    cout << sum << endl;

    return 0;

}


Measured memory_bytes: 3640
#include <iostream>
using namespace std;
int main()
{
	int a,b;
	cin >> a >> b;
	if(a<b)
		cout << "a < b" << endl;
	else if(a>b)
		cout << "a > b" << endl;
	else 
		cout << "a == b" << endl;
	return 0;
}


Measured memory_bytes: 3076
#include <iostream>

using namespace std;

const int MAX_N = 55, BLACK = 2, WHITE = 1;
int grid[MAX_N][MAX_N];

int all_neighbours_white(int row, int column)
{
    const int NO_OF_NEIGHBOURS = 4;
    int neighbour_x[NO_OF_NEIGHBOURS] = {-1, 0, 0, 1};
    int neighbour_y[NO_OF_NEIGHBOURS] = {0, 1, -1, 0};

    for(int i = 0; i < NO_OF_NEIGHBOURS; i++)
        if(grid[row + neighbour_x[i]][column + neighbour_y[i]] == BLACK)
            return false;

    return true;
}

int main()
{
    int height, width;
    cin >> height >> width;

    for(int i = 1; i <= height; i++)
    {
        for(int j = 1; j <= width; j++)
        {
            char block;
            cin >> block;

            grid[i][j] = (block == '#' ? BLACK : WHITE);

            
        }
    }

    int possible = true;
    for(int i = 1; i <= height; i++)
    {
        for(int j = 1; j <= width; j++)
        {
            if(grid[i][j] == BLACK && all_neighbours_white(i, j))
            {
                possible = false;
            }
        }
    }

    cout << (possible ? "Yes\n" : "No\n");

    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
  int n;
  char alp[27]="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  char s[10000];
  char ans[10000];
  int len;
  scanf("%d",&n);
  scanf("%s",s);
  len=strlen(s);
  int i;
  int j;
  int checker;
  for(i=0;i<len;i++){
    j=0;
    while(s[i]!=alp[j]){
      j++;
    }
    ans[i]=alp[(j+n)%26];
  }
  ans[len]='\0';
  printf("%s",ans);


return 0;
}


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

int main(){
	int N,M;
	cin >> N >> M;
	int k[10],s[10][10],p[10];
	for(int i=0;i<M;i++){
		cin >> k[i];
		for(int j=0;j<k[i];j++){
			cin >> s[i][j];
		}
	}
	
	for(int i=0;i<M;i++)cin >> p[i];
	long long ans=0;
	for(int x=0;x<(1<<N);x++){
		vector<int> S(N,0);
		for(int i=0;i<N;i++){
			if(x & (1<<i))S[i]=1;
		}
		int ok=0;
		
		for(int i=0;i<M;i++){
			int cnt = 0;
			for(int j=0;j<k[i];j++){
				if(S[s[i][j]-1]==1)cnt++;
			}
			if(cnt%2==p[i])ok++;
		}
	if(ok==M){
		ans++;
		
	}

	}
	cout << ans <<endl;
	}

Measured memory_bytes: 256
N,M = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)

#dp[n] : 丁度n本のマッチを使って作れる整数で最大のもの
# もし、n本で数字が作れるならば、n+f(m)本使ったものも作れる。
# ここでf(m)はマッチ棒で数字mを作るときに必要なマッチ棒の本数
# 遷移式はdp[n+f(m)] = max(dp[n+f(m)], dp[n] + m.to_s)

dp = Array.new(N+10){-1.to_s}

def f(m)
  table = [2,5,5,4,5,6,3,7,6]

  return table[m-1]
end

def max(s1,s2)
  tmp = s1
  if s2.length > s1.length
    tmp = s2
  elsif s2 > s1
    tmp = s2
  end
  return tmp
end

dp[0] = ""

N.times do |n|
  next if dp[n] == "-1"
  A.each do |m|
    dp[n+f(m)] = max(dp[n+f(m)], dp[n] + m.to_s)
  end
end

puts dp[N]

Measured memory_bytes: 54908
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
ll const MOD = 1e9 + 7;

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k;
    cin >> n >> k;
    vector<vector<ll>> pascal (2e3 + 5, vector<ll>(2e3 + 5));
    pascal[0][0] = 1;
    FOR(i, 1, sz(pascal))
    {
        pascal[i][0] = 1;
        FOR(j, 1, i + 1)
        {
            pascal[i][j] = (pascal[i - 1][j] + pascal[i - 1][j - 1]) % MOD;
        }   
    }
    FOR(i, 1, k + 1)
    {
        ll res = pascal[n - k + 1][i] * pascal[k -1][i - 1];
        res %= MOD;
        cout << res << "\n";
    }
    return 0;
}

Measured memory_bytes: 31744
/*input
async layered coding
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}
int main()
{
	IOS;
	int a,b;
	cin>>a>>b;
	cout<<b+b-a;
	return 0;
}


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

int main() {
	int N, M;
	cin >> N >> M;
	vector<long long int> a (N);
	vector<long long int> b (N);
	vector<long long int> c (N);
	vector<long long int> vec (N);
	for(int i = 0;i < N;i++){
		cin >> a.at(i) >> b.at(i) >> c.at(i);
	}
	long long int s1 = 0;
	long long int s2 = 0;
	long long int s3 = 0;
	long long int s4 = 0;
	long long int s5 = 0;
	long long int s6 = 0;
	long long int s7 = 0;
	long long int s8 = 0;
	//phase1 +++
	for(int i = 0;i < N;i++){
		vec.at(i) = a.at(i) + b.at(i) + c.at(i);
	}
	sort(vec.begin(),vec.end());
	reverse(vec.begin(),vec.end());
	for(int i = 0;i < M;i++){
		s1 += vec.at(i);
	}
	//phase2 ++-
	for(int i = 0;i < N;i++){
		vec.at(i) = a.at(i) + b.at(i) - c.at(i);
	}
	sort(vec.begin(),vec.end());
	reverse(vec.begin(),vec.end());
	for(int i = 0;i < M;i++){
		s2 += vec.at(i);
	}
	//phase3 +-+
	for(int i = 0;i < N;i++){
		vec.at(i) = a.at(i) - b.at(i) + c.at(i);
	}
	sort(vec.begin(),vec.end());
	reverse(vec.begin(),vec.end());
	for(int i = 0;i < M;i++){
		s3 += vec.at(i);
	}
	//phase4 +--
	for(int i = 0;i < N;i++){
		vec.at(i) = a.at(i) - b.at(i) - c.at(i);
	}
	sort(vec.begin(),vec.end());
	reverse(vec.begin(),vec.end());
	for(int i = 0;i < M;i++){
		s4 += vec.at(i);
	}
	//phase5 -++
	for(int i = 0;i < N;i++){
		vec.at(i) = 0 - a.at(i) + b.at(i) + c.at(i);
	}
	sort(vec.begin(),vec.end());
	reverse(vec.begin(),vec.end());
	for(int i = 0;i < M;i++){
		s5 += vec.at(i);
	}
	//phase6 -+-
	for(int i = 0;i < N;i++){
		vec.at(i) = 0 - a.at(i) + b.at(i) - c.at(i);
	}
	sort(vec.begin(),vec.end());
	reverse(vec.begin(),vec.end());
	for(int i = 0;i < M;i++){
		s6 += vec.at(i);
	}
	//phase7 --+
	for(int i = 0;i < N;i++){
		vec.at(i) = 0 - a.at(i) - b.at(i) + c.at(i);
	}
	sort(vec.begin(),vec.end());
	reverse(vec.begin(),vec.end());
	for(int i = 0;i < M;i++){
		s7 += vec.at(i);
	}
	//phase8 ---
	for(int i = 0;i < N;i++){
		vec.at(i) = 0 - a.at(i) - b.at(i) - c.at(i);
	}
	sort(vec.begin(),vec.end());
	reverse(vec.begin(),vec.end());
	for(int i = 0;i < M;i++){
		s8 += vec.at(i);
	}
	
	cout << max(s1,max(s2,max(s3,max(s4,max(s5,max(s6,max(s7,s8))))))) << endl;
}

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

using namespace std;
using ll = long long;

int main() {
  int K, A, B;
  cin >> K >> A >> B;
  bool ok = false;
  for (int i = A; i <= B; i++) {
    if (i % K == 0) {
      ok = true;
      break;
    }
  }

  if (ok) {
    cout << "OK" << endl;
  } else {
    cout << "NG" << endl;
  }

  return 0;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

template <class T, class U>
void chmin(T &a, U b) {
  if (b < a) a = b;
}

template <class T>
T Sq(const T &t) {
  return t * t;
}

signed main() {
  int n, m;
  cin >> n >> m;
  vi a;
  REP(i, n) { a.PB(read()); }
  sort(ALL(a));
  vector<pi> cb;
  REP(i, m) {
    int b = read();
    int c = read();
    cb.PB(MP(c, b));
  }
  sort(ALL(cb), greater<pi>());
  int cb_i = 0;
  REP(i, n) {
    if (a[i] > cb[cb_i].first) break;
    a[i] = cb[cb_i].first;
    --cb[cb_i].second;
    if (cb[cb_i].second <= 0) ++cb_i;
  }
  print(accumulate(ALL(a), (int)0));
}


Measured memory_bytes: 3188
#include<stdio.h>
#define TRUE 1
#define FALSE 0;

int prime(int x);

int main()
{
  int i, n, x;
  int count = 0;

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &x);

    if(prime(x) == TRUE) count++; 
  }
  printf("%d\n", count);
  
  return 0;
}

int prime(int x){
  int i;

  if(x < 2) return FALSE;
  if(x == 2) return TRUE;
  if(x%2==0) return FALSE;
  for(i = 3; i*i <= x; i+=2){
    if(x % i ==0) return FALSE;
  }
  
  return TRUE;
}




Measured memory_bytes: 2040
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define pb            push_back
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      (a)/GCD((a),(b))*(b)
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

// code
// ------------------------------------------------
typedef std::deque<int> IntDeque;
void PrintDeque(const IntDeque& deq)
{
    const IntDeque::const_iterator itEnd = deq.end();
    for (IntDeque::const_iterator it = deq.begin(); it != itEnd; ++it) {
        std::cout << *it << "\n";
    }
    std::cout << std::endl;
}
int main() {

  string s;
  cin >> s;
  deque<int> q,deq;

  rep(i,sz(s))
  {
    if(s[i] == '1')
    {
        q.push_back(1);
    }
    else if(s[i] == '0')
    {
        q.push_back(0);
    }
    else
    {
        if(!q.empty())
          q.pop_back();
    }
  }

  for(auto itr = q.begin();itr != q.end();itr++)
  {
    cout << *itr;
  }

  cout << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
int CalcSumOfDigit(int n)
{
  int s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


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

int main() {
  
  vector<vector<int>> c(3,vector<int>(3));
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      cin >> c.at(i).at(j);
    }
  }
  
  //a0=0
  vector<int> a(3);
  vector<int> b(3);
  a.at(0) = 0;
  for(int i=0; i<3; i++){
    b.at(i) = c.at(0).at(i) - a.at(0);
  }
  for(int i=0; i<3; i++){
    a.at(i) = c.at(i).at(0) - b.at(0);
  }
    
  bool good = true;
  for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
      if(a.at(i) + b.at(j) != c.at(i).at(j)){
        good = false;
      }
    }
  }
    
  if(good == true){
    cout << "Yes" <<endl;
  }
  else{
    cout << "No" << endl;
  }
  
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
using namespace std;
using ll=long long;
using ld=long double;
typedef pair<int,int> P;

class Calc_Mod{//mod演算用クラス
    public:
        unsigned int mod=1000000007;
        ll plus_mod(ll a,ll b){
            return (a+b)%mod;
        }
        ll minus_mod(ll a,ll b){
            return (a-b)%mod;
        }
        ll multi_mod(ll a,ll b){
            return a*b%mod;
        }
        ll LSM(ll a,int b){//a^b%mod
            queue<int> q;
            while(b>=1){
                q.push(b%2);
                b/=2;
            }
            ll ans=1;
            while(!q.empty()){
                if(q.front()==1){
                    ans=multi_mod(ans,a);
                }
                a=multi_mod(a,a);
                q.pop();
            }
            return ans;
        }
        ll div_mod(ll a,ll b){// a/b
            return multi_mod(a,LSM(b,mod-2));
        }

        ll combi(ll a,ll b){
            ll ans=1;
            ll kaijo=1;
            rep(i,b){
                ans=multi_mod(ans,a-i);
                kaijo=multi_mod(kaijo,b-i);
            }
            ans=div_mod(ans,kaijo);
            return ans;
        }
};

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

    int ans=0;
    Calc_Mod mod;
    ans=mod.LSM(2,N)-1;
    P no_use;
    no_use.first=mod.combi(N,a);
    no_use.second=mod.combi(N,b);
    ans=mod.minus_mod(ans,no_use.first);
    ans=mod.minus_mod(ans,no_use.second);
    if(ans<0){
        ans+=mod.mod;
    }
    cout << ans << endl;


}

Measured memory_bytes: 256
A[1<<17];i;b;y;k;long s;main(j){for(;i<=*A;)scanf("%d",A+i++);for(;~scanf("%d",&b);i<0?s+=i,++y:(A[k++]=i))i=A[j++]-b;for(qsort(A,k,4,"\x8b\7+\6Ð");k--&&s<0;++y)s+=A[k];printf("%d",s<0?-1:y);}

Measured memory_bytes: 892
#include<iostream>
#include<vector>
#include<map>
using namespace std;

typedef long long ll;
const ll mod = 1e9 + 7;

ll modpow(ll a, ll b, ll p = 1e9+7){
    if(b == 0)  return 1;

    if(b % 2 == 0){
        ll d = modpow(a, b/2, p);
        return (d*d) % p;
    }else{
        return (a%p * modpow(a, b-1, p)) % p;
    }
}

struct ModComb{
    vector<ll> po, inv;
    ll N;

    ModComb(ll n) : N(n), po(n), inv(n) {
        po[0] = 1;
        for(int i = 1; i < N; i++)  po[i] = (po[i-1] * i) % mod;
        inv[N-1] = modpow(po[N-1], mod-2, mod);
        for(int i = N-2; i >= 0; i--)   inv[i] = (inv[i+1] * (i+1)) % mod;
    }
    
    ll nCk(ll n, ll k){
        if(n < k)   return 0;
        return (((po[n]*inv[n-k])%mod)*inv[k])%mod;
    }

    ll nPk(ll n, ll k){
        if(n < k)   return 0;
        return (po[n]*inv[n-k])%mod;
    }

    ll nHk(ll n, ll k){
        if(n == 0 && k == 0)    return 1;
        return nCk(n+k-1, k-1);
    }
};

int main(){
    int n, m;
    cin >> n >> m;
    ModComb mc(200000);
    map<int, int> f;
    for(int i = 2; i*i <= m; i++){
        while(m%i == 0) m /= i, f[i]++;
    }
    if(m != 1)  f[m]++;
    ll ans = 1;
    for(auto p : f){
        ans *= mc.nHk(p.second, n);
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  
  map<int,int> a;
  map<int,int> b;
  
  int w[n];
  
  for(int i=0; i<n; i++)
    cin >> w[i];
  
  int flag = 1;
  for(int i=1; i<n; i++){
    if(w[i] != w[i-1]){
      flag = 0;
      break;
    }
  }
  
  for(int  i=0; i<n; i++){
    if(i%2 == 0){
      a[w[i]] ++;
    }else{
      b[w[i]] ++;
    }
  }
  
  int res11=0;
  int res12=0;
  int key11=-11;
  int key12=-12;
  int res21=0;
  int res22=0;
  int key21=-21;
  int key22=-22;
  
  for(auto s: a){
    if(res11 < s.second){
      res12 = res11;
      key12 = key11;
      res11 = s.second;
      key11 = s.first;
    }
    if(res12 < s.second && (s.first != key11)){
      res12 = s.second;
      key12 = s.first;
    }
  }
  
  for(auto t: b){
    if(res21 < t.second){
      res22 = res21;
      key22 = key22;
      res21 = t.second;
      key21 = t.first;
    }
    if(res22 < t.second && t.first != key21){
      res22 = t.second;
      key22 = t.first;
    }
  }
  
  int ans;
  if(key11 == key21){
    ans = min(n-res11-res22, n-res12-res21);
  }else{
    ans = n-(res11+res21);
  }
    
  if(ans == 0 && flag == 1){
    ans = n/2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 5376
n, m = [int(i) for i in input().split()]
p = []
s = []
for i in range(m):
    q, t = input().split()
    p.append(int(q))
    s.append(t)

is_ac = [0] * (n+1)
wa = [0] * (n+1)
count_ac = count_penalty = 0
for pp, ss in zip(p, s):
    if not is_ac[pp]:
        if ss == 'WA':
            wa[pp] += 1
        else:
            count_ac += 1
            count_penalty += wa[pp]
            is_ac[pp] = 1

print(count_ac, count_penalty)


Measured memory_bytes: 14992
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e9+7
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 long long int gcd(long long int m,long long int n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
long long int lcm(long long int number1,long long int number2){
	return number1 * number2 / gcd(number1,number2);	

}
int main(){
  ll A,B,C,D,E,F;
  cin>>A>>B>>C>>D>>E>>F;
  
  double max2=0;
  ll sugar=0;
  ll water=0;
  
  for(ll i=0;i*100*A<F;i++){//A
    for(ll j=0;j*100*B<F;j++){//B
      for(ll k=0;k*C<F;k++){//C
        for(ll m=0;m*D<F;m++){//D
          if(max(i,j)==0){
            continue;
          }
          if(k*C+m*D+A*100*i+B*100*j>F){
            continue;//ここのIFは順番が逆だとアウト
          }
          
          
          
        double unko=double(double(k*C+m*D)/double(A*100*i+B*100*j+k*C+m*D));
          
          if(max2<=unko&&(k*C+m*D)<=E*(A*i+B*j)){
            max2=double(double(k*C+m*D)/double(A*100*i+B*100*j+k*C+m*D));
          sugar=(k*C+m*D);
            water=(A*100*i+B*100*j);
          }
          }
        }
      }
    }
  
  
  cout<<water+sugar<<" "<<sugar<<endl;
}


Measured memory_bytes: 384
//template code, C343, 2019
import java.util.*;

class Graph {
	private int totalVertex;
	private LinkedList<LinkedList<Integer>> adjList;
	//adjacency list of edges
	public Graph() { totalVertex = 0; }
	public void loadAdjList() {
		Scanner in = new Scanner(System.in);
		totalVertex = in.nextInt();
		adjList = new LinkedList<LinkedList<Integer>>();
		for(int i = 0; i < totalVertex; i ++) {
			LinkedList<Integer> tmp = new LinkedList<Integer>();
			int idx1 = in.nextInt() - 1;
			int degree = in.nextInt();
			//System.out.println("mark idx1 = " + idx1 + " degree = " + degree);
			for(int j = 0; j < degree; j ++) {
				int idx2 = in.nextInt() - 1;
				tmp.add(idx2);
			}	
			adjList.add(tmp);
		}
		in.close();
	}
	public void printAdjMatrix() {
		Integer[][] adjMatrix = new Integer[totalVertex][totalVertex];
		Iterator<LinkedList<Integer>> it = adjList.iterator();
		int x = 0;
		while(it.hasNext()) {
			LinkedList<Integer> curr = it.next();
			Iterator<Integer> it2 = curr.iterator();
			while(it2.hasNext()) {
				adjMatrix[x][it2.next()] = 1;
			}
			x++;
		}
		for(int i = 0; i < totalVertex; i++) {
			String temp = "";
			for(int j = 0; j < totalVertex; j++) {
				if(adjMatrix[i][j] == null) {
					temp += "0 ";
				}
				else {
					temp += "1 ";
				}
			}
			System.out.println(temp.substring(0, temp.length() - 1));
		}
	}
}

//change class name GraphRepresentation to Main() for submission to AIZU
public class Main {
	public static void main(String argv[]) {
		Graph g = new Graph();
		g.loadAdjList();
		g.printAdjMatrix();
	}
}


Measured memory_bytes: 39860
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,a, b) for (int i = (a); i < (b); i++ )

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

const int INF = 100000000;
const double PI=3.14159265358979323846;

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

    vector<vector<int>> a(N,vector<int> (2));
    vector<int> ans(N);

    rep(i,0,N) {
        a[i][0] = N-1-i;
        cin >> a[i][1];
    }
    sort(a.begin(), a.end());


    for (int i=0;i<N;i+=2) {
        ans[i/2]=a[i][1];
    }
    for (int i=1;i<N;i+=2) {
        ans[N-1-i/2]=a[i][1];
    }
    rep(i,0,N) {
        cout << ans[i] << " ";
    }
    cout << endl;

}



Measured memory_bytes: 13952
#include<iostream>

int main(){
    int N;
    int m[100000];
    int X;
    int sum=0;
    int min=1000;
    m[0]=10000;

    std::cin>>N>>X;
    for(int i=1;i<=N;i++){
        std::cin>>m[i];
    }        
    for(int i=1;i<=N;i++){
        sum+=m[i];
        if(min>m[i]&&m[i]!=0)min=m[i];
    }

    int amari=(X-sum)/min;
    std::cout<<N+amari<<std::endl;
}

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

#define ll long long 
#define d  double 
#define endl "\n"

const ll int MOD=1e9+7;

void solve()
{
	ll n,a,b,x,ans;
	cin >> n >> a >> b;
	if((a+b)%2==0)
		ans = (b-a)/2;
	else
		ans = min(a-1,n-b)+1+(b-a-1)/2;
	cout << ans << endl;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	solve();
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const char sp = ' ';

string S;
int DP[1111111][2];

int main() {
	cin >> S;
	reverse(S.begin(), S.end());
	S.push_back('0');
	DP[0][1] = 0xE869120;
	for (int i = 0; i < S.size(); i++) {
		DP[i + 1][0] = min(DP[i][0] + S[i] - '0', DP[i][1] + S[i] - '0' + 1);
		DP[i + 1][1] = min(DP[i][0] + 10 - (S[i] - '0'), DP[i][1] + 10 - (S[i] - '0' + 1));
	}
	cout << DP[S.size()][0] << endl;
}

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



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

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

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n;cin>>n;
  vector<ll>p(n),ip(n);
  rep(i,n){cin>>p[i];p[i]--;}
  rep(i,n)ip[p[i]]=i;
  multiset<ll>se;
  se.insert({-1,-1,n,n});
  vector<vector<ll>>lr(n,vector<ll>(4));
  rrep(i,n){
    auto itr=se.lower_bound(ip[i]);
    auto itr2=itr;
    ll l1=*(--itr);
    ll l2=*(--itr);
    ll r1=*(itr2);
    ll r2=*(++itr2);
    lr[ip[i]]={l2,l1,r1,r2};
    se.insert(ip[i]);
  }
  ll res=0;
  rep(i,n){
    ll tres=0;
    tres+=(lr[i][1]-lr[i][0])*(lr[i][2]-i);
    tres+=(i-lr[i][1])*(lr[i][3]-lr[i][2]);
    res+=tres*(p[i]+1);
  }
  cout<<res<<endl;

  return 0;

}


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

int main(void){
	int a, b, max;

	cin >> a >> b;
	if(a + b < a - b)
		max = a - b;
	else
		max = a + b;
	if(max < a * b)
		max = a * b;
	cout << max << endl;

	return 0;
}


Measured memory_bytes: 764
import sys,heapq
from collections import defaultdict,deque

input = sys.stdin.readline
n,m = map(int,input().split())
#+路線*chg : その路線ホーム
chg = 10**6

edge=defaultdict(set)
used =defaultdict(bool)
for i in range(m):
    p,q,c = map(int,input().split())
    edge[p].add(p+c*chg)
    edge[p+c*chg].add(p)
    edge[p+c*chg].add(q+c*chg)
    edge[q+c*chg].add(p+c*chg)
    edge[q].add(q+c*chg)
    edge[q+c*chg].add(q)
    used[p] = False
    used[q] = False
    used[p+c*chg] = False
    used[q+c*chg] = False

edgelist = deque()
edgelist.append((1,0))
res = float("inf")

while len(edgelist):
    x,cost = edgelist.pop()
    used[x] = True

    if x == n:
        res = cost
        break
    for e in edge[x]:
        if used[e]:
            continue
        #ホーム→改札
        if x <= 10**5 and chg <= e:
            edgelist.appendleft((e,cost+1))
        else:
            edgelist.append((e,cost))
        
if res == float("inf"):
    print(-1)
else:
    print(res)

Measured memory_bytes: 216172
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second)
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) (find(all(v),x)!=v.end())
#define incls(s,c) (s.find(c)!=string::npos)
#define lb(a,x) distance((a).begin(),lower_bound(all(a),(x)))
#define ub(a,x) distance((a).begin(),upper_bound(all(a),(x)))
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(all(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using vb = vector<bool>;
using vvb = vector<vb>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; cin >> x; return x;}
inline ll lin() { ll x; cin >> x; return x;}
inline char chin() { char x; cin >> x; return x;}
inline string stin() { string x; cin >> x; return x;}
inline double din() { double x; cin >> x; return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const vector<T>& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};

int main () {
  int a, b, c;
  cin >> a >> b >> c;
  if (a < b && b < c) yn;
  return 0;
}


Measured memory_bytes: 3068
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

N = ri()
A = rl()

s = 0
prev = A[0]
for i in range(1, N):
	if A[i] < prev:
		dif = prev-A[i]
		A[i] += dif
		s += dif
	prev = A[i]
print(s)


Measured memory_bytes: 93584
import java.util.*;

class Main {
    public static void main(String args[]) {
        Scanner inp = new Scanner(System.in);
        String a = inp.next();
        String b = inp.next();
        String c = inp.next();
        char al = last(a);
        char bf = first(b);
        char bl = last(b);
        char cf = first(c);
        System.out.println(al == bf && bl == cf ? "YES" : "NO");
    }
    public static char first(String s) {
        return s.toCharArray()[0];
    }
    public static char last(String s) {
        char ss[] = s.toCharArray();
        return ss[ss.length - 1];
    }
}

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

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

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

// non-decreasing.cpp
// author: Seong Yong-ju ( @sei40kr )
// Copyright (c) 2017 Seong Yong-ju

#define DEBUG(x) cout << #x << ": " << x << endl

#define MIN(a, b) (a > b ? b : a)
#define MAX(a, b) (a > b ? a : b)

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)

#define ALL(a) (a).begin(), (a).end()

using namespace std;

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

  int n;
  cin >> n;

  int xs[n];

  REP(i, n) {
    int x;
    cin >> x;

    xs[i] = x;
  }

  size_t M = max_element(xs, xs + n) - xs;
  size_t m = min_element(xs, xs + n) - xs;

  size_t base = abs(xs[m]) <= abs(xs[M]) ? M : m;

  cout << n * 2 - 1 << endl;

  REP(i, n) {
    cout << base + 1 << ' ' << (i + 1) << endl;
  }

  if (0 <= xs[base]) {
    FOR(i, 1, n) {
      cout << i << ' ' << i + 1 << endl;
    }
  } else {
    RREP(i, n - 1) {
      cout << i + 2 << ' ' << i + 1 << endl;
    }
  }
}


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

int main() {
  string n;
  cin >> n;
  
  for (int i=0; i<n.size(); ++i) {
    if (n.at(i) == '1') {
      n.at(i) = '9';
    }
    else if (n.at(i) == '9') {
      n.at(i) = '1';
    }
  }
  
  cout << n;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dy[] = {1, 0, -1, 0};
const int dx[] = {0, 1, 0, -1};
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    while(cin >> n >> m, n | m)
    {
        int h[n + 1], w[m + 1];
        for(int i = 0; i < n; i++) cin >> h[i];
        for(int i = 0; i < m; i++) cin >> w[i];
        map<int, int> mp;
        for(int i = 0; i < n; i++)
        {
            int sum = h[i];
            mp[sum]++;
            for(int j = i + 1; j < n; j++)
            {
                sum += h[j];
                mp[sum]++;
            }
        }
        int ans = 0;
        for(int i = 0; i < m; i++)
        {
            int sum = w[i];
            ans += mp[sum];
            for(int j = i + 1; j < m; j++)
            {
                sum += w[j];
                ans += mp[sum];
            }
        }
        cout << ans << endl;
    }
    return 0;
}




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

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {
		var inputArray = retreiveLongArray();
			var inputCount = 2;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long N = inputArray[0];
			long M = inputArray[1];

			if (N>9 | M >9) {
				Console.WriteLine(-1);
				return;

			}

			//答えの出力
			var ans = N*M;
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}


		/// <summary>
		/// 2組みずつの入力データ(数値)からTuppleListを作成する
		/// </summary>
		/// <param name="N"></param>
		/// <returns></returns>
		private static List<Tuple<long, long>> createLongTuppleList(long N) {
			var inpList = new List<Tuple<long, long>>();

			for (int i = 0; i < N; i++) {
				var inp = retreiveLongArray();
				var item1 = inp[0];
				var item2 = inp[1];
				inpList.Add(new Tuple<long, long>(item1, item2));
			}
			return inpList;
		}
	}
}

Measured memory_bytes: 28176