akhauriyash/Code-Regression huggingface dataset:
package main

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

const MAX = 8
const Q = 1

var sc = bufio.NewScanner(os.Stdin)

func Perm(arr []int) [][]int {
	ret := make([][]int, 0)
	perm(arr, &ret, 0)
	return ret
}

func perm(arr []int, ret *[][]int, i int) {
	if i > len(arr) {
		*ret = append(*ret, append([]int{}, arr...))
		return
	}
	perm(arr, ret, i+1)
	for j := i + 1; j < len(arr); j++ {
		arr[i], arr[j] = arr[j], arr[i]
		perm(arr, ret, i+1)
		arr[i], arr[j] = arr[j], arr[i]
	}
}

func scanInt() int {
	num, _ := strconv.Atoi(scanString())
	return num
}

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

func init() {
	sc.Split(bufio.ScanWords)
}

func isFit(arr []int, fix map[int]int) bool {
	for k, v := range fix {
		if arr[k] != v {
			return false
		}
	}
	return true
}

func generateBord() [][]int {
	bord := make([][]int, MAX)
	for i := range bord {
		bord[i] = make([]int, MAX)
	}
	return bord
}

func findQ(arr []int) int {
	for i, e := range arr {
		if e == Q {
			return i
		}
	}
	return -1
}

func printBord(bord [][]int) {
	q := strconv.Itoa(Q)
	for _, arr := range bord {
		s := strings.Trim(fmt.Sprint(arr), "[]")
		s = strings.Replace(s, " ", "", -1)
		s = strings.Replace(s, "0", ".", -1)
		s = strings.Replace(s, q, "Q", -1)
		fmt.Println(s)
	}
}

func isOK(bord [][]int) bool {
	var x, y int
	for i := range bord {
		q := findQ(bord[i])
		x = i - 1
		y = q - 1
		// 対角線上に存在したらダメ
		for x >= 0 && y >= 0 {
			if bord[x][y] == Q {
				return false
			}
			x--
			y--
		}
		x = i - 1
		y = q + 1
		// 対角線上に存在したらダメ
		for x >= 0 && y < MAX {
			if bord[x][y] == Q {
				return false
			}
			x--
			y++
		}
	}
	return true
}

func main() {
	k := scanInt()
	fix := make(map[int]int, k)
	for i := 0; i < k; i++ {
		x := scanInt()
		y := scanInt()
		fix[x] = y

	}

	for _, p := range Perm([]int{0, 1, 2, 3, 4, 5, 6, 7}) {
		if !isFit(p, fix) {
			continue
		}

		bord := generateBord()
		for i, e := range p {
			bord[i][e] = Q
		}

		if isOK(bord) {
			printBord(bord)
			break
		}
	}
}



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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;

int main() {
    int n, m, sum = 0;
    cin >> n >> m;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
        sum += a[i];
    }
    sort(a.rbegin(), a.rend());
    if (a[m - 1] >= sum / (4.0 * m)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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


int main() {
  vector<string> title(3);
  for(int i = 0; i < 3; i++) {
    cin >> title.at(i);
  }
  
  char ini;
  ini = title.at(1).at(0);

  cout << "A" << ini << "C" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {

  int a, b, c, i, cnt = 0;
  int array[101] = {};

  scanf("%d %d %d", &a, &b, &c);

  array[a] = 1;
  array[b] = 1;
  array[c] = 1;

  for(i=0;i<101;i++)
    if(array[i] == 1)
      cnt++;

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

  return 0;
}


Measured memory_bytes: 128
#include <float.h>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int A;
  int B;
  cin >> A >> B;
  int a, b, c, ans;
  a = A + B;
  b = A - B;
  c = A * B;
  ans = a;
  if (b > a) {
    ans = b;
  }

  if (c > a) {
    ans = c;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))
m = 0
low = abs(l[0])
s = 0
for i in range(n):
  if l[i] < 0:
    l[i] = abs(l[i])
    m += 1
  if low > l[i]:
    low = l[i]
  s += l[i]
if m%2:
  s -= low*2
print(s)

Measured memory_bytes: 14412
#include<iostream>
#include<cstdio>
#define _USE_MATH_DEFINES
#include<cmath>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;


#define INF 1e+10
#define EPS 1e-10
#define EQ(a,b) (abs(a-b)<EPS)

//誤差を考慮して足し算
double add(double a,double b){
	if(abs(a+b) < EPS*(abs(a)+abs(b)))return 0;
	return a+b;
}
struct P{//2次元ベクトル
	double x,y;
	P(){}
	P(double x,double y):x(x),y(y){}
	P operator + (P p)const{
		return P(add(x,p.x),add(y,p.y));
	}
	P operator - (P p)const{
		return P(add(x,-p.x),add(y,-p.y));
	}
	P operator * (double d)const{
		return P(x*d,y*d);
	}
	P operator / (double d)const{
		return P(x/d,y/d);
	}
	double dot(P p)const{//内積
		return add(x*p.x,y*p.y);
	}
	double det(P p)const{//外積
		return add(x*p.y,-y*p.x);
	}
	bool equal(P p)const{
		return (x-p.x)*(x-p.x)+(y-p.y)*(y-p.y) < EPS*EPS;
	}
};


bool cmp_x(const P& p,const P& q){
	if(p.x!=q.x)return p.x<q.x;
	return p.y<q.y;
}
vector<P> convex_hull(vector<P> ps){
	sort(ps.begin(),ps.end(),cmp_x);
	int k=0;
	vector<P> qs(ps.size()*2);
	for(int i=0;i<ps.size();i++){
		while(k>1 && (qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1]) <= 0 )k--;
		qs[k++]=ps[i];
	}
	for(int i=ps.size()-2,t=k;i>=0;i--){
		while(k>t && (qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1]) <= 0 )k--;
		qs[k++]=ps[i];
	}
	qs.resize(k-1);
	return qs;
}


