akhauriyash/Code-Regression huggingface dataset:
package main

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

type TupleInt struct {
	first  int
	second int
}

func main() {
	sc := NewScanner()
	N := sc.NextInt()
	edge := make([][]TupleInt, N+1)
	for i := 0; i < N+1; i++ {
		edge[i] = make([]TupleInt, 0)
	}
	for i := 0; i < N-1; i++ {
		a, b := sc.NextInt(), sc.NextInt()
		edge[a] = append(edge[a], TupleInt{b, i})
		edge[b] = append(edge[b], TupleInt{a, i})
	}

	checked := make([]int, N-1)
	mx := 0
	var dfs func(parent int, p int, c int)
	dfs = func(parent int, p int, c int) {
		//fmt.Println(parent, p, c)
		b := 1
		set := map[int]bool{}
		set[c] = true
		for i := 0; i < len(edge[p]); i++ {
			nx := edge[p][i]
			if nx.first == parent {
				continue
			}
			for _, ok := set[b]; ok; b++ {
				_, w := set[b]
				if w == false {
					break
				}
			}
			set[b] = true
			checked[nx.second] = b
			if mx < b {
				mx = b
			}
		}
		for i := 0; i < len(edge[p]); i++ {
			nx := edge[p][i]
			if nx.first == parent {
				continue
			}

			dfs(p, nx.first, checked[nx.second])
		}
	}
	dfs(0, 1, -1)

	fmt.Println(mx)
	for i := 0; i < len(checked); i++ {
		fmt.Println(checked[i])
	}
}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 38272
// Shell_Sort.cs

using System;
using System.Collections.Generic;

class Shell_Sort {
    public static void Main() {

        int n = int.Parse(Console.ReadLine());
        int[] arr = new int[n];
        var list = new List<int>();

        for (int i = 0; i < n; i++) {
            arr[i] = int.Parse(Console.ReadLine());      
        }

        for(int i = 1; i <= n; i = i * 3 + 1) {
            list.Add(i);
        }

        int count = list.Count;
        int c = 0;

        for(int i = count - 1; i >= 0; i--) {
            for(int j = list[i]; j < n; j++) {

                int a = arr[j];
                int b = j - list[i];

                while(b >= 0 && arr[b] > a) {

                    arr[b + list[i]] = arr[b];
                    b -= list[i];
                    c++;
                    
                }

                arr[b + list[i]] = a;

            }
        }

        Console.WriteLine(count);

        for(int i = count - 1; i > 0; i--) {
            Console.Write("{0} ", list[i]);
        }

        Console.WriteLine(list[0]);
        Console.WriteLine(c);

        for(int i = 0; i < n; i++) {
            Console.WriteLine(arr[i]);
        }

    }
}

Measured memory_bytes: 16640
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <map>
#include <queue>
#include <cstring>
using namespace std;
typedef long long int ll;


int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	ll a,b,c; cin >> a >> b >> c;
	if(c-a-b<0){
		cout << "No" << endl;
	}else{
		if(4*a*b<(c-a-b)*(c-a-b)){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}
}


Measured memory_bytes: 256
A,B,H,M = gets.split.map(&:to_i)
h = (H + M/60.0)/12 * 2*Math::PI
m = M/60.0 * 2*Math::PI
hx,hy = A*Math.sin(h),A*Math.cos(h)
mx,my = B*Math.sin(m),B*Math.cos(m)
puts Math.sqrt((hx-mx)**2+(hy-my)**2)


Measured memory_bytes: 14744
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

# N = int(input())
# A = LI()

# tmp = 1000
# stocks = 0
# for i in range(N - 1):
#     if A[i] < A[i + 1]: # 明日の方が高い　買う
#         new_stocks = tmp // A[i]
#         stocks += new_stocks
#         tmp -= new_stocks * A[i]
#     else:# 明日の方が安い　うる
#         tmp += stocks * A[i]
#         stocks = 0
# tmp += stocks * A[-1]
# print(tmp)

N = int(input())
A = LI()

cash = 1000
stocks = 0
for i in range(N - 1): 
    if A[i] < A[i + 1]: # 明日の方が高いなら買えるだけ買い
        buy_stocks = cash // A[i]
        stocks += buy_stocks
        cash -= buy_stocks * A[i]
    else: # 値段が同じor安いなら全ての株を現金化しておく
        cash += stocks * A[i]
        stocks = 0
cash += stocks * A[-1] # 最終日には全てを現金化する
print(cash)



Measured memory_bytes: 10768
S = input()
T = input()
n = len(S)
t = len(T)
ans = ''
if t > n:
    flag = False
for i in range(t, n+1):
    flag = True
    for j in range(t):
        if S[-i+j] != '?' and S[-i+j] != T[j]:
            flag = False
            break
    if flag:
        break
if flag:
    for s in S[:-i]:
        if s == '?':
            ans += 'a'
        else:
            ans += s
    ans += T
    if i != t:
        for s in S[-i+t:]:
            if s == '?':
                ans += 'a'
            else:
                ans += s
    print(ans)
else:
    print('UNRESTORABLE')
            
            

Measured memory_bytes: 3064
/**
 *    author  : 𝒌𝒚𝒐𝒎𝒖𝒌𝒚𝒐𝒎𝒖𝒑𝒖𝒓𝒊𝒏
 *    created : 2020-03-11 21:32:37
**/

#include <iostream>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
#include <bitset>
#include <cassert>
#include <cctype>
#include <iomanip>
#include <random>
#include <utility>
#include <chrono>

using namespace std;

using int64 = long long;

