akhauriyash/Code-Regression huggingface dataset:
A,B,M =map(int,input().split())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
x = []
for m in range(M):
    x.append([int(i) for i in input().split()])
_min = min(a)+min(b)
		
for i in x:
    _min = min( (a[i[0]-1]+b[i[1]-1] - i[2]),_min)
print(_min)

Measured memory_bytes: 32488
use std::cmp;

fn main(){
  let inf:usize = 1000000000;
  loop {
    let nm: Vec<usize> = read_vec();
    let n = nm[0];
    let m = nm[1];

    if n == 0 && m == 0 { break; }

    let mut rv: Vec<Vec<usize>> = vec![vec![0;1000];n];

    for i in 0 .. n {
      let kv: Vec<usize> = read_vec();

      for j in 0 .. kv[0] {
        rv[i][kv[j*2+1]-1] = kv[j*2+2];
      }
    }

    let mut dv0: Vec<Vec<usize>> = vec![vec![inf;1000]; m+1];
    
    for i in 0 .. 1000 {
      if rv[0][i] > 0 {
        dv0[m][i] = 0;
      }
    }
    
    let mut dv1 = dv0;
    dv0 = vec![vec![inf;1000]; m+1];
    
    for i in 0 .. 1000 {
      if rv[1][i] > 0 && m > 0 {
        dv0[m-1][i] = 0;
      }
      for j in 0 .. 1000 {
        if rv[0][j] > 0 {
          dv0[m][i] = cmp::min(dv0[m][i], dv1[m][j] + (cmp::max(i, j) - cmp::min(i, j)) * (rv[1][i] + rv[0][j]));
        }
      }
    }

    let mut dv2 = dv1;
    dv1 = dv0;
    dv0 = vec![vec![inf;1000]; m+1];
      
    for k in 2 .. n {
      for i in 0 .. 1000 {
        if rv[k][i] > 0 {
          for j in 0 .. 1000 {
            if rv[k-1][j] > 0 {
              for l in 0 .. m+1 {
                dv0[l][i] = cmp::min(dv0[l][i], dv1[l][j] + (cmp::max(i, j) - cmp::min(i, j)) * (rv[k][i] + rv[k-1][j]));
              }
            }
            if rv[k-2][j] > 0 {
              for l in 0 .. m {
                dv0[l][i] = cmp::min(dv0[l][i], dv2[l+1][j] + (cmp::max(i, j) - cmp::min(i, j)) * (rv[k][i] + rv[k-2][j]))
              }
            }
          }
        }
      }
      
      dv2 = dv1;
      dv1 = dv0;
      dv0 = vec![vec![inf;1000]; m+1];
    }
    
    let mut ans: usize = inf;

    for i in 0 .. m+1 {
      for j in 0 .. 1000 {
        ans = cmp::min(ans, dv1[i][j]);
      }
      if i > 0 {
        for j in 0 .. 1000 {
          ans = cmp::min(ans, dv2[i][j]);
        }
      }
    }
    println!("{}", ans);
  }
}

fn read_vec<T>() -> Vec<T>
  where T: std::str::FromStr,
        T::Err: std::fmt::Debug
{
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).expect("failed to read");
  buf.split_whitespace().map(|e| e.parse().unwrap()).collect()
}



Measured memory_bytes: 7064
chomp($n=<>);

$tt=0;
$xx=0;
$yy=0;
$flg=0;
while(<>){
    chomp;
    ($t, $x, $y)=split/ /,$_;
    $val= abs($x-$xx) + abs($y-$yy);
    if($val > $t || ($t-$tt)%2 != $val%2){
        print "No";
        exit;
    }
    $tt=$t;
    $xx=$x;
    $yy=$y;
}

print "Yes";

Measured memory_bytes: 512
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr long double EPS = 1e-8;

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

	vector<vector<int>>v(1024, vector<int>(1024));
	for (int i = 1; i < 1024; i += 2) {
		for (int j = 1; j < 1024; j += 2)v[i][j] = 1;
	}
	for (int i = 4; i <= 1024; i *= 2) {
		for (int j = i / 2; j < 1024; j += i) {
			for (int k = i / 2; k < 1024; k += i) {
				v[j][k] = 1;
			}
		}
	}
	int N, M;
	cin >> N >> M;
	for (int i = 1; i < (1 << N); i++) {
		for (int j = 1; j < (1 << M); j++)cout << v[i][j];
		cout << endl;
	}
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  
  if(s == "SUN")
    cout << "7" << endl;
  else if(s == "MON")
    cout << "6" << endl;
  else if(s == "TUE")
    cout << "5" << endl;
  else if(s == "WED")
    cout << "4" << endl;
  else if(s == "THU")
    cout << "3" << endl;
  else if(s == "FRI")
    cout << "2" << endl;
  else if(s == "SAT")
    cout << "1" << endl;
}

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

