akhauriyash/Code-Regression huggingface dataset:
use text_io::*;
// use std::collections::*;
// use std::process::exit;

fn main() {
    let n:usize = read!();
    let mut p:Vec<usize> = Vec::new();
    for _ in 0..n {
        let kk:usize = read!();
        p.push(kk);
    }
    let mut q:Vec<usize> = Vec::new();
    for _ in 0..n {
        let kk:usize = read!();
        q.push(kk);
    }
    let mut pp:usize = 0;
    for i in 0..n-1 {
        let mut ppp:usize = 1;
        for j in 1..n-i {
            ppp *= j;
        }
        pp += (p[i]-1)*ppp;
        for j in i+1..n-1 {
            if p[i]<p[j] {
                p[j]-=1;
            }
        }
    }
    let mut qq:usize = 0;
    for i in 0..n-1 {
        let mut qqq:usize = 1;
        for j in 1..n-i {
            qqq *= j;
        }
        qq += (q[i]-1)*qqq;
        for j in i+1..n-1 {
            if q[i]<q[j] {
                q[j]-=1;
            }
        }
    }
    println!("{}",(pp as isize-qq as isize).abs());
}

Measured memory_bytes: 2104
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define mod 1000000007
#define SYOU(x) setprecision(x+1)
#define abs(x,y) (max(x,y)-min(x,y))
#define lol long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a,b,c;
    string s;
    cin >>s;
    if(s[0]==s[1]&&s[1]==s[2]) cout <<"No\n";
    else cout <<"Yes\n";
    return (0);
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, X: int):
    # a_0 = 1
    # a_{n+1} = 2 * a_n + 3
    # b_0 = 1
    # b_{n+1} = 2 * b_n + 1

    # a_n = 2**(n+2) - 3
    # b_n = 2**(n+1) - 1
    def f(N: int, X: int):
        aN = 2 ** (N + 2) - 3
        bN = 2 ** (N + 1) - 1
        if X >= aN:
            return bN

        aN1 = 2 ** ((N - 1) + 2) - 3

        ans = 0

        X -= 1
        if X <= 0:
            return ans

        ans += f(N - 1, X)
        X -= aN1
        if X <= 0:
            return ans

        ans += 1
        X -= 1
        if X <= 0:
            return ans

        ans += f(N - 1, X)
        X -= aN1
        if X <= 0:
            return ans

        X -= 1
        if X <= 0:
            return ans

        assert False

    print(f(N, X))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    solve(N, X)


if __name__ == '__main__':
    main()


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

s=[int(input()) for i in range(n)]
s.sort()
ans=sum(s)
if ans % 10 != 0:
    print(ans)
else:
    for i in range(len(s)):
        if s[i] % 10 != 0:
            print(ans-s[i])
            break
    else:
        print(0)

Measured memory_bytes: 3060
s, t = list(input()), list(input())
if len(s) != len(t):
    print('No')
    exit(0)
s_cset = set(s)
t_cset = set(t)
if len(s_cset) != len(t_cset):
    print('No')
    exit(0)
s_count = set([])
t_count = set([])
for char in s_cset:
    disto = set([])
    for i, item in enumerate(s):
        if char == item:
            disto.add(i)
    s_count.add(frozenset(disto))
for char in t_cset:
    disto = set([])
    for i, item in enumerate(t):
        if char == item:
            disto.add(i)
    t_count.add(frozenset(disto))
if s_count != t_count:
    print('No')
    exit(0)
print('Yes')

Measured memory_bytes: 42080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    int x,y,z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;
    return 0;
}

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

