akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
using namespace std;

int main(){
  int i,n,m,d[10001],p[10001];
  while(1){
    cin >> n >> m;
    if(n==0 && m==0)break;
    for(i = 0; i < n; i++){
      cin >> d[i] >> p[i];
    }
    //   for(i = 0; i < n; i++){
    //for(int j = 0; j < n-1; j++){
    //	if(p[i] < p[i+1]){
    //	  swap(p[i],p[i+1]);
    //	  swap(d[i],d[i+1]);
    //	}
    // }
    // }
    for(i = 0; i < n; i++){
      for(int j = 0; j < n-1; j++){
	if(p[j] < p[j+1]){
	  swap(p[j],p[j+1]);
	  swap(d[j],d[j+1]);
	}
      }
    }

    i = 0;
    while(m>0){
      //  cout << "m " << m << endl;
      m--;
      d[i]--;
      if(d[i]==0)i++;
    }
    // for(i = 0; i < n; i++){
    // cout << "d[i]" << d[i] << " " << "p[i]" << p[i] << endl;
    // }
    int result = 0;
    for(i = 0; i < n; i++){
      result += d[i] * p[i];
    }
    cout << result << endl;
  }
  return 0;
}

Measured memory_bytes: 1236
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;

#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define ll __int64
#define __int64 long long
#define P pair<int,int>
#define PP pair<P,int>
#define F first
#define S second


int n, m;
int s[10], c[10];

