akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string>

using namespace std;

#define INF 1000000007

int main(){
  int n;
  int ans = 0;
  cin >> n;
  vector<int> b(n-1);
  for(int i = 0; i < n-1 ;i++) cin >> b[i];
  ans = b[0];
  for(int i = 0; i < n-2; i++){
    ans += min(b[i], b[i+1]);
  }
  ans += b[n-2];
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=25005,mod=1000000007;
int n,k,m,a[N],f[N][405],g[N][405],lst[405];
int pw(int a,int b){int ans=1;for(;b;b>>=1,a=1ll*a*a%mod)if(b&1)ans=1ll*ans*a%mod;return ans;}
int fac(int x){int ans=1;for(int i=1;i<=x;i++)ans=1ll*ans*i%mod;return ans;}
int main()
{
	scanf("%d%d%d",&n,&k,&m);
	for(int i=1;i<=m;i++)scanf("%d",&a[i]);
	int mx=0,x=0,ans=1ll*(n-m+1)*pw(k,n-m)%mod,res=0;
	for(int i=1;i<=m;i++){x=min(x+1,i-lst[a[i]]);lst[a[i]]=i;mx=max(mx,x);}
	if(mx==k){printf("%d\n",ans);return 0;}
	if(mx==m)
	{
		f[0][0]=1;
		for(int i=1;i<=n;i++)for(int j=k-1,s1=0,s2=0;j>=1;j--)
		{
			s1=(s1+f[i-1][j])%mod;s2=(s2+g[i-1][j])%mod;
			f[i][j]=(f[i][j]+1ll*f[i-1][j-1]*(k-j+1)%mod)%mod;
			g[i][j]=(g[i][j]+1ll*g[i-1][j-1]*(k-j+1)%mod)%mod;
			f[i][j]=(f[i][j]+s1)%mod;g[i][j]=(g[i][j]+s2)%mod;
			if(j>=m)g[i][j]=(g[i][j]+f[i][j])%mod;
		}
        for(int i=1;i<=k;i++)(res+=g[n][i])%=mod;
		res=1ll*res*fac(k-m)%mod*pw(fac(k),mod-2)%mod;
		printf("%d\n",(ans+mod-res)%mod);
	}
	else
	{
		int u=0,v=0;
		memset(lst,0,sizeof(lst));
		for(int i=1;i<=m;i++)if(!lst[a[i]])u++,lst[a[i]]=1;else break;
		memset(lst,0,sizeof(lst));
		for(int i=m;i>=1;i--)if(!lst[a[i]])v++,lst[a[i]]=1;else break;
		f[0][u]=g[0][v]=1;
		for(int i=1;i<=n;i++)for(int j=k-1,s1=0,s2=0;j>=1;j--)
		{
			s1=(s1+f[i-1][j])%mod;s2=(s2+g[i-1][j])%mod;
			f[i][j]=(f[i][j]+1ll*f[i-1][j-1]*(k-j+1)%mod)%mod;
			g[i][j]=(g[i][j]+1ll*g[i-1][j-1]*(k-j+1)%mod)%mod;
			f[i][j]=(f[i][j]+s1)%mod;g[i][j]=(g[i][j]+s2)%mod;
		}
		for(int i=0;i+m<=n;i++)
		{
			int s=0,t=0;
			for(int j=1;j<k;j++)(s+=f[i][j])%=mod,(t+=g[n-m-i][j])%=mod;
			(ans+=mod-1ll*s*t%mod)%=mod;
		}
		printf("%d\n",ans);
	}
	return 0;
}

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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

void printVec(vector<int>& vec) {
    for (auto& e : vec) {
        cout << e << " ";
    }
    cout << endl;
}

int main() {
    cout << fixed << setprecision(10);
    double n;
    cin >> n;

    if (n == 1) {
        cout << 1.000000000 << endl;
        return 0;
    }
    if ((int)n % 2 == 0) {
        cout << (n / 2) / n << endl;
    } else {
        cout << (n + 1) / 2 / n << endl;
    }

    return 0;
}


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

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solution solver = new Solution();
        solver.solve(1, in, out);
        out.close();
    }

    static class Solution {
        public void solve(int testNumber, InputReader in, PrintWriter out) {

            int total = in.nextInt();
            String[] keys = {"AC", "WA", "TLE", "RE"};

            Map<String, Integer> hm = new HashMap<String, Integer>();
            for (int n = 0; n < total; n++) {
                String s = in.next();
                if (hm.containsKey(s)) {
                    hm.put(s,  hm.get(s) + 1) ;
                }
                else {
                    hm.put(s, 1);
                }

            }
            for (String k : keys) {
                if (hm.containsKey(k)) {
                    System.out.println(k + " x " + hm.get(k));
                }
                else {
                    System.out.println(k + " x " + 0);
                }

            }

        }
    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

        public String nextLine() {
            String inputLine = "";
            try {
                inputLine = reader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return inputLine;
        }
    }
}