template<class T> using binary_heap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) { os << '{'; size_t n = vec.size(); for (size_t i = 0; i < n; ++i) { os << vec[i]; if (i != n - 1) os << ','; } os << '}'; return os; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) { return os << '{' << p.first << " " << p.second << '}'; }
template<class T, class U> std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) { os << '{'; for (auto it = mp.begin(); it != mp.end(); ++it) { os << '{' << it->first << ':' << it->second << '}'; if (it != --mp.end()) os << ','; } os << '}'; return os; }
template<class T> std::ostream& operator<<(std::ostream& os, const std::set<T>& st) { os << '{'; for (auto it = st.begin(); it != st.end(); ++it) { os << *it; if (it != --st.end()) os << ','; } os << '}'; return os; }
template<class T> std::istream& operator>>(std::istream& is, std::vector<T>& vec) { size_t n = vec.size(); for (size_t i = 0; i < n; ++i) is >> vec[i]; return is; }

#define all(_) begin(_), end(_)
#define rall(_) rbegin(_), rend(_)

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...) 1728
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}

using graph = std::vector<std::vector<int>>;

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

  int n, q; cin >> n >> q;
  graph g(n);
  for (int i = 0; i < n - 1; ++i) {
    int a, b; cin >> a >> b;
    --a; --b;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }

  vector<int> counter(n, 0);

  for (int i = 0; i < q; ++i) {
    int p, x; cin >> p >> x; --p;
    counter[p] += x;
  }

  auto dfs = [&](const auto& dfs, int cur, int prev) -> void {
    for (int next : g[cur]) {
      if (next == prev) continue;
      counter[next] += counter[cur];
      dfs(dfs, next, cur);
    }
  };

  dfs(dfs, 0, -1);

  for (int i = 0; i < n; ++i) {
    cout << counter[i] << " ";
  }

  return 0;
}

Measured memory_bytes: 20736
#include <stdio.h>

int	main(void)
{
  	char	s[3];
  	char	t[3];
 	int 	num;
  	int		count;
  	int		i;
  	
  	num = scanf("%s\n", s);
  	if (num != 1)
      	return (0);
  
  	num = scanf("%s\n", t);
  	if (num != 1)
      	return (0);
  
  	count = 0;
  	for (i=0; i<3; i++)
    {
      	if (s[i] == t[i])
      	{
          	count++;
      	}
    }
  
  	printf("%d", count);
  	return (0);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int digit(int N)
{
	int tmp, t = N;
	while (t >= 1)
	{
		tmp += (t % 10);
		t /= 10;
	}
	return tmp;
}
int main()
{
	int n;
	cin >> n;
	int d = digit(n);
	if (n % d == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    xyp = [list(map(int, input().split())) for _ in [0]*n]
    d = []

    def calc(seq):
        m = len(seq)
        dp = [[10**15]*(m+1) for _ in [0]*(m+1)]
        dp[0][0] = 0
        for i in range(m):
            s = seq[i][0]
            for j in range(i+1):
                temp = dp[j][0]
                for a, b in seq[:i+1]:
                    temp += min(abs(a), s-a)*b
                dp[j+1][i+1] = min(dp[j+1][i+1], temp)
                temp2 = 10**15
                for k in range(1, i+1):
                    temp = dp[j][k]
                    t = seq[k-1][0]
                    for a, b in seq[k:i+1]:
                        temp += min(abs(a), a-t, s-a)*b
                    temp2 = min(temp2, temp)
                dp[j+1][i+1] = min(dp[j+1][i+1], temp2)
        for i in range(m+1):
            for a, b in seq[:m]:
                dp[i][0] += abs(a)*b
            for k in range(1, m+1):
                t = seq[k-1][0]
                temp = 0
                for a, b in seq[k:m]:
                    temp += min(abs(a), a-t)*b
                dp[i][k] += temp
        for i in range(m+1):
            dp[i] = min(dp[i])
        dp += [0]*(n-m)
        return dp

    xyp.sort()
    for i in range(2**n):
        x_list, y_list = [], []
        for j in range(n):
            x, y, p = xyp[j]
            if i & 1:
                x_list.append([x, p])
            else:
                y_list.append([y, p])
            i >>= 1
        y_list.sort()
        d.append([calc(x_list), calc(y_list)])

    ans = [10**15]*(n+1)
    for x, y in d:
        for i in range(n+1):
            for j in range(n-i+1):
                ans[i+j] = min(ans[i+j], x[i]+y[j])
    for i in ans:
        print(i)


main()


Measured memory_bytes: 117128
#include <iostream>
using namespace std;
int x,y;
int main(void)
{
    cin>>x>>y;
    if(4*x<y||y<2*x)cout<<"No"<<endl;
    else
    {
        if((4*x-y)%2)cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3604
import java.util.*;
public class Main{

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		/*String[] s = stdIn.next().split("");
		boolean flag = false;
		Arrays.sort(s);
		
		for(int i = 0; i < s.length-1; i++) {
			if(s[i].equals(s[i+1])) {
				flag = true;
			}
		}
		if(flag) {
			System.out.println("no");
		}else {
			System.out.println("yes");
		}
		*/
		String s = stdIn.next();
		boolean flag = false;
		
		for(int i = 0; i < s.length(); i++) {
			for(int j = i+1; j < s.length(); j++) {
				if(s.charAt(i)==s.charAt(j)) {
					flag = true;
				}
			}
		}
		
		if(flag) {
			System.out.println("no");
		}else {
			System.out.println("yes");
		}
	}

}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair 
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
typedef pair<int,int> pii;
typedef long long ll;	


string s;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	cin >> s;
	if (s[s.size()-1] != 's') {
		s += "s";
	}
	else {
		s += "es";
	}
	cout << s << "\n";
	return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
# define fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define all(v) v.begin(),v.end()
typedef long long ll;

void IO()
{
	#ifndef ONLINE_JUDGE
			freopen("input.txt","r",stdin);
			freopen("output.txt","w",stdout);
	#endif 
}


vector<int> used(200000);
vector<int> adj[200000];
vector<int> a,b;

void bfs(int i)
{	
queue<int> q;
	q.push(i);
	used[i] = 1;
	a.push_back(i);
	while(!q.empty())
	{	i = q.front();
		q.pop();
		for(auto vertex:adj[i])
		{	
			if(used[vertex]==-1)
			{
				used[vertex] = used[i]^1;
				if(used[vertex]==1) a.push_back(vertex);
				else b.push_back(vertex);
				q.push(vertex);
			}
			if(used[vertex]==used[i]){
				cout<<-1;
				exit(0);
			}
			
			
		}


	}
}

void solve()
{
int n;cin>>n;
int a[n];
for(int i=0;i<n;i++)
	cin>>a[i];
ll dp[n] = {0};
dp[1] = abs(a[0]-a[1]);
dp[2] = abs(a[0]-a[2]);
for(int i = 3;i<n;i++)
{
dp[i] = min(dp[i-1] + abs(a[i-1]-a[i]) ,  dp[i-2] + abs(a[i-2]-a[i]));
}
cout<<dp[n-1];
}


int main()
{
	IO();
	fast;

	// int t;cin>>t;while(t--)
	solve();

				

	return 0;
}





Measured memory_bytes: 9780
#include<iostream>
#include<algorithm>
using namespace std;
int n,arr[100005][3],dp[100005][3];
int main()
{
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<3;j++){
			cin>>arr[i][j];
		}
	}
	dp[0][0]=arr[0][0];
	dp[0][1]=arr[0][1];
	dp[0][2]=arr[0][2];
	for(int i=1;i<n;i++){
		dp[i][0]=max(dp[i-1][1]+arr[i][0],dp[i-1][2]+arr[i][0]);
		dp[i][1]=max(dp[i-1][0]+arr[i][1],dp[i-1][2]+arr[i][1]);
		dp[i][2]=max(dp[i-1][1]+arr[i][2],dp[i-1][0]+arr[i][2]);
	}
	cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
	return 0;
}

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

using namespace std;
 
/// ----------------------------- (Debug) ------------------------------
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";}
sim dor(rge<c> d) {*this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]";}
#else
sim dor(const c&) { ris; }
#endif
};
vector<char*> tokenizer(const char* args) {
	char *token = new char[111]; strcpy(token, args); token = strtok(token, ", ");
	vector<char*> v({token});
	while(token = strtok(NULL,", ")) v.push_back(token);
	return reverse(v.begin(), v.end()), v;
}
void debugg(vector<char*> args) { cerr << "\b\b "; }
template <typename Head, typename... Tail>
void debugg(vector<char*> args, Head H, Tail... T) {
	debug() << " [" << args.back() << ": " << H << "] ";
	args.pop_back(); debugg(args, T...);
}
#define harg(...) #__VA_ARGS__
#ifndef ONLINE_JUDGE
#define dbg(...) { debugg(tokenizer(harg(__VA_ARGS__, \b\t-->Line)), __VA_ARGS__, __LINE__); cerr << endl;}
#else
#define dbg(...) { }
#endif
/// -----------------------------------------------------------------------
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi; 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)    
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define print(x) cout << x << "\n";
#define REP(i,a,b) for(i=a;i<=b;i++)
#define RAP(i,a,b) for(i=a;i>=b;i--)
#define spa <<" "<<
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
ll mod=1e9+7;
const int MX=0x3f3f3f3f;