int main() {
    cin >> n >> m;;
    rep(i, m)cin >> s[i] >> c[i];
    rep(i, m)s[i]--;

    for (int i = 0;; i++) {
        string now = to_string(i);
        
        if (now.size() > n) {
            cout << -1 << endl;
            return 0;
        }
        if (now.size() != n)
            continue;

        bool f = 1;
        rep(j, m)f &= ( (now[s[j]]-'0')==c[j]);
        if (f) {
            cout << now << endl;
            return 0;
        }

    }
    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll n, k;
ll x[100001];
int main() {
    cin>>n>>k;
    REP(i, 0, n) cin>>x[i];

    ll ans=inf;
    REP(i, 0, n-k+1){
        if(x[i]<=0 && x[i+k-1]<=0){
            ans=min(ans, abs(x[i]));
        }
        else if(x[i]<=0 && x[i+k-1]>0){
            if(abs(x[i])<abs(x[i+k-1])){
                ans=min(ans, 2*abs(x[i])+abs(x[i+k-1]));
            }
            else{
                ans=min(ans, abs(x[i])+2*abs(x[i+k-1]));
            }
        }
        else{
            ans=min(ans, x[i+k-1]);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<long long,long long>
#define rd(x) cin >> x;
#define rda(a,n) for(int i=1;i<=n;i++) cin >> a[i];
#define wr(x) cout << x << ' ';
#define wrl(x) cout << x << '\n';
#define wra(a,n) for(int i=1;i<=n;i++) cout << a[i] << ' '; cout << '\n';
#define lg length()
#define pb(x) push_back(x)
ifstream in("file.in");
ofstream out("file.out");
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
struct comp{
    bool operator()(int a, int b){
        return a>b;
    }
};

long long n,a[100005],s,cnt1,cnt2;


int main(){
    ios_base :: sync_with_stdio(0);
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    for(int i=1;i<=n;i++){
        s+=a[i];
        if(i%2 && s<=0) cnt1+=1-s,s=1;
        else if(!(i%2) && s>=0) cnt1+=s+1,s=-1;
    }
    s=0;
    for(int i=1;i<=n;i++){
        s+=a[i];
        if(!(i%2) && s<=0) cnt2+=1-s,s=1;
        else if(i%2 && s>=0) cnt2+=s+1,s=-1;
    }
    cout << min(cnt1,cnt2);
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int syouhinsu = sc.nextInt();
    int[] syouhin = new int[syouhinsu];
    for (int i = 0; i < syouhin.length; i++) {
      syouhin[i] = sc.nextInt();
    }
    int max = 0;
    int syohinnunber = -1;
    int sum = 0;
    for (int i = 0; i < syouhin.length; i++) {
      if (syouhin[i] > max) {
        max = syouhin[i];
        syohinnunber = i;
      }
    }
    syouhin[syohinnunber] = max / 2;
    for (int i = 0; i < syouhin.length; i++) {
      sum += syouhin[i];
    }
    System.out.println(sum);
  }

}


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

typedef long long ll;
const long long mod=1e9+7;

int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	vector<int>a(m);
	vector<bool>ok(n,true);
	for(int i=0;i<m;i++){
		scanf("%d",&a[i]);
		ok[a[i]]=false;
	}
	vector<ll>dp(n+1);
	dp[0]=1;
	for(int i=1;i<=n;i++){
		if(ok[i]){
			dp[i]+=dp[i-1];
			dp[i]%=mod;
			if(i>=2)dp[i]+=dp[i-2];
			dp[i]%=mod;
		}
	}
	printf("%lld\n",dp[n]);
	return 0;
}


Measured memory_bytes: 1408
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

N,M = map(int,readline().split())

cnt = [0]*(N+1)
for m in map(int,read().split()):
    cnt[m] += 1

print('YES' if all(c%2 == 0 for c in cnt) else 'NO')

Measured memory_bytes: 100876
while True:
    m, f, r = map(int, input().split())

    if m==-1 and f==-1 and r==-1: break

    mf_sum = m + f
    if m==-1 or f == -1:
        print('F')
    elif mf_sum >= 80:
        print('A')
    elif mf_sum >= 65:
        print('B')
    elif mf_sum >= 50 or r >= 50:
        print('C')
    elif mf_sum >= 30:
        print('D')
    elif mf_sum < 30:
        print('F')


Measured memory_bytes: 5596
#include <iostream>
#include <cstdio>
#include <cmath>


using namespace std;


int main (void){

	int a,b,c;
	int N;

	int parts[512];

	int experiments[1024][4];

	unsigned char judge = 0;

	while(true){
		scanf("%d%d%d",&a,&b,&c);
		if((a==0)||(b==0)||(c==0))break;
		scanf("%d",&N);
		for(int i=0;i<512;i++){
			parts[i] = 2;
		}
		for(int i=0;i<N;i++){
			scanf("%d%d%d%d",experiments[i],experiments[i]+1,experiments[i]+2,experiments[i]+3);
			if(experiments[i][3] == 1){
				parts[experiments[i][0]] = 1;
				parts[experiments[i][1]] = 1;
				parts[experiments[i][2]] = 1;
			}
		}
		/*for(int i=0;i<N;i++){
			printf("###%d%d%d%d\n",experiments[i][0],experiments[i][1],experiments[i][2],experiments[i][3]);
		}*/
		for(int i=0;i<N;i++){
			judge = 0;
			if(experiments[i][3] == 0){
				judge |= (parts[experiments[i][0]] != 1?0x1:0x0);
				judge |= (parts[experiments[i][1]] != 1?0x2:0x0);
				judge |= (parts[experiments[i][2]] != 1?0x4:0x0);
				switch(judge){
				case 0x1:
					parts[experiments[i][0]] = 0;
					break;
				case 0x2:
					parts[experiments[i][1]] = 0;
					break;
				case 0x4:
					parts[experiments[i][2]] = 0;
					break;
				}
			}
		}


		for(int i=1;i<=a+b+c;i++){
			printf("%d\n",parts[i]);
		}
	}


	return 0;
}

Measured memory_bytes: 1204
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 <_ >>() } ;($iter :expr ,{chars :$base :expr } ) =>{read_value !($iter ,String ) .chars () .map (|c |(c as u8 -$base as u8 ) as usize ) .collect ::<Vec <usize >>() } ;($iter :expr ,{char :$base :expr } ) =>{read_value !($iter ,{chars :$base } ) [0 ] } ;($iter :expr ,chars ) =>{read_value !($iter ,String ) .chars () .collect ::<Vec <char >>() } ;($iter :expr ,char ) =>{read_value !($iter ,chars ) [0 ] } ;($iter :expr ,usize1 ) =>{read_value !($iter ,usize ) -1 } ;($iter :expr ,$t :ty ) =>{$iter .next () .unwrap () .parse ::<$t >() .unwrap () } ;}
macro_rules !input_inner {($iter :expr ) =>{} ;($iter :expr ,) =>{} ;($iter :expr ,mut $var :ident :$t :tt $($r :tt ) *) =>{let mut $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;($iter :expr ,mut $var :ident $($r :tt ) *) =>{input_inner !{$iter ,mut $var :usize $($r ) *} } ;($iter :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;($iter :expr ,$var :ident $($r :tt ) *) =>{input_inner !{$iter ,$var :usize $($r ) *} } ;}
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;(iter =$iter :ident ,$($r :tt ) *) =>{let s ={use std ::io ::Read ;let mut s =String ::new () ;std ::io ::stdin () .read_to_string (&mut s ) .unwrap () ;s } ;let mut $iter =s .split_whitespace () ;input_inner !{$iter ,$($r ) *} } ;($($r :tt ) *) =>{let s ={use std ::io ::Read ;let mut s =String ::new () ;std ::io ::stdin () .read_to_string (&mut s ) .unwrap () ;s } ;let mut iter =s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;}
use std::collections::HashMap;
fn abssub(x: usize, y: usize) -> usize {
    if x > y {
        x - y
    } else {
        y - x
    }
}
fn main() {
    input!(t, q: [(usize, usize, usize, usize, usize); t]);
    use std::cmp::Reverse;
    for &(n, a, b, c, d) in &q {
        let mut ans = std::usize::MAX;
        let mut memo = HashMap::new();
        memo.insert(n, 0usize);
        let mut heap = std::collections::BinaryHeap::new();
        heap.push(Reverse((0usize, n)));
        while let Some(Reverse((x, m))) = heap.pop() {
            if memo.get(&m).map(|&z| z < x).unwrap_or(false) {
                continue;
            }
            ans = std::cmp::min(ans, x.saturating_add(d.saturating_mul(m)));
            for &(k, e) in &[(2, a), (3, b), (5, c)] {
                for &l in &[m / k, m / k + 1] {
                    let y = x.saturating_add(abssub(m, l * k).saturating_mul(d).saturating_add(e));
                    let z = memo.entry(l).or_insert(std::usize::MAX);
                    if *z > y {
                        *z = y;
                        heap.push(Reverse((y, l)));
                    }
                }
            }
        }
        println!("{}", ans);
    }
}


Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
typedef pair<int,int> P;
typedef vector<int> vi;

ll gcd(ll a,ll b){
    ll v0=a,v1=b,v2=a%b;
    while(v2!=0){
        v0=v1;
        v1=v2;
        v2=v0%v1;
    }
    return v1;
}

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

int main(){
    ios::sync_with_stdio(false);
    int a,b;
    int count=0;
    cin >> a >> b;
    if(a<=0&&b>=0) cout << "Zero" << endl;
    else{
        for(int i=a;i<=b;i++){
            if(i<0) count++;
        }
        if(count%2==1) cout << "Negative" << endl;
        else cout << "Positive" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[]args){
      Scanner sc = new Scanner(System.in);

      int n = sc.nextInt();
      int[] adata = new int[n];
      int[] bdata = new int[n];
      int[] cdata = new int[n-1];
      int sum = 0;

      for (int i =0 ;i<n ;i++ ) {
        adata[i] = sc.nextInt();
      }
      for (int i =0 ;i<n ;i++ ) {
        bdata[i] = sc.nextInt();
      }
      for (int i =0 ;i<n-1 ;i++ ) {
        cdata[i] = sc.nextInt();
      }

      for (int i =0 ;i<n ;i++ ) {
        sum = sum + bdata[i];
      }


        for (int i =0 ;i<n-1 ;i++ ) {
          if (adata[i]+1==adata[i+1]) {
            sum += cdata[adata[i]-1];
          }
          }



      System.out.println(sum);
}
}


Measured memory_bytes: 21844
#include <stdio.h>
#include <iostream>
#include <string>
#include <stdlib.h>
#include<time.h>
#include<cmath>
#include<vector>
using namespace std;

int main(void)
{
	int count;
	string w;
	cin >> w;
	
	for (int i = 0; i < w.size(); i++) {
		count = 0;
		for (int j = 0; j < w.size(); j++) {
			if (w[i] == w[j]) {
				count++;
			}
		}
		if (count % 2 != 0) {
			cout << "No";
			break;
		}

	}
	if(count%2==0)
		cout << "Yes";

	cout << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
	char[] list1 = reader.readLine().toCharArray();
	char[] list2 = reader.readLine().toCharArray();
	int res = 0;
	for(int i = 0;i<list1.length;i++){
		if(list1[i]!=list2[i]) res++;
	}
	System.out.println(res);
	}
}


Measured memory_bytes: 37688
N = int(input())
P = input().split()
P = [int(P[i]) for i in range(N)]

c = 0
X = []
for i in range(N):
    T = "go"
    X.append(P[i])
    x = min(X)
    X = [x]
    if P[i] > x:
        T = "end"
    if T == "go":
        c +=1
print(c)

Measured memory_bytes: 26012
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <set>
#include <queue>
#include <map>
#include <numeric>
#include <functional>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define INF ((int)1e9)
#define INFLL ((ll)1e18)
#define MOD (1000000007LL)


int main(int argc, const char * argv[]) {
    ios_base::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> Res(N);
    for (int n = 0; n < N; ++n) {
        int a;
        cin >> a;
        Res[a-1] = n+1;
    }
    for (auto n : Res) {
        cout << n << ' ';
    }
    cout << endl;

    return 0;
}


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

///////////////////////////////////////////
const long long int INF = 1000000000000000000LL;
using ll = long long int;
using vi = vector<int>;
using Vi = vector<long long int>;
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return 1; } return 0; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return 1; } return 0; }
template<class T>T sqar(T x){ return x*x; }
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
///////////////////////////////////////////

