akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {
	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	//n := r.nextInt()
	r.Scan(true)
	d := r.nextStringArray().toInts()

	dc := func(a []int) map[int]int {
		c := map[int]int{}
		for i := range a {
			c[a[i]]++
		}
		return c
	}(d)

	ans := 1
	const MOD = 998244353
	if d[0] != 0 || dc[0] != 1 {
		ans = 0
	} else {
		for i, endi := 1, len(dc); i < endi; i++ {
			if dc[i] == 0 {
				ans = 0
				break
			}
			//ans = (ans * pow(dc[i-1], dc[i], MOD)) % MOD
			for k := 0; k < dc[i]; k++ {
				ans = ans * dc[i-1] % MOD
			}
		}

	}

	fmt.Fprintln(stdout, ans)
}


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

namespace ABC043A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n;　　　　　//人数
            int s;　　　　　//必要な個数
            int i;

            //人数ｎを入力
            n = int.Parse(Console.ReadLine());

            //必要な個数ｓを求める
            //（合計を求めるアルゴリズム）
            s = 0;                      //合計を０に初期化

            for (i = 1; i <= n; i++)
            {
                s = s + i;    //s+=iでもよい
            }
            //ｓを出力（表示）
            Console.WriteLine(s);

            //入力待ち
            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 11092
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(V) sort((V).begin(),(V).end())
#define pb push_back
#define endl '\n'
#define int long long

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

// 変数定義
int n,mvC=0,rec=0;
//

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  vector<int> h(n);
  REP(i, n) {
    cin >> h[i];
  }
  FOR(i,1,n) {
    if(h[i] <= h[i-1]) {
      mvC++;
    } else {
      rec = max(rec, mvC);
      mvC = 0;
    }
  }
  rec = max(rec, mvC);
  cout << rec << endl;
}

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

#define _ << " " <<
#define tr(x) cout << #x _ x << endl
#define fi first
#define se second

#ifdef _WIN32
#define LD "%I64d"
#else
#define LD "%ld"
#endif

using namespace std;

typedef long long ll;

struct State {
    int red_at, iter;
    map<int, int> Qt;
    State(int n, int m) {
        Qt.clear();
        for (int i = 1; i <= n; i++) {
            Qt[i] = 1;
        }
        red_at = 1;
        iter = m;
    }
    bool operator<(const State & other) const {
        return iter < other.iter;
    }
    void print() {
        cout << "State" << iter << " ";
        for (auto& k : Qt) {
            cout << k.se << " ";
        }
        cout << red_at << endl;
    }
};

const int maxn = 100005;

int n, m;
int balls[maxn];
int had_red[maxn];

int read() {
    if (scanf("%d %d", &n, &m) < 2) {
        return 0;
    }
    for (int i = 0; i <= n; i++) {
        balls[i] = 1;
        had_red[i] = 0;
    }
    return 1;
}

void solve() {
    int x, y;
    had_red[1] = 1;
    for (int i = 0; i < m; i++) {
        scanf("%d %d", &x, &y);
        if (had_red[x]) {
            if (balls[x] > 1) {
                had_red[y] = 1;
            }
            else {
                had_red[x] = 0;
                had_red[y] = 1;
            }
        } 
        balls[x]--;
        balls[y]++;
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += (had_red[i]);
    }
    printf("%d\n", ans);
}

int main(int argc, char *argv[]) {
    while (read()) {
        solve();
    }
}


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

int main() {
  int n, l;
  cin >> n >> l;
  int first = l, last = l + n - 1;
  int sum = 0;
  for (int i = 1; i <= n; i++)
    sum += l + i - 1;
  if (first <= 0 && 0 <= last)
    sum -= 0;
  else
    sum -= (abs(first) < abs(last)) ? first : last;
  cout << sum << endl;
}

Measured memory_bytes: 256
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def judge(input)
    case input
    when "Vacant" then
        return 0
    when "Male" then
        return 1
    when "Female" then
        return 2
    end
end
N=gets.to_i
head=0
tail=N-1
#Vacant:0 Male:1 Female:2
info=array(N,-1)
puts head
STDOUT.flush
info[0]=judge(gets.chomp)
exit if info[0].zero?
puts tail
STDOUT.flush
info[tail]=judge(gets.chomp)
exit if info[tail].zero?
18.times do|i|
  mid=(head+tail)/2
  puts mid
  STDOUT.flush
  info[mid]=judge(gets.chomp)
  if info[mid].zero?
      exit
  elsif (((mid-head+1)%2).even? and info[head]==info[mid]) or (((mid-head+1)%2).odd? and info[head]!=info[mid]) or (((tail-mid+1)%2).even? and info[tail]!=info[mid]) or (((tail-mid+1)%2).odd? and info[tail]==info[mid])
      tail=mid
  else
      head=mid
  end
  unless tail-head>1
      if head>N/2
          head=0
          tail=N/2-1
          if info[tail]==-1
              puts tail
              STDOUT.flush
              info[tail]=judge(gets.chomp)
              exit if info[tail].zero?
          end
      else
          head=N/2+1
          tail=N-1
          if info[head]==-1
              puts head
              STDOUT.flush
              info[head]=judge(gets.chomp)
              exit if info[head].zero?
          end
      end
  end
