akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cout << #x << ": " << x << endl
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

int gcd(int a, int b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	int n, k;
	cin >> n >> k;
	vi h(n);
	rep(i, n) cin >> h[i];
	//iterate over possible points
	sort(all(h));
	int mn = 1e9;
	rep(i, n){
		if(i + (k - 1) >= n) break;
		mn = min(mn, h[i + k - 1] - h[i]);
	}
	cout << mn << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 640
def resolve():
    import sys
    sys.setrecursionlimit(10 ** 6)  # 再帰関数の再帰の深さを設定
    to_index = lambda x: int(x) - 1  # 入力した数字に1を引いたものを返す
    print_list_in_2D = lambda x: print(*x, sep="\n")  # リストの要素を改行を挟んで表示する関数

    # 入力を整数に変換して受け取る
    def input_int():
        return int(input())

    def map_int_input():
        return map(int, input())

    MII = map_int_input

    def MII_split():
        return map(int, input().split())

    def MII_to_index():
        return map(to_index, input())

    def MII_split_to_index():
        return map(to_index, input().split())

    # 入力全てを整数に変換したものの配列を受け取る
    def list_int_inputs():
        return list(map(int, input()))

    LII = list_int_inputs

    def LII_split():
        return list(map(int, input().split()))

    # 2次元リスト化
    def LII_2D(rows_number):
        return [LII() for _ in range(rows_number)]

    def LII_split_2D(rows_number):
        return [LII_split() for _ in range(rows_number)]

    import itertools
    import copy

    H, W, K = MII_split()
    field = [input() for _ in range(H)]

    # print(field)

    ans = 0
    rows = [i for i in range(H)]
    cols = [i for i in range(W)]
    for row_num in range(H + 1):
        for col_num in range(W + 1):
            # 行の選び方
            for paint_rows in itertools.combinations(rows, row_num):
                for paint_cols in itertools.combinations(cols, col_num):
                    tmp_field = copy.deepcopy(field)
                    blacks = 0
                    for i, row in enumerate(tmp_field):
                        if i in paint_rows:
                            continue
                        for j, col in enumerate(row):
                            if j in paint_cols:
                                continue
                            if col == '#':
                                blacks += 1
                    if blacks == K:
                        ans += 1
    print(ans)
resolve()

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

int main() {
    int n,k,ans=0;
    cin>>n>>k;
    vector<int> l(n);
    rep(i,n) cin>>l[i];
    sort(l.begin(),l.end(),greater<int>());
    rep(i,k) ans+=l[i];
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define rep(a,t) for(int a=0;a<t;a++) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
#define pb push_back
int main()
{
	
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a[26];
	for (int i = 0; i < 26; i++) {
		a[i] = 0;
	}
	string u;
	cin >> u;
	for (int i = 0; i < u.length(); i++) {
		a[u[i] - 'a']++;
	}bool flag = true;
	if (a[0] == 1 && a[1] == 1 && a[2] == 1) {
		for (int i = 3; i < 26; i++) {
			if (a[i] != 0)
			{
				flag = false;
			}
		}
	}
	else {
		flag = false;
	}
	if (flag) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
class Main {
 public static void main(String[] args) throws IOException{
	try ( BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) ){
		final int target = Integer.parseInt( br.readLine() );
		int counter = 0;

		for( int i = 3; i <= target; i+=2 ){
			int tmpCnt = 0;
			for( int j = 1 ; j <= i ; j+=2 ){
				if( i%j == 0 ){
					tmpCnt++;	
				}
			}
//			System.out.println(i + ", " +tmpCnt);
			if( tmpCnt == 8 ){
				counter++;
			}
		}

		System.out.println(counter);

	}


 }
}

Measured memory_bytes: 22868
from functools import lru_cache

@lru_cache()
def eat(n, x):  # x = number of levels, return = number of patties
    #print(n,x)
    if n == 0:
        if x == 1:
            return 1  # 1 = patty
    if x == 1:
        return 0  # 0 = bun
    elif x <= 1 + thickness[n - 1]:
        return eat(n - 1, x - 1)
    elif x <= 1 + thickness[n - 1] + 1:
        return patties[n - 1] + 1
    elif x <= 1 + thickness[n - 1] + 1 + thickness[n-1]:
        return patties[n - 1] + 1 + eat(n - 1, x - 1 - thickness[n-1] - 1)
    else:
        return patties[n - 1] + 1 + patties[n - 1]

    return 0

N,X = map(int, input().split())

thickness = [0] * (N+1)
thickness[0] = 1
for i in range(1,N+1):
    thickness[i] = 1 + thickness[i-1] + 1 + thickness[i-1] + 1
patties = [0] * (N+1)
patties[0] = 1
for i in range(1,N+1):
    patties[i] = patties[i-1] + 1 + patties[i-1]

print(eat(N,X))


Measured memory_bytes: 3684
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pi acos(-1)
#define pb push_back
#define all(v) v.begin(),v.end()
#define INF 1e8
using namespace std;
typedef pair<int,int> p;
typedef long long ll;

int main(){
	int n,m,a,b;
	cin>>n>>m;
	bool edges[n],edgee[n];
	rep(i,n)edges[i]=edgee[i]=false;
	rep(i,m){
		cin>>a>>b;
		a--;b--;
		if(a==0)edges[b]=true;
		if(b==0)edges[a]=true;
		if(a==n-1)edgee[b]=true;
		if(b==n-1)edgee[a]=true;
	}
	bool check=false;
	loop(i,1,n-1){
		if(edges[i] && edgee[i]){
			check=true;
			break;
		}
	}
	cout<<((check)?"POSSIBLE":"IMPOSSIBLE")<<endl;
	return 0;
}

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

long long rec(int n,long long x){
    if(n == 0)return 1;
    long long len = (1LL << (n+1)) - 3;
    long long num = (1LL << n) - 1;
    if(x == 1)return 0;
    else if(x <= len + 1)return rec(n-1,x-1);
    else if(x == len + 2)return num +1;
    else if( x <= (len + 1)*2)return num + 1 + rec(n-1,x-len-2);
    else return num * 2 + 1;

}

int main(){
    int N;long long X;
    cin >> N >> X;
    cout << rec(N,X) << endl;
    
}

Measured memory_bytes: 3640
# 桁DP
def solve(S, K):
    L = len(S)
    # dp[決定した桁数][未満フラグ][０以外の数字を使った個数]
    dp = [[[0 for _ in range(4)] for _ in range(2)] for _ in range(101)]
    dp[0][0][0] = 1
    for i in range(L):  # 今見ている桁
        D = int(S[i])
        for j in range(2):  # 未満フラグ(0 or 1)
            for k in range(4):  # ０以外の数字を使った個数が0~3
                for d in range(10 if j else D + 1):
                    cnt = k
                    if d != 0:
                        cnt += 1
                    if cnt > K:
                        continue
                    dp[i + 1][j or (d < D)][cnt] += dp[i][j][k]

    return dp[L][0][K] + dp[L][1][K]


def main():
    n = int(input())
    K = int(input())
    print(solve(str(n), K))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (n, mut k) = scan!(usize, usize);
    let max = (n - 2) * (n - 1) / 2;
    if max < k {
        println!("-1");
        return;
    }

    k = max - k;

    let mut route = vec![(n - 1, n)];
    for i in 1..n - 1 {
        route.push((i, n - 1));
    }

    let mut index = 1;
    'out: loop {
        if k == 0 {
            break;
        }

        route.push((index, n));
        k -= 1;
        if k == 0 {
            break 'out;
        }

        let to = index + 1;
        for i in to..n - 1 {
            route.push((index, i));
            k -= 1;
            if k == 0 {
                break 'out;
            }
        }
        index += 1;
    }

    println!("{}", route.len());
    for (a, b) in route.into_iter() {
        println!("{} {}", a, b);
    }
}


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

