akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void) {

  long n,m;
  scanf("%ld %ld", &n, &m);
  long a[m],b[m],c[m];
  for (long i = 0; i < m; i++) {
    scanf("%ld %ld %ld", &a[i], &b[i], &c[i]);
  }
  long dist[n+1][n+1];
  for (long i = 0; i <= n; i++) {
    for (long j = 0; j <= n; j++) {
      if (i == j) {
        dist[i][j] = 0;
      } else {
        dist[i][j] = -1;
      }
    }
  }
  for (long i = 0; i < m; i++) {
    dist[a[i]][b[i]] = c[i];
    dist[b[i]][a[i]] = c[i];
  }
  int flag;
  while (1) {
    flag = 0;
    for (long i = 1; i <= n; i++) {
      for (long j = 1; j <= n; j++) {
        for (long k = 1; k <= n; k++) {
          if (dist[i][k] == -1 || dist[k][j] == -1) {
            continue;
          }
          if (dist[i][j] == -1 || dist[i][k]+dist[k][j] < dist[i][j]) {
            dist[i][j] = dist[i][k]+dist[k][j];
            dist[j][i] = dist[i][j];
            flag = 1;
          }
        }
      }
    }
    if (flag == 0) {
      break;
    }
  }
  long count = 0;
  for (long i = 0; i < m; i++) {
    flag = 0;
    for (long start = 1; start <= n; start++) {
      if (dist[start][a[i]]+c[i] == dist[start][b[i]]) {
        flag = 1;
        break;
      }
    }
    if (flag == 1) {
      count++;
    }
  }
  printf("%ld\n", m-count);

  return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO.Pipes;

namespace cswork
{
    class Program
    {
        public Program() { }

        Scanner cin;
        const int MAXIN = 1024;
        bool[] used = new bool[MAXIN];
        int[] perm = new int[MAXIN];

        List<int[]> permList = new List<int[]>();

        void Omame()
        {
            cin = new Scanner();
            int n = cin.nextInt();
            List<int> h = new List<int>();
            for (int i = 0; i < n; i++)
            {
                h.Add(cin.nextInt());
            }
            int[] cost = new int[n];
            cost[0] = 0;
            cost[1] = Math.Abs(h[1] - h[0]);

            for (int i = 2; i < n; i++)
            {
                int x = cost[i - 1] + Math.Abs(h[i] - h[i - 1]);
                int y = cost[i - 2] + Math.Abs(h[i] - h[i - 2]);
                cost[i] = Math.Min(x, y);
            }

            Console.WriteLine(cost[n - 1]);
        }


        static void Main(string[] args)
        {
            new Program().Omame();
        }

        public void Permutation(int pos, int n, int length)
        {
            if (pos == n)
            {
                permList.Add((int[])perm.Clone());
            }

            for (int i = 0; i < n; i++)
            {
                if (!used[i])
                {
                    perm[pos] = i;
                    used[i] = true;
                    Permutation(pos + 1, n, length);
                    used[i] = false;
                }
            }
        }
    }

    class Scanner
    {
        string[] s;
        int i;

        char[] cs = new char[] { ' ' };

        public Scanner()
        {
            s = new string[0];
            i = 0;
        }

        public string next()
        {
            if (i < s.Length) return s[i++];
            string st = Console.ReadLine();
            while (st == "") st = Console.ReadLine();

            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next();
        }

        public int nextInt()
        {
            return int.Parse(next());
        }

        public long nextLong()
        {
            return long.Parse(next());
        }

        public double nextDouble()
        {
            return double.Parse(next());
        }
    }
}

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

typedef long long ll;

int main(void)
{
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    double ans = ceil((double)n/1000);
    cout << (int)ans*1000 - n << "\n";

    return 0;
}


Measured memory_bytes: 3632
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<sstream>
#include<queue>
#include<cstdlib>
#include<cmath>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

int cont;
void saiki(double rest,int a, int n, int st, vector<int>& bin){
	
	if(fabs(rest)<0.0000001){cont++; return;}
	if(bin.size()==n)return;
	if(rest<0)return;
	
	int sum = 1;
	rep(i,bin.size())sum*=bin[i];
	
	for(int i=st;;i++){
		if(sum*i<=a){
			bin.push_back(i);
			saiki(rest-1.0/i, a, n, i, bin);
			bin.pop_back();
		}else{
			break;
		}
	}
}

int main(){
	while(1){
		int p,q,a,n;
		cin>>p>>q>>a>>n;
		cont = 0;
		
		if(n==0)break;
		
		vector<int> bin;
		int st = 1;
		double rest = (double)p/q;
		saiki(rest,a,n,st,bin);
		
		printf("%d\n",cont);
	}
}

Measured memory_bytes: 1192
using System;
using System.IO;
using System.Linq;




namespace AtCoder
{
    public class Practice_DP
    {
        static void Main(){
            int n = int.Parse(Console.ReadLine());
            var harray = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            //dp[i] => 足場iへと移動するときの最小コスト
            var dp = new int[n];
            dp[0] = 0;
            dp[1] = Math.Abs(harray[1] - harray[0]);

            for(int i = 2;i < n; i++){
                dp[i] = Math.Min(
                    dp[i-1] + Math.Abs(harray[i-1] - harray[i]),
                    dp[i-2] + Math.Abs(harray[i-2] - harray[i]));
            }
            Console.WriteLine(dp[n - 1]);

        }
    }
}

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

int solve(vector<int>& dp, const vector<vector<int>>& g, int n) {
  if (dp[n] != -1) return dp[n];
  int res = 0;
  for (auto e : g[n]) {
    res = max(res, solve(dp, g, e) + 1);
  }
  return dp[n] = res;
}

int main(void) {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> g(N);
  vector<int> dp(N, -1);
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    g[x - 1].push_back(y - 1);
  }

  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans = max(ans, solve(dp, g, i));
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,a,b) for (int i = (a); i < (b); i++ )

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