end


Measured memory_bytes: 3272
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define d1(x) cout<<(x)<<endl
#define d2(x,y) cout<<(x)<<" "<<(y)<<endl
#define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define endl "\n"

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}


 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;

}

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

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

const ll N=1e6+5;


int main()
{ 

  IOS;

  ll n;
  cin>>n;

  ll x=n%1000;

  if(x)x=1000-x;

  cout<<x<<endl;



return 0;
 
}



Measured memory_bytes: 3648
# coding: utf-8
# Your code here!
import itertools
import sys

N, M, X  = map(int, input().split())
money = []
A = []
ans = []
for _ in range(N):
    nums = [int(x.strip()) for x in input().split(' ') ]
    money.append(nums[0])
    nums.pop(0)
    A.append(nums)
num_money = []
for index, num in enumerate(money):
    num_money.append(index)
    
def run(lis, num, A, X, M, ans, money):
    ans_list = []
    for team in itertools.combinations(lis, num):
        count = 0
        for i in range(M):
            tmp = 0
            for j in list(team):
                tmp += A[j][i]
            if tmp >= X:
                count += 1
        if count == M:
            tmp_ans = []
            for n in list(team):
                tmp_ans.append(money[n])
            ans_list.append(sum(tmp_ans))
    if not len(ans_list) == 0:
        ans.append(min(ans_list))
    
    return ans
        
for i in range(1, N+1):
    ans = run(num_money, i, A, X, M, ans, money)
    
if not len(ans) == 0:
    print(min(ans))
    
else:
    print(-1)

Measured memory_bytes: 9304
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define ll              long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define mod             998244353
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define vpii            vector<pair<int,int> >
#define all(x)          x.begin(),x.end()
#define matrixprint(arr,a,b,c,d) for(int i=a;i<=c;i++){for(int j=b;j<=d;j++){cout<<arr[i][j]<<" ";}cout<<"\n";}
#define show(arr,x,y)   for(int i=x;i<=y;i++){cout<<arr[i]<<" ";}cout<<"\n"
#define sz               size()
#define inc(i,x,y)      for(int i=x;i<y;i++)
#define dec(i,x,y)      for(int i=x;i>=y;i--)

const int N = 2e5 + 5;

#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define deb(...)
#endif

void fast()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//#endif
}

//////////////////////////////code//////////////////////////////

int fac[200001];
int inv[200001];

int power(int a, int n = mod - 2)
{
	if (!n)
		return 1;
	int pt = power(a, n / 2);
	pt *= pt, pt %= mod;
	if (n & 1)
		pt *= a, pt %= mod;
	return pt;
}

int ncr(int n, int r)
{
	int ans1 = fac[n];
	int ans2 = (inv[r] * inv[n - r]) % mod;

	ans1 = (ans1 * ans2) % mod;

	return ans1;
}

void fillfac()
{
    fac[0] = inv[0] = 1;

	for (int i = 1; i <=200001; ++i)
	{
		fac[i] = (fac[i - 1] * i) % mod;
		inv[i] = power(fac[i]);
	}

}
int32_t main()
{
  fast();

  int n,m,k;
  cin>>n>>m>>k;

  fillfac();

  int ans=0;

  for(int i=n-k-1;i<=n-1;i++)
  {
    int curr = ncr(n-1,i);
    curr*=m;
    curr%=mod;
    curr*=power(m-1,i);
    curr%=mod;
    ans+=curr;
    ans%=mod;

  }
  cout<<ans<< "\n";



}


Measured memory_bytes: 6780
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;
import std.ascii;


void main()
{
  int n, r;
  readf("%s %s\n", &n, &r);
  if (n >= 10) {
    r.writeln;
  } else {
    writeln(r + 100 * (10 - n));
  }
}


Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author yassin
 */

#include <bits/stdc++.h>

using namespace std;

class arc092_d {
private:
    inline int count(int start_num, int end_num, const vector<int> &b) {
        auto it_start = lower_bound(begin(b), end(b), start_num);
        auto it_end = lower_bound(begin(b), end(b), end_num);
        int cnt = it_end - it_start;
        return cnt;
    }
public:
    void solve(istream& in, ostream& out) {
        int N;
        in >> N;
        vector<int> a(N), b(N);
        for (int i = 0; i < N; ++i) {
            in >> a[i];
        }
        for (int i = 0; i < N; ++i) {
            in >> b[i];
        }
        vector<int> res(29, 0);
        for (int j = 0; j < 29; ++j) {
            int T = (1 << j);
            vector<int> cur_b(N);
            for (int i = 0; i < N; ++i) {
                cur_b[i] = b[i] % (2 * T);
            }
            sort(begin(cur_b), end(cur_b));
            for (int i = 0; i < N; ++i) {
                res[j] += count(T - (a[i] % (2 * T)), 2 * T - (a[i] % (2 * T)), cur_b);
                res[j] += count(3 * T - (a[i] % (2 * T)), 4 * T - (a[i] % (2 * T)), cur_b);
            }
        }
        int ans = 0;
        for (int j = 0; j < 29; ++j) {
            if (res[j] % 2) {
                ans |= (1 << j);
            }
        }
        out << ans << "\n";
    }
};

