akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cmath>
#include<cstring>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<vector>
#include<iostream>
#include<algorithm>
#define MAXN 11000
#define LL long long
#define ll __int64
#define INF 0x3f3f3f3f
#define mem(x) memset(x,0,sizeof(x))
#define PI acos(-1)
#define eps 1e-10
#define RD(n) scanf("%d",&n)
using namespace std;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
LL powmod(LL a,LL b,LL MOD){LL ans=1;while(b){if(b%2)ans=ans*a%MOD;a=a*a%MOD;b/=2;}return ans;}
//head  ios::sync_with_stdio(false);


/*
    1.Shoud it use long long ?
    2.Have you ever test several sample(at least three) yourself?
    3.Can you promise that the solution is right? At least,the main ideal
    4.use the puts("") or putchar() or printf and such things?
    5.init the used array or any value?
    6.use error MAX_VALUE?
    7.use scanf instead of cin/cout?
    8.whatch out the detail input require
*/
const int maxn=1e18+5; 
int main()
{
	LL a,b;
	cin>>a>>b;
	if(a%b==0)
	{
		cout<<-1;
	}
	else
	{
		cout<<a;
	 } 
}




Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,m,i,j,mx,sum,a,b;
	scanf("%d %d",&n,&m);
	sum=0;
	mx=0;
	for(i=1;i<=m;i++){
		scanf("%d %d",&a,&b);
		if(a<n){
			sum+=n-a;
			mx=max(mx,n-a);
		}
	}
	printf("%d\n",sum-mx);
	return 0;
}


Measured memory_bytes: 2764
#include <stdio.h>

int main (void){
    int i;
    int abh[3];
    for (i=0;i<3;i++){//入力
        scanf ("%d",&abh[i]);
    }
    printf("%d\n",(abh[0]+abh[1])*abh[2]/2);
    return 0;
}

Measured memory_bytes: 128
mod reader {
    use std::fmt::Debug;
    use std::str::FromStr;
    use std::collections::VecDeque;
    use std::io::{self, Read};

    fn _read_line() -> String {
        let mut buf = String::new();
        io::stdin().read_to_string(&mut buf);
        buf
    }

    fn _read_vec_deque_string() -> VecDeque<String> {
        _read_line().split_whitespace().map(|s| s.to_string()).collect()
    }

    pub struct Reader {
        buf: VecDeque<String>
    }

    impl Reader {
        pub fn new() -> Reader {
            Reader {buf: VecDeque::new()}
        }

        fn update_buf(&mut self) {
            if self.buf.is_empty() {
                self.buf = _read_vec_deque_string();
            }
        }

        pub fn next<T>(&mut self) -> T where T: FromStr, T::Err: Debug {
            self.update_buf();
            self.buf.pop_front().unwrap().parse::<T>().unwrap()
        }

        pub fn nextN<T>(&mut self, n: usize) -> Vec<T> where T: FromStr, T::Err: Debug {
            let mut vec: Vec<T> = Vec::with_capacity(n);
            for i in 0..n {
                vec.push(self.next());
            }
            vec
        }
    }
}

fn main() {
    let mut reader = reader::Reader::new();
 
    let n: usize = reader.next();

    let a: Vec<i64> = reader.nextN(3 * n);

    use std::collections::BinaryHeap;
    let mut q : BinaryHeap<i64> = BinaryHeap::new();
    let mut asum: Vec<i64> = vec![0; n + 1];
    for i in 0..n {
        asum[0] += a[i];
        q.push(-a[i]);
    }
    for i in n..n*2 {
        q.push(-a[i]);
        asum[i - n + 1] = asum[i - n] + a[i] + q.pop().unwrap();
    }

    q.clear();
    let mut bsum: Vec<i64> = vec![0; n + 1];
    for i in (n*2..n*3).rev() {
        bsum[n] += a[i];
        q.push(a[i]);
    }
    for i in (n..n*2).rev() {
        q.push(a[i]);
        bsum[i - n] = bsum[i - n + 1] + a[i] - q.pop().unwrap();
    }

    let mut ans = asum[0] - bsum[0];
    for i in 1..n+1 {
        ans = std::cmp::max(ans, asum[i] - bsum[i])
    }
    println!("{}", ans);
}

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

using namespace std;

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b) {return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b) {return a = (a < b ? a : b);}

const int MAX_N = 3010;
const int MAX_M = 3010;


int n, m;
string s, t;
int dp[MAX_N + 1][MAX_M + 1];

int solve() {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (s[i] == t[j]) {
                dp[i + 1][j + 1] = dp[i][j] + 1;
            } else {
                dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
            }
        }
    }
    return dp[n][m];
}