int main(){
    int N;
    cin >> N;
    vector<vector<int>> word(N+1, vector<int>(N+1, -1));
    for (int i = 0; i < N; i++) {
        int A;
        cin >> A;
        for (int j = 0; j < A; j++) {
            int x, y;
            cin >> x >> y;
            word[i+1][x] = y;
        }
    }
    
    int ans = 0;
    for (int i = 0; i < (1 << N); i++) {
        vector<bool> honest(N+1, false);
        int cnt = 0;
        for (int j = 0; j < N; j++) {
            if (((i >> j) & 1) == 1) {
                honest[j+1] = true;
                cnt++;
            }
        }
        bool check = true;
        for (int j = 0; j < N; j++) {
            if (!honest[j+1]) continue;
            for (int k = 1; k <= N; k++) {
                if (word[j+1][k] == 1 && !honest[k]) check = false;
                if (word[j+1][k] == 0 && honest[k]) check = false;
            }
        }
        if (check) ans = max(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}

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

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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rrep1(i, n) for (int i = ((int)(n)); i > 0; --i)
#define sz(x) ((int)(x).size())
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define pb push_back

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<double>    vd;
typedef vector<long long> vl;

// template<class T>bool maxc(T &a, const T &b) { if (a<b) { a=b; return 1; } }
// template<class T>bool minc(T &a, const T &b) { if (b<a) { a=b; return 1; } }

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

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    // cout << fixed << setprecision(5);

    // 入力
    int n;
    cin >> n;
    ll r[n];
    rep(t, n) { cin >> r[t]; }

    // 処理
    ll maxV = -INF;
    ll minV = r[0];
    for (int i = 1; i < n; i++) {
        maxV = max(maxV, r[i] - minV);
        minV = min(minV, r[i]);
    }

    // 出力
    cout << maxV << endl;

    return 0;
}



Measured memory_bytes: 4640
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin >> n;
    
    for(int i = 0; i < 20; i++){
        if(n < (1 << (i+1))){
            cout << (1 << i) << endl;
            break;
        }
    }
    
}

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

typedef long long ll;

int main(){
	cin.tie(0);	
	cout.tie(0);	
	ios_base::sync_with_stdio(0);
	string s;
	cin >> s;
	int res = 0;
	for(char c: s){
		if(c == 'p')--res;
	}
	res += (s.length())/2;
	cout << res << '\n';
}


Measured memory_bytes: 512
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools
from collections import Counter

def main():
    n = int(input())
    v = list(map(int, input().split()))
    v.sort()
    while len(v)>1:
        a = v[0]
        b = v[1]
        c = (a+b)/2
        v.pop(0)
        v.pop(0)
        v.insert(0, c)
    print(v[0])


if __name__=="__main__":
    main()


Measured memory_bytes: 9372
#include <iostream>
#include<vector>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
#define srep(i,s,t) for (int i = s; i < t; i++)
#define rng(a) a.begin(),a.end()
using ll = long long;

using namespace std;



int main() {
    int n;
    cin>>n;
    vector<char>c(n+1);
    rep(i,n) cin>>c[i+1];
    int ans = 0;
    bool b = false;
    int j = 1;
    for(int i = n; i > 0; i--){
        if(c[i]=='R'){
            while(j <= i-1){
                if(c[j]=='W') {
                    ans++;
                    c[j] = 'R';
                    c[i] = 'W';
                    b = true;
                    break;
                }
                j++;
            }
            if(b) continue;
            cout<<ans<<endl;
            return 0;
        }
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>

using namespace std;

const int INF = 1e9 + 239;

struct Qmin {
	deque<pair<int, int>> c;

	void pop(pair<int, int> x) {
		if (!c.empty() && c.back() == x) c.pop_back();
	} 

	void push(pair<int, int> x) {
		while (!c.empty() && x < c.front()) {
			c.pop_front();
		}
		c.push_front(x);
	}

	pair<int, int> mn() {
		return c.back();
	}

	Qmin(){};
};

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int n, m;
	cin >> n >> m;
	n++;
	vector<int> ban(n);
	for (auto &t : ban) {
		char c;
		cin >> c;
		t = (c - '0');
	}
	// cerr << "read ok " << endl;
	vector<int> dp(n, INF);
	vector<int> wr(n, -1);
	dp[n - 1] = 0;
	wr[n - 1] = -1;
	Qmin qm;
	qm.push({dp[n - 1], n - 1});
	for (int i = n - 2; i >= 0; i--) {
		if (!ban[i]) {
			tie(dp[i], wr[i]) = qm.mn();
			dp[i]++;
			dp[i] = min(dp[i], INF);
		}
		qm.push({dp[i], i});
		if (i + m < n) {
			qm.pop({dp[i + m], i + m});
		}
		// for (int j = i + 1; j < min(n, i + m + 1); j++) {
		// 	if (dp[i] > dp[j] + 1) {
		// 		dp[i] = dp[j] + 1;
		// 		wr[i] = j;
		// 	}
		// }
	}
	// cerr << dp[0] << endl;
	if (dp[0] == INF) {
		cout << -1 << endl;
	} else {
		int c = 0;
		vector<int> ans;
		while (c != -1) {
			ans.push_back(c);
			c = wr[c];
		}
		vector<int> res;
		for (int i = 0; i + 1 < (int)ans.size(); i++) {
			res.push_back(ans[i + 1] - ans[i]);
		}
		// cout << dp[0] << endl;
		for (auto t : res) {
			cout << t << ' ';
		}
		cout << endl;
	}
}


Measured memory_bytes: 2552
#include <stdio.h>

int main(void){
    char input[5];
    int ans;
    int i;
    ans = 0;
    scanf("%s", input);
    for (i = 0; i < 2; i++){
        if(input[i] == 57){
            printf("Yes\n");
            goto end;
            ans = 1;
        }
    }
    if(ans != 1){
        printf("No\n");
    }
end:
    return 0;
}
    

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

template<class Ty>
using passive_queue = priority_queue<Ty, vector<Ty>, greater<Ty>>;

struct Problem {

	void Solve() {
		ULL N, K; cin >> N >> K;
		N %= K;
		N = min(N, K - N);
		cout << N << endl;
	}

	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template <typename T>
using V = vector<T>;
template <typename T>
using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(), (v).end()
#define siz(v) (ll)(v).size()
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define repr(i, a, n) for (ll i = n - 1; (ll)a <= i; i--)
#define lb lower_bound
#define ub upper_bound
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 + 99);
vector<ll> dx = {-1, 1, 0, 0}, dy = {0, 0, -1, 1};
template <typename T, typename U>
void chmin(T &t, const U &u)
{
    if (t > u)
        t = u;
}
template <typename T, typename U>
void chmax(T &t, const U &u)
{
    if (t < u)
        t = u;
}
template <typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <typename T>
T mpow(T a, T n)
{
    T res = 1;
    for (; n; n >>= 1)
    {
        if (n & 1)
            res = res * a;
        a = a * a;
    }
    return res;
}


signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll n, k, q,ans=LINF;
    cin >> n >> k >> q;
    vector<ll> v(n), ord;
    rep(i, 0, n) cin >> v[i];

    ord = v;
    sort(all(ord));

    rep(i, 0, n)
    {
        ll st = ord[i],r=-1;
        priority_queue<ll,vector<ll>,greater<ll>> pq;
        vector<ll> kho;
        rep(l,0,n){
            while(r<n && v[r+1]>=st){
                r++;
                pq.push(v[r]);
                if(r-l+1>=k){
                    kho.pb(pq.top());
                    pq.pop();
                }
            }
            l=r+1;
            r++;
            while(!pq.empty())pq.pop();
        }
        if(siz(kho)<q)continue;
        else{
            sort(all(kho));
            chmin(ans,kho[q-1]-st);
        }
        //cout<<ans<<endl;
    }
    cout<<ans<<endl;
}
//( ・ __ ・ ) KEEP BEING ORGANIZED
//CHECK overflow,vector_size,what to output?

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

