akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
using namespace std;

//Base class for Segment Trees
template <class T>
class segtree_base
{
protected:
	size_t width;
	vector<T> vec;
	T def;
	virtual T query_raw(int l_, int r_, int a_, int b_, int k_) = 0;
public:
	segtree_base(size_t size_, const T& def_ = T()) : def(def_)
	{
		width = 1;
		while (width < size_)width *= 2;
		vec.resize(width * 2 - 1, def);
	}
	T query(int left, int right)
	{
		return query_raw(left, right, 0, width, 0);
	}
	virtual ~segtree_base() {}
};

//Range Minimum Tree
template <class T>
class rmq_tree : public segtree_base<T>
{
public:
	rmq_tree(size_t size_, const T& def) : segtree_base<T>(size_, def)
	{}
	void update(int index, T val)
	{
		auto &vec = this->vec;
		index += (this->width - 1);
		vec[index] = val;
		while (index > 0)
		{
			index = (index - 1) / 2;
			vec[index] = min(vec[index * 2 + 1], vec[index * 2 + 2]);
		}
	}
private:
	T query_raw(int l_, int r_, int a_, int b_, int k_)override
	{
		const auto &vec = this->vec;
		if (l_ <= a_ && b_ <= r_)
		{
			return vec[k_];
		}
		if (b_ <= l_ || r_ <= a_)
		{
			return this->def;
		}
		int m = (a_ + b_) / 2;
		return min(
			query_raw(l_, r_, a_, m, k_ + k_ + 1),
			query_raw(l_, r_, m, b_, k_ + k_ + 2));
	}
};

int main(void)
{
	int n;
	while (cin >> n, n)
	{
		vector<string>dt;
		for (int i = 0; i < n; ++i)
		{
			string s; cin >> s; dt.push_back(s);
		}
		vector<int>dep;
		rmq_tree<int>rmq(n, INT_MAX);
		for (int i = 0; i < n; ++i)
		{
			dep.push_back(dt[i].find_last_of('.'));
			if (dep.back() == string::npos)dep[i] = 0;
			else
			{
				dep[i]++;
				dt[i][dep[i] - 1] = '+';
			}
			rmq.update(i, dep[i]);
		}
		vector<pair<int, int>>srt;
		for (int i = 0; i < dep.size(); ++i)srt.push_back({ dep[i],i });
		sort(srt.begin(), srt.end());
		for (int i = 0; i < srt.size() - 1; ++i)
		{
			if (srt[i].first != srt[i + 1].first)continue;
			if (rmq.query(srt[i].second, srt[i + 1].second) >= srt[i].first)
			{
				for (int j = srt[i].second + 1; j < srt[i + 1].second; ++j)
				{
					dt[j][srt[i].first - 1] = '|';
				}
			}
		}
		for (string s : dt)
		{
			replace(s.begin(), s.end(), '.', ' ');
			cout << s << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3748
#include <bits/stdc++.h>
#pragma GCC optimize("O3")

#define fi first
#define se second
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

using ll = long long;
using ld = long double;
using namespace std;

constexpr ll MOD = 1000000007;

signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  int x; cin >> x;

  if (x == 3 || x == 7 || x == 5) cout << "YES" << endl;
  else cout << "NO" << endl;

  return (0);
}


Measured memory_bytes: 3636
from collections import Counter
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]

score = [K]*N
c = Counter(A)
for i, j in c.items():
    score[i-1] += j

for x in range(N):
    if score[x] - Q > 0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 13948
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt();
		long x = sc.nextLong();
		long[] a = new long[n+1];
		a[0] = x;
		for(int i = 1; i < n+1; i++) {
			a[i] = sc.nextLong();
		}
		Arrays.sort(a);
		long[] b = new long[n];
		long g = a[1]-a[0];
		for(int i = 1; i < n; i++) {
			g = gcd((a[i+1] - a[i]),g);
		}
		System.out.println(g);
	}

	static long gcd(long a, long b) {
		long x = Math.max(a, b), y = Math.min(a, b);
		if(x%y == 0) return y;
		else return gcd(y, x%y);
	}

	static  class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

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

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

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

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

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


Measured memory_bytes: 45956
import numpy as np

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

dp = np.zeros((N+1, W+1), dtype='uint64')

for i in range(N):
  w, v = map(int, input().split()) 
  dp[i+1][:w] = dp[i][:w]
  dp[i+1][w:] = np.maximum(dp[i][w:], dp[i][:-w]+v)
print(np.max(dp[N]))

Measured memory_bytes: 92304
#include <stdio.h>

int num[100], val[100];
int main(viod)
{
	int i= 0, n, minn = 100, maxv = 0;

	scanf("%d", &n);
	for (i = 0; i< n; i++){
		scanf("%d %d", &num[i], &val[i]);
		if (maxv < val[i]){
			maxv = val[i];
		}
	}
	for (i =0; i< n; i++){
		if (maxv == val[i] && minn > num[i]){
			minn = num[i];
		}
	}
	printf("%d %d\n", minn, maxv);
	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#include <string.h>
int main(void){
    char s[4];
    int sum=700;
    scanf("%s",s);
    
    for(int i=0;i<(int)strlen(s);i++){
        if('o' == s[i])sum += 100;
    }
    printf("%d\n",sum);
    return 0;
}


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


int n,m,Ans;
int A[100][100];
int f[1000010];

int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++) 
		for(int j=1;j<=m;j++) cin>>A[i][j];
	for(int i=0;i<=1000;i++) f[i*i]=1;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
		{
			int S=0;
			for(int k=1;k<=m;k++) S+=(A[i][k]-A[j][k])*(A[i][k]-A[j][k]);
			Ans+=f[S];
		}
	cout<<Ans<<endl;
}

Measured memory_bytes: 3200
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MOD = 37; // 37;