const int INF = 100000000;
const double PI=3.14159265358979323846;

int main () {
    string s,t,t_;

    cin >> s;

    rep(i,0,s.size()) {
        if(s[i]!='x') {
            t.push_back(s[i]);
        }
        if(s[s.size()-1-i]!='x') {
            t_.push_back(s[s.size()-1-i]);
        }
    }
    //cout << t << " " << t_  << endl;;
    if (t!=t_) {
        cout << -1 << endl;
    }
    else {
        int l = t.size()+1;
        int cnt = 0;
        t = t_ = {};
        string k1,k2;
        int idx;
        rep(i,0,s.size()) {
            k1.push_back(s[i]);
            //k2.push_back(s[s.size()-1-i]);
            if(s[i]!='x') {
                t.push_back(s[i]);
            }
            if (t.size()==(l/2)) {
                idx = i;
                break;
            }
        }

        rep(i,0,s.size()) {
            k2.push_back(s[s.size()-1-i]);
            if(s[s.size()-1-i]!='x') {
                t_.push_back(s[s.size()-1-i]);
            }
            if (t_.size()==(l/2)) {
                idx = i;
                break;
            }
        }

        //cout << k1 << " " << k2 << endl;
 
        int ans = 0;
        while(k1.size()>=0 && k2.size()>=0) {
            if (k1.size()==0 && k2.size()==0) {
                break;
            }
            if (k1.size()==0) {
                ans+=k2.size();
                k2 = {};
            }
            else if (k2.size()==0) {
                ans+=k1.size();
                k1 = {};
            }
            else if (k1.back()==k2.back()) {
                k1.pop_back();
                k2.pop_back();
            }
            else if (k1.back()!='x') {
                k1.push_back('x');
                ans++;
            }
            else if (k2.back()!='x') {
                k2.push_back('x');
                ans++;
            }

        }        
        cout << ans << endl;
    }
}

Measured memory_bytes: 768
// ref: https://img.atcoder.jp/abc084/editorial.pdf

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef int64_t int64;
typedef uint32_t uint;
typedef uint64_t uint64;
using namespace std;

//---

template <typename T>
inline void print(const T& rhs){ std::cout<<" = "<<rhs<<std::endl; }
template <typename T>
inline void print(const std::vector<T>& rhs){
    std::cout<<" = [ ";
    for(uint i=0; i<rhs.size(); ++i){ std::cout<<rhs[i]<<' '; }
    std::cout<<"]"<<std::endl;
}
template <typename T>
inline void print(const std::vector<std::vector<T>>& rhs){
    std::cout<<" = "<<std::endl;
    std::cout<<"[[ ";
    for(uint p=0; p<rhs.size(); ++p){
        if(p!=0){ std::cout<<" [ "; }
        for(uint q=0; q<rhs[p].size(); ++q){
            std::cout<<rhs[p][q]<<' ';
        }
        if(p!=rhs.size()-1){ std::cout<<"]"<<std::endl; }
    }
    std::cout<<"]]"<<std::endl;
}
template <typename TL, typename TR>
inline void print(const std::vector<std::pair<TR,TL>>& rhs){
    std::cout<<" = [";
    uint i=0;
    for(; i<rhs.size()-1; ++i){ std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"], "; }
    std::cout<<"[f: "<<rhs[i].first<<", s: "<<rhs[i].second<<"]]" << endl;
}
#define printn(var) {printf("%s", #var);print(var);}
#define printn_all(var) {printf("%s(%d): ", __func__, __LINE__);printf("%s", #var);print(var);}

//---