using namespace std;

#define rep(i,m,n) for(long long i=m;i<n;i++)

typedef long long ll;

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

 ll n;
  cin >> n;
  vector<ll> p(n);
  rep(i,0,n){
    ll a;
    cin >> a;
    a--;
    p[a]=i;
  }
  
  set<ll> s;
  s.insert(-1);
  s.insert(n);
  ll res=0;
  
  rep(i,0,n){
    auto v=s.lower_bound(p[i]);
    ll r=*v-p[i];
    v--;
    ll l=p[i]-*v;
    s.insert(p[i]);
    res+=(i+1)*l*r;
  }
  cout << res << endl;
}


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

using namespace std;

#define FOR(i, x, y) for(int i = (x); i < (y); ++i)
#define REP(i, x, y) for(int i = (x); i <= (y); ++i)
#define PB push_back
#define MP make_pair
#define PH push
#define fst first
#define snd second
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int, int> pii;

const int maxn = 2505;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int dx[2] = {1, 0};
const int dy[2] = {0, 1};

int n, m;
char s[maxn][maxn];

namespace Dinic{
	const int maxv = maxn * maxn;
	const int maxe = maxv * 10;
	int tot = 0;
	int head[maxv], to[maxe], cap[maxe], cost[maxe], nxt[maxe];
	int fv[maxv], fe[maxv], dis[maxv];
	
	inline void init(){
		memset(head, -1, sizeof(head));
		return;
	}
	inline void add(int u, int v, int w, int c){
		to[tot] = v;
		cap[tot] = w;
		cost[tot] = c;
		nxt[tot] =  head[u];
		head[u] = tot++;
		return;
	}
	inline void addEdge(int u, int v, int w, int c){
		add(u, v, w, c);
		add(v, u, 0, -c);
		return;
	}
	inline void bfs(int s){
		deque<int> que;
		memset(dis, 0x3f, sizeof(dis));
		que.PB(s); dis[s] = 0;
		while(!que.empty()){
			int u = que.front(); que.pop_front();
			for(int i = head[u]; ~i; i = nxt[i]) if(cap[i]){
				int v = to[i], c = cost[i];
				if(dis[v] > dis[u] + c){
					dis[v] = dis[u] + c;
					fv[v] = u;
					fe[v] = i;
					if(!c)
						que.push_front(v);
					else
						que.push_back(v);
				}
			}
		}
		return;
	}
	inline ll minCostFlow(int s, int t){
		ll ret = 0;
		while(true){
			bfs(s);
			if(dis[t] == 0x3f3f3f3f)
				break;
			int d = 0x3f3f3f3f;
			for(int u = t; u != s; u = fv[u])
				d = min(d, cap[fe[u]]);
			for(int u = t; u != s; u = fv[u])
				cap[fe[u]] -= d, cap[fe[u] ^ 1] += d;
			ret += d * dis[t];
		}
		return ret;
	}
}

int main(){
	scanf("%d%d", &n, &m);
	FOR(i, 0, n)
		scanf("%s", s[i]);
		
	Dinic::init();
		
	FOR(x, 0, n) FOR(y, 0, m){
		if(s[x][y] == 'o')
			Dinic::addEdge(n * m, x * m + y, 1, 0);
		if(s[x][y] == 'o' || s[x][y] == '.'){
			Dinic::addEdge(x * m + y, n * m + 1, 1, 0);
			FOR(k, 0, 2){
				int nx = x + dx[k], ny = y + dy[k];
				if(nx >= 0 && nx < n && ny >= 0 && ny < m && (s[nx][ny] == 'o' || s[nx][ny] == '.'))
					Dinic::addEdge(x * m + y, nx * m + ny, 0x3f3f3f3f, -1);
			}
		}
	}
	
	printf("%lld\n", -Dinic::minCostFlow(n * m, n * m + 1));
	return 0;
}


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

typedef long long ll;

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll xs[n];
    for (int i = 0; i < n; i++) {
        cin >> xs[i];
    }
    ll ds[n - 1];
    for (int i = 1; i < n; i++) {
        int d = xs[i] - xs[i - 1];
        ds[i - 1] = (d > 0) ? d : (-d);
    }
    sort(ds, ds + n - 1);
    ll res = 0;
    int i = 0;
    while (ds[i] * a < b) {
        res += ds[i] * a;
        i++;
    }
    res += b * (n - 1 - i);
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>          // printf(), scanf()
#define MAX_N 500000

typedef struct node_tbl
{
	int key;
	int parent;
	int left;
	int right;
} node;

const int nil = -1;
node t[MAX_N + 1];
int root;
int ix;