int main(){
  int n;
  cin>>n;
  int r[n];
  cin>>r[0];
  int r_min=r[0];
  int ans=-1000000001;
  for (int i = 1; i < n; i++) {
    cin>>r[i];
    if (r[i]-r_min>ans) ans=r[i]-r_min;
    if (r[i]<r_min) r_min=r[i];

  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3876
#include <bits/stdc++.h>
using namespace std;
#define watch(x) cout << (#x) << " is " << (x) << '\n'
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef double db;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
//head
 
void solve(){
    int n;
    cin >> n;
    vector<ll> a(n+1);
    vector<ll> b(n);

    for (int i = 0; i < n+1; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];

    ll ans = 0;

    for (int i = 0; i < n; i++){
        ll defeated = min(a[i], b[i]);
        b[i] -= defeated;
        a[i] -= defeated;
        ans += defeated;
        defeated = min(a[i+1], b[i]);
        ans += defeated;
        a[i+1] -= defeated;
        b[i] -= defeated;
    }

    cout << ans << '\n';
}

int main(void){ 
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

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


Measured memory_bytes: 4720
object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val Array(datX, datN) = readLine.split(" ").map(_.toInt)
    val datP_ = readLine

    // early retrun in N = 0
    if (datN == 0) {
      println(datX)
      return
    }

    val datP = datP_.split(" ").map(_.toInt).toSet
    var flag = false
    var i = 0
    while (flag == false) {
      if (datP(datX - i) == false) {
        println(datX - i)
        flag = true
      }
      else if (datP(datX + i) == false) {
        println(datX + i)
        flag = true
      }
      i += 1
    }
  }
}


Measured memory_bytes: 54964
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 100000
struct edge{ int to,cost; };
typedef pair<int,int> P;
const int INF=1000000001;
 
int N,M;
int d[MAX_N];
vector<edge> G[MAX_N];
 
int main(){
  cin>>N>>M;
  for(int i=0;i<M;i++){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    G[a].push_back((edge){b,c});
  }
  int ans=-1;  
  priority_queue< P , vector<P> , greater<P> > Q;
  fill(d,d+MAX_N,INF);
  Q.push(P(1,1));
  d[1]=1;
  while(!Q.empty()){
    P p=Q.top();Q.pop();
    int pos=p.second;
    int cost=p.first;
    if(d[pos]<cost)continue;
    for(int i=0;i<(int)G[pos].size();i++){
      edge e=G[pos][i];
      if(e.cost<d[pos])continue;
      if(e.to==N)ans=max(ans,e.cost);
      if(d[e.to]>e.cost){
        d[e.to]=e.cost;
        Q.push(P(d[e.to],e.to));
      }
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 9564
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>

using namespace std;

#line 2 "abc160_d.cpp"

struct edge {
  int to, cost;
};
typedef vector<vector<edge>> graph;

void dijkstra(int s, int n, graph &g, vector<int> &d) {
  // (最短距離, 頂点)
  priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> q;

  REP(i, n) { d[i] = INT_MAX; }
  d[s] = 0;
  q.push(make_pair(0, s));

  while (!q.empty()) {
    auto p = q.top();
    q.pop();

    int v = p.second;
    if (d[v] < p.first)
      continue;
    REP(i, g[v].size()) {
      auto e = g[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        q.push(make_pair(d[e.to], e.to));
      }
    }
  }
}

int main() {
  int n, x, y;
  cin >> n >> x >> y;
  x--;
  y--;
  graph g(n);
  REP(i, n - 1) {
    g[i].push_back({i + 1, 1});
    g[i + 1].push_back({i, 1});
  }
  g[x].push_back({y, 1});
  g[y].push_back({x, 1});

  vi ans(n);

  REP(i, n) {
    vi d(n, 0);
    dijkstra(i, n, g, d);
    REP(i, n) { ans[d[i]]++; }
  }

  FOR(i, 1, n) { cout << ans[i] / 2 << endl; }
}


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

int main() {
    int N;
    cin >> N;
    vector<vector<int>> A(N, vector<int>(2));
    for (int i = 0; i < N; i++) {
        cin >> A.at(i).at(0);
        A.at(i).at(1) = i + 1;
    }
    sort(A.begin(), A.end());
    for (int i = 0; i < N; i++) {
        cout << A.at(i).at(1) << " ";
    }
}

Measured memory_bytes: 6272
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var XY = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var group = new int[12] { 0, 2, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0 };
            var x = group[XY[0] - 1];
            var y = group[XY[1] - 1];
            Console.WriteLine(x == y ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 28280
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
count = 0
ans = 0
for i in range(n):
  l = list(map(int,input().split()))
  for j in range(m):
    ans += b[j]*l[j]
  if ans +c > 0:
    count += 1
    
  ans = 0
print(count)


Measured memory_bytes: 3060
MOD = 998244353
N, M, K = map(int, input().split())

factorials = [0] * (N + 1)
factorials[0] = 1
for i in range(1, N + 1):
    factorials[i] = factorials[i - 1] * i % MOD
invs = [None] * (N + 1)
invs[1] = 1
for i in range(2, N + 1):
    invs[i] = (invs[i - 1] * pow(i, MOD - 2, MOD)) % MOD


def nCr(n, r):
    if n <= 0 or n <= r or r <= 0:
        return 1
    if n - r < r:
        return nCr(n, n - r)
    return factorials[n] * invs[n - r] * invs[r] % MOD


ans = 0
for x in range(N - K - 1, N):
    ans = (ans + nCr(N - 1, x) * M * pow(M - 1, x, MOD)) % MOD
print(ans)

Measured memory_bytes: 24664
#include<iostream>

using namespace std;

typedef long long ll;

int main(){
  ll N,M; cin >> N >> M;
  ll cnt = 0;
  cnt += min( N, M / 2); ll a = M - 2 * cnt;
  if( a > 0){ cnt += a / 4;}
  cout << cnt << endl; return 0;}

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

using namespace std;

int main()
{
	int n;
	cin >> n;
	int m = 0, ans;
	for (int i = 0; i < n; i++)
	{
		int a, b;
		cin >> a >> b;
		if (a > m)
		{
			ans = a + b;
			m = a;
		}
	}
	cout << ans << endl;

	return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<string> S(n);
  int min_i = -1, min_size = 51;
  for (int i = 0; i < n; ++i) {
    cin >> S[i];
    sort(S[i].begin(), S[i].end());
    if (S[i].size() < min_size) {
      min_size = S[i].size();
      min_i = i;
    }
  }
  
  string result = "";
  for (int i = 0; i < min_size; ++i) {
    char c = S[min_i][i];
    bool flg = true;
    for (int j = 0; j < n; ++j) {
      if (j == min_i) {
        continue;
      }
      auto itr = find(S[j].begin(), S[j].end(), c);
      if (itr == S[j].end()) {
        flg = false;
        break;
      } else {
        S[j].erase(itr);
      }
    }
    if (flg) {
      result += c;
    }
  }
  cout << result << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  string s;
  cin >> s;
  string l = s.substr(0, n);
  string r = s.substr(n);
  reverse(all(r));
  // cout << "l: " << l << endl;
  // cout << "r: " << r << endl;

  // Here, we want to check all substring of l and r.
  unordered_map<string, ll> patterns; // pair of <pattern, count>
  rep(i, 1ll<<n) {
    string red, blue;
    rep(j, n) {
      if (i & 1ll<<j) {
        red += l[j];
      } else {
        blue += l[j];
      }
    }
    reverse(all(blue));

    string pattern = red + "$" + blue;
    ++patterns[pattern];
  }

  ll ans = 0;
  // Here, we want to find the pattern in right.
  rep(i, 1ll<<n) {
    string red, blue;
    rep(j, n) {
      if (i & 1ll<<j) {
        red += r[j];
      } else {
        blue += r[j];
      }
    }
    reverse(all(blue));

    string pattern = red + "$" + blue;
    if (patterns.find(pattern) != patterns.end()) {
      ans += patterns[pattern];
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 35016
import java.io.*;

public class Main{
    public static void main(String[] args){
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String line;

        try{
        while((line = reader.readLine()) != null){
            if(line.equals("0")){break;}
            int sum=0;
            for(int i=0;i<line.length();i++){
                sum = sum + line.charAt(i)- '0';
            }

            System.out.println(sum);
        }
        } catch (IOException e){
            System.out.println(e);
        }

    }
}


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

int main() {
	int temp;
	int s[4];
	int format[2] = { 1, 1 };
	// 0:YYMM 1:MMYY
	cin >> temp;
	for (int i = 3; i >= 0; i--) {
		s[i] = temp % 10;
		temp /= 10;
	}

	if (s[0] != 0 && s[0] != 1)
		format[1] = 0;
	if (s[0] == 1 && s[1] != 0 && s[1] != 1 && s[1] != 2)
		format[1] = 0;
	if (s[0] == 0 && s[1] == 0)
		format[1] = 0;
	if (s[2] != 0 && s[2] != 1)
		format[0] = 0;
	if (s[2] == 1 && s[3] != 0 && s[3] != 1 && s[3] != 2)
		format[0] = 0;
	if (s[2] == 0 && s[3] == 0)
		format[0] = 0;
	if (format[0] == 1 && format[1] == 1)
		cout << "AMBIGUOUS" << endl;
	if (format[0] == 0 && format[1] == 0)
		cout << "NA" << endl;
	if (format[0] == 1 && format[1] == 0)
		cout << "YYMM" << endl;
	if (format[0] == 0 && format[1] == 1)
		cout << "MMYY" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long ways[3][30], best[3][30];
int main(){
	int n, a, b; cin >> n >> a >> b;
	vector<long long> v(n);
	for(int i = 0; i < n; i++) cin >> v[i];
	if(n == 1){
		cout << v[0] << endl;
		cout << 1 << endl;
		return 0;
	}
	if(n == 2){
		if(v[0] == v[1]){
			cout << v[0] << endl;
			cout << 3 << endl;
			return 0;
		} else {
			cout << max(v[0], v[1]) << endl;
			cout << 1 << endl;
			return 0;
		}
	}
	int pa = n / 3;
	int pb = n / 3;
	int pc = n - pa - pb;
	long long mean = 0, sz = 1, wy = 0;
	auto apply = [&](long long sum, int len, long long was){
		if(a <= len && len <= b){
			if(mean * len < sum * sz) mean = sum, sz = len, wy = was;
			else if(mean * len == sum * sz) wy += was;
		}
	};
	auto gen = [&](int who, int len, int off){
		vector<long long> sums(1<<len, 0);
		unordered_map<int,int> pos;
		for(int i = 0; i < len; i++) pos[1<<i] = i;
		for(int i = 0; i < 1<<len; i++){
			if(i){
				sums[i] = sums[i - (i&-i)] + v[pos[i&-i] + off];
			}
			int id = __builtin_popcount(i);
			apply(sums[i], id, 1);
			if(best[who][id] < sums[i]) best[who][id] = sums[i], ways[who][id] = 1;
			else if(best[who][id] == sums[i]) ways[who][id]++;
		}
	};
	gen(0, pa, 0);
	gen(1, pb, pa);
	gen(2, pc, pa + pb);
	for(int i = 0; i <= pa; i++){
		for(int j = 0; j <= pb; j++){
			for(int k = 0; k <= pc; k++){
				int big = 0;
				big += i > 0;
				big += j > 0;
				big += k > 0;
				if(big > 1)
				apply(best[0][i] + best[1][j] + best[2][k], i + j + k, ways[0][i] * ways[1][j] * ways[2][k]);
			}
		}
	}
	cout << fixed << setprecision(9) << mean * 1.0 / sz << endl;
	cout << wy << endl;
	return 0;
}


Measured memory_bytes: 2812
def ketanowa(p):
    ans = 0
    p = str(p)
    for i in p:
        ans += int(i)
    return ans


def main():
    temp=input()
    temp=list(map(int,list(temp.split(" ")))) 
    X = temp[2]
    Y = temp[3]
    temp=input()
    temp=list(map(int,list(temp.split(" ")))) 
    x = max(temp)
    temp=input()
    temp=list(map(int,list(temp.split(" ")))) 
    y = min(temp)
    for z in range(X+1,Y+1):
        if x < z and z<=y:
            print("No War")
            return 0
    
    print("War")

if __name__ == '__main__':
    main()


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

using namespace std;

int main() {
	int n, total = 0;
	cin >> n;
	
	int arr[n];
	for (int i = 0; i < n; i++) cin >> arr[i];
	
	for (int i = 1; i < n - 1; i++) {
		if ((arr[i] > arr[i - 1] && arr[i] < arr[i + 1]) || (arr[i] > arr[i + 1] && arr[i] < arr[i - 1])) {
			total++;
		}
	}
	
	cout << total;
	
	return 0;
}

Measured memory_bytes: 256
#%%
import collections

n = int(input())
v = list(input().split())
v1 = v[0::2]
v2 = v[1::2]

#print(v1)
#print(v2)


l1 = list(collections.Counter(v1).items())
l2 = list(collections.Counter(v2).items())


l1 = sorted(l1, key=lambda x: x[1], reverse=True) 
l2 = sorted(l2, key=lambda x: x[1], reverse=True) 


if l1[0][0] != l2[0][0]:
    tmp = l1[0][1] + l2[0][1]
else:
    if len(l1) > 1 and len(l2) > 1: 
        tmp = max(l1[1][1] + l2[0][1], l1[0][1] + l2[1][1])
    elif len(l1) == 1 and len(l2) > 1:
        tmp = max(l2[0][1], l1[0][1] + l2[1][1])
    elif len(l2) == 1 and len(l1) > 1:
        tmp = max(l1[1][1] + l2[0][1], l1[0][1])
    else:
        tmp = max(l2[0][1], l1[0][1])

ans = n - tmp
print(ans)


Measured memory_bytes: 23388
n = int(input())
s = list(input())
s1 = [1 if si=='(' else -1 for si in s]
cnt1=0#( のカウント
cnt2=0
ans1=0
ans2=0
for i in range(n):
    if s1[i]==1and cnt2>0:
        ans2+=cnt2
        cnt2 = 0
    cnt2+=-s1[i]
if cnt2>0:
    ans2+=cnt2
for i in range(n)[::-1]:
    if s1[i]==-1and cnt1>0:
        ans1+=cnt1
        cnt1 = 0
    cnt1+=s1[i]
if cnt1>0:
    ans1+=cnt1
s=['(']*ans2+s+[')']*ans1
print(''.join(s))

Measured memory_bytes: 38256
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
typedef unsigned int ui; 
struct edge { int to, cost; };
int V=10;
vector<edge> G[10];
int d[10];
void dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P>>que;
	fill(d, d + V, MOD);
	d[s] = 0;
	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first)continue;
		for (int i = 0; i < (int)G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}
int main() {
	int h, w,c,A;
	cin >> h >> w;
	int i, j;
	for (i = 0; i < 10; i++) {
		for (j = 0; j < 10; j++) {
			cin >> c;
			G[j].push_back({ i,c });
		}
	}
	dijkstra(1); int sum = 0;
	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			cin >> A;
			if (A > -1)sum += d[A];
		}
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
txy = [(0, 0, 0)] + [tuple(map(int, input().split())) for _ in range(N)]
for i in range(N):
    t1, x1, y1 = txy[i]
    t2, x2, y2 = txy[i+1]
    if abs(x2-x1) + abs(y2-y1) <= t2 - t1 and (x1+y1+x2+y2) % 2 == (t2-t1) % 2:
        continue
    else:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 62040
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;

lint K;
lint amari = 0;
int main() {
	cin >> K;
	REP(i, K + 1) {
		amari *= 10;
		amari += 7;
		amari %= K;
		if (amari == 0) {
			cout << i + 1 << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}


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

int main()
{
  int64_t n,k;
  cin >> n >> k;
  
  int64_t ans = n % k;
  if(ans < abs(ans - k)){
    cout << ans << endl;
  }else{
    cout << abs(ans - k) << endl;
  }
}

Measured memory_bytes: 3600
from functools import reduce
INF = int(1e9 + 7)


def modmulti(a, b):
    # aとbを掛けた値をmodする(a * b mod p)
    return a * b % INF


def factorial(x):
    FCT = 1
    FCT = reduce(modmulti, range(2, x + 1), FCT)
    return FCT


def main():
    N, M = map(int, input().split())
    MIN_NM = factorial(min(N, M))
    if N == M or N + 1 == M or N == M + 1:
        print(modmulti(2, modmulti(MIN_NM, MIN_NM))
              if N == M else modmulti(MIN_NM, modmulti(MIN_NM, max(N, M))))
    else:
        print(0)

    return


main()


Measured memory_bytes: 3572
#include <iostream>

using namespace std;

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

  k = ( a + b ) / 2;

  if ( (a+b)%2 != 0 ) {
    cout << "IMPOSSIBLE" << endl;
  } else {
  	cout << k << endl;
  }
  return 0;

}


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

#define N 401
using namespace std;

int n;
long long a[N];
long long dp1[N][N];
long long dp2[N][N];

long long solve()
{
	for (int i = 1; i <= n; i++)
	{
		dp1[i][i] = a[i];
		dp2[i][i] = 0;
	}
	for (int len = 2; len <= n; len++)
	{
		for (int i = 1; i <= n - len + 1; i++)
		{
			int j = i + len - 1;
			dp2[i][j] = LLONG_MAX;
			for (int k = i; k < j; k++)
			{
				long long temp = dp1[i][k] + dp1[k + 1][j] + dp2[i][k] + dp2[k + 1][j];
				if (temp < dp2[i][j])
				{
					dp1[i][j] = dp1[i][k] + dp1[k + 1][j];
					dp2[i][j] = temp;
				}
			}
		}
	}
	return dp2[1][n];
}

int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	cout << solve() << endl;
	return 0;
}



Measured memory_bytes: 2816
from functools import reduce
from fractions import gcd
n=int(input())
a=[int(input()) for i in range(n)]
def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)
print(lcm_list(a))

Measured memory_bytes: 5128
#![allow(unused)]

//input
//use std::io::Read;

//collections
//use std::collections::BTreeMap;
//use std::collections::BTreeSet;
//use std::collections::HashMap;
//use std::collections::HashSet;

//入力マクロここから
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
//入力マクロここまで

fn mod_pow(a: u64, n: u64, p: u64) -> u64 {
    let mut ans = 1;
    let mut a = a;
    let mut n = n;

    while n > 0 {
        if n & 1 == 1 {
            ans = ans * a % p
        }
        a = a * a % p;
        n >>= 1;
    }

    ans
}

fn inv_init(n: usize, p: u64) -> Vec<u64> {
    let mut inv = vec![0; n + 1];

    inv[1] = 1;

    for i in 2..n + 1 {
        inv[i] = p - inv[p as usize % i] * (p / i as u64) % p;
    }

    inv
}

fn com_init(n: u64, k: usize, p: u64, inv: &Vec<u64>) -> Vec<u64> {
    let mut com = vec![0; k + 1];

    com[0] = 1;

    let end = std::cmp::min(n, k as u64) as usize;

    for i in 1..end + 1 {
        com[i] = com[i - 1];
        com[i] *= (n - (i as u64) + 1) % p;
        com[i] %= p;
        com[i] *= inv[i];
        com[i] %= p;
    }
    com
}

fn main() {
    input! {
        n: u64,
        a: usize,
        b: usize,
    }

    let p: u64 = 1_000_000_007;
    let k: usize = 200_000;

    let inv = inv_init(k, p);
    let com = com_init(n, k, p, &inv);

    let m_mod = |a: i64, b: i64| {
        let r = a % b;
        if r < 0 {
            r + b.abs()
        } else {
            r
        }
    };

    let pow = mod_pow(2, n as u64, p);

    println!(
        "{}",
        m_mod((pow as i64 - 1 - com[a] as i64 - com[b] as i64), p as i64)
    );
}

Measured memory_bytes: 8444
#include<cstdio>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int main(){
	static int lg[1<<20];
	rep(u,20) lg[1<<u]=u;

	for(int n,lb;scanf("%d%d",&n,&lb),n;){
		int score[20];
		bool wf[20][20]={};
		rep(u,n){
			int m; scanf("%d%d",score+u,&m);
			rep(i,m){
				int v; scanf("%d",&v);
				wf[v][u]=true;
			}
		}

		rep(k,n) rep(i,n) rep(j,n) wf[i][j]|=wf[i][k]&wf[k][j];

		int a[20]={};
		rep(u,n) rep(v,n) if(u!=v && wf[v][u]) a[u]|=1<<v;

		static int pc[1<<20],sum[1<<20],A[1<<20];

		int ans=n;
		for(int S=1;S<(1<<n);S++){
			int T=S&~(S&(-S));
			int lsb=lg[S&(-S)];
			pc[S]=pc[T]+1;
			sum[S]=sum[T]+score[lsb];
			A[S]=A[T]|a[lsb];
			if((S&A[S])==A[S] && sum[S]>=lb) ans=min(ans,pc[S]);
		}
		printf("%d\n",ans);
	}

	return 0;
}

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


ll mod = 1e9+7;

ll modpower(ll a, ll r){ //a^r
    ll x = 1;
    while (r > 0) {
        if (r & 1) x = x * a % mod;
        r >>= 1;
        a = a * a % mod;
    }
    return x;
}

ll modinv(ll a){
    return modpower(a, mod-2);
}

ll modconv(ll n, ll k){
	ll res = 1;
	for (ll i = n; i >= n-k+1; i--) res = res * i % mod;
	for (ll i = 1; i <= k; i++) res = res * modinv(i) % mod;
	return res;
}

int main(){
    ll N, M, K;
    cin >> N >> M >> K;
    
    ll ans = 0;
    ans += N*N %mod *M %mod *(M-1) %mod *(M+1)%mod*modinv(6)%mod*modconv(N*M-2, K-2)%mod;
    ans += M*M %mod *N %mod *(N-1) %mod *(N+1)%mod*modinv(6)%mod*modconv(N*M-2, K-2)%mod;
    cout << ans%mod << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define M 100007
using namespace std;
int n,ans=1,a[M],b[M];
int main() {
	scanf("%d",&n);
	for(int i=1; i<=n; i++)
		scanf("%d",&a[i]);
	b[1]=a[n];
	for(int i=n-1; i>=1; i--) {
		if(b[ans]<=a[i])b[++ans]=a[i];
		else {
			int l=1,r=ans;
			while(l<=r){
				int mid=(l+r)>>1;
				if(b[mid]<=a[i])l=mid+1;
				else r=mid-1;
			}b[l]=a[i];
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1024
import java.util.*;
import java.math.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int a = s.nextInt();
        int b = s.nextInt();
        int c = s.nextInt();
        if (a + b + c <= 21) {
            System.out.println("win");
        } else {
            System.out.println("bust");
        }
    }
}

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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e10;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)

typedef priority_queue<P, vector<P>, greater<P>> PQ_ASK;
const int mod = 1000000007;

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

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

int ans = a - 1;
if( b >= a) {
    ans ++;
}

    cout << ans << endl;

}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
   int h,w,k,i,j,a[300][300],c,f,ff;
   char s[300][301];
 
   scanf("%d %d %d",&h,&w,&k);
   for (i=0;i<h;i++) {
      scanf("%s",&s[i]);
      for (j=0;j<w;j++)
         if (s[i][j]=='.') a[i][j]=0;
         else              a[i][j]=k--;
   }
   for (ff=i=0;i<h;i++) {
      for (f=c=j=0;j<w;j++)
         if (a[i][j]==0 && c>0) a[i][j]=c;
         else if (a[i][j]>0) c=a[i][j];
         else f=1;
         if (f && c>0) {
            for (j=0;a[i][j]==0;j++) ;
            c=a[i][j];
            for (j--;j>=0;j--) a[i][j]=c;
         } else if (f && ff) {
            for (j=0;j<w;j++) a[i][j]=a[i-1][j];
         }
         if (c>0 && ff==0) {
            ff=1;
            for (k=0;k<i;k++)
               for (j=0;j<w;j++) a[k][j]=a[i][j];
         }
   }     
   for (i=0;i<h;i++) {
      printf("%d",a[i][0]);
      for (j=1;j<w;j++)
         printf(" %d",a[i][j]);
      puts("");
   }
   return 0;
}


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

using namespace std;

int main(){
  int A,B;
  
  cin >> A >> B;
  
  int a,b,c;
  
  a = A+(A-1);
  b = B+(B-1);
  c = A+B;
  
  int result;
  
  result = max(a,max(b,c));
  
  cout << result << endl;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmax(v) v.rbegin()->first
#define mapmin(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

template<class T>
inline bool chmax(T& a, T b){if(a<b){a=b;return true;} return false;}

template<class T>
inline bool chmin(T& a, T b){if(a>b){a=b;return true;} return false;}

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,r=0,g=0,b=0;
	string s,t="BGR";
	cin >> n >> s;
	rep(i,n){
		if(s[i]=='R') r++;
		if(s[i]=='G') g++;
		if(s[i]=='B') b++;
	}
	ll ans=r*g*b;
	rep(i,n-1){
		for(ll j=i+1;j<n;j++){
			if(j+(j-i)>=n) continue;
			string tmp="";
			tmp+=s[i];
			tmp+=s[j];
			tmp+=s[j+(j-i)];
			sort(all(tmp));
			if(tmp==t) ans--;
		}
	}
	cout << ans << endl;
	return 0;
}


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

#define rep(i, n) for(int i = 0; i < n; ++i)

int w,h;
bool black[51][51];
bool white[51][51];
string field[51];

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

void solve(int x, int y, char c) {
  if ((c == 'B' and black[y][x]) || (c == 'W' and white[y][x])) return;

  if (c == 'W' and field[y][x] != 'W') white[y][x] = true;
  else if (c == 'B' and field[y][x] != 'B') black[y][x] = true;

  rep(i, 4) {
    int nx = x + dx[i], ny = y + dy[i];
    if (0 <= nx and nx < w and 0 <= ny and ny < h and field[ny][nx] == '.') {
      solve(nx, ny, c);
    }
  }
}

int main() {
  while (cin >> w >> h, w || h) {
    rep(i, h) {
      cin >> field[i];
    }

    fill(black[0], black[50], false);
    fill(white[0], white[50], false);

    rep(i, h) rep(j, w) {
      if (field[i][j] == 'W') solve(j,i,'W');
      else if (field[i][j] == 'B') solve(j,i,'B');
    }

    int bl, wh;
    bl = wh = 0;

    rep(i, h) rep(j, w) {
      if (black[i][j] && !white[i][j]) bl += 1;
      else if (!black[i][j] && white[i][j]) wh += 1;
    }

    cout << bl << " " << wh << endl;
  }
}


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

using namespace std;

int main(void){

    int a, b, k;
    cin >> a >> b >> k;

    for(int i = a;i <= min(b, a+k-1);i++) cout << i << endl;
    for(int i = max(b-k+1, a+k);i <= b;i++) cout << i << endl;

    return 0;
}

Measured memory_bytes: 256
N , K = map(int,input().split())

ALL = set()
for _ in range(K):
    d = int(input())
    A = list(map(int,input().split()))
    for a in A:
        ALL.add(a)
cnt = 0

for i in range(1,N+1):
    if not i in ALL:
        cnt += 1
print(cnt)

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int main(){
    string n;
    cin >> n;;
    int k;
    cin >> k;
    int sz;
    sz = n.size();

    int dp[110][2][5] = {};
    //dp[i+1][j][k] i桁目まで　j=0ならn未満決定　0でない数がk個
    dp[0][1][0] = 1;

    for (int i = 0; i < sz; ++i) {
        int di = n[i] - '0';
        for (int j = 0; j <= 3; ++j) {
            if(di == 0){
                dp[i+1][1][j] += dp[i][1][j];
                dp[i+1][0][j] += dp[i][0][j];
                dp[i+1][0][j+1] += dp[i][0][j] * 9;
            }
            else{
                dp[i+1][1][j+1] += dp[i][1][j];
                dp[i+1][0][j] += dp[i][0][j] + dp[i][1][j];
                dp[i+1][0][j+1] += dp[i][0][j] * 9 + dp[i][1][j] * (di - 1);
            }
        }
    }
    cout << dp[sz][0][k] + dp[sz][1][k] << endl;
}

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

int ia, ib, ps;

void read(void)
{
    if (scanf("%d %d", &ia, &ib) != 2)
        exit(EXIT_FAILURE);
}

void exec(void)
{
    ps = (ia > 0) ? 1 : ((ib < 0) ? 2 * ((ib - ia) % 2) - 1 : 0);
}

void print(void)
{
    printf("%s\n", ps < 0 ? "Negative" : (ps > 0 ? "Positive" : "Zero"));
}

void repl(void)
{
    read();
    exec();
    print();
}

int main(void)
{
    repl();
    return 0;
}


Measured memory_bytes: 128
package main

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

func main() {
  sc := bufio.NewScanner(os.Stdin)
  sc.Split(bufio.ScanWords)

  sc.Scan()

  n, _ := strconv.Atoi(sc.Text())

  a := make([]int64, n)
  sign := int64(1)

  for i := 0; i < n; i++ {
    sc.Scan()
    v, _ := strconv.Atoi(sc.Text())
    if v >= 0 {
      a[i] = int64(v)
    } else {
      a[i] = -1 * int64(v)
      sign *= -1
    }
  }

  if sign >= 0 {
    sum := int64(0)
    for i := 0; i < n; i++ {
      sum += a[i]
    }
    fmt.Println(sum)
    os.Exit(0)
  }

  var j int
  min := int64(math.MaxInt64)
  for i := 0; i < n; i++ {
    v := a[i]
    if v < min {
      min = v
      j = i
    }
  }

  sum := int64(0)

  for i := 0; i < n; i++ {
    if i == j {
      sum -= a[i]
    } else {
      sum += a[i]
    }
  }

  fmt.Println(sum)
}


Measured memory_bytes: 3072
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
using namespace std;
#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define INF 100000000
#define _INF -100000000
#define INFLL (long long)1e14
#define _INFLL (long long)-1e14
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;

struct node {
	bool done;
	vi to, dist;
	int id, from;
	ll d;
	bool operator<(const node & another) const {
		return !(d != another.d ? d < another.d : id < another.id);
	}
};

void prim(vector<node> nodes, int n) {
	priority_queue<node> pq;
	nodes[0].d = 0;
	pq.push(nodes[0]);
	while (pq.size()) {
		node focus = pq.top(); pq.pop();
		if (nodes[focus.id].done) continue;
		Loop(i, focus.to.size()) {
			if (!nodes[focus.to[i]].done && focus.dist[i] < nodes[focus.to[i]].d) {
				nodes[focus.to[i]].d = focus.dist[i];
				nodes[focus.to[i]].from = focus.id;
				pq.push(nodes[focus.to[i]]);
			}
		}
		nodes[focus.id].done = true;
	}
	ll ans = 0;
	Loop(i, n) {
		ans += nodes[i].d;
	}
	cout << ans << endl;
	return;
}

int main() {
	int v, e; cin >> v >> e;
	vector<node> nodes(v);
	Loop(i, v) nodes[i] = { false,{},{}, i, -1, INFLL };
	Loop(i, e) {
		int s, t, d; cin >> s >> t >> d;
		nodes[s].to.push_back(t);
		nodes[s].dist.push_back(d);
		nodes[t].to.push_back(s);
		nodes[t].dist.push_back(d);
	}
	prim(nodes, v);
}

Measured memory_bytes: 14656
mod = 10**9+7
n = int(input())
num = [ int(v) for v in input().split() ]

def gcd(a,b):
    if a < b:
        a, b = b, a
    while b >= 1:
        a, b = b, a % b
    return a
def lcm(a,b):
	return a * b // gcd(a,b)

def shave(n):
    if n < 2:
        return []
    else:
        n_root = int(n**0.5)
        candidate = [i for i in range(3, n+1, 2)]
        for i in range(3, n_root+2, 2):
            candidate = [j for j in candidate if j == i or j % i != 0]
        candidate = [2] + candidate
        return candidate

d = {}
prime_list = shave(10**3)
for i in prime_list:
    d[i] = 0

def prime_factorization(x):

    for i in prime_list:
        if x == 1:
            break
        elif x % i == 0:
            q = 0
            while x % i == 0:
                x //= i
                q += 1
            d[i] = max(d[i], q)
    if x != 1:
        d[x] = 1
    return 

for i in num:
    prime_factorization(i)

l = 1
for i in d:
    l *= pow(i, d[i], mod)
    l %= mod

ans = 0
for i in num:
    a = l * pow(i, mod-2, mod)
    ans += a
    ans %= mod
print(ans)

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

int main(){
    ll n, ans;
    cin >> n;
    ans = n + 1;
    for(ll i = 1; i <= sqrt(n); ++i){
        if(n%i == 0) ans = min(i + n/i, ans); 
    }
    cout << ans-2;
 }


Measured memory_bytes: 256
//AtCoder 
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
int main() {
#if LOCAL&0
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll N; cin>>N;
    ll base=-2;
    string ans;
    while(N!=1&&N!=0){
        ll s0=1;
        if (abs(N-s0)%2==0) {
            //s0が1
            ans.push_back('1');
            N=(N-s0)/base;
        } else {
            //s0が0
            ans.push_back('0');
            N=N/base;
        }
    }
    ans.push_back('0'+N);
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;   
    return 0;
}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

use std::collections::BinaryHeap;
use std::iter::FromIterator;

fn main() {
    let nm: Vec<usize> = read_vec();
    let n = nm[0];
    let m = nm[1];
    let a: Vec<u64> = read_vec();
    let mut bh = BinaryHeap::from(a);

    let mut bc: Vec<Vec<u64>> = read_vec2(m);
    bc.sort_by(|x, y| y[1].partial_cmp(&x[1]).unwrap());

    let mut cnt: usize = 0;
    for i in 0..m {
        for _ in 0..bc[i][0] {
            bh.push(bc[i][1]);
            cnt += 1;
            if cnt >= n {
                break;
            }
        }
        if cnt >= n {
            break;
        }
    }

    let mut ans: u64 = 0;
    for _ in 0..n {
        ans += bh.pop().unwrap();
    }

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


Measured memory_bytes: 14708
import java.util.*;
import java.io.*;
import java.math.*;
public class Main{
	static int mod = (int)1e9+7;
	public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
	public static void main(String sp[])throws IOException{
		FastReader sc = new FastReader();
		int n = sc.nextInt();
		int arr[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
		System.out.println(arr[n-1]);
		
		
	}
	
	
	public static class pair{
		int a;
		int b;
	}
	
	
	
	static int parent[];
	public static int find(int a){
		if(parent[a]==a)
			return a;
		int rep = find(parent[a]);
		parent[a]=rep;
		return rep;
	}
	public static void join(int a, int b){
		int f1 = find(a);
		int f2 = find(b);
		if(f1==f2)
			return;
		
		if(f1<f2)
			parent[f2] = f1;
		else parent[f1] = f2;
	}
	
	
	public static class FastReader {
		BufferedReader br;
		StringTokenizer st;
	
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
 
		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (Exception r) {
					r.printStackTrace();
				}
			}
			return st.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());//converts string to integer
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (Exception r) {
				r.printStackTrace();
			}
			return str;
		}
	}
}


Measured memory_bytes: 21332
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

cnt = 0
mi = 10**9
for i in range(n):
    if a[i] < 0 or a[i] == 0:
        cnt += 1
    mi = min(mi, abs(a[i]))

sum = 0
for i in a:
    sum += abs(i)

if cnt % 2 != 0:
    print(sum - mi * 2)
else:
    print(sum)


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

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(in.readLine());
        long l = Long.parseLong(st.nextToken());
        long r = Long.parseLong(st.nextToken());
        if (r - l > 2019) {
            System.out.println("0");
            return;
        }
        long res = Integer.MAX_VALUE;
        for (long i = l; i <= r; i++) {
            for (long j = l; j <= r; j++) {
                if (i != j) {
                    long x = (i * j) % 2019;
                    if (x < res) {
                        res = x;
                    }
                }
            }
        }
        System.out.println(res);
    }

}
/*

 */

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

int main() {
    int integers[101] = {};
    int n;
    while (cin >> n) {
        integers[n]++;
    }
    int modeValue = 0;
    for (int i = 1; i < 101; i++) {
        if (modeValue < integers[i]) {
            modeValue = integers[i];
        }
    }
    for (int i = 1; i < 101; i++) {
        if (modeValue == integers[i]) {
            cout << i << endl;
        }
    }
}

Measured memory_bytes: 0
#include <algorithm>
#include <iostream>
#include <string>

int main() {
  int N;
  std::string S;
  std::cin >> N >> S;

  int count[300000];
  count[0] = std::count(S.begin() + 1, S.end(), 'E');
  for (int i = 1; i < N; ++i) {
    count[i] = count[i - 1];
    if (S[i] == 'E')
      --count[i];
    if (S[i - 1] == 'W')
      ++count[i];
  }

  std::cout << *std::min_element(count, count + N) << std::endl;
}


Measured memory_bytes: 1796
#include<algorithm>
#include <iostream>
#include<bitset>
using namespace std;
int main() {
	string s;int n, a;
	bool b = true;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a;
		if (a % 2 == 0) {
			if (a % 3 == 0 || a % 5 == 0)
				continue;
			else {
				b = false;
				break;
			}
		}
	}
	if (b)
		cout << "APPROVED" << endl;
	else
		cout << "DENIED" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main() {
  ll n,ans=0;
  cin >> n;
  vl a(n);
  rep(i,n){
    cin >> a[i];
  }
  ll x=-INF,y=0;
  rep(i,n){
    if(x>=a[i]){
      x=a[i];
      y++;
      ans=max(ans,y);
    }
    else{
      y=0;
      x=a[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024