vector<int> gen_primeList(const int size){
    vector<bool> v(size+1, true);
    v[0] = false;
    v[1] = false;
    
    for(int prime=2; prime<=size; ++prime){
        if(!v[prime]){ continue; }
        for(int tmp=2*prime; tmp<=size; tmp+=prime){ v[tmp]=false; }
    }
    
    vector<int> vPrime;
    for(int i=0; i<=size; ++i){
        if(v[i]){ vPrime.push_back(i); }
    }
    return vPrime;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); 
    
    int Q; cin >> Q;
    
    int N=100000;
    vector<int> vPrime = gen_primeList(N);
    
    unordered_map<int,int> ht(vPrime.size());
    for(uint i=0; i<vPrime.size(); ++i){ ht[vPrime[i]]=1; }
    
    vector<int> vSimilar2017;
    for(uint i=0; i<vPrime.size(); ++i){
        if(ht.find((vPrime[i]+1)/2) != ht.end()){ vSimilar2017.push_back(vPrime[i]); }
    }
    
    vector<int> cSum(N+1, 0);
    for(uint i=0; i<vSimilar2017.size(); ++i){
        ++cSum[ vSimilar2017[i] ];
    }
    for(int i=1; i<=N; ++i){ cSum[i] += cSum[i-1]; }
    
    for(int i=0; i<Q; ++i){
        int l, r; cin >> l >> r;
        cout << (cSum[r] - cSum[l-1]) << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1536
n = int(input())

cords = [list(map(int, input().split() )) for _ in range(n)]

cord_dif_dict = {}

for i in range(n):
	for j in range(n):
		if i == j:
			continue

		dif_tuple = (cords[i][0] - cords[j][0], cords[i][1] - cords[j][1])

		if dif_tuple in cord_dif_dict:
			cord_dif_dict[dif_tuple] += 1
		else:
			cord_dif_dict[dif_tuple] = 1

m = 0
for key in cord_dif_dict:
	if cord_dif_dict[key] > m:
		m = cord_dif_dict[key]

print(n - m)
# print(cord_dif_dict)

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef long int li;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<float, float> ff;
typedef pair<double, double> dd;
typedef unsigned int ui;
typedef vector<ii> vii;
typedef vector<ff> vff;
typedef set<int> si;
typedef set<lli> slli;
typedef vector<lli> vlli;
typedef long long ll;
typedef long long ll;
typedef vector<ll> vll;
typedef unsigned long long int ulli;
#define MOD 1000000007
#define INF (unsigned)(~0)>>1
typedef pair<int, ii> iii;
void arr_int(int* given_arr, int n){
  for(int i=0;i<n;i++)
    scanf("%d", &given_arr[i]);
  return;
}
void solve();
int main(int argc, char const *argv[]){
  solve();
  return 0;
}
void solve(){
  int N;
  scanf("%d", &N);
  int M;
  scanf("%d", &M);
  ii q[M];
  for(int i=0;i<M;i++)scanf("%d %d", &q[i].first, &q[i].second);

  int l = 1;
  for(int i=1;i<N;i++)l*=10;

  int t = N>1?l:0;
  for(;t<10*l;t++){
    bool done = true;
    for(int j=0;j<M;j++){
      int si = N -(q[j].first);
      int ci = q[j].second;
      int temp =t;
      while(si){
        temp/=10;
        si--;
      }
      if(temp%10 != ci){
        done = false;
        break;
      }
    }
    if(done){
      printf("%d\n", t);
      return;
    }
  }
  printf("%d\n", -1);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
const int MAXN=300005;
const int MOD=1000000007;
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define DEC(i,a,b) for(int i=(a);i>=(b);i--)
#define fst first
#define snd second
#define pb push_back

const int MAXM=100005;
const int S=409;
inline int read() {
    int x = 0;
    char ch = getchar_unlocked();
    while (ch < '0' || ch > '9') ch = getchar_unlocked();
    while (ch >= '0' && ch <= '9'){
		x = (x << 3) + (x << 1) + ch - '0';
		ch = getchar_unlocked();
	}
    return x;
}

int N,M;
int L[MAXN],R[MAXN];
int ans[MAXN];
int fw[MAXN];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	N=read();
	M=read();
	FOR(i,0,N-1){
		L[i]=read();
		R[i]=read();
		L[i]--;
	}
	FOR(n,0,N-1){
		FOR(d,1,S){
			if (R[n]/d-L[n]/d > 0){
				ans[d]++;
			}
		}
	}
	FOR(n,0,N-1){
		vector<int>v={0};
		int x=R[n]/(S+1);
		int y=L[n]/(S+1);
		while (x>=1 && y>=1){
			if (R[n]/x < L[n]/y) v.pb(R[n]/x--);
			else v.pb(L[n]/y--);
		}
		while (x>=1) v.pb(R[n]/x--);
		while (y>=1) v.pb(L[n]/y--);
		v.pb(INT_MAX/2);
		FOR(i,1,(int)v.size()-1){
			if (R[n]/v[i] - L[n]/v[i] > 0){				
				if (v[i]>0) fw[v[i]]++;
				if (v[i-1]>0) fw[v[i-1]]--;
			}
		}
	}
	DEC(d,M,S+1){
		fw[d]+=fw[d+1];
		ans[d]+=fw[d];
	}
	FOR(d,1,M){
		cout<<ans[d]<<"\n";
	}
}
/*
3 3
1 2
2 3
3 3

7 9
1 7
5 9
5 7
5 9
1 1
6 8
3 4
*/

Measured memory_bytes: 4480
#include <bits/stdc++.h>
#define fi first
#define se second
using ll = long long;
using namespace std;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    int n, k;
    cin >> n >> k;
    string s; cin >> s;
    s.erase(unique(s.begin(), s.end()), s.end());
    int ans = n - s.size();
    int x = (s.size() - 1) / 2;
    if(k <= x) ans += k * 2;
    else {
        ans += x * 2;
        if(s.size() % 2 == 0) ans += 1;
    }

    cout << ans << '\n';
    
}


Measured memory_bytes: 512
#include <stdio.h>
int main(void) {
    int height,width,tile[101][101],i,j;
    char floor[101][101];
    while (1) {
        scanf("%d %d\n",&height,&width);
        if (height==0&&width==0) break;
        for (i=0; i<height; i++) {
            for (j=0; j<width; j++) tile[i][j]=0;
        }
        for (i=0; i<height; i++) scanf("%s",floor[i]);
       i=0,j=0;
        while (floor[i][j]!='.'&&tile[i][j]!=1) {
            tile[i][j]=1;
            if (floor[i][j]=='>') {
                j++;
            } else if (floor[i][j]=='<') {
                j--;
            } else if (floor[i][j]=='^') {
                i--;
            } else {
                i++;
            }
        }
        if (tile[i][j]==0) {
            printf("%d %d\n",j,i);
        } else {
            printf("LOOP\n");
        }
    }
    return 0;
}

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

using namespace std;

#define int long long
#define ALL(x) (x).begin(),(x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

typedef pair<int,int> PI;
typedef pair<int,pair<int,int>> PII;
static const int INF=1010000000000000017LL;
static const double eps=1e-12;
static const double pi=3.14159265358979323846;
static const int dx[4]={1,-1,0,0};
static const int dy[4]={0,0,1,-1};
static const int ddx[8]={1,-1,0,0,1,1,-1,-1};
static const int ddy[8]={0,0,1,-1,1,-1,1,-1};

template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}

const int mod=998244353;

int A,B,C,D;

int dp[3005][3005];