typedef  long long int ll;
#define ent cout << "\n"
#define pb push_back
#define mp make_pair
#define sz(x) x.size()
#define pair < ll, ll > pp
#define f(a, b) for(auto i = a;i < b;i++)
#define rev_f(a, b) for(auto i = b;i >= a;i--)
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

#define st(x) sort(x.begin(), x.end()) 
#define rv(x) reverse(x.begin(), x.end()) 
#define cintc() ll tc;while(tc--) 
#define deb(x) cout << x << "\n";
#define cin() ll a; cin >> a;
#define cin2() ll a, b; cin >> a >> b
#define cin3() ll a, b, c; cin >> a >> b >> c
#define cinn(vect, n) def_v vect(n); f(0, n) cin >> vect[i]
#define coutn(vect, n)  f(0, n) {cout << vect[i] << " ";}ent;

typedef vector < ll > def_v;
typedef tuple< ll, ll, ll> def_tuple;
ll mod = 1e9 + 7,cnt = 0;

vector < ll > bfs(vector < ll > graph[], vector < ll > vect, ll start, ll flag, ll n)
{

    ll vis[n + 1] = {0};
    vis[start] = 1;
    queue < ll > q;
    q.push(start);
    while(!q.empty())
    {

        ll start = q.front();
        q.pop();
        auto size = ll(graph[start].size());
        for(ll j = 0;j < size;j++)
        {
            ll x = graph[start][j];
            if(!vis[x])
            {
                vis[x] = 1;
                if(x == 1 && flag == 2)
                {
                    flag = 2;
                }
                else
                    q.push(x);
                vect[x] = flag;
            }
        }
    }

    return vect;
}