int main() {
    cin >> s >> t;
    n = s.size();
    m = t.size();
    solve();
    int i = n, j = m;
    string ans;
    while(i != 0 && j != 0) {
        if(i > 0 && j > 0 && dp[i][j] == dp[i-1][j-1] + 1 && s[i-1] == t[j-1]) {
            i--;
            j--;
            ans += s[i];
        } 
        else {
            if(i > 0 && dp[i][j] == dp[i-1][j]) i--;
            else j--;
        }
    }
    reverse(all(ans));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 35584
import java.awt.Point;
import java.io.*;
import java.util.*;
import java.math.BigInteger;

public class Main {
    static class Solver {
        public void solve(MyReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();

            int a1 = 0;
            if (n>=2)a1 = n*(n-1)/2;

            int a2 = 0;
            if (m >= 2)a2 = m*(m-1)/2;

            out.println(a1+a2);
        }


    }

    public static void main(String[] args) {
        MyReader mr = new MyReader();
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        new Solver().solve(mr, out);
        out.close();
    }

    //    static int[][] dir = {{0,1}, {1,0},{-1,0}, {0,-1}};
//    static int[][] dir = {{0,1}, {1,0},{-1,0}, {0,-1}, {-1,-1},{-1,1}, {1,1}, {1,-1}};
    static class MyReader {
        BufferedReader br;
        StringTokenizer st;

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

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

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

        String nextLine() {
            String res = "";
            try {
                res = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }

            return res;
        }

        int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }

            return arr;
        }

        Integer[] nextIntegerArray(int n) {
            Integer[] arr = new Integer[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }

            return arr;
        }

        Long[] nextLongArray(int n) {
            Long[] arr = new Long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }

            return arr;
        }

        String[] nextStringArray(int n) {
            String[] arr = new String[n];
            for (int i = 0; i < n; i++) {
                arr[i] = next();
            }
            return arr;
        }
    }

    static void swap(int[] arr, int i, int j) {
        int tmp = arr[i];
        arr[i] = arr[j];
        arr[j] = tmp;
    }

}




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

int main(){
  int N;
  int a[200000];
  bool b[200000];
  bool clear = false;
  int pos = 0;
  int count = 1;

  cin >> N;
  for(int i=0;i<N;++i){
    cin >> a[i];
    b[i] = true;
  }

  for(int i=0;i<N;++i){
    if(a[pos]-1 == 1){
      clear = true;
      break;
    }else if(b[pos]){
      b[pos] = false;
      pos = a[pos]-1;
      count++;
    }else{
      break;
    }
  }

  if(clear){
    cout << count << endl;
  }else{
    cout << -1 << endl;
  }
}


Measured memory_bytes: 768
// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;

const int N = 2e5 + 5;

int n;
int arr[N];