int main(){
	IOS;
	int l,r,d,ans=0,i;
	cin>>l>>r>>d;
	REP(i,l,r) if(i%d==0) ans++;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3616
// Problem: C - Sum of product of pairs
// Contest: AtCoder - AtCoder Beginner Contest 177
// URL: https://atcoder.jp/contests/abc177/tasks/abc177_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define pb push_back
#define mp make_pair
#define y1 y114514
#define elif else if
#define VPII vector <PII>
#define y2 y1919810
typedef pair <int, int> PII;
typedef vector <int> VI;
#define int long long
#define all(x) x.begin(),  x.end()
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define repn(i, n) for (int i = 1; i <= (int)n; i++)
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define range(i, s, t)  for (int i = s; i <= (int)t; i++)
#define RESET(x) memset((x), 0, sizeof(x))
const int INF = 0x3f3f3f3f;
const long double EPS = 1e-6;
const int N = 200200;
const int mod  = 1e9 + 7;
int a[N]; int n; int sum[N];
void solve() {
  cin >> n;
  repn(i, n) {
    cin >> a[i];
  }
  int ans = 0;
  for (int i = n; i >= 1; i--) sum[i] = (sum[i + 1] + a[i]) % mod;
  repn(i, n - 1) ans = (ans + sum[i + 1] * a[i] % mod) % mod;
  cout << ans << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr); cout.tie(nullptr);
  int T = 1;
  // cin >> T;
  while (T--) 
    solve();
  return 0;
}


Measured memory_bytes: 6708
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <set>
#include <sstream>
#include <numeric>
#include <bitset>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cctype>
#include <cassert>
using namespace std;

typedef long long ll;
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
bool ISINT(double x){return fabs(x-(int)x)<EPS;}
bool ISEQ(double x,double y){return fabs(x-y)<EPS;}
string itos(ll x){stringstream ss;ss<<x;return ss.str();}
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define EREP(i,a,b) for(int i=a;i<=b;i++)
#define erep(i,n) EREP(i,0,n)
#define foreach(itr,c) for(__typeof(c.begin()) itr=c.begin();itr!=c.end();itr++)

struct P{
  bool wall[4];
}t[200][200];

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