vector < ll > int_binary(ll n, ll size)
{
    ll cnt = 0;
    def_v str(size);
    while(n > 0)
    {
        str[cnt++] = n%2;
        n = n/2;
    }
    return str;
}
void solve()
{   
    ll n, m, x;
    cin >> n >> m >> x;
        
    vector < ll > C;

    vector < ll > vect[n];
    f(0, n)
    {
        cin();
        C.pb(a);
        for(ll j = 0;j < m;j++)
        {
            cin();
            vect[i].pb(a);
        }
    }

    ll k = pow(2, n), mini = 1ll << 60;
    vector < ll > str;
    f(1, k)
    {
        vector < ll > str = int_binary(ll(i), n);

        ll cost = 0;
        vector < ll > sum(m);
        for(ll j = 0;j < n;j++)
        {
            if(str[j] == 1)
            {
                for(ll k = 0;k < m;k++)
                    sum[k] += vect[j][k];

                cost += C[j];
            }
        }
        ll cnt = 0;
        for(ll j = 0;j < m;j++)
        {
            if(sum[j] >= x)
                cnt++;
        }
        if(cnt == m)
            mini = min(mini, cost);
    }
    if(mini <= n*(100000))
        cout << mini << "\n";
    else
        cout << -1 << "\n";

    return ;
}
int main()
{
    fastio();
    ll tc = 1;
    // cin >> tc;
    while(tc--)
        solve();
    return 0;
}

Measured memory_bytes: 4068
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<utility>
#include<string>
#include<map>
#include<unordered_map>
#include<queue>

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

using namespace std;

typedef long long ll;
typedef pair<int, int> Pi;
int gcd(int a, int b){return b ? gcd(b, a%b) : a;}
int lcm(int a, int b){return a*b / gcd(a, b);}


int main(){
    string s; cin >> s;
    int n = s.size();
    deque<char> ans;
    for(int i = 0; i < n; i++) ans.push_back(s[i]);

    int Q; cin >> Q;
    bool head = true;
    for(int i = 0; i < Q; i++){
        int t; cin >> t;
        if(t == 1){
            head ^= 1;
        }
        else{
            int f;
            char c;
            cin >> f >> c;
            if(f == 1){
                if(head == true) ans.push_front(c);
                else ans.push_back(c);
            }
            else{
                if(head == true) ans.push_back(c);
                else ans.push_front(c);
            }
        }
    }
    
    if(head == true){
        for(int i = 0; i < ans.size(); i++){
            cout << ans[i];
        }
        cout << "\n";
    }
    else{
        for(int i = ans.size()-1; i >= 0; i--){
            cout << ans[i];
        }
        cout << "\n";
    }
    return 0;
}


Measured memory_bytes: 4036
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
typedef pair<int64_t, int64_t> PII;
typedef vector<int64_t> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
const int64_t INF = 1000000000000000;
const int64_t MOD = 1000000007;

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

int64_t N , M; cin >> N >> M;
int turn = (N - M) * 100 + 1900 * M;

double expect = 0.;
double suc = 1. / pow(2, M), fail = 1;
rep(i, 1, 10000){
    expect += i * suc * fail;
    fail *= 1 - suc;
}

cout <<  (int)ceil(expect * turn) << endl;



}
// 書いて考える
// 境界，出力文字列 チェック
// 可読性優先．高速化次点．
// まずは全探索，分割統治，次にDP
// 制限を見る．境界に注意．求めたい量の変域．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
int N, M;
vector<int> G[100000];
bool used[100000];
int ans[100000];

void bfs(){
    used[0] = true;
    queue<int> que;
    for(int v:G[0]) {
        used[v] = true;
        que.push(v);
        ans[v] = 0;
    }
    while(!que.empty()){
        int v = que.front();
        que.pop();
        for(int to : G[v]){
            if(!used[to]){
                used[to] = true;
                ans[to] = v;
                que.push(to);
            }
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int A, B;
        cin >> A >> B;
        A--; B--;
        G[A].push_back(B);
        G[B].push_back(A);
    }
    bfs();
    cout << "Yes" << endl;
    for(int i = 1; i < N; i++) cout << ans[i]+1 << endl;
}

Measured memory_bytes: 10640
c=[]
for i in range(3):
    ci=list(map(int,input().split()))
    c.append(ci)
for i in range(101):
    a1=i
    b1=c[0][0]-a1
    b2=c[0][1]-a1
    b3=c[0][2]-a1
    a2=c[1][0]-b1
    a3=c[2][0]-b1
    a=[a1,a2,a3]
    b=[b1,b2,b3]
    T=True
    for j in range(3):
        for k in range(3):
            if c[j][k]!=a[j]+b[k]:
                T=False
                break
    if T:
        print("Yes")
        quit()
print("No")


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

typedef long long ll;

int main(int argc, char* argv[])
{
  ll n;
  std::cin >> n;
  std::map< ll, ll > mm;

  ll max_a = 0;
  for (ll i = 0; i < n; i++) {
    ll tmp;
    std::cin >> tmp;
    mm[tmp]++;
    max_a = std::max(tmp, max_a);
  }
  //std::cout << max_a << " " << mm[max_a] << std::endl;

  ll max_val = 0;
  for (ll i = 0; i <= max_a; i++) {
    max_val = std::max(max_val, mm[i-1] + mm[i] + mm[i+1]);
  }

  std::cout << max_val << std::endl;
  return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}

int main(){
  int a, b;
  cin >> a >> b;
  int sum = 1, cnt = 0;
  while(b > sum){
    sum += a-1;
    cnt++;
  }
    cout << cnt << endl;
    return 0;
}

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

public class Main{
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		String string;
		int n, m, a = 0, b = 0, c = 0;
		
		while(!(string = reader.readLine()).equals("0")){
			n = Integer.valueOf(string);
			m = Integer.valueOf(reader.readLine());
			
			int map[][] = new int[n][n];
			boolean visit[] = new boolean[n];
			for(int i = 0;i < n; i++) Arrays.fill(map[i], 1 << 29);
			for(int i = 0; i < m; i++){
				string = reader.readLine();
				a = Integer.valueOf(string.split(",")[0]);
				b = Integer.valueOf(string.split(",")[1]);
				c = (Integer.valueOf(string.split(",")[2]) - 100) / 100;
				map[a][b] = map[b][a] = c;
			}
			c = 0;
			visit[0] = true;
			for(int x = 0; x < n - 1; x++){
				m = 1 << 29;
				for(int i = 0; i < n; i++){
					if(map[0][i] < m && !visit[i]){
						m = map[0][i];
						b = i;
					}
				}
				visit[b] = true;
				c += map[0][b];
				for(int i = 0; i < n; i++){
					map[0][i] = Math.min(map[0][i], map[b][i]);
				}
			}
			System.out.println(c);
		}
		reader.close();
	}
}