int main(){
	int n;
	char _;
	while(cin>>n&&n){
		vector<P> ps(n);
		for(int i=0;i<n;i++){
			cin>>ps[i].x>>_>>ps[i].y;
		}
		cout<<ps.size()-convex_hull(ps).size()<<endl;
	}
	return 0;
}

Measured memory_bytes: 1244
import sys

def main():
	input = sys.stdin.readline

	N, M = list(map(int,input().strip().split()))
	A = list(map(int,input().strip().split()))
	A.sort(reverse=True)

	count = [0]*N
	ind = [0]
	for i in range(M):
		maximum = 0
		for j in ind:
			if A[j]>maximum:
				maxind = j
				maximum = A[j]

		if maximum==0: break

		# print(maxind)
		A[maxind] = A[maxind]/2
		count[maxind] += 1
		# print(count[maxind])
		if count[maxind]==len(ind):
			ind.append(0)
			# ind[-2] += 1
			ind[-2] = min(N-1,ind[-2]+1)
			# if ind[-1]!=N-1:
		else: 
			# ind[count[maxind]-1] += 1
			ind[count[maxind]-1] = min(N-1,ind[count[maxind]-1]+1)

		# print(ind)

	print(sum(map(int,A)))

if __name__ == "__main__":
    main()

Measured memory_bytes: 63856
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>


ll n,a1 = 0,a2 = 0,a[210000],b[210000],ans = INF;
string s;
bool ok = false;
int main() {
	cin >> n;
	cin >> s;
	REP(i, n) {
		if (s[i] == '#')a[i + 1]++;
		a[i + 1] += a[i];
	}
	REPR(i, n - 1) {
		if (s[i] == '.')b[i]++;
		b[i] += b[i + 1];
	}
	REP(i, n + 1)ans = min(ans, a[i] + b[i]);
	cout << ans << endl;
}




Measured memory_bytes: 3716
#include<stdio.h>
 
int minof(int min,int y){
  min=(min<y)?min:y;
  return min;
}
 