Measured memory_bytes: 49972
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define ff first
#define ss second

typedef vector<int> vi;
int ara[205][205];
pii d, p;

vector<string> grid;
int xx[] = {0, 0, 1, -1};
int yy[] = {1, -1, 0, 0};
int n, m;

bool isValid(int x, int y){
	return (x>=0 && y>=0 && x<n && y<m);	
}

void cost(int x, int y){
	queue<int> qx, qy;
	qx.push(x);
	qy.push(y);
	memset(ara, 0, sizeof(ara));
	ara[x][y] = 1;
	while(!qx.empty()){
		x = qx.front();
		y = qy.front();
		qx.pop();
		qy.pop();
		for(int i=0; i<4; i++){
			int tx = x+xx[i], ty = y+yy[i];
			if(isValid(tx, ty) && !ara[tx][ty] && grid[tx][ty] != '#'){
				qx.push(tx);
				qy.push(ty);
				ara[tx][ty] = ara[x][y]+1;
			}

		}
	}
}

int main(){
	scanf("%d %d",&n, &m);

    grid = vector<string>(n);
	for(int i=0; i<n; i++){
		cin >> grid[i];
	}
	
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			if(grid[i][j] == '%') d = mp(i, j);
			else if(grid[i][j] == '@') p = mp(i, j);		
		}
	}

	cost(d.ff, d.ss);
	
	bool flag = true;
	int mn = ara[p.ff][p.ss], t;
	for(int i=0; i<n && flag; i++){
		for(int j=0; j<m && flag; j++){
			if(grid[i][j] == '$'){
				flag = (mn < ara[i][j]);
			}	
		}
	}
	
	if(flag) printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 3504
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

import java.util.*;

public class Main {
    long MOD = (long) 1e9 + 7;

    InputStream in;
    OutputStream out;

    public Main() {
        this(System.in, System.out);
    }

    public Main(InputStream in, OutputStream out) {
        this.in = in;
        this.out = out;
    }

    void run() {
        Scanner sc = new Scanner(this.in);
        PrintWriter out = new PrintWriter(this.out);

        // write your code
        int n = sc.nextInt(), k = sc.nextInt();
        long[] cnts = new long[k + 1];
        long ans = 0;

        for (int i = k; i >= 1; i--) {
            int cnt = k / i;
            cnts[i] = modpow(cnt, n);
            for (int j = 2; i * j <= k; j++) {
                cnts[i] = (cnts[i] - cnts[i * j] + MOD) % MOD;
            }
            ans = (ans + i * cnts[i]) % MOD;
        }

        out.println(ans);
        out.flush();
    }

    long modpow(long a, long b) {
        if (b == 0) return 1;
        else if (b == 1) return a;

        long x = modpow(a, b / 2);
        return b % 2 == 0 ? x * x % MOD : x * (x * a % MOD) % MOD;
    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

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

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion
#pragma region chminmax
template <typename T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion
const ll p = 1e9 + 7;
struct mint
{
    ll x;
    mint(ll x = 0) : x(x % p) {}
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= p)
            x -= p;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += p - a.x) >= p)
            x -= p;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= p;
        return *this;
    }

    mint operator+(const mint a) const
    {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const
    {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const
    {
        mint res(*this);
        return res *= a;
    }

    mint pow(ll t) const
    {
        if (t == 0)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }

    mint inv() const
    {
        return pow(p - 2);
    }
    mint &operator/=(const mint a)
    {
        return (*this) *= a.inv();
    }
};

int main()
{
    int h, w;
    cin >> h >> w;
    vector<vector<char>> grid(h, vector<char>(w));
    rep(v, h)
    {
        rep(u, w)
        {
            cin >> grid[v][u];
        }
    }
    vector<vector<mint>> dp(h, vector<mint>(w));
    dp[0][0] = 1;
    rep(i, w)
    {
        if (grid[0][i] == '#')
            break;
        dp[0][i] = 1;
    }
    rep(i, h)
    {
        if (grid[i][0] == '#')
            break;
        dp[i][0] = 1;
    }

    for (int y = 1; y < h; ++y)
    {
        for (int x = 1; x < w; x++)
        {
            if (grid[y][x] == '#')
            {
                continue;
            }
            dp[y][x] += dp[y][x - 1];
            dp[y][x] += dp[y - 1][x];
        }
    }
    cout << dp[h - 1][w - 1].x << endl;

    return 0;
}

Measured memory_bytes: 9088
#define _USE_MATH_DEFINES
#include  <iostream>
#include  <algorithm>
#include  <climits>
#include  <vector>
#include  <string>
#include  <cstring>
#include  <stack>
#include  <queue>
#include  <cmath>
#include  <iomanip>
#include  <set>
#include  <map>
#include  <new>
#include <cstdint>
#include <cctype>
#include  <cstdio>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define lrep(i,n,m)  for(int i = n; i < m; i++)

using ll = long long;
using ld = long double;
using Vii = vector<vector<int> >;
using Gjudge = vector<vector<bool>>;
using Vi = vector<int>;
using Vl = vector<ll>;
using Vd = vector<double>;
using Vld = vector<long double>;
using Vll = vector<vector<ll> >;
using Vldd = vector<vector<ld> >;
using Vs = vector<string>;
using Vb = vector<bool>;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Pli = pair<ll, int>;
using VPi = vector<Pi>;
using VPl = vector<Pl>;
using VPli = vector<Pli>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;

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; }