Measured memory_bytes: 33244
import Data.IntMap ((!))
import qualified Data.IntMap.Strict as M
import Control.Monad

apply n f x = foldr ($!) x (replicate n f)

main = do
 [n,_] <- map read . words <$> getLine
 abcs <- map (map read . words) . lines <$> getContents
 putStrLn $ maybe "inf" show (scoreAttack n abcs)
 
scoreAttack n abcs = do 
 let gf = apply n (move abcs) (M.singleton 1 0)
 let gs = apply n (move abcs) gf
 guard (gf!n == gs!n)
 return (gf!n)
 
move abcs g = foldr (\[a,b,c] acc -> if M.member a g then M.insertWith max b ((g!a) + c) acc else acc) g abcs


Measured memory_bytes: 4476
from sys import stdin
mat = [[False] * 8 for _ in range(8)]
def dfs(point, visited):
        all_visited = True
        n = len(visited)
        for i in range(n):
            if visited[i] == False:
                all_visited = False
        if all_visited:
            return 1
        ans = 0
        for i in range(n):
            # print("point", point, "i", i)
            # print(visited)
            if mat[point][i] == True and visited[i] ==False:
                # print("passed")
                visited[i] = True
                ans += dfs(i, visited)
                visited[i] = False
        return ans
def main():
    n, m = list(map(int, input().split()))
    
    for _ in range(m):
        a, b = list(map(int, input().split()))
        a = a - 1
        b = b - 1
        mat[a][b] = True
        mat[b][a] = True
    # print(mat)
    v = [False] * n
    v[0] = True
    print(dfs(0, v))

if __name__ == '__main__':
    main()

Measured memory_bytes: 42972
#include <cmath>

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;

int x;

void solve() {
  cin >> x;

  ll ans = 0;

  ll cnt = x / 500;

  x -= cnt * 500;
  ans += 1000 * cnt;

  cnt = x / 5;

  cout << ans + 5 * cnt << '\n';
}

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

  int t = 1;

#ifdef _DEBUG
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);

  t = 3;
#endif

  while (t--)
    solve();
}

Measured memory_bytes: 256
N=int(input())
s=["".join(sorted(input())) for i in range(N)]
s.sort()
ans=0
t=0
for i in range(N):
  if s[t]!=s[i]:
    ans+=(i-t)*(i-t-1)//2
    t=i
i+=1
ans+=(i-t)*(i-t-1)//2

print(ans)

Measured memory_bytes: 10640
#include <stdio.h>
#include <math.h>

int main(void)
{
  int N;
  scanf("%d",&N);
  int l[N],r[N];
  int i,all=0;
  for(i=0; i<N; i++)
    scanf("%d%d",&l[i],&r[i]);

  for(i=0; i<N; i++)
    all += r[i]-l[i]+1;

  printf("%d\n",all);
  return 0;
}


Measured memory_bytes: 128
line = input().split()
N = int(line[0])
M = int(line[1])
X = int(line[2])
Y = int(line[3])

xline = list(map(int,input().split()))
yline = list(map(int,input().split()))

a = max(xline)
b = min(yline)

if (b > a) and (a < Y) and (b > X):
    print("No War")
else:
    print("War")


Measured memory_bytes: 3064
nk=list(map(int,input().split()))
d=list(map(int,input().split()))
i=nk[0]
ans=0
while ans==0:
  flag=0
  for j in range(len(str(i))):
    if int(str(i)[j]) in d:
      flag=1
      break
  if flag==0:
    ans=i
  i+=1
print(ans)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<functional>
#include<vector>
#include<queue>
using namespace std;
#define f(i,n) for(int i=0;i<(int)n;i++)
#define MOD 1000000009