int id[MOD + 1][MOD], eid;

vector<vector<int> > pages;

int intersect(const vector<int> &a, const vector<int> &b) {
	int ret = 0; REPSZ(i, a) { int cnt = 0; REPSZ(j, b) if (a[i] == b[j]) ++cnt; assert(cnt <= 1); ret += cnt; } return ret;
}
void run() {
	REP(i, MOD + 1) REP(j, MOD) id[i][j] = i*MOD + j + 1; eid = MOD*MOD + MOD + 1;
	
	pages.clear();
	REP(i, MOD + 1) { vector<int> page; page.PB(eid); REP(j, MOD) page.PB(id[i][j]); pages.PB(page); }
	REP(j, MOD) REP(delta, MOD) { vector<int> page; page.PB(id[0][j]); REP(i, MOD) page.PB(id[i + 1][(delta+j*i) % MOD]); pages.PB(page); }

	//REPSZ(i, pages) { printf("%d: ", i); REPSZ(j, pages[i]) { if (j != 0) printf(" "); printf("%d", pages[i][j]); } REPSZ(ii, pages) if (i != ii&&intersect(pages[i], pages[ii])!=1) printf(" !%d", ii); puts(""); }

	printf("%d %d\n", SZ(pages), SZ(pages[0]));
	REPSZ(i, pages) { REPSZ(j, pages[i]) { if (j != 0) printf(" "); printf("%d", pages[i][j]); } puts(""); }
}

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


Measured memory_bytes: 768
#include<iostream>
#include <algorithm>

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

using namespace std;
int main()
{
    // 整数の入力
    int N,K;
    cin >> N >> K;
    int a[N];
    // 入力
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    if (N <= K) {
        cout << 0 << endl;
        return 0;
    }

    sort(a, a + SIZE_OF_ARRAY(a), greater<>());
    long A = 0;
    for (int i = K; i < N; i++) {
        A += a[i];
    //    cout << A << endl;
    }
 
    cout << A << endl;
    return 0;
   
}

Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

int main() {
	string W; cin >> W;
	transform(W.begin(), W.end(), W.begin(), ::tolower);
	int cnt = 0;
	for (string T; cin >> T&&T != "END_OF_TEXT";) {
		transform(T.begin(), T.end(), T.begin(), ::tolower);
		if (T == W)
			cnt++;
	}
	cout << cnt << endl;
	return 0;
}

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

signed main(){
	int X, Y, Z, K, i, j, k;
	scanf("%lld%lld%lld%lld", &X, &Y, &Z, &K);
	vector<int> A(X), B(Y), C(Z);
	for(i = 0; i < X; i++){
		scanf("%lld", &A[i]);
	}
	sort(A.begin(), A.end(), greater<int>());
	for(i = 0; i < Y; i++){
		scanf("%lld", &B[i]);
	}
	sort(B.begin(), B.end(), greater<int>());
	for(i = 0; i < Z; i++){
		scanf("%lld", &C[i]);
	}
	sort(C.begin(), C.end(), greater<int>());
/*	priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, function<bool(tuple<int, int, int>, tuple<int, int, int>)>> pq(
		[&](tuple<int, int, int> a, tuple<int, int, int> b){
			int a0, a1, a2;
			tie(a0, a1, a2) = a;
			int b0, b1, b2;
			tie(b0, b1, b2) = b;
			return A[a0] + B[a1] + C[a2] < A[b0] + B[b1] + C[b2];
	});
*/	
	const auto comp = [&](tuple<int, int, int> a, tuple<int, int, int> b){
/*		int a0, a1, a2;
		tie(a0, a1, a2) = a;
		int b0, b1, b2;
		tie(b0, b1, b2) = b;
		return A[a0] + B[a1] + C[a2] < A[b0] + B[b1] + C[b2];
*/		return A[get<0>(a)] + B[get<1>(a)] + C[get<2>(a)] < A[get<0>(b)] + B[get<1>(b)] + C[get<2>(b)];
	};
	priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, decltype(comp)> pq(comp);
	set<tuple<int, int, int>> s;
	pq.push(make_tuple(0, 0, 0));
	while(K > 0){
		i = get<0>(pq.top());
		j = get<1>(pq.top());
		k = get<2>(pq.top());
		pq.pop();
		if(i == X || j == Y || k == Z || s.count(make_tuple(i, j, k)) == 1){
			continue;
		}
		printf("%lld\n", A[i] + B[j] + C[k]);
		K--;
		s.insert(make_tuple(i, j, k));
		pq.push(make_tuple(i + 1, j, k));
		pq.push(make_tuple(i, j + 1, k));
		pq.push(make_tuple(i, j, k + 1));
	}
	return 0;
}

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

int main() {
  int64_t N,M;
  cin>>N>>M;
  int64_t v=0;
  vector<int64_t> A(N);
  vector<vector<int>> X(M,vector<int>(2));
  for(int64_t i=0;i<N;i++)
    cin>>A[i];
  sort(A.begin(),A.end());
  for(int64_t i=0;i<M;i++){
    cin>>X[i][1]>>X[i][0];
    v+=X[i][1];
  }
  sort(X.begin(),X.end());
  reverse(X.begin(),X.end());
  v=min(v,N);
  vector<int64_t> D;
  for(int i=0;i<N;i++){
    if(D.size()==v)
        break;
    for(int j=0;j<X[i][1];j++){
      D.push_back(X[i][0]);
      if(D.size()==v)
        break;
    }
  }
  /*for(int i=0;i<v;i++)
    cout<<D[i];*/
  int64_t answer=0;
  for(int i=0;i<N;i++){
    if(i<v)
      answer+=max(A[i],D[i]);
    else
      answer+=A[i];
  }
  cout<<answer; 
}