const int Mod = static_cast<int>(1e9 + 7);
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
const int dx[4] = { 1,0,-1,0 };
const int dy[4] = { 0,1,0,-1 };

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


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;
const int MAX=3000;

signed main(){
    int N,K;cin>>N>>K;
    int ans=(K!=0?0:-N);
    REPS(b,N){
        ans+=(N/b)*max(0ll,b-K)+max(0ll,N%b-K+1);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long s = sc.nextLong();
    long ans = -1;
    long b;
    if(s < n + 1) {
      long i;
      for(i = 1; i * i < n; i++) {
        if((n - s) % i == 0) {
          if(func(i + 1, n) == s) {
            if(ans > -1) {
              ans = Math.min(i + 1, ans);
            } else {
              ans = i + 1;
            }
          }
          if(func((n - s) / i + 1, n) == s) {
            if(ans > -1) {
              ans = Math.min((n - s) / i + 1, ans);
            } else {
              ans = (n - s) / i + 1;
            }
          }
        }
      }
      if(ans == -1 && s == n) ans = n + 1;
    }
    System.out.println(ans);
  }

  public static long func(long b, long n) {
    if(b > n) return n;
    if(b == 1) return 0;
    return func(b, n / b) + (n % b);
  }
}

Measured memory_bytes: 23764
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())
def NIJIGEN(H): return [list(input()) for i in range(H)]
X=int(input())
L=list()
R=list()
for i in range(-1000,1001):
  L.append(i**5)
  R.append(i)
for i in range(-1000,1001):
  if (i**5)+X in L:
    n=L.index((i**5)+X)
    print(R[n],i)
    exit()

Measured memory_bytes: 9232
from operator import itemgetter
N = int(input())

def checkNonnegative(brankets):
    curup = 0
    for (minup , up) in sorted(brankets , key= itemgetter(0) , reverse = True):
        if curup + minup < 0:
            return False
        curup += up
    return True

def canArrangeBranket(brankets):
    totup = 0
    left_brankets = []
    right_brankets = []
    for branket in brankets:
        up = 0
        minup = 0
        for c in list(branket):
            if c == '(':
                up += 1
            else:
                up -= 1
                minup = min(minup , up)
        totup += up
        if up >= 0:
            left_brankets.append((minup , up))
        else:
            right_brankets.append((minup - up , - up))
    if totup != 0:
        return False
    return checkNonnegative(left_brankets) and checkNonnegative(right_brankets)

branketList = []
for i in range(N):
    l = input()
    branketList.append(l)

if canArrangeBranket(branketList):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 95916
/*
AizuOnline A0208
Maximum Sum Sequence
*/
#include <stdio.h>


main()
{
  long int x;
  char buffer[15];
  char buffer2[20];
  char *p,*a,*b;


  while(EOF != scanf("%ld",&x) && x)
    {
      sprintf(buffer,"%lo",x);
      a=buffer;
      b=buffer2;
    
      do
      { 
	*b="01235789"[*a-'0'];
	a++;b++;
      }
      while(*a);
      *b='\0';

      printf("%s\n",buffer2);
    }
      return(0);
}

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

int main() {
  int Ans = 0;  // 回答：

  int N; cin >> N; // 文字列丁
  string S; cin >> S; // スライム文字列

  char Pre = ' ';  // 前の文字

  rep(i,N){
    if(S.at(i)!=Pre){
      Ans++;
      Pre = S.at(i);
    }
  }

  cout << Ans << endl;
}