int main() {
	std::ios::sync_with_stdio(false); cin.tie(nullptr);
	arc092_d solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 2672
import java.util.*;
import java.io.*;
public class Main {
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        int ans = Integer.MAX_VALUE;
        int n = sc.nextInt();
        int l = sc.nextInt();
        int pi = 0;
        int sum = 0;
        for(int i=0; i<n; i++){
            int t = l + i;
            if(ans > Math.abs(t)){
                ans = Math.abs(t);
                pi = i;
            }
            sum += t;
        }
        System.out.println(sum-(l+pi));

    }


    private static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;

        private boolean hasNextByte() {
            if (ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (buflen <= 0) {
                    return false;
                }
            }
            return true;
        }

        private int readByte() {
            if (hasNextByte())
                return buffer[ptr++];
            else
                return -1;
        }

        private static boolean isPrintableChar(int c) {
            return 33 <= c && c <= 126;
        }

        public boolean hasNext() {
            while (hasNextByte() && !isPrintableChar(buffer[ptr]))
                ptr++;
            return hasNextByte();
        }

        public String next() {
            if (!hasNext())
                throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while (isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public long nextLong() {
            if (!hasNext())
                throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) {
                throw new NumberFormatException();
            }
            while (true) {
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                } else if (b == -1 || !isPrintableChar(b)) {
                    return minus ? -n : n;
                } else {
                    throw new NumberFormatException();
                }
                b = readByte();
            }
        }

        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
                throw new NumberFormatException();
            return (int) nl;
        }

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

}


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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int A,B;
    cin >> A >> B;

    rep(C,1,4) if(A*B*C%2==1){
        cout << "Yes" << endl;
        return;
    }
    cout << "No" << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


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

using namespace std;

constexpr int ms = 100013;

void solve() {
    int n, m;
    cin >> n >> m;

    vector<vector<int>> adj(n);
    vector<bool> source(n, true);
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;

        --u; --v;
        adj[u].push_back(v);
        source[v] = false;
    }

    int dp[ms];
    for (int i = 0; i < ms; ++i) dp[i] = -1;

    function<int(int)> dfs = [&] (int s) {
        if (dp[s] != -1)
            return dp[s];

        int best = 0;
        for (int v : adj[s]) {
            if (dp[v] != -1) {
                best = max(best, 1+dp[v]);
            } else {
                best = max(best, 1+dfs(v));
            }
        }

        dp[s] = best;
        return best;
    };

    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (source[i]) {
            ans = max(ans, dfs(i));
        }
    }

    cout << ans << endl;
}

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

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

    int t = 1;
    // cin >> t;

    for (int i = 0; i < t; ++i) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 16740