Measured memory_bytes: 7672
#include <stdio.h>
#include <string.h>

int main(void)
{
	int i;
	char str[1000];
	int len;
	
	
	gets(str);
	
	len = strlen(str);
	
	i = 0;
	for (i = 0; i < len; i++){
		if (str[i] >= 'a' && str[i] <= 'z'){
			str[i] -= 0x20;
		}
	}
	
	printf("%s\n", str);
	
	return (0);
}

Measured memory_bytes: 524
N, K = map(int, input().split())
h = [int(i) for i in input().split()]

INF = float('inf')
dp = [INF] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, N):
    tmp = INF
    step = max(0, i-K)
    for j in range(step, i):
        tmp = min(tmp, dp[j] + abs(h[i] - h[j]))
    dp[i] = tmp

print(dp[N-1])


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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

const db PI = 3.14159265359;

int main()
{
  fastio;
  int R; cin >> R;
  cout << fixed << setprecision(3) << 1.00 * 2 * R * PI;
  return 0;
}

Measured memory_bytes: 3808
H, W = gets.split.map( &:to_i )
Board = Array.new( H ) do
	gets.strip
end

def painted( y, x )
	if !( 0 <= y && y < H && 0 <= x && x < W ) then
		return false
	end

	return Board[y][x] == '#'
end

dy = [ 0, 1, 0, -1 ]
dx = [ 1, 0, -1, 0 ]

H.times do |i|
	W.times do |j|
		if Board[i][j] == '.' then
			next
		end

		ok = false
		4.times do |d|
			ok = ok || painted( i + dy[d], j + dx[d] )
		end

		if !ok then
			puts "No"
			exit 0
		end
	end
end

puts "Yes"

Measured memory_bytes: 3836
#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
 
#define endl '\n'
#define loop(i, m, n) for (lli i = m; i < n; i++)
#define loope(i, m, n) for (lli i = m; i <= n; i++)
#define epool(i, m, n) for (lli i = m; i >= n; i--)
#define maxe *max_element
#define mine *min_element
#define mod 1000000007
#define mod2 998244353
#define vt vector<lli>
#define fi first
#define se second
#define pb push_back
#define umap unordered_map
#define mmap multimap
#define MP make_pair
#define empf emplace_front
#define empb emplace_back
#define ret(x) return cout << x, 0;
#define all(v) v.begin(),v.end()

#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
using namespace std;
 
lli gcd(lli a, lli b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
 
lli lcm(lli a, lli b){
    return (a * b) / gcd(a, b);
}
 
lli modi( lli n, lli m=mod ){ 
    n%=m;
    n+=m;
    n%=m;
    return n;
}

lli mpow(lli base, lli exp){
    base %= mod;
    lli result = 1;
    while (exp > 0){
        if (exp & 1)
            result = ((lli)result * base) % mod;
        base = ((lli)base * base) % mod;
        exp >>= 1;
    }
    return result;
}

const lli MIN=-1*1e18;
const lli INF=1e18+999999999999999999;
const lli N=2e5+5;
const ldb pi=4*atan(1);

int32_t main(){
    fast_io
    lli i = 0,j = 0;
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //cout << fixed << setprecision(22);
    
    lli n,m,x;
    cin >> n >> m >> x;
    lli c[n],arr[n][m];
    loop(i,0,n){
        cin >> c[i];
        loop(j,0,m){
            cin >> arr[i][j];
        }
    }
    lli ans=12e5+1;
    loop(i,0,1<<n){
        lli cur=0;
        lli t[m]={0};
        bool fl=1;
        loop(j,0,n){
            if((i&(1<<j))){
                //cout << j << " ";
                cur+=c[j];
                //cout << cur << " ";
                loop(k,0,m){
                    t[k]+=arr[j][k];
                }
            }
        }
        loop(k,0,m){
            if(t[k]<x) fl=0;
        }
        if(fl) ans=min(ans,cur);
        //cout << ans << endl;
    }

    if(ans==12e5+1) cout << -1 << endl;
    else cout << ans << endl;

}



Measured memory_bytes: 3688
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; i++)
#define RREP(i, n) for (int i = n; 0 <= i; i--)
#define FOR(i, start, end) for (int i = start; i < end; i++)
#define FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define RFOR(i, start, end) for (int i = start; end <= i; i--)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

class UnionFind {
  public:
    // 親の番号を格納する。親の場合 -1 になる
    vector<int> Parent;

    // 宣言されたとき Parent の値はすべて -1 にする
    UnionFind(int N) { Parent = vector<int>(N, -1); }

    // 与えられた値 x がどの親であるか調べる
    int root(int x) {
        // x が親だったとき
        if (Parent[x] < 0)
            return x;
        // 辺の縮約をいっしょにおこなう
        return Parent[x] = root(Parent[x]);
    }

    // 木の全体の数を返す
    int size(int x) {
        // マイナスがついているのは root
        // 以下の数をマイナスの値で管理しているから
        return -Parent[root(x)];
    }

    // 2つの引数を同じ親にする
    bool merge(int x, int y) {
        x = root(x);
        y = root(y);

        // 同じ親の場合くっつけない
        if (x == y)
            return false;

        // x のほうが必ず大きな size にしたい
        if (size(x) < size(y))
            swap(x, y);
        Parent[x] += Parent[y];
        Parent[y] = x;
        return true;
    }
};

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

    int N, M;
    cin >> N >> M;
    vector<int> A(M), B(M);
    REP(i, M) cin >> A[i] >> B[i];

    UnionFind uni(N + 1);
    vector<ll> ans(M);
    ans[M - 1] = (ll)N * (N - 1) / 2;

    RFOR(i, M - 1, 1) {
        ans[i - 1] = ans[i];
        if (uni.root(A[i]) != uni.root(B[i])) {
            ans[i - 1] -= (ll)uni.size(A[i]) * uni.size(B[i]);
            uni.merge(A[i], B[i]);
        }
    }

    REP(i, M) cout << ans[i] << '\n';

    return 0;
}

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