Measured memory_bytes: 512
//
//  main.cpp
//  Test
//
//  Created by momoc on 2019/8/18.
//  Copyright © 2019年 momoc. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
typedef long long ll;
using namespace std;
const int N = 200000 + 1;
int a[N]={0};
vector<int> dege[N];
void bfs(){
    queue<int> q;
    q.push(1);
    while(!q.empty()){
        int v = q.front();
        q.pop();
        int add = a[v];
       // printf("%d\n",add);
        for(int i = 0;i<dege[v].size();i++){
            a[dege[v][i]] +=add;
            q.push(dege[v][i]);
        }
    }
}
int main(int argc, const char * argv[]) {
    // insert code here...
    int n,m;
    scanf("%d%d",&n,&m);
    for(int i=0;i<n - 1;i++){
        int p,q;
        scanf("%d %d",&p,&q);
        dege[p].push_back(q);
        //cout<<sum<<endl;
    }
    for(int i=0;i<m;i++){
        int p,q;
        scanf("%d %d",&p,&q);
        a[p] += q;
    }
    bfs();
    for(int i = 1;i<=n;i++){
        printf("%d ",a[i]);
    }
    return 0;
}


Measured memory_bytes: 14080
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main() {

    int N, R;
    cin >> N >> R;

    if (N >= 10) {
        cout << R << endl;
    } else {
        cout << (R + 100 * (10 - N)) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	sc := NewScanner()

	n := sc.NextInt()
	x := sc.NextInt()
	a := []int{}
	for i := 0; i < n; i++ {
		tmp := sc.NextInt()
		a = append(a, tmp)
	}
	sort.Ints(a)
	ans := 0
	for i := 0; i < n; i++ {
		x -= a[i]
		if x < 0 {
			break
		}
		ans += 1
		if x == 0 {
			break
		}
	}

	if x > 0 {
		ans -= 1
	}
	fmt.Printf("%v\n", ans)

}

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) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	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: 640
#include<bits/stdc++.h>
using namespace std;

int main(){
    while(1){
        int rg,wl,C,g;  cin>>rg>>wl>>C>>g;
        if(rg==0)break;
        
        int ans=0;
        while(rg/wl<C){
            ans++;
            rg+=g;
        }

        cout<<ans<<endl;

    }

    return 0;
}



Measured memory_bytes: 2988
#![allow(unused_imports)]
#![allow(unused_macros)]
use std::cmp::{ min, max };

macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

#[allow(dead_code)]
const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let w: Vec<i32> = (0..n).map(|_| sc.cin()).collect();
    put!((1..n).map(|t| {
        let a: i32 = (0..t).map(|i| w[i]).sum();
        let b: i32 = (t..n).map(|i| w[i]).sum();
        (a - b).abs()
    }).min().unwrap());
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Scanner { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
}


Measured memory_bytes: 4352
#include <cstdio>
#include <iostream>
#include <cstring>

using namespace std;

#define open 1
#define close 0

int search;
bool key;

void judge(int N, int M, char U[300][12], char T[300][12])
{
	for(int j = 0; j < M; j++){
		for(int i = 0; i < N; i++){
			if(strcmp(U[i], T[j]) == 0){
				if(key == close){
					cout << "Opened by ";
					printf("%s\n", T[j]);
					key = open;
				}
				else if(key == open){
					cout << "Closed by ";
					printf("%s\n", T[j]);
					key = close;
				}
				search = true;
			}
		}
		if(search == false){
			cout << "Unknown ";
			printf("%s\n", T[j]);
		}
		search = false;
	}
}
			

int main()
{
	int N, M;
	char U[300][12];
	char T[300][12];
	
	while(scanf("%d", &N) != EOF){
		for(int i = 0; i < N; i++){
			cin >> U[i];
		}
		cin >> M;
		for(int i = 0; i < M; i++){
			cin >> T[i];
		}
		key = close;
		judge(N, M, U, T);		
	}
	return 0;
}

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

using LL = long long int;
using uLL = unsigned long long int;
using uint = unsigned int;
using ld = long double;

int k, licznik;

string ans;
bool czy = true;

void rek(string &w, int d, int m){
    if(licznik > k) return;
    if(d == m){
        if(licznik == k){
            ans = w;
            czy = false;
        }
        //cout << w << '\n';
        licznik++;
        return;
    }
    if(d == 0){
        for(char i = '1'; i <= '9'; i++){
            w.push_back(i);
            rek(w, d+1, m);
            w.pop_back();
        }
        return;
    }
    char ost = w.back();
    if(ost > '0'){
        w.push_back(ost-1);
        rek(w, d+1, m);
        w.pop_back();
    }
    w.push_back(ost);
    rek(w, d+1, m);
    w.pop_back();
    if(ost < '9'){
        w.push_back(ost+1);
        rek(w, d+1, m);
        w.pop_back();
    }
}