int main(void){
  while(scanf("%d%d%d",&w,&h,&n),w||h||n){
    memset(t,0,sizeof(t));
    rep(i,h) t[i][0].wall[3] = t[i][w-1].wall[1] = true;
    rep(j,w) t[0][j].wall[0] = t[h-1][j].wall[2] = true;

    rep(i,n){
      int fx,fy,tx,ty;
      scanf("%d%d%d%d",&fx,&fy,&tx,&ty);
      if(fx > tx) swap(fx,tx);
      if(fy > ty) swap(fy,ty);

      if(fx == tx){
        REP(i,fy,ty){
          t[i][fx-1].wall[1] = t[i][fx].wall[3] = true;
        }
      }
      else{
        REP(j,fx,tx){
          t[fy-1][j].wall[2] = t[fy][j].wall[0] = true;
        }
      }
    }

    int x1,y1,x2,y2,gx,gy;
    scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&gx,&gy);

    if(x1 > x2) swap(x1,x2);
    if(y1 > y2) swap(y1,y2);

    int x=x1,y=y1,d=0;
    if(x1 == x2){
      if(x1 == 0){
        d = 1;
      }
      else{
        d = 3;
        x--;
      }
    }
    else{
      if(y1 == 0){
        d = 2;
      }
      else{
        d = 0;
        y--;
      }
    }

    int res = 1;
    bool flg = true;
    bool used[102][102][4];
    memset(used,0,sizeof(used));

    while(x != gx || y != gy){
      if(used[x][y][d]){
        flg = false;
        break;
      }
      used[x][y][d] = true;

      if(!t[y][x].wall[(d+1)%4]){
        d = (d+1)%4;
        x += dx[d];
        y += dy[d];
        res++;
      }
      else if(!t[y][x].wall[d]){
        x += dx[d];
        y += dy[d];
        res++;
      }
      else{
        d = (d + 3) % 4;
      }
    }

    if(flg){
      printf("%d\n",res);
    }
    else{
      printf("Impossible\n");
    }
  }
}

Measured memory_bytes: 1088
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
typedef long long ll;
int main() {
	int N, M;
	cin >> N >> M;
	scc_graph G(N);
	for (int i = 0; i < M; ++ i) {
		int u, v;
		cin >> u >> v;
		G.add_edge(u, v);
	}
	auto scc = G.scc();
	cout << scc.size() << endl;
	for (auto& a : scc) {
		cout << a.size();
		for (auto x : a) cout << " " << x;
		cout << endl;
	}
}


Measured memory_bytes: 40088
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e10;
const ll MAX_N = 1010;

//組み合わせの余りを求める
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];

void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX_N; i++) {
		fac[i] = fac[i - 1] * i;
	}
}

// 二項係数計算
long long COM(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	if (n > k * 2) {

	}
	return fac[n] / (fac[k] * fac[n - k]);
}

ll dp[201010][2];
ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
char c[10][10];
bool flag[10][10];
bool flag2[10][10];

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll l, r, d;
	cin >> l >> r >> d;
	ll ans = 0;
	for (ll i = l;i <= r;++i) {
		if (i % d == 0)ans++;
	}
	cout << ans << endl;
	return 0;
}

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