int main(void){
	char a[201];
	f(i, 201)a[i] = 0;
	int k, s;
	int n, m;
	int x, y, z;
	int ans = 0;
	for (;;){
		scanf("%s", a);
		if (a[0] == '-')return 0;
		m = strlen(a);
		scanf("%d", &n);
		s = 0;
		f(i, n){
			scanf("%d", &x);
			s += x;
		}
		s = s%m;
		for (int i = s; i < m; i++)printf("%c", a[i]);
		for (int i = 0; i < s; i++)printf("%c", a[i]);
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 2548
#include <bits/stdc++.h>
#include <cstdio>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define SORT(v, n) sort(v, v+n)
#define VREV(v) reverse(v.begin(),v.end())
#define REV(v,n) reverse(v,v+n)
#define vi vector<int>
#define pf push_front
#define pb push_back

template<class T, size_t N> size_t countof(const T (&array)[N]) { return N; }
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<"\n";}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}

void mprint(auto *matrix,auto N){
	REP(i,N) cout<<matrix<<(i!=N-1?' ':'\n');
	return;
}

const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18;
const long MOD =1e+9+7;
#define PI 3.14159265258979

#define P pair<int,int>
#define Pll pair<ll,ll>
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

inline int in(){int x; cin>>x; return x;}

struct UnionFind{
	vector<int> par; //データiが属する親の番号
	vector<int> sizes; //根ノードiの木に含まれるデータの数

	// 最初は全てのデータiがグループiに存在するものとして初期化
	UnionFind(int n):par(n),sizes(n, 1){
		REP(i,n) par[i] = i;
	}

	// 根を張り替えながら再帰的に根ノードを探す
	int find(int x){
		if(x==par[x]) return x;
		return par[x]=find(par[x]);
	}

	// 2つのデータx, yが属する木をマージする
	void unite(int x, int y) {
		// データの根ノードを得る
		x = find(x);
		y = find(y);

		// 既に同じ木に属しているならマージしない
		if (x == y) return;

		// xの木がyの木より大きくなるようにする
		if (sizes[x] < sizes[y]) swap(x, y);

		// xがyの親になるように連結する
		par[y] = x;
		sizes[x] += sizes[y];
		sizes[y] = 0;  // sizes[y]は無意味な値となるため
	}

	// 2つのデータx, yが属する木が同じならtrueを返す
	bool same(int x, int y) {
		return find(x) == find(y);
	}

	// データxが含まれる木の大きさを返す
	int size(int x) {
		return sizes[find(x)];
	}
};
int gcd(int n,int m){
	if(m>n) return gcd(m,n);
	if(m==0) return n;
	else return gcd(m,n%m); 
}

int main(void){
	int A,B;
	cin>>A>>B;
	print((A*3+B)/2);
	return 0;
}


Measured memory_bytes: 256
N=map(int,input())
T,A=map(int,input().split())
H=list(map(int,input().split()))

import numpy as np
def temp(T1,H):
    return T1-H*0.006
   
Q=[]
for i in range(len(H)):
    Q.append(np.abs(temp(T,H[i])-A))

print(np.argmin(Q)+1)

Measured memory_bytes: 12540
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>

using namespace std;



int main(){
    int N;
    int *H;
    cin >> N ;
    H = (int *)malloc(sizeof(int)*(N + 1));
    for (int i = 1; i <= N; i++) {
        scanf("%d",&H[i]);
    }
    for (int i = 1; i <= N; i++) {
        printf("node %d: ",i);
        printf("key = %d, ",H[i]);
        int k = i/2;
        if (k > 0) printf("parent key = %d, ",H[k]);
        k = 2*i;
        if (k <= N) printf("left key = %d, ",H[k]);
        k++;
        if (k <= N) printf("right key = %d, ",H[k]);
        
        printf("\n");
    }
    
    return 0;
}

Measured memory_bytes: 1228
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define f(n) for (int i = 0; i < n; i++)
#define fo(i, x, n) for (int i = x; i < n; i++)
#define fb(i, x, n) for (int i = n - 1; i >= x; i--)
#define w(t)  \
    int t;    \
    cin >> t; \
    while (t--)

typedef unsigned long long ull;
typedef vector<long long> vi;
#define msi map<string, long long>
#define mii map<long long, long long>
const int MX = 2e5 + 5;
const int INF = 1e18;
#define pb push_back
//#define endl "\n"
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define all(x) x.begin(), x.end()
#define ff first
#define ss second

void print(int a[], int n)
{
    for (int i = 0; i < n; i++)
    {
        cout << a[i] << " ";
    }
    cout << endl;
}

void print(vi &v)
{
    f(v.size())
    {
        cout << v[i] << " ";
    }
    cout << endl;
}

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

    string s;
    cin>>s;
    if(s[s.size()-1]=='s')
    {

        cout<<s<<"es"<<endl;
    }
    else
    {

        cout<<s<<"s"<<endl;
    }


    cerr<< "Time Killed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
    return 0;
}


Measured memory_bytes: 3840
n,d=map(int,input().split())
x_l = [list(map(int,input().split())) for _ in range(n)]
cnt=0
dis=[]
for i in range(n-1):
    for j in range(i+1,n):
        for k in range(d):
            if k==0:dis = 0
            dis += (x_l[i][k] - x_l[j][k])**2
        if dis**0.5%1 == 0:
            cnt += 1

print(cnt)

Measured memory_bytes: 3188
// AOJ 1248: The Balance
// 2017.12.17 bal4u@uu