int main(){
	cin.tie(NULL);
	ios_base::sync_with_stdio(0);
    cin >> k;
    int dl = 1;
    licznik = 1;
    while(czy){
        string xx = "";
        rek(xx, 0, dl);
        dl++;
    }
    cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main() {
	

	int abc[26] = { 0 };
	char c;
	while (scanf("%c", &c) != EOF) {
		int n = tolower(c) - 'a';
		if (0 <= n && n < 26) { abc[n]++; }
	}

	for (int i = 0; i < 26; i++) {
		printf("%c : %d\n", i + 97, abc[i]);
	}

	return 0;
}

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

num_R = len([c for c in S if c == "R"])
num_G = len([c for c in S if c == "G"])
num_B = len([c for c in S if c == "B"])

total = num_R * num_G * num_B

count = 0
for i in range(0, N - 2):
    for j in range(i, N - 1):
        k = (j - i) + j
        if k < N:
            if S[i] != S[j] and S[i] != S[k] and S[j] != S[k]:
                count += 1

print(total - count)

Measured memory_bytes: 73980
#include <iostream>
#include <algorithm>
#include <vector>

int main() {
    int temp;
    std::vector<int> N;
    for (auto i=0; i<3; ++i) {
        std::cin >> temp;
        N.push_back(temp);
    }
    std::sort(N.begin(),N.end());
    if ((N[0] == 5) && (N[1] == 5) && (N[2] == 7)) {
        std::cout << "YES" << std::endl;
    } else {
        std::cout << "NO" << std::endl;
    }
    return 0;
}

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

int main(){
    int a, b, h;
    cin >> a >> b >> h;
    cout << (a+b)*h/2 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int d,n;
    cin>>d>>n;
        if(n!=100){
        if(d==0) cout<<n;
        else if(d==1) cout<<n*100;
        else cout<<n*10000;
        }
        else {
            if(d==0) cout<<"101";
            else if(d==1) cout<<"10100";
            else cout<<"1010000";
        }

    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
double a,b,s;
int m;
int main()
{
    cin>>m>>a>>b;
    while(m)
    {
        s=s+m*b-b/2+a;
        a=(2*m*a+2*a+5*b)/m/2;
        b=(2*m+4)*b/(2*m);
        m--;
    }
    cout<<fixed<<setprecision(9)<<s<<endl;
	return 0;
}
/*
*/

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner scn = new Scanner(System.in);
        int n = scn.nextInt();
        char[] a = scn.next().toCharArray();
        for(char tmp : a) {
            int num = 0;
            if((char)(tmp + n) > 'Z'){
                num = n - 26;
                System.out.print((char)(tmp + num));
            }else {
                System.out.print((char) (tmp + n));
            }
        }
    }
}

Measured memory_bytes: 23676
// package app;

import java.util.Arrays;
import java.util.Objects;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);

        // final String a = sc.next();
        // final String b = sc.next();

        final int A = sc.nextInt();
        final int B = sc.nextInt();
        // final int b = sc.nextInt();
        // final int D = sc.nextInt();
        // System.out.println();

        String result = "";
        if (A == 1 && B != 1) {
            result = "Alice";
        } else if (A != 1 && B == 1) {
            result = "Bob";
        } else {
            int ret = Integer.compare(A, B);
            if (ret > 0) result = "Alice";
            else if (ret < 0) result = "Bob";
            else result = "Draw";
        }

        System.out.println(result);

        // System.out.println(A <= X && A + B >= X ? "YES" : "NO");

    }
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int>> vvint;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<int, vector<int>, greater<int>> spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int>> bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;        //大きい順に取り出し

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)

int INF = 1e9;
int NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
double EPS = 1e-9;
double PI = M_PI;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}
//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::chrono::system_clock::time_point start,end;
    start = std::chrono::system_clock::now();

    int n ;
    cin >> n ;
    string s ;
    cin >> s ;
    int right = 0;
    int left = 0 ;
    int cnt = 0 ;
    REP(i,n){
        if(s[i]==')' && cnt==0){
            right++ ;
        }
        else if(s[i]==')' && cnt !=0){
            cnt-- ;
        }
        else{
            cnt++ ;
        }
    }
    cnt = 0 ;
    for(int i=n-1;i>=0;i--){
        if(s[i]=='(' && cnt==0){
            left++ ;
        }
        else if(s[i]=='(' && cnt!=0){
            cnt-- ;
        }
        else{
            cnt++ ;
        }
    }
    REP(i,right){
        s = "(" + s ;
    }
    REP(i,left){
        s = s + ")" ;
    }

    cout << s <<endl;


    end = std::chrono::system_clock::now();
    auto elapsed = std::chrono::duration_cast< std::chrono::milliseconds >(end - start).count();
    //std::cout << elapsed <<"ms"<< std::endl;

    

    return 0;
}



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