signed main(){

  int n; cin >> n;
  map<int,int> mp;
  for(int i = 0; i < n; i++){
    int a; cin >> a;
    mp[a]++;
  }

  int ans = 0;
  for(auto p = mp.rbegin(); p != mp.rend(); p++){
    int t = 1;
    while(p->first > t) t *= 2;
    if(p->first == t && p->second >= 2){
      ans += p->second/2;
      mp[p->first] /= 2;
      continue;
    }
    if(mp.find(t-p->first) != mp.end()){
      while(mp[p->first] > 0 && mp[t-p->first] > 0){
        mp[p->first]--;
        mp[t-p->first]--;
        ans++;
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    vector<pair<int,int>> dish;

    int minT=INT_MAX,minIdx;
    rep(i,0,5){
        int time; cin>>time;
        if(minT>time%10 && time%10!=0){minT=time%10;minIdx=i;}
        dish.push_back(make_pair(time,ceil(time/10.0)*10));
    }

    int ans=0;
    rep(i,0,5){
        if(i==minIdx) ans+=dish.at(i).first;
        else ans+=dish.at(i).second;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
import Data.List
import Data.Char
import qualified Data.ByteString.Char8 as BS8
 
main :: IO ()
main = do
    [a, b] <- unfoldr (BS8.readInt . BS8.dropWhile isSpace) <$> BS8.getLine

    putStrLn $ if abs ((a - b) `mod` 2) == 0
        then show $ abs (abs (a - b) `div` 2 - maximum [a, b])
        else "IMPOSSIBLE"


Measured memory_bytes: 380
N, M = map(int,input().split())

from1 = set()
gotoN = set()

for i in range(M):
	a, b = map(int,input().split())
	if a == 1:
		from1.add(b)
	elif a == N:
		gotoN.add(b)

	if b == 1:
		from1.add(a)
	elif b == N:
		gotoN.add(a)

res = from1 & gotoN

print("POSSIBLE" if len(res) > 0 else "IMPOSSIBLE")

Measured memory_bytes: 18892
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

void solve(int n) {
    VI d(n);
    for_each(ALL(d), [](auto &e){cin >> e;});
    set<int> se;
    FORE(e, d) se.insert(e);
    if (n >= 2) REP(i, n - 1) {
        int num = d[i] * 10 + d[i + 1];
        se.insert(num);
    }
    if (n >= 3) REP(i, n - 2) {
        int num = d[i] * 100 + d[i + 1] * 10 + d[i + 2];
        se.insert(num);
    }
    REP(i, 1001) {
        if (!FIND(se, i)) {
            cout << i << endl;
            break;
        }
    }
    return;
}

signed main(void) {
    int n, m, p, a, b, c, x, y, z, q;
    string s;
    bool f = false;
    while (cin >> n) {
        solve(n);
        return 0;
    }
}

Measured memory_bytes: 3152
#include<bits/stdc++.h> 
typedef long long LL;
using namespace std;
namespace IO{
	const int __buffsize = 1000000;char __buff[__buffsize];char *__buffS, *__buffT;
	char getch(){if (__buffS == __buffT){__buffT = (__buffS = __buff) + fread(__buff,1,__buffsize,stdin);if (__buffS == __buffT) return EOF;}return *__buffS++;}
	#define getch getchar
	int read(){int T = 0,f = 1;char c = getchar();while((c<'0'||c>'9')&&(c!='-'))c=getchar();if(c=='-')f=-1,c=getchar();while(c>='0'&&c<='9'){T=((T<<1)+(T<<3))+c-48;c=getchar();}return T*f;}
	void write(int x){if(x < 0) putchar('-'),x = -x;if (x>=10) write(x / 10);putchar((x % 10)+'0');}
	void writeln(int x){write(x);puts("");}
};
using namespace IO;
inline bool cmp(pair<int,int> a,pair<int,int> b){
	return a.second<b.second;
}
#define mid ((l+r)>>1)
#define lson (o<<1)
#define rson (o<<1|1)
const int maxn = 300005;
int t[300005 << 2],add[300005 << 2];
int h,w;
pair<int,int> a[maxn],q1[maxn],q2[maxn];
int top1,top2;
#define mp make_pair
void build(int o,int l,int r){
	if (l==r) {
		t[o] = w - a[l].second;
		return ;
	}
	build(lson,l,mid);
	build(rson,mid+1,r);
	add[o] = 0;
	t[o] = max(t[lson],t[rson]);
}
void del(int o,int l,int r,int x,int y,int s){
	if(x>y) return;
	if (l == x && y == r){
		t[o] += s;
		add[o] += s;
		return;
	}
	if (l<=x&&y<=mid) del(lson,l,mid,x,y,s); else
	if (mid+1<=x&&y<=r) del(rson,mid+1,r,x,y,s); else
	del(lson,l,mid,x,mid,s),del(rson,mid+1,r,mid+1,y,s);
	t[o] = max(t[lson],t[rson]) + add[o];
}

int n,ans;

void solve(){
	sort(&a[1],&a[n+1],cmp);
	build(1,0,n);
	q1[0].first = q2[0].first = -1;
	q1[top1 = 1] = mp(0,0);
	q2[top2 = 1] = mp(0,w);
	for (int i=1;i<=n;i++){
		ans = max(ans,t[1] + a[i].second);
		if (a[i] . first <= (w>>1)){
			while (top1 && a[i].first > q1[top1] . second){
				del(1,0,n,q1[top1-1].first+1,q1[top1].first,q1[top1].second - a[i].first);
				top1--;
			}
			q1[++top1] = mp(i-1,a[i].first);
		} else{
			while (top2 && a[i].first < q2[top2] . second){
				del(1,0,n,q2[top2-1].first+1,q2[top2].first,a[i].first - q2[top2].second);
				top2--;
			}
			q2[++top2] = mp(i-1,a[i].first);
		}
		q1[++top1] = mp(i,0);
		q2[++top2] = mp(i,w);
	}
	ans = max(ans,t[1] + h);
}

int main(){
	w = read();
	h = read();
	n = read();
	for (int i=1;i<=n;i++)
		a[i].first = read(),a[i].second = read();
	solve();
	swap(w,h);
	for (int i=1;i<=n;i++)
		swap(a[i].first,a[i].second);
	solve();
	printf("%lld\n",ans*2);
	return 0;	
}

Measured memory_bytes: 15488
/*
 * @Author: Kaizyn
 * @Date: 2020-06-13 19:58:00
 * @LastEditTime: 2020-06-13 20:05:30
 */ 
#include <bits/stdc++.h>

// #define DEBUG

using namespace std;

const double eps = 1e-7;
const double PI = acos(-1);
typedef pair<int, int> pii;
const int MOD = 998244353;
const int INF = 0x3f3f3f3f;

int a, b, v, w, t;

inline void solve() {
  cin >> a >> v >> b >> w >> t;
  if (v < w || (v == w && a != b)) return cout << "NO" << endl, void();
  cout << (abs(a-b) <= 1ll*(v-w)*t ? "YES" : "NO") << endl;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  int T = 1;
  // cin >> T;
  for (int t = 1; t <= T; ++t) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 3648
from collections import Counter

def m():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort(reverse=True)
    ans = A[0]
    c = Counter(A[1:])
    d = list(c.items())
    d.sort(reverse=True, key=lambda x:x[0])
    tmp = []
    for k,v in d:
        for i in range((v-1)+(v+1)):
            tmp.append(k)
    ans += sum(tmp[:N-2])
    return ans
print(m())

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

public class Main
{
	public static void main(String [] Args)
	{
		Scanner in=new Scanner(System.in);		
		int n=in.nextInt();
		int [] p=new int [n];
		for(int i=0;i<n;i++)
		{
			p[i]=in.nextInt();
		}
		int ans=0;
		Arrays.sort(p);
		System.out.println(p[n/2]-p[n/2-1]);
	}
}
	

Measured memory_bytes: 51532
#include <bits/stdc++.h>
#define pq priority_queue
#define P pair<int, int>
#define P2 pair<int, P>
#define P3 pair<int, P2>
using namespace std;
typedef long long ll; typedef long double ld;
constexpr int gcd(int a, int b){return b ? gcd(b, a % b) : a;}
constexpr int lcm(int a, int b){return a / gcd(a, b) * b;}
constexpr int INF = 1e9, MOD = INF + 7, around[] = {0, 1, 1, -1, -1, 0, -1, 1, 0, 0};
constexpr int inv(const int x){ll n=MOD-2,ret=1,pos=x;while(n){if(n&1)(ret*=pos)%=MOD;(pos*=pos)%=MOD;n>>=1;}return ret;}
template<int n> struct Factorial{ll arr[n+1],ary[n+1];constexpr Factorial():arr(),ary(){arr[0]=1;ary[0]=1;for(int i=0;i<n;i++){arr[i+1]=arr[i]*(i+1)%MOD;ary[i+1]=inv(arr[i+1]);}}};
constexpr Factorial<10> fact;
constexpr int comb(int a, int b){ll pos = fact.arr[a], pot = fact.ary[a - b], por = fact.ary[b];return pos * pot % MOD * por % MOD;}
constexpr int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};
constexpr int sqrtN = 512, logN = 32;
constexpr ld PI = abs(acos(-1));
constexpr ll LINF=1e18;

struct Node{
	int data, ind;
	
	Node(int data, int ind) : data(data), ind(ind) {}
	Node operator*(const Node r){return data < r.data ? *this : r;}
} e(INF, INF);

struct SegmentTree{
	vector<Node> seg;
	int sz = 1;
	
	SegmentTree(int n){
		while(sz < n) sz *= 2;
		seg.assign(sz * 2, e);
	}
	
	void update(int k, int x){
		k += sz - 1;
		seg[k] = Node(x, k - (sz - 1));
		while(k){
			k = (k - 1) / 2;
			seg[k] = seg[2 * k + 1] * seg[2 * k + 2];
		}
	}
	
	Node get(int a, int b){
		return get(a, b, 0, 0, sz);
	}
	
	Node get(int a, int b, int k, int l, int r){
		if(b<=l||r<=a) return e;
		if(a<=l&&r<=b) return seg[k];
		
		return get(a, b, 2 * k + 1, l, (l + r) / 2) * get(a, b, 2 * k + 2, (l + r) / 2, r);
	}
};

SegmentTree seg[2](200010);
vector<int> g[200010];
int a[200010];
P ans[200010];
int c = 0;

void dfs(int l, int r, int par = 0){
	if(l >= r) return;
	
	g[par].push_back(++c);
	int pos = c;	
	if(l % 2 == 0){
		Node p = seg[0].get(l, r);
		Node q = seg[1].get(p.ind, r);
		seg[0].update(p.ind, INF);
		seg[1].update(q.ind, INF);
		ans[pos] = {p.data, q.data};

		dfs(l, p.ind, par);
		dfs(p.ind + 1, q.ind, pos);
		dfs(q.ind + 1, r, par);
	}else{
		Node p = seg[1].get(l, r);
		Node q = seg[0].get(p.ind, r);
		seg[1].update(p.ind, INF);
		seg[0].update(q.ind, INF);
		ans[pos] = {p.data, q.data};
		
		dfs(l, p.ind, par);
		dfs(p.ind + 1, q.ind, pos);
		dfs(q.ind + 1, r, par);
	}
}

int main(){
	int n; cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n; i++) seg[i % 2].update(i, a[i]);
	dfs(0, n);
	
	pq<P, vector<P>, greater<P>> qu;
	for(auto e:g[0]) qu.push({ans[e].first, e});
	while(!qu.empty()){
		auto p = qu.top(); qu.pop();
		
		cout << ans[p.second].first << " " << ans[p.second].second << " ";
		for(auto e:g[p.second]) qu.push({ans[e].first, e});
	}
	cout << endl;
	return 0;
}


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

int main() {
  long long N;
  cin >>N;
  int keta=log10(N)+1;
  if(keta==1){
    cout<<N<<endl;
    return 0;
  }
  vector <int> d(20,0);
  int i=0;
  while(N>0){
    d[i]=N%10;
    N=N/10;
    i++;
  }
  int sumketa=0;
  for(int i=0;i<keta;i++){
    sumketa=sumketa+d[i];
  }
  
  //cout<<d[keta-1]<<" "<<keta<<" "<<sumketa<<endl;
  
    
  if(((keta-1)*9+d[keta-1])==sumketa){
    cout<<sumketa<<endl;
    return 0;
  }
  else cout<<d[keta-1]-1+(keta-1)*9<<endl;
  return 0;
}

    
    

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

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

const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    map <string, int> x;
    int n, mx = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        x[s]++;
        chmax(mx, x[s]);
    }
    //sort(x.begin(), x.end());
    for (auto tmp: x) {
        if (tmp.second == mx) cout << tmp.first << endl;
    }
    return 0;
}



Measured memory_bytes: 25216
s = input()

bb = ""
b = ""
ans = -1
end = -1
for i in range(len(s)):
    if s[i] == b:
        ans = i
        end = i+1
        break
    elif s[i] == bb:
        ans = i-1
        end = i+1
        break
    else:
        bb = b
        b = s[i]


print(ans,end)

Measured memory_bytes: 69980
#include <stdio.h>
#include <string.h>
int main(){
  int a=0;
  char S[4];
  scanf("%s",&S);
  for(int i=0;i<4;i++){
  if(S[i]=='+')a+=1;
    else a-=1;
  }
  printf("%d",a);
  return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define F first
#define S second
#define MEM(i,j) memset(i,j,sizeof i)
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define ET cout << "\n"
#define DB(a,s,e) {for(int i=s;i<e;i++) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll m,dp[100005],ans[100005];
vector<ll> G[100005],rG[100005],Gdp[100005];

void dfs(ll u,ll f)
{
	vector<ll> v,vv;
	dp[u]=1;
	for(ll i:G[u])
		if(i!=f) dfs(i,u),v.pb(dp[i]+1),dp[u]=dp[u]*(dp[i]+1)%m,rG[u].pb(i);
	vv=v;
	for(ll i=(ll)vv.size()-2;i>=0;--i)
		vv[i]=vv[i]*vv[i+1]%m;
	for(ll i=1;i<v.size();++i)
		v[i]=v[i]*v[i-1]%m;
	if(vv.size()>=2) Gdp[u].pb(vv[1]);
	else Gdp[u].pb(1);
	for(ll i=1;i+1<v.size();++i)
		Gdp[u].pb(v[i-1]*vv[i+1]%m);
	if(vv.size()>=2) Gdp[u].pb(v[v.size()-2]);
}

void dfs2(ll u,ll x)
{
	ans[u]=(x+1)*dp[u]%m;
	for(ll i=0;i<rG[u].size();++i)
		dfs2(rG[u][i],(x+1)*Gdp[u][i]%m);
}

int main()
{jizz
	ll n,L,a,b;
	cin >> n >> m;
	for(int i=1;i<n;++i)
		cin >> a >> b,G[a].pb(b),G[b].pb(a);
	dfs(1,1),dfs2(1,0);
	for(int i=1;i<=n;++i)
		cout << ans[i] << "\n";
}

Measured memory_bytes: 30208
#include <iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<limits.h>

#define MOD 1000000007


using namespace std;

long long int modpow(long long int a, int n) {

	if (n == 0)return 1;
	if (n == 1) return a;

	long long int wk = modpow(a, n / 2);

	long long int ret = 0;
	if (n % 2 == 0) {
		ret = 1;
	}
	else {
		ret = a;
	}

	return (((ret * wk) % MOD) * wk) % MOD;

}

long long int gcd(long long int a, long long int b) {
	long long int tmp;
	if (a < b) {
		tmp = a;
		a = b;
		b = tmp;
	}

	long long int r = a % b;

	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	return b;
}

long long int lcm(long long int a, long long int b) {

	long long int wk_int;

	wk_int = (a * b) % MOD;
	
	long long int ret;

	ret = (wk_int * modpow(gcd(a, b), MOD - 2)) % MOD;

	return ret;

}

bool isPrime(int n) {
	if (n == 1)return false;
	if (n == 2)return true;

	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}

	return true;
}








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

	int waza = 0;
	int wk;
	for (int i = 0; i < n; i++) {
		cin >> wk;
		waza += wk;
	}

	if (h <= waza) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}



	





	return 0;

}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 100005;
int a[MAXN],n,m,p[MAXN],ret[MAXN],t[MAXN];
typedef long long ll;
ll k,d[MAXN];
inline void ksm(ll k)
{
	for(int i=1;i<=n;++i)ret[i]=i;
	while(k){
		if(k&1){
			for(int i=1;i<=n;++i)ret[i]=p[ret[i]];
		}
		for(int i=1;i<=n;++i)t[i]=p[i];
		for(int i=1;i<=n;++i)p[i]=t[p[i]];
		k>>=1;
	}
}
int v[MAXN],ans[MAXN];
int main()
{
	cin>>n;
	for(int i=1;i<=n;++i)scanf("%d",a+i),d[i]=a[i]-a[i-1],v[i]=i;
	cin>>m>>k;
	for(int i=1;i<=m;++i){
		int x;
		scanf("%d",&x);
		swap(v[x],v[x+1]);
	}
        for(int i=1;i<=n;++i)p[v[i]]=i;
	ksm(k);
        ll sum=0;
	for(int i=1;i<=n;++i)ans[ret[i]]=i;
	for(int i=1;i<=n;++i)
		printf("%lld\n",sum+=d[ans[i]]);
	return 0;
}