namespace AtCoderBeginnerContest148
{
	class Program
	{
		static void Main(string[] args)
		{
			var number = int.Parse(Console.ReadLine());
			var input = Console.ReadLine();

			var inputs = input.Split(' ');
			var now = 0;
			for (var i = 0; i < inputs.Length; i++)
			{
				if (int.Parse(inputs[i]) == now + 1)
				{
					now++;
				}
			}

			if (now == 0)
			{
				Console.WriteLine("-1");
			}
			else
			{
				Console.WriteLine(inputs.Length - now);
			}
		}
	}
}


Measured memory_bytes: 32348
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,W;
	cin>>n>>W;
	long long int K[n+1][W+1];
	long long int val[n+1];
	long long int wt[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>wt[i]>>val[i];
	}
	for(int i=0;i<=W;i++)
	{
		K[0][i]=0;
	}
	for(int i=0;i<=n;i++)
	{
		K[i][0]=0;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=W;j++)
		{
			if(wt[i]>j)
			K[i][j]=K[i-1][j];
			else
			K[i][j]=max(K[i-1][j],val[i]+K[i-1][j-wt[i]]);
		}
	}
	cout<<K[n][W];
	return 0;
}

Measured memory_bytes: 79104
#include <stdio.h>
int main(void){
    // Your code here!
    int a;
    int b;
    int c;
    scanf("%d %d %d",&a,&b,&c);
    if(a+b<c)
    {
    printf("No");   
    }
    else{printf("Yes");}
    
    
    
    
}


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

using namespace std;

