akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int n, q;
vector<int> v[200005];
long long val[200005];
bool vis[200005];
void calc(int pos)
{
	vis[pos] = true;
	for (int i = 0; i < v[pos].size(); i++)
	{
		if (vis[v[pos][i]])continue;
		val[v[pos][i]] += val[pos];
		calc(v[pos][i]);
	}
}
int main()
{
	cin >> n >> q;
	long long a, b;
	for (int i = 1; i < n; i++)
	{
		cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	while (q--)
	{
		cin >> a >> b;
		val[a] += b;
	}
	calc(1);
	for (int i = 1; i <= n; i++)
		cout << val[i] << (i == n ? '\n' : ' ');
	return 0;
}

Measured memory_bytes: 24448
package main 

import (
  "fmt"
)

func main() {
  var S, T string
  fmt.Scan(&S, &T)
  
  ret := false
  for i:=1; i < len(S)+1; i++ {
    front := S[:i]
    end := S[i:]
    if T == end + front {
      ret = true
    }
  }
  if ret {
    fmt.Println("Yes")
  } else {
    fmt.Println("No")
  }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fr(i, n) for (int i = 0; i < (int)n; i++)
#define frab(i, a, b) for (int i = a; i < b; i++)

using namespace std;

typedef long long ll;
typedef long double ld;

const ll INF = 1e9 + 10;
const ld PI = acos(-1);
const ld EPS = 1e-9;
const ll MOD = 1e9 + 7;
const int M = 1003;
const int N = 200 + 10;

int a[N][N];
vector <int> v;

ll calc(int n) {
    int r = v.size();
    ll ans = 0;
    fr(i, r - 1)
        ans += a[v[i]][v[i + 1]];
    return ans;
}

int main() {
    //freopen("a.in", "r", stdin);
    int n, m, r;
    cin >> n >> m >> r;
    fr(i, n)
        fr(j, n)
            a[i][j]= INF;

    fr(i, r) {
        int x;
        cin >> x;
        x--;
        v.pb(x);
    }

    fr(i, m) {
        int v, u, w;
        cin >> v >> u >> w;
        v--, u--;
        a[v][u] = a[u][v] = w;
    }


    fr(k, n)
        fr(i, n)
            fr(j, n)
                a[i][j] = min(a[i][j], a[i][k] + a[k][j]);

    int fc = 1;
    fr(i, r)
        fc *= (i + 1);

    ll ans = INF;
    fr(i, fc) {
        ans = min(ans, calc(n));
        next_permutation(v.begin(), v.end());
    }
    cout << ans;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define fix(n) cout<<fixed<<setprecision(n)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
using namespace std;
typedef long long ll;
const ll mod=1000000007;
double pi=3.1415926535;

int main(){
  string s;
  cin>>s;
  if(s.size()==2) co(s);
  else rep(i,0,3) cout<<s[2-i];
  
  
  return 0;
}

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

using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'

int main()
{
	int n,a[100005];
	map<int,int>m;
	cin >>n;
	
	for(int i = 1; i <= n; i++)
	{
		cin >> a[i];
		m.insert({a[i],i});
	}
	vector<int>v;
	for(auto it : m)
	{
		v.push_back(it.second);
	} 
	
	for(int i = 0; i < n-1; i++)
	{
		cout << v[i] <<" ";
	}
	cout << v[n-1] << endl;
	return 0;
}


Measured memory_bytes: 6392
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

vector<P> ans;
vector<vector<int>> e;

int dfs(int nn, int time) {
    // 探れるところがあるか探す
    if (ans[nn].first == 0) {
        // 到達していなければ時間を足して記録
        time += 1;
        ans[nn].first = time;
        // cout << "achived " << nn << ": " << time << endl; 
    }
    rep(i, e[nn].size()) {
        if (ans[e[nn][i]].first != 0) continue;
        // 到達していない箇所があれば入る
        time = dfs(e[nn][i], time);
    }
    time += 1;
    ans[nn].second = time;
    return time;
}

int main() {
    cout << fixed << setprecision(10);
    
    int n; cin >> n;
    // vector<vector<int>> e(n);
    e.resize(n);
    rep(i, n) {
        int id; cin >> id; id--;
        int k; cin >> k;
        rep(j, k) {
            int v; cin >> v; v--;
            e[id].emplace_back(v);
        }
    }

    // vector<P> ans(n);
    ans.resize(n);
    int time = 0;
    rep(i, n) {
        if (ans[i].first == 0) {
            time = dfs(i, time);
        }
    }
    rep(i, n) {
        cout << i+1 << " " << ans[i].first << " " << ans[i].second << endl;
    }
    return 0;
}


Measured memory_bytes: 3160
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

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

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  double w, h, x, y;
  cin >> w >> h >> x >> y;

  double s = (w * h) / 2.0;
  bool one = !(x == w / 2 && y == h / 2);

  printf("%.9lf ", s);
  if(x == w / 2 && y == h / 2) cout << 1 << endl;
  else cout << 0 << endl;

  return 0;
}


Measured memory_bytes: 504
n, m = map(int, input().split())
stair = [0] * (n + 10)
stair[1] = 1
stair[2] = 1
mod = 1000000007
for i in range(m):
    a = int(input())
    stair[a] = -1

for i in range(1, n+1):
    if (stair[i] == -1):
        continue
    if (stair[i + 2] != -1):
        stair[i + 2] = (stair[i] + stair[i + 2]) % mod

    if (stair[i + 1] != -1):
        stair[i + 1] = (stair[i] + stair[i + 1]) % mod

print(stair[n])



Measured memory_bytes: 6996
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt(); 
        int[] x = new int[n];
        int[] y = new int[n];
        
        for(int i=0;i<n;i++){x[i]=sc.nextInt();}
        for(int i=0;i<n;i++){y[i]=sc.nextInt();}
        
        double[] lst = new double[4];
        double z ;
        
        for(int i=0;i<n;i++){
            z = Math.abs(x[i]-y[i]);
            lst[0]+=z;lst[1]+=z*z;lst[2]+=z*z*z;lst[3]=Math.max(z,lst[3]);
        }
        
        for(int i=0;i<3;i++){
            System.out.println(Math.pow(lst[i],1/(double)(i+1)));
        }
        System.out.println(lst[3]);
    }
}