Measured memory_bytes: 4352
from collections import defaultdict

n=int(input())
a=sorted(map(int,input().split()))

s=defaultdict(int)
wild=0
for x in a:
    if x>=3200:
        wild+=1
    else:
        s[x//400]+=1

mn=len(s)+(len(s)==0)
mx=len(s)+wild

print(mn,mx)


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

int x_tar[10];
int y_tar[10];
int x[10];
int y[10];

//頂点0を中心に時計回りに90度回転
void rotate(int m)
{
	int newx,newy;
	for(int i=1;i<m;i++)
	{
		newx=(y[i]-y[0]);
		newy=-1*(x[i]-x[0]);
		// if(i==1)
		// 	cerr<<x[i]<<" "<<y[i]<<endl;
		x[i]=newx;
		y[i]=newy;
	}
	return;
}

//回転しながら同じものか確かめる
bool check(int m)
{
	bool f=true;
	for(int i=0;i<4;i++)
	{
		f=true;
		for(int j=0;j<m;j++)
		{
			if(!(x[j]==x_tar[j] && y[j]==y_tar[j]))
			{
				f=false;
				break;
			}
		}
		if(f)
			return true;
		rotate(m);
	}
	return false;
}

int main()
{
	int n;
	int m_tar;
	int m;
	while(1)
	{
		cin>>n;
		if(n==0)
			break;
		//探索元
		cin>>m_tar;
		for(int i=0;i<m_tar;i++)
			cin>>x_tar[i]>>y_tar[i];
		for(int i=m_tar-1;i>-1;i--)
		{
			x_tar[i]-=x_tar[0];
			y_tar[i]-=y_tar[0];
		}
		//ここから探索
		for(int i=0;i<n;i++)
		{
			cin>>m;
			for(int j=0;j<m;j++)
				cin>>x[j]>>y[j];
			if(m!=m_tar)
				continue;
			//頂点0を目標と同じ位置に移動する
			int xdif=x_tar[0]-x[0];
			int ydif=y_tar[0]-y[0];
			//cerr<<xdif<<" "<<ydif<<endl;
			for(int j=0;j<m;j++)
			{
				x[j]+=xdif;
				y[j]+=ydif;
			}
			//cerr<<x[0]<<" "<<y[0]<<endl;
			//頂点0を中心に回転しつつ同じか調べる
			if(check(m))
			{
				cout<<i+1<<endl;
				continue;
			}
			//始点と終点を逆にしてもう一度調べる
			reverse(x,x+m);
			reverse(y,y+m);
			//補正をやり直す
			xdif=x_tar[0]-x[0];
			ydif=y_tar[0]-y[0];
			for(int j=0;j<m;j++)
			{
				x[j]+=xdif;
				y[j]+=ydif;
			}
			if(check(m))
				cout<<i+1<<endl;
		}
		cout<<"+++++"<<endl;
	}
}


Measured memory_bytes: 3108
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>
#include <limits>
#include <iomanip>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

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

	string A;
	for (size_t i = 0; i < atoi(b.c_str()); i++)
	{
		A += a;
	}

	string B;
	for (size_t i = 0; i < atoi(a.c_str()); i++)
	{
		B += b;
	}

	string result = A > B ? B : A;

	cout << result<< endl;
	return 0;
}

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