#include <stdio.h>
#include <math.h>

int a, b;
int ansx, ansy;

void answer(int x, int y)
{
	if (x + y < ansx + ansy) ansx = x, ansy = y;
	else if (a*x + b*y < a*ansx + b*ansy) ansx = x, ansy = y;
}

int main()
{
	int d, t, x, ax;

	while(scanf("%d%d%d", &a, &b, &d) && a > 0) {
		ansx = 0x7ffffff, ansy = 0x7ffffff;
		for (ax = x = 0; x < 50000; x++, ax += a) {
			t = ax + d;
			if (!(t % b)) answer(x, t/b);
			t -= d << 1;
			if (t >= 0 && !(t % b)) answer(x, t/b);
			t = -t;
			if (t >= 0 && !(t % b)) answer(x, t/b);
		}
		printf("%d %d\n", ansx, ansy);
	}
	return 0;
}

Measured memory_bytes: 1784
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;

const int N = 200003;

int a[N], n, b[N];

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%d", a + i);
	int tmp = 0;
	for (int i = n; i > 1; i -= 2) {
		++tmp;
		b[tmp] = a[i];
		b[n - tmp + 1] = a[i - 1];
	}
	if (n & 1)
		b[tmp + 1] = a[1];
	for (int i= 1; i <= n; ++i) printf("%d ", b[i]); puts("");
	return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>
#include <chrono>
#include <stack>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator<< (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

istream& operator>> (istream& a, pii& b) {
    cin >> b.first >> b.second;
    return a;
}

ostream& operator<< (ostream& a, const pii& b) {
    cout << "{" << b.first << ", " << b.second << "}";
    return a;
}

template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 &y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 &y) {if (x < y) x = y;}


#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 500;
    // const int mod = 2600000069;
    // const int p = 10;
    // const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
    // const int mod = 2600000069;
    // const int p = 179;
    // const ld PI = 3.1415926535;
#endif

// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,sse3,sse4")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC optimize("fast-math")
// #pragma GCC target("avx2")  
// #pragma GCC optimize("section-anchors")
// #pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
// #pragma GCC optimize("vpt")
// #pragma GCC optimize("rename-registers")
// #pragma GCC optimize("move-loop-invariants")
// #pragma GCC optimize("unswitch-loops")
// #pragma GCC optimize("function-sections")
// #pragma GCC optimize("data-sections")

mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

const int MAXN = 1e6 + 10;

int dp[MAXN][2];
int a[MAXN];

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    for (int i = 0; i < MAXN; i++) {
        dp[i][0] = dp[i][1] = INF;
    }
    string s;
    cin >> s;
    int n = s.size();
    for (int i = 0; i < n; i++) {
        a[i] = s[i] - '0';
    }
    dp[0][0] = a[0];
    dp[0][1] = 2 + 9 - a[0];
    for (int i = 1; i < n; i++) {
        dp[i][0] = min(dp[i - 1][0], dp[i - 1][1]) + a[i];
        dp[i][1] = min(dp[i - 1][0] + 2, dp[i - 1][1]) + 9 - a[i];
    }
    cout << min(dp[n - 1][0], dp[n - 1][1]);
}
/*

*/


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

public class Main {

	private static void solve(){
		//Implement solution here.
		int n = ni();
		int result = 0;
		Map<Integer,Map<Integer,Integer>> map = new HashMap<Integer, Map<Integer,Integer>>();
		for(int i = 0; i < n; i++) {
			int cnt = ni();
			map.put(i + 1, new HashMap<Integer,Integer>());
			for(int j = 0; j < cnt; j++) {
				map.get(i + 1).put(ni(), ni());
			}
		}

		for(int i = 0; i < Math.pow(2, n); i++) {
			boolean ok = true;
			String s = String.format("%0" + n + "d",Long.parseLong(Long.toBinaryString((long)i)));
			char[] ca = s.toCharArray();
			for(int key:map.keySet()) {//証言者
				for(int target:map.get(key).keySet()) {//target
					int tv = map.get(key).get(target);
					if(ca[key - 1] == '1') {//証言者が正直者の場合
						if((tv == 1 && ca[target - 1] != '1') || (tv == 0 && ca[target - 1] != '0')) {
							ok = false;
							break;
						}
					}
				}
				if(!ok)break;
			}
			if(ok) {
				int cnt = 0;
				for(char c:ca) {
					if(c == '1')cnt++;
				}
				result = Math.max(result, cnt);
			}
		}
		System.out.println(result);		
	}

	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		solve();
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}

Measured memory_bytes: 55592
#coding:utf-8

N = int(input())
ls = []
for n in range(N):
    ls.append(int(input()))
ls.sort()
rm = []
temp = ls.pop(0)
rm.append(temp)
temp = ls.pop(-1)
rm.append(temp)
ans = rm[-1]-rm[0]
while(1):
    if len(ls)==0:
        break
    mx = 0
    for rm_index in range(2):
        for ls_index in [0,-1]:
            dist = abs(rm[rm_index]-ls[ls_index])
            if dist >= mx:
                mx = dist
                arg_rm = rm_index
                arg_ls = ls_index
    ans += mx
    rm[arg_rm] = ls.pop(arg_ls)
    #print(rm,ls)