Measured memory_bytes: 26660
residence=[[[0 for i in range(10)] for j in range(3)] for k in range(4)]
n=int(input())
lines=[input() for i in range(n)]
for l in lines:
    k=list(map(int,l.split()))
    residence[k[0]-1][k[1]-1][k[2]-1]+=k[3]
    if residence[k[0]-1][k[1]-1][k[2]-1]>9: residence[k[0]-1][k[1]-1][k[2]-1]=9

for b in range(4):
    for f in range(3):
        print(' '+' '.join(map(str,residence[b][f])))
    if b!=3: print('#'*20)

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

int main() {
  int a, b;
  cin >> a >> b;
  int cnt=0;
  for(int i=1; i<=1000; i++) {
    if (i*8/100==a&&i/10==b) {
      cnt++;
      cout << i << endl;
      break;
    }
  }
  if (cnt==0) cout << -1 << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        struct Point
        {
            internal int x;
            internal int y;
        }

        static void Main()
        {
            string input;

            while (!string.IsNullOrEmpty(input = Console.ReadLine()))
            {
                char[][] map = new char[12][];

                map[0] = input.ToCharArray();

                for (int i = 1; i < 12; i++)
                {
                    map[i] = Console.ReadLine().ToCharArray();
                }

                int count = 0;

                for (int i = 0; i < 12; i++)
                {
                    for (int j = 0; j < 12; j++)
                    {
                        if (map[i][j] == '1')
                        {
                            SearchIsland(map, i, j);
                            count++;
                        }
                    }
                }
                Console.WriteLine(count.ToString());
                Console.ReadLine();
            }
        }

        static void SearchIsland(char[][] map, int x, int y)
        {
            int[] moveX = new int[] { -1, 0, +1, 0 };
            int[] moveY = new int[] { 0, +1, 0, -1 };

            Stack<Point> stk = new Stack<Point>();

            Point willPush;
            willPush.x = x;
            willPush.y = y;
            stk.Push(willPush);

            while (stk.Count > 0)
            {
                Point temp = stk.Pop();
                map[temp.x][temp.y] = '3';

                for (int i = 0; i < 4; i++)
                {
                    willPush.x = temp.x + moveX[i];
                    willPush.y = temp.y + moveY[i];

                    if (IsValid(willPush.x, willPush.y) && map[willPush.x][willPush.y] == '1')
                    {
                        stk.Push(willPush);
                    }
                }
            }
        }

        static bool IsValid(int x, int y)
        {
            if (x < 0) return false;
            if (x > 11) return false;
            if (y < 0) return false;
            if (y > 11) return false;
            return true;
        }
    }
}

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

int main(void){
   
  int a,b,c;
  cin >> a >> b >> c;
  
  if(a == b+c || b == a+c || c == a+b){
      cout << "Yes" <<endl;
  }
  else{
      cout << "No" <<endl;
  }
}