#include<stdio.h>
int main(void)
{
	int a[3],temp,i,j;
	for(i=0;i<3;i++){
		scanf("%d",&a[i]);
	}
	for(i=0;i<3;i++){
		for(j=i+1;j<3;j++){
			if(a[i]>a[j]){
				temp=a[i];
				a[i]=a[j];
				a[j]=temp;
			}
		}
	}
	printf("%d %d %d\n",a[0],a[1],a[2]);
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
typedef long long ll;

int main() {
	int n, m, a, b, c;
  ll ans;
	vector<pair<int,int>> v;
	cin >> n >> m;
  REP(i, n) {
		cin >> a;
		v.push_back(make_pair(a, 1));
	}
  REP(i, m) {
		cin >> b >> c;
    v.push_back(make_pair(c, b));
	}
	sort(v.rbegin(), v.rend());
	int i = 0;
	while(n) {
    ll res = min(n, v[i].second);
		ans += res * v[i].first;
		n -= res;
		i++;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,x,y,maxx,minn;
	cin>>a>>b>>c>>x>>y;
	if(x>y) minn=y,maxx=x;
	else minn=x,maxx=y;
	int sum[maxx+2];
	sum[0]=x*a+y*b;
	for(int i=1;i<=minn;i++)
		sum[i]=2*i*c+(y-i)*b+(x-i)*a;
	for(int i=minn+1;i<=maxx;i++)
		if(y>x) sum[i]=2*i*c+(y-i)*b;
		else sum[i]=2*i*c+(x-i)*a;
	sort(sum,sum+maxx+1);
	cout<<sum[0];
	return 0;
}

Measured memory_bytes: 640
import sys
n = int(sys.stdin.readline().rstrip("\n"))
INF = float('inf')
ans = INF
for a in range(1,(n+2)//2):
    b = n-a
    s = 0
    while a != 0:
        a,p = divmod(a, 10)
        s += p
    while b != 0:
        b,p = divmod(b, 10)
        s += p
    ans = min(ans,s)
print(ans)

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

using namespace std;



int main(){
long long int N;

cin >> N;

int A[N],flag=0;
for (int i = 0; i < N; i++)
{
  cin >> A[i];
}

for (int i = 0; i < N; i++)
{
  if (A[i]%2==0)
  {
    if (A[i]%3!=0 && A[i]%5!=0)
    {
      flag=1;
    }
  }
}
if (flag==0)
{
  cout << "APPROVED";
}
else cout << "DENIED";
return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

const string YES = "Yes";

void solve(int N, int M, std::vector<int> A, std::vector<int> B){
    vector<vector<int> > G(N+1);
    for(int i = 0; i < M; i++) {
        G[A[i]].push_back(B[i]);
        G[B[i]].push_back(A[i]);
    }

        // BFS のためのデータ構造
    vector<int> dist(N+1, -1); // 全頂点を「未訪問」に初期化
    vector<int> isi(N+1, -1);
    queue<int> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[1] = 0;
    que.push(1); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int i = 0; i < G[v].size(); i++) {
            int nv = G[v][i];
            // cout << nv << endl;
            if (dist[nv] != -1) continue; // すでに発見済みの頂点は探索しない
            isi[nv] = v;
            // cout << isi[nv] << endl;
            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }
    bool flag = true;
    for(int i =1; i < isi.size(); i++) {
        if(isi[i] == -1) {
            flag = false;
            break;
        }
    }

    isi[0]= 0;
    isi[1] = 0;

    if(flag) {
        cout << "No" << endl;
    }else  {
        cout << "Yes" << endl;
        for(int i = 2; i < isi.size(); i++) {
            cout << isi[i] << endl;
        }
    }
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    int N;
    scanf("%d",&N);
    int M;
    scanf("%d",&M);
    std::vector<int> A(M);
    std::vector<int> B(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%d",&A[i]);
        scanf("%d",&B[i]);
    }
    solve(N, M, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 12188
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define mp make_pair
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=1e9+7;
const int N=3e3+5;
int dp[N][N];
int a[N],n;

int find(int x,int y){
	if(dp[x][y]!=-1e18){return(dp[x][y]);}
	if(x+y>=n) return(0);
	int st=x;
	int la=n-y-1;
	dp[x][y]=max(dp[x][y],a[st]-find(x+1,y));
	dp[x][y]=max(dp[x][y],a[la]-find(x,y+1));
	return(dp[x][y]);
}

int32_t main(){
    IOS;
    cin>>n;
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<N;i++){
    	for(int j=0;j<N;j++) dp[i][j]=-1e18;
    }
	cout<<find(0,0);
}

Measured memory_bytes: 70912
H, W, K = map(int, input().split())
X = []
import sys;input=sys.stdin.readline
for _ in range(H):
    X.append(input().strip())

ks = [[0]*(W+1) for _ in range(H+1)]

for i in range(1, H+1):
    for j in range(1, W+1):
        ks[i][j] = ks[i][j-1] + ks[i-1][j] - ks[i-1][j-1] + int(X[i-1][j-1])
#print(ks[1])
#print(ks[2])
#print(ks[3])

R = 10**18
for ii in range(2**(H-1)):
    i = ii
    c = 0
    cs = []
    while i:
        if i%2:
            cs.append(c)
        i //= 2
        c += 1
    b = 0
    r = 0
    cs.append(H-1)
#    print(ii, cs)
    tmp = []
    fff = False
    for j in range(1, W+1):
        cb = 0
        for c in cs:
#            print(c+1, cb, j, b, ks[c+1][j] - ks[c][b] - ks[cb][j] + ks[cb][b])
            if ks[c+1][j] - ks[c+1][b] - ks[cb][j] + ks[cb][b] > K:
                if j - b == 1:
                    fff = True
                tmp.append(j)
                r += 1
                b = j-1
                break
            cb = c+1
    if fff:
        continue
#    print(ii, cs, tmp)
#    print(r+len(cs)-1)
    R = min(R, r+len(cs)-1)
print(R)


Measured memory_bytes: 42844
#include <iostream>

using namespace std;

#define MAX_DEPTH  (50010)

long long leaf[MAX_DEPTH];

// テヲツ慊ィテ」ツつ津・ツ?催・ツクツーテァツ堋?」ツ?ォテァツ板淌ヲツ按静」ツ?凖」ツつ凝」ツつ、テ」ツδ。テ」ツδシテ」ツつクテ」ツつ津」ツ?療」ツ?ヲテ」ツ??」ツ?敕」ツ?ョテ」ツ?ィテ」ツ?催ヲツウツィテァツ崢ョテ」ツ?凖」ツつ凝ィツ堕嘉」ツ?ョテヲツキツアテ」ツ?陛」ツつ津ィツィツ佚ゥツ個イ
// テ・ツ青古」ツ?佚ヲツキツアテ」ツ?陛」ツ?ァテ」ツ?づ」ツつ古」ツ?ーテァツコツ湘」ツつ?」ツつ嘉」ツつ古」ツつ凝」ツ?ョテ」ツ?ァテ」ツ??ヲツキツアテ」ツ?陛ヲツッツ偲」ツ?ォ nC2 テ」ツつ津ァツョツ療・ツ?コテ」ツ?療」ツ?淌ァツキツ湘・ツ陳古」ツつ津ヲツアツづ」ツつ?」ツつ古」ツ?ーテ」ツつ暗」ツ??
int main() {
  
  string s;
  int size;
  
  cin >> s; size = s.size();
  
  int depth = -1;
  
  for(int i=0; i<size; i++) {
    if(s[i] == '(') leaf[++depth] ++;
    else {
      leaf[--depth] ++;
    }
  }
  
  long long ans = 0;
  for(int i=0; leaf[i]>0; i++) {
    ans += (leaf[i]*(leaf[i]-1))/2;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 1700
#include <stdio.h>

int checkRightTriangle( int a, int b, int c )
{
	int i;
	int buf;
	
	do
	{
		if( a < b )
		{
			buf = a;
			a = b;
			b = buf;
		}
		
		if( b < c )
		{
			buf = b;
			b = c;
			c = buf;
		}
	}while( a < b || b < c );
	
	if( ( a * a ) == ( b * b ) + ( c * c ) )
	{
		return (1);
	}
	else
	{
		return (0);
	}
}

int main( void )
{
	int a;
	int b;
	int c;
	int numOfDataSet;
	int i;
	
	scanf( "%d", &numOfDataSet );
	for( i = 0; i < numOfDataSet; i++ )
	{
		scanf( "%d%d%d", &a, &b, &c );
		if( checkRightTriangle( a, b, c ) )
		{
			printf( "YES\n" );
		}
		else
		{
			printf( "NO\n" );
		}
	}
	
	return (0);
}

Measured memory_bytes: 580
import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N = int(input())
    A = list(map(int, input().split()))
    AA = [0] * N

    for i in range(N):
        AA[i] = 2 * A[i]
    val = 0
    cnt=0
    for i in range(N):
        if i % 2 == 0:
            cnt += AA[i]
        else:
            cnt -= AA[i]

    val=cnt//2
    print('{} '.format(val), end='')
    for i in range(N-1):
        print('{} '.format(AA[i] - val), end='')
        val = AA[i] - val



resolve()

Measured memory_bytes: 63984
#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,ll> ;
//#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 dy4 = {-1,0,1,0} ;
vll dx4 = {0,1,0,-1} ;

int main(){
	ll h,w ;
	cin >> h >> w ;
	vvc g(h,vc(w)) ;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >> g.at(i).at(j) ;
		}
	}
	vvll d(h,vll(w,-1)) ;
	queue<int> q ;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(g.at(i).at(j)=='#'){
				d.at(i).at(j) = 0 ;
				q.push(i) ;
				q.push(j) ;
			}
		}
	}
	auto check = [&](int y,int x,int dis){
		if(0<=y&&y<h&&0<=x&&x<w&&d.at(y).at(x)==-1){
			d.at(y).at(x) = dis ;
			q.push(y) ;
			q.push(x) ;
		}
	} ;
	while(!q.empty()){
		int y = q.front() ;
		q.pop() ;
		int x = q.front() ;
		q.pop() ;
		int dis = d.at(y).at(x)+1 ;
		for(int i=0;i<4;i++){
			check(y+dy4.at(i),x+dx4.at(i),dis) ;
		}
	}
	ll ans = 0 ;
	for(int i=0;i<h;i++) for(int j=0;j<w;j++) ans = max(ans,d.at(i).at(j)) ;
	cout << ans << endl ;
}


Measured memory_bytes: 20076
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
    int n;
    cin >> n;
    vector<int> dp(n+1,1e8);
    dp.at(0) = 0;
    vector<int> add(1,1);
    REP(i,1,20){
        int tmp = pow(6,i);
        if(tmp > n) break;
        add.push_back(tmp);
    }
    REP(i,1,20){
        int tmp = pow(9,i);
        if(tmp > n) break;
        add.push_back(tmp);
    }
    REP(i,1,n+1){
        for(int x : add){
            if(i-x<0) continue;
            dp.at(i) = min(dp.at(i), dp.at(i-x)+1);
        }
    }
    cout << dp.at(n) << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

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

Measured memory_bytes: 256
#define _GLIBCXX_IOSTREAM
#include<bits/stdc++.h>
#define inf 1000000007
using namespace std;
int f[1<<15],dp[1<<15][15],tot,c[15][15],n,m;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;++i)
		for(int j=0;j<n;++j)
			c[i][j]=(i==j?0:-inf);
	for(int i=1,u,v;i<=m;++i)
		scanf("%d%d",&u,&v),scanf("%d",&c[--u][--v]),tot+=(c[v][u]=c[u][v]);
	for(int i=0;i<(1<<n);++i)
		for(int j=0;j<n;++j)if(i>>j&1)
			for(int k=j;k<n;++k)if(i>>k&1)if(c[j][k]!=-inf)
				f[i]=max(-inf,f[i]+c[j][k]);
	for(int i=0;i<(1<<n);++i)
		for(int j=0;j<n;++j)
			dp[i][j]=-inf;
	dp[1][0]=0;
	for(int i=1;i<(1<<n);++i)
		for(int j=0;j<n;++j)if(dp[i][j]!=-inf){
			int nk=(((1<<n)-1)^i)|(1<<j);
			for(int k=nk;k;k=(k-1)&nk)if(k>>j&1)
				dp[i|k][j]=max(dp[i|k][j],dp[i][j]+f[k]);
			for(int k=0;k<n;++k)if(~i>>k&1)
				dp[i|(1<<k)][k]=max(dp[i|(1<<k)][k],dp[i][j]+c[j][k]);//,printf("{%d->%d}",j,k);
//			printf("dp[%d][%d]=%d\n",i,j,dp[i][j]);
		}
	int ans=0;
	for(int i=1;i<(1<<n);++i)ans=max(ans,dp[i][n-1]);
	printf("%d",tot-ans);
}

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