int main(void){
  string S, T;
  cin >> S >> T;
  vector<bool> B(26, false);
  for(char c : S) B[c - 'a'] = true;
  int cnt = 0;
  for(bool b : B) if(b) cnt++;
  map<char, char> m;
  for(int i = 0; i < S.length(); i++){
    if(m[S[i]] == 0) m[S[i]] = T[i];
    else if(m[S[i]] != T[i]){
      cout << "No" << endl;
       return 0;
    }
  }
  vector<bool> B2(26, false);
  for(auto p : m) B2[p.second - 'a'] = true;
  int cnt2 = 0;
  for(bool b : B2) if(b) cnt2++;
  if(cnt2 != cnt){
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  return 0;
}


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

int main()
{
    int N, T;
    cin >> N >> T;
    vector<int> t(N);
    REP (i, N) {
        cin >> t[i];
    }
    long long ans = 0;

    REP (i, N - 1) {
        ans += min(T, t[i + 1] - t[i]);
    }
    ans += T;
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
    int ii1 = 0;
    char s[100];
    scanf("%s", s);
    int n = strlen(s);
    int p = n-1;
    while(ii1 <= p){
        if(s[ii1] != s[p]){
            printf("No");
            return 0;
        }
        ii1++;
        p--;
    }
    ii1 = 0;
    p=(n - 1)/2-1;
    while(ii1 <= p){
        if(s[ii1] != s[p]){
            printf("No");
            return 0;
        }
        ii1++;
        p--;
    }
    ii1 = (n+3)/2-1;
    p = n-1;
    while(ii1 <= p){
        if(s[ii1] != s[p]){
            printf("No");
            return 0;
        }
        ii1++;
        p--;
    }

    printf("Yes");
    return 0;
}


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

map<int,vector<int>> g;

int dp[100001];


int dfs( int src){


    if(dp[src]!=-1){
        return dp[src];
    }

    int ans=0;
    int leaf=1;

    for( int i: g[src]){
        leaf=0;
        ans=max(ans,1+dfs(i));

    }


    return dp[src]=leaf==1?0:ans;

}



int longestPath(int n){

    int ans=0;

    for(int i=1;i<=n;i++){
        ans=max(ans,dfs(i));
    }

    return ans;

}


int main() {
    int n,m;
    cin>>n>>m;
    for(int i=0;i<m;i++){

        int x,y;
        cin>>x>>y;
        g[x].push_back(y);

    }
    memset(dp,-1,sizeof(dp));


    cout<<longestPath(n);


}


Measured memory_bytes: 18968
from queue import Queue
from collections import defaultdict
n, k = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= 1
s = [0] * (n+1)
for i in range(n):
    s[i+1] = (s[i]+a[i])%k

d = defaultdict(int)
ans = 0
q = Queue()

for j in range(n+1):
    ans += d[s[j]]
    d[s[j]] += 1
    q.put(s[j])
    if q.qsize() == k:
        d[q.get()] -= 1

print(ans)


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

int main() {
  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;
  int a = 60 * h1 + m1;
  int b = h2 * 60 + m2;
  int ans = b - a - k;
  cout << ans << endl;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#define N 202
using namespace std;
const int Mod = 1e9 + 7;

inline int gcd(int x, int y) {
    return !y ? x : gcd(y, x % y);
}

inline int fsp(int x, int k = Mod - 2) {
    int res = 1;
    while (k) {
        if (k & 1) res = 1ll * res * x % Mod;
        x = 1ll *  x * x % Mod, k >>= 1;
    }
    return res;
}

int n, m, K, tim, dfn[N], f[N], low[N], ex[N], ey[N], vis[N], c[N][N];
int tot = 1, fir[N], nxt[N << 1], to[N << 1];
int cnt, num[N], stk[N], top;
vector<int> bcc[N];

inline int get(int x) {
    if (~f[x]) return f[x];
    f[x] = 0;
    for (int i = 1; i <= x; ++i)
        f[x] = (f[x] + fsp(K, gcd(i, x))) % Mod;
    return f[x] = 1ll * f[x] * fsp(x) % Mod;
}

inline void addE(int u, int v) {
    nxt[++tot] = fir[u], fir[u] = tot, to[tot] = v;
}

void Tarjan(int u, int e) {
    dfn[u] = low[u] = ++tim;
    for (int i = fir[u], v; i; i = nxt[i]) {
        if (i / 2 == e) continue;
        v = to[i];
        if (!dfn[v]) {
            stk[++top] = i / 2;
            Tarjan(v, i / 2);
            low[u] = min(low[u], low[v]);
            if (low[v] >= dfn[u]) {
                stk[top + 1] = 0, ++cnt;
                while (stk[top + 1] != i / 2)
                    bcc[cnt].push_back(stk[top--]);
            }
        } else if (dfn[v] < dfn[u]) low[u] = min(low[u], dfn[v]), stk[++top] = i / 2;
    }
}

int main() {
#ifdef isLOCAL
    freopen("graph.in", "r", stdin);
    freopen("graph.out", "w", stdout);
#endif
    
    for (int i = 0; i <= 200; ++i)
        for (int j = c[i][0] = 1; j <= i; ++j)
            c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % Mod;

    cin >> n >> m >> K;

    for (int i = 1, u, v; i <= m; ++i)
        scanf("%d%d", &u, &v),
        ex[i] = u, ey[i] = v,
        addE(u, v), addE(v, u);

    for (int i = 1; i <= n; ++i)
        if (!dfn[i]) Tarjan(i, 0);

    memset(f, -1, sizeof f);

    long long ans = 1;
    for (int i = 1; i <= cnt; ++i) {
        int dot = 0, sz = bcc[i].size();
        for (int j = 0, u, v; j < sz; ++j) {
            u = ex[bcc[i][j]], v = ey[bcc[i][j]];
            if (vis[u] != i) ++dot, vis[u] = i;
            if (vis[v] != i) ++dot, vis[v] = i;
        }
        if (dot > sz) ans = ans * K % Mod;
        if (dot == sz) ans = ans * get(sz) % Mod;
        if (dot < sz) ans = ans * c[sz + K - 1][K - 1] % Mod;
    }

    cout << ans << endl;

    return 0;
}


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

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
const double PI = acos(-1.0);

void header() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

int k;

void bfs() {
    queue<ll> q;
    vector<ll> v;
    for (int i = 1; i <= 9; i++) q.push(i);
    ll x, y, z;
    v.pb(0);
    while (!q.empty()) {
        x = q.front();
        q.pop();
        if (x >= (1ll << 32)) continue;
        v.pb(x);
        y = x * 10, z = x % 10;
        if (!z) q.push(y), q.push(y + 1);
        else if (0 < z && z < 9) q.push(y + z), q.push(y + z - 1), q.push(y + z + 1);
        else q.push(y + 9), q.push(y + 8);
    }
    sort(v.begin(), v.end());
    cout << v[k] <<endl;
}


void solve() {
    cin >> k;
    bfs();
}

int main() {
	header();
	solve();
	return 0;
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()

int main()
{
    int i,j;
    int h,w;
    cin >> h >> w;
    int ch, dh, cw, dw;
    cin >> ch >> cw >> dh >> dw;
    --ch, --cw, --dh, --dw;
    vector<string> s(h);
    rep(i,h) cin >> s.at(i);

    int INF = (1 << 30);

    vector<vector<int>> dp(h,vector<int>(w,INF));
    priority_queue<pair<int,pair<int,int>>> pq;

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

    pair<int,int> top = make_pair(ch, cw); //開始点
    dp.at(ch).at(cw) = 0;
    pq.emplace(0, top);
    while(!pq.empty()){
        auto x = pq.top();
        pq.pop();
        int nx = x.second.first;
        int ny = x.second.second;
        int dist = -x.first;
        if(dp.at(nx).at(ny) < dist) continue;

        rep(i,4){
            int x = nx + dx[i];
            int y = ny + dy[i];
            if(x < 0 || x >= h || y < 0 || y >= w) continue;
            if(s.at(x).at(y) == '#') continue;
            if(dp.at(x).at(y) > dist){
                dp.at(x).at(y) = dist;
                pq.emplace(-dist, make_pair(x, y));
            }
        }

        int nd = dist + 1;
        for(i = -2;i < 3;++i){
            for(j = -2;j < 3;++j){
                int x = nx + i;
                int y = ny + j;
                if(x < 0 || x >= h || y < 0 || y >= w) continue;
                if(s.at(x).at(y) == '#') continue;
                if(dp.at(x).at(y) > nd){
                    dp.at(x).at(y) = nd;
                    pq.emplace(-nd, make_pair(x, y));
                }
            }
        }
    }
    if(dp.at(dh).at(dw) == INF) cout << -1 << endl;
    else cout << dp.at(dh).at(dw) << endl;

    return 0;
}

Measured memory_bytes: 9624
n,m = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(n)]
ls.sort(key=lambda x: x[0])
drink = 0
ans = 0
for i in range(n):
    if drink + ls[i][1] < m:
        ans += ls[i][0]*ls[i][1]
        drink += ls[i][1]
    else:
        ans += ls[i][0]*(m-drink)
        print(ans)
        break

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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()
#define endl        "\n"
#define repp(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a,b) 	for(int i=a;i<=b;i++)
#define IOS         ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);

const int N=1e5 + 5;

int32_t main()
{
	IOS;
	int n;
	cin >> n;
	cout << pow(n,3) << endl;
}


Measured memory_bytes: 512
from itertools import product
h, w = list(map(int,input().split()))
canvas = [list(input()) for i in range(h)]

cross = [[1,0],[0,1],[-1,0],[0,-1]]
flag = True
for i, j in product(range(h), range(w)):
    if canvas[i][j] == ".":
        continue
    flag_tmp = False
    for di, dj in cross:
        if 0<= i + di < h and 0 <= j + dj < w:
            if canvas[i+di][j+dj] == "#":
                flag_tmp = True
    if not flag_tmp:
        flag = False
        break
if flag:
    print("Yes")
else:
    print("No")

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

typedef long long ll;

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

int main() {
  ll N, X;
  cin >> N >> X;
  ll g = gcd(N, X);
  ll M = N/g;
  cout << g * (M-1) * 3 << endl;
}


Measured memory_bytes: 256
main = do
    line<-getLine
    let p = read line ::Int
    print $ sum_ $ filter nr3n5 [1..p]

nr3n5 :: Int -> Bool
nr3n5 x
    | (mod x 3)==0 = False
    | (mod x 5)==0 = False
    | otherwise = True

sum_ :: [Int] ->Integer
sum_ [] = 0
sum_ (x:xs) = (fromIntegral x) + sum_ xs

Measured memory_bytes: 13532
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1<<30;

int main(){
  int n, x;cin>>n>>x;
  int ans=1, d=0;
  for(int i=0;i<n;i++){
  	int l;cin>>l;
    d+=l;
    if(d<=x)ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
n = int(input())
line = input().split()
a = int(line[0])
b = int(line[1])
line = input().split()
p = []
for i in range(n):
    p.append(int(line[i]))

c1 = 0
c2 = 0
c3 = 0

for i in p:
    if (i <= a):
        c1 += 1
    elif ((i >= a + 1) and (i <= b)):
        c2 += 1
    elif (i >= b +1):
        c3 += 1

print(min(c1,c2,c3))


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <map>
 
using namespace std;

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

    int order[5];

    cin >> order[0] >> order[1] >> order[2] >> order[3] >> order[4];

    int last = 4;
    int count = 0;
    int plus = 0;

    for(int i = 0; i < 4; i++) 
    {
        if((order[i] - 1) % 10 < (order[last] - 1) % 10)
        {
            last = i;
        }
    }

    for(int i = 0; i < 5; i++)
    {
        if(i != last)
        {
            if(order[i] % 10 != 0)
            {
                plus = 10 - order[i] % 10;
            }
            count += order[i] + plus;
            plus = 0;
        }
    }

    count += order[last];

    cout << count;
}

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


int main() {
  int N, M, X; cin >> N >> M >> X;
  vector<int> A(M);
  int c1 = 0;
  int c2 = 0;

  for(int i=0; i<M; i++){
    cin >> A[i];
    if(X < A[i]) c1++;
    else c2++;
  }

  cout << min(c1, c2) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
 
int i,n,loc,left,right;
char logg[2000],order[60];
 
int main(){
    for(scanf("%d",&n);n>0;n--){
        scanf("%s",logg);
        loc=30;left=30;right=30;
        order[30]=logg[0];
        for(i=1;i<(signed)strlen(logg);i+=3){
            if(logg[i]=='<'){
                if(loc==left)left--;
                loc--;
            }
            else{
                if(loc==right)right++;
                loc++;
            }
            order[loc]=logg[i+2];
        }
        for(i=left;i<=right;i++){printf("%c",order[i]);}
        printf("\n");
    }
 
    return 0;
}

Measured memory_bytes: 572
h,w,d=map(int,input().split())
nums=[[0 for s in range(w)] for i in range(h)]
gya=[[0,0] for i in range(h*w)]
for i in range(h):
    nums[i]=list(map(int,input().split()))
    for j in range(w):
        gya[nums[i][j]-1]=[i,j]
cost=[0]*(h*w+d)
for i in range(d):
    s=i
    while s<h*w-d:
        cost[s+d]=cost[s]+abs(gya[s+d][0]-gya[s][0])+abs(gya[s+d][1]-gya[s][1])
        s+=d
q=int(input())
for i in range(q):
    l,r=map(int,input().split())
    print(cost[r-1]-cost[l-1])


Measured memory_bytes: 71676
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
def unite(x, y):
    p = find(x)
    q = find(y)
    if p == q:
        return None
    if p > q:
        p, q = q, p
    par[p] += par[q]
    par[q] = p
def same(x, y):
    return find(x) == find(y)
def size(x):
    return -par[find(x)]
n, m = map(int, input().split())
par = [-1 for i in range(n)]
p = list(map(int, input().split()))
for i in range(m):
    x, y = map(int, input().split())
    unite(x - 1, y - 1)
ans = 0
for i in range(n):
    if same(p[i] - 1, i):
        ans += 1
print(ans)

Measured memory_bytes: 21212
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int ans=200;
		int[] w=new int[n];
		int sum=0;
		for(int i=0; i<n; i++){
			w[i] = sc.nextInt();
			sum+=w[i];
		}
		int pp=0;
		for(int i=0; i<n; i++){
			pp+=w[i];
			ans=Math.min(ans,Math.abs((sum-pp)-pp));
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a>=b and a>=c){
    cout<<b*c/2<<endl;
  }
  else if(b>c and b>a){
    cout<<a*c/2<<endl;
  }
  else
    cout<<a*b/2<<endl;
}


Measured memory_bytes: 256
K = int(input())
if K % 2 == 0 or K % 5 == 0:
  print(-1)
  exit()
i, ai = 0, 0
while True:
  ai = (ai * 10 + 7) % K
  i += 1
  if ai == 0:
    print(i)
    exit()

Measured memory_bytes: 9120
#include <iostream>
#include <iomanip>
#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 <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    int n; cin>>n;
    vector<int> b;
    for(int i=0; i<n; i++){
        int x; cin>>x;
        b.eb(x);
    }

    vector<int> ans;
    for(int i=n-1; i>=0; i--){
        for(int j=b.size()-1; j>=0; j--){
            if(b[j] == j + 1){
                ans.eb(b[j]);
                b.erase(b.begin() + j);
                break;
            }
        }
    }

    if(ans.size() != n){
        cout << -1 << endl;
    }
    else{
        for(int i=n-1; i>=0; i--){
            cout << ans[i] << endl;
        }
    }
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int x,y,k1,k2;
    scanf("%d %d",&x,&y);
    k2=(y-2*x)/2;
    k1=(4*x-y)/2;
    int z;
    z=2*k1+4*k2;
    if(z==y&&k1>=0&&k2>=0)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
}


Measured memory_bytes: 1728
#include <bits/stdc++.h>
#define FLASH ios_base::sync_with_stdio(0);
#define ll long long
#define debt(x,y)cout<<"#x = "<<(x)<<" and "<<"#y = "<<(y)<<endl;
#define deb(x)cout<<"#x = "<<(x)<<endl;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define endl "\n"
#define arr(a,n) for(ll i=1;i<=n;i++) cout<<a[i]<<" "; cout << "\n";
#define vecc(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<" "; cout << "\n";


using namespace std;

ll n;
ll massiv[200010];
ll xxor=0;

int main(){
FLASH;
cin>>n;
for(ll i=1;i<=n;i++){cin>>massiv[i];xxor=(xxor^massiv[i]);}
for(ll i=1;i<=n;i++)cout<<(xxor^massiv[i])<<" ";
cout<<endl;





return 0;
} 


Measured memory_bytes: 5104
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 10007;
const ld PI = acosl(-1);

ll conv(string &s) {
    ll res = 0, p = 1;
    int N = s.length();
    reverse(s.begin(), s.end());

    while (!s.empty() && s.back() != '.') {
        res *= 10;
        res += (s.back() - '0');
        s.pop_back();
    }

    ll res2 = 0;
    if (!s.empty() && s.back() == '.')
        s.pop_back();
    reverse(s.begin(), s.end());
    for (int i = 8; i >= 0; --i) {
        if (i < s.length())
            res2 += (s[i] - '0') * p;
        p *= 10;
        res *= 10;
    }

    return res + res2;
}

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

    int N;
    cin >> N;
    vector<int> cnt2(N), cnt5(N);
    for (int i = 0; i < N; ++i) {
        string s;
        cin >> s;
        ll tmp = conv(s);
        while (tmp % 2 == 0)
            cnt2[i]++, tmp /= 2;
        while (tmp % 5 == 0)
            cnt5[i]++, tmp /= 5;
    }

    ll ans = 0;
    static int ccnt[20][20];
    for (int i = 0; i < N; ++i) {
        int a = min(cnt2[i], 18), b = min(cnt5[i], 18);
        for (int j = 18 - a; j <= 18; ++j) {
            for (int k = 18 - b; k <= 18; ++k) {
                ans += ccnt[j][k];
            }
        }
        ccnt[a][b]++;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4676
#include <stdio.h>

#define MAX 10000

int main(){
  int n,q,i,j,S[MAX],T,res = 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",&T);
    for(j = 0 ; j < n ; j++){
      if(T == S[j]){
        ++res;
        break;
      }
    }
  }
  printf("%d\n",res);
  return 0;
}


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

int main(){
    int n, k, in0, in1;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, n) a.at(i) = 0;
    rep(i, k){
        cin >> in0;
        rep(j, in0){
            cin >> in1;
            a.at(in1-1) = 1;
        }
    }
    int ans = 0;
    rep(i, n) if(a.at(i) == 0) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3636
import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeSet;

public class Main implements Runnable {

    private static int MOD = 1_000_000_007;

    public static void main(String[] args) {
        // Run with 32MB stack
        Thread thread = new Thread(null, new Main(), "", 32 * 1024 * 1024);
        thread.start();
    }

    @Override
    public void run() {
        final Scanner scanner = new Scanner(System.in);
        solve(scanner);
    }

    static void solve(Scanner scanner) {
        int N = Integer.parseInt(scanner.next());
        int[] h = new int[N];
        for (int i = 0; i < N; i++) {
            h[i] = Integer.parseInt(scanner.next());
        }
        int[] dp = new int[N];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
        for (int i = 0; i < N; i++) {
            if (i + 1 < N)
                dp[i + 1] = Math.min(dp[i + 1], dp[i] + Math.abs(h[i + 1] - h[i]));
            if (i + 2 < N)
                dp[i + 2] = Math.min(dp[i + 2], dp[i] + Math.abs(h[i + 2] - h[i]));
        }

        System.out.println(dp[N - 1]);
    }

}



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

int main(){
  ll n, m;
  cin >> n >> m;
  vector<ll> l(m+1);
  vector<ll> r(m+1);
  for(int i=1; i<=m; i++){
  	cin >> l[i] >> r[i];
  }
  
  ll lmax = 1;
  ll rmin = 1e5;
  for(ll i=1; i<=m; i++){
    if(l[i] > lmax) lmax = l[i];
    if(r[i] < rmin) rmin = r[i];
    //cerr << lmax << " " << rmin << endl;
  }
  
  //cerr << lmax << " " << rmin << endl;
  rmin = min(rmin, n);
  ll ans = max((ll)0, rmin-lmax+1);
  cout << ans << endl;
}

Measured memory_bytes: 1792
N = int(input())
A = []
for i in range(N):
        A.append(int(input()))
m = max(A)
n = A.index(m)
A.remove(m)
m1 = max(A)
for i in range(n):
        print(m)
print(m1)
for i in range(N-1-n):
        print(m)

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define pb push_back
#define all(v) (v).begin(), (v).end()

typedef long long ll;

template <class T = int>
T in() { T x; cin >> x; return x; }
#define output(e) cout << e << '\n'

#ifdef LOCAL
    #define dr(x) cout << "L" << __LINE__ << ": " << #x << " -> " << x << "\n"
#else
    #define dr(x)
#endif

//
// Implementation
//

int main() {
  string a = in<string>();
  string b = in<string>();
  string c = in<string>();
  if (a[a.size()-1] == b[0] && b[b.size()-1] == c[0]) {
    output("YES");
  } else {
    output("NO");
  }
}


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

const int S = 100010;
int N, T;
int imos[S];
int main() {
    cin >> N >> T;
    for(int i=0; i<N; i++) {
        int l, r; cin >> l >> r;
        imos[l]++;
        imos[r]--;
    }

    for(int i=1; i<S; i++) {
        imos[i] += imos[i-1];
    }
    cout << *max_element(imos, imos+S) << endl;
    return 0;
}

Measured memory_bytes: 3488
import numpy as np
import itertools
 
N, D = [int(i) for i in input().split()]
X = []
for i in range(N):
    X.append(np.array([int(i) for i in input().split()]))

d = []
for c in itertools.combinations(X, 2):
    d.append(np.linalg.norm(c[1] - c[0]))

print(len([True for x in d if x.is_integer()]))

Measured memory_bytes: 12496
#include <iostream>
#include <stdio.h>
#include <cstdlib>
#include <math.h>

using namespace std;

int main(){

    long long n1, n2, k, x;

    cin >> x >> k;

    n1 = x % k;
    n2 = k - (x % k);

    cout << min(n1, n2);

    return 0;

}

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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll n, a, b;
  cin >> n >> a >> b;
  if ((n == 1 && a != b) || (a > b))
	cout << 0 << endl;
  else
	cout << 1 + (n-2) * (b - a) << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Abc160E
    {
        public static void Main()
        {
            var xyabc = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            var x = xyabc[0];
            var y = xyabc[1];
            var a = xyabc[2];
            var b = xyabc[3];
            var c = xyabc[4];

            var p = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).OrderByDescending(i => i).Take(x);
            var q = Console.ReadLine().Split(' ').Select(s => long.Parse(s)).OrderByDescending(i => i).Take(y);
            var r = Console.ReadLine().Split(' ').Select(s => long.Parse(s));

            long score = r.Concat(p).Concat(q).OrderByDescending(i => i).Take(x + y).Sum();

            Console.WriteLine(score);
        }
    }
}