using namespace std;

//#define int long long
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<bool> vb;

inline void setMax(int &a, int b){ a = max(a, b); }
inline void setMin(int &a, int b){ a = min(a, b); }

vi val;
vvi g;

signed main(){
    cin.tie(0); cout.tie(0); cin.sync_with_stdio(0); cout.sync_with_stdio(0);

    int N, Q;
    cin >> N >> Q;
    
    g.resize(N+1);
    val.resize(N+1, 0);

    int a, b;
    for(int i=1; i<N; i++){
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    while(Q--){
        cin >> a >> b;
        val[a] += b;
    }

    queue<pii> q;
    q.push({1, -1});

    while(!q.empty()){
        auto curr = q.front();
        q.pop();

        for(auto i : g[curr.fi])if(i != curr.se){
            val[i] += val[curr.fi];
            q.push({i, curr.fi});
        }
    }

    for(int i=1; i<=N; i++) cout << val[i] << " ";
}

Measured memory_bytes: 16372
n=int(input())

i=1
cnt = 0 
while(i<=n):
	if i < 10 or (i >= 100 and i < 1000) or (i>=10000 and i<100000) :
		cnt+=1
		i+=1
	elif n == 100000:
		cnt  = 90909
		break
	elif len(str(i)) > 1:
		if i < 100:
			i = 100

		elif i >999 and i< 10000:
			i = 10000
	
print(cnt)



Measured memory_bytes: 38512
#include <iostream>
#include <math.h> 
#include <string> 
#include <algorithm>
using namespace std;

int main() {

	string ans = "Yes";
	int N; cin >> N;

	string W[1000];

	for (int i = 1; i <= N; i++) cin >> W[i];

	for (int j = 1; j <= N - 1; j++) if (W[j][W[j].length() - 1] != W[j + 1][0]) ans = "No";

	for (int k = 1; k <= N; k++) for (int l = k + 1; l <= N; l++) if (W[k] == W[l]) ans = "No";

	cout << ans << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<ctype.h>
using namespace std;
int main(){
  string s1,s2,s3;
  int j;
  char a[4];
  cin >>s1 >>s2 >>s3;
  a[0]=toupper(s1[0]);
  a[1]=toupper(s2[0]);
  a[2]=toupper(s3[0]);
  for(j=0;j<3;j++){
    cout <<a[j];
  }
  cout <<'\n';
  return 0;
}


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

namespace Atc_0022
{
    class Program
    {
        static void Main(string[] args)
        {
            ulong N = ulong.Parse(Console.ReadLine());

            ulong result = 0;

            for (ulong i = 1; i <= N; i++)
            {
                if (i % 3 == 0 && i % 5 == 0)
                {

                }
                else if (i % 3 == 0)
                {

                }
                else if (i % 5 == 0)
                {

                }
                else
                {
                    result += i;
                }

            }

            Console.WriteLine(result);
        }
    }
}


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

using namespace std;

typedef long long ll;

int main()
{
	ll n, a, b;
	
	scanf("%lld%lld%lld", &n, &a, &b);
	
	if(b - a & 1) printf("%lld\n", min(a + b - 1, n + n - a - b + 1) >> 1);	
	else printf("%lld\n", b - a >> 1);
	
	return 0;
}

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

int main()
  
{
    
    
    int k;
    cin>>k;
    
    string s;
    cin>>s;
    
    if(s.length()<=k)
    {
        cout<<s<<endl;
    }
    else
    {
        for(int i=0;i<k;i++)
        {
            cout<<s[i];
        }
        cout<<"..."<<endl;
    }
  
  
  
  return 0;
}

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

using namespace std;

#define ll long long
#define fix cout << fixed; cout << setprecision(0)





void solve() {

	string s;
	cin >> s;
	if(s.find('A') != string::npos && s.find('B') != string::npos) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}
	




	
}

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	fix;
	solve();

	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
 
public class Main {
	
	public static final int SIZE = 4;
	
	public static void main(String[] args) throws IOException {
		final Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		final int m = sc.nextInt();
		
		int[] es = new int[m];
		for(int i = 0; i < m; i++){
			es[i] = sc.nextInt();
		}
		
		boolean[] showed = new boolean[n + 1];
		int[] order = new int[n + 1];
		int count = 0;
		
		for(int i = m - 1; i >= 0; i--){
			final int e = es[i];
			if(showed[e]){ continue; }
			
			showed[e] = true;
			order[count++] = e;
		}
		
		for(int i = 1; i <= n; i++){
			if(!showed[i]){
				showed[i] = true;
				order[count++] = i;
			}
		}
		
		for(int i = 0; i < n; i++){
			System.out.println(order[i]);
		}
	}
 
	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;
 
		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}	
 
		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}
 
		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}
 
		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 68412