Measured memory_bytes: 3636
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;
#define ALL(x)              (x).begin(),(x).end()
typedef long long           ll;
#define REP(i, n)           for (ll i = 0 ; i < (ll)n ; ++i)
#define REPN(i, m, n)       for (ll i = m ; i < (ll)n ; ++i)
#define INF                 (ll)1e9
#define MOD                 (1000 * 1000 * 1000 + 7)
#define Ceil(x, n)          (((((x))+((n)-1))/n))
#define CeilN(x, n)         (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)        ((x)-(x)%(n))
#define IsOdd(x)            (((x)&0x01UL) == 0x01UL)
#define IsEven(x)           (!IsOdd((x)))
#define M_PI                3.14159265358979323846
typedef pair<ll, ll>	    P;

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	string S;
	cin >> S;

	string ans = "ABC";
	if (S == "ABC") {
		ans = "ARC";
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>
int C[500001];
int A[500001];
int count=0;
void merge(int a[],int left,int right);
int main(){
  int i,n;
 
  scanf("%d",&n);
  for(i=0; i < n ; i++){
    scanf("%d",&A[i]);
  }
  merge(A,0,n-1);
  for(i=0; i < n ; i++){
    if(i < n-1){
    printf("%d ",A[i]);
    }
    else{
      printf("%d",A[i]);
    }
  }
  printf("\n%d\n",count);
  return 0;
}

void merge(int A[],int left,int right){
  int mid,i,j,p;
  if(right <=left)return;
  mid=(left+right)/2;
  merge(A,left,mid);
  merge(A,mid+1,right);

  for(i=left; i <= mid;i++){
    C[i]=A[i];
  }
  j=right;
  for(i=mid+1;i <=right;i++){
    C[i]=A[j];
    j--;
  }
  j=right;
  i=left;
  for(p=left;p<=right;p++){
    if(C[i]<=C[j]){
      A[p]=C[i++];
      count++;
    }
    else{
      A[p]=C[j--];
      count++;
    }
  }
}



Measured memory_bytes: 5596
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

enum Color { kRed, kGreen, kNone };
using int64 = long long;
using Apple = pair<int64, Color>;

int main() {
  int64 x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<Apple> P(a, Apple(0, kRed)), Q(b, Apple(0, kGreen)), R(c, Apple(0, kNone));
  for (auto& p : P)
    cin >> p.first;
  for (auto& q : Q)
    cin >> q.first;
  for (auto& r : R)
    cin >> r.first;
  vector<Apple> apples(P);
  apples.insert(apples.end(), Q.begin(), Q.end());
  apples.insert(apples.end(), R.begin(), R.end());
  sort(apples.begin(), apples.end(), greater<Apple>());

  int64 ret = 0;
  vector<int64> stock;
  for (auto& a : apples) {
    switch (a.second) {
    case kRed: {
      if (x) {
        ret += a.first;
        --x;
      }
      break;
    }
    case kGreen: {
      if (y) {
        ret += a.first;
        --y;
      }
      break;
    }
    case kNone: {
      stock.push_back(a.first);
      break;
    }
    }
    if (stock.size() >= x + y)
      break;
  }
  ret += accumulate(stock.begin(), stock.begin() + x + y, 0LL);
  cout << ret << "\n";

  return 0;
}


Measured memory_bytes: 14180
#include<stdio.h>
int main(){
int i,input,a[4],b;
for(i=0;i<4;i++){
	scanf("%d%d",&input,&b);
	switch (input){
		case 1:
			a[i]=6000*b;
			break;
		case 2:
			a[i]=4000*b;
			break;
		case 3:
			a[i]=3000*b;
			break;
		case 4:
			a[i]=2000*b;
			break;
	}
}
for(i=0;i<4;i++){
	printf("%d\n",a[i]);
}
return 0;
}

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

int N,K;
int ans = 0;

int main()
{
    scanf("%d%d",&N,&K);
    for(int i = 0; i < N; i++)
    {
        int x;
        scanf("%d",&x);
        ans += min(x,abs(x - K));
    }
    printf("%d\n",ans * 2);
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? (-(a)) : (a))

typedef long long ll;

using namespace std;

int N, K, C;
char input[200000 + 5];

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

	scanf("%d %d %d", &N, &K, &C);
	scanf("%s", input);

	int last = -C - 1;

	vector<int> min_idx;
	vector<int> max_idx;

	for (int i = 0; i < N; ++i)
	{
		if (input[i] == 'o' && i >= last + C + 1)
		{
			min_idx.push_back(i + 1);
			last = i;
			if (min_idx.size() == K+1) break;
		}
	}

	last = N - 1 + C + 1;

	for (int i = N - 1; i >= 0; --i)
	{
		if (input[i] == 'o' && i <= last - C - 1)
		{
			max_idx.push_back(i + 1);
			last = i;
			if (max_idx.size() == K+1) break;
		}
	}

	sort(max_idx.begin(), max_idx.end());

	if (min_idx.size() == K && max_idx.size() == K)
	{
		for (int i = 0; i < min_idx.size(); ++i)
		{
			auto it = lower_bound(max_idx.begin(), max_idx.end(), min_idx[i]);
			if (*it == min_idx[i]) printf("%d\n", min_idx[i]);
		}
	}

	return 0;
}

Measured memory_bytes: 3444
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// ?¨??????\???????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		// ????????????????????????????????´??°?????¨????????????????????????
		int n = sc.nextInt();
		for (int i = 1; i <= n; i++) {
			int x = i;
			if (x % 3 == 0) {
				System.out.print(" " + i);
			} else {
				while (true) {
					if (x % 10 == 3) {
						System.out.print(" " + i);
						break;
					}
					x /= 10;
					if (x != 0)
						continue;
					else
						break;
				}
			}
		}
		System.out.println();
	}
}

Measured memory_bytes: 28464
c = [list(map(int, input().split())) for i in range(3)]
a = [0] * 3
b = [0] * 3

for i in range(3):
    a[i] = min(c[i][0], c[i][1], c[i][2])
    for j in range(3):
        c[i][j] -= a[i]

for i in range(3):
    if min(c[0][i], c[1][i], c[2][i]) != \
        max(c[0][i], c[1][i], c[2][i]):

        print('No')
        exit()
print('Yes')

Measured memory_bytes: 3064
N,Y=map(int,input().split())
n=Y//10000

if n>N:
    print("-1 -1 -1")
    exit()

for i in range(n+1):
    fukuzawa=10000*i
    x=i
    for j in range(N-x+1):
        higuchi=5000*j
        y=j
        if fukuzawa+higuchi+1000*(N-x-y)==Y:
            z=N-x-y
            print(x,y,z)
            exit()
print("-1 -1 -1")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define endl "\n" 
#define ll long long 
#define sp " "
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	#ifndef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin);
    	freopen("output.txt", "w", stdout);
	#endif
	ll q=1,a,b,p(0);long double f;cin>>q>>f;
	while(q--){
		cin>>a>>b;
		if(f>=sqrt(a*a+b*b))
			p++;
	}
	cout<<p;
}


Measured memory_bytes: 3804
from collections import deque

def main():
    ans = deque(input())
    n = int(input())
    vec = 1
    for i in range(n):
        q = input()
        if q == "1":
            vec *= -1
        else:
            _,o,s = q.split()
            if ((o == "1") and (vec == 1)) or ((o == "2") and (vec == -1)):
                ans.appendleft(s)
            else:
                ans.append(s)
    if vec == -1:
        ans.reverse()
    ans = ''.join(ans)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 74968
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws java.io.IOException {
		Scanner scan = new Scanner(System.in);
		double mux = 0;
		double min = 1000000000;
		while(scan.hasNext()){
			double x = scan.nextDouble();
			if(mux < x){
				mux = x;
			}
			if(min > x){
				min = x;
			}
		}
		System.out.println(mux - min);
	}
}