void
insert(int k)
{
	int y = nil;
	int x = root;
	int z = ix++;

	t[z].key = k;
	t[z].left = nil;
	t[z].right = nil;

	while (x != nil)
	{
		y = x;
		if (t[z].key < t[x].key)
			x = t[x].left;
		else
			x = t[x].right;
	}

	t[z].parent = y;
	if (y == nil)
		root = z;
	else
	{
		if (t[z].key < t[y].key)
			t[y].left = z;
		else
			t[y].right = z;
	}
}

void
inorder(int u)
{
	if (u == nil)
		return;

	inorder(t[u].left);
	printf(" %d", t[u].key);
	inorder(t[u].right);
}

void
preorder(int u)
{
	if (u == nil)
		return;

	printf(" %d", t[u].key);
	preorder(t[u].left);
	preorder(t[u].right);
}

int
main(int argc, char** argv)
{
	char command[8];
	int n;
	int x;
	int i;

	root = nil;
	ix = 0;
	scanf("%d", &n);
	for (i = 0; i < n; ++i)
	{
		scanf("%s", command);
		switch (command[0])
		{
		case 'i':
			scanf("%d", &x);
			insert(x);
			break;

		case 'p':
		default:
			inorder(root);
			printf("\n");

			preorder(root);
			printf("\n");
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 8416
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <map>
#include<iomanip>
#include<vector>

using namespace std;
typedef long long ll; 


ll ans,mx,sum,mn=1e18,flag;

int main(){
	string s;
	cin>>s;
	if(s[2]==s[3] && s[4]==s[5]) cout<<"Yes"<<endl;
	else cout<<"No";
}

Measured memory_bytes: 384
import java.util.*;
//import java.util.stream.Collectors;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int a = Integer.parseInt(sc.next()) * 3;
		int p = Integer.parseInt(sc.next());
		System.out.println((a + p) / 2);
	}
}


Measured memory_bytes: 35828
n, m, d = gets.split.map(&:to_i)
a = (1..n).map { gets.chomp }
f = -> a { a.map {|l| l.split(?#).map {|s| [s.size - d + 1, 0].max}}.flatten.inject(:+) }
c = f[a]
a = a.map {|l| l.split("")}.transpose.map(&:join)
p c + f[a]


Measured memory_bytes: 7004
#include <iostream>
#include <iomanip>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <boost/range/irange.hpp>
#include <boost/container/static_vector.hpp>
#include <boost/utility/string_ref.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/math/common_factor_rt.hpp>

class input
{
    std::istream& cin;

public:
    input() : cin(std::cin)
    {
        std::cin.tie(nullptr);
        std::ios::sync_with_stdio(false);
    }

    template <class T>
    inline input& operator>>(T& var)
    {
        cin >> var;
        return *this;
    }
    template <class T>
    inline input& operator,(T& var)
    {
        cin >> var;
        return *this;
    }

    template <class T>
    inline T read()
    {
        T var;
        cin >> var;
        return var;
    }

    template <class InputIterator>
    inline void read(InputIterator head, std::size_t n)
    {
        for (std::size_t i = 0; i < n; ++i) {
            cin >> *head;
            ++head;
        }
    }

    template <class T>
    inline std::vector<T> read(std::size_t n)
    {
        std::vector<T> res;
        res.reserve(n);

        for (std::size_t i = 0; i < n; ++i) {
            T tmp;
            cin >> tmp;
            res.emplace_back(tmp);
        }
        return res;
    }

    template <class T, class F>
    inline void online(std::size_t n, F&& f)
    {
        T var;
        for (std::size_t i = 0; i < n; ++i) {
            cin >> var;
            f(var);
        }
    }
};
template <class T, std::size_t n>
std::istream& operator>>(std::istream& in, std::array<T, n>& var)
{
    for (std::size_t i = 0; i < n; ++i) {
        in >> var[i];
    }
    return in;
}

class output
{
    std::ostream& cout;

public:
    template <bool nl>
    class proxy
    {
        std::ostream& cout;

    public:
        proxy() : cout(std::cout) {}
        ~proxy() { final(); }
        template <class T>
        proxy& operator,(T&& val)
        {
            cout << ' ' << val;
            return *this;
        }
        template <bool f = nl>
        auto final() -> std::enable_if_t<f> { cout << '\n'; }
        template <bool f = nl>
        auto final() -> std::enable_if_t<!f> {}
    };

public:
    output() : cout(std::cout)
    {
        cout << std::fixed << std::setprecision(15);
    }

    template <class T>
    proxy<true> operator,(T&& val)
    {
        cout << val;
        return {};
    }
    proxy<false> noreturn() { return {}; }

    template <class T>
    void print(const T& container)
    {
        bool first = true;
        for (auto&& x : container) {
            if (!first) {
                cout << ' ';
            }
            cout << x;
            first = false;
        }
    }
};

void prog()
{
    input in;
    output out;

    int a, p;
    in >> a, p;
    out, (p + 3 * a) / 2;
}

int main()
{
    prog();
    return 0;
}


Measured memory_bytes: 256
n, h = map(int, raw_input().split())
throw = []
hit = []
for i in range(0, n): 
    ai, bi = map(int, raw_input().split())
    throw += [bi]
    hit += [ai]
throw.sort(reverse = True)
hit.sort(reverse = True)

ans = 0 
hth = 0 

for i in range(0, n): 
    if(throw[i] < hit[0]):
        break
    if (hth >= h): 
        break
    ans += 1
    hth += throw[i]
if (h - hth > 0): 
    ans += (h - hth + hit[0] - 1) // hit[0]
print ans 

Measured memory_bytes: 12212
import numpy as np
def I(): return map(int,input().split())

w, h, n = I()
m = np.zeros((h, w), int)

while n:
    x, y, a = I()

    start = y * (a == 4)             # a = 4 のときのみy それ以外は0
    end = y if (a == 3) else h       # a = 3 のときのみy それ以外はh

    begin = x * (a == 2)             # a = 2 のときのみx それ以外は0
    finish = x if (a == 1) else w    # a = 1 のときのみx それ以外はw

    m[start:end, begin:finish] = 1
    n -= 1
print(h * w - m.sum())

Measured memory_bytes: 12508
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stdlib.h>
#include <time.h>
#include <queue>
#include <sstream>
using namespace std;
void cut(int n[200], int k);
void refl(int n[200]);
int n;
int main(void){
	cin >> n;
	int state[200];
	for(int i = 0; i < n*2; i++){
		state[i] = i+1;
	}
	int m;
	cin >> m;
	for(int i = 0; i < m; i++){
		int k;
		cin >> k;
		cut(state, k);
	}
	for(int i = 0; i < 2*n; i++){
		cout << state[i] << endl;
	}

}
void refl(int state[200]){
	int A[n], B[n];
	for(int i = 0, j = n; i < n; i++, j++){
		A[i] = state[i];
		B[i] = state[j];
	}
	for(int i = 0, j = 1, s = 0; i < n; i++, s += 2){
		state[s] = A[i];
		state[j+s] = B[i];
	}
}
void cut(int state[200], int k){
	if(k == 0)refl(state);
	int A[k];
	for(int i = 0; i < k; i++){
		A[i] = state[i];
	}
	int B[2*n-k];
	for(int i = 0; i < 2*n-k; i++){
		B[i] = state[k+i];
	}
	for(int i = 0; i < 2*n-k; i++){
		state[i] = B[i];
	}
	for(int i = 2*n-k, j = 0; i < 2*n; i++, j++){
		state[i] = A[j];
	}
}

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

#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define mem(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sz(x) (int)x.size()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.14159265358979323846
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define endl '\n'
#define int long long

int a[200005][2];
int st[4*200005][2];

void build(int node,int start,int end)
{
    if(start==end)
    {
        st[node][0]=a[start][0];
        st[node][1]=a[start][1];
        return;
    }
    build(2*node,start,(start+end)/2);
    build(2*node+1,(start+end)/2+1,end);
    st[node][0]=st[node][1]=1e7;
}
 
void update(int node,int start,int end,int l,int r,int val, int idx)
{
    if(l>r) return;
 
    if(l<=start&&end<=r)
    {
        st[node][idx]=min(st[node][idx],val);
        //cout<<start<<" "<<end<<endl;
    }
    else if(end<l||r<start) return;
    else
    {
        update(2*node,start,(start+end)/2,l,r,val, idx);
        update(2*node+1,(start+end)/2+1,end,l,r,val, idx);
    }
}

ll query(int node,int start,int end,int index, int idx)
{
    if(start==end) return st[node][idx];
    int mid=(start+end)/2;
    if(index<=mid) return min(st[node][idx],query(2*node,start,mid,index, idx));
    else return min(st[node][idx],query(2*node+1,mid+1,end,index, idx));
}

signed main()
{
    fast;

    int n,q;
    cin>>n>>q;

    int ans=(n-2)*(n-2);

    ffor(i,0,n)
    {
        a[i][0]=n-1;
        a[i][1]=n-1;
    }

    build(1,0,n-1);

    while(q--)
    {
        int x,y;
        cin>>x>>y;
        y--;
        if(x==1)
        {
            int lowest=query(1,0,n-1,y,1);
          //  cout<<lowest<<endl;
            if(lowest>=1) ans-=lowest-1;
            update(1,0,n-1,y,y,0,1);
            if(lowest>=1) update(1,0,n-1,0,lowest-1,y,0);
        }
        else
        {
            int lowest=query(1,0,n-1,y,0);
         //   cout<<lowest<<endl;
            if(lowest>=1) ans-=lowest-1;
            update(1,0,n-1,y,y,0,0);
            if(lowest>=1) update(1,0,n-1,0,lowest-1,y,1);
        }
    }

    cout<<ans;
    
    
    return 0;
}



Measured memory_bytes: 14924
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, b, n;
    cin >> n;
    b = n % 1000;
    if(b == 0){
        cout << "0" <<endl;
        return 0;
    }
    else
    a = 1000 - b;
    cout << a << endl;
    return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll fun(ll x)
{
	return (x * (x - 1)) / (2 * 1LL);
}
int main()
{
	ll t, tot = 0;
	cin >> t;
	map<string, ll> m;
	string s;
	while (t--)
		{
			cin >> s;
			sort(s.begin(), s.end());
			m[s]++;
		}
	for (auto i : m) tot += fun(i.second);
	cout << tot << endl;
}

Measured memory_bytes: 11136
#include <iostream>
#include <string> 
#include <vector>
#include <map>
#include <set>

using namespace std;

template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {
	o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;
}

template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {
	o << "{" << obj.first << ", " << obj.second << "}"; return o;
}

template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {
	o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}

void print(void) {
	cout << endl;
}

template <class Head> void print(Head&& head) {
	cout << head;
	print();
}

template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {
	cout << head << " ";
	print(forward<Tail>(tail)...);
}

int main() {
	int N;
	cin >> N;
  	if(N<1000) print("ABC");
  	else print("ABD");

	return 0;
}


Measured memory_bytes: 256
unittest
{
	assert( [ "3", "dwango 2", "sixth 5", "prelims 25", "dwango" ].parse.expand.solve == 30 );
	assert( [ "1", "abcde 1000", "abcde" ].parse.expand.solve == 0 );
	assert( [ "15", "ypnxn 279", "kgjgwx 464", "qquhuwq 327", "rxing 549", "pmuduhznoaqu 832", "dagktgdarveusju 595", "wunfagppcoi 200", "dhavrncwfw 720", "jpcmigg 658", "wrczqxycivdqn 639", "mcmkkbnjfeod 992", "htqvkgkbhtytsz 130", "twflegsjz 467", "dswxxrxuzzfhkp 989", "szfwtzfpnscgue 958", "pmuduhznoaqu" ].parse.expand.solve == 6348 );
}



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

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

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	auto sts = new Tuple!( dchar[], long )[ n ];
	foreach( ref st; sts )
	{
		input.popFront;
		auto z = input.front.split;
		st[ 0 ] = z[ 0 ].to!( dchar[] );
		st[ 1 ] = z[ 1 ].to!( long );
	}
	input.popFront;
	auto x = input.front.to!( dchar[] );
	return tuple( sts, x );
}

auto solve( Tuple!( dchar[], long )[] sts, dchar[] x )
{
	sts = sts.find!( ( a, b ) => a[ 0 ] == b )( x );
	sts.popFront;
	return reduce!( ( a, b ) => a + b[ 1 ] )( 0L, sts );
}


Measured memory_bytes: 320
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

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

int main() {
    //cout.precision(10);
    string s;
    long long k;
    cin >> s >> k;
    for(int i = 0; i < k; i++){
        if(s[i] != '1'){
            cout << s[i] << endl;
            return 0;
        }
    }
    cout << "1" << endl;
    return 0;
}

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

int main() {
  ll n, q;
  string s;
  cin >> n;
  cin >> s;
  cin >> q;

  map<char, set<ll>> m;
  for (ll i = 0; i < (ll) s.size(); i++) {
    m[s[i]].insert(i);
  }

  for (ll i = 0; i < q; i++) {
    int num;
    cin >> num;
    if (num == 1) {
      ll iq;
      char cq;
      cin >> iq >> cq;
      iq--;
      m[s[iq]].erase(iq);
      s[iq] = cq;
      m[cq].insert(iq);
    } else {
      ll lq, rq;
      cin >> lq >> rq;
      lq--; rq--;

      ll ans = 0;
      for (char c = 'a'; c <= 'z'; c++) {
        auto it = m[c].lower_bound(lq);
        if (it == m[c].end()) continue;
        // cout << c << " " << *it << endl;
        if (*it <= rq) ans++;
      }
      cout << ans << endl;
    }
  }
}


Measured memory_bytes: 26244
#include<cstdio>
#define N 55
const int p=1000000007;
int a[2][N*N][N],i,j,k,m,n,x;
int main()
{
	scanf("%d%d",&n,&m),a[n&1][0][0]=1;
	if(m&1){puts("0");return 0;}
	m=(m+n*(n+1))/2;
	for(i=n;i;i--)
	for(j=0;j<=n*n;j++)
	for(k=0;k<=n;k++)
	if(a[i&1][j][k])
	{
		(a[i&1^1][j+i][k]+=a[i&1][j][k])%=p,(a[i&1^1][j+i+i][k+1]+=a[i&1][j][k])%=p,(a[i&1^1][j+i][k]+=2ll*a[i&1][j][k]*k%p)%=p;
		if(k)(a[i&1^1][j][k-1]+=1ll*a[i&1][j][k]*k*k%p)%=p;
		a[i&1][j][k]=0;
	}
	printf("%d\n",a[0][m][0]);
	return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <queue>

#define ll long long
#define ull unsigned long long
#define mod 1000000007

using namespace std;

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

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

    int x = 1;
    int ans = 0;
    while(x < b){
        x += (a-1);
        ++ans;
    }

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


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

int main(){
    int n; cin>>n;
    int Amax = 1000005;
    vector<int> a(n);
    vector<int> c(Amax);
    int allgcd;
    for(int i=0;i<n;i++){
        cin>>a[i];
        (i==0) ? allgcd=a[i] : allgcd=__gcd(allgcd,a[i]);
        c[a[i]]++;
    }

    bool pairwise = true;
    for(int i=2;i<Amax;i++){
        int cnt = 0;
        for(int j=i;j<Amax;j+=i) cnt += c[j];
        if(cnt>1) pairwise = false;
    }

    if(pairwise){
        cout << "pairwise coprime" << endl;
        return 0;
    }

    if(allgcd==1){
        cout << "setwise coprime" << endl;
        return 0;
    }

    cout << "not coprime" << endl;
    return 0;
}

Measured memory_bytes: 11120
n, k = map(int, input().split())
a = list(map(int, input().split()))

b = 0
r = k + 1
seen = [-1] * n
seen[0] = 0
p = 1
for i in range(k):
    p = a[p - 1]
    if seen[p - 1] != -1:
        b = seen[p - 1]
        r = i + 1 - b
        for j in range((k - b) % r):
            p = a[p - 1]
        print(p)
        exit()
    seen[p - 1] = i + 1
else:
    print(p)


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

ll const INF = 1LL << 60;
int const MAX_N = 1005;

vector<int> G[MAX_N];
vector<int> rG[MAX_N];
bool ok[MAX_N];
bool rok[MAX_N];
bool use[MAX_N];

void dfs(int v) {
    if(ok[v]) return;
    ok[v] = true;
    for(int nv : G[v]) {
        dfs(nv);
    }
}

void rdfs(int v) {
    if(rok[v]) return;
    rok[v] = true;
    for(int nv : rG[v]) {
        rdfs(nv);
    }
}

bool bellman_ford(vector<tuple<int,int,ll>> &Es, int V, int s, vector<ll> &dist) {
    dist.resize(V,INF);
    dist[s] = 0;
    int cnt = 0;
    while(cnt < V) {
        bool end = true;
        for(auto e : Es) {
            int a,b; ll c;
            tie(a,b,c) = e;
            if(!use[a]) continue;
            if(!use[b]) continue;
            if(dist[a] != INF && dist[b] > dist[a] + c) {
                dist[b] = dist[a] + c;
                end = false;
            };
        }
        if(end) break;
        cnt++;
    }
    return (cnt == V);
}

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

    vector<tuple<int,int,ll>> edges;
    rep(i,m) {
        int a, b; ll c;
        cin >> a >> b >> c;
        a--; b--; c *= -1;
        edges.emplace_back(a,b,c);
        G[a].push_back(b);
        rG[b].push_back(a);
    }

    dfs(0); rdfs(n-1);
    rep(i,n) use[i] = ok[i] & rok[i];

    vector<ll> dist;
    if(bellman_ford(edges, n, 0, dist)) cout << "inf" << endl;
    else cout << -dist[n-1] << endl;
    return 0;
}

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

typedef long long ll;
const ll N = 200005, mod = 1e9+7;

ll n, ans = 1, fac[N] = {1}, fi[N] = {1};
ll vis[N], wh[N], sz[N], cv, ms;
vector<ll> adj[N], tree[N], cur, cyc;
bool done[N], onc[N];

ll calc (ll A, ll B) {
	if(!B) return 1;
	ll R = calc(A, B/2);
	R = (R * R) % mod;
	if(B%2) R = (R * A) % mod;
	return R;
}

ll comb (ll A, ll B) {
	return fac[A] * fi[B] % mod * fi[A-B] % mod;
}

ll multicomb (vector<ll> &V) {
	ll R = 1, C = 0;
	for(auto &T : V) {
		C += T;
	}
	for(auto &T : V) {
		R = (R * comb(C, T)) % mod;
		C -= T;
	}
	return R;
}

ll dfs1 (ll I) {
	ms += adj[I].size();
	cur.push_back(I);
	done[I] = true;
	vis[I] = cv;
	for(auto &T : adj[I]) {
		if(vis[T] != cv) dfs1(T);
	}
}

ll dfs2 (ll I, ll P) {
	vis[I] = cv;
	for(auto &T : adj[I]) {
		ll X;
		if(vis[T] != cv) {
			X = dfs2(T, I);
			if(X == -1) return -1;
			else if(X) {
				cyc.push_back(I);
				onc[I] = true;
				return (X == I ? -1 : X);
			}
		}
		else if(T != P) {
			cyc.push_back(I);
			onc[I] = true;
			return T;
		}
	}
	return 0;
}

void dfs3 (ll I) {
	vis[I] = cv;
	for(auto &T : adj[I]) {
		if(onc[T] || vis[T] == cv) continue;
		wh[T] = I;
		dfs3(T);
	}
}

ll dfs4 (ll I) {
	sz[I] = 1;
	vector<ll> S;
	ll R = 1;
	for(auto &T : tree[I]) {
		R = (R * dfs4(T)) % mod;
		S.push_back(sz[T]);
		sz[I] += sz[T];
	}
	return (R * multicomb(S)) % mod;
}

ll subsol () {
	cv++;
	for(auto &C : cur) {
		tree[C].clear();
		for(auto &T : adj[C]) {
			if(T < wh[C]) {
				vis[T] = cv;
				tree[C].push_back(T);
			}
		}
	}
	tree[0].clear();
	for(auto &C : cur) {
		if(vis[C] == cv) continue;
		tree[0].push_back(C);
	}
	return dfs4(0);
}

ll solve (ll I) {
	cv++;
	cur.clear();
	ms = 0;
	dfs1(I);
	if(ms != 2*cur.size()) {
		puts("0");
		exit(0);
	}
	cv++;
	cyc.clear();
	dfs2(I, 0);
	cv++;
	for(auto &C : cyc) {
		dfs3(C);
	}
	ll R = 0, S = (ll)cyc.size();
	for(ll i=0;i<S;i++) {
		wh[cyc[i]] = cyc[(i+1)%S];
	}
	R += subsol();
	for(ll i=0;i<S;i++) {
		wh[cyc[(i+1)%S]] = cyc[i];
	}
	R += subsol();
	return R % mod;
}

int main()
{
	scanf("%lld",&n);
	n *= 2;
	for(ll i=1;i<=n;i++) {
		fac[i] = (fac[i-1] * i) % mod;
		fi[i] = calc(fac[i], mod-2);
	}
	for(ll i=1;i<=n;i++) {
		ll A, B;
		scanf("%lld%lld",&A,&B);
		B += n/2;
		adj[A].push_back(B);
		adj[B].push_back(A);
	}
	vector<ll> S;
	for(ll i=1;i<=n;i++) {
		if(done[i]) continue;
		ans = (ans * solve(i)) % mod;
		S.push_back((ll)cur.size());
	}
	printf("%lld\n", (ans * multicomb(S)) % mod);
}


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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

#ifdef LOCAL
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else 
#define dump(x) true
#endif

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const int maxn = 18;

int winner[1 << 18][maxn + 1];

int main() {
	int N; cin >> N;
	string S; cin >> S;
	V<int> P(1 << N);

	rep(i, (1 << N)) {
		cin >> P[i];
	}

	rep(i, (1 << N)) {
		winner[i][0] = P[i];
	}

	for (int k = 1; k <= N; ++k) {
		rep(l, (1 << N)) {
			int x = winner[l][k-1];
			int r = ((1 << (k-1)) + l) % (1 << N);
			int y = winner[r][k-1];
			if (x > y) swap(x, y);
			if (S[y-x-1] == '0') {
				winner[l][k] = x;
			} else {
				winner[l][k] = y;
			}
		}
	}

	rep(i, 1 << N) {
		printf("%d\n", winner[i][N]);
	}
	return 0;
}


Measured memory_bytes: 23792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main(){
  long long int n,x,ans=0;
  cin>>n>>x;
  vector<long long int> v(n);
  for(long long int i=0;i<n;i++) cin>>v[i];
  for(long long int i=0;i<n-1;i++){
    if(v[i]+v[i+1]>x){
      if(x>=v[i]){
        ans+=v[i]+v[i+1]-x;
        v[i+1]=x-v[i];
      }else{
        ans+=v[i+1];
        v[i+1]=0;
        ans+=v[i]-x;
        v[i]=x;
        ans+=v[i]-x;
      }
    }
  }
  cout<<ans<<endl;
}




Measured memory_bytes: 1024
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
b = [int(input()) for _ in range(m)]
c = [0 for _ in range(n)]
for i in range(n):
    dot = 0
    for j in range(m):
        dot += a[i][j] * b[j]
    c[i] = dot
for i in range(n):
    print(c[i])


Measured memory_bytes: 6024
import math
import numpy

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def get_nearest(li, num):
    index = numpy.abs(numpy.asarray(li) - num).argmin()
    return li[index]

n = int(input())
a = [int(_) for _ in input().split()]

if n == 2:
    print(max(a), 0)
    exit()

ans_a = max(a)
ans_b = get_nearest(a, ans_a/2)

print(ans_a, ans_b)


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}

const int MAX_N = 305;
const ll INF = 1LL << 61;
ll d[MAX_N][MAX_N];
ll ans[MAX_N][MAX_N];

int main2() {
  REP(i, MAX_N) REP(j, MAX_N) d[i][j] = INF;
  REP(i, MAX_N) d[i][i] = 0;
  int N = nextInt();
  int M = nextInt();
  int L = nextInt();
  REP(i, M) {
    int A = nextInt() - 1;
    int B = nextInt() - 1;
    ll C = nextInt();
    chmin(d[A][B], C);
    chmin(d[B][A], C);
  }
  REP(k, N) REP(i, N) REP(j, N) {
    chmin(d[i][j], d[i][k] + d[k][j]);
  }

  REP(i, MAX_N) REP(j, MAX_N) ans[i][j] = INF;
  REP(start, N) {
    queue<int> q;
    q.push(start);
    ans[start][start] = 0;
    while (!q.empty()) {
      int pos = q.front(); q.pop();
      REP(nxt, N) if (d[pos][nxt] <= L) {
        if (ans[start][nxt] > ans[start][pos] + 1) {
          ans[start][nxt] = ans[start][pos] + 1;
          q.push(nxt);
        }
      }
    }
  }

  int Q = nextInt();
  REP(_, Q) {
    int A = nextInt() - 1;
    int B = nextInt() - 1;
    if (ans[A][B] >= INF/2)
      cout << -1 << endl;
    else
      cout << ans[A][B] - 1 << endl;
  }
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 2048
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

typedef std::pair<int, int> p;

const int MAX_N = 100000;

int main(void) {
    cout << std::fixed << std::setprecision(10);
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    std::vector<int> v;
    for (int i = 0; i < n; i++) {
        int m1;
        cin >> m1;
        v.push_back(m1);
    }

    std::vector<p> even, odd;
    for (int i = 0; i < MAX_N; i++) {
        p pushed = std::make_pair(0, i + 1);
        even.push_back(pushed);
        odd.push_back(pushed);
    }

    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            even[v[i]].first++;
        } else {
            odd[v[i]].first++;
        }
    }

    std::sort(even.begin(), even.end(), std::greater<p>());
    std::sort(odd.begin(), odd.end(), std::greater<p>());

    int result    = 0;
    p target_even = even[0];
    p target_odd  = odd[0];
    if (target_even.second == target_odd.second) {
        p next_even      = even[1];
        p next_odd       = odd[1];
        int tempresult_a = n - target_even.first - next_odd.first,
            tempresult_b = n - target_odd.first - next_even.first;
        result = (tempresult_a < tempresult_b) ? tempresult_a : tempresult_b;

    } else {
        result = n - target_even.first - target_odd.first;
    }
    cout << result << endl;

    return 0;
}


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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//以降 cin の入力元が 'input.txt' になる
//std::ifstream in("input.txt");
//std::cin.rdbuf(in.rdbuf());
 
signed main()
{
    gearup;
    ll k; cin >> k;
    ll num = 7 % k;
    set<ll> s;
    ll cnt = 1;
    while(s.count(num) == 0){
        if(num == 0){
            out(cnt);
            return 0;
        }
        s.insert(num);
        num = (num * 10 + 7) % k;
        cnt++;
    }
    out(-1);
}

Measured memory_bytes: 50480
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define md (ll)(1e9+7)
#define all(X) X.begin(),X.end()

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   str.substr (x) : returns a substring str[x],... end of string
   str.find(qtr) : returns the first occurenece of qtr in str */

const int M=1e6+6;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

ll dp[M],h[M];

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

	ll n,k,i,j;

	cin >> n >> k;

	for(i=1;i<=n;++i)
		cin >> h[i];

	for(i=2;i<=n;++i)
	{
		dp[i] = 1e16;
		for(j=max(i-k,1ll);j<i;++j)
			dp[i] = min(dp[i],dp[j]+abs(h[i]-h[j]));
	}

	cout << dp[n] << endl;
	return 0;
}

	


Measured memory_bytes: 5120
#include<iostream>
#include<algorithm>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

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



Measured memory_bytes: 3100
#include<stdio.h>
#include<math.h>
int isPrime(int x)
{
  int i;
  if(x==2) return 1;
  if(x<2||x%2==0) return 0;
  i=3;
  while(i<=sqrt(x))
  {
    if(x%i==0) return 0;
    i=i+2;
  }
  return 1;
}
int main(void)
{
  int i,n,count=0,num;
  scanf("%d",&n);
  for(i=0;i<n;i++)
  {
    scanf("%d",&num);
    count+=isPrime(num);
  }
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2040
import java.util.Scanner;

public class Main
{

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

		int a = Integer.parseInt(sc.next());
		int p = Integer.parseInt(sc.next());

		System.out.println((3 * a + p) / 2);

		sc.close();
	}
}

Measured memory_bytes: 22484