fn main() {
    let _ = read_i64();
    let xs = read_vec_i64();
    let n = xs.iter().max().unwrap();
    let mut r = -1;
    for &x in &xs {
        if &x == n {
            continue;
        }
        let v = min(r,n-r);
        let nv = min(x,n-x);
        if r == -1 || v < nv {
            r = x;
        }
    }
    println!("{} {}", n, r);
}

#[allow(dead_code)]
fn read_line() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok();
    ret.pop();
    return ret;
}

#[allow(dead_code)]
fn read_i64() -> i64 {
    let ss = read_line();
    return ss.parse::<i64>().unwrap();
}

#[allow(dead_code)]
fn read_vec_i64() -> Vec<i64> {
    let mut res = vec![];
    let ss = read_line();
    for ts in ss.split_whitespace() {
        let x = ts.parse::<i64>().unwrap();
        res.push(x);
    }
    return res;
}


Measured memory_bytes: 6396
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;


public class Main {
	static final int N = 10000;
	
	public static void main(String[] args) {
		new Main().solve();
	}
	
	void solve(){
		Scanner sc = new Scanner(System.in);
		
		// メモ化みたいな
		ArrayList<Long> p = new ArrayList<Long>();
		for(long i=2; p.size()<=N; ++i){
			boolean f = true;
			for(int j=0; j<p.size(); ++j){
				// いままでの素数で試し割り
				f &= i%p.get(j)!=0;
				if(!f) break;
			}
			if(f){
				p.add(i);
			}
		}
		
		while(true){
			int n = sc.nextInt();
			
			if(n==0) break;
			
			int sum = 0;
			
			for(int i=0; i<n; ++i){
				sum += p.get(i);
			}
			
			System.out.println(sum);
		}
		
		sc.close();
	}
	
	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}
}