Measured memory_bytes: 50888
a=int(input());b=int(input());c=int(input());d=int(input());e=int(input());k=int(input())
if b-a>k or c-a>k or d-a>k or e-a>k or c-b>k or d-b>k or e-b>k or d-c>k or e-c>k or e-d>k:
  print(':(')
else:
  print('Yay!')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define forn(i,n) for(int i = 0; i< n;++i)
ll MOD = 1e9 + 7;
ll INF = 1e17 + 9;	


int main(){
	int n;
	cin >> n;
	vector<int> arr(n,0);
	set<int> sarr;
	map<int,int> m;
	forn(i,n){
		cin >> arr[i];
		sarr.insert(arr[i]);
		m[arr[i]] += 1;
	}
	int maxx = 0;
	forn(i,n) maxx = max(maxx, arr[i]);
	sort(arr.begin(),arr.end());
	vector<bool> ans(maxx+1,true);
	int res = 0;
	for(int i = 1; i <= maxx; ++i){
		if(ans[i] == false || sarr.find(i) == sarr.end()){
			continue;
		}
		if(m[i] == 1){
			res += 1;
		}
		for(int j = 2*i; j <= maxx; j += i){
			ans[j] = false;
		}
		//for(int x : ans) cout << x << "  ";
		//cout << endl;
	}
	cout << res << endl;
}
			
			
			
		//for(int j = 0; j < n && ((j < i) || arr[i] == arr[j]); ++j){
			//if(i == j){
				//continue;
			//}
			//if(arr[i] % arr[j] == 0){
				//res  -= 1;
				//break;
			//}
		//}
	//}
	//cout << res << endl;
	