signed main(){
    cin>>A>>B>>C>>D;
    dp[0][0]=1;
    for(int y=0;y<=D-B;++y){
        for(int x=0;x<=C-A;++x){
            if(x>=1)dp[y][x]+=((y+B)*dp[y][x-1])%mod;
            if(y>=1)dp[y][x]+=((x+A)*dp[y-1][x])%mod;
            if(x>=1&&y>=1)dp[y][x]=(dp[y][x]-(x+A-1)*(y+B-1)*dp[y-1][x-1]+mod)%mod;
            dp[y][x]=(dp[y][x]+mod)%mod;
        }
    }
    cout<<dp[D-B][C-A]<<endl;
}

Measured memory_bytes: 73940
n,m = gets.chomp.split.map(&:to_i)
max = 0
count = 0
num = 0
hash = {}
n.times do
  input = gets.chomp.split.map(&:to_i)
  if hash.has_key?(input[0])
    hash[input[0]] += input[1]
  else
    hash[input[0]] = input[1]
  end
#  count += input[1]
#  max = (input[0] > max) ? input[0] : max
#  if count >= m
#
#    puts input[0]
#  end
#  num = input[1]
end

arr = hash.sort_by{|k,v| k}

arr.each do |o|
  count += o[1]
  if count >= m
    puts o[0]
    exit
  end
end

Measured memory_bytes: 10488
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define fi first
#define se second

#define INF 2147483600

int main(){
  int n;
  cin>>n;
  vector<int> vec(n);
  rep(i,n) scanf("%d", &vec[i]);

  int sum=0;
  for(int x:vec) sum += x;
  int y  = round(1. * sum / n);

  int res=0;
  for(int x:vec) res += (x-y)*(x-y);

  cout<<res<<endl;

  return 0;
}


Measured memory_bytes: 512
#include <iostream>
using namespace std; 
typedef long long int ll;
#define rd(t,n) for (int i = 0; i < n; i++)cin>>t[i]
int main() 
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n,m;cin>>n>>m;
	ll t[m];rd(t,m);
	sort(t,t+m);
	ll d[m];d[0]=0;
	for (int i = 1; i < m; i++)d[i]=t[i]-t[i-1];
	sort(d,d+m);
	ll s=0;
	for (int i = 0; i <= m-n; i++)s+=d[i];
	cout<<s; 
}

Measured memory_bytes: 4660
#include <stdio.h>


int main(void) {
    char buf[8][9];
    int i, j;

    for (i = 0; i < 8; i++) {
        gets(buf[i]);
    }

    puts("90");
    for (i = 0; i < 8; i++) {
        for (j = 0; j < 8; j++) {
            putc(buf[7-j][i], stdout);
        }
        puts("");
    }
    puts("180");
    for (i = 0; i < 8; i++) {
        for (j = 0; j < 8; j++) {
            putc(buf[7-i][7-j], stdout);
        }
        puts("");
    }
    puts("270");
    for (i = 0; i < 8; i++) {
        for (j = 0; j < 8; j++) {
            putc(buf[j][7-i], stdout);
        }
        puts("");
    }

    return 0;
}

Measured memory_bytes: 524
#include<iostream>
#include<string>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	string s;
	getline(cin,s);
	rep(i,s.size()-4){
		string str=s.substr(i,5);
		if(str=="apple")s.replace(i,5,"peach");
		else if(str=="peach")s.replace(i,5,"apple");
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
#define int               long long
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll

template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;}
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}

const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;

const int N=0;

vector<int> v[100005];int vis[100005];
void dfs(int z){
	vis[z]=1;
	for(int x:v[z]){
		if(vis[x])continue;
		dfs(x);
	}
}

int h[100005];
void solve(){
	int n,m;
	cin>>n>>m;
	set<int> s;
	rep(i,1,n+1){
		cin>>h[i];
	}
	
	rep(i,0,m){
		int x,y;
		cin>>x>>y;
		v[x].pb(y);
		v[y].pb(x);
	}
	
	rep(i,1,n+1){
		bool f=1;
		for(int x:v[i]){
			if(h[x]>=h[i])f=0;
		}
		if(f)s.insert(i);
	}
	cout<<sz(s);
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#ifdef SEIVE
		seive();
	#endif
	#ifdef NCR
		init();
	#endif
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}


Measured memory_bytes: 13236
#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
#define MP make_pair
#define PB push_back
#define ll long long
#define int long long
#define f(i,x,n) for(int i=x;i<n;i++)
#define ld long double
#define mod 1000000007
int n,m;
int dp[100006];
int tr[100006];
int dfs(int i)
{
	if(dp[i]!=-1)
		return dp[i];
	if(tr[i]==1)
		return dp[i]=0;
	if(i==n)
		return dp[i]=1;
	if(i>n)
		return dp[i]=0;
	return dp[i]=(dfs(i+1)+dfs(i+2))%mod;
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n>>m;
	f(i,0,100006)
		dp[i]=-1;
	f(i,0,m)
	{
		int b;
		cin>>b;
		tr[b]=1;
	}
	cout<<dfs(0)<<endl;
	return 0;
}

Measured memory_bytes: 4864
h={}
f=->l,r{h[[l,r]]||=l>r ? 0:l<2?1+f[2,r]:f[l/2,~-r/2]+f[-~l/2,r/2]+f[-~l/2,~-r/2]}
eval"p f[%d,%d].%%10**9+7"%gets.split

Measured memory_bytes: 3836
#include <stdio.h>
#define VAR_MAX 9

int main(void){
	int a, b, c, N, count=0;
	
	while(~scanf("%d",&N)){
		count=0;
		for(a=0;a<=VAR_MAX;a++){
			for(b=0;b<=VAR_MAX;b++){
				for(c=0;c<=VAR_MAX;c++)
					if(0<=N-a-b-c && N-a-b-c<=VAR_MAX) count++;
			}
		}
		printf("%d\n",count);
	}
	
	return 0;
}