Measured memory_bytes: 12000
n, k = map(int, input().split())
a_lst = map(int, input().split())

dic = {}
for i, a in enumerate(a_lst):
    dic[i+1] = a

roop = []
visit = [0] * (n + 1)
cur = 1
while visit[cur] != 1:
    visit[cur] = 1
    roop.append(cur)
    cur = dic[cur]   
    
if roop.index(cur) > k:
    print(roop[k])
else:
    roop_length = len(roop) - roop.index(cur)
    rep = roop[roop.index(cur):]
    print(rep[(k - roop.index(cur)) % roop_length]) 

Measured memory_bytes: 50692
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>

using namespace std;

int main() {
  int64_t r, D, x2000;
  cin >> r >> D >> x2000;
  int64_t x = x2000;
  for (int i = 1; i <= 10; i++) {
    x = r*x -D;
    cout << x << endl;
  }
  return 0;
}


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

int strtoi(string s) {
  int res=0;
  for (int i = 0; i < s.size(); ++i) {
    res*=10;
    res+=s[i]-'0';
  }
  return res;
}

int main() {
  string s;
  cin>>s;
  int res = 810;
  for (int i = 0; i < s.size() - 2; ++i) {
    res=min(res,abs(753-strtoi(s.substr(i,3))));
  }
  cout<<res<<endl;
}


Measured memory_bytes: 256
from itertools import permutations
ls=[int(input()) for _ in range(5)]
ans = 1000000
for p in permutations(ls):
    t = 0
    for x in p[:-1]:
        t += x
        if t % 10 != 0:
            t += 10-(t%10)
    t += p[-1]
    ans = min(ans,t)
print(ans)

Measured memory_bytes: 9000
#include<bits/stdc++.h>
using namespace std;
class Graph{
  typedef pair<int, int> p; 

  int V;
  list<p> *adj; 

  public: 
  Graph(int V){ 
    this->V = V; 
    adj = new list<p> [V]; 
  } 

  void addEdge(int u, int v, int w){ 
    adj[u].push_back(make_pair(v, w)); 
    adj[v].push_back(make_pair(u, w)); 
  } 

  vector<int> bfs(int n){
    queue<int> q;
    vector<int> vec(V,-1);

    q.push(n);
    vec[n]=0;
    while(!q.empty()){
      int p=q.front();
      q.pop();
      for(auto e:adj[p]){
        if(vec[e.first]==-1){
          q.push(e.first);
          vec[e.first] = e.second + vec[p];
        }
      }
    }
    return vec;
  }
};

int main(){
  int n, x, y;
  cin >> n >> x >> y;
  Graph g(n+1);
  for(int i=1;i<n;i++){
    g.addEdge(i,i+1,1);
  }
  g.addEdge(x,y,1);
  
  vector<int> ans(n,0);
  for(int i=1;i<n;i++){
    vector<int>vec = g.bfs(i);
    for(int j=i;j<=n;j++){
      ans[vec[j]]++;
    }
  }
  for(int i=1;i<n;i++){
    cout << ans[i] << endl;
  }

}