Measured memory_bytes: 18628
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;
long long modinv(long long a, long long m=MOD) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
    /*MODの割り算の際に
    a/＝b;
    を
    a *= modinv(b,MOD);
    とする。
        */
}
int main(){
  	int tmp;
  	Rep(i,5){
      int a;cin >>a;
      if(a==0)tmp = i;
    }
  cout << tmp << endl;
    return 0;
}

Measured memory_bytes: 3552
#include<stdio.h>
#define MAX 10000
#define NIL -1

struct Node{
  int pa, le, ri;
};

struct Node T[MAX];
int n;
int D[MAX], H[MAX];

int getDepth(int u);
int getSibling(int u);
void print(int u);

int main(){
  int i, v, l, r;
  
  scanf("%d", &n);
  for ( i = 0; i < n; i++ ) {
    T[i].pa = NIL;
  }
  for ( i = 0; i < n; i++ ){
    scanf("%d %d %d", &v, &l, &r);
    T[v].le = l;
    T[v].ri = r;
    if ( l != NIL ) T[l].pa = v;
    if ( r != NIL ) T[r].pa = v;
  }
  for ( i = 0; i < n; i++ ){
    D[i] = getDepth(i);
    H[i] = 0;
  }
  for ( i = 0; i < n; i++ ){
    if ( T[i].le == NIL && T[i].ri == NIL ) { // is leaf
      H[i] = 0;
      int p = T[i].pa;
      int c = 1;
      while(1){
	if ( p == NIL ) break;
	if ( H[p] < c ) H[p] = c;
	c++;
	p = T[p].pa;
      }
    }
  }
  for ( i = 0; i < n; i++ ) print(i);
  return 0;
}

int getDepth(int u){
  int d = 0;
  while(1){
    u = T[u].pa;
    if ( u == NIL ) break;
    d++;
  }
  return d;
}

int getSibling(int u){
  if ( T[u].pa == NIL ) return NIL;
  if ( T[T[u].pa].le != u && T[T[u].pa].le != NIL ) return T[T[u].pa].le;
  if ( T[T[u].pa].ri != u && T[T[u].pa].ri != NIL ) return T[T[u].pa].ri;
  return NIL;
}

void print(int u){
  printf("node %d: ", u);

  printf("parent = %d, ", T[u].pa);
  printf("sibling = %d, ", getSibling(u));
  int deg = 0;
  if ( T[u].le != NIL ) deg++;
  if ( T[u].ri != NIL ) deg++;
  printf("degree = %d, ", deg);
  printf("depth = %d, ", D[u]);
  printf("height = %d, ", H[u]);

  if ( T[u].pa == NIL ){
    printf("root\n");
  } else if ( T[u].le == NIL && T[u].ri == NIL ){
    printf("leaf\n");
  } else {
    printf("internal node\n");
  }
}



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

signed main(){

  char a,b,c;
  cin>>a>>b>>c;
  int ans = 0;
  char r = 'R';
  if(a==r&&b==r&&c==r)ans=3;
  else if(a==r&&b==r)ans=2;
  else if(b==r&&c==r)ans=2;
  else if(a==r||b==r||c==r)ans=1;
  cout<<(ans)<<endl;

}


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