Measured memory_bytes: 0
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author varunvats32
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        APoor solver = new APoor();
        solver.solve(1, in, out);
        out.close();
    }

    static class APoor {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();

            if ((a == b && b != c) || (b == c && c != a) || (c == a && b != a)) {
                out.println("Yes");
                return;
            }

            out.println("No");
        }

    }
}



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

int main(){
  int H, W; cin >> H >> W;
  vector<string> s(H);
  
  string hash(W + 2, '#');
  rep(i, H){
    cin >> s.at(i);
    s.at(i) = "#" + s.at(i) + "#";
  }
  
  cout << hash << endl;
  rep(i, H) cout << s.at(i) << endl;
  cout << hash << endl;
  
}


Measured memory_bytes: 256
n, a, b = map(int,input().split())
cities = list(map(int,input().split()))
ans = 0

for i in range(1, n):
    if (cities[i] - cities[i-1]) * a >= b:
        ans += b
    else:
        ans += (cities[i] - cities[i-1]) * a

print(ans)

Measured memory_bytes: 14252
import java.util.Scanner;

public class Main {
    public static void main(String[] ars) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] a = new int[n];

        int ans = 0;
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        if (n == 2)
            ans = Math.max(a[0], a[1]);
        else {
            int[] L = a.clone();
            for (int i = 1; i < n; i++) {
                L[i] = EuclideanAlgorithm(L[i-1], a[i]);
            }

            int[] R = a.clone();
            for (int i = n-2; i >= 0; i--) {
                R[i] = EuclideanAlgorithm(R[i+1], a[i]);
            }

            ans = Math.max(L[n-2], R[1]);   // 端を消した場合
            for (int i = 1; i < n-1; i++) {
                ans = Math.max(ans, EuclideanAlgorithm(L[i-1], R[i+1]));
            }
        }

        System.out.println(ans);
    }

    public static int EuclideanAlgorithm(int a, int b) {
        int max = Math.max(a, b);
        int min = Math.min(a, b);

        int re = max % min;
        if (re == 0)
            return min;
        return EuclideanAlgorithm(min, re);
    }
}


Measured memory_bytes: 50404
/* while(!cin.eof()) */
 
#include<bits/stdc++.h>
using namespace std; 
#define int long long 
#define mod (int)(1e9+7)
#define MAXI (int)(1e15+100)
#define N 1000500


 
// Driver code to test above functions
int32_t main()
{
    
 
     
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int n;
    cin >> n;
    vector<pair<int, int>>x;
    for(int i=1;i<=n;i++)
    {
        int p;
        cin >> p;
        x.push_back({p, i});
    }
    sort(x.begin(), x.end());
    for(int i=0;i<n;i++)
        cout << x[i].second << " ";

    return 0;
} 

Measured memory_bytes: 2544
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Double A = sc.nextDouble();
		int B = sc.nextInt();
		Double T = sc.nextDouble();
		sc.close();
		int a = (int)((T+0.5)/A);
		System.out.println(a*B);
	}

}

Measured memory_bytes: 37272
<?php
error_reporting(0);
//$N = explode(" ",trim(fgets(STDIN)));
list($A,$B,$K) = explode(" ",trim(fgets(STDIN)));
//$N=trim(fgets(STDIN));

$a = array();
for($i=$A;$i<min($A+$K,$B);$i++) {
  $a[]=$i;
}
for($i=max($B+1-$K,$A);$i<=$B;$i++) {
  $a[]=$i;
}
$sa = array_unique($a);
foreach($sa as $v) {
  printf("%d\n",$v);
}


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

#define ll long long
#define ld long double
#define pb push_back
#define mod 1000000007
#define mk make_pair


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

    ll n,i,q,a,b;
    cin>>n>>q;
    vector<vector<ll>> g(n+1);
    vector<ll> dp(n+1,0);
    for(i=0;i<n-1;i++){
        cin>>a>>b;
        g[a].pb(b);
        g[b].pb(a);
    }
    for(i=0;i<q;i++){
        cin>>a>>b;
        dp[a]+=b;
    }
    stack<ll> s;
    vector<bool> vis(n+1,false);
    s.push(1);
    while(!s.empty()){
        ll t=s.top();
        s.pop();

        if(!vis[t]){
            vis[t]=true;
        }

        for(auto k: g[t]){
            if(!vis[k]){
                s.push(k);
                dp[k]+=dp[t];
            }
        }
    }

    for(i=1;i<=n;i++)
        cout<<dp[i]<<" ";
    return 0;  
}

Measured memory_bytes: 17904
from collections import defaultdict
def solve():
	N,A = map(int,raw_input().split())
	x = map(int,raw_input().split())
	DP = [defaultdict(int) for i in xrange(N+1)]
	DP[0][0] = 1
	for i in xrange(N):
		for k,v in DP[i].iteritems():
			DP[i+1][k+x[i]-A] += v
			DP[i+1][k] += v
	print DP[N][0] - 1
solve()

Measured memory_bytes: 5112
N,K = map(int,input().split())
A = list(map(int,input().split()))
A = sorted(A)

mod = 10**9+7


def p(m,n):
    a = 1
    for i in range(n):
        a = a*(m-i)
    return a

def p_mod(m,n,mod):
    a = 1
    for i in range(n):
        a = a*(m-i) % mod
    return a

def c(m,n):
    return p(m,n) // p(n,n)

def c_mod(m,n,mod):
    return (p_mod(m,n,mod)*pow(p_mod(n,n,mod),mod-2,mod)) % mod