Measured memory_bytes: 384
/*input

*/
#include <bits/stdc++.h>
#define up(i,a,b) for(int (i) = (a);(i)<=(b);++(i))
#define down(i,b,a) for(int (i) = (b);i>=(a);--i)
#define debug(x) cerr << (x) << '\n';
#define bits(x,i) ((x >> i) & 1)
#define mid ((l+r)/2)
#define pr pair<int,int>
using namespace std;
const int N = 1005;
int d[N][N];
int ox[] = {0,0,1,-1};
int oy[] = {1,-1,0,0};
char a[N][N];
int n,m,ch,cw,dh,dw;
#define sp pair< int, pr> 
bool ok(int x,int y){
    return (x >= 1 && x <=n && y >= 1 && y <= m && a[x][y] != '#');
}
int shortestPath(){
    if (!ok(ch,cw)) return -1;
    deque< pair<int, pr> > dq;
    // duong di ngan nhat den o <i,j> 
    // push_back() --> cuoi mang
    // push_front() --> dinh manh
    up(i,1,n) up(j,1,m) d[i][j] = INT_MAX;
    d[ch][cw] = 0;
    dq.push_back({0, {ch,cw}});
    while (dq.size()){
        pr u = dq.front().second;
        int value = dq.front().first; 
        dq.pop_front();
        int x = u.first;
        int y = u.second;
        if (value != d[x][y]) continue;
        // cout << value << ' ' << x << ' ' << y << '\n';
        if (x == dh && y == dw) return value;
        for (int i=0;i<4;++i){
            int nx = x + ox[i], ny = y + oy[i];
            if (!ok(nx,ny)) continue;
            if (d[nx][ny] > d[x][y]) {
                d[nx][ny] = d[x][y];
                dq.push_front({d[x][y], {nx, ny}});
            }
        }
        for(int xAdd = -2;xAdd <= 2; ++xAdd){
            for(int yAdd = -2; yAdd <= 2; ++yAdd){
                if (xAdd == 0 && yAdd == 0) continue;
                int nx = x + xAdd, ny = y + yAdd;
                if (!ok(nx,ny)) continue;
                if (d[nx][ny] > d[x][y] + 1) {
                    d[nx][ny] = d[x][y] + 1;
                    dq.push_back({d[x][y] + 1, {nx, ny}});
                }
            }
        }
    }
    return -1;

}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m;
    cin >> ch >> cw >> dh >> dw;
    for(int i=1;i<=n;++i){
        for(int j=1;j<=m;++j) cin >> a[i][j];
    }
    cout << shortestPath();
}



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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 2005;

/* ...o(^-^)o... */

struct edge{
    int from, to; lint cost;
    edge(int f, int t, lint c) : from(f), to(t), cost(c) {}
    edge(int t, lint c) : from(-1), to(t), cost(c) {}
};
vector<edge> ve;

lint d[MAX];
int V, E;
void bellman_ford(int s){
    rep(i, V) d[i] = INF;
    d[s] = 0;
    rep(j, V - 1) rep(i, E){
        edge e = ve[i];
        if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
            d[e.to] = d[e.from] + e.cost;
        }
    }
}

bool find_negloop(int s, int t){
    rep(i, V) d[i] = INF;
    d[s] = 0;
    rep(j, V - 1) rep(i, E){
        edge e = ve[i];
        if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
            d[e.to] = d[e.from] + e.cost;
        }
    }
    bool neg[MAX];
    rep(i, V) neg[i] = false;
    rep(j, V) rep(i, E){
        edge e = ve[i];
        if(d[e.from] != INF && d[e.to] > d[e.from] + e.cost){
            d[e.to] = d[e.from] + e.cost;
            neg[e.to] = true;
        }
        if(neg[e.from]) neg[e.to] = true;
    }
    return neg[t];
}

bool find_negloop(){
    rep(i, V) d[i] = 0;
    rep(i, V) rep(j, E){
        edge e = ve[j];
        if(d[e.to] > d[e.from] + e.cost){
            d[e.to] = d[e.from] + e.cost;
            if(i == V - 1) return true;
        }
    }
    return false;
}