int main()
{
  const int busstop[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  const int bussize = sizeof(busstop) / sizeof(int);

  int n;
  while (cin >> n) {
    while (n--) {
      int a, b;
      cin >> a >> b;

      int s = 0;
      for (; s < bussize; ++s) {
	if (busstop[s] == a)
	  break;
      }

      vector<int> ans;
      for (int i = s; i < bussize; ++i) {
	ans.push_back(busstop[i]);
	if (busstop[i] == b)
	  break;
      }

      if (1 <= a && a <= 5 && b < a) {
	vector<int> rev;
	for (int i = s; i >= 0; --i) {
	rev.push_back(busstop[i]);
	if (busstop[i] == b)
	  break;
	}
	if (rev.size() < ans.size())
	  ans = rev;
      }

      for (int i = 0; i < ans.size()-1; ++i)
	cout << ans[i] << " ";
      cout << ans.back() << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
from collections import defaultdict
from itertools import groupby, accumulate, product, permutations, combinations
from math import gcd

def reduction(x,y):
    g = gcd(x,y)
    return abs(x)//g,abs(y)//g

def solve():
    mod = 10**9+7
    dplus = defaultdict(lambda: 0)
    dminus = defaultdict(lambda: 0)
    N = int(input())
    xzero,yzero,xyzero = 0,0,0
    for i in range(N):
        x,y = map(int, input().split())
        if x==0:
            if y==0:
                xyzero += 1
            else:
                xzero += 1
        elif y==0:
            yzero += 1
        elif x*y>0:
            dplus[reduction(x,y)] += 1
        else:
            dminus[reduction(-y,x)] += 1
    ans = pow(2,xzero,mod)+pow(2,yzero,mod)-1
    other = N-xzero-yzero-xyzero
    for k,v in dplus.items():
        ans *= pow(2,dminus[k],mod)+pow(2,v,mod)-1
        other -= dminus[k]+v
    ans *= pow(2,other,mod)
    ans += xyzero-1
    ans %= mod
    return ans
print(solve())

Measured memory_bytes: 55024
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
using ll = long long;
const ll mod = 1000000007;
const ll INF = 100000000000000000LL;
signed main(){
    string s;
    cin>>s;
    int cnt = 0;
    rep(i,3){
        if(s[i]=='o')cnt++;
    }
    cout<<700+100*cnt<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INT_INF = 2147483647;
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 pair<int,int> P;

int main(){
  int a,b;
  cin >> a >> b;
  rep(i,10000){
    if((int)(i*0.08)==a&&(int)(i*0.1)==b){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 256
input_val = []
for i in range(5) :
    input_val.append(int(input()))

start = 0 
amari = []
shou = []
for i in range(5) :
    if input_val[i] % 10 == 0 :
        amari.append(10)
        shou.append(input_val[i] - 10)
    else :
        amari.append(input_val[i]%10)
        shou.append(input_val[i] - input_val[i]%10)

amari.sort()
loss = [(10 - i) for i in amari]
start += sum(shou)
for i in range(5):
    start += loss[i] + amari[i]

start -= loss[0]

print(start)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
using P = pair<int,int>;
using ivec = vector<int>;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }


const int MOD=1000000007;
int INF=100100100100100;

signed main(){
  int k,x;cin>>k>>x;
  if(500*k>=x)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 3572
#include <iostream>

using namespace std;
int a[2010];
long long mod = 1000000007;
int main(){
	long long i,j,n,k;
	cin >> n >> k;
	for(i=0;i<n;i++){
		cin >> a[i];
	}
	long long cnt = 0,cnt1 = 0;
	for(i=0;i<n;i++){
		for(j=i;j<n;j++){
			if(a[i]>a[j]) cnt++;
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			if(a[i]>a[j]) cnt1++;
		}
	}
	(cnt *= k) %= mod;
	(cnt += (k*(k - 1))/2%mod*cnt1%mod) %= mod;
	cout << cnt << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int sum = 0;
        for (int i=1;i<=n;i++) {
            int digSum = 0;
            int num = i;
            while (num > 0) {
                digSum += num % 10;
                num /= 10;
            }
            if ((digSum >= a) && (digSum <= b)) {
                sum += i;
            }
        }
        System.out.println(sum);
    }
}


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

typedef struct{
  int m;
  int f;
  int r;
  int sum;
  char judge;
}Score;

char j_s(Score X){
  char score;

  if(X.m == -1 || X.f == -1){
    score = 'F';
  }else{
    if(X.sum >= 80 ){
      score = 'A';
    }else if(X.sum >= 65){
      score = 'B';
    }else if(X.sum >= 50){
      score = 'C';
    }else if(X.sum >= 30){
      if(X.r >= 50){
        score = 'C';
      }else{
        score = 'D';
      }
    }else{
      score = 'F';
    }
  }
  return score;
}


int main(){
  int n=0;
  Score data[100];
  
  while(1){
    cin >> data[n].m >> data[n].f >> data[n].r;
    if(data[n].m == -1 && data[n].f == -1 && data[n].r == -1){
      break;
    }
    n++;
  }

  for(int i=0;i<n;i++){
    data[i].sum = data[i].m + data[i].f;
    data[i].judge = j_s(data[i]);
    cout << data[i].judge << endl;
  }
  return 0;
}

Measured memory_bytes: 1152
// by Balloons
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#define mpr make_pair
#define debug() puts("okkkkkkkk")
#define rep(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)

using namespace std;

typedef long long LL;

const int inf = 1 << 30;

vector<pair<int,int> >edge;

int main(){
	int n,k;scanf("%d%d",&n,&k);
	if(k>(n-1)*(n-2)/2)return puts("-1"),0;
	for(int i=2;i<=n;i++)edge.push_back(mpr(1,i));
	int tmp=(n-1)*(n-2)/2-k;
	if(tmp==0){
		printf("%d ",edge.size());
		for(int i=0;i<edge.size();i++)
			printf("%d %d\n",edge[i].first,edge[i].second);
		return 0;
	}
	
	while(tmp>0){
		for(int i=2;i<=n;i++)
			for(int j=i+1;j<=n;j++){
				edge.push_back(mpr(i,j));
				-- tmp;
				if(!(tmp)){
					printf("%d ",edge.size());
					for(int i=0;i<edge.size();i++)
						printf("%d %d\n",edge[i].first,edge[i].second);
					return 0;
				}
			}
	}

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define STEP(i, a, b, c) for (ll i = a; i <= ll(b); i += c)
#define STEPD(i, a, b, c) for (ll i = a; i >= (ll)b; i -= c)
#define LOOP while (true)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;

const ll INF = 1LL << 60;

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

  map<ll, ll> m;
  vector<ll> As;
  REP(i, N)
  {
    ll a;
    cin >> a;
    m[a]++;
    As.push_back(a);
  }

  ll ans = 0;
  map<ll, ll> p;
  for (auto &[k, v] : m)
  {
    if (v < 2)
    {
      p[k] = 0;
    }
    else
    {
      ll x = v * (v - 1) / 2;
      p[k] = x;
      ans += x;
    }
  }
  for (auto a : As)
  {
    if (m[a] < 2)
    {
      cout << ans << endl;
    }
    else
    {
      cout << (ans - p[a] + (m[a] - 1) * (m[a] - 2) / 2) << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 20576
def hoge(n, k)
  if k - n > n
    puts n
  else
    hoge(k-n, k)
  end
end

n,k = gets.split(' ').map(&:to_i)

if n == k
  puts 0
elsif n > k
  n = n % k
  hoge(n, k)
else
  hoge(n, k)
end

Measured memory_bytes: 1788
using System;


class Program
{
    static void Main(string[] args)
    {
        var s = Console.ReadLine();
        int c = 0;
        if (s[0] == '1') ++c;
        if (s[1] == '1') ++c;
        if (s[2] == '1') ++c;
        Console.WriteLine(c);
    }
}

Measured memory_bytes: 11092
from collections import deque
H, W = map(int, input().split())
padding = ['#' for _ in range(W + 2)]
Map = tuple([padding])
Map += tuple(['#'] + list(input()) + ['#'] for _ in range(H))
Map += tuple([padding])
dxy = [(1, 0), (-1, 0), (0, 1), (0, -1)]

done = [[-1 for _ in range(W + 2)] for _ in range(H + 2)]

q = deque()
push, pop = q.append, q.popleft
push((1, 1))
done[1][1] = 0
while q:
  y, x = pop()
  for dy, dx in dxy:
    if Map[y + dy][x + dx] == '.' and done[y + dy][x + dx] == -1:
      push((y + dy, x + dx))
      done[y + dy][x + dx] = done[y][x] + 1
  if done[H][W] != -1:
    break
    
cnt = 0
for i in range(1, H + 1):
  for j in range(1, W + 1):
    if Map[i][j] == '.':
      cnt += 1
ans = cnt - done[H][W] -1

print(ans if done[H][W] != -1 else -1)

Measured memory_bytes: 3700
#include <stdio.h>

int fibonacci(int);

int F[44];


int main(){
	int x;
	scanf("%d",&x);
	printf("%d\n",fibonacci(x));
	
	return 0;
}

int fibonacci(int n){
	if (n == 0 || n == 1) return F[n] = 1;
	if(F[n] != 0)return F[n];
	return F[n] = fibonacci(n-2) + fibonacci(n - 1);
}

Measured memory_bytes: 596
using System;
using System.Linq;

public class Pg
{
    readonly int[,] dir = new int[,]{{0,0},{-1,0}, {0,-1},{0,1},{1,0},{-1,-1},{-1,1},{1,-1},{1,1},{-2,0},{0,-2},{0,2},{2,0}};
    readonly int[] size = {0, 5, 9, 13};
    int[][] a;
    int[,] ans;
    int w, e;

    bool IsBad(int i, int j)
    {
        i -= 2;
        if (j < 3)
        {
            --i;
            j = 9;
        }
        else
            j -= 3;
        while (0 <= i && 0 <= j)
        {
            if (a[i][j] > 0)
                return true;
            if (j == 0)
            {
                --i;
                j = 9;
            }
            else
                --j;
        }
        return false;

    }

    bool IsOkay(int i, int j, int drop)
    {
        for (int k = 0; k < size[drop]; ++k)
        {
            int ni = i+dir[k,0], nj = j+dir[k,1];
            if (ni < 0 || 9 < ni || nj < 0 || 9 < nj || a[ni][nj] == 0)
                return false;
        }
        return true;
    }

    void main()
    {
        a = new int[10][];
        w = int.Parse(Console.ReadLine());
        e = 0;
        for (int i = 0; i < 10; ++i)
            a[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
        e = a.Sum(x => x.Sum());
        ans = new int[w, 3];
        CanFill(1, 1, 0, 3);
        var v =ans;
        for (int i = 0; i < w; ++i)
            Console.WriteLine($"{ans[i, 0]} {ans[i, 1]} {ans[i, 2]}");
    }
    bool CanFill(int i, int j, int k, int drop)
    {
        if (e == 0)
            return true;
        if (k == w)
            return false;
        if (IsBad(i, j))
            return false;
        if (drop < 1)
            return CanFill(i, j + 1, k, 3);
        if (i == 9)
            return false;
        if (j == 9)
            return CanFill(i + 1, 1, k, 3);
        if (a[i][j] == 0)
            return CanFill(i, j + 1, k, 3);
        if (IsOkay(i, j, drop))
        {
            for (int q = 0; q < size[drop]; ++q)
                a[i + dir[q, 0]][j + dir[q, 1]]--;
            ans[k, 0] = j;
            ans[k, 1] = i;
            ans[k, 2] = drop;
            e -= size[drop];
            if (CanFill(i, j, k + 1, drop))
                return true;
            e += size[drop];
            for (int q = 0; q < size[drop]; ++q)
                a[i + dir[q, 0]][j + dir[q, 1]]++;
        }
        return CanFill(i, j, k, drop - 1);
    }
   public static void Main() => new Pg().main();
}



Measured memory_bytes: 18548
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v, int idx)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        if (i == idx)
        {
            cout << "[" << v[i] << "]"
                 << " \n"[i == sz - 1];
            continue;
        }
        cout << v[i] << " \n"[i == sz - 1];
    }
}

int partition(vector<int> &a, int p, int r)
{
    int x = a[r];
    int i = p - 1;
    for (int j = p; j < r; j++)
    {
        if (a[j] <= x)
        {
            i++;
            swap(a[i], a[j]);
        }
    }
    swap(a[i + 1], a[r]);
    return i + 1;
}

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

    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    int idx = partition(a, 0, n - 1);
    printv(a, idx);
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	double sum=0;
	cin>>n;
	vector<int> a;
	for (int i=0;i<n;i++) {cin>>k;a.push_back(k);sum+=(double)1/a[i];}
	cout<<1/sum;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define RFOR(i,n1,n2) for(ll i=((ll)(n1)-1);i>=(ll)(n2);i--)
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
#define IOS cin.tie(0),ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }
template<class Type>struct is_vector : std::false_type {};
template<class ValueType, class Alloc>struct is_vector<std::vector<ValueType, Alloc>> : std::true_type {};
template <typename T> inline ostream& operator << (ostream& out, const vector<T>& v) {
	if (v.empty())return out;
	constexpr bool is_vector_v = is_vector<T>::value;
	if (is_vector_v)for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? "\n" : "");
	else for (auto itr = v.begin(); itr != v.end();)out << (*itr), out << ((++itr != v.end()) ? " " : "");
	return out;
}
inline void put() {}
template<class T> inline void put(const T& first) { std::cout << first << "\n"; }
template<class T, class... N> inline void put(const T& first, const N& ... rest) { std::cout << first << " "; put(rest...); }
inline void putn() {}
template<class T, class... N> inline void putn(const T& first, const N& ... rest) { std::cout << first << "\n"; putn(rest...); }

template <typename T>
vector<pair<int, T>> rle(vector<T> a)
{
	int n = (int)a.size();
	vector<pair<int, T>> res;
	if (n == 0)
	{
		return res;
	}
	T now = a[0];
	int con = 0;
	for (int i = 0; i < n; ++i)
	{
		if (a[i] == now)
		{
			con++;
		} else
		{
			res.push_back(pair<int, T>(con, now));
			now = a[i];
			con = 1;
		}
	}
	res.push_back(pair<int, T>(con, now));
	return res;
}


int main() {
	IOS;
	int n, k, q;
	cin >> n >> k >> q;
	vector<int> a(n);
	REP(i, n) {
		cin >> a[i];
	}
	int res = INT_MAX;
	REP(i, n) {
		vector<int> temp;
		vector<int> b(n);
		REP(j, n) {
			if (a[i] > a[j]) {
				b[j] = 0;
			} else {
				b[j] = 1;
			}
		}
		auto rl = rle(b);
		int cnt = 0;
		REP(j, rl.size()) {
			if (rl[j].second) {
				vector<int> c;
				REP(l, rl[j].first) {
					c.push_back(a[cnt + l]);
				}
				sort(all(c));
				REP(l, rl[j].first - k + 1) {
					temp.push_back(c[l]);
				}
			}
			cnt += rl[j].first;
		}
		if (temp.size() >= q) {
			sort(all(temp));
			chmin(res, temp[q-1]-a[i]);
		}
	}
	put(res);
	return 0;
}


Measured memory_bytes: 256
//Solution By SlavicG
#include <bits/stdc++.h>
using namespace std;
 
#define ll                          long long
 
#define forn(i,n)                   for(int i=0;i<n;i++)
#define all(v)                      v.begin(), v.end()
#define rall(v)                     v.rbegin(),v.rend()
	
#define pb                          push_back
#define sz(a)                       (int)a.size()
#define mp                          make_pair
 
#define   endl                       "\n"
#define fastio                       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

int  main()
{
	int n;
	cin >> n;
	vector<int> v;
	int a[n];
	for(int i=  0;i<n;i++)
	{
		cin >> a[i];
		v.pb(a[i]);
	}
	sort(all(v));
	for(int i = 0;i<n;i++)
	{
		if(abs(a[i] - v[i]) > 1)
		{
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
}

Measured memory_bytes: 4120
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2 * 1e5 + 5;
int pos[maxn];
int main(){
	int j = 0;
	string str;
	cin>>str;
	for(int i = 0; i < str.size();i++)
		if(str[i] == 'B') pos[j++] = i;
	long long k = str.size() - j ,sum = 0; 
	for(int i = 0; i < j ; i++){
		sum += k  - pos[i];
		k++;
    }
    printf("%lld\n",sum);
    return 0;
	}

Measured memory_bytes: 1284
n = gets.to_i
s = gets.to_s
A= s.split(" ")

puts A.join(' ')

for i in 1..n-1
      v = A[i].to_i
   j = i  - 1
   while j >= 0 && A[j].to_i > v
	  A[j + 1] = A[j]
	  j -= 1
   end
   
   A[j+1] = v	  
   puts A.join(' ')
end



Measured memory_bytes: 6936
/*
        AOJ - ALDS1_1_D
        Date: 20190310
        Author: Mikoron * ♡mikoiwate_351♡
*/

#define N 200001

#include<stdio.h>

int main(void) {
        int i, j, n, max_diff, min;
        int value;

        scanf("%d", &n);
        scanf("%d", &min);
        max_diff = -999999999;
        for(i = 1; i < n; i++) {
                scanf("%d", &value);
                if(max_diff < value - min) max_diff = value - min;
                if(min > value) min = value;
        }

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

        return 0;
}



Measured memory_bytes: 2112
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] num = new int[n];
		int s = 0;
		for (int i = 0; i < n; i++) {
			num[i] = scanner.nextInt();
			s += num[i];
		}
		boolean[] map = new boolean[s + 1];

		slove(0, 0, num, map);
		int m = scanner.nextInt();
		while (m-- > 0) {
			int a = scanner.nextInt();
			System.out.println(a <= s && map[a] ? "yes" : "no");
		}

	}

	private void slove(int i, int sum, int[] num, boolean[] map) {
		map[sum] = true;
		if (i == num.length)
			return;

		slove(i + 1, sum + num[i], num, map);
		slove(i + 1, sum, num, map);
	}
}

Measured memory_bytes: 20352
import os,sys
from io import BytesIO, IOBase

def ii(): return int(input())
def si(): return input()
def mi(): return map(int,input().split())
def li(): return list(mi())

mod=1000000007

import math  

for i in range(1):
    h,n=mi()
    a=li()
    if sum(a)>=h:
        print("Yes")
    else:
        print("No")

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

const ll MAXN = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;

ll L, R, D, ans=0, tmp=0;
vector<ll> A;

signed main(){
    cin >> L >> R >> D;
    ll l = L/D;
    if(L%D!=0) l++;
    ll r = R/D;
    cout << r-l+1 << endl;
    return 0;
}

Measured memory_bytes: 3620
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""
def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# a^n
def power(a,n,mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod

# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n-1
    while(tmp >= l):
        a = a*tmp%mod
        tmp -= 1
    return a

inf = 10**18
mod = 10**9+7

n = ir()
a = [ir() for i in range(n)]
a.sort()
ans = [0,0]

if n == 2:
    print(abs(a[1]-a[0]))
    sys.exit()

if n%2 == 0:
    for i in range(n//2-1):
        ans[0]-=2*a[i]
    ans[0]-=a[n//2-1]
    ans[0]+=a[n//2]
    for i in range(n//2+1,n):
        ans[0]+=2*a[i]

    for i in range(n//2):
        ans[1]-=2*a[i]
    ans[1]-=a[n//2]
    ans[1]+=a[n//2+1]
    for i in range(n//2+2,n):
        ans[1]+=2*a[i]
else:
    for i in range(n//2):
        ans[0]-=2*a[i]
    ans[0]+=a[n//2]
    ans[0]+=a[n//2+1]
    for i in range(n//2+2,n):
        ans[0]+=2*a[i]

    for i in range(n//2-1):
        ans[1]-=2*a[i]
    ans[1]-=a[n//2-1]
    ans[1]-=a[n//2]
    for i in range(n//2+1,n):
        ans[1]+=2*a[i]
print(max(ans))


Measured memory_bytes: 79476
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> pii;
#define rep(i, start, n) for (int i = (int)(start); i < (int)(n); ++i)
#define all(a) a.begin(), a.end()

const int MOD = 1e9+7;
const int INF = 1001001001;
int edge[8][8] {0};

int main(){
    int N, M;
    cin >> N >> M;
    rep(i, 0, M){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        edge[a][b] = 1;
        edge[b][a] = 1;
    }
    int ans = 0;
    vector<int> v(N-1);
    iota(v.begin(), v.end(), 1);
    do {
        int bef = 0;
        bool ok = true;
        for (auto now : v){
            if (edge[bef][now] != 1){
                ok = false;
            }
            bef = now;
        }
        if (ok){
            ans++;
        }
    } while(next_permutation(v.begin(), v.end()));
    cout << ans << endl;
}


Measured memory_bytes: 3576
#include<stdio.h>
#include<string.h>
int main(void){
  char S[10],T[10];
  int a,b;
  char U[10];
  
  scanf("%s %s",&S,&T);
  scanf("%d %d",&a,&b);
  scanf("%s",&U);
  
  if(strcmp(S,U)==0){
    printf("%d %d",a-1,b);
  }else{
    printf("%d %d",a,b-1);
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  int N;cin >> N;
  vector<ll> v(N),w(N);
  ll sum = 0;
  rep(i,N){
    cin >> v[i];
    sum -= v[i];
  }
  rep(i,N){
    cin >> w[i];
    sum += w[i];
  }

  bool sat =true;
  ll s = 0;
  rep(i,N) if(v[i]<w[i]) s += (w[i]-v[i]+1)/2;
  YesNo(s<=sum);
  return 0;
}


Measured memory_bytes: 384
/*input
2 2
##
##
*/

#include <bits/stdc++.h>

using namespace std;

const int MOD = 1e9 + 7;
const int N = 1004;

int dr[] = {-1, 0, 1, 0};
int dc[] = {0, 1, 0, -1};

int merge(int x, int y) {
  return x * N + y;
}

int getX(int c) {
  return c / N;
}

int getY(int c) {
  return c % N;
}

int h, w;
char s[N][N];

bool valid(int x, int y) {
  return x >= 0 && y >= 0 && x < h && y < w;
}

int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);

  cin >> h >> w;

  queue<int> q;
  for (int i = 0; i < h; ++i) {
    cin >> s[i];
    for (int j = 0; j < w; ++j) {
      if (s[i][j] == '#') q.push(merge(i, j));
    }
  }

  if (q.size() == (h * w)) {
    cout << 0;
    return 0;
  }

  int ans = 0, batch = q.size();
  while (!q.empty()) {
    auto el = q.front();
    q.pop();
    int x = getX(el);
    int y = getY(el);

    for (int i = 0; i < 4; ++i) {
      int xx = x + dr[i];
      int yy = y + dc[i];

      if (!valid(xx, yy)) {
        continue;
      }

      if (s[xx][yy] == '#') {
        continue;
      }

      s[xx][yy] = '#';
      q.push(merge(xx, yy));
    }

    batch--;
    if (batch == 0 && !q.empty()) {
      ans++;
      batch = q.size();
    }
  }

  cout << ans;

  return 0;
} 

Measured memory_bytes: 5376
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

x = inn()
pmax = x//100
for p in range(pmax+1):
    r = x - 100*p
    if r <= 5*p:
        print(1)
        exit()
print(0)


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

int main() {
	int N, l=0, r=0, S=0;
	cin >> N;

	for(int i = 0; i < N; i++)
	{
		cin >> l >> r;
		S += r - l + 1;
	}

	cout << S << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
)

const (
	SCANNER_BUF_SIZE = 2 << 20

	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var (
	writer  *bufio.Writer
	scanner *bufio.Scanner
)

func init() {
	writer = bufio.NewWriter(os.Stdout)
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, SCANNER_BUF_SIZE), SCANNER_BUF_SIZE)
}

func printf(f string, a ...interface{}) {
	fmt.Fprintf(writer, f, a...)
}

func sint64() int64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func suint64() uint64 {
	scanner.Scan()
	bb := scanner.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func sstring() string {
	scanner.Scan()
	return scanner.Text()
}

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

func main() {
	defer writer.Flush()
	n := sint64()
	k := sint64()
	p := make([]int64, n)
	for i := range p {
		p[i] = sint64()
	}
	sort.Slice(p, func(a, b int) bool {
		return p[a] < p[b]
	})
	ans := int64(0)
	for i := range p[:k] {
		ans += p[i]
	}
	printf("%d\n", ans)
}


Measured memory_bytes: 1820