C = [0]*(N-K+1)  #C[i] = (N-i-1)C_(K-1),予め二項係数を計算しておく
for i in range(N-K+1):
    if i == 0:
        C[i] = c_mod(N-1,K-1,mod)
    else:
        C[i] = (C[i-1]*(N-K-i+1)*pow(N-i,mod-2,mod)) % mod

#各Aの元が何回max,minに採用されるかを考える

ans = 0
for i in range(N-K+1):
    ans -= (A[i]*C[i]) % mod

A.reverse()
for i in range(N-K+1):
    ans += (A[i]*C[i]) % mod

print(ans % mod)

Measured memory_bytes: 64168
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
 
signed main()
{
 
    
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int n; cin >> n;
    int a[n]; 
    int all = 0;
    for (int i=0; i<n; i++) {
        cin >> a[i];
        all ^= a[i]; 
    }
    for (int i=0; i<n; i++) {
        a[i] = a[i]^all;
        cout << a[i] << " ";
    }
    
    return 0;
}

Measured memory_bytes: 5108
#include <iostream>
#include <string>
#include <ctype.h>

using namespace std;


int main(void){
  int a, b;
  string str;

  cin >> a >> b >> str;
  int cnt=0;
  bool judge = true;
  for(auto s: str){
    if(cnt == a){
      if(s != '-'){
        judge = false;
      }
    }else{
      if(!isdigit(s)){
        judge = false;
      }
    }
    cnt++;
  }

  if(judge == true){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}

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

using namespace std;

int main(void){
    string s;

    cin >> s;

    int n = s.length();

    for(int i=0; i<n/2; i++){
        if(s[i] != s[n-i-1]){
            cout << "No" << endl;
            return 0;
        }
    }

    for(int i=0; i<(n-1)/2; i++){
        if(s[i] != s[(n-1)/2-i-1]){
            cout << "No" << endl;
            return 0;
        }
    }

    for(int i=((n+3)/2-1); i<n; i++){
        if(s[i] != s[n-i-1]){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    ll H, W, K;
    cin >> H >> W >> K;
    vector<string> c(H);
    rep(i,H){
        cin >> c[i];
    }
    ll count=0;
    for(int i=0; i<(1<<W); i++){
        bitset<6> map_w(i);
        for(int j=0; j<(1<<H); j++){
            vector<string> tmp(H);
            ll tmp_count=0;
            rep(k,H){
                tmp[k]=c[k];
            }
            bitset<6> map_h(j);
            rep(k,W){
                if(map_w.test(k)){
                    rep(l,H){
                        tmp[l][k]='N';
                    }
                }
            }
            rep(k,H){
                if(map_h.test(k)){
                    rep(l,W){
                        tmp[k][l]='N';
                    }
                }
            }
            rep(k,H){
                rep(l,W){
                    if(tmp[k][l]=='#'){
                        tmp_count++;
                    }
                }
            }
            if(tmp_count==K){
                count++;
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 3660
import numpy as np
import bisect
from operator import itemgetter
import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,M = IL()
K = [IL()[1:] for i in range(M)]
p = np.array(IL())

switch = np.array([[0]*M for i in range(N)])
for i in range(M):
    while K[i]:
        num = K[i].pop()
        switch[num-1][i] = 1

ans = 0
for i in range(1 << N):
    cnt = np.array([0]*M)
    for j in range(N):
        if ((i >> j) & 1) == 1:
            cnt += switch[j]
    else:
        if (p == (cnt%2)).all():
            ans += 1
print(ans)

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

int main() {
  int n;
  cin >> n;
  vector<int> ary(n);
  
  for(int i=0; i<n; i++)
    cin >> ary.at(i);
  
  int a=0, b=0;
  
  for(int i=0; i<n; i++){
    int k;
    int max=0;
    for(int j=0; j<n; j++){
      if(ary.at(j) >= max){
        max=ary.at(j);
        k=j;
      }
    }
    a+=max;
    ary.at(k)=0;
    max=0;
    
    for(int j=0; j<n; j++){
      if(ary.at(j) >= max){
        max=ary.at(j);
        k=j;
      }
    }
    b+=max;
    ary.at(k)=0;
  }
  
  cout << a - b << endl;
}
    
      


Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int  a, b;
  cin >> a >> b;
  int ans = 0;

  ans +=max(a*2-1,max(b*2-1,a+b));
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,m,a[100010],ans;
pair<long long,long long> p[100010];
int main(){
	cin>>n>>m;
	for (int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	for (int i=0;i<m;i++) cin>>p[i].second>>p[i].first;
	sort(p,p+m);m--;
	for (int i=0;i<n;i++)
		if (p[m].first>a[i]){
			a[i]=p[m].first;
			p[m].second--;
			if (p[m].second==0) m--;
		}
	for (int i=0;i<n;i++) ans+=a[i];
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

def bisect(lst, isok, ok, ng):
    while(abs(ok-ng)>1):
        mid = (ok+ng)//2
        if isok(lst[mid]):
            ok = mid
        else:
            ng = mid
    return ok

s = []
for i in range(10**5):
    if i%2 == 1 and is_prime(i) and is_prime((i+1)//2):
        s.append(i)

s.sort()

q = int(input())
for k in range(q):
    l, r = map(int, input().split())
    l0 = bisect(s, lambda x:x >= l, len(s), -1)
    r0 = bisect(s, lambda x:x <= r, -1, len(s))
    print(max(0, r0-l0+1))

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

using namespace std;
const int N = 12, M = 1010;
int s[N][M], col[N], cnt[N];

int main()
{
    int n, m, k; cin >> n >> m >> k;
    for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) {char c; cin >> c, s[i][j] = c - '0';}
    int M = 1<<(n-1), ans = n + m - 2;
    for (int mask = 0; mask < M; mask++) {
        int c = 0, res = __builtin_popcount(mask);
        for (int i = 0; i < n; i++) {
            col[i] = c, cnt[c] = 0;
            if ((mask>>i)&1) c++;
        }
        bool flag = 1;
        memset(cnt, 0, sizeof cnt);
        for (int j = 0; j < m; j++) {
            for (int i = 0; i < n; i++) {
                cnt[col[i]] += s[i][j];
                if (cnt[col[i]] > k) {
                    res++;
                    memset(cnt, 0, sizeof cnt);
                    for (int t = 0; t < n; t++) {
                        cnt[col[t]] += s[t][j];
                        if (cnt[col[t]] > k) flag = 0;
                    }
                    break;
                }
            }
        }
        if (flag == 0) continue ;
        ans = min(ans, res);
    }
    cout << ans << "\n";
}


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

#define __ ios::sync_with_stdio(0),  cin.tie(0);
#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'

typedef long long ll;

int main(){__
  int h1, m1; cin >> h1 >> m1;
  int h2, m2; cin >> h2 >> m2;
  int k;  cin >> k;
  cout << (h2-h1)*60 + (m2-m1) - k << endl;
  return 0;
}	

Measured memory_bytes: 3608
import java.util.Arrays;
import java.util.Scanner;

//Autumnal Illumination
public class Main{

	int n;
	int[][][] p;
	
	int cross(int[] s, int[] t, int[] r){
		int x1 = t[0]-s[0], y1 = t[1]-s[1], x2 = r[0]-s[0], y2 = r[1]-s[1];
		return x1*y2-x2*y1;
	}
	boolean online(int[] s, int[] t, int[] r){
		if(cross(s, t, r)!=0)return false;
		int minx = Math.min(s[0], t[0]), maxx = Math.max(s[0], t[0]);
		int miny = Math.min(s[1], t[1]), maxy = Math.max(s[1], t[1]);
		return minx<=r[0]&&r[0]<=maxx&&miny<=r[1]&&r[1]<=maxy;
	}
	boolean isCross(int[] a, int[] b, int[] s, int[] t){
		if(cross(a, b, s)*cross(a, b, t)>=0)return false;
		if(cross(b, a, s)*cross(b, a, t)>=0)return false;
		if(cross(s, t, a)*cross(s, t, b)>=0)return false;
		return cross(t, s, a)*cross(t, s, b)<0;
	}
	
	boolean col(int a, int b){
		for(int i=0;i<4;i++)for(int j=0;j<4;j++){
			if(online(p[a][i], p[a][(i+1)%4], p[b][j]))return true;
//			if(online(p[b][i], p[b][(i+1)%4], p[a][j]))return true;
			if(isCross(p[a][i], p[a][(i+1)%4], p[b][j], p[b][(j+1)%4]))return true;
		}
		for(int j=0;j<4;j++){
			boolean in = true;
			for(int i=0;i<4;i++)if(cross(p[a][i], p[a][(i+1)%4], p[b][j])>=0)in = false;
			if(in)return true;
		}
		return false;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int m = sc.nextInt();
			if(m==0)break;
			while(m--!=0){
				n = sc.nextInt();
				p = new int[n][4][2];
				for(int i=0;i<n;i++)for(int j=0;j<4;j++)for(int k=0;k<2;k++)p[i][j][k]=sc.nextInt();
				UnionFind u = new UnionFind(n);
				for(int i=0;i<n;i++)for(int j=0;j<n;j++){
					if(u.find(i, j))continue;
					if(col(i, j))u.union(i, j);
				}
				System.out.println(u.num);
			}
		}
	}
	
	class UnionFind {
		final int[] tree;
		int num;
		public UnionFind(int n) {
			this.tree = new int[n];
			Arrays.fill(tree, -1);
			num=n;
		}
		void union(int x, int y) {
			x = root(x);
			y = root(y);
			if(x != y) {
				if(tree[x] < tree[y]) {
					x ^= y; y ^= x; x^= y;
				}
				tree[x] += tree[y];
				tree[y] = x;
				num--;
			}
		}
		boolean find(int x, int y) {
			return root(x) == root(y);
		}
		int root(int x) {
			return tree[x] < 0 ? x : (tree[x] = root(tree[x]));
		}
		int size(int x) {
			return -tree[root(x)];
		}
		int getNum() {
			return num;
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,h;

int main(){
  ll ans=999999999;
  cin >> h >> n;
  vi a(n),b(n);
  REP(i,n)
  {
    cin>>a[i]>>b[i];
  }
  vi dp(h+10001,999999999);
  dp[0]=0;

  ll aa;
  REP(i,h){
    if (dp[i]==999999999)continue;
    REP(j,n){
      aa=a[j];
      dp[i+aa]=min(dp[i+aa],dp[i]+b[j]);
    }
  }


  for(int i=h;i<h+10001;i++){
      ans=min(dp[i],ans);
  }
  cout<<(ans)<<endl;
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7;

int main() {
  ll N; cin>>N;
  vector<ll> A(N);
  ll sum = 0;
  ll ans = 0;
  for(int i=0; i<N; ++i) {
    cin>>A[i];
    sum=(sum+A[i])%MOD;
  }
  for(int i=0; i<N; ++i) {
    sum=(sum-A[i]+MOD)%MOD;
    ans=(ans+A[i]*sum)%MOD;
  }
  cout << ans << endl;
}


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

int n, k ;

int num[200010] ;

int main(){
	#define NAME "arc012_c"
	//freopen( NAME".inp" , "r" , stdin ) ; freopen( NAME".out" , "w" , stdout ) ;

	cin >> n >> k ;

	for (int i = 0; i < k; ++ i) {
		if(n % k >= i) num[i] = n / k + 1 ;
		else num[i] = n / k ;
	} 

	num[0] -- ;

	long long ans = 1ll * num[0] * num[0] * num[0] ;

	if(k % 2 == 0) ans += 1ll * num[k / 2] * num[k / 2] * num[k / 2] ;
 	
	cout << ans << endl ;

	return 0 ;
}

Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll N;
  cin>>N;
  ll a[N];
  ll tmptmp;
  for(ll i=0;i<N;++i) {
    cin>>tmptmp;
    tmptmp--;
    a[tmptmp] = i;
  }
  set<ll> st;
  st.insert(-1);
  st.insert(N);
  auto tmp=st.begin(), tmp1=st.begin(), tmp2=st.begin();
  ll ans = 0;
  for(ll i=0;i<N;++i) {
    st.insert(a[i]);
    tmp = st.find(a[i]);
    tmp1 = st.find(a[i]);
    tmp1--;
    tmp2 = st.find(a[i]);
    tmp2++;
    ans += (i+1)*(*tmp-*tmp1)*(*tmp2-*tmp);
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 14516
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 
#define int long long
#define double long double

////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////

bool b[1000];int a[31000][10];
signed main(){
  int n;string s;cin>>n>>s;
  rep(i,n){
    a[i][s[i]-'0']++;
  }
  rep(i,10){
    rep(j,n-1){
      a[j+1][i] += a[j][i];
    }
  }
  repd(i,1,n-1){
    int p = s[i]-'0';
    rep(j,10){
      rep(k,10){
        if(a[i-1][j] > 0 && (a[n-1][k] - a[i][k]) > 0){
          b[j*100+p*10+k] = true;
        }
      }
    }
  }
  int ans = 0;
  rep(i,1000)if(b[i])ans++;
  cout << ans << endl;
}


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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll mod = (ll)1e9 + 7;
const ll mxN = 200200;

void solve() {
	ll n,m;
	cin>>n>>m;
	vll cnt(m,0);
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		for(int j=0;j<x;j++) {
			ll y;cin>>y;y--;
			cnt[y]++;
		}	
	}
	ll ans=0;
	for(int i=0;i<m;i++)
		ans+=(cnt[i]==n);
	cout<<ans;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;

	//ll t;cin>>t;while(t--)
	solve();

}


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

using namespace std;

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

    vector<int> arr(n);
    for(int i=0;i<n;i++) cin>>arr[i];

    int q;
    cin>>q;

    while(q--)
    {
        int key;
        cin>>key;

        cout<<(*lower_bound(arr.begin(),arr.end(),key)==key)<<endl;
    }

    return 0;
}



Measured memory_bytes: 3352
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *

sys.setrecursionlimit(100000000)


def input(): return sys.stdin.readline().rstrip()


N, K, C = map(int, input().split())
S = input()

L = [None] * K
R = [None] * K

i = 0
for j in range(N):
    if S[j] == 'o' and i < K and (i == 0 or j - L[i - 1] > C):
        L[i] = j
        i += 1

i = K - 1
for j in reversed(range(N)):
    if S[j] == 'o' and i >= 0 and (i == K - 1 or R[i + 1] - j > C):
        R[i] = j
        i -= 1

for l, r in zip(L, R):
    if l == r:
        print(l + 1)


Measured memory_bytes: 57420
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int D = sc.nextInt();
		int N = sc.nextInt();
		int ans = 0;
		switch(D) {
		case 0:
			ans = N;
			if(ans % 100 == 0) {
				ans++;
			}
			break;
		case 1:
			ans = 100 * N;
			if(ans % (100 * 100) == 0) {
				ans += 100;
			}
			break;
		case 2:
			ans = 100 * 100 * N;
			if(ans % (100 * 100 * 100) == 0) {
				ans += 100*100;
			}
			break;
		}
		System.out.println(ans);
	}
}

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

#define MOD 1000000007

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


template <class T>
ostream &operator<<(ostream &o, const vector<T>&obj) {
    o << "["; for (int i = 0; i < (int)obj.size(); ++i) o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const vector<vector<T>>&obj) {
    o << "[" << endl; for (int i = 0; i < (int)obj.size(); ++i) o << "  " << obj[i] << endl; o << "]"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const pair<T, U>&obj) {
    o << "(" << obj.first << ", " << obj.second << ")"; return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, const map<T, U>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const set<T>&obj) {
    o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;
}
template <class T>
ostream &operator<<(ostream &o, const queue<T>&obj) {
    queue<T> obj_cp = obj;
    bool first = true;
    o << "{";
    while (!obj_cp.empty()) { o << (!first ? ", " : "") << obj_cp.front(); obj_cp.pop(); first = false; }
    o << "}"; return o;
}

void print() {
    cout << "\n";
}
template<class Head, class... Body>
void print(Head head, Body... body) {
    cout << head << " ";
    print(body...);
}


int main(int argc, char const *argv[]) {
    int X, Y;
    cin >> X >> Y;
    if (Y % 2 == 0 && Y/2-X >= 0 && X*2-Y/2 >= 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    

    return 0;
}


Measured memory_bytes: 3624
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

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

int main(){
    ll n,k;
    cin>>n>>k;
    lvec a(n);
    rep(i,n)cin>>a[i];
    sort(all(a));
    bool ok=false;
    if(a[0]==1)ok=true;
    for(int i=0;i<n;i++){
        if(a[i]==k)ok=true;
    }
    if(!ok&&k<=a[n-1]){
        ll s=gcd(a[0],a[1]);
        if(n>3){
            for(int i=2;i<n;i++){
                s=gcd(s,a[i]);
            }
        }
        if(k%s==0)ok=true;
    }
    if(ok)cout<<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 1024