akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>

using namespace std;

int cnt;

void insertionSort(int *A, int n, int g) {
	for (int i = g; i<n; i++) {
		int v = A[i];
		int j = i - g;
		while (j >= 0 && A[j] > v) {
			A[j+g] = A[j];
			j = j - g;
			cnt++;
		}
		A[j+g] = v;
	}
}

void shellSort(int *A, int n) {
	cnt = 0;
	int m = 1, m_count, h_tmp;
	for(h_tmp = 1, m_count = 1; h_tmp * 3 + 1 < n; h_tmp = m){
		m = h_tmp * 3 + 1;
		m_count++;
	}
	cout << m_count << endl;

	cout << m;
	while( m > 0 ){
		insertionSort(A, n, m);
		m /= 3;
		if (m > 0) {
			cout << " ";
			cout << m;
		}
	}
	cout << endl;
}

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	int array[n];
	for (int i=0; i<n; i++) {
		cin >> array[i];
	}
	shellSort(array, n);
	
	cout << cnt << endl;
	for (int i=0; i<n; i++) {
		cout << array[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 5064
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>

using namespace std;

int main() {
	long long N, K;
	cin >> N >> K;
	long long cnt = 0;
	if (K > (N-1) * (N-2) / 2){
		cout << "-1" << endl;
		return 0;
	}
	else {
		long long M = N - 1 + (N - 1) * (N - 2) / 2 - K;
		cout << M << endl;
		for (int i = 1; i < N; i++) {
			cout << "1" << " " << i + 1 << endl;
			cnt++;
		}
		for (int i = 2; i < N; i++) {
			for (int j = i + 1; j < N + 1; j++) {
				if (cnt == M) return 0;
				cout << i << " " << j << endl;
				cnt++;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
def main():
	n,a,b,c,d = map(int,input().split())
	s = input()
	ans = ""
	if c < d:
		if s.count("##",a, d) > 0:
			ans = "No"
		else:
			ans = "Yes"
	else:
		if s.count("##", a ,c) > 0 or s.count("...",b-2, d+1) == 0:
			ans = "No"
		else:
			ans = "Yes"
	print(ans)
	return
main()

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

struct point {
	int a, b, c;
	bool operator<(const point &p)const {
		return a + b < p.a + p.b;
	}
}w[1010];
long long D[20100];
int n;
int main() {
	int i, j;
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		scanf("%d%d%d", &w[i].a, &w[i].b, &w[i].c);
	}
	sort(w + 1, w + n + 1);

	for (i = 1; i <= n; i++) {
		for (j = w[i].b; j >= 0; j--) {
			D[j + w[i].a] = max(D[j + w[i].a], D[j] + w[i].c);
		}
	}
	long long res = 0;
	for (i = 0; i <= 20000; i++)res = max(res, D[i]);
	printf("%lld\n", res);
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define ll long long
#define rg register
#define gc getchar()
#define t(i) edge[i].to
#define rp(i,x,y) for(rg int i=x;i<=y;++i)
#define my(i,x,y) for(rg int i=x;i>=y;--i)
#define e(i,x) for(rg int i=head[x];i;i=edge[i].nxt)

const int N=1e5+10;
int n,m,head[N],ed_cnt,sz[N],st,to,sum,as,top,stck[N],g[N];
struct ed{int to,nxt;}edge[N<<1];
bool jud;
bool vis[N];

il int read()
{
    rg char ch=gc;rg int x=0;rg bool y=1;
    while(ch!='-' && (ch>'9' || ch<'0'))ch=gc;
    if(ch=='-')ch=gc,y=0;
    while(ch>='0' && ch<='9')x=(x<<1)+(x<<3)+(ch^'0'),ch=gc;
    return y?x:-x;
}
il void ad(int x,int y){edge[++ed_cnt]=(ed){x,head[y]};head[y]=ed_cnt;}
void dfs1(int x,int fa){e(i,x)if(t(i)^fa)if(sz[t(i)]){if(sz[t(i)]==sz[x])jud=1;st=x;to=t(i);}else sz[t(i)]=-sz[x],dfs1(t(i),x);}
void dfs2(int x,int fa){vis[x]=1;e(i,x)if(t(i)^fa && !((x==st && t(i)==to) || (x==to && t(i)==st)))dfs2(t(i),x),sz[x]+=sz[t(i)],g[x]+=g[t(i)];return;}

int main()
{
	n=read();m=read();rp(i,1,m){int x=read(),y=read();ad(x,y);ad(y,x);}sz[1]=1;dfs1(1,0);
	rp(i,1,n)sum+=sz[i];if(!jud)if(sum)return printf("-1\n"),0;
	if(m==n)if(jud){if(sum&1)return printf("-1\n"),0;as+=abs(sum>>1);sz[st]-=(sum>>1);sz[to]-=(sum>>1);}else g[st]=1,g[to]=-1;
	dfs2(1,0);
	rp(i,1,n){if(g[i])stck[++top]=g[i]*sz[i];else as+=abs(sz[i]);}
    stck[++top]=0;sort(stck+1,stck+top+1);int mid=stck[(top+1)>>1];
    rp(i,1,top)as+=abs(stck[i]-mid);
	printf("%lld\n",as);
    return 0;
}


Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int i,count_1=0,count_2=0;
  for(i=0;i<s.size();i++){
    if(i%2==0 && s.at(i)=='1'){
      count_1++;
    }else if(i%2==0 &&s.at(i)=='0'){
      count_2++;
    }
    if(i%2==1 && s.at(i)=='0'){
      count_1++;
    }else if(i%2==1 && s.at(i)=='1'){
      count_2++;
    }
  }
  cout <<min(count_1,count_2);
}
    

Measured memory_bytes: 512
/*
(1)for binary shift operator always use 'LL' 1LL<<63

*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
#define ordered_set_pair tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_multiset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
  ll powe(ll a,ll b,ll c){
    if(b==0)
    return 1;
    if(b%2==0)
    {
        ll z=powe(a,b/2,c);
        return (z*z)%c;
    }
    else return ((a%c)*powe(a,b-1,c))%c;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,p;//cin>>n>>p;
	ll i,j;
	ll sum=0;
	map<ll,ll> ma;
	string s;cin>>s;
	n=s.size();p=2019;
	
	ll prev=0;
	ma[0]=1;
	for(j=n-1;j>=0;j--){
		prev=(prev+(s[j]-'0')*powe(10,n-j-1,p))%p;
		sum+=ma[prev];
		ma[prev]++;

	}
	cout<<sum<<endl;;

	return 0;
} 

Measured memory_bytes: 3764
#include<stdio.h>
int main(void)
{
  int i;
  char moji;
  while(1)
  {
    scanf("%c",&moji);
    if(moji=='\n') break;
    if(moji<'D') moji=moji+26;
    moji=moji-3;
    printf("%c",moji);
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 2100
#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef unsigned long long llu;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
const ll MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

struct node {
	int u, v;
	ll c;
	int id;
	bool operator< (const node &v2) const {
		return c > v2.c;
	}
} edg[2001];

int p[1001], pa[1001], dist[1001], pe[1001];
char use[2001];
priority_queue<node> pq;
vector<node> v[1001];

ll mp(ll a, ll b) {
	ll ret = 1;

	while (b) {
		if (b % 2) ret = ret * a % MOD;
		a = a * a % MOD;
		b /= 2;
	}

	return ret;
}

int find(int a) {
	if (p[a] == -1) return a;
	return p[a] = find(p[a]);
}

void merge(int a, int b) {
	a = find(a); b = find(b);
	if (a == b) return;
	p[b] = a;
}

void go(int o, int pp, int di) {
	pa[o] = pp; dist[o] = di;
	
	for (int i = 0; i < sz(v[o]); i++)
		if (v[o][i].v != pp) {
			pe[v[o][i].v] = v[o][i].id;
			go(v[o][i].v, o, di + 1);
		}
}

ll fmv(int a, int b) {
	if (dist[a] > dist[b]) swap(a, b);

	ll mav = 0;
	while (dist[a] < dist[b]) {
		mav = max(mav, edg[pe[b]].c);
		b = pa[b];
	}
	while (a != b) {
		mav = max(mav, edg[pe[a]].c);
		mav = max(mav, edg[pe[b]].c);
		a = pa[a], b = pa[b];
	}

	return mav;
}

int main() {
	memset(p, -1, sizeof(p));
	int n, m;
	ll x;
	scanf("%d %d %lld", &n, &m, &x);

	int a, b, t;
	ll c;
	for (int i = 0; i < m; i++) {
		scanf("%d %d %lld", &a, &b, &c);
		a--; b--;
		edg[i] = { a, b, c, i };
		pq.push(edg[i]);
	}

	node tv;
	ll ac = 0;
	while (!pq.empty()) {
		tv = pq.top();
		pq.pop();

		if (find(tv.u) == find(tv.v)) continue;
		ac += tv.c; merge(tv.u, tv.v);
		
		v[tv.u].push_back({ tv.u, tv.v, tv.c, tv.id });
		v[tv.v].push_back({ tv.v, tv.u, tv.c, tv.id });
		use[tv.id] = 1; t = tv.u;
	}
	go(t, t, 0);

	ll ans = 0;
	if (ac > x) return !printf("0");
	if (ac == x) ans = (mp(2, n - 1) - 2 + MOD) * mp(2, (m - n + 1)) % MOD;

	ll d = x - ac;
	int cc = 0, ccc = 0;
	for (int i = 0; i < m; i++) {
		if (use[i]) continue;
		t = edg[i].c - fmv(edg[i].u, edg[i].v);

		if (t == d) cc++;
		else if (t > d) ccc++;
	}

	ll sum = 2 * (mp(2, cc) - 1 + MOD) * mp(2, ccc) % MOD + ans;
	printf("%lld", sum % MOD);
}

Measured memory_bytes: 512
#include<stdio.h>

#define NMAX 100000

int main(void){
    int fr[NMAX], i, N, ans = 0;
    
    scanf("%ld", &N);
    
    for(i = 0; i < N; i++) scanf("%ld", &(fr[i]));
    
    for(i = 0; i < N; i++){
        if(fr[fr[i] - 1] - 1 == i) ans++;
    }
    
    printf("%ld\n", ans / 2);
    
    return 0;
}

Measured memory_bytes: 512
//package src.com.jetman.atcoder;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

/**
 * @description:
 * @author: Jetman
 * @create: 2020-08-29 14:39
 **/
public class Main {

    Scanner sc = new Scanner(System.in);

    long MOD = 1000000000 + 7;


    private void slove() {

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        long ans = (long)a*c;
        ans = Math.max(ans,(long)b*c);
        ans = Math.max(ans,(long)a*d);
        ans = Math.max(ans,(long)b*d);
        System.out.println(ans);





    }

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


Measured memory_bytes: 35684
n,k = map(int,input().split())
x = list(map(int,input().split()))
ans = []
for i in range(n):
    if (i + k -1) >= n:
        break
    x1 = x[i]
    x2 = x[i+k-1]
    ans1 = abs(x2) + abs(x2-x1)
    ans2 = abs(x1) + abs(x1-x2)
    ans.append(ans1)
    ans.append(ans2)
print(min(ans))

Measured memory_bytes: 14224
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const int DEBUG = 0;

bool ok2(const VI &cptbl, int x) {
  if (DEBUG) {
    cerr <<"ok2";
    for (auto y:cptbl)cerr << " " << y;
    cerr << " x = " << x << endl;
  }
  REP(i, 0, 24) {
    if (not cptbl[i]) {
      continue;
    }
    for (int j = i + 24 - x + 1; j <= i + 24 + x - 1; ++j) {
      if (j % 24 != i && cptbl[j % 24]) {
	return false;
      }
    }
  }
  return true;
}

bool ok(const VI &freq, int x) {
  if (DEBUG) {
    cerr << "ok";
    for (auto f: freq) cerr << " " << f;
    cerr << " x = " << x << endl;
  }
  VI tbl(24);
  int one = 0;
  REP(i, 0, 13) {
    int f = freq[i];
    if (f >= 3) {
      return false;
    }
    if ((i == 0 || i == 12) && f == 2) {
      return false;
    }
    if ((i != 0 && i != 12)  && f == 2) {
      tbl[i] = tbl[24 - i] = 1;
    } else if (f == 1) {
      one |= 1 << i;
    }
  }
  if (DEBUG) {
    cerr << "one = " << one << endl;
  }
  REP(bits, 0, 1 << 13) {
    if ((bits & one) != bits) { continue; }
    VI cptbl(tbl);
    REP(i, 0, 13) {
      if ((one & 1 << i) == 0) { continue; }
      if (bits & 1 << i) {
	cptbl[i] = 1;
      } else {
	cptbl[(24 - i) % 24] = 1;
      }
    }
    if(DEBUG)
      cerr << "bits = " << bits << endl;
    if (ok2(cptbl, x)) {
      return true;
    }
  }
  return false;
}

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VI d(n + 1, 0);
  VI freq(13);
  freq[0] = 1;
  REP(i, 0, n) {
    cin >> d[i + 1];
    freq[d[i + 1]] += 1;
  }
  sort(d.begin(), d.end());
  int lo = 0;
  int hi = 24 / (n + 1) + 1;
  while (hi - lo > 1) {
    int mid = (hi + lo) / 2;
    if (ok(freq, mid)) {
      lo = mid;
    } else {
      hi = mid;
    }
  }
  cout << lo << "\n";
}


Measured memory_bytes: 256
n=100004
prime=[False]*2+[True]*(n-2)
for i in range(2,n):
  if prime[i]:
    for j in range(i*2,n,i):
      prime[j]=False
s = [i for i in range(2,n) if prime[i]]
x=int(input())
import bisect as bi
print(s[bi.bisect_left(s,x)])

Measured memory_bytes: 4596
#include <iostream>

#include <map>
#include <string>

#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cinttypes>


using namespace std;

int main()
{
	std::vector<bool> already(1000000000+1);

	int n;
	cin >> n;

	int i;

	for (i = 0; i < n; ++i)
	{
		int a;
		cin >> a;

		if (already[a])
			break;

		already[a] = true;
	}

	if (i == n)
	{
		cout << "YES" << endl;
	}
	else
	{
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 122368
from typing import List


def partition(elements: List[int], start_idx: int, pivot_idx: int) -> int:
    pivot = elements[pivot_idx]
    i = start_idx - 1

    for j in range(start_idx, pivot_idx):
        if elements[j] <= pivot:
            i += 1
            elements[i], elements[j] = elements[j], elements[i]
    elements[i + 1], elements[pivot_idx] = elements[pivot_idx], elements[i + 1]

    return i + 1


if __name__ == "__main__":
    n = int(input())
    elements = list(map(lambda x: int(x), input().split()))

    # pivot_idx = random.randint(0, n - 1)

    pivot_idx = partition(elements, 0, n - 1)

    print(" ".join([f"{elem}" if pivot_idx != idx else f"{[elem]}"
                    for idx, elem in enumerate(elements)]))



Measured memory_bytes: 18468
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define LL long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
//
int main(){
  int M,F,B;
  cin>>M>>F>>B;
  if(M>=B){
    cout<<0<<endl;
  }else if(M+F<B){
    cout<<"NA"<<endl;
  }else{
    cout<<B-M<<endl;
  }
  return 0;
}


Measured memory_bytes: 3096
#include<stdio.h>
#define INFINITY 2000000000
int c=0,l[250000+1],r[250000+1];

void merge(int a[],int n,int left,int mid,int right){
  int i,j,k,n1,n2;
  n1=mid-left;n2=right-mid;
  for(i=0;i<n1;i++)l[i]=a[left+i];
  for(i=0;i<n2;i++)r[i]=a[mid+i];
  l[n1]=INFINITY;
  r[n2]=INFINITY;
  i=0;j=0;
  for(k=left;k<right;k++){
    c++;
    if(l[i]<=r[j]){
      a[k]=l[i];
      i++;
    }
    else{a[k]=r[j];j++;}
  }
}
void mergesort(int a[],int n,int left,int right){
  int mid;
  if(left+1<right){
      mid=(left+right)/2;
      mergesort(a,n,left,mid); 
      mergesort(a,n,mid,right); 
      merge(a,n,left,mid,right); 
    }
}


int main(){
  int i,n,s[500000];
  
  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&s[i]);
  mergesort(s,n,0,n);

  for(i=0;i<n-1;i++) printf("%d ",s[i]);
  printf("%d\n%d\n",s[n-1],c);
  return 0;
}



Measured memory_bytes: 5688
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    string s;
    scanf("%d %d", &a,&b);
    cin>>s;
    int check=0;
    for(int i=0;i<a;i++){
        if ('0'<=s[i] && '9'>=s[i]){
        }
        else{
            check+=1;
        }
    }
    if(s[a]!='-'){
        check+=1;
    }
    for(int i=a+1; i<a+1+b;i++){
        if ('0'<=s[i] && '9'>=s[i]){
        }
        else{
            check+=1;
        }
    }
    if (check==0){
        printf("Yes");
    }
    else{
        printf("No");
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int mod = 1000000007;
int memoGrid(vector<vector<char>>& mat, vector<vector<int>>& dp, int i, int j, int h, int w){
    if(i >= h || j>= w)
        return 0;
    if(mat[i][j] == '#')
        return 0;
    if(i==(h-1) && j==(w-1))
        return 1;
    
    if(dp[i][j] != -1)
        return dp[i][j];

    int count = (memoGrid(mat, dp, i+1, j, h, w)%mod + memoGrid(mat, dp, i, j+1, h, w)%mod)%mod;
    return dp[i][j] = count;
       
}
int main(){
    int h,w;
    cin>>h>>w;
    vector<vector<char>> mat(h, vector<char>(w));
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin>>mat[i][j];
        }
    }
    vector<vector<int>> dp(h, vector<int>(w, -1));
    int ans = memoGrid(mat, dp, 0, 0, h, w);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 8640
#include <iostream>
#include <math.h>
using namespace std;

long long mod = 1000000007;
long long res = 1;
int N;

int main()
{
	cin >> N;
	for (int i = 2; i <= N; i++)
	{
		bool flag = true;
		//проверка на простоту
		for (int c = 2; c <= (int)sqrt(i + 0.0); c++)		
			if (i % c == 0)
			{
				flag = false;
				break;
			}		
		//поиск чисел
		if (flag)
		{

			int sum = 0;
			for (int j = i; j <= N; j *= i)
				sum += N / j;
			if (sum == 0) continue;
			res = (res * (sum + 1)) % mod;
		}
	}
	cout << res;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i < n; ++i)
#define repe(i, n) for(int i=0; i <= n; ++i)
#define repr(i, n) for(int i=n-1; i > 0; --i)
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define PI 3.14159265359
using namespace std;
template <class T> bool chmax(T &a, const T &b) {if (a<b) {a = b; return 1;} return 0;}
template <class T> bool chmin(T &a, const T &b) {if (b<a) {a = b; return 1;} return 0;}
template <class T> using V=vector<T>;
typedef long long ll;
const int INF = 1e9;
const ll MOD = 1000000007;
const ll MAX = 510000;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
vector<int> Eratosthenes(const int N)
{
    vector<bool> is_prime(N+1, true);
    vector<int> P;
    for(int i=2; i<=N; i++) {
        if (is_prime[i]) {
            for(int j=2*i; j<=N; j+=i) {
                is_prime[j] = false;
            }
            P.emplace_back(i);
        }
    }
    return P;
}
 
int main() {
    int n;
    cin >> n;
    vector<int> B(n-1);
    rep(i,n-1) {
        cin >> B[i];
    }
    vector<int> A(n,-1);
    if (n==2) {
        cout << 2*B[0] << "\n";
        return 0;
    }
    rep(i,n-1) {
        if (i==0) {
            if (B[i]<B[i+1]) {
                A[i] = B[i];
                A[i+1] = B[i];
            } else {
                A[i] = B[i];
                A[i+1] = B[i+1];
            }
        } else if (i==n-2) {
            A[i+1] = B[i];
        } else {
            A[i+1] = min(B[i],B[i+1]);
        }
    }

    int res = 0;
    rep(i,n) {
        res += A[i];
    }
    cout << res << "\n";
}

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

int main(){
	string n;
	cin >> n;
	ll sum = 0;

	for(ll i=0; i<n.size(); i++){
		if(n[i] == '1'){
			sum += 1;
		}
		else if(n[i] == '2'){
			sum += 2;
		}
		else if(n[i] == '3'){
			sum += 3;
		}
		else if(n[i] == '4'){
			sum += 4;
		}
		else if(n[i] == '5'){
			sum += 5;
		}
		else if(n[i] == '6'){
			sum += 6;
		}
		else if(n[i] == '7'){
			sum += 7;
		}
		else if(n[i] == '8'){
			sum += 8;
		}
		else if(n[i] == '9'){
			sum += 9;
		}
	}

	if(sum % 9 == 0){
		cout << "Yes" << endl;
	}	
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 3716
use std::cmp::min;

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

fn main() {
    let n = scan!(usize);
    let vs = scan!(String;n);

    let mut numab = 0;
    let mut numa = 0;
    let mut numb = 0;

    let mut ans = 0;
    for v in vs {
        let chars = v.chars().collect::<Vec<_>>();
        if chars.first().unwrap() == &'B' && chars.last().unwrap() == &'A' {
            numab += 1;
        } else if chars.first().unwrap() == &'B' {
            numb += 1;
        } else if chars.last().unwrap() == &'A' {
            numa += 1;
        }

        for (c0, c1) in chars.iter().zip(chars.iter().skip(1)) {
            if c0 == &'A' && c1 == &'B' {
                ans += 1
            }
        }
    }

    if numab > 0 {
        if numa > 0 && numb > 0 {
            numa -= 1;
            numb -= 1;
            ans += numab - 1 + 2;
        } else if numa > 0 {
            numa -= 1;
            ans += numab - 1 + 1;
        } else {
            numb -= 1;
            ans += numab - 1 + 1;
        }
    }
    println!("{}", ans + min(numb, numa));
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main()
{
    using vi = vector<int>;
    using vvi = vector<vi>;
    using vvvi = vector<vvi>;

    string S;
    cin >> S;
    if(S == "Sunny")
        cout << "Cloudy" << endl;
    else if(S == "Cloudy")
    {
        cout << "Rainy" << endl;
    }
    else if(S == "Rainy")
    {
        cout << "Sunny" << endl;
    }
}

Measured memory_bytes: 256
n = int(input())
def calc(t):
    if int(t) > n:
        return 0
    if (("3" in t) & ("5" in t) & ("7" in t)):
        ret = 1
    else:
        ret = 0
    for c in "357":
        ret += calc(t+c)
    return ret

print(calc("0"))

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

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    if(abs(a-n) < abs(b-n)){
        cout << 'A' << endl;
    }else{
        cout << 'B' << endl;
    }
    return 0;
}

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

int main(){
    int N;
    std::cin >> N;
    std::vector< std::vector< int > > AB(N);
    std::map< long long, long long > dist;
    for(int i=0; i<N-1; i++){
        int tmp1, tmp2;
        long long tmp3;
        std::cin >> tmp1 >> tmp2 >> tmp3;
        AB[tmp1 - 1].push_back(tmp2 - 1);
        AB[tmp2 - 1].push_back(tmp1 - 1);
        dist[((long long)tmp1 - 1) * 1e6 + (long long)tmp2 - 1] = tmp3;
        dist[((long long)tmp2 - 1) * 1e6 + (long long)tmp1 - 1] = tmp3;
    }
    
    std::vector< int > ans(N);
    
    std::deque< int > deq_No;
    std::deque< int > deq_preNo;
    std::deque< long long > deq_dist;
    deq_No.push_back(0);
    deq_preNo.push_back(-1);
    deq_dist.push_back(0);
    
    while(!deq_No.empty()){
        int cur_No = deq_No[0];
        int cur_preNo = deq_preNo[0];
        long long cur_dist = deq_dist[0];
        deq_No.pop_front();
        deq_preNo.pop_front();
        deq_dist.pop_front();
        //std::cout << cur_No << " " << cur_preNo << " " << cur_dist << std::endl;
        
        ans[cur_No] = cur_dist % 2;
        
        for(int i=0; i<AB[cur_No].size(); i++){
            int next_No = AB[cur_No][i];
            if(next_No == cur_preNo){
                continue;
            }
            deq_No.push_back(next_No);
            deq_preNo.push_back(cur_No);
            deq_dist.push_back(cur_dist + dist[(long long)cur_No * 1e6 + (long long)next_No]);
        }
    }
    
    for(int i=0; i<N; i++){
        std::cout << ans[i] << std::endl;
    }
    
    return 0;
}



Measured memory_bytes: 18816
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = s, i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = s, i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = s; i < (n); ++i)
#define VFORS(i, s, n) for(int i = s; i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = s, i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = s, i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define SZ(x) ((int)(x).size())
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end());

using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VD = vector<double>;

const int MOD = 1000000007;
const int INF = 1000000000;

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

int main(){
    int n; cin >> n;
    int cnt = 0, t = n;
    while(t){
        cnt += t%10; t /= 10;
    }
    cout << (n%cnt ? "No\n" : "Yes\n");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
using namespace std;

int INC[5100][5100] = {};
int DEC[5100][5100] = {};

int main() {
	
	int N, M;
	cin >> N >> M;
	
	for(int i = 0; i < M; i++){
		int A, B, X;
		cin >> A >> B >> X;
		A = A - B + 1;
		INC[A][B]++;
		INC[A + X + 1][B]--;
		DEC[A - 1][B + 1]++;
		DEC[A - 1][B + X + 2]--;
	}
	
	for(int i = 0; i <= N + 1; i++){
		int ret = 0;
		int ret2 = 0;
		for(int j = 0; j <= N + 1; j++){
			ret += DEC[i][j];
			DEC[i][j] = ret;
			ret2 += INC[j][i];
			INC[j][i] = ret2;
		}
	}
	
	/*
	for(int i = 0; i <= N + 1; i++){
		for(int j = 0; j <= N + 1; j++){
			cout << INC[i][j] << " ";
		}
		cout << endl;
	}
	
	for(int i = 0; i <= N + 1; i++){
		for(int j = 0; j <= N + 1; j++){
			cout << DEC[i][j] << " ";
		}
		cout << endl;
	}
	*/
	
	int ans = 0;
	for(int i = 0; i <= N + 1; i++){
		int ret = 0;
		for(int j = 1; j <= i - 1; j++){
			int id1 = i - j;
			int id2 = j;
			ret += INC[id1][id2];
			ret -= DEC[id1][id2];
			if(ret > 0){
				ans++;
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}




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

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

    map<string, size_t> m;
    m["AC"] = 0;
    m["WA"] = 0;
    m["TLE"] = 0;
    m["RE"] = 0;
    for (size_t i = 0; i < N; i++)
    {
        string S;
        cin >> S;
        m[S]++;
    }
    cout << "AC x " << m["AC"] << endl;
    cout << "WA x " << m["WA"] << endl;
    cout << "TLE x " << m["TLE"] << endl;
    cout << "RE x " << m["RE"] << endl;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main(void){
  long long n,c; cin>>n>>c;
  vector<long long> x(n),v(n),y(n),w(n,0);
  for(int i=0; i<n; ++i) cin>>x[i]>>v[i];
  for(int i=0; i<n; ++i){ y[i]=c-x[n-i-1]; w[i]=v[n-i-1];}
  for(int i=0; i<n; ++i){ v[i]-=x[i]; w[i]-=y[i]; if(i>0){ v[i]+=v[i-1]+x[i-1]; w[i]+=w[i-1]+y[i-1];}}
  vector<long long> p(n,v[0]),q(n,w[0]);
  for(int i=1; i<n; ++i){ p[i]=max(p[i-1],v[i]); q[i]=max(q[i-1],w[i]);}
  long long res=0;
  res=max(res,max(p[n-1],q[n-1]));
  for(int i=0; i<n-1; ++i) res=max(res,max(v[i]+q[n-i-2]-x[i],w[i]+p[n-i-2]-y[i]));
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 8000
#include <bits/stdc++.h>
#include <string>
using namespace std;
 
int main(){
   string s;
   int a,b;
   cin>>a>>b>>s;
   if(s[a]!='-')goto loop1;
   for(int i=0;i<s.size();i++){
	   if(i!=a){
		   if(s[i]<'0'||s[i]>'9')goto loop1;
	   }
   }
   cout<<"Yes"<<endl;
   goto loop2;
   loop1:;
   cout<<"No"<<endl;
   loop2:;
    return 0;
}    


Measured memory_bytes: 256
/*
	watch me go
*/
#pragma GCC optimize("O3")
//#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define d long double
#define pii pair<int,int>
#define pb push_back
#define inf (int)1e18
#define init(x,a) memset(x,a,sizeof(x))
#define all(c) c.begin(),c.end()
int const mod=998244353;
int const mod1=1000000007;
int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}
#define out(x) cout<<#x<<" = "<<" "<<x<<"\n";
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
 #define haha ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// ******** Using PBDS ********
// typedef tree<long long, null_type, less<long long>, rb_tree_tag, 
//              tree_order_statistics_node_update> 
//                 os; 
// ******** Using PBDS ********
int modexp(int x, int n){
	if(n==0){
		return 1;
	}
	else if(n&1){
		return (modexp((x*x)%mod, n/2)%mod * x%mod)%mod;
	}
	else{
		return (modexp((x*x)%mod, n/2)%mod);
	}
}
 
int modinv(int n)
{
	return modexp(n,mod-2);
}


signed main()
{
    haha
    int arr[3];
    cin>>arr[0]>>arr[1]>>arr[2];
    cout<<arr[2]<<" "<<arr[0]<<" "<<arr[1];
    
   
}




Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string> //文字列
#include <iomanip> //doubleの桁数指定 setprecision()
#include <list> //前後に数値を入れれる配列
#include <map> //map
#include <vector> //vecror



#define REP(i,m,n) for(ll i = (ll) (m);i < (ll) (n);i++) //forの短縮
#define rep(i,n) REP(i,0,n) //REPが0の時
#define ll long long int

using namespace std;

double PI = acos(-1); //円周率

//常設関数↓

//最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

//degree → radian
long double chg_DegRad(long double deg) {
	return deg * PI / 180.0;
}

//radian → degree
long double chg_RadDeg(long double rad) {
	return rad * 180.0 / PI;
}
 
//桁数
ll CountDigit(ll n) {
	ll digit = 1;
	while ((n /= 10) != 0) digit++;
	return digit;
}

//距離
double dis(double xa, double ya, double xb, double yb) {
	return pow(pow(xa - xb, 2.0) + pow(ya - yb, 2.0), 0.5);
}

//abs()平均
//pow(,)累乗


//提出コード↓

ll h, n;
ll a[100010];


int main() {
	cin >> h >> n;
	rep(i, n) {
		cin >> a[i];
		h -= a[i];
	}
	if (h <= 0) cout << "Yes" << endl;
	else cout << "No" << endl;
	


	return 0;
}



Measured memory_bytes: 1024
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int x = sc.nextInt();
    if(x==1||x==2*n-1){
      System.out.println("No");
      return;
    }
    System.out.println("Yes");
    int[] cen = {x-2,x+1,x,x-1};
    int min = x-2;
    if(x==2){
      cen[0]=x+2;
      cen[1]=x-1;
      cen[3]=x+1;
      min=x-1;
    }
    if(n==2){
      System.out.println("1");
      System.out.println("2");
      System.out.println("3");
      return;
    }
    int num = 0;
    for(int i=0;i<n-3;i++){
      num++;
      if(num==min)num+=4;
      System.out.println(num);
    }
    for(int i=0;i<4;i++)System.out.println(cen[i]);
    for(int i=0;i<n-2;i++){
      num++;
      if(num==min)num+=4;
      System.out.println(num);
    }
  }
}

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

int main(void) {
  int a, b;
  cin >> a >> b;

  if(a*b%2 == 1) {
    cout << "Odd" << endl;
  }
  else {
    cout << "Even" << endl;
  }
  return 0;
}

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

const int mx = 305;
const int inf = 0x3f3f3f3f;
const int S = mx - 2, T = mx - 1;

struct edge {
  int from, to, cap;
  edge *rev;
  edge(int from, int to, int cap) : from(from), to(to), cap(cap) {}
  void flow(int f) { cap -= f, rev->cap += f; }
};

vector<edge *> adj[mx];

void addEdge(int u, int v, int c) {
  edge *e = new edge(u, v, c);
  edge *rev = new edge(v, u, 0);
  e->rev = rev, rev->rev = e;
  adj[u].push_back(e);
  adj[v].push_back(rev);
}

bool vis[mx], inq[mx];
int bt[mx], mf[mx];
edge *bte[mx];
bool augment(int &flow) {
  fill(vis, vis + mx, false);
  fill(inq, inq + mx, false);
  fill(mf, mf + mx, 0);
  queue<int> q;
  q.push(S);
  mf[S] = inf;
  while (!q.empty()) {
    int p = q.front();
    q.pop();
    inq[p] = false;
    if (vis[p])
      continue;
    // printf("Visit: %d\n", p);
    vis[p] = true;
    if (p == T)
      break;
    for (edge *e : adj[p]) {
      // printf("Edge: %d -> %d, cap %d\n", e->from, e->to, e->cap);
      if (!vis[e->to] && min(e->cap, mf[p]) > mf[e->to]) {
        bt[e->to] = p;
        bte[e->to] = e;
        mf[e->to] = min(e->cap, mf[p]);
        if (!inq[e->to])
          q.push(e->to), inq[e->to] = true;
      }
    }
  }
  // printf("Done, vis: %d\n", vis[T]);
  if (!vis[T])
    return false;
  int p = T, f = mf[T];
  while (p != S) {
    bte[p]->flow(f);
    p = bt[p];
  }
  flow = f;
  return true;
}

int maxflow() {
  int flow, mflow = 0;
  while (augment(flow))
    mflow += flow;
  return mflow;
}

int main() {
  int x, y, e;
  cin >> x >> y >> e;

  for (int i = 0; i < x; i++)
    addEdge(S, i, 1);
  for (int i = 100; i < 100 + y; i++)
    addEdge(i, T, 1);

  for (int i = 0; i < e; i++) {
    int a, b;
    cin >> a >> b;
    addEdge(a, 100 + b, inf);
  }

  cout << maxflow() << endl;
  return 0;
}


Measured memory_bytes: 3956
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#define in inline
#define re register
using namespace std;
in long long read(){
	re long long t=0;
	re char v=getchar();
	while(v<'0'||v>'9')v=getchar();
	while(v>='0'&&v<='9'){
		t=(t<<3)+(t<<1)+(v^48);
		v=getchar();
	}
	return t;
}
int a[82][82],b[82][82],n,m,f[82][35002],g[82][35002];
int main(){
	n=read();
	m=read();
	for(re int i=1;i<=n;++i)
	for(re int j=1;j<=m;++j)a[i][j]=read();
	for(re int i=1;i<=n;++i)
	for(re int j=1;j<=m;++j)b[i][j]=read();
	f[1][abs(a[1][1]-b[1][1])]=f[1][abs(b[1][1]-a[1][1])]=1;
	for(re int i=2;i<=m;++i){
		for(re int j=0;j<=(i-1)*80;++j){
			if(f[i-1][j])f[i][abs(j+abs(a[1][i]-b[1][i]))]=1,f[i][abs(j-abs(a[1][i]-b[1][i]))]=1;
		}
	}
	for(re int i=2;i<=n;++i){
		for(re int j=1;j<=m;++j){
			for(re int k=0;k<=(i+j-1)*80;++k){
				if(f[j][k]||g[j-1][k]){//cout<<f[j][k]<<" "<<g[j-1][k]<<" "<<i<<" "<<j<<" "<<k<<endl;
				g[j][abs(k+abs(a[i][j]-b[i][j]))]=1,g[j][abs(k-abs(a[i][j]-b[i][j]))]=1;
				}
				
			}
			
		}
		for(re int j=1;j<=m;++j){
			for(re int k=0;k<=(i+j-1)*80;++k){
				f[j][k]=g[j][k];
				g[j][k]=0;
			}
			
		}
	}
	int tmp=0;
	while(!f[m][tmp])++tmp;
	printf("%d",tmp);
}


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

int main(){
int n;
cin >> n;
map<string, int> mp;
rep(i,n) {
    string s;
    cin >> s;
    mp[s]++;
}
int mx=0; // c++ではキーが辞書順にソートされているので楽です。
for(auto p: mp) mx=max(mx, p.second);
for(auto p: mp) if(p.second==mx) cout << p.first << endl;

}

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

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] A = new int[3];
        for(int i = 0; i < 3; i++){
            A[i] = sc.nextInt();
        }
        Arrays.sort(A);
        System.out.println(A[0] + " " + A[1] + " " + A[2]);
    }
}



Measured memory_bytes: 26404
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define per(i, n, s) for (int i = (n-1); i >= (int)(s); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;

int main() {
    int n; cin>>n;
    rep(i,0,30){
        if((n-4*i)%7==0){
            cout<<"Yes"<<endl;
            return 0;
        }
        if(i*4>n) break;
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
using namespace std;
typedef map<string,int>M;
int main()
{
	int n,d,t,r,i,j;
	char s[99];
	M m;
	M::iterator ite;
	while(scanf("%d",&n),n)
	{
		m.clear();
		int f[12345]={};
		while(n--)
		{
			scanf("%s%d%d",s,&d,&t);
			t=t%100+(t-600)/100*60+d*1440;
			m[s]=t;
		}
		scanf("%d",&n);
		for(r=n;n--;)
		{
			scanf("%s",s);
			t=(ite=m.find(s))->second;
			for(i=0;i<30;++i)
				if(f[t+i]++)r=-1;
			m.erase(ite);
		}
		if(r>=0)
		{
			vector<int>v;
			for(ite=m.begin();ite!=m.end();++ite)v.push_back(ite->second);
			sort(v.begin(),v.end());
			for(i=0;i<v.size();++i)
			{
				if(!f[v[i]]&&!f[v[i]+29])
				{
					++r;
					for(j=0;j<30;++j)f[v[i]+j]=1;
				}
			}
		}
		printf("%d\n",r);
	}
	return 0;
}

Measured memory_bytes: 936
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const n = Number(stdin.split('\n')[0])
const s = stdin.split('\n').slice(1, n + 1)
const m = Number(stdin.split('\n')[n + 1])
const t = stdin.split('\n').slice(n + 2, n + 2 + m)

const getTotal = str => {
  let total = 0
  for (let i = 0; i < n; i++) {
    if (s[i] === str) {
      total++
    }
  }

  for (let i = 0; i < m; i++) {
    if (t[i] === str) {
      total--
    }
  }

  return total
}

const ans = () => {
  const totals = s.map(str => getTotal(str))

  const max = Math.max(...totals)

  return max < 0 ? 0 : max
}

console.log(ans())


Measured memory_bytes: 7500
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define repi(i,a,b) for(int i = (a); i < (b); i++)

using namespace std;

typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
typedef    pair<int,pair<int,string> >    P;
const int INF=1<<29;
const double EPS=1e-9;

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int n;
int main(){
	string team;
	vector<P> data;

	int w,l,d;
	int c =0;
	while(cin>>n,n){
		if(c!=0){
			cout <<endl;
		}
		data.clear();
		for(int i =0;i <n;i++){
			cin>>team>>w>>l>>d;
			int sum =w*3+d*1;
			data.push_back(P(sum,mp(-i,team)));
		}
		sort(data.begin(),data.end(),greater<P>());
		for(int i =0;i <data.size();i++){
			string out =data[i].second.second;
			int score =data[i].first;
			cout <<out<<","<<score<<endl;
		}
		c++;
	}
	return 0;
}

Measured memory_bytes: 1220
#include<bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long
int main()
{
    ll x,i,k,n=0,j;
    cin>>x;
    for(ll i=1;i<300;i++)
    {
        for(ll j=i-1;j>-300;j--)
        {
            if(pow(i,5)-pow(j,5)==x)
            {
                 cout<<i<<" "<<j<<endl;
               return 0;
            }

        }
    }



}





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

using namespace std;

int main(){
    int w,h,x,y,r;
    cin >> w >> h >> x >> y >> r;
    if(x-r>=0 && y-r>=0 && w>=x+r && h>=y+r){
        cout << "Yes" << endl;
    }
    else{cout << "No" << endl;}
    return 0;
}


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

int main(){

    int n;
    double a, t;
    cin >> n >> t >> a;
    double m = 1000000;
    int best = 0;
    for (int i = 0; i < n; ++i)
    {
        double h;
        cin >> h;
        double tmp = t - 0.006 * h;

        if (m > abs(a - tmp))
        {
            best = i + 1;
            m = abs(a - tmp);

        }
    }
    cout << best << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<memory>
#include<algorithm>
#include<cstring>

// 最大値かその次の値を返す問題と見た

constexpr int size = 200000;

int main(void)
{
        int N;
        std::cin >> N;
        auto A = std::make_unique<int[]>(size);
        auto B = std::make_unique<int[]>(size);

        for(auto i = 0; i < N; i++)
        {
                int input;
                std::cin >> input;
                A.get()[i] = input;
        }

        std::memcpy(B.get(), A.get(), size * sizeof(int));

        std::sort(A.get(), A.get() + N);

        int max_1 = A.get()[N-1];
        int max_2 = A.get()[N-2];

        for(auto i = 0; i < N; i++)
        {
                auto ret = B.get()[i];
                ret = (ret != max_1) ? max_1 : max_2;
                std::cout << ret << std::endl;;
        }
}


Measured memory_bytes: 3200
#include <iostream>
#include <queue>
#include <vector>
#include <string>
using namespace std;

#define INF 1e+15
#define MAX_V 1000000

struct edge {
    long long to;
};

// <最短距離, 頂点の番号>
using P = pair<long long, pair<long long, bool> >;

long long V;
long long K;
vector<edge> G[MAX_V][2];
long long d[MAX_V][2];

void dijkstra(long long s, bool direct) {
    priority_queue<P, vector<P>, greater<P> > que;
    for(long long i=0; i<V; i++){
        d[i][1]=INF;
        d[i][0]=INF;
    }
    d[s][1] = 0;
    d[s][0] = 0;
    que.push(make_pair(0,make_pair(s,direct)));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        long long v = p.second.first;
        bool ar = p.second.second;
        if (d[v][ar] < p.first) continue;
        //if prim,
        //d[v] = -d[v];
        //for keep tree
        for (long long i=0; i<G[v][ar].size(); ++i) {
            edge e = G[v][ar][i];
            if (d[e.to][ar] > d[v][ar]+1) {
                d[e.to][ar] = d[v][ar]+1;
                que.push(make_pair(d[e.to][ar],make_pair(e.to,ar)));
            }
        }
        for (long long i=0; i<G[v][!p.second.second].size(); ++i) {
            edge e = G[v][!p.second.second][i];
            if(d[v][ar]%K==0){
                if (d[e.to][!ar] > d[v][ar]+1) {
                    d[e.to][!ar] = d[v][ar]+1;
                    que.push(make_pair(d[e.to][!ar],make_pair(e.to,!p.second.second)));
                }
            }else{
                if (d[e.to][!ar] > d[v][ar]-(d[v][ar]%K)+K+1) {
                    d[e.to][!ar] = d[v][ar]-(d[v][ar]%K)+K+1;
                    que.push(make_pair(d[e.to][!ar],make_pair(e.to,!p.second.second)));
                }
            }
        }
    }
}

int main() {
    //input
    long long H,W;
    cin >> H >> W >> K;
    V=H*W;
    long long x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    string c[H];
    long long i,j;
    for(i=0; i<H; i++){
        cin >> c[i];
    }
    
    //calc
    for(i=0; i<H; i++){
        for(j=0; j<W-1; j++){
            if((c[i][j]=='.')&&(c[i][j+1]=='.')){
                G[W*i+j][0].push_back({W*i+j+1});
                G[W*i+j+1][0].push_back({W*i+j});
            }
        }
    }
    for(i=0; i<H-1; i++){
        for(j=0; j<W; j++){
            if((c[i][j]=='.')&&(c[i+1][j]=='.')){
                G[W*i+j][1].push_back({W*(i+1)+j});
                G[W*(i+1)+j][1].push_back({W*i+j});
            }
        }
    }
    long long ans;
    dijkstra(W*(x1-1)+(y1-1),1);
    ans = min(d[W*(x2-1)+(y2-1)][1],d[W*(x2-1)+(y2-1)][0]);

    //answer
    if(ans==INF){
        cout << -1 << endl;
    }else{
        cout << (ans+K-1)/K << endl;
    }
    system("pause");
    return 0;
}

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

const int n = 500 + 10;

int h[n][n], a[n][n];

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

void dfs(int x, int y) {
    int z = h[x][y] + a[x][y];
    for (int k = 0; k < 4; k++) {
        int tx = x + dx[k], ty = y + dy[k];
        if (h[tx][ty] > z) {
            h[tx][ty] = z;
            dfs(tx, ty);
        }
    }
}

int main() {
    int n;  scanf("%d", &n);
    
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            h[i][j] = min(min(i - 1, n - i), min(j - 1, n - j));
            a[i][j] = 1;
        }
    }

    int ans = 0;
    for (int i = 0; i < n*n; i++) {
        int pos;    scanf("%d",&pos);
        int x = (pos - 1) / n + 1, y = (pos - 1) % n + 1;
        ans += h[x][y];
        a[x][y] = 0;
        dfs(x, y);
    }
    printf("%d\n", ans);
}


Measured memory_bytes: 21148
import numpy as np

def isPrimeNum(x):
    if type(x) is not int: return False
    if x <= 1: return False
    if x <= 3: return True
    max = int(np.sqrt(x))
    for i in range(2, max+1):
        if x % i == 0: return False
    return True
    
def isNumLike2017(x):
    if isPrimeNum(x) == False: return False
    if isPrimeNum(int((x+1)/2)) == False: return False
    return True
        
N = 10**5
X = np.zeros(N+1, dtype='int64')
for i in range(1, N+1):
    if isNumLike2017(i): X[i] += 1
X = X.cumsum()

Q = int(input())
for _ in range(Q):
    l, r = input().split()
    l, r = int(l), int(r)
    print(X[r] - X[l-1])

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

int main() {
 int N;
 cin >> N;
 vector<pair<int, int>> lr(N);
 int ans = 0;
 for(int i=0; i<lr.size(); i++) {
  cin >> lr.at(i).first >> lr.at(i).second;
  ans += lr.at(i).second - lr.at(i).first + 1;
 }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import Control.Monad

solver n a b c d e = let (r,q) = divMod n (minimum [a,b,c,d,e]) in
                     (if q == 0 then 0 else 1)+ 4 + r

main::IO()
main=do
    (n:a:b:c:d:e:[])<-forM [1..6] (\_-> return.read=<<getLine)
    print (solver n a b c d e)


Measured memory_bytes: 508