int main()
{
  cin >> n;
  for(int i = 0; i < n; i++)
    cin >> arr[i];
  sort(arr, arr + n);
  ll ans = 0;
  priority_queue<int> pq;
  pq.push(arr[n - 1]);
  for(int i = n - 2; i >= 0; i--) {
    ans += pq.top();
    pq.pop();
    pq.push(arr[i]);
    pq.push(arr[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5088
from sys import stdin
from numba import jit
@jit(nopython=True)
def nC2(n):
    return n*(n-1)//2

def main():
    #入力
    readline=stdin.readline
    s=readline().strip()

    d=dict()
    p=1
    t=0
    for i in range(len(s)-1,-1,-1):
        n=int(s[i])
        m=(n*p+t)%2019
        t=m
        p*=10
        p%=2019
        if m not in d:
            d[m]=1
        else:
            d[m]+=1
        
    if 0 in d:
        ans=d[0]
    else:
        ans=0
    for v in d.values():
        ans+=nC2(v)
    print(ans)
    
if __name__=="__main__":
    main()

Measured memory_bytes: 107716
#include <stdio.h>

int main(){
    int n, l[1000], r[1000];
    int i, ninzu, total = 0;

    scanf("%d", &n);

    for(i=0; i<n; i++){
        scanf("%d %d", &l[i], &r[i]);
    }

    for(i=0; i<n; i++){
        ninzu = r[i] - l[i] + 1;
        total += ninzu;
    }

    printf("%d\n", total);

    return 0;
}

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

using namespace std;

#define UN unsigned
#define ll long long int
#define pb push_back
#define MOD 1000000007

int main(void){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	string s;
	cin >> s;
	
	int ans = 1;
	for(int i=0; i<n-1; i++){
		if(s[i] != s[i+1])
			ans++;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
int n;
char s[110][20];
int main() {
	scanf("%d",&n);
	for(register int i=0;i<n;++i)scanf("%s",s[i]);
	for(register int i=1;i<n;++i)if(s[i][0]!=s[i-1][strlen(s[i-1])-1]) return puts("No"),0;
	for(register int i=0;i<n;++i)for(register int j=0;j<i;++j)if(!strcmp(s[i],s[j])) return puts("No"),0;
	return puts("Yes"),0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;


int main()
{
	int h, a;
	scanf("%d%d", &h, &a);
	
	int count = h / a;
	if (h % a != 0)
		count++;
		
	printf("%d\n", count);
	
	return 0;
}



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

vector<int> make_bit(int n){
  vector<int> tmp;
  for (int i = 0; i < 10; ++i)
  {
    tmp.emplace_back(n%2);
    n/=2;
  }
  reverse(tmp.begin(), tmp.end());
  return tmp;
}

int main()
{
  int n;
  cin>>n;
  vector<vector<int>> vec(n,vector<int>(10));
  for (int i = 0; i < n; ++i)
  {
    for (int j = 0; j < 10; ++j)
    {
      cin>>vec[i][j];
    }
  }
  vector<vector<int>> P(n,vector<int>(11));
  for (int i = 0; i < n; ++i)
  {
    for (int j = 0; j < 11; ++j)
    {
      cin>>P[i][j];
    }
  }
  //priority_queue<int> ansv;
  vector<int> ansv;
  for (int i = 1; i < 1024; ++i)
  {
    vector<int> tmp=make_bit(i);
    int ans=0;
    for (int j = 0; j < n; ++j)
    {
      int cnt=0;
      for (int k = 0; k < 10; ++k)
      {
        if(vec[j][k]+tmp[k]==2) cnt++;
      }
      ans+=P[j][cnt];
    }
    //ansv.push(ans);
    ansv.emplace_back(ans);
  }
//  cout<<ansv.top();
  cout<<*max_element(ansv.begin(), ansv.end());
}

Measured memory_bytes: 256
#include<stdio.h>

int h[100];
int w[100];
int i;
int j;
int k;

int main(void){
	
	for(i=0;i<100;i++){
		scanf("%d %d",&h[i],&w[i]);
		if(h[i] == 0 && w[i] == 0){
			break;
		}
	}
	for(i=0;i<100;i++){
		for(j=0;j<h[i];j++){
			for(k=0;k<w[i];k++){
				printf("#");
			}
			printf("\n");
			
		}
			printf("\n");
			if(h[i+1] == 0 && w[i+1] == 0){
			break;
			
		}
		
	}

	return 0;
}

Measured memory_bytes: 572
# 2019-11-16 14:51:41(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    k, x = [int(x) for x in sys.stdin.readline().split()]
    stones = range(-10**6, 10**6+1)
    x_place = bi_l(stones, x)
    ans = stones[x_place-(k-1):x_place+(k-1)+1]
    for c in ans:
        print(c, end=' ')
    # k, x の制約から端を気にする必要はない
if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
n,m=map(int,input().split())
ka= [list(map(int,input().split())) for i in range(n)]
for i in range(n):
    ka[i].pop(0)
ans = ka[0]
for i in range(1,n):
    ans = set(ans) & set(ka[i])
print(len(ans))

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll read(){
	ll sum=0,f=1;
	char s=getchar();
	while (s<'0' or s>'9'){
		if (s=='-')f=-1;
		s=getchar();
	}
	while (s>='0' and s<='9'){
		sum=sum*10+s-'0';
		s=getchar();
	}
	return sum*f;
}
const int N=2*1e5+10;
ll a[N],b[N];
int n;
int main(){
	n=read();
	for (int i=1;i<=n;i++)a[i]=read();
	b[1]=a[1];
	for (int i=2;i<=n;i++)b[i]=max(b[i-1],a[i-1]);
	ll sum=0;
	for (int i=2;i<=n;i++){
		if (b[i]>a[i])sum+=b[i]-a[i];
	}
	cout<<sum<<endl;
	return 0;
}



Measured memory_bytes: 6720
from math import factorial
from operator import mul
from functools import reduce

def comb2(n,r):
    r = min(n - r, r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

def pff(m):
    pf = {}
    for i in range(2, int(m ** 0.5) + 1):
        while m % i == 0:
            pf[i] = pf.get(i, 0) + 1
            m //= i
    if m > 1: pf[m] = 1
    return pf

N, M = map(int, input().split())
L = pff(M)


anst = int(1)
for i in L.values():
    anst *= comb2(i+N-1, i)
    anst = anst%1000000007

ans = anst
print(ans)

Measured memory_bytes: 38896
//
//  main.cpp
//  CoderWork
//
//  Created by Minoru Hayashi on 2020/02/29.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//

#include <bits/stdc++.h>
using namespace std;

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

//#define __DBG__


void solve(void){

  int N, M;
  cin >> N >> M;
  
  int P[M];
  string S[M];
  
  map<int,int> AC;
  map<int,int> WA;
  
  REP(i,M){
    cin >> P[i] >> S[i];
    
    if(S[i]=="AC"){
      AC[P[i]]=1;
    }
    else
    {
      if(AC[P[i]]!=1){
        if(WA.count(P[i])){
          WA[P[i]]++;
        }
        else
        {
          WA[P[i]]=1;
        }
      }
    }
  }
  
  int ac_count=0;
  int wa_count=0;

  for(auto i:AC){
    if(i.second){
      ac_count++;
      if(WA[i.first]){
        wa_count += WA[i.first];
      }
    }
  }
  
  cout << ac_count << ' ' << wa_count << endl;

  return;
}

int main(int argc, const char * argv[]) {


    // cinを高速にするためのおまじない
    cin.tie(0);
    ios::sync_with_stdio(false);
  
    solve();
 
    return 0;
}





Measured memory_bytes: 15488
import java.io.*;

public class Main{
	public static void main(String[] args) throws IOException{
		//n:入力値の個数, ai:入力値, min:最小値 , max:最大値,
		int n,ai,min,max,i;
		//sum:合計値, aiを合算する為、int型では無くlong型で範囲を拡大する
		long sum = 0;

		//キーボード入力
		BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in));

		//nの値を受け取る（この後入力される値の個数を把握する）
		n = Integer.parseInt(br.readLine());

		//int型の最大値をminに代入
		min = Integer.MAX_VALUE;
		//int型の最小値をmaxに代入
		max = Integer.MIN_VALUE;

		//strAryにキーボード入力された文字列を” ”で区切った状態で代入
		String[] strAry = br.readLine().split(" ");

		//iが0のときi+してiがnより小さい間、{}処理を繰り返す
		for (i = 0; i < n; i++){
			//aiに文字列を代入
			ai = Integer.parseInt(strAry[i]);
			//条件：aiがminより小さい場合、minにaiを代入する
			if(ai < min) min = ai;
			//条件：aiがmaxより大きい場合、maxにaiを代入する
			if(ai > max) max = ai;
			//sumにsum+aiを代入する
			sum += ai;
		}
		//最小値、最大値、合計を1行で出力
		System.out.println(min+" "+max+" "+sum);
	}
}

Measured memory_bytes: 25488
N,M = list(map(int,input().split()))
H = [0] + list(map(int,input().split()))
Htree = []
for i in range(N+1):
    Htree.append([])
tower_check_log = [False for i in range(N+1)] # チェック済みフラグ

for i in range(M):
    a, b = list(map(int,input().split()))
    Htree[a].append(b)
    Htree[b].append(a)
    if H[a] > H[b]:
        tower_check_log[b] = True
    else:
        tower_check_log[a] = True

def chkNiceTower(tower_index):
    if tower_check_log[tower_index] == True:
        return False
    
    tgt = Htree[tower_index]
    tgt_hight = H[tower_index]
    tower_check_log[tower_index] = True

    for x in tgt:
        if tgt_hight > H[x]:
            tower_check_log[x] = True
        if tgt_hight < H[x]:
            return False
        if tgt_hight == H[x]:
            tower_check_log[x] = True
            return False

    return True

nice_cnt= 0
for i in range(1,N+1):
    if chkNiceTower(i):
        nice_cnt += 1

print(nice_cnt)


Measured memory_bytes: 30332
from collections import defaultdict, deque


def main():
    N = int(input())
    edges = list()
    adj_nodes = defaultdict(list)
    for _ in range(N - 1):
        a, b = list(map(int, input().split(' ')))
        a -= 1
        b -= 1
        edges.append((a, b))
        adj_nodes[a].append(b)
        adj_nodes[b].append(a)
    MAX_COLORS = max([len(nodes) for nodes in adj_nodes.values()])
    # BFS
    edge_colors = dict()
    frontier = deque()
    frontier.append((None, 0, None))  # from_node, to_node, color
    explored = [0 for _ in range(N)]
    while len(frontier) > 0:
        n = frontier.popleft()
        explored[n[1]] = 1
        next_from_node = n[1]
        before_color = n[2] if n[2] is not None else (MAX_COLORS - 1)
        next_color = before_color
        next_to_nodes = adj_nodes[next_from_node]
        for next_to_node in next_to_nodes:
            if explored[next_to_node] == 1:
                continue
            next_color = (next_color + 1) % MAX_COLORS
            frontier.append((next_from_node, next_to_node, next_color))
            edge_colors[(next_from_node, next_to_node)] = next_color
            edge_colors[(next_to_node, next_from_node)] = next_color
    # print answer
    print(MAX_COLORS)
    for edge in edges:
        print(edge_colors[edge] + 1)


if __name__ == '__main__':
    main()

Measured memory_bytes: 75612
#include <stdio.h>

using namespace std;

int main() {
  int A,B,result;
  char op;
scanf("%d %c %d",&A,&op,&B);
  if(op == '+')
  {
      result=A+B;
      printf("%d\n",result);
  }
  else if(op == '-')
  {
      result=A-B;
      printf("%d\n",result);
  }
  return 0;
}



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

int main(){
	int N, A, B;
	cin >> N >> A >> B;
	vector<int> AB;

	int sum, tmpi;
	for(int i = 1; i <= N; ++i){
		sum = 0;
		tmpi = i;
		while(1){
			sum += tmpi % 10;
			if(tmpi / 10 == 0) break;
			tmpi /= 10;
		}
		if(sum >= A && sum <= B){
			AB.push_back(i);
		}
	}

	sum = 0;
	for(int i = 0; i < AB.size(); ++i){
		sum += AB[i];
	}

	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 384
import std.stdio;
import std.string;

void main(){
	string str = chomp(readln());
	int len = cast(int)str.length;
	char[1000] str2;
	foreach(i; 0 .. len){
		str2[i] = str[len - i - 1];
	}
	str2[len] = '\0';
	writeln(str2);
}

Measured memory_bytes: 1028
from collections import defaultdict

N, M = map(int, input().split())
a = []
c = []
dp = defaultdict(lambda: 1000000000)
for i in range(M):
    ai, bi = map(int, input().split())
    a.append(ai)
    c.append(sum([1 << int(ci) - 1 for ci in input().split()]))

dp[0] = 0
for i in range(M):
    for k, v in list(dp.items()):
        dp[k | c[i]] = min(dp[k | c[i]], dp[k] + a[i])
print(dp[(1 << N) - 1] if (1 << N) - 1 in dp else -1)


Measured memory_bytes: 4260
#include <stdio.h>
 
int main(){
  int n,q,i,key,l,u,m;
  int S[100000],ans = 0;
 
  scanf("%d" ,&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d" , S + i);
  }
 
  scanf("%d" ,&q);
  for(i = 0 ; i < q ; i++){
    scanf("%d" ,&key);
    l = 0; u = n;
    while(u >= l){
      m = (l + u) / 2;
 
      if(S[m] == key){
    ans++;
    break;
      }
 
      if(S[m] < key){
    l = m+1;
      }else{
    u = m-1;
      }
    }
  }
  printf("%d\n" ,ans);
 
  return 0;
}



Measured memory_bytes: 2184
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#define MAX_N 100001
#define INF 2147483647
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
int main()
{
  long long int N,res;
  cin >> N;
  res = log10(N) + 1;
  for(int i=2;i<=sqrt(N)+1;i++){
    if(N % i == 0){
      res = max(log10(i)+1,log10(N/i)+1);
    }
  }
  cout << res << endl;
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}



Measured memory_bytes: 512
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def eratosthenes(n):
    p = []
    t = [True] * n

    t[1] = True
    for i in range(2, int(math.ceil(math.sqrt(n)))):
        if t[i]:
            p.append(i)
            for j in range(2*i, n, i):
                t[j] = False

    for j in range(i+1, n):
        if t[j]:
            p.append(j)

    return p


def divisor(n):
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            yield i
            if i != n // i:
                yield n // i


@mt
def slv(N):
    ans = 0
    for i in divisor(N):
        m = i-1
        if m == 0:
            continue
        if N//m == N % m:
            ans += m
    return ans


def slv2(N):
    ans = 0
    for m in range(1, N+1):

        if N//m == N % m:
            # print(m)
            print(m, N//m, N % m)
            ans += m
    return ans


def main():
    N = read_int()
    # print(slv2(N))
    print(slv(N))


if __name__ == '__main__':
    main()


Measured memory_bytes: 6344
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"12"# => r#"Yes"#,
r#"57"# => r#"No"#,
r#"148"# => r#"No"#,
}


fn solve(src: &str) -> String {
    input! {
        source = src,
        x: u64,
    }
    let sum = x.to_string().chars().map(|i| i as u64 - '0' as u64).sum::<u64>();

    if x % sum == 0 {
        "Yes"
    } else {
        "No"
    }.to_string()
}

Measured memory_bytes: 4352
#include <stdio.h>
#define MAX 100005
#define NIL -1

struct Node {
	int p , r , l;
};

struct Node T[MAX];
int n , D[MAX];

void print(int u)
{
	int i , c;
	printf("node %d: ",u);
	printf("parent = %d, ",T[u].p);
	printf("depth = %d, ",D[u]);
	
	if( T[u].p == NIL) printf("root, ");
	else if(T[u].l == NIL) printf("leaf, ");
	else printf("internal node, ");
	
	printf("[");
	
	for( i = 0, c = T[u].l; c != NIL; i++ , c = T[c].r)
	{
		if(i)printf(", ");
		printf("%d",c);
	}
	printf("]\n");
}

int rec( int u , int p)
{
	D[u] = p;
	if(T[u].r != NIL) rec(T[u].r,p);
	if(T[u].l != NIL) rec(T[u].l,p+1);
}

int main(void)
{
	int i , j , d , v , c , l , r;
	scanf("%d",&n);
	for( i = 0; i < n; i++) T[i].p = T[i].l = T[i].r = NIL;
	
	for( i = 0; i < n; i++)
	{
		scanf("%d %d",&v,&d);
		for( j = 0; j < d; j++)
		{
			scanf("%d",&c);
			if( j == 0)T[v].l = c;
			else T[l].r = c;
			l = c;
			T[c].p = v;
		}
	}
	for( i = 0; i < n; i++)
	{
			if(T[i].p == NIL) r = i;
	}
	
	rec(r,0);
	for( i = 0; i < n; i++) print(i);
	return 0;
}


Measured memory_bytes: 6376
#include <bits/stdc++.h>
using namespace std;
int main(){
bool c=false,f=false;
string s;
int i;
cin>>s;
for(i=0;i<s.size();i++){
if(s[i]=='C') c=true;
if(c==true&&s[i]=='F') f=true;
}
if(c==true&&f==true) cout<<"Yes";
else cout<<"No";
return 0;
}

Measured memory_bytes: 256
# 約数の列挙
#############################################################
def make_divisors(n):
    lower_divisors, upper_divisors = [], []
    i = 1
    while i * i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n // i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
#############################################################

N = int(input())

# Nの約数
div1 = make_divisors(N)
# N-1の約数
div2 = make_divisors(N - 1)

#　マージして、不適な1は除く
div_set = set(div1 + div2)
div_set.remove(1)
# print(div_set)

# div_setの中身をそれぞれシミュレート
# N -> N-K　を愚直にやると時間がかかる、modK == 1となるか否かで判定
ans = 0
for div in div_set:
    tmp = N
    while tmp % div == 0:
        tmp = tmp // div

    if tmp % div == 1:
        ans += 1
print(ans)


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

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

  cout << (a+b) * h / 2 << endl;
  

  return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "string"
using namespace std; 
int main(){ 
	string E, O; 
	cin>>E >>O; 
	for(int i=0; i < E.size(); i++){ 
cout<<E[i];
	 if (i < O.size()) cout << O[i]; 
	} 
	return 0;
}

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

const int INF=0x3f3f3f3f;

struct Segtree{
	int N;
	vector<int>dat;
	Segtree(int n){
		N=1;while(N<n)N<<=1;
		dat=vector<int>(2*N,-INF);
	}
	void update(int k,int x){
		k+=N;dat[k]=max(dat[k],x);
		while(k>1){
			k>>=1;
			dat[k]=max(dat[k*2],dat[k*2+1]);
		}
	}
	int query(int l,int r){
		int res=-INF;
		for(l+=N,r+=N;l<r;l>>=1,r>>=1){
			if(l&1)res=max(res,dat[l++]);
			if(r&1)res=max(res,dat[--r]);
		}
		return res;
	}
};

int b[300000];
int sum[300000];
vector<int>E[300000];

int main(){
	int n;cin>>n;
	int cnt=0;
	rep(i,n){
		scanf("%d",&b[i]);
		sum[i+1]+=sum[i];
		if(b[i]==0)sum[i+1]--,cnt++;
		else sum[i+1]++;
	}
	int q;cin>>q;
	rep(i,q){
		int l,r;scanf("%d%d",&l,&r);l--;
		E[l].push_back(r);
	}
	Segtree seg1(n+1),seg2(n+1);
	seg1.update(0,0);seg2.update(0,0);
	int ans=0;
	rep(i,n){
		for(int u:E[i]){
			int s1=seg1.query(0,i)+(sum[u]-sum[i]),s2=seg2.query(i,u)+sum[u];
			int res=max(s1,s2);
			ans=max(ans,res);
			seg1.update(u,res);seg2.update(u,res-sum[u]);
		}
	}
	cout<<n-(cnt+ans)<<endl;
}


Measured memory_bytes: 18944
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,i,cnt=0;
  cin >> n;
  int a[n];
  for(i=0;i<n;i++){
    cin >> a[i];
  }
  for(i=0;i<n;i++){
    if(a[i]!=(i+1)){
      cnt++;
    }
  }
  cout << (cnt <= 2 ? "YES" : "NO") << endl;
  return 0;
}


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


int main (int argc, char const *argv[])
{
    string N,M;
    cin>>N>>M;

    
    if (N[0]==M[2]&&N[1]==M[1]&&N[2]==M[0]) {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
    
    
    return 0;
}

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

int main() {
  ll N = 5;
  vector<ll>A(N);
  rep(i,N){
    cin >> A[i];
    if(A[i] == 0){
      cout << i+1;
      return 0;
    }
  }
}

Measured memory_bytes: 3568
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

Tuple!(int, int)[] prime_division(int n)
{
    Tuple!(int, int)[] res;
    foreach (i; 2..10^^6+1) {
        if (n%i == 0) {
            int cnt;
            while (n%i == 0) {
                ++cnt;
                n /= i;
            }
            res ~= tuple(i, cnt);
        }
    }
    if (n != 1) res ~= tuple(n, 1);
    return res;
}

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    auto ps = prime_division(M);
    int[] ds = [1];
    foreach (p; ps) {
        auto len = ds.length;
        foreach (i; 0..p[1]+1) {
            foreach (d; ds[0..len]) {
                ds ~= d * p[0]^^i;
            }
        }
    }
    sort(ds);
    foreach (d; ds) if (d >= N) {
        writeln(M/d);
        return;
    }
}

Measured memory_bytes: 380
use std::io;

fn main() {
    let mut case = 1;
    loop {
        let mut buf = String::new();
        io::stdin().read_line(&mut buf).unwrap();
        let v = buf.trim().parse::<i64>().unwrap();
        if v == 0 {
            break;
        }
        println!("Case {}: {}", case, v);
        case += 1;
    }
}


Measured memory_bytes: 5048
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  int n; cin >> n;
  vector<int> x(n);
  for(int i = 0; i < n; i++) cin >> x[i];
  lint ans = INF;
  for(int pos = 1; pos <= 100; pos++) {
    lint cost = 0;
    for(int i = 0; i < n; i++) {
      cost += (pos - x[i]) * (pos - x[i]);
    }
    ans = min(ans, cost);
  }
  cout << ans << endl;
  return 0;
}


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

vector<int> g[101];
bool use[101];
int n;

int dfs(int x,int k){
  int res = 0;
  use[x] = true;
  for(int i=0;i<(int)g[x].size();i++){
    if(!use[g[x][i]])res = max(res,dfs(g[x][i],k-1));
    if(res+1==k)break;
  }
  use[x] = false;
  return res+1;
}

int main(){
  int a,b;

  while(scanf("%d",&n) && n){
    for(int i=1;i<=100;i++){
      use[i] = false;
      g[i].clear();
    }

    for(int i=0;i<n;i++){
      scanf("%d %d",&a,&b);
      g[a].push_back(b);
      g[b].push_back(a);
    }

    int ans = 0;
    for(int i=1;i<=100;i++)
      if(g[i].size())ans = max(ans,dfs(i,n));
    printf("%d\n",ans);
  }
}

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

using namespace std;

int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  int a[n];
  for (size_t i = 0; i < n; i++) cin >> a[i];
  sort(a, a+n);
  int ans = 0;
  for (size_t i = 0; i < n-1; i++) ans += a[i+1] - a[i];

  cout << ans << endl;
  return 0;
}


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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var K = int.Parse(Console.ReadLine());
            var one = K / 2;
            var two = K - one;
            
            Console.WriteLine(one*two);
        }
    }
}


Measured memory_bytes: 11092
#include <iostream>
#include <string>
#include <cstdint>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <climits>
#include <numeric>
#include <algorithm>
#include <cassert>

using namespace std;


int main()
{
    int x,y,z;
    cin >> x >> y >> z;
    swap(x,y);
    swap(x,z);
    cout << x << ' ' << y << ' ' << z << '\n';
    return 0;
}


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

// int main() {
//     int n, m;
//     cin >> n >> m;
//     vector<int> a(n);
//     rep(i,m) {
//         int k;
//         cin >> k;
//         rep(j,k) {
//             int s;
//             cin >> s;
//             s--;
//             a[s] |= 1<<i;
//         }
//     }
//     int p = 0;
//     rep(i,m) {
//         int x;
//         cin >> x;
//         p |= x<<i;
//     }
//     int ans = 0;
//     rep(s,1<<n) {
//         int t = 0;
//         rep(i,n) {
//             if (s>>i&1) t ^= a[i];
//         }
//         if (t==p) ans++;
//     }
//     cout << ans << endl;
//     return 0;
// }

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> s(n);
    rep(i,m) {
        s[i] = 0;
        int c;
        cin >> c;
        rep(j,c){
            int t;
            cin >> t;
            s[i] |= 1<<(t-1);
        }
    }
    int p = 0;
    rep(i,m) {
        int t;
        cin >> t;
        p |= t<<i;
    }
    int ans = 0;
    rep(i,1<<n) {
        bool ok = true;
        rep(j,m) {
            if (__builtin_popcount(s[j]&i)%2 != (p>>j&1)) ok = false;
        }
        if (ok) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

int n, temp;
deque<int> ans;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    if(n==1) {
        cin >> temp;
        cout << temp << '\n';
    } else if(n==2) {
        cin >> temp;
        ans.push_back(temp);
        cin >> temp;
        ans.push_front(temp);
        for(int i=0; i<ans.size(); i++) cout << ans[i] << ' ';
    } else {
        for(int i=1; i<=n; i++) {
            cin >> temp;
            if(i%2!=0) ans.push_front(temp);
            else ans.push_back(temp);
        }
    }
    if(n>2) {
        if(n%2==0) for(int i=ans.size()-1; i>=0; i--) cout << ans[i] << ' ';
        else for(int i=0; i<ans.size(); i++) cout << ans[i] << ' ';
    }

    return 0;
}


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

using namespace std;

#define ll long long

int n;

void solve() {
  cin >> n;
  int d[n];
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  ll ans = 0;
  for (int i = 0; i < n-1; i++) {
    for (int j = i+1; j < n; j++) {
      ans += d[i]*d[j];
    }
  }
  cout << ans << '\n';
}

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


Measured memory_bytes: 256
def main():
	N, C = map(int, input().split())
	sushi_r = [[0 for _ in range(2)] for _ in range(N+2)]
	sushi_l = [[0 for _ in range(2)] for _ in range(N+2)]
	sushi_r[N+1] = [C, 0]
	sushi_l[N+1] = [C, 0]
	dp_r = [0]*(N+2)
	dp_l = [0]*(N+2)
	ans = 0
	for i in range(1, N+1):
		sushi_r[i] = list(map(int, input().split()))
		sushi_r[i][1] += sushi_r[i-1][1]
		dp_r[i] = max(dp_r[i-1], sushi_r[i][1]-sushi_r[i][0])
	for i in range(1, N+1):
		sushi_l[i][0] = C - sushi_r[N-i+1][0]
		sushi_l[i][1] = sushi_r[N-i+1][1]-sushi_r[N-i][1] + sushi_l[i-1][1]
		dp_l[i] = max(dp_l[i-1], sushi_l[i][1]-sushi_l[i][0])

	for i in range(0, N+1):
		ans = max(ans, dp_l[i]-sushi_l[i][0]+dp_r[N-i])
		ans = max(ans, dp_r[i]-sushi_r[i][0]+dp_l[N-i])

	print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 54992
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>

using namespace std;

int n, ct = 0;
bool p[1000001];

int main(){
	for (int i = 0; i < 1000001; i++) p[i] = 1;
	for (int i = 2; i < 1000; i++){
		if (p[i] == 1){
			for (int j = 0; i*(j + 2) < 1000000; j++){
				p[i*(j + 2)] = 0;
			}
		}
	}
	while (cin >> n){
		if (n == 0) break;
		for (int i = n + 1; i < 2*n + 1; i++)
			if (p[i] == 1) ct++;
		cout << ct << endl;
		ct = 0;
	}
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N;
  cin>>N;
  vector<int>A(N),B(N),C(N);
  for(int i=0;i<N;i++)cin>>A[i];
  for(int i=0;i<N;i++)cin>>B[i];
  for(int i=0;i<N-1;i++)cin>>C[i];
  int ans=0;
  for(int i=0;i<N;i++){
    ans+=B[A[i]-1];
    if(i<N-1&&A[i+1]==A[i]+1)ans+=C[A[i]-1];
  }
  cout<<ans<<endl;
  return 0;
}


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

inf = float('inf')
dp = [inf]*N
dp[0] = 0
dp[1] = abs(h[0] - h[1])
for i in range(2,N):
    kouho1 = dp[i-1] + abs(h[i] - h[i-1])
    kouho2 = dp[i-2] + abs(h[i] - h[i-2])
    dp[i] = min(kouho1, kouho2)

print(dp[N-1])


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

const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int SUMN = 1e5 + 2;
const int N = 1e2 + 2;

int n, w, sum;
int weight[N], value[N];

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

	for (int i = 1; i <= n; ++i) {
		cin >> weight[i] >> value[i];
		sum += value[i];
	}

	vector<vector<ll>> dp(n + 1, vector<ll>(sum + 1, INFLL));
	dp[0][0] = 0;

	for (int i = 1; i <= n; ++i) {
		for (int j = 0; j <= sum; ++j) {
			dp[i][j] = dp[i-1][j];
			if (value[i] <= j) 
				dp[i][j] = min(dp[i][j], dp[i-1][j-value[i]] + weight[i]);
		}
	}

	int ans = 0;
	for (int i = 0; i <= sum; ++i) {
		if (dp[n][i] <= w) {
			ans = max(ans, i);
		}
	}

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


Measured memory_bytes: 80256
#include<iostream>
#include<cstdio>
#include<cstring>
#define LL long long
using namespace std;
const int N=2e5+10;
const LL mod=1e9+7;
int n,d=0;
LL K,ans=0;
int a[3000];
int main(){
	cin>>n>>K;
	LL re1=(LL)(K+1)*K/(LL)2%mod;
LL re2=(LL)(K)*(K-1)/(LL)2%mod;
	for(int i=1;i<=n;++i) {
		cin>>a[i];
		for(int j=1;j<i;++j){
			if(a[i]==a[j]) continue;
			if(a[j]>a[i]) ans=(ans+re1)%mod;
			else ans=(ans+re2)%mod;
		}
	}
	cout<<ans<<endl;
}

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

int HW[201][201] = {};
int WW[10][10] = {};

void func()
{
	for (unsigned int k = 0; k < 10; k++)for (unsigned int j = 0; j < 10; j++)for (unsigned int i = 0; i < 10; i++)WW[i][j] = min(WW[i][j], WW[i][k] + WW[k][j]);
}

int main()	
{
	int H, W, ans = 0;
	cin >> H >> W;
	for (unsigned int i = 0; i < 10; i++)for (unsigned int j = 0; j < 10; j++)cin >> WW[i][j];
	for (unsigned int i = 0; i < H; i++)for (unsigned int j = 0; j < W; j++)cin >> HW[i][j];
	func();
	for (unsigned int i = 0; i < H; i++)for (unsigned int j = 0; j < W; j++)if (HW[i][j] != -1)ans += WW[HW[i][j]][1];
	cout << ans << endl;
	return 0;
}

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

unsigned long long fight(unsigned long long N){
  unsigned long long result=0;
  if (N==1) return 1;
  else{
    return result+=2*fight(N/2);
  }  
}
 
int main(){
  unsigned long long H;
  cin >>H;
  cout << 2*fight(H)-1 <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;
struct edge {int to,costa,costb;};

signed main() {
 int d,g;
 cin>>d>>g;
 int p[d],c[d];
 for(int i=0;i<d;i++)cin>>p[i]>>c[i];
 int ans=g,a,t;
 for(int i=0;i<(1ll<<d);i++){
     a=0;t=0;
     for(int j=0;j<d;j++){
         if(i&(1ll<<j)){
             a+=p[j]*(j+1)*100+c[j];
             t+=p[j];
         }
     }
     for(int j=d-1;j>=0;j--){
         if(!(i&(1ll<<j))){
             if(g>a) t+=(g-a-1)/((j+1)*100) +1;
             a+=p[j]*(j+1)*100;
            break;
         }
     }
     if(g<=a)ans=min(ans,t);
  //   cerr<<ans<<' ';
 }
 cout<<ans;

return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	ll n, t;

	cin>>n>>t;

	vll time(n);

	rep(i, n) cin>>time[i];

	int i=0;
	ll ans=0, temp=0, d=0;
	while(i<n){
		if(temp>time[i]){
			temp=t+time[i];
		}else{
			ans+=temp-d;
			temp=t+time[i];
			d=time[i];
		}
		i++;
	}
	ans+=temp-d;
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int a,b,c,k;
   cin>>a>>b>>c>>k;
   if(a>=0&&b>=0&&c>=0&&k>=1&&k<=a+b+c&&a+b+c<=2*pow(10,9))
   {
	 if(k<=a+b)
	 {
		 if(k<a)
		 cout<<k<<endl;
		 else 
		 cout<<a<<endl;
	  }
		else
       {
	   cout<<(((k-(a+b))*-1)+a*1)<<endl;
      }
  }	     
   
  
  
  
return 0;
}


Measured memory_bytes: 3656
// Package main provides ...
package main

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

func main() {
	var m1, m2 int
	var err error

	scanner := bufio.NewScanner(os.Stdin)
	scanner.Scan()
	m1, err = strconv.Atoi(strings.Split(scanner.Text(), " ")[0])
	if err != nil {
		fmt.Println(err)
		return
	}
	scanner.Scan()
	m2, err = strconv.Atoi(strings.Split(scanner.Text(), " ")[0])
	if err != nil {
		fmt.Println(err)
		return
	}

	if m1 == m2 {
		fmt.Println(0)
	} else {
		fmt.Println(1)
	}
}



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

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

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int N = sc.nextInt();
		int[] A = nextIntArray(sc, N);

		sc.close();

		for (int n : A) {

			if (n % 2 == 0) {
				if (n % 3 == 0 || n % 5 == 0) {
					// ok
				} else {
					out.println("DENIED");
					return;
				}
			} else {
				// ok
			}
		}
		out.println("APPROVED");

	}

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

	@SuppressWarnings("unused")
	private int[] nextIntArray(Scanner sc, int n) {
		int[] result = new int[n];
		for (int i = 0; i < n; i++) {
			result[i] = sc.nextInt();
		}
		return result;
	}
}


Measured memory_bytes: 23764