akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define F first
#define S second
#define int long long
#define inf 1000000000000000001
#define mod 1000000007


using namespace std;

typedef pair<int, int> num;


struct pr{
    int pl,  mn;
    pr(){
        pl = mn = 0;
    }
};

void upr(num& n){
    if (n.S < 0){
        n.S *= -1;
        n.F *= -1;
    }
    int g = __gcd(abs(n.F), n.S);
    n.S /= g;
    n.F /= g;
}

map<num, pr> mp;


num getPr(const num& ld){
    if (ld.S == 0){
        return make_pair(0, 1);
    }
    if (ld.F == 0){
        return make_pair(0, 0);
    }
    num ret(-ld.S, ld.F);
    upr(ret);
    return ret;
}

int fastPow(int a, int pow){
    if (pow == 0) return 1;
    if (pow == 1) return a;
    int nxt = fastPow(a, pow/2);
    if (pow&1){
        return (((nxt*nxt)%mod)*a)%mod;
    } else {
        return (nxt*nxt)%mod;
    }
}

int getAns(map<num, pr>::iterator it){
    if (it == mp.end()){
        return 1;
    }
    pr cur = it->S;
    it++;
    int nxtAns = getAns(it);
    return  ( ( ( fastPow(2, cur.pl)+fastPow(2, cur.mn) -1 +mod)%mod  )*nxtAns)%mod;
}

signed main(){
    int n, zer = 0;
    cin >> n;
    for (int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        num id;
        if (a == 0 && b == 0){
            zer++;
            continue;
        } else if (b == 0){
            id = make_pair(0, 0);
        } else if (a == 0){
            id = make_pair(0, 1);
        } else {
            id = make_pair(a, b);
            upr(id);
        }
        if (id.F < 0 || id.S == 0){
            id = getPr(id);
            mp[id].mn++;
        } else {
            mp[id].pl++;
        }
    }


//    for (auto i : mp){
//        cout << i.F << " : " << i.S.pl << " " << i.S.mn << endl;
//    }


    cout << (getAns(mp.begin())-1+mod+zer)%mod << endl;
    return 0;
}























Measured memory_bytes: 28400
#include <stdio.h>

int main() {
	int N;
	scanf("%d",&N);
	int A[N], ans[N+1];
	for (int i = 0; i < N; i++) {
		scanf("%d",&A[i]);
		ans[i] = -1;
	}
	ans[N] = -1;
	for (int i = 0; i < N; i++) {
		int point = 0;
		while (1) {
			if (ans[point] < A[i]) {
				ans[point] = A[i];
				break;
			}
			else point++;
		}
	}
	int cnt = 0;
	for (int i = 0; ans[i] != -1; i++) {
		cnt++;
	}
	printf("%d\n",cnt);
	return 0;
}

Measured memory_bytes: 1024
fn main() {
    let s = read();
    let ans = solve(s);
    write(ans);
}

fn read() -> String {
    let mut l1 = String::new();
    std::io::stdin().read_line(&mut l1).ok();
    let s = l1.trim().to_string();

    s
}

fn write(s: String) {
    println!("{}", s);
}

fn solve<'a>(s: String) -> String {
    let c = s.chars().next().unwrap();
    if 'a' <= c && c <= 'z' {
        "a".to_string()
    } else {
        "A".to_string()
    }
    
}

Measured memory_bytes: 2128
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")
MOD = 10 ** 9 + 7

# dsu / UnionFind


def init_unionfind(N):
    global parent, rank
    parent = [-1] * N
    rank = [0] * N


def find_root_1(x):
    p = parent[x]
    if p == -1:
        return x
    p2 = find_root(p)
    parent[x] = p2
    return p2


def find_root(x):
    p = parent[x]
    while p != -1:
        x = p
        p = parent[x]
    return x


def unite(x, y):
    x = find_root(x)
    y = find_root(y)
    if x == y:
        return  # already united
    if rank[x] < rank[y]:
        parent[x] = y
    else:
        parent[y] = x
        if rank[x] == rank[y]:
            rank[x] += 1


def is_connected(x, y):
    return (find_root(x) == find_root(y))

# acl/dsu


init = init_unionfind
merge = unite
# FIXME: return value

same = is_connected
leader = find_root


def size(a):
    raise NotImplementedError


def group(a):
    raise NotImplementedError
# ---


def debug(*x):
    print(*x, file=sys.stderr)


def main():
    # parse input
    N, Q = map(int, input().split())
    init(N)
    for _q in range(Q):
        q, u, v = map(int, input().split())
        if q == 0:
            merge(u, v)
        else:
            print(int(same(u, v)))


# tests
T1 = """
4 7
1 0 1
0 0 1
0 2 3
1 0 1
1 1 2
0 0 2
1 1 3
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
0
1
0
1
"""


def _test():
    import doctest
    doctest.testmod()
    g = globals()
    for k in sorted(g):
        if k.startswith("TEST_"):
            doctest.run_docstring_examples(g[k], g, name=k)


def as_input(s):
    "use in test, use given string as input file"
    import io
    f = io.StringIO(s.strip())
    g = globals()
    g["input"] = lambda: bytes(f.readline(), "ascii")
    g["read"] = lambda: bytes(f.read(), "ascii")


input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