print (ans)


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

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


int main() {
	int n;
	while(cin >> n && n){
		if(n == 1){
			cout << 1 << " " << 1 << endl;
			continue;
		}
		int p, d, x[200] = {0}, y[200] = {0}, min_x = 0, max_x = 0, min_y = 0, max_y = 0;
		for(int i = 1; i <= n - 1; ++i){
			cin >> p >> d;
			x[i] = x[p] + dx[d];
			y[i] = y[p] + dy[d];
			min_x = min(min_x, x[i]);
			max_x = max(max_x, x[i]);
			min_y = min(min_y, y[i]);
			max_y = max(max_y, y[i]);
		}
		cout << max_x - min_x + 1 << " " << max_y - min_y + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
int y[101],r,n;

double mk_dis(int x1,int h,double cy){
  return sqrt(x1*x1+(h-cy)*(h-cy));
}

bool check(double cy){
  //  cy=(int)(cy*100000)/100000.0;
  double x=sqrt(r*r-cy*cy);
  if(cy>=0)x=r;
  int L=(-x-0.999999),R=(x+0.999999),hb[101]={};
  for(int i=L+50;i<R+50;i++)
    if(i>=50){
      if(mk_dis(i-50,y[i],cy)>=r)hb[i]++;
    }
    else {
      if(mk_dis(i-49,y[i],cy)>=r)hb[i]++;
    }
  
  for(int i=L+50;i<R+50;i++)if(!hb[i])return false;
  return true;
}

int main(){
  while(1){
    cin>>r>>n;
    if(!r&&!n)break;
    memset(y,0,sizeof(y));
    for(int i=0;i<n;i++){
      int x1,x2,h;
      cin>>x1>>x2>>h;
      for(int j=x1;j<x2;j++) y[j+50]=max(y[j+50],h);
    }
    double ans;
    for(ans=0;check(ans-r);ans+=0.0001);
    cout << ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int n, m, c[50];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> m;
  FOR(i, 0, m){
    int a, b;
    cin >> a >> b;
    if(a==b) continue;
    c[a-1]++;
    c[b-1]++;
  }
  FOR(i, 0, n) cout << c[i] << endl;
}

Measured memory_bytes: 256
# 2020/03/14
# パナソニックプログラミングコンテスト2020 - B

# Input
h, w = map(int,input().split())

# Calc
hw = h * w
if h == 1 or w == 1:
    ans = 1
else:
    if hw % 2 == 0:
        ans = hw // 2
    else:
        ans = hw // 2 + 1

# Output
print(ans)


Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int main(){
    int x,y,w,h,n;
    int xx,yy;
    int cases;
    cin >> cases;

    for(int c=0;c<cases;++c){
        int ret=0;
        cin >> x >> y >> w >> h >> n;
        for(int i=0;i<n;i++){
            cin >> xx >> yy;
            if(x <= xx && xx <= x+w &&
               y <= yy && yy <= y+h){
                ret++;
            }
        }
        cout << ret << endl;
    }
}

Measured memory_bytes: 0
import itertools
import queue
l = [int(input()) for i in range(5)]
q = queue.Queue()
f = 123*5 + 60
for v in itertools.permutations(l, 5):
    for a in v:
        q.put(a)

    t = q.get()
    for i in range(0, 123*5 + 60):
        if t == 0 and q.empty():
            if i <= f:
                f = i
            break
        elif t == 0 and i % 10 == 0:
            t = q.get()
            t = t - 1
        elif t > 0:
            t = t - 1
print(f)

Measured memory_bytes: 3952
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
#define trace(x)  cerr << #x << ": " << x << endl;
typedef long long ll;
typedef long double ld;
ll fexp(ll a, ll b, ll p){ll ans = 1;while(b){if(b&1) ans = ans*a%p; b/=2;a=a*a%p;}return ans;}
const ll mod=1000000007;
const int N=1e5+5;
int main()
{
	fast;ll t;t=5;ll ans;
	while(t--)
	{
		ll x;cin>>x;if(x==0)ans=5-t;

	}
	cout<<ans;

}

Measured memory_bytes: 3584
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = 0
for i in range(n):
    ans += b[a[i] - 1]
    if i>0 and a[i] == a[i-1]+1:
        ans += c[a[i-1]-1]
        
print(ans)

Measured memory_bytes: 3064
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int c = 0;
        
        for(int i = 0;i < n;i++){
                int d1 = sc.nextInt();
                int d2 = sc.nextInt();
                
                
                if(d1 == d2){
                    c++;
                }else{
                    c = 0;
                }
                
                if(c >= 3){
                    System.out.println("Yes");
                    return;
                }
        }
        
        
        System.out.println("No");
        
        
    }
}


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

#define int long long
#define vi vector <int>
#define endl "\n"
#define vvi vector <vector<int> >
#define vii vector <pair<int,int> >
#define rep(i,a,b) for (int i=a;i<b;i++)
#define repD(i,a,b) for (int i=a;i>=b;i--)
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define init(i,k) memset(i,k,sizeof i)
#define pb push_back
#define pii pair <int,int>
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
const int N=3e3+5 , MOD=1e9+7;

// vector<vector<string> > dp(N, vector<string>(N,""));
string dp[2][N]={""};

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


void solve()
{
    string f,s;
    cin >> f >> s;
    f = '*'+f;
    s = '*'+s;
    int n1 = f.size(), n2 = s.size(), t=1;
    

    rep(i,1,n1)
    {
    	rep(j,1,n2)
    	{
    		if(f[i]==s[j])
    		{
    			dp[t][j] = dp[t^1][j-1] + s[j];
    		}
    		else
    		{
    			int x=dp[t][j-1].size(), y=dp[t^1][j].size(), z=dp[t^1][j-1].size();
    			if(x>=y && x>=z)
    				dp[t][j] = dp[t][j-1];
    			else if(y>=z && y>=x)
    				dp[t][j] = dp[t^1][j];
    			else
    				dp[t][j] = dp[t^1][j-1];
    		}
    	}
    	t ^= 1;
    }

    cout << dp[t^1][n2-1] << endl;
}

signed main()
{
    speed;
    
 //    int t; cin >> t;
 //    rep(tt,1,t+1)
 //    {
	// cout <<"Case #"<<tt<<": ";
	solve();
 //    }
    return 0;
}

Measured memory_bytes: 17016
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG abc/abc059/d.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    ll x, y;
    cin >> x >> y;
    if(abs(x - y) <= 1) cout << "Brown" << "\n";
    else cout << "Alice" << "\n";
    return 0;
}