int main(){
    cin >> V >> E;
    rep(i, E){
        ii2(a, b); a--; b--;
        lint c; cin >> c;
        ve.push_back(edge(a, b, -c));
    }
    bool isneg = find_negloop(0, V-1);
    if(isneg){
        out("inf"); return 0;
    }
    bellman_ford(0);
    out(-d[V-1]);
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

vector<int> G[100010];
bool visited[100010]={0};

int grundy(int i=0) {
    int ans = 0;
    visited[i] = true;
    for (auto g:G[i]) {
        if (visited[g]) continue;
        ans ^= grundy(g);
    }
    if (i > 0) ans++;
    // cerr << i << ' ' << ans << '\n';
    return ans;
}

int main() {
    int n;
    cin >> n;
    for (int i=1, x, y; i<n; i++) {
        cin >> x >> y;
        x--; y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    cout << (grundy() ? "Alice" : "Bob") << '\n';
    return 0;
}

Measured memory_bytes: 10496
///*****************************************************///
///*.......................Faiyaj Bin Amin............................*///
///*...................................................................*///
///*.........................KUET CSE 2K17......................*///
///*...................................................*///
///*****************************************************///

#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

#define fastio      ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define ret return
#define rep(q, i, n) for(int q=i; q<n; q++)
#define forn(i, n) for(int i=0; i<n; i++)
#define mems(a,x) memset(a,x,sizeof(a))
#define ll long long
#define pb push_back
#define em emplace_back
#define mp make_pair
#define all(v) (v).begin(), (v).end()
#define ff first
#define ss second
#define pii pair<int,int>
#define pdd pair<double, double>

#define see(x)        cerr<< __LINE__ << ": " << (#x) << " is "<< (x) <<'\n';
#define seecontent(v) for(auto x : v) { cout << x << " ";} cout << "\n\n";

#define PI 2*acos(0.0)
#define lcm(a, b)  ((a / __gcd(a, b) ) * b)

#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)

#define mx 100005
#define INF 1e18
#define MOD 1000000007
#define MIN 0

//template <typename T>  using orderedSet =
//    tree<T, null_type, less_equal<T>,
//    rb_tree_tag, tree_order_statistics_node_update>; //find_by_order, order_of_key


/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0}; // Directional
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/

/**------------------------------------BITMASK------------------------------------------**/
//int Change(int N, int pos){return N= N^(1<<pos);}
//bool Check(int N, int pos){return (bool)(N &(1<<pos));}  /// check bit 0 or 1
/**-----------------------------------------------------------------------------------------------**/

//using namespace __gnu_pbds;
using namespace std;

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

    int a[n];
    forn(i, n)
    {
        cin >> a[i];
    }

    int ans=0;
    for(int i=0; i<n-1; i++)
    {
        if(a[i]>a[i+1])
        {
            ans += a[i]-a[i+1];
        }
    }
    ans+=a[n-1];
    cout << ans << "\n";

    return 0;
}




Measured memory_bytes: 3652
n = int(input())
a = [int(i) for i in input().split()]
ans = 0
mod = 10**9+7
for i in range(60):
    x = 0
    for j in range(n):
        if a[j] >> i & 1: x += 1 # i桁目が1である数の個数
    now = x*(n-x)%mod # 0と1の組み合わせの数(0 xor 1 = 1)
    for _ in range(i): now = now*2%mod # i桁目が1なら*2^i
    ans += now
    ans %= mod
print(ans)

Measured memory_bytes: 122936
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int dy[][7] = {{1, 0, -1, -1, -1, 0, 0}, {1, 1, 0, -1, 0, 1, 0}};
int dx[7] = {0, 1, 1, 0, -1, -1, 0};

const int INF = INT_MAX / 4;

class Data
{
public:
    int t, y, x;
    Data(int t0, int y0, int x0){
        t = t0;
        y = y0;
        x = x0;
    }
};

int main()
{
    int sx, sy, gx, gy, n;
    cin >> sx >> sy >> gx >> gy >> n;

    vector<int> fx(n), fy(n); // 家具の位置
    for(int i=0; i<n; ++i)
        cin >> fx[i] >> fy[i];

    int lx, ly;
    cin >> lx >> ly;

    vector<vector<bool> > isEnter(2*ly+1, vector<bool>(2*lx+1, true));
    for(int i=0; i<n; ++i)
        isEnter[fy[i]+ly][fx[i]+lx] = false;

    vector<vector<vector<int> > > dp(6, vector<vector<int> >(2*ly+1, vector<int>(2*lx+1, INF)));
    deque<pair<int, Data> > q;
    dp[0][sy+ly][sx+lx] = 0;
    q.push_back(make_pair(0, Data(0, sy, sx)));

    int ret = -1;
    while(!q.empty()){
        int cost0 = q.front().first;
        int t0 = q.front().second.t;
        int y0 = q.front().second.y;
        int x0 = q.front().second.x;
        q.pop_front();
        if(cost0 > dp[t0][y0+ly][x0+lx])
            continue;

        if(y0 == gy && x0 == gx){
            ret = cost0;
            break;
        }

        int d = abs(x0 * y0 * t0) % 6; // お姉さんが指示した方向
        int t = (t0 + 1) % 6;

        for(int i=0; i<7; ++i){
            int y = y0 + dy[abs(x0)%2][i];
            int x = x0 + dx[i];
            if(abs(y) > ly || abs(x) > lx || !isEnter[y+ly][x+lx])
                continue;

            if(i == d){
                int cost = cost0;
                if(cost < dp[t][y+ly][x+lx]){
                    dp[t][y+ly][x+lx] = cost;
                    q.push_front(make_pair(cost, Data(t, y, x)));
                }
            }else{
                int cost = cost0 + 1;
                if(cost0 < dp[t][y+ly][x+lx]){
                    dp[t][y+ly][x+lx] = cost;
                    q.push_back(make_pair(cost, Data(t, y, x)));
                }
            }
        }
    }

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 2460