if sys.argv[-1] == "-t":
    print("testing")
    _test()
    sys.exit()

main()


Measured memory_bytes: 75028
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stack>

using ll = unsigned long long;
using namespace std;


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

    int *d = new int[n];
    for(int i = 0; i < n; ++i) {
        cin >> d[i];
    }

    // sol
    stack<int> stk;
    sort(d, d+n, [](const int a, const int b){return b < a;});
    
    for (int i = 0; i < n; ++i) {
        if(stk.empty() || stk.top() > d[i]) {
            stk.push(d[i]);
        }
    }

    cout << stk.size() << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
   int h,w,a[60][60];
   cin>>h>>w;
   for (int i = 0; i < h; i++)
   {
       for (int j = 0; j < w; j++)
       {
           char ch;
           cin>>ch;
           if (ch == '.')
            a[i][j]=0;
           else if (ch == '#')
            a[i][j]=1;
       }
   }
   for (int i = 0; i < h; i++)
   {
       for (int j = 0; j < w; j++)
       {
           if (a[i][j] == 1)
           {
               if ((i-1 >= 0&&(a[i-1][j] == 1||a[i-1][j] == 2))||(i+1 < h&&(a[i+1][j] == 1||a[i+1][j] == 2))||(j-1 >= 0&&(a[i][j-1] == 1||a[i][j-1] == 2))||(j+1 < w&&(a[i][j+1] == 1||a[i][j+1] == 2)))
                a[i][j]=2;
           }
       }
   }
   int flag=1;
   for (int i = 0; i < h&&flag; i++)
   {
       for (int j = 0; j < w; j++)
       {
           if (a[i][j] == 1)
            {
              flag=0;
              break;
            }
       }
   }
   if (flag == 1)
    cout<<"Yes"<<endl;
   else
    cout<<"No"<<endl;
    return 0;
}


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

using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
//#pragma GCC target ("avx,tune=native")
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;

const double pi = acos(-1);
const ll INF = 1e18 + 5;
const int N = 2e5 + 20;

void solve()
{
	int n;
	cin >> n;
	map <string, int> mp;
	for(int i = 1; i <= n; ++i)
	{
		string s;
		cin >> s;
		mp[s]++;
	}
	cout << mp.size();
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t = 1;
    //cin >> t;
    while(t--) solve();
    return 0;
}


Measured memory_bytes: 19244
#include <iostream>
#define inf 1000000000
#define llint long long int

using namespace std;

llint n, m, c, s, g;
llint G[25][105][105];
llint G2[105][105];
llint fee[25][10001];
llint p[25], q[25][55], r[25][55];

void warshallfloyd(llint G[105][105])
{
	for(llint k = 1; k <= n; k++){
		for(llint i = 1; i <= n; i++){
			for(llint j = 1; j <= n; j++){
				G[i][j] = min(G[i][j], G[i][k] + G[k][j]);
			}
		}
	}
}

llint getfee(llint c, llint i)
{
	if(c <= 10000) return fee[i][c];
	else return fee[i][10000] + (c - 10000) * r[i][p[i]-1];
}

int main(void)
{
	while(1){
		cin >> n >> m >> c >> s >> g;
		if(n == 0 && m == 0 && c == 0 && s == 0 && g == 0) break;
		
		for(llint i = 1; i <= c; i++){
			for(llint j = 1; j <= n; j++){
				for(llint k = 1; k <= n; k++){
					G[i][j][k] = inf;
					if(j == k) G[i][j][k] = 0;
				}
			}
		}
		
		llint x, y, a, b;
		for(llint i = 0; i < m; i++){
			cin >> x >> y >> a >> b;
			G[b][x][y] = min(G[b][x][y], a);
			G[b][y][x] = min(G[b][y][x], a);
		}
		for(llint i = 1; i <= c; i++) cin >> p[i];
		
		for(llint i = 1; i <= c; i++){
			for(llint j = 0; j < p[i]-1; j++) cin >> q[i][j];
			q[i][p[i]-1] = inf;
			for(llint j = 0; j < p[i]; j++) cin >> r[i][j];
			
			llint z = 0, sum = 0;
			for(llint j = 0; j <= 10000; j++){
				fee[i][j] = sum;
				if(j >= q[i][z]) z++;
				sum += r[i][z];
			}
		}
		
		for(llint i = 1; i <= c; i++){
			warshallfloyd(G[i]);
			for(llint j = 1; j <= n; j++){
				for(llint k = 1; k <= n; k++){
					G[i][j][k] = getfee(G[i][j][k], i);
				}
			}
		}
		
		for(llint i = 1; i <= n; i++){
			for(llint j = 1; j <= n; j++){
				G2[i][j] = inf;
			}
		}
		for(llint i = 1; i <= n; i++){
			for(llint j = 1; j <= n; j++){
				for(llint k = 1; k <= c; k++){
					G2[i][j] = min(G2[i][j], G[k][i][j]);
				}
			}
		}
		warshallfloyd(G2);
		
		if(G2[s][g] == inf) G2[s][g] = -1;
		cout << G2[s][g] << endl;
	}
	return 0;
}

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

int main(){
  string S;
  cin >> S;
  int total = 700;
  for (int i = 0; i < S.size(); i++){
    if (S.at(i) == 'o') total += 100;
  }
  cout << total << endl;
} 