Measured memory_bytes: 256
import itertools
import numpy as np
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

num = np.arange(1, n+1)

zyun = list(itertools.permutations(list(num), n))

for i in range(0, len(zyun)):
    if zyun[i] == p:
        a = i+1
    if zyun[i] == q:
        b = i+1

print(abs(a-b))

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

using namespace std;

#define int long long
#define ff first
#define ss second
#define pii pair<int, int>
#define pb emplace_back
#define pf emplace_front
#define mp make_pair
#define ld long double


signed main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s;
    int k;
    cin >> s >> k;
    int cnt = 0;
    int n = s.size();
    vector<int> kek;
    for (int i = 0; i < n; i++)
    {
        if (i && s[i] != s[i - 1])
        {
            kek.pb(cnt);
            cnt = 1;
        }
        else
            cnt++;
    }
    kek.pb(cnt);
    if ((int)kek.size() == 1)
    {
        int c = n * k;
        cout << c / 2;
        return 0;
    }
    int ans = 0;
    if (s[0] == s[n - 1])
    {
        for (int i = 1; i < (int)kek.size() - 1; i++)
            ans += kek[i] / 2;
        ans *= k;
        int c = kek[0] + kek.back();
        ans += (c / 2) * (k - 1);
        ans += kek[0] / 2 + kek.back() / 2;
    }
    else
    {
        for (int e : kek)
            ans += e / 2;
        ans *= k;
    }
    cout << ans;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")

/****Author: Barish Namazov****/
#include <bits/stdc++.h>

using namespace std;

/***TEMPLATE***/
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

#define F first
#define S second
#define pb push_back

#define endl '\n'

const int max4 = 10004;
const int maxx = 100005;
const int max6 = 1000006;
const int lg5 = 17;

const int INF = 2 * 1000000007;
const long long INFLL = 4LL * 1000000000 * 1000000000;

/***************/

int powmod (int a, int b, int mod) {
    int res = 1; a %= mod;
    for (; b; b >>= 1) {
        if (b & 1) {
            res = 1LL * res * a % mod;
        }
        a = 1LL * a * a % mod;
    }
    return res;
}

int gcd (int a, int b) {
    while (b > 0) {
        int t = a % b;
        a = b, b = t;
    }
    return a;
}

int lcm (int a, int b) {
    return (a / gcd (a, b)) * b;
}

int is_prime (int n) {
    if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
        return 0;
    for (int i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
        if (n % i == 0)
            return 0;
    return 1;
}

/******Don't forget to use long long when needed!!******/

int main() {
    //freopen("262144.in","r",stdin);
    //freopen("262144.out","w",stdout);
    int a, b;
    cin >> a >> b;
    cout << a - b + 1 << endl;
    return 0;
}


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

int main() {
    int n; cin >> n;
    string q, word;
    set<string> dic;
    
    for(int i=0; i < n; ++i){
        cin >> q >> word;
        if(q=="insert"){
            dic.insert(word);
        }else{
            if(dic.count(word)){
                cout << "yes" << endl;  
            }else{
                cout << "no" << endl;
            }
        }
    }
}



Measured memory_bytes: 32568
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	int cal(int x){
		if(x%2==0) {
			return 1+cal(x/2);
		}else {
			return 0;
		}
	}
	
	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int[] a = new int[N];
		for(int i=0;i<N;i++) {
			a[i] = sc.nextInt();
		}
		
		int ans = 0;
		for(int i=0;i<N;i++) {
			ans += cal(a[i]);
		}
		
		out.println(ans);
		
		
		sc.close();

	}

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

}


Measured memory_bytes: 34124