int main(){
ios::sync_with_stdio(0);
cin.tie(0);
    int n,m;cin>>n>>m;
    cout<<n*(n-1)/2+m*(m-1)/2;
 
return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	N := nextInt64()
	ans := ""
	current := N

	for {
		current--
		r:= current % 26
		ans = string(r+97) + ans
		current = current / int64(26)
		if current == 0 {
			break
		}
	}
	fmt.Println(ans)
}

func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}

func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}

func nextString() string {
	return nextReader()
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

func nextInt64s(n int) []int64 {
	r := make([]int64, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt64()
	}
	return r
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func Min(a int, b int) int {
	if a > b {
		return b
	}
	return a
}

func Max(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

func MinA(arg ...int) int {
	var s = arg[0]
	for _, v := range arg {
		s = Min(s, v)
	}
	return s
}

func MaxA(arg ...int) int {
	var s = arg[0]
	for _, v := range arg {
		s = Max(s, v)
	}
	return s
}

func Abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}


Measured memory_bytes: 1772
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string str;
    cin >> str;
    int n = SZ(str);
    ll table[n];
    fill_n(table, n, 1);
    int i = 0;
    while (str[i] == 'L') { table[i] = 0; i++; }
    if (i != 0) table[0] = i;
    
    for (; i < n; ++i) {
        int l, r, r1 = i;
        while (str[i] == 'R' && i < n) { table[i] = 0; i++; }
        r = i - 1;
        l = i;
        int rr = r - r1 + 1;
        
        if (i == n && str[n - 1] == 'R') {
            table[n - 1] = rr;
            break;
        }
        
        while (str[i] == 'L' && i < n) { table[i] = 0; i++; }
        i--;
        
        int ll = i - l + 1;
        
        table[r] = (rr - rr / 2) + ll / 2;
        table[l] = rr / 2 + (ll - ll / 2);
        
    }
    
    outa(table, n);
    
}




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

int main(){
	lint n,ans=0;
	cin>>n;
	vector<lint>p(n),c(n);
	rep(i,n)cin>>p.at(i);
	c=p;
	rep(i,n){
		if(c.at(i)<c.at(0))c.at(0)=c.at(i);
		if(p.at(i)<=c.at(0))ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3328
text = gets.chomp
q = gets.to_i
q.times do
  commands = gets.split(" ")
  a = commands[1].to_i
  b = commands[2].to_i
  if(commands[0] == "print") then
    printf "%s\n", text[a..b]
  elsif(commands[0] == "reverse") then
    word = text.slice(a..b)
    text[a..b] = word.reverse
  else
    text[a..b] = commands[3]
  end
end

Measured memory_bytes: 8680
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,l/l> ;
//#define all(v) v.begin(),v.end()
ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

vll fac(2,1),inv(2,1),finv(2,1) ;

void nCr_set(ll n){
	for(int i=2;i<=n;i++){
		fac.emplace_back(fac.at(fac.size()-1)*i%mod) ;
		inv.emplace_back(mod-inv.at(mod%i)*(mod/i)%mod) ;
		finv.emplace_back(finv.at(finv.size()-1)*inv.at(i)%mod) ;
	}
}

ll nCr(ll n,ll r){
	if(n<0||r<0||n<r) return 0 ;
	if(n==r||r==0) return 1 ;
	return fac.at(n)*finv.at(n-r)%mod*finv.at(r)%mod ;
}

ll nHr(ll n,ll r) {
	return nCr(n+r-1,n-1) ;
}


int main(){
	nCr_set(5000) ;
	ll n,k ;
	cin >> n >> k ;
	if(n==k){
		for(int i=1;i<=k;i++){
			if(i==1) cout << 1 << endl ;
			else cout << 0 << endl ;
		}
		return 0 ;
	}
	for(int i=1;i<=k;i++){
		ll ans = 0 ;
		ll sub = nHr(i,k-i) ;
		ans += nHr(i-1,n-k-i+1)*sub ; ans %= mod ;
		ans += 2*nHr(i,n-k-i)*sub ; ans %= mod ;
		ans += nHr(i+1,n-k-i-1)*sub ; ans %= mod ;
		cout << ans << endl ;
	}
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  string s;
  cin>>s;
  for(i=s.size()-2;i>=0;i-=2){
    bool ans=true;
    for(j=0;j<i/2;j++)
      if(s[j]!=s[i/2+j]){
        ans=false;
        break;
      }
    if(ans){
      cout<<i<<endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main () {
  int n, x, temp, sum = 0, minimum;
  cin >> n >> x;
  minimum = x+1;
  for (int k = 0; k< n; k++) {
    cin >> temp;
    sum = sum + temp;
    if (temp < minimum) {
      minimum = temp;
    }
  }

  int ans = n + ((x - sum) / minimum);
  cout << ans;
  return 0;
}

Measured memory_bytes: 256