Measured memory_bytes: 3624
using System;
using System.Collections.Generic;

namespace P0002_DigitNumber
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> lines = new List<string>();
            string readLine;
            
            do
            {
                readLine = Console.ReadLine();
                if (readLine != null) 
                {
                    lines.Add(readLine);
                }
            }
            while (readLine != null);
            

            foreach (string line in lines)
            {
                string[] digits = line.Split(' ');

                int add = int.Parse(digits[0]) + int.Parse(digits[1]);
                
                Console.WriteLine(add.ToString().Length);

            }

        }
        
    }
}

Measured memory_bytes: 5712
#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"

using namespace std;

//const long long int MOD = 1000000007;
const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R


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

	string s;
	cin >> s;
	int a = 0, b = 0;
	for (auto i : s) {
		if (i == '0')a++;
		else b++;;
	}
	cout << min(a, b) * 2 << endl;
	return 0;
}

Measured memory_bytes: 512
N,x=map(int,input().split())
A=list(map(int,input().split()))
count=0
for i in range(N-1):
    if A[i]+A[i+1]>x:
        count+=A[i]+A[i+1]-x
        A[i+1]=max(x-A[i],0)
print(count)


Measured memory_bytes: 14252
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI 3.14159265358979
 
signed main(){

	lli n;
	string s;

	cin>>n;
	cin>>s;
	if(n==1 || n%2==1){
		cout<<"No"<<endl;
		return 0;
	}

	REP(i,0,n/2){
		if(s.at(i) != s.at(i+n/2)){
			cout<<"No"<<endl;
			return 0;
		}
	}

	cout<<"Yes"<<endl;
 
 
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

void pigi(int i, vector<queue<int>> &ques, set<P> &st){
    int j = ques[i].front();
    if (ques[j].empty() || ques[j].front() != i) return;
    st.insert(P(min(i, j), max(i, j)));
}

int main() {
    int n;
    cin >> n;
    vector<queue<int>> ques(n);
    REP(i,n){
        REP(j,n-1){
            ques[i].push(in() - 1);
        }
    }
    int end = 0, ans = 0;
    set<P> del;
    REP(i,n){
        int j = ques[i].front();
        if (ques[j].front() == i){
            del.insert(P(min(i, j), max(i, j)));
        }
    }
    while (end < n){
        if (del.empty()){
            cout << -1 << endl;
            return 0;
        }
        set<P> del_next;
        for (P p : del){
            ques[p.first].pop();
            ques[p.second].pop();
            if (ques[p.first].empty()) end++;
            else pigi(p.first, ques, del_next);
            if (ques[p.second].empty()) end++;
            else pigi(p.second, ques, del_next);
        }
        del.swap(del_next);
        ans++;
    }
    cout << ans << endl;
    return 0;
}


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

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int K = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		boolean ok = false;
		for(int i = A; i <= B; i++)
			if(i % K == 0)
				ok = true;
		System.out.println(ok ? "OK" : "NG");
	}

}


Measured memory_bytes: 27076
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define lREP(i, n) for(int i = 1; i <= (int)(n); i++)
#define ALL(x) (x).begin(),(x).end()
typedef long long ll;

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

int main(){
  int N;
  cin >> N;
  int V[N];
  REP(i,N) cin >> V[i];

  sort(V, V+N);
  double ans = V[0];
  for(int i = 1; i < N; i++) ans = (ans + V[i]) / 2;

  cout << ans <<  endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	private	static	BufferedReader br = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		double[]	data = null;
		double		bmi  = 0.0;

		while ((data = parseData()) != null) {
			bmi = data[1] / Math.pow(data[2], 2.0);
			if (bmi >= 25.0) {
				System.out.println((int)data[0]);
			}
		}
	}

	private static double[] parseData() {
		double[]	data  = null;
		String[]	split = null;
		String		strIn = null;

		if ((strIn = parseStdin()) != null) {
			split   = strIn.split(",");
			data    = new double[3];
			data[0] = Double.parseDouble(split[0]); 
			data[1] = Double.parseDouble(split[1]); 
			data[2] = Double.parseDouble(split[2]); 
		}
		
		return data;
	}

	private static String parseStdin() {
		String	strNum = null;

		try {
			String line = br.readLine();
			if (line != null) {
				if (!line.isEmpty()) {
					strNum = line;
				}
			}
		}
		catch (IOException e) {}

		return strNum;
	}
}

Measured memory_bytes: 16928
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };

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

#[allow(unused_macros)]
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")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

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

#[allow(unused_imports)]
use std::io::Write;
use std::cmp::Ordering;

fn main() {
    input!{
      n: usize,
      m: usize,
      uvs: [(usize1,usize1); m],
      s: usize1,
      t: usize1
    }

    let mut edges = vec![vec![]; n];
    for (u, v) in uvs {
        edges[u].push(v);
    }

    let mut q = std::collections::VecDeque::new();
    q.push_back((s,0));
    let mut vis = vec![vec![false; n]; 3];

    while q.len() > 0 {
        let (node, d) = q.pop_front().unwrap();
        if vis[d%3][node] == true {
            continue;
        }
        vis[d%3][node] = true;

        if d % 3 == 0 {
            if node == t {
                return println!("{}", d/3);
            }
        }


        for &nd in edges[node].iter() {
            if !vis[(d+1)%3][nd] {
                q.push_back((nd, d+1));
            }
        }
    }
    println!("{}", -1);
}