int main(){
  int min[51], g,i,j,k,l;
  while(1){
    scanf("%d",&g);
    if(g==0){
      break;
    };
    g/=100;
    for(l=0;l<51;l+=1){
      min[l]=100000;
    };
    for(i=0;i<26;i+=1){
      for(j=0;j<17;j+= 1){
        for(k=0;k<11;k+=1){
          if(2*i+3*j+5*k==g){
            min[2*i+3*j+5*k]=minof(min[2*i+3*j+5*k],(i/5)*1520+(i%5)*380+(j/4)*1870+(j%4)*550+(k/3)*2244+(k%3)*850);
          };
        };
      };
    };
    printf("%d\n", min[g]);
  };
  return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const int mod = 1000000007;

int main() {
  ll n, c;
  cin >> n >> c;
  vector<ll> x(n), v(n);
  rep(i, n) {
    cin >> x[i] >> v[i];
  }
  vector<ll> maxv(n + 1), maxrv(n + 1);
  ll sum = 0;
  ll pre = 0;
  rep(i, n) {
    sum += v[i] - (x[i] - pre);
    pre = x[i];
    maxv[i + 1] = max(maxv[i], sum);
  }
  sum = 0;
  pre = 0;
  rep(i, n) {
    ll dist = (c - x[n - 1 - i]) - pre;
    sum += v[n - 1 - i] - dist;
    maxrv[i + 1] = max(sum, maxrv[i]); 
    pre = c - x[n - 1 - i];
  }

  ll ans = 0;
  rep(i, n) {
    ll t = max(maxv[i + 1], maxv[i + 1] + maxrv[n - 1 - i] - x[i]);
    ll rt = max(maxrv[i + 1], maxrv[i + 1] + maxv[n - 1 - i] - (c - x[n - i - 1]));
    
    chmax(ans, max(t, rt));
    // cout << maxrv[i + 1] << endl;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3328
import java.io.*;
import java.util.*;

public class Main {
	FastScanner in;
	PrintWriter out;

	int[] p;

	int get(int x) {
		return p[x] == x ? x : (p[x] = get(p[x]));
	}

	void unite(int x, int y) {
		p[get(x)] = get(y);
	}

	class Q implements Comparable<Q> {
		int fr, to, cost;

		public Q(int fr, int to, int cost) {
			super();
			this.fr = fr;
			this.to = to;
			this.cost = cost;
		}

		public int compareTo(Q arg0) {
			return Integer.compare(cost, arg0.cost);
		}

	}

	void solve() {
		int n = in.nextInt();
		int q = in.nextInt();
		p = new int[n];
		for (int i = 0; i < n; i++) {
			p[i] = i;
		}
		PriorityQueue<Q> pq = new PriorityQueue<Main.Q>();
		for (int i = 0; i < q; i++) {
			int from = in.nextInt();
			int to = in.nextInt();
			int co = in.nextInt();
			pq.add(new Q(from, to, co));
			pq.add(new Q((from + 1) % n, to, co + 1));
		}
		long res = 0;
		while (pq.size() > 0) {
			Q cur = pq.poll();
			if (get(cur.fr) == get(cur.to)) {
				continue;
			}
			unite(cur.fr, cur.to);
			res += cur.cost;
			cur.fr = (cur.fr + 1) % n;
			cur.to = (cur.to + 1) % n;
			cur.cost += 2;
			pq.add(cur);
		}
		out.println(res);

	}

	void run() {
		try {
			in = new FastScanner(new File("object.in"));
			out = new PrintWriter(new File("object.out"));

			solve();

			out.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	void runIO() {

		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);

		solve();

		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}

	public static void main(String[] args) {
		new Thread(null, new Runnable() {
			public void run() {
				new Main().runIO();
			}
		}, "1", 1 << 26).start();
	}
}

Measured memory_bytes: 59552
import sys

S = input()
op_cnt = len(S) - 1

for i in range(2 ** op_cnt):
    op = ["-"] * op_cnt
    for j in range(op_cnt):
        if ((i >> j) & 1):
            op[op_cnt - j - 1] = "+"
    formula = ""
    for p_n, p_o in zip(S, op + [""]):
        formula += (p_n + p_o)
    if eval(formula) == 7:
        print(formula + "=7")
        sys.exit()

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
#define dbg(x) #x "=" << x << " "
#define fore(i,a,b) for(int i=a,gon=b;i<gon;++i)
#define pb push_back
#define F first
#define S second
typedef double lf;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        //freopen("out.txt", "w", stdout);
    #else
        #define endl '\n'
    #endif
    int n;
    string s;
    cin >> n;
    map<char, int> cnt[n];
    fore(i,0,n) {
        cin >> s;
        fore(j,0,s.size()) {
            cnt[i][s[j]]++;
        }
    }
    fore(c,'a','z'+1) {
        int mn = 100;
        fore(i,0,n) {
            mn = min(mn, cnt[i][c]);
        }
        cout << string(mn, c);
    }
    cout << endl;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <vector>
using std::vector;

#define MAXN 100005
#define MAXH 405
int indeg[MAXH],outdeg[MAXH];
bool vis[MAXH];
vector<int> G[MAXH];

void add_edge(int u,int v)
{
    outdeg[u]++;indeg[v]++;
    G[u].push_back(v);G[v].push_back(u);
}

bool dfs(int v)
{
    bool f=indeg[v]!=outdeg[v];
    vis[v]=true;
    for(auto to:G[v])
    {
        if(!vis[to]) 
            f|=dfs(to);
    }
    return f;
}

int main()
{
    int N,H;
    int a[MAXN],b[MAXN],c[MAXN],d[MAXN];
    scanf("%d%d",&N,&H);
    for(int i=1;i<=N;i++) 
    {
        scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);
        int l,r;
        l= ( c[i]==0 ? a[i] : -c[i] );
        r= ( d[i]==0 ? -b[i] : d[i] );
        add_edge(l+H,r+H);
    }

    bool flag=true;
    for(int i=0;flag && i<=H;i++) 
    {
        if(outdeg[i]>indeg[i]) 
            flag=false;
    }
    for(int i=H+1;flag && i<=2*H;i++)
    {
        if(indeg[i]>outdeg[i]) 
             flag=false;
    }

    memset(vis,false,sizeof(vis));
    for(int i=0;flag && i<=2*H;i++)
    {
        if((indeg[i]||outdeg[i])&&!vis[i]) 
            flag &=dfs(i);
    }

    if(flag) 
    {
        printf("YES\n"); 
    }
    else
    { 
        printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 3328
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 mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

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

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

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

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

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

#[allow(unused_mut)]
#[allow(non_snake_case)]
fn main() {
    input! {
        N: usize,
        h: [usize; N],
    }

    let mut cost = 0;
    compute_cost(h, &mut cost, 0);

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

fn compute_cost(array: Vec<usize>, cost: &mut usize, current_min: usize) {
    let min = *array.iter().min().unwrap();
    *cost += min - current_min;
    let mut length = array.len() as i32;
    let mut len2: i32;

    let mut mut_iter = array.into_iter(); 
    while length > 0 {
        let array2: Vec<usize> = 
            mut_iter.by_ref().take_while(|num| *num > min).collect();
        len2 = array2.len() as i32;

        if len2 > 0 {
            compute_cost(array2, cost, min);
        }

        length -= len2 + 1;
    }
}


Measured memory_bytes: 4352
n = int(input())
w = list([input() for _ in range(n)])

tmp = [1 for i in range(n-1) if w[i][-1]!=w[i+1][0]]


if len(tmp)>0:
  print("No")
elif len(set(w))<len(w):
  print("No")
else:
  print("Yes")

Measured memory_bytes: 3060
#include<stdio.h>
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <functional>
#include <stdio.h>
#include <array>
#include <algorithm>
#include <string>
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include <queue>
#include<iomanip>
#include<bitset>
#include<stack>
#include<set>
#include<limits>
#include <complex>
using namespace std;
template < class BidirectionalIterator >
bool next_combination(BidirectionalIterator first1,
	BidirectionalIterator last1,
	BidirectionalIterator first2,
	BidirectionalIterator last2)
{
	if ((first1 == last1) || (first2 == last2)) {
		return false;
	}
	BidirectionalIterator m1 = last1;
	BidirectionalIterator m2 = last2; --m2;
	while (--m1 != first1 && !(*m1 < *m2)) {
	}
	bool result = (m1 == first1) && !(*first1 < *m2);
	if (!result) {
		// ?
		while (first2 != m2 && !(*m1 < *first2)) {
			++first2;
		}
		first1 = m1;
		std::iter_swap(first1, first2);
		++first1;
		++first2;
	}
	if ((first1 != last1) && (first2 != last2)) {
		// ?
		m1 = last1; m2 = first2;
		while ((m1 != first1) && (m2 != last2)) {
			std::iter_swap(--m1, m2);
			++m2;
		}
		// ?
		std::reverse(first1, m1);
		std::reverse(first1, last1);
		std::reverse(m2, last2);
		std::reverse(first2, last2);
	}
	return !result;
}

template < class BidirectionalIterator >
bool next_combination(BidirectionalIterator first,
	BidirectionalIterator middle,
	BidirectionalIterator last)
{
	return next_combination(first, middle, middle, last);
}



int main() {
	while (1) {
		int w, d; cin >> w >> d;
		if (!w)break;
		vector<int>ws;
		vector<int>ds;
		if (w >= d) {
			for (int i = 0; i < w; ++i) {
				int a; cin >> a; ws.push_back(a);
			}
			for (int i = 0; i <d; ++i) {
				int a; cin >> a; ds.push_back(a);
			}
		}
		else {
			for (int i = 0; i < w; ++i) {
				int a; cin >> a; ds.push_back(a);
			}
			for (int i = 0; i <d; ++i) {
				int a; cin >> a; ws.push_back(a);
			}
		}
		assert(ws.size() >= ds.size());

		vector<int>perm;
		for (int i = 0; i < ws.size(); ++i) {
			perm.push_back(i);
		}
		int finans = 500;


		do {
			int nans = 0;
			vector<bool>used(ws.size(), false);
			for (int i = 0; i < ds.size(); ++i) {
				if (ds[i] == ws[perm[i]]) {
					nans += ds[i];
				}
				else {
					nans += ds[i] + ws[perm[i]];
				}
				used[perm[i]] = true;
			}
			for (int i = 0; i < ws.size(); ++i) {
				if (!used[i]) {
					nans += ws[i];
				}
			}
			finans = min(finans, nans);

		} while (next_permutation(perm.begin(), perm.end()));
		cout << finans << endl;

	}

	return 0;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
int main(){
    int n;
    int a=0;
    int b=0;
    int roop=0;
    int num[10];
    int p[10];
    int q[10];
    cin >> n;
    rep(i,n)cin >> p[i];
    rep(i,n)cin >> q[i];
    rep(i,n)num[i]=i+1;

    do{
        bool judge = true;
        rep(i,n)if(num[i]!=p[i])judge = false;
        if(judge)a = roop;

        judge = true;
        rep(i,n)if(num[i]!=q[i])judge = false;
        if(judge)b = roop;

        roop++;

    }while(next_permutation(num,num+n));

    cout << abs(a-b);
    return 0;
}

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

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

  if( a < b ) cout<<"a < b"<<endl;
  if( a > b ) cout<<"a > b"<<endl;
  if( a == b ) cout<<"a == b"<<endl;

  return 0;
}



Measured memory_bytes: 3084
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stdio.h>
#include <cmath>

using namespace std;

typedef unsigned long long ull;
typedef unsigned int uint;
typedef unsigned char uchar;
#define umap unordered_map
const static ull INVALID_DIGIT = ~(ull)0;

int main()
{
    ull N, M;
    cin >> N >> M;

    ull invalidMax = std::numeric_limits<ull>::max() - 1;
    std::pair<ull, ull> possibleRange(0, invalidMax);
    for (ull i = 0; i < M; i++) {
        ull L, R;
        cin >> L >> R;

        possibleRange.first = std::max(L, possibleRange.first);
        possibleRange.second = std::min(R, possibleRange.second);
    }

    if (possibleRange.first == 0 && possibleRange.second == invalidMax) {
        cout << "0" << endl;
    }
    else if (possibleRange.first > possibleRange.second) {
        cout << "0" << endl;
    }
    else {
        cout << possibleRange.second - possibleRange.first + 1 << endl;
    }

    return 0;
}

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

using namespace std;

int main() {
	int h, w;
	cin >> h >> w;
	vector<string> s(50);
	for (int i = 0; i < h; i++) {
		cin >> s.at(i);
	}
	vector<int> kx(8);
	kx = {1, 1, 1, 0, 0, -1, -1, -1};
	vector<int> ky(8);
	ky = {0, 1, -1, -1, 1, 0, 1, -1};
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s.at(i).at(j) == '#') {
				continue;
			}
			int ans = 0;
			for (int k = 0; k < 8; k++) {
				int ki = i + kx.at(k);
				int kj = j + ky.at(k);
				if (ki < 0 || h <= ki) {
					continue;
				}
				if (kj < 0 || w <= kj) {
					continue;
				}
				if (s.at(ki).at(kj) == '#') {
					ans++;
				}
			}
			s.at(i).at(j) = char(ans + '0');
		}
	}
	for (int i = 0; i < h; i++) {
		cout << s.at(i) << endl;
	}
	return 0;
}


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

using namespace std;

int main(){
    int n;
    cin>>n;
    int cnt=0;
    for (int i = 0; i < n; ++i) {
        int a;
        cin>>a;
        if(a!=i+1)++cnt;
    }
    if(cnt>=3)cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using boost::multiprecision::cpp_int;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll,pair<ll, ll>> lpll;
typedef pair<ll, int> pli;
typedef pair<int, int> pii;

const ll INF = LLONG_MAX;
const ll MOD = 1e9+7;

const ld PI = (acos(-1));
const ld EPS = 0.0000000001;

int main() {
    // input, ready
  int N;
    cin >> N;
    // output
    cout << (N+1)/2 << endl;
    // cout << fixed << setprecision(10) << middle << endl;

    return 0;
}


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

int main(){
	int a, b, c, sum = 0, maxv;
	cin >> a >> b >> c;
	sum = a + b + c;
	maxv = max(a, b);
	maxv = max(maxv, c);
	int calc = (3 * maxv - sum + 1) / 2;
	int ans;
	if( sum % 2 == 0 ){
		if(maxv % 2 == 0) ans = calc;
		else ans = calc + 1;
	}
	else{
		if( maxv % 2 != 0 ) ans = calc;
		else ans = calc + 1;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
//2013
#include<iostream>
using namespace std;
int main(void){
	int a,b,c,d,e,ave=0;
	cin>>a;
	cin>>b;
	cin>>c;
	cin>>d;
	cin>>e;
	if(a<40)a=40;
	if(b<40)b=40;
	if(c<40)c=40;
	if(d<40)d=40;
	if(e<40)e=40;
	ave=(a+b+c+d+e)/5;
	cout<<ave<<endl;
	return 0;
}


Measured memory_bytes: 3096
#include <iostream>

using namespace std;

int main()
{
    long int K;
    cin >> K;
    string palabra;
    cin >> palabra;
    int lon= palabra.size();
    if(lon>K){
            for(int i=0; i<K; i++){
            cout<<palabra[i];
        }
        cout<<"...";

    }
    else{
        cout << palabra;
    }
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

void solve(){
    int n;cin >> n;
    vector<int>v(n);
    vector<int>c(n);
    int sum = 0;
    for(int i = 0;i<n;i++) cin >> v[i];
    for(int i = 0;i<n;i++) cin >> c[i];
    for(int i = 0;i<n;i++)
        sum = max(sum,sum+v[i]-c[i]);
    cout << sum;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 3632
/* -----------------------------------------------------------------------------
	AtCoder Beginner Contest 139
	A - Tenki
	g++ bc139A.cpp

----------------------------------------------------------------------------- */
#include <cstdio>

#define N 3

/* -----------------------------------------------------------------------------
	�����f�[�^
----------------------------------------------------------------------------- */

int main () {

	char s[N+1], t[N+1];
	int cnt = 0;

	// �I�萔�̓Ǎ���
	scanf("%s %s", s, t);
	// �x�N�g���̓Ǎ��݂ƕΊp�v�Z
	for(int i = 0; i < N; i++) cnt += (s[i] == t[i]);		
	printf("%d\n", cnt);
	return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
 
#define M 1046527
#define L 14
#define NIL (-1)
 
char H[M][L]; /* Hash Table */
 
int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}
 
/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}
 
int h1(int key){ return key % M; }
int h2(int key){ return 1+(key % (M-1)); }
 
int find(char str[]){
  long long key,i,h;
  key = getKey(str);
  for ( i = 0;; i++) {
    h = (h1(key) + i*h2(key)) % M;
    if ( strcmp(H[h],str) == 0) return 1;
    else if ( strlen(H[h]) == 0 ) return 0;
  }
  return 0;
}
 
int insert(char str[]){
  long long key,i,h;
  key = getKey(str);
  for ( i = 0;; i++) {
    h = (h1(key) + i*h2(key)) % M;
    if ( strcmp(H[h],str) == 0) return 1;
    else if ( strlen(H[h]) == 0 ) {
     strcpy(H[h], str); 
     return 0;
     }
  }
  return 0;
}
 
int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
     
    scanf("%d", &n);
     
    for ( i = 0; i < n; i++ ){
    scanf("%s %s", com, str);
     
    if ( com[0] == 'i' ){
        insert(str);
    } else {
        if (find(str)){
        printf("yes\n");
        } else {
        printf("no\n");
        }
    }
    }
 
    return 0;
}


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

#define MAX 1000000007
int main(){
    
    long long H,W;
    cin >> H >> W;
    char arr[H+1][W+1];
    
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            cin >> arr[i][j];
        }
    }
    
    vector<vector<int>>dp(H+1, vector<int>(W+1, 0));
    // dp[1][1] = 1;
    for(int i=1;i<=H;i++){
        for(int j =1;j<=W;j++){
            if(arr[i][j] == '.' and i==1 and j==1){
                dp[i][j] = 1;
            }
            else if(arr[i][j] == '.'){
                dp[i][j] = (dp[i-1][j] + dp[i][j-1])%MAX;
            }
            else{
                dp[i][j] = 0;
            }
        }
    }

    cout << dp[H][W]<<endl;;
	return 0;
}


Measured memory_bytes: 5120
N = int(input())
# 3 * 10^5
S = input()
#S = [{'W':'<', 'E':'>'}[c] for c in S]

w = 0
e = 0
W = [0]*N
E = [0]*N
for i, c in enumerate(S):
    if c == 'W':
        w+=1
    elif c == 'E':
        e+=1
    W[i] = w
    E[i] = e

m = N
D = [0]*N
result = 0
for i in range(N):
    # > < > < >
    #       W E
    #   o   i
    if i == 0:
        D[i] =  E[N-1] - E[i]
    elif i == N-1:
        D[i] = W[i-1]
    else:
        D[i] = W[i-1] + E[N-1] - E[i]
    if m > D[i]:
        m = D[i]
        result = i+1

#print("S=", *list(S))
#print("W=", *W)
#print("E=", *E)
#print("D=",*D)
#print(result)
print(m)





Measured memory_bytes: 29472
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i,n) for(int i = 1; i < n+1 ;i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;

int main(){
  long a,b;
  cin >> a >> b;
  if (a == 1 || b == 1){
    cout << 1 << endl;
  }
  else if (a*b % 2 == 0) {
    cout << a * b / 2 << endl ;
  }else{
    cout << (a * b + 1) / 2 << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n,i,l;
  scanf("%d",&n);
  if(n==1){
    printf("1");
  }else{
    printf("0.");
    l=(n+1)/2;
    for(i=0;i<7;i++){
      l*=10;
      printf("%d",l/n);
      l%=n;
    }
  }
  return(0);
}

Measured memory_bytes: 128
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long



using namespace std;

void file(){
	#ifndef ONLINE_JUDGE
    	freopen("in.txt", "r", stdin);
	#endif
}
int tc;
const int N=1e6+5,M=2e6+5,MOD=1e9+7,OO=1e9;

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	//file();

	string a,b;

	cin>>a>>b;

	int pos = -1;
	for(int i=0;i+sz(b)-1<sz(a);i++){
		string curr = a.substr(i,sz(b));
		bool ok = true;
		for(int j=0;j<sz(b);j++){
			if(curr[j]=='?')continue;
			if(curr[j]!=b[j])ok = false;
		}
		if(ok)pos = i;
	}

	if(pos ==-1)cout<<"UNRESTORABLE\n";
	else{
		for(int i=0;i<sz(a);i++){
			a[i] = a[i]=='?' ? 'a': a[i];
			if(i==pos){
				cout<<b;
				i=i+sz(b)-1;
			}
			else	cout<<a[i];
		}
	}

}


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

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;

inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}
inline int ad(int x,int y){int ret=(x%mod+y%mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int sub(int x,int y){int ret=((x%mod)-(y%mod)+mod)%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}
inline int gun(int x,int y){int ret=((x%mod)*(y%mod))%mod;if(ret<0){ret+=mod,ret=ret%mod;}return ret;}


 main()

{
    fast
    int a,b,c;
    cin>>a>>b>>c;
    if(a%2==0 || b%2==0 || c%2==0)
    {
        cout<<"0"<<endl;
    }
    else
    {
        int ses=min(a*c,min(a*b,b*c));
        cout<<ses<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

type Edge struct {
	from, to, cost int
}

const INF = 1000 * 1000 * 1000

func main() {
	var N, M, P int
	fmt.Scan(&N)
	fmt.Scan(&M)
	fmt.Scan(&P)

	ES := make([]Edge, M)
	for i := 0; i < M; i++ {
		var A, B, C int
		fmt.Scan(&A)
		fmt.Scan(&B)
		fmt.Scan(&C)
		A--
		B--
		ES[i] = Edge {
			A, B, P - C,
		}
	}

	DF := make([]int, N)
	DR := make([]int, N)
	
	for i := 0; i < N; i++ {
		DF[i] = INF
		DR[i] = INF
	}
	DF[0] = 0
	DR[N - 1] = 0

	for i := 0; i < N; i++ {
		for _, e := range(ES) {
			if DF[e.from] != INF && DF[e.to] > DF[e.from] + e.cost {
				DF[e.to] = DF[e.from] + e.cost
			}
			if DR[e.to] != INF && DR[e.from] > DF[e.to] + e.cost {
				DR[e.from] = DR[e.to] + e.cost
			}
		}
	}
	
	for _, e := range(ES) {
		if DF[e.from] == INF || DR[e.to] == INF {
			continue
		}
		
		if DF[e.to] > DF[e.from] + e.cost {
			fmt.Println(-1)
			return
		}
	}

	if DF[N - 1] > 0 {
		fmt.Println(0)
	} else {
		fmt.Println(-DF[N - 1])
	}
}


Measured memory_bytes: 1664
n,m = map(int, input().split())
h_a = list(map(int, input().split()))

m_l = [[0,0]]*m
r_l = [{}]*n
for i in range(m):
  r = list(map(int, input().split()))
  a = r[0] - 1
  b = r[1] - 1

  ral = set([]) if len(r_l[a]) == 0 else r_l[a]
  rbl = set([]) if len(r_l[b]) == 0 else r_l[b]

  ral.add(b)
  rbl.add(a)

  r_l[a] = ral
  r_l[b] = rbl

cnt = 0
for ni in range(n):
  for r in r_l[ni]:
    if h_a[r] >= h_a[ni]:
      break
  else:
    cnt+=1

print(cnt)

Measured memory_bytes: 43088
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	string S;
	cin >> n >> S;
	int ans = 0;
	for (int i = 0; i < n - 2; ++i) {
		if (S.substr(i, 3) == "ABC") ans++;
	}
	dunk(ans);
	return 0;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define repll(i,n) for(ll i = 0; i < n; i++)
#define REPll(i,n) for(ll i = 1; i < n; i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yesorno(a) printf(a ? "yes\n" : "no\n")
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define YESorNO(a) printf(a ? "YES\n" : "NO\n") 
#define endl "\n"
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}


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

  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i,h) cin >> s[i];
  rep(i,h){
    rep(j,w){
      if(s[i][j] == '#'){
        bool ok = false;
        rep(k,4){
          int ny = i + dy[k];
          int nx = j + dx[k];
          if(ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
          if(s[ny][nx] == '#') ok = true;
        }
        if(!ok){
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
s = 0
for i in range(n):
  s += b[a[i]-1]
  if 0 < i  and a[i] == a[i-1]+1:
    s += c[a[i-1]-1]

print(s)

Measured memory_bytes: 3064
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    n = S()
    if n[1] == n[2]:
        if n[0] == n[1] or n[2] == n[3]:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
    return

#B
def B():
    return

#C
def C():
    a,b,c,d = list(map(int, S()))
    s = ["-","+"]
    for i in range(2):
        for j in range(2):
            for k in range(2):
                if eval(str(a)+s[i]+str(b)+s[j]+str(c)+s[k]+str(d)) == 7:
                    print(str(a)+s[i]+str(b)+s[j]+str(c)+s[k]+str(d)+"=7")
                    quit()
#D
def D():
    h,w = LI()
    d = [None for i in range(10)]
    for i in range(10):
        d[i] = LI()
    for k in range(10):
        for i in range(10):
            for j in range(10):
                d[i][j] = min(d[i][j],d[i][k]+d[k][j])
    ans = 0
    for i in range(h):
        s = LI()
        for k in s:
            if k != -1:
                ans += d[k][1]
    print(ans)
#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    A()


Measured memory_bytes: 38640
import Control.Applicative

main :: IO ()
main = solve <$> words <$> getLine <*> f <*> getLine >>= putStrLn
  where
    f = map read <$> words <$> getLine

solve :: [String] -> [Int] -> String -> String
solve [s, _] [a, b] u
  | s == u = unwords $ map show [a-1, b]
  | otherwise = unwords $ map show [a, b-1]


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

int main(){

int X, Y;
cin >> X >> Y;

if(Y%2 == 1){
	cout << "No" << endl;
	return 0;
}
if(Y > X * 4){
	cout << "No" << endl;
	return 0;
}
for(int i = 0;i <= X;i++){
	if(i * 4 + (X - i) * 2 == Y){
		cout << "Yes" << endl;
		return 0;
	}
	
}
cout << "No" << endl;

}


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

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		int[] v = new int[N];

		for(int i=0;i<N;i++) {
			v[i] = sc.nextInt();
		}
		Arrays.sort(v);

		double ans = (double)v[0];
		for(int i=1;i<N;i++) {
			ans = (ans + (double)v[i])/2.0;
		}

		System.out.println(ans);
	}

}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
const ll INF=1000000000000001;
const double PI=3.141592653589;


int main(){
  int n; cin>>n;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  sort(a.begin(),a.end());
  int ans=abs(a[n-1]-a[0]);
  
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

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

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

const int INF=5e8;
int n,m;
pi vs[500005];
int cnt;
vector<pi> g[500005];
pair<pi,int> es[200005];
map<pi,int> conv;
bool done[500005];
int cost[500005];
int root[500005];
int main(){
  cin>>n>>m;
  REP(i,n) vs[cnt++]=mp(i,-1);
  REP(i,m){
    int p,q,c;scanf("%d%d%d",&p,&q,&c);
    --p;--q;

    vs[cnt++]=mp(p,c);
    vs[cnt++]=mp(q,c);
    es[i]=mp(mp(p,q),c);
  }
  sort(vs,vs+cnt);
  cnt=unique(vs,vs+cnt)-vs;

  REP(i,cnt){
    if(vs[i].sc==-1) root[vs[i].fr]=i;
    else{
      int v=vs[i].fr;
      g[i].pb(mp(root[v],0));
      g[root[v]].pb(mp(i,1));
    }
    conv[vs[i]]=i;
  }
  REP(i,m){
    int a=es[i].fr.fr,b=es[i].fr.sc,c=es[i].sc;
    int id1=conv[mp(a,c)],id2=conv[mp(b,c)];
    g[id1].pb(mp(id2,0));
    g[id2].pb(mp(id1,0));
  }

  REP(i,cnt) cost[i]=INF;

  deque<int> dq;
  cost[root[0]]=0;
  dq.pb(root[0]);
  while(!dq.empty()){
    int cur=dq.front();dq.pop_front();
    if(done[cur]) continue;
    done[cur]=1;
    for(auto e:g[cur]){
      if(e.sc==0 && cost[e.fr]>cost[cur]){
        cost[e.fr]=cost[cur];
        dq.push_front(e.fr);
      }
      if(e.sc==1 && cost[e.fr]>cost[cur]+1){
        cost[e.fr]=cost[cur]+1;
        dq.pb(e.fr);
      }
    }
  }
  int res=cost[root[n-1]];
  if(res==INF) res=-1;
  cout<<res<<endl;
  return 0;
}





Measured memory_bytes: 70912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf=1ll<<60;
vector<ll> to[100000],cost[100000],rev[100000];
bool used[100000];
int main(){
	int n,m,c;	cin>>n>>m>>c;
	ll esum=0;
	for(int i=0;i<m;i++){
		ll a,b,d;	cin>>a>>b>>d;	a--;	b--;
		to[a].push_back(b);	cost[a].push_back(d);	rev[a].push_back(to[b].size());
		to[b].push_back(a);	cost[b].push_back(d);	rev[b].push_back(to[a].size()-1);
		esum+=d;
	}
	vector<ll> dist(n,inf);	dist[0]=0;
	priority_queue<pair<ll,ll> > pq;
	pq.push(make_pair(0,0));
	while(!pq.empty()){
		auto now=pq.top();	pq.pop();
		ll cc=-now.first,x=now.second;
		for(int i=0;i<(int)to[x].size();i++){
			if(dist[to[x][i]]>cc+cost[x][i]){
				dist[to[x][i]]=cc+cost[x][i];
				pq.push(make_pair(-dist[to[x][i]],to[x][i]));
			}
		}
	}
	map<ll,vector<ll> > data;
	for(int i=0;i<n;i++)	data[dist[i]].push_back(i);
	used[0]=true;
	ll ans=inf;
	for(auto it=data.begin();it!=data.end();it++){
		ll cc=it->first;
		vector<ll> vec=it->second;
		for(int i=0;i<(int)vec.size();i++){
			int x=vec[i];
			used[x]=true;
			for(int j=0;j<(int)to[x].size();j++){
				if(used[to[x][j]]){
					esum-=cost[x][j];
					cost[to[x][j]][rev[x][j]]=0;
				}
			}
		}
		ans=min(ans,esum+c*cc);
	}
	cout<<ans<<endl;
	return 0;
}

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

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DBG(...)                \
  cerr << #__VA_ARGS__ << ": "; \
  debug(__VA_ARGS__);           \
  cerr << " (L" << __LINE__ << ")" << endl
#else
#define DBG(...)
#endif

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, n) for (auto i : (n))
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using ll = long long;

using namespace std;

int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  cout << N / (A + B) * A + min(N % (A + B), A) << endl;
}


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

using namespace std;

int main(){
	
    vector<int> a;
    
    int buf;
    while(cin >> buf){
        
        if(buf == 0){
            break;
        }
        
        a.push_back(buf);
        
    }
	
    int num = 1;
    for(auto ai : a){
        cout << "Case " << num << ": " << ai << endl;
    	++num;
    }
    
    return 0;
}

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

int main(){
    int N;
    long Y;
    cin >> N >> Y;
    long  e =0;
    long  f =0;
    long  g =0;
    int bb = 0;
    for(int i=0;i<N+1;i++){
        if(bb==1){
            break;
            }
        e = i*10000;
        // if(e == Y){
        //     cout << i <<" "<< 0 <<" "<< 0 << endl;
        //     bb = 1;
        //     break;
        //     }
        for(int j=0;j<N+1-i;j++){
            if(bb==1){
                break;
                }
            f = e + j*5000;
            // if(f == Y){
            //     cout << i << " " << j  << " " << 0 << endl;
            //     bb = 1;
            //     break;
            // }
            int k = N - i -j;
            g = f + k*1000;
            if(g == Y){
                cout << i <<" "<< j << " "<< k << endl;
                bb = 1;
                break;
            }
            
        }
    }
    if(bb==0){
        cout << -1 << " " << -1 <<" "<< -1<< endl;
    }
    
}

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


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

    vector<int> w(n);
    rep(i,n) cin >> w[i];

    int sum_all = 0;
    rep(i,n) sum_all += w[i];

    vector<int> sum(n);
    int sum_diff_min = sum_all;


    for (int i = 0; i < n; ++i) {
        for (int j = 0; j <= i; ++j) {
            sum[i] += w[j];
        }
        if(abs(sum_all - 2 * sum[i]) < sum_diff_min) {
            sum_diff_min = abs(sum_all - 2 * sum[i]);
        }
    }
    print(sum_diff_min);
}

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

int main(void)
{
    IOS
    int n, m;
    cin >> n >> m;
    vector<pii> v;
    REP(i,m) {
        int s, c;
        cin >> s >> c;
        s--;
        v.emplace_back(s,c);
    }

    int i = n == 1 ? 0 : pow(10,n-1);
    int e = pow(10,n);

    while(i < e) {
        string s = to_string(i);
        bool ok = true;
        REP(j,m) {
            if (s[v[j].first] != v[j].second + '0') ok = false;
        }
        if (ok) {
            cout << s << '\n';
            return 0;
        }
        i++;
    }

    OUT(-1)

    return 0;
}

Measured memory_bytes: 256
/**
*    created: 21.06.2020 02:52:49
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pcnt(bit) __builtin_popcount(bit)
#define mod 1000000007
#define pi acos(-1.0)
using namespace std;

signed main() {

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

    int n, x;
    cin >> n >> x;
    vector<int> p;
    rep(i,n) {
        int tmp;
        cin >> tmp;
        p.push_back(abs(tmp-x));
    }
    int d = p[0];
    rep(i,n-1) {
        d = __gcd(d,p[i+1]);
    }
    cout << d << endl;
    return 0;
}

Measured memory_bytes: 4232
#include <iostream>
#include <vector>
#include <utility>
#include <math.h>
#include <float.h>
#include <algorithm>
using namespace std;
#define M_PI       3.14159265358979323846
int lis(const vector<int> &arr){
	vector<int> t;
	for(int i=0;i<arr.size();++i){
		vector<int>::iterator it = lower_bound(t.begin(),t.end(),arr[i]);
		if(it==t.end())
			t.emplace_back(arr[i]);
		else
			*it = arr[i];
	}
	return t.size();
}
int main(){
	int x1,x2,y1,y2,n,x,y;
	scanf("%d%d%d%d%d",&x1,&y1,&x2,&y2,&n);
	int h = abs(y1-y2);
	int w = abs(x1-x2);
	vector<pair<int,int> > p;
	for(int i=0;i<n;++i){
		scanf("%d%d",&x,&y);
		x = x1 < x2 ? x-x1:x1-x;
		y = y1 < y2 ? y-y1:y1-y;
		if(x>=0&&y>=0&&x<=w&&y<=h)
			p.emplace_back(make_pair(x,y));
	}
	sort(p.begin(),p.end());
	vector<int> v;
	for(int i=0;i<p.size();++i)
		v.emplace_back(p[i].second);
	int l = lis(v);
	double ans = (w+h)*100.0 - (20 - 5 * M_PI) * l;
	if(l == min(w,h)+1)
		ans += 5*M_PI;
	printf("%.15lf\n",ans);
}

Measured memory_bytes: 4464
from collections import defaultdict
def main():
    dic = defaultdict(int)
    ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
    for i,s in enumerate(ascii_lowercase):
        dic[s] = i
    inp = input()
    idx = dic[inp] + 1
    print(ascii_lowercase[idx])
if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
N,L = input().split()
N,L = int(N),int(L)
S = L-1+N
Ans = int(S*(S+1)/2-L*(L-1)/2)
if S>=0 and L <= 0:
  print(Ans)
elif S<0:
  print(Ans-S)
else:
  print(Ans-L)

Measured memory_bytes: 3060