int main(){
    int n;cin>>n;
    vi v;
    if(n==0){
        cout<<0<<endl;
    }else{
        while(n!=0){
            if(n&2!=0){
                v.pb(1);
                n--;
            }else{
                v.pb(0);
            }
            n = -n/(2);
        }
        for(int i=v.size()-1;i>=0;i--){
            cout<<v[i];
        }
        cout<<""<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef vector<pii> VP;
typedef priority_queue<int> PQ;
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;

struct UnionFind {
	VI par;
	UnionFind(int N) :par(N) {
		REP(i, N)par[i] = i;
	}
	int root(int x) {
		if (par[x] == x)return x;
		return par[x] = root(par[x]);
	}
	void unite(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		if (rx == ry)return;
		par[rx] = ry;
	}
	bool same(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

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

	int N; cin >> N;

	UnionFind uni(N);

	VI A(N), B(N);
	VP a(N), b(N);
	VI cnt(N, 0);
	REP(i, N) {
		cin >> A[i];
		a[i].first = A[i];
		a[i].second = i;
	}
	REP(i, N) {
		cin >> B[i]; 
		b[i].first = B[i];
		b[i].second = i;
	}
	SORT(a);
	SORT(b);
	REP(i, N) {
		if (a[i].first > b[i].first) {
			cout << "No" << endl;
			return 0;
		}
		//cout << a[i].second << " " << b[i].second << endl;

		

		if (cnt[uni.root(b[i].second)] == 0)cnt[uni.root(b[i].second)] = 1;
		if (cnt[uni.root(a[i].second)] == 0)cnt[uni.root(a[i].second)] = 1;
		if (!uni.same(a[i].second, b[i].second))cnt[uni.root(b[i].second)]+=cnt[uni.root(a[i].second)];
		if(!uni.same(a[i].second,b[i].second))uni.unite(a[i].second, b[i].second);
		//cout << uni.root(a[i].second) <<" "<<uni.root(b[i].second)<< endl;
	}
	bool F = true;
	REP(i, N) {
		//cout << cnt[i] << endl;
		if (cnt[i] == N)F = false;
	}
	if (F) {
		cout << "Yes" << endl;
		return 0;
	}
	REP(i, N - 1) {
		if (b[i].first >= a[i + 1].first) {
			cout << "Yes" << endl;
			return 0;
		}
	}


	cout << "No" << endl;

	return 0;
}



Measured memory_bytes: 7424
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, m;
	cin >> n >> m;
	vector<pii> v(m);
	REP(i, m)cin >> v[i].first >> v[i].second;
	sort(ALL(v));
	int ans = n + 1;
	int c = 0, d = 0;
	REP(i, m) {
		if (v[i].first > d) {
			ans += 2 * (d - c);
			c = v[i].first;
			d = v[i].second;
		}
		else d = max(d, v[i].second);
	}
	ans += 2 * (d - c);
	cout << ans << endl;
}

Measured memory_bytes: 3212
#include <iostream>
#include <bits/c++io.h>
#include <vector>
#include <tuple>
#include <queue>
#define N 100
#define INF 1e9 + 5
using namespace std;

#include <iostream>
#include <bits/c++io.h>
#include <vector>
#include <tuple>
#include <queue>
#define N 100
#define INF 1e9 + 5
using namespace std;
using ll = long long;
vector<int> dp(10000005,-1);
int c[10000005];
ll solve(int k){
    if(k<1)return INF;
    if(k==1)return 0;
    
    if(dp[k]!=-1) return dp[k];
    ll a = solve(k-1)+abs(c[k]-c[k-1]);
    ll b = solve(k-2)+abs(c[k]-c[k-2]);
    dp[k]= min(a,b);
    return dp[k];
}
//20          10
//10 30     20

int main()
{
    int n;
    scanf("%d", &n);
    for (int i=1;i<=n;i++){
        scanf("%d", &c[i]);
    }
    //재귀로 풀어봅시다. 
    //solve 는 n일 때 최소가 되는 값을 반환하는 함수라고 합시다. 
    dp[0]=INF;
    dp[1]=0;
    dp[2]=abs(c[2]-c[1]);
    printf("%d",solve(n));
    //선형으로 풀어봅시다.
    // dp[0]=0; 
    // for(int i =0;i<n;i++){
    //     for(auto j:{i+1,i+2}){
    //         dp[j] = min( dp[j], dp[i]+abs(v[j]-v[i]) );
    //     }
    // }
    // cout<<dp[n-1];

    return 0;
}

Measured memory_bytes: 42880
while True:
  n = int(input())
  if n == 0:break
  mp = [list(map(int, input().split())) for _ in range(n)]
  used = [[False] * n for _ in range(n)]
  
  inits = []
  for y in range(n):
    for x in range(n):
      if mp[y][x] < 0:
        inits.append((x, y, mp[y][x]))
        used[y][x] = True
  
  vec = ((0, 1), (-1, 0), (0, -1), (1, 0))
  
  def search(x, y, s, index, inits, end):
    if s == 0 and index == end:
      return True
    elif s == 0:
      x, y, s = inits[index]
      index += 1
    
    ret = False
    for dx, dy in vec:
      nx, ny = x + dx, y + dy
      if 0 <= nx < n and 0 <= ny < n and not used[ny][nx] and mp[ny][nx] + s <= 0:
        used[ny][nx] = True
        ret = ret or search(nx, ny, s + mp[ny][nx], index, inits, end)
        used[ny][nx] = False
    return ret
  
  if sum([sum(lst) for lst in mp]) != 0:
    print("NO")
  else:
    if search(0, 0, 0, 0, inits, len(inits)):
      print("YES")
    else:
      print("NO")


Measured memory_bytes: 5632
X = gets.to_i
A = gets.split.map &:to_i
mod = 10**9+7
acc = []
A.each do |a|
    acc << (acc[-1] ? (acc[-1] + a) % mod : a % mod)
end
ans = 0
for i in 0..A.size-2
    ans += ((A[i] % mod) * (acc[-1] - acc[i] % mod)) % mod
    ans %= mod
end
p ans

Measured memory_bytes: 29840
N, K = map(int, input().split())
p = list(map(int, input().split()))
sumlist = [sum(p[i] for i in range(K))]
for i in range(N-K):
  S = sumlist[i]
  S += p[i+K]
  S -= p[i]
  sumlist.append(S)
print((max(sumlist) + K)/2)

Measured memory_bytes: 25060
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    ll n;
    cin >> n;
    ll l = 3 * n;
    vector<ll> a(l);
    for(ll i = 0; i < l; i++) {
        cin >> a[i];
    }
    sort(ALL(a), greater<ll>());
    ll ans = 0;
    for(ll i = 1; i < 2 * n; i += 2) {
        ans += a[i];
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 2560
#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>;

const int MAX=1e6+1;

int main(){
    int N;
    cin >> N;

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

    sort(A, A+N);

    vector<int> div(MAX, 0);
    int num_pre=0;
    rep(i, N){
        if(num_pre==A[i]){
            div[A[i]]=1;
            continue;
        }
        for(int j=A[i]*2; j<MAX; j+=A[i]){
            div[j]=1;
        }
        num_pre=A[i];
    }

    int ans=0;
    rep(i, N){
        if(div[A[i]]==0) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 8012
H,W,K = [ int(it) for it in input().split() ]
MOD = 1000000007

if (W==1):
    print (1)
else:
    import itertools as tool
    amd = [ it  for it in  tool.product( *([[0,1]]*(W-1)) ) if sum([ 1 if it[i]+it[i+1]==2 else 0 for i in range(W-2)] ) == 0   ]

    dp = [0]*W
    dp[0]=1


    for h in range(H):
        _dp = [0]*W
        for it in amd:
            w = 0
            for i in range(W):
                if w >= W-1 :
                    break
                if (it[w]==1):
                    _dp[w]+=dp[w+1]
                    _dp[w+1]+=dp[w]
                    w+=2
                else:
                    _dp[w]+=dp[w]
                    w+=1
            if (w==W-1):
                _dp[w]+=dp[w]
                w+=1
        dp = [ it%MOD for it in _dp]
    print (dp[K-1]%MOD)


Measured memory_bytes: 3064
/*
AizuOnline A0513
Shuffle The Cards
*/
#include <stdio.h>

int N;
int cards[200];
int w_card[200]; /* work area*/

void riffle_shuffle()
{
  int i;

  for(i=0;i<N;i++)
    {
      w_card[i*2]=cards[i];
      w_card[i*2+1]=cards[i+N];
    }
  for(i=0;i<2*N;i++)
    cards[i]=w_card[i];
}
void cut(int k)
{
  int i;

  for(i=0;i<2*N-k;i++)
    w_card[i]=cards[i+k];
  for(i=2*N-k;i<2*N;i++)
    w_card[i]=cards[i-2*N+k];

  for(i=0;i<2*N;i++)
    cards[i]=w_card[i];

}
void show_card()
{
  int i;

  for(i=0;i<2*N;i++)
    printf("%d\n",cards[i]);
}
void init_card()
{ 
  int i;

  for(i=0;i<2*N;i++)
    cards[i]=i+1;
}
main()
{
 
  int m,s;

  scanf("%d",&N);
  init_card();    
  scanf("%d",&m);

  while(m)
    {  
      scanf("%d",&s);
      if(s == 0)
	riffle_shuffle();
      else
	cut(s);
      m--;
    }
  
  show_card();
  return(0);
}

Measured memory_bytes: 0
#include <cstdio>
#include <queue>
#include <functional>
#include <algorithm>

using namespace std;
typedef long long ll;
int n,m;
int p[100001];
int a[100001],b[100001],c[100001];
int cnt[100001];

int main(void){
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++){
		scanf("%d",&p[i]);
	}
	for(int i=0;i<m-1;i++){
		cnt[min(p[i],p[i+1])]++;
		cnt[max(p[i],p[i+1])]--;
	}
	for(int i=1;i<=n;i++){
		cnt[i+1]+=cnt[i];
	}
	ll res=0;
	for(int i=1;i<=n-1;i++){
		scanf("%d %d %d",&a[i],&b[i],&c[i]);
		ll cost=(ll)a[i]*cnt[i];
		if(cost>(ll)b[i]*cnt[i]+c[i])cost=(ll)b[i]*cnt[i]+c[i];
		res+=cost;
	}
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 2976
using System;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = Console.ReadLine();
            var S = Console.ReadLine();

            var n = int.Parse(N);

            if (n % 2 != 0) {
                Console.WriteLine("No");
                return;
            }

            var len = n / 2;

            var b = S.Substring(0, len) == S.Substring(len);

            if (b) {
                Console.WriteLine("Yes");
            } else {
                Console.WriteLine("No");
            }
        }
    }
}


Measured memory_bytes: 11092
#include<cstdio>
#include<algorithm>
int main(){
	double n,m,d;
	scanf("%lf%lf%lf",&n,&m,&d);
	if(d!=0){
		printf("%.10lf\n",(m-1)*2*(n-d)/n/n);
	}else{
		printf("%.10lf\n",(m-1)*(n-d)/n/n);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int M = 305, p = 998244353;
int main() {
  do {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
  } while (false);
  int n, m;
  cin >> n >> m;
  vector<bitset<M> > arr(n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      int x;
      cin >> x;
      arr[i][j] = x;
    }
  }
  int rank = 0;
  for (int i = 0; i < m; i++) {
    int row = rank;
    while (row < n && !arr[row][i]) {
      row++;
    }
    if (row < n) {
      swap(arr[row], arr[rank]);
      for (int j = rank + 1; j < n; j++) {
        if (arr[j][i]) {
          arr[j] ^= arr[rank];
        }
      }
      rank++;
    }
  }
  vector<int> pow(n + m);
  pow[0] = 1;
  for (int i = 1; i < n + m; i++) {
    pow[i] = pow[i - 1] * 2 % p;
  }
  cout << (pow[n + m - 1] - pow[n - rank + m - 1] + p) % p << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

vector<int> p;

int main()
{
	int n;
	read(n);
	for(int i=1; i<=n; ++i){
		int x;
		read(x);
		if(i == x) p.pb(i);
	}
	n=p.size();
	int ans=0;
	for(int i=0; i<n;){
		if(i+1<n && p[i]+1==p[i+1]){
			i+=2;
		} else ++i;
		++ans;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;

const int N=3000005,mod=998244353;
int fac[N],rev[N],n,m,ans,sum;

inline int power(int x,int p){
	int res=1;
	for(;p;p>>=1,x=(ll)x*x%mod)
		if(p&1)res=(ll)res*x%mod;
	return res;
}
inline int C(int n,int m){
	return m<0||m>n?0:(ll)fac[n]*rev[m]%mod*rev[n-m]%mod;
}
void init(int lim){
	fac[0]=1;
	rep(i,1,lim)fac[i]=(ll)fac[i-1]*i%mod;
	rev[lim]=power(fac[lim],mod-2);
	per(i,lim,1)rev[i-1]=(ll)rev[i]*i%mod;
}

int calc(int n,int m){
	if(m<0||n<0)return 0;
	if(m==0&&n==0)return 1;
	return C(m+n-1,n-1);
}

int doit(int k){
	int rem=(sum-k)/2,mx=m;
	int sum=(calc(n,rem)-(ll)(n-k)*calc(n,rem-mx-1)%mod
			+2ll*mod-(ll)k*calc(n,rem-mx)%mod)%mod;
	//cerr<<k<<" "<<sum<<"  "<<rem<<endl;
	return (ll)C(n,k)*sum%mod;
}

int main(){
	scanf("%d%d",&n,&m);
	init(max(n,m)*3);
	sum=3*m;
	rep(i,0,min(m,n))
		if((sum-i)%2==0)
			ans=(ans+doit(i))%mod;
	printf("%d\n",ans);

	return 0;
}

Measured memory_bytes: 23680
#include <iostream>
#include <string>
#include <queue>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i <= (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

int main()
{
	long long N;
	cin >> N;
	long long sum = N/11*2;
	N -= N/11*11;
	if(N>6){
		sum+=2;
	}else if(N>0){
		sum+=1;
	}
	cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
const int N = 35;
const int M = 1e4;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0); 

int main(){
	double r;
	cin >> r;
	printf("%.20f",2*PI*r);
	return 0;
}

Measured memory_bytes: 3780
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+7;
struct nod
{
	int x,y;
}line[maxn];
bool cmp (nod a,nod b)
{
	return a.x<b.x;
}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++)
	{
		scanf("%d%d",&line[i].x,&line[i].y);
	}
	sort(line,line+n,cmp);
	int sum=0;
	int ans=0;
	priority_queue<int> q;
	for(int i=1;i<=m;i++)
	{
		while(line[ans].x<=i&&ans<n)
		{
			q.push(line[ans].y);
			ans++;
		}
		if(q.empty())
		{
			continue;
		}
		sum+=q.top();
		q.pop();
	}
	printf("%d\n",sum);
	
	
	
	return 0;
	
}

Measured memory_bytes: 1660
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1000000007;
const ll N=998244353;
ll power(ll x,ll n){ll res=1;while(n>0){if(n&1) res=res*x%MOD;x=x*x%MOD;n>>=1;}return res;}
ll modinverse(ll a){return power(a, MOD-2);}
void solve()
{
	ll n;
	ll d;
	cin>>n>>d;
	ll ans=0;
	forr(i, n)
	{
		ll x, y;
		cin>>x>>y;
		if(x*x+y*y<=d*d)
			ans++;
	}
	cout<<ans<<endl;
}
int main()
{
	#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll test=1;
    //cin>>test;
    while(test--)
    {
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 3812
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int num[3];

int main()
{
	string str;cin >> str;
	
	REP(i,str.size())
	{
		num[str[i] - 'a']++;
	}
	
	if(max(max(num[0],num[1]),num[2]) - min(min(num[0],num[1]),num[2]) < 2)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}
	
	return 0;
}

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


int main(){
    string s; cin >> s;
    int n; bool flag = true;
    n = s.size();
    if(n%2 == 1){
        cout << "No" << endl;
        return 0;
    }
    for(int j=0;j<n;j++){
        if(j%2 == 0){
            if(s[j] != 'h'){
                flag = false;
                cout << "No" << endl;
                return 0;
            }
        }else{
            if(s[j] != 'i'){
                flag = false;
                cout << "No" << endl;
                return 0; 
            }
        }
    }
    if(flag){
        cout << "Yes" << endl;
        return 0;
    }
} 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <cassert>
#include <random>


int main() {
	int x; std::cin >> x;
	std::cout << x / 500 * 1000 + (x % 500) / 5 * 5 << std::endl;
	return 0;
}


Measured memory_bytes: 256
import Control.Monad

mulList :: [Int] -> [Int] -> Int
mulList [] _ = 0
mulList _ [] = 0
mulList (x:xs) (y:ys) = x * y + mulList xs ys

solv :: [[Int]] -> [Int] -> [Int]
solv [] _ = []
solv _ [] = []
solv (af:as) b = mulList af b : solv as b

main = do
    l <- getLine
    let (m:n:_) = map read . words $ l
    la <- replicateM m getLine
    lb <- replicateM n getLine
    let a = map (map read . words) $ la
    let b = map read lb
    mapM_ (putStrLn . show) $ solv a b

Measured memory_bytes: 7556
N, L = map(int,input().split())
T = []
A = 0
for i in range(N):
    T.append(L + i)

if T[0] <= 0 and T[-1] >= 0:
    A = sum(T)

elif T[-1] < 0:
    A = sum(T[:-1])

else:
    A = sum(T[1:])

print(A)

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

int main(){
    int n,t,x,y,tmp;
    int chk[3]={0,0,0};
    scanf("%d",&n);
    for (int i=0;i<n;i++) {
        scanf("%d %d %d",&t,&x,&y);
        tmp=abs(x-chk[1])+abs(y-chk[2]);
        if (tmp>t-chk[0] || ((t-chk[0])-tmp)%2) {
            printf("No\n");
            return 0;
        }
        chk[0]=t;
        chk[1]=x;
        chk[2]=y;
    }
    printf("Yes\n");
    return 0;
}


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

int main(){
    int N;
    cin>>N;
    int C[N],S[N],F[N];
    for(int i=1;i<N;i++)cin>>C[i]>>S[i]>>F[i];

    for(int i=1;i<N;i++){
        int ans=S[i]+C[i];
        for(int j=i+1;j<N;j++){
            if(ans<S[j])ans=S[j];
            if((ans-S[j])%F[j]!=0)ans+=F[j]-(ans%F[j]);
            ans+=C[j];
        }
        cout<<ans<<endl;
    }
    cout<<0<<endl;
}

Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define REP(i, n) for(int i = 0;i < (n);i++)
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const llint mod=998244353;
const llint inf=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}

int main(void){
	int i,n;cin>>n;
	vector<int>dp(n);
	for(i=1;i<n;i++){
		int b=i,p=0;
		while(b>0){
			if(b%2==1){p++;}
			b/=2;
		}
		dp[i]=dp[i%p]+1;
		//cerr<<dp[i]<<endl;
	}
	string X;cin>>X;
	REV(X);
	int p=0;
	for(auto c:X){
		if(c=='1'){p++;}
	}
	//cerr<<"p="<<p<<endl;
	llint ro=1,ri=1,wo=0,wi=0;
	for(i=0;i<n;i++){
		if(X[i]=='1'){wo+=ro;wi+=ri;wo%=p+1;if(p>1){wi%=p-1;}}
		ro*=2;ri*=2;ro%=p+1;if(p>1){ri%=p-1;}
	}
	vector<int>ans(n);
	ro=1,ri=1;
	for(i=0;i<n;i++){
		if(X[i]=='0'){ans[i]=dp[(wo+ro)%(p+1)]+1;}
		else if(p>1){ans[i]=dp[(wi-ri+p-1)%(p-1)]+1;}
		else{ans[i]=0;}
		ro*=2;ri*=2;ro%=p+1;if(p>1){ri%=p-1;}
	}
	REV(ans);
	for(i=0;i<n;i++){cout<<ans[i]<<endl;}
	return 0;
}


Measured memory_bytes: 5056
#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)
int main()
{
    int N, K;
    cin >> N >> K;
    int total = K;
    REP2( i, 1, N )
    {
        total *= K - 1;
    }
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
s=input()
l=[0]
c=0
for i in range(1,n):
    if(s[i]=='C'):
        if(s[i-1]=='A'):
            c+=1
    l.append(c)
for q in range(k):
    x,y=map(int,input().split())
    print(l[y-1]-l[x-1])



Measured memory_bytes: 79668
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  int n, k; cin >> n >> k;
  vector<int> v(n, 0);
  for(int i = 0; i < k; i++){
    int d; cin >> d;
    for(int j = 0; j < d; j++){
      int a; cin >> a;
      v[a-1]++;
    }
  }

  int ans = 0;
  for(int i = 0; i < n; i++){
    ans += (v[i] == 0);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3596
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int k = sc.nextInt();
		Integer []a = new Integer [n];
		int sum = 0;
		for(int i = 0 ; i < n; i++) {
			a[i] = sc.nextInt();
			
		}
		Arrays.sort(a,Collections.reverseOrder());
		
		for(int j = 0; j < k; j++) {
			sum += a[j];
		}
		System.out.println(sum);
	}

}


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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

ll dp[222222][2];

void ch_max(ll &a, ll b){
	a = max(a, b);
}

int main(){
	cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
	string str;cin >> str;
	dp[0][0] = 1;
	dp[1][1] = 1;
	REP(i, str.size() - 1){
		if(str[i] != str[i+1])ch_max(dp[i+1][0], dp[i][0] + 1);
		ch_max(dp[i+2][1], dp[i][0] + 1);
		ch_max(dp[i+1][0], dp[i][1] + 1);
		ch_max(dp[i+2][1], dp[i][1] + 1);
	}

	//REP(i, str.size())cout << dp[i][0] << " ";cout << endl;
	//REP(i, str.size())cout << dp[i][1] << " ";cout << endl;

	cout << max(dp[str.size()-1][0], dp[str.size()-1][1]) << endl;
	return 0;
}


Measured memory_bytes: 3732
#include <iostream>
#include <algorithm>
using namespace std;
int
main ()
{
  int a, b;
  char op;
  while (true)
    {
      cin >> a >> op >> b;
      switch (op)
	{
	case '+':
	  cout << a + b << endl;
	  break;
	case '-':
	  cout << a - b << endl;
	  break;
	case '*':
	  cout << a * b << endl;
	  break;
	case '/':
	  cout << a / b << endl;
	  break;
	case '?':
	  exit (0);
	}
    }
}

Measured memory_bytes: 1160
#include<stdio.h>
#define MAX 251
#define NIL -100
struct Node{
  int p;
  int l;
  int r;
};
struct Node A[MAX];
int n,T[MAX];

int main(){
  int i,x;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    A[i].p=NIL;
    A[i].l=NIL;
    A[i].r=NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d",&T[i]);
    if(i!=0){
      if(i%2==1)
	A[i].p=T[i/2];
      else A[i].p=T[i/2-1];
    }
  }
  for(i=0;i<=n/2;i++){
    if((2*i+2)<n)A[i].r=T[2*i+2];
    if((2*i+1)<n)A[i].l=T[2*i+1];
  }
  for(i=0;i<n;i++){
     printf("node %d: key = %d, ",i+1,T[i]);
    if(i!=0){
      printf("parent key = %d, ",A[i].p);
      }
    if(A[i].l!=NIL)printf("left key = %d, ",A[i].l);
    if(A[i].r!=NIL)printf("right key = %d, ",A[i].r);
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
  int N,M,X;
  cin >> N >> M >> X;
  vector<int> A(M);
  rep(i,M) cin >> A[i];
  sort(A.begin(),A.end());
  auto P = lower_bound(A.begin(), A.end(), X);
  int i = P-A.begin();
  int L = i;
  int R = M - i;
  cout << ((L < R) ? L : R) << endl;
}


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

int main(void){
    int ma = 1, n;
    cin >> n;
    for(int i=1;i<=n;++i){
        for(int j=2;j<=n;++j){
            long long va = pow(i, j);
            if(va > n) break;
            if(va > ma)ma = va;
        }
    }
    cout << ma << endl;
}

Measured memory_bytes: 256
from sys import stdin
from itertools import groupby
S = stdin.readline().rstrip()
K = int(stdin.readline().rstrip())
l = len(S)
# Run Length Encoding
rle = [len(list(g)) for k, g in groupby(S)]

if len(set(S)) == 1:
    print(len(S) * K //2)
else:
    tmp_ans = sum([l // 2 for l in rle])*K
    if S[0] != S[-1]:
        print(tmp_ans)
    else:
        print(tmp_ans - (rle[0] // 2 + rle[-1] // 2 - (rle[0] + rle[-1]) // 2) * (K-1))

Measured memory_bytes: 3064
using System;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var N = input[0];
            var A = input[1];
            var B = input[2];

            if (A == 0)
            {
                Console.WriteLine(0);
                return;
            }
            else if (B == 0)
            {
                Console.WriteLine(N);
                return;
            }

            var k = N / (A + B);
            Console.WriteLine(k * A + Math.Min(A, N % (A + B)));
        }
    }
}


Measured memory_bytes: 13268
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define FOR(i, j, limit) for(int i=j; i< limit; ++i)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ECHO(x) cout<<x<<endl;
#define LL long long
int INF = 2147483647;
LL LINF = 9223372036854775807;
LL MOD = 1000000007;
typedef pair<int, int>P;
typedef pair<LL, LL>PL;
typedef vector<int> vi;
typedef vector<LL> vl;


int main(){
  int a[3];

  REP(i, 3)cin>>a[i];
  int ans=0;
  int even=0, odd=0;
  REP(i, 3){
    if(a[i]%2)++odd;
    else ++even;
  }
  if(odd==2) {
    ++ans;
    REP(i, 3){
      if(a[i]%2==1) ++a[i];
    }
  }
  if(even==2){
    ++ans;
    REP(i, 3){
      if(a[i]%2==0) ++a[i];
    }
  }
  int ma=0;
  REP(i, 3){
    ma=max(ma, a[i]);
  }
  REP(i, 3) ans += (ma-a[i])/2;

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


Measured memory_bytes: 256
import sys
from random import randint
input = sys.stdin.readline
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
t = [randint(0, 25) for i in range(D)]
last = [0] * 26
def score(day, score):
  for i in range(26): score -= (day - last[i]) * c[i]
  return score
def run(day):
  global last
  last = [0] * 26
  res = 0
  for d in range(day):
    contest = t[d]
    last[contest] = d + 1
    res = score(d + 1, res) + s[d][contest]
  return res


for d in range(1, D + 1):
  mx = -float("inf")
  mxx = randint(0, 25)
  for x in range(26):
    t[d - 1] = x
    res = run(d)
    if mx < res:
      mx = res
      mxx = x
  t[d - 1] = mxx

for _ in range(75):
  l = randint(1, 365)
  last = [0] * 26
  run(l)
  #print(last)
  zmx = -float("inf")
  zmxz = 0
  for z in range(26):
    t[l - 1] = z

    for d in range(l + 1, D + 1):
      mx = -float("inf")
      mxx = t[d - 1]
      for x in range(26):
        t[d - 1] = x
        res = score(d, 0) + s[d - 1][x]
        if mx < res:
          mx = res
          mxx = x
      t[d - 1] = mxx
      last[mxx] = d
    zres = run(D)
    if zres > zmx:
      zmx = zres
      zmxz = z
  t[l - 1] = zmxz

for x in t: print(x + 1)

Measured memory_bytes: 82344
import java.util.*;

class Main{
	public static void main(String[] $){
		Scanner s=new Scanner(System.in);
		ArrayList<StringBuilder> l=new ArrayList<>();

		int h=s.nextInt(),w=s.nextInt();

		for(int i=0;i<h;++i){
			String v=s.next();
			if(v.contains("#"))
				l.add(new StringBuilder(v));
		}
		for(int i=w-1;i>=0;--i){
			int I=i;
			if(l.stream().allMatch(o->o.charAt(I)=='.'))
				l.stream().forEach(o->o.deleteCharAt(I));
		}
		l.stream().forEach(System.out::println);
	}
}


Measured memory_bytes: 27728
#include <iostream>
using namespace std;
 
int main(){
    int a, b;
    int s, r;
 
    cin >> a;
    cin >> b;

    s = a * b;
    r = 2 * (a + b);

    if((a>=1)&&(b<=100)){
       cout << s << " " << r << endl;
    }else{
       cout << "error" << endl;
    };
}

Measured memory_bytes: 3052
n, m = [int(i) for i in input().split()]
A_Matrix = []
B_Matrix = []
output_list = []
tmp = 0
for i in range(n):
        A_Matrix.append([int(j) for j in input().split()])
for i in range(m):
    B_Matrix.append(int(input()))

for i in range(n):
    for j in range(m):
        tmp += A_Matrix[i][j] * B_Matrix[j]
    output_list.append(tmp)
    tmp = 0
for i in range(n):
    print(output_list[i])

Measured memory_bytes: 8104
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000007
int main(){
    int h,w,k; cin>>h>>w>>k;
    vector<vector<long>> dp(h+1,vector<long>(w,0));
    dp[0][0]=1;
    int num[]={1,2,3,5,8,13,21};
    for(int i=1;i<=h;i++){
        for(int j=0;j<w;j++){
            int l=j-1,r=w-1-(j+1);
            if(l<0)
                l=0;
            if(r<0)
                r=0;
            int n=num[r]*num[l];
            int a=num[r];
            if(j-2>=0)
                a*=num[j-2];
            int b=num[l];
            if(w-1-(j+2)>=0)
                b*=num[w-1-(j+2)];
            if(j-1>=0)
                dp[i][j-1]+=(dp[i-1][j]*a)%INF;
            if(j+1<w)
                dp[i][j+1]+=(dp[i-1][j]*b)%INF;
            dp[i][j]+=(dp[i-1][j]*n)%INF;
        }
    }
    cout<<dp[h][k-1]%INF;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  int H,W,i,j,n;
  cin >> H;
  cin >> W;
  
  while(H != 0 && W != 0){
      for(i = 0; i < H; i++){
          for(j = 0; j < W; j++){
              if((i + j) % 2 == 0){
                  cout << "#";
              }
              else{
                  cout << ".";
              }
          }
          cout << endl;
      }
      cin >> H;
      cin >> W;
      cout << endl;
  }
}


Measured memory_bytes: 3096