Measured memory_bytes: 12540
#!/usr/bin/env python3
import sys
from collections import Counter
YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(N: int, K: int, Q: int, A: "List[int]"):
    c = Counter(A)
    for i in range(N):
        if K - Q + c[i+1] > 0:
            print(YES)
        else:
            print(NO)


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    K = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(Q)]  # type: "List[int]"
    solve(N, K, Q, A)

if __name__ == '__main__':
    main()


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

int main() {
	int n;
	cin >> n;
	int ans = 360/gcd(360, n);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3588
def main():
  n, d, mods = 0, 1, [1] + [0] * 2019
  for i in reversed(input()):
    n = (n + int(i) * d) % 2019
    d = d * 10 % 2019
    mods[n] += 1
  print(sum([i * ( i - 1 ) // 2 for i in mods]))
main()

Measured memory_bytes: 9296
import java.util.Scanner;

/**
 *
 * @author ena000078
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        
        int C = A + B;
        if (C < 10){
            System.out.println(C);
        }else{
            System.out.println("error");
        }
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <utility>

using namespace std;

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

int main() {
	ll n, k;
	P a[100000];
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i].first >> a[i].second;
	}
	sort(a, a + n);
	ll j = 0, sum = a[0].second;
	while (sum < k) {
		j++;
		sum += a[j].second;
	}
	cout << a[j].first << endl;
	return 0;
}


Measured memory_bytes: 1792
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 6
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	tt := make([]int, n)
	for i := 0; i < n; i++ {
		ii := i
		for ii > 0 && ii%2 == 0 {
			tt[i]++
			ii >>= 1
		}
		tt[i]++
	}

	for i := 1; i < n; i++ {
		ans := make([]string, 0)
		for j := i; j < n; j++ {
			ans = append(ans, fmt.Sprintf("%d", tt[j-i+1]))
		}
		fmt.Fprintln(writer, strings.Join(ans, " "))
	}
}


Measured memory_bytes: 5248
using System;
using System.Collections.Generic;
using System.Linq;

public static partial class Program
{
    public static void Main()
    {
        var s = new List<char>();
        foreach (var c in CRL())
        {
            switch (c)
            {
                case '0':
                case '1':
                    s.Add(c);
                    break;
                case 'B':
                    if (s.Count != 0)
                    {
                        s.RemoveAt(s.Count - 1);
                    }
                    break;
            }
        }

        CWL(s.Join());
    }
}

public static partial class Program
{
    //テンプレここから
    public static int ToInt(this double d) => (int) d;
    public static int ToInt(this string str) => int.Parse(str);
    public static long ToLong(this string str) => long.Parse(str);
    public static long[] ToLong(this IEnumerable<string> strs) => strs.Select(x => x.ToLong()).ToArray();
    public static int[] ToInt(this IEnumerable<string> strs) => strs.Select(x => x.ToInt()).ToArray();
    public static long[] ArrayLongs(this string str, char opr = ' ') => str.Split(opr).ToLong();
    public static int[] ArrayInts(this string str, char opr = ' ') => str.Split(opr).ToInt();
    public static string CRL() => Console.ReadLine();
    public static void CWL(object obj) => Console.WriteLine(obj);
    public static long Diff(long a, long b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    public static int Diff(int a, int b) => Math.Abs(Math.Max(a, b) - Math.Min(a, b));
    public static long Sign(this long i) => Math.Sign(i);
    public static bool IsEven(this long i) => i % 2 == 0;
    public static bool IsEven(this int i) => i % 2 == 0;
    public static long[] dx = new long[] {0, -1, 0, 1};
    public static long[] dy = new long[] {-1, 0, 1, 0};
    public static long mod = 1000000007;
    public static string alphabet = "abcdefghijklmnopqrstuvwxyz";
    public static long ToLong(this char c) => c.ToString().ToInt();
    public static long[] Sort(this long[] array) => array.OrderBy(x => x).ToArray();
    public static int[] Sort(this int[] array) => array.OrderBy(x => x).ToArray();
    public static long[] DSort(this long[] array) => array.OrderByDescending(x => x).ToArray();
    public static int[] DSort(this int[] array) => array.OrderByDescending(x => x).ToArray();
    public static string Join(this IEnumerable<string> array, string sep = "") => string.Join(sep, array);
    public static string Join(this IEnumerable<char> array, string sep = "") => string.Join(sep, array);
    public static long GCD(long a, long b) => b == 0 ? a : GCD(b, a % b);

    public static long LCM(long a, long b) => a * b / GCD(a, b);



    //テンプレここまで
}

Measured memory_bytes: 13268
using System;

class Program
{
    static void Main(string[] args)
    {
        var num = Convert.ToInt32(Console.ReadLine());

        if (num % 2 == 0) Console.WriteLine((num / 2) * (num / 2));
        else Console.WriteLine((num / 2 + 1) * (num / 2));
    }
}

Measured memory_bytes: 13268
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int mod = (int)1e9+7;
const ll INF = 1e18+5;
const int nax = 100005;
int n;
vector<int> adj[nax];

pair<ll,ll> solve(int u,int par){
	if(adj[u].size()==1)
		return {1,1};
	ll white = 1;
	ll black = 1;
	for(int v : adj[u]){
		if(v==par)
			continue;
		pair<ll,ll> ret = solve(v,u);
		white = (white * (ret.first + ret.second)) % mod;
		black = (black * ret.second) % mod;	
	}	
	return {black,white};
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	
	cin>>n;
	for(int i=0;i<n-1;i++){
		int x,y;
		cin>>x>>y;
		adj[x].emplace_back(y);
		adj[y].emplace_back(x);
	}
	int sv = 1;
	for(int i=2;i<=n;i++){
		if(adj[i].size()>1){
			sv = i;
			break;
		}
	}
	pair<ll,ll> ans = solve(sv,-1);
	cout<<(ans.first + ans.second) % mod;
    return 0;
}









Measured memory_bytes: 11008
using System;

class B{
  public static void Main(){
    int n,i,count = 0;
    n = int.Parse(Console.ReadLine());
    string[] str = Console.ReadLine().Split(' ');
    int[] array = new int[n];
    for(i = 0;i < n;i++){
      array[i] = int.Parse(str[i]);
    }
    for(i = 0;i < n;i++){
      int min = i;
      for(int j = i + 1;j < n;j++){
        if(array[min].CompareTo(array[j]) > 0)  min = j;
      }
        if(min != i){
          Swap(ref array[i],ref array[min]);
          count++;
        }
    }
    for(i = 0;i < n - 1;i++){
      Console.Write(array[i] + " ");
    }
    Console.Write(array[n - 1]);
    Console.WriteLine("");

    Console.WriteLine(count);
  }

  static void Swap(ref int x,ref int y){
    int temp;
    temp = x;
    x = y;
    y = temp;
  }
}



Measured memory_bytes: 9196
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	/*/TODO:!!!!!!!テスト用!!!!!!!!!
	sc = bufio.NewScanner(strings.NewReader(`
	8
	ABABBABA
										`))
	//TODO:!!!!!!!テスト用!!!!!!!!!*/

	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	//fmt.Fprintln(out, "[DEBUG]", time.Now())

	d := nextInt()
	t := nextInt()
	s := nextInt()

	ans := "Yes"
	if d > t*s {
		ans = "No"
	}

	//fmt.Fprintln(out, "[DEBUG]", a)
	fmt.Fprintln(out, ans)

}

// 挿入ソート配列
type slist struct {
	l []int
}

func makeSlist() slist {
	return slist{[]int{}}
}

func (s *slist) add(a int) {
	pos := sort.Search(len(s.l), func(i int) bool { return s.l[i] >= a })
	if pos < len(s.l) {
		s.l = append(s.l[:pos+1], s.l[pos:]...)
		s.l[pos] = a
	} else {
		s.l = append(s.l, a)
	}
}
func (s slist) contains(a int) bool {
	pos := sort.Search(len(s.l), func(i int) bool { return s.l[i] >= a })
	return pos < len(s.l) && s.l[pos] == a
}

//------------------------------------------------------------------------------

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

func printArray(a []int) {
	for i := 0; i < len(a); i++ {
		if i >= 1 {
			fmt.Fprint(out, " ")
		}
		fmt.Fprint(out, a[i])
	}
	fmt.Fprintln(out)
}

func absInt(x int) int {
	return int(math.Abs(float64(x)))
}
func minInt(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func maxInt(x, y int) int {
	if x > y {
		return x
	}
	return y
}
func sign(x int) int {
	if x == 0 {
		return 0
	}
	if x > 0 {
		return 1
	}
	return -1
}
func log10(x int) float64 {
	return math.Log10(float64(x))
}
func divCeil(shi, bo int) int {
	ans := shi / bo
	if shi%bo != 0 {
		ans++
	}
	return ans
}


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

using namespace std;

const int N = 100000;

int n;
int A[N];
int cnt[3];

bool ok(){
  cnt[2] -= cnt[0];
  if(cnt[2] >= 0) return 1;
  else{
    if(cnt[1] == 0 && cnt[2] == -1) return 1;
    else return 0;
  }
  
}

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

    cin >> n;
    for(int i=0; i!=n; ++i){
      cin >> A[i];
    }
    
    for(int i=0; i!=n; ++i){
      if(A[i]%4 == 0) ++cnt[2];
      else if (A[i]%2 == 0) ++cnt[1];
      else ++cnt[0];
    }
    
    cout << (ok() ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<list>
#include<numeric>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;
using namespace std;
template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll frac(ll n)
{
	if (n == 0) {
		return 1;
	}
	return (n * frac(n - 1)) % MOD;
}

/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*/
int main() {
	ll sx, sy,tx,ty; cin >> sx >> sy>>tx>>ty;
	ll x = sx, y = sy;
	while (1) {
		if (ty - y > 0) {
			y++;
			cout << "U";
		}
		else if (tx - x > 0) {
			x++;
			cout << "R";
		}
		else break;
	}
	while (1) {
		if (y - sy > 0) {
			y--;
			cout << "D";
		}
		else if (x - sx > 0) {
			x--;
			cout << "L";
		}
		else break;
	}
	x--;
	cout << "L";
	while (1) {
		if (ty - y >= 0) {
			y++;
			cout << "U";
		}
		else if (tx - x > 0) {
			x++;
			cout << "R";
		}
		else break;
	}
	cout << "D";
	y--;
	x++;
	cout << "R";
	while (1) {
		if (sy - y <= 0) {
			y--;
			cout << "D";
		}
		else if (sx - x < 0) {
			x--;
			cout << "L";
		}
		else break;
	}
	cout << "U";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;

void Main() {
  ll n;
  R n;
  P a[n];
  rep(i,n) cin >> a[i].F >> a[i].S;
  ll ans=0;
  rep(k,4) {
    vector<PP> p(n);
    rep(i,n) {
      p[i].F=a[i].F+a[i].S;
      p[i].S=a[i];
    }
    sort(all(p));
    rep(i,1000) {
      if(i>=n) break;
      rep(j,1000) {
        if(n-1-j<0) break;
        P x=p[i].S,y=p[n-1-j].S;
        ans=max(ans,abs(x.F-y.F)+abs(x.S-y.S));
      }
    }
    rep(i,n) {
      swap(a[i].F,a[i].S);
      a[i].F=MAX-a[i].F;
    }
  }
  pr(ans);
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 11468
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std; 
long long a[100020]={0}; 
int main ()
{
	int i,n;
	while(cin>>n)
	{
		for(i=0;i<n;i++)
		scanf("%lld",&a[i]);
		sort(a,a+n);
		long long t=1,m=0;
		for(i=n-1;i>0;i--)
		{
			if(a[i]==a[i-1])
			{
				t=a[i]*t;
				a[i-1]=0;
				m++;
			}
		if(m>=2)
			break;
		}
		if(m<2)
		cout<<"0"<<endl;
		else
		cout<<t<<endl;
	}
	
	return 0;
} 

Measured memory_bytes: 1024
#include <stdio.h>

int main(void) {
	int d[8] = {0,1,2,3,4,5,6},ans,n,i,sa;
	char s[8];
	while(scanf("%d",&n) , n != 0){
		ans = 1;
		for(i = 1;i <= 6;i++){
			d[i] = i;
		}
		for(i = 1;i <= n;i++){
			scanf("%s",s);
			if(s[0] == 'N'){
				sa = d[1];
				d[1] = d[2];
				d[2] = d[6];
				d[6] = d[5];
				d[5] = sa;
			}
			if(s[0] == 'E'){
				sa = d[1];
				d[1] = d[4];
				d[4] = d[6];
				d[6] = d[3];
				d[3] = sa;
			}
			if(s[0] == 'W'){
				sa = d[1];
				d[1] = d[3];
				d[3] = d[6];
				d[6] = d[4];
				d[4] = sa;
			}
			if(s[0] == 'S'){
				sa = d[1];
				d[1] = d[5];
				d[5] = d[6];
				d[6] = d[2];
				d[2] = sa;
			}
			if(s[0] == 'R'){
				sa = d[2];
				d[2] = d[3];
				d[3] = d[5];
				d[5] = d[4];
				d[4] = sa;
			}
			if(s[0] == 'L'){
				sa = d[2];
				d[2] = d[4];
				d[4] = d[5];
				d[5] = d[3];
				d[3] = sa;
			}
			ans+=d[1];
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 604
package main

import (
	"fmt"
	"strings"
)

func main() {
	var n, q int
	var s []string
	var l, r []int

	fmt.Scan(&n, &q)
	var tmp string
	fmt.Scan(&tmp)
	s = strings.Split(tmp, "")

	for i := 0; i < q*2; i++ {
		var tmp int
		fmt.Scan(&tmp)
		if i%2 == 0 {
			l = append(l, tmp)
		} else {
			r = append(r, tmp)
		}
	}

	sumList := []int{0}
	for i := 0; i < n-1; i++ {
		if s[i] == "A" && s[i+1] == "C" {
			sumList = append(sumList, sumList[i]+1)
		} else {
			sumList = append(sumList, sumList[i])
		}
	}

	for i := 0; i < q; i++ {
		fmt.Println(sumList[r[i]-1] - sumList[l[i]-1])
	}
}


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

int main()
{
    int N,Y;

    cin >> N >> Y;
    for(int i=0; i<=N; i++){
        for(int j=0; j<=N; j++){
            if(i*10000+j*5000+(N-i-j)*1000 == Y && i>=0 && j>=0 && N-i-j>=0){
                cout << i << " " << j << " " << N-i-j;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1;
    return 0;

}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		List<int[]> a = new ArrayList<int[]>(n);
		for (int i = 0; i < n; i++) {
			int[] anum = { Integer.parseInt(sc.next()), Integer.parseInt(sc.next()) };
			a.add(anum);
		}
		List<int[]> b = new ArrayList<int[]>(n);
		for (int i = 0; i < n; i++) {
			int[] bnum = { Integer.parseInt(sc.next()), Integer.parseInt(sc.next()) };
			b.add(bnum);
		}
		Collections.sort(a, new xsort());
		Collections.sort(b, new ysort());
		//		for(int []tmp:a) {
		//			System.out.println("("+tmp[0]+","+tmp[1]+")");
		//		}
		//		System.out.println();
		//		for(int []tmp:b) {
		//			System.out.println("("+tmp[0]+","+tmp[1]+")");
		//		}
		int cnt = 0;
		int x, y;
		for (int i = n - 1; i >= 0; i--) {
			x = a.get(i)[0];
			y = a.get(i)[1];
			//	System.out.println("a"+x+","+y);
			for (int j = 0; j < b.size(); j++) {
				if (x < b.get(j)[0] && y < b.get(j)[1]) {
					//			System.out.println("b"+b.get(j)[0]+","+b.get(j)[1]);
					b.remove(j);
					cnt++;
					break;
				}
			}
		}
		System.out.println(cnt);
	}
}

class xsort implements Comparator<int[]> {
	@Override
	public int compare(int[] a, int[] b) {
		return a[0] > b[0] ? 1 : -1;
	}
}

class ysort implements Comparator<int[]> {
	@Override
	public int compare(int[] a, int[] b) {
		return a[1] > b[1] ? 1 : -1;
	}
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
int main() {
  char C;
  cin >> C;
  if (C == 'a') {cout << 'b' << endl;}
  else if (C == 'b') {cout << 'c' << endl;}
  else if (C == 'c') {cout << 'd' << endl;}
  else if (C == 'd') {cout << 'e' << endl;}
  else if (C == 'e') {cout << 'f' << endl;}
  else if (C == 'f') {cout << 'g' << endl;}
  else if (C == 'g') {cout << 'h' << endl;}
  else if (C == 'h') {cout << 'i' << endl;}
  else if (C == 'i') {cout << 'j' << endl;}
  else if (C == 'j') {cout << 'k' << endl;}
  else if (C == 'k') {cout << 'l' << endl;}
  else if (C == 'l') {cout << 'm' << endl;}
  else if (C == 'm') {cout << 'n' << endl;}
  else if (C == 'n') {cout << 'o' << endl;}
  else if (C == 'o') {cout << 'p' << endl;}
  else if (C == 'p') {cout << 'q' << endl;}
  else if (C == 'q') {cout << 'r' << endl;}
  else if (C == 'r') {cout << 's' << endl;}
  else if (C == 's') {cout << 't' << endl;}
  else if (C == 't') {cout << 'u' << endl;}
  else if (C == 'u') {cout << 'v' << endl;}
  else if (C == 'v') {cout << 'w' << endl;}
  else if (C == 'w') {cout << 'x' << endl;}
  else if (C == 'x') {cout << 'y' << endl;}
  else {cout << 'z' << endl;}
}

Measured memory_bytes: 3572
#include <stdio.h>
#include <math.h>
int main() {
	double x1,y1,x2,y2;
	scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
	printf("%lf\n",sqrt(((x1-x2)*(x1-x2))+((y1-y2)*(y1-y2))));
	return 0;
}

Measured memory_bytes: 652
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define Dev 1000000007

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    int h, w;
    cin >> h >> w;
    string s[h];
    rep(i, h)
    {
        cin >> s[i];
    }
    set<int> height;
    set<int> width;
    rep(i, h)
    {
        bool flag = false;
        if (s[i][0] == '.')
        {
            rep(j, w)
            {
                if (s[i][j] == '#')
                    goto LOOPOUT;
            }
            height.insert(i);
        }
    LOOPOUT:;
    }
    rep(j, w)
    {
        bool flag = false;
        if (s[0][j] == '.')
        {
            rep(i, h)
            {
                if (s[i][j] == '#')
                    goto LOOPAUTO;
            }
            width.insert(j);
        }
    LOOPAUTO:;
    }
    rep(i, h)
    {
        if (height.count(i))
            continue;
        rep(j, w)
        {
            if (width.count(j))
                continue;
            else
            {
                cout << s[i][j];
            }
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
//Apparat : drobucs, aleonov, vit_72
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <iomanip>
#include <algorithm>
#include <string>
#include <queue>
#include <numeric>

//pragma warning(disable : 4996)
//#pragma GCC optimize("O3")

#define nptr nullptr
#define all(x) (x).begin(), (x).end()
#define drobucs ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define ff first
#define ss second
#define pb push_back

using namespace std;

typedef long long ll;

const int maxn = (int)2e5 + 13;
const ll INFL = 9223372036854775807;
const int INF = 2147483647;
const ll MOD = (int)1e9 + 7, MOD2 = 1e9 + 21;//1e9 + 21, 1e9 + 33, 1e9 + 87, 1e9 + 93
const ll base = 101, base2 = 37;
const long double pi = 3.1415926535897932;

ll a[maxn], b[maxn], c[maxn];

int main() {
	drobucs;
	
	ll n;
	cin >> n;
	for (int i = 1; i <= n; ++i)cin >> a[i];
	for (int i = 1; i <= n; ++i)cin >> b[i];
	for (int i = 1; i <= n - 1; ++i)cin >> c[i];
	ll sum = 0;
	int pref = -1;
	for (int i = 1; i <= n; ++i) {
		sum += b[a[i]];
		if (pref != -1) {
			if (pref == a[i] - 1)sum += c[a[i] - 1];
		}
		pref = a[i];
	}
	cout << sum << "\n";
	return 0;
}

Measured memory_bytes: 2304
use std::io::prelude::*;

fn input<T>() -> T
where
    T: std::str::FromStr,
{
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let d: i64 = input();
    let x: usize = input();
    let a: Vec<i64> = (0..n).map(|_| input()).collect();

    println!(
        "{}",
        x + a.iter().fold(0, |acc, &a| acc
            + (0..).map(|i| 1 + a * i).take_while(|&j| j <= d).count())
    );
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>
#include <stack>

using namespace std;

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

const ll mod = 1e9 + 7;
const ll mmod = 998244353;

vector<ll> dx = {1, -1, 0, 0};
vector<ll> dy = {0, 0, 1, -1};

vector<vector<ll>> g;
vector<vector<ll>> par;
vector<vector<ll>> dp;
vector<ll> d;


int main() {
    
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    ll n, s;
    cin >> n >> s;
    vector<ll> a(n);
    
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
    }
    ll ret = 0;
    vector<vector<ll>> dp(n + 1, vector<ll>(3001));
    dp[0][0] = 0;
    for (int i = 1; i <= n; ++i)
    {
        dp[i - 1][0]++;
        dp[i - 1][0] %= mmod;
        for (int j = 0; j < dp[i].size(); ++j)
        {
            dp[i][j] += dp[i - 1][j];
            dp[i][j] %= mmod;
            if (j - a[i - 1] >= 0)
            {
                dp[i][j] += dp[i - 1][j - a[i - 1]];
                dp[i][j] %= mmod;
            }
        }
        ret += dp[i][s];
        ret %= mmod;
    }
    
    cout << ret << endl;

    
    return 0;
}

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

using namespace std;

int main(){
    ll n;
    cin >> n;
    map<string,ll> memo;
    rep(i,n){
        string ai;
        cin >> ai;
        memo[ai]++;
    }
    bool ans = true;
    for(auto p:memo){
        if(p.second >= 2) ans = false;
    }
    cout << (ans ? "YES" : "NO") << endl;
}

Measured memory_bytes: 24832
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
static class Program{
	const int mod=1000000007;
	static void Main(){
		Sc sc=new Sc();
		int[] s=sc.Ia;
		int[] a=sc.Ia;
		long ans=0,m=0;
		long[] h1=new long[s[1]+2];
		long[] h2=new long[s[1]+2];
		for(int i = 1;i<s[0];i++) {
			ans+=(s[1]+a[i]-a[i-1])%s[1];
			if((s[1]+a[i]-a[i-1])%s[1]<2){continue;}
			int q=((a[i-1]+1)%s[1])+1;
			h1[q]++;
			h1[a[i]+1]--;
			h2[a[i]+1]-=(s[1]+a[i]-a[i-1]-1)%s[1];
			if(q>a[i]){
				h1[1]++;
				h2[1]+=s[1]-a[i-1]-1;
			}
		}
		for(int i = 1;i<=s[1];i++) {
			h1[i]+=h1[i-1];
			h2[i]+=h1[i]+h2[i-1];
			m=Math.Max(m,h2[i]);
		}
		Console.WriteLine(ans-m);
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()).Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()).Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
}

Measured memory_bytes: 18528
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 100010
int n,ans;
struct node
{
	int x,id;
}a[MAXN];
bool cmp(node A,node B)
{
	return A.x<B.x;
}
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i].x);
		a[i].id=i;
	}
	sort(a+1,a+1+n,cmp);
	for(int i=1;i<=n;i++)
		ans+=((a[i].id&1)!=(i&1));
	printf("%d\n",ans/2);
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <set>

class union_find {
  mutable std::vector<intmax_t> c;

public:
  union_find(size_t n): c(n, -1) {}

  size_t find(size_t v) const {
    if (c[v] < 0) return v;
    return (c[v] = find(c[v]));
  }

  bool unite(size_t u, size_t v) {
    u = find(u);
    v = find(v);
    if (u == v) return false;
    if (-c[u] > -c[v]) std::swap(u, v);
    c[v] += c[u];
    c[u] = v;
    return true;
  }

  bool connected(size_t u, size_t v) const { return (find(u) == find(v)); }

  size_t size() const { return c.size(); }
  size_t size(size_t v) const {
    return -c[find(v)];
  }
};

constexpr size_t m1 = -1;
constexpr size_t di[] = {m1, m1, m1, 0, 0, 1, 1, 1};
constexpr size_t dj[] = {m1, 0, 1, m1, 1, m1, 0, 1};

int testcase_ends() {
  size_t h, w;
  scanf("%zu %zu", &w, &h);
  if (h == 0 && w == 0) return 1;

  std::vector<std::vector<int>> c(h, std::vector<int>(w));
  for (auto& ci: c)
    for (auto& cij: ci) scanf("%d", &cij);

  union_find uf(h*w);
  for (size_t i = 0; i < h; ++i)
    for (size_t j = 0; j < w; ++j) {
      if (c[i][j] == 0) continue;
      for (size_t k = 0; k < 8; ++k) {
        size_t ni = i + di[k];
        size_t nj = j + dj[k];
        if (!(ni < h && nj < w)) continue;
        if (c[ni][nj] == 0) continue;
        uf.unite(i*w+j, ni*w+nj);
      }
    }

  std::set<size_t> r;
  for (size_t i = 0; i < h; ++i)
    for (size_t j = 0; j < w; ++j)
      if (c[i][j] == 1)
        r.insert(uf.find(i*w+j));

  printf("%zu\n", r.size());
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 2892