//}


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

int main() {
  int N;
  vector<int> num(300);
  bool num_even = true;
  int counter = 0;

  cin >> N;

  for (int i = 0;i < N;i++){
    cin >> num.at(i);
  }

  while(true){
    for(int i = 0;i < N;i++){
      if(num.at(i) % 2 != 0) {
        num_even = false;
      }
    }
    if(num_even == false)break;
    for(int i = 0;i < N;i++){
      num.at(i) /= 2;
    }
    counter++;
  }

  cout << counter << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 1500;
const int MAX_M = 1500;

/* typedef */

typedef long long ll;
typedef map<int,int> mii;

/* global variables */

int n, m;
int his[MAX_N + 1], wis[MAX_N + 1];
mii hmap;

/* subroutines */

/* main */

int main() {
  for (;;) {
    cin >> n >> m;
    if (n == 0) break;

    his[0] = wis[0] = 0;
    int h, w;
    
    for (int i = 1; i <= n; i++) {
      cin >> h;
      his[i] = his[i - 1] + h;
    }
    for (int i = 1; i <= m; i++) {
      cin >> w;
      wis[i] = wis[i - 1] + w;
    }

    hmap.clear();
    
    for (int i = 1; i <= n; i++)
      for (int j = 0; j < i; j++) {
	h = his[i] - his[j];
	mii::iterator mit = hmap.find(h);
	if (mit == hmap.end())
	  hmap[h] = 1;
	else
	  mit->second++;
      }

    ll count = 0;
    
    for (int i = 1; i <= m; i++)
      for (int j = 0; j < i; j++) {
	w = wis[i] - wis[j];
	mii::iterator mit = hmap.find(w);
	if (mit != hmap.end())
	  count += mit->second;
      }

    cout << count << endl;
  }

  return 0;
}

Measured memory_bytes: 14624