#include<bits/stdc++.h>
using namespace std;
int n, q, cnt[100005];
bool pos[100005];

int main()
{
    scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++) cnt[i] = 1;
    pos[1] = 1;
    for(int i=1;i<=q;i++) {
        int A, B;
        scanf("%d%d",&A,&B);
        if(pos[A]) pos[B] = true;
        cnt[A]--; cnt[B]++;
        if(cnt[A]==0) pos[A] = false;
    }
    int ans = 0;
    for(int i=1;i<=n;i++) if(pos[i]) ans++;
    printf("%d\n",ans);
}


Measured memory_bytes: 768
fun main(args: Array<String>) {
    val s = readString()
    if (s.contains("A") && s.contains("B")) println("Yes")
    else println("No")
}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

Measured memory_bytes: 33980
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

int main(int argc, char const *argv[])
{
	string s;
	cin >> s;

	if (s[0] == 'a' || s[0] == 'i' || s[0] == 'u' || s[0] == 'e' || s[0] == 'o')
	{
		cout << "vowel" << endl;
	} else {
		cout << "consonant" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define FORN(i,b,a)for(int i=(b);_a=(a);i>=_a;i--)
#define REP(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define re return
#define vi vector<int>
#define pb push_back
#define si set<int>
#define in insert
#define fl float
#define db double
#define ld long double
#define X first
#define Y second
#define st string
#define ull unsigned long long
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
int main()
{
	int n;
	int a[111];
	cin>>n;
	REP(i,n)
		cin>>a[i];
	REP(i,n)
	{
		if(a[i]%2||a[i]%3==0||a[i]%5==0)continue;
		cout<<"DENIED\n";
		return 0;
	}
	cout<<"APPROVED\n";
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#ifdef TEST
#define getchar_unlocked _getchar_nolock
#define putchar_unlocked _putchar_nolock
#endif
#define int long long
#define ins insert
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define pp pop
#define ppb pop_back
#define ppf pop_front
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef double db;
typedef long long ll;
typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;
typedef tree<pair<int, int>, null_type, less<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<pair<int, int>, null_type, less<pair<int, int> >, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

int N, A, C;

main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> A;
		if (i & 1 && A & 1) C++;
	}
	cout << C << '\n';
}


Measured memory_bytes: 3648
unittest
{
	assert( [ "3 1 4" ].parse.expand.solve == 3 );
	assert( [ "3 3 33" ].parse.expand.solve == 2 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto abc = input.front.split.to!( long[] );
	return tuple( abc );
}

auto solve( long[] abc )
{
	return abc.sort().uniq.walkLength;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>
#include <cmath>

using namespace std;

int main(void){
  map<int, int> m;
  int n;
  vector<int> v;
  cin >> n;
  for(int i = 0; i < n; i++){
    int tmp;
    cin >> tmp;
    auto itr = m.find(tmp);
    if(itr != m.end()){
      m[tmp] = m[tmp] + 1;
    } else {
      m[tmp] = 1;
    }
  }
  int ans = 0;
  for (auto itr = m.begin(); itr != m.end(); ++itr) {
    if(itr->first > itr->second){
      ans += itr->second;
    }
    if(itr->first < itr->second){
      ans += itr->second - itr->first;
    }

  }
  cout << ans;
  return 0;
}


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

static const int N=100;

int main(){
    int n,p[N+1],m[N+1][N+1];
    cin>>n;
    for (int i=1;i<=n;i++) cin>>p[i-1]>>p[i];
    for (int i=1;i<=n;i++) m[i][i]=0;
    for (int l=2;l<=n;l++) {
        for (int i=1;i<=n-l+1;i++){
            int j=i+l-1;//長さ
            m[i][j]=(1<<21);
            for (int k=i;k<=j-1;k++){
                m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
            }
        }
    }

    cout<<m[1][n]<<endl;

    return 0;
}


Measured memory_bytes: 3152
//code by lynmisakura.wish to be accepted!
/****************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vpi;
 
//const long long INF = 1LL << 55;
 
#define itn int
#define endl '\n'
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define ioboost cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20)
 
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }
 
#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

int main(void){
   int n;cin >> n;
   vector<int> a(n);rep(i,n)cin >> a[i];
   sort(all(a));
   int ans = 0;
   for(int i = 0;i < n -2;i++)for(int j = i+1;j < n-1;j++)for(int k =j+1;k < n;k++){
       if((a[i] + a[j] > a[k]) and (a[i] + a[k] > a[j]) and (a[j] + a[k] > a[i]))ans++;
   }
   cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

int main(){
  int n,h,m,s;
  while(scanf("%d",&n), n){
    vector<pii> event;

    for(int i=0;i<n;i++){
      scanf("%d:%d:%d",&h,&m,&s);
      event.push_back(pii(h*3600 + m*60 + s, 1));
      scanf("%d:%d:%d",&h,&m,&s);
      event.push_back(pii(h*3600 + m*60 + s, -1));
    }

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

    int cnt = 0, ans = 0;
    for(int i=0;i<(int)event.size();i++){
      cnt += event[i].second;
      ans = max(ans, cnt);
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1460
object Main extends App{
val Array(a,b,c,d) = scala.io.StdIn.readLine.split("\\s").map(_.toInt)

if (a+b > c+d) {
  println("Left")
} else if (a+b == c+d) {
  println("Balanced")
} else if (a+b < c+d){
  println("Right")
}
}

Measured memory_bytes: 25428
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]
x = list()
y = list()
for i in range(h):
    if "#" in a[i]:
        x.append(i)
for j in range(w):
    cnt = 0
    for k in range(h):
        if a[k][j] == "#":
            y.append(j)
            break
for p in x:
    z = ""
    for q in y:
        z += a[p][q]
    print(z)

Measured memory_bytes: 9256
package main

import (
	"fmt"
)

func main() {
	var n,k  int
	fmt.Scan(&n, &k)

	as := make([]int, n+1)
	for i:= 0; i < n; i++ {
		fmt.Scan(&as[i])
		as[i]--
	}

	ss := make([]int, 0)
	m := make(map[int]int)
	ss = append(ss, 0)
	m[0] = 0
	var cnt int
	for cnt < k {
		s := ss[len(ss)-1]
		if p, ok := m[as[s]]; ok {
			cycle := cnt - p + 1
			offset := (k - p) % (cycle)
			fmt.Println(ss[p+offset] + 1)
			return
		}
		ss = append(ss, as[s])
		cnt++
		m[as[s]] = cnt
	}
	fmt.Println(ss[len(ss)-1] + 1)
}




Measured memory_bytes: 19172
N=int(input())
A=list(map(int,input().split()))
A.sort()
P=0
Q=[]
if A[0]<=0 and A[-1]>=0:
  B,C=[],[]
  for i in range(N):
    if A[i]==0:
      if len(B)==0:
        B.append(0)
      else:
        C.append(0)
    else:
      if A[i]<0:
        B.append(A[i])
      else:
        C.append(A[i])
  for i in range(len(C)-1):
    Q.append([B[0],C[-1]])
    B[0]-=C[-1]
    del C[-1]
  for i in range(len(B)):
    Q.append([C[0],B[-1]])
    C[0]-=B[-1]
    del B[-1]
  P=C[0]
else:
  if A[0]>0:
    for i in range(N-2,0,-1):
      Q.append([A[0],A[i]])
      A[0]-=A[i]
    Q.append([A[-1],A[0]])
    P=A[-1]-A[0]
  else:
    for i in range(N-1):
      Q.append([A[-1],A[i]])
      A[-1]-=A[i]
    P=A[-1]
print(P)
for i in range(N-1):
  print(*Q[i])

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

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

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    bool flag = true;
    rep(i, n - 1) if (a[i] == a[i + 1]) flag = false;

    cout << (flag ? "YES" : "NO") << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

void insert(int);
void inorder(Node);
void preorder(Node);
Node treeSearch(Node,int);

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    }
    
    else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    }
    
    else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}


void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key) x=x->left;
    else x=x->right;
  }
  z->parent=y;

  if(y==NIL) root=z;
  else if(z->key < y->key) y->left=z;
  else y->right=z;
}

void inorder(Node u){
  if(u!=NIL){
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
  }

}
void preorder(Node u){
  if(u!=NIL){
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
  }
}

Node treeSearch(Node u, int k){
  if(u==NIL || k==u->key) return u;
    
  if(k<u->key) return treeSearch(u->left,k);
  else return treeSearch(u->right,k);
  
}



Measured memory_bytes: 20452
def myAnswer(S:dict) -> str:
   target = "a"
   while True:
      if(S[target] == []):
         return target.upper()
      else:
         target = S[target].pop(0)

def modelAnswer():
   return
def main():
   S = {chr(97+i):list(input()) for i in range(3)}
   print(myAnswer(S))
if __name__ == '__main__':
   main()

Measured memory_bytes: 3060
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string str;
	int m, h;

	while (1){
		cin >> str;
		if (str[0] == '-')
			break;
		else{
			cin >> m;
			for (int i = 0; i < m; i++){
				cin >> h;
				string go_right = str.substr(0, h);
				string go_left = str.substr(h, str.length() - h);

				str = go_left + go_right;
			}
			cout << str << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1212