akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	while(true) {
    		int H = sc.nextInt();
    		int W = sc.nextInt();
    		int a = 1; //tate
    		int b = 1; //yoko
    		if(H == 0 && W == 0) {
    			break;
    		}
    		for(int h = 0; h < H; h ++, a ++) {
    			for(int w = 0; w < W; w ++, b ++) {
    				if(a % 2 == 1) {
    					if(b % 2 == 1) {
    						System.out.print("#");
    					}
    					else {
    						System.out.print(".");
    					}
    				}
    				else {
    					if(b % 2 == 0) {
    						System.out.print("#");
    					}
    					else {
    						System.out.print(".");
    					}
    				}
    			}
    			System.out.println("");
    			b = 1;
    		}
    		System.out.println("");
    	}
    }
}


Measured memory_bytes: 32676
#include <cstdio>
#include <algorithm>
#define ll long long
#define rep(i,j,k) for (i=j;i<=k;i++)
using namespace std;
ll n,a,b,c,d,i,l,r,l1,r1,l2,r2;
ll cross(ll a,ll b,ll c,ll d) {
	return max(a,c)<=min(b,d);
}
int main()
{
//	freopen("moderate.in","r",stdin);
//	freopen("moderate.out","w",stdout);
	scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
	n-=2;
	rep(i,0,n)
	{
		l=a-d*i; r=a-c*i;
		l1=b-(n-i)*d-d; r1=b-(n-i)*c-c;
		l2=b-(n-i)*d+c; r2=b-(n-i)*c+d;
		if (cross(l,r,l1,r1) || cross(l,r,l2,r2)) {
			printf("YES\n"); return 0;
		}
	}
	printf("NO\n");
	return 0;
}

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

int main(){
    long long int n;
    scanf("%lld",&n);
    long long int sum = n*(n + 1) / 2;
    for(int i = 0;3*i <= n;i++){
        sum -= 3*i;
    }

    for(int i = 0;5*i <= n;i++){
        sum -= 5*i;
    }

    for(int i = 0;15*i <= n;i++){
        sum += 15*i;
    }

    printf("%lld",sum);
    return 0;
}


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

struct E {
    int from, to, cost;
    E(int f, int t, int c) : from(f), to(t), cost(c) { }
    bool operator <(const E &x) const {
        return cost < x.cost;
    }
};

struct union_find {
    vector<int> par;
    union_find(int n) : par(n, -1) { }
    bool same(int x, int y) {
        x = root(x);
        y = root(y);
        return x == y;
    }

    void merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x != y) {
            par[x] += par[y]; par[y] = x;
        }
    }

    int root(int x) {
        return par[x] < 0 ? x : par[x] = root(par[x]);
    }
};

int kruskal(vector<E> edges, const int N) {
    sort(edges.begin(), edges.end());
    union_find uf(N);
    int res = 0;
    for(int i = 0; i < (int)edges.size(); i++) {
        E e = edges[i];
        if(uf.same(e.from, e.to) == false) {
            res += e.cost;
            uf.merge(e.from, e.to);
        }
    }
    return res;
}

int main() {
    for(int N, M; cin >> N >> M, N + M != 0; ) {
        vector<E> edges;
        for(int i = 0; i < M; i++) {
            int f, t, c; cin >> f >> t >> c;
            edges.push_back(E(f, t, c));
        }
        int res = kruskal(edges, N);
        cout << res << endl;
    }
}

Measured memory_bytes: 1204
#include<iostream>
#include<vector>
#include<cstring>
#define ll long long 
using namespace std;
ll ans;
char s[10];
bool vis[10];
int len;
void dfs(int x, int flag)
{
	if (x == len)
	{
		ll tmp = 0;
		ll x = 0;
		ll sqr = 1;
		for (int i = len - 1; i >= 0; i--)
		{
			tmp += (s[i] - '0') * 1ll * sqr;
			if (vis[i] || i == 0)
			{
				x += tmp;
				tmp = 0;
				sqr = 1;
			}
			else
				sqr *= 10;
		}
		ans += x;
		return;
	}
	vis[x] = flag;
	dfs(x + 1, 1);
	dfs(x + 1, 0);
}
int main()
{
	cin >> s;
	len = strlen(s);
	dfs(0, 0);
	ans /= 2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    ll max=0;
ll count=0;
   for(int i=0;i<n-1;i++)
   {
       if(arr[i]>=arr[i+1])
       {
           count++;
       }
       else
       {
           if(count>max)
            max=count;
           count=0;

       }
   }
   if(count>max)
   {
       max=count;
   }
   cout<<max<<endl;

}


Measured memory_bytes: 640
l=[0 for i in range(5)]
for i in range(3):
    a, b = map(int, input().split())
    l[a] += 1
    l[b] += 1
ans=True
for i in range(1, 5):
    if l[i] <= 0:
        ans = False
    if l[i] >= 3:
        ans = False
print('YES' if ans else 'NO')


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
const int INF = 1e8;
using namespace std;


const int MAX_V = 300;

void init(int m[MAX_V][MAX_V]){
	rep(i,MAX_V) rep(j,MAX_V) m[i][j] = INF;
	rep(i,MAX_V) m[i][i] = 0;
}

long long warshallFloyd(int m[MAX_V][MAX_V], int n, bool f){
	rep(k,n){
		rep(i,n){
			rep(j,n){
				if(f){
					if(m[i][k] == INF || m[k][j] == INF) continue;
					if(i == k || j == k) continue;
					if(m[i][j] == m[i][k] + m[k][j]){
						m[i][j] = INF;
					}
				}else{
					m[i][j] = min(m[i][j], m[i][k] + m[k][j]);
				}
			}
		}
	}

	long long cnt = 0;
	rep(i,n){
		rep(j,n){
			if(m[i][j] != INF) cnt += m[i][j];
		}
	}
	return cnt / 2;
}

bool check(int a[MAX_V][MAX_V], int b[MAX_V][MAX_V], int n){
	rep(i,n){
		rep(j,n){
			if(a[i][j] != b[i][j]) return true;
		}
	}
	return false;
}

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

	int g[MAX_V][MAX_V], cp[MAX_V][MAX_V];
	rep(i,n){
		rep(j,n){
			cin >> g[i][j];
			cp[i][j] = g[i][j];
		}
	}
	warshallFloyd(cp, n, 0);
	if(check(g,cp,n)){
		cout << -1 << endl;
		return 0;
	}
	cout << warshallFloyd(g, n, 1) << endl;
}


Measured memory_bytes: 1024
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Kein Yukiyoshi
 */

#include "bits/stdc++.h"
#define int long long
#define rep(i, n)           for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b)        for (int i = (int)(a); i < (int)(b); i++)
#define FOR(i, a)           for (auto &i : a)
#define ALL(obj)            begin(obj), end(obj)
#define MAX(x)              *max_element(ALL(x))
#define MIN(x)              *min_element(ALL(x))
#define sum(x)              accumulate(ALL(x), 0LL)
#define LOWER_BOUND(A, key) distance(A.begin(), lower_bound(ALL(A), key))
#define UPPER_BOUND(A, key) distance(A.begin(), upper_bound(ALL(A), key))

using namespace std;
const int MOD    = (int)(1e9 + 7);
const int INF    = (int)(1e13 + 7);
const double EPS = 1e-14;
const double PI  = acos(-1);

int CEIL(int a, int b) { return (a >= 0 ? (a + (b - 1)) / b : (a - (b - 1)) / b); } //ceil() for int
int mod(int a, int b) { return a >= 0 ? a % b : a - (b * CEIL(a, b)); }             //always return positive num
int bpm(int a, int b) {                                                             //return x^y in order(log(y))
  int res = 1;
  for (a %= MOD; b; a = a * a % MOD, b >>= 1)
    if (b & 1) res = res * a % MOD;
  return res;
}
vector<int> non_duplication; //change if you need
template <class T>
void without_duplication(T a) {
  non_duplication.emplace_back(a[0]);
  for (int i = 1; i < a.size(); i++)
    if (a[i] != a[i - 1]) non_duplication.push_back(a[i]);
}

class DNotDivisible {
public:
  static void solve(istream &cin, ostream &cout) {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    vector<int> check(10000000, 0);
    sort(ALL(A));
    without_duplication(A);
    rep(i, non_duplication.size()) {
      for (int j = 1; j * non_duplication[i] <= 1000000; j++) {
        check[j * non_duplication[i]]++;
      }
    }
    int ans = 0;
    rep(i, N) {
      if (i < N - 1) {
        if (A[i + 1] == A[i]) continue;
      }
      if (i > 0) {
        if (A[i - 1] == A[i]) continue;
      }
      if (check[A[i]] == 1) {
        ans++;
      }
    }
    cout << ans << endl;
  }
};


signed main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
  DNotDivisible solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}


Measured memory_bytes: 86524
#include "bits/stdc++.h"
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const long long mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

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

ll powMod(ll n, ll k, ll m) {
	if (k == 0) {
		return 1;
	} else if (k % 2 == 1) {
		return powMod(n, k - 1, m) * n % m;
	} else {
		ll t = powMod(n, k / 2, m);
		return t * t % m;
	}
}


int main() {
	ll l, r, d;
	cin >> l >> r >> d;

	ll ans=0;

	for (int i = l; i <= r; i++) {
		if (i % d == 0) {
			ans++;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3628
# -*- coding: utf-8 -*-


def main():
    n, w = map(int, input().split())
    ws = [0 for _ in range(n)]
    vs = [0 for _ in range(n)]
    inf = 10 ** 12
    dp = [[inf for _ in range(((n + 1) * 10 ** 3) + 1)] for _ in range(n + 1)]

    for i in range(n):
        wi, vi = map(int, input().split())
        ws[i] = wi
        vs[i] = vi

    dp[0][0] = 0

    for i in range(n):
        for sum_v in range(((n + 1) * 10 ** 3) + 1):
            if sum_v - vs[i] >= 0:
                dp[i + 1][sum_v] = min(dp[i + 1][sum_v],
                                       dp[i][sum_v - vs[i]] + ws[i])

            dp[i + 1][sum_v] = min(dp[i + 1][sum_v], dp[i][sum_v])

    ans = 0

    for index, d in enumerate(dp[n]):
        if d <= w:
            ans = index

    print(ans)


if __name__ == '__main__':
    main()


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

typedef long long ll;
const ll INF = 1e18;
const int BIG = 1e9 + 555;
const int maxN = 20 + 9;

int n;
int a[maxN], b[maxN], c[maxN];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cin >> n;
	
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}

	for(int i = 1; i <= n; i++){
		cin >> b[i];
	}
	
	for(int i = 1; i + 1 <= n; i++){
		cin >> c[i];
	}
	
	int ans = 0;
	for(int i = 1; i <= n; i++){
		int curDishes = a[i];
		ans += b[curDishes];
		if(i + 1 <= n && a[i + 1] == a[i] + 1){
			ans += c[curDishes];
		}
	}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);
    for (auto &a : A) cin >> a;
    int j = 1;
    for (int i = 0; i < N; ++i) {
        if (A[i] == j) {
            j++;
        }
    }
    printf("%d\n", j == 1 ? -1 : N-j+1);
    return 0;
}


Measured memory_bytes: 1152
/*input
1
C
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

string s[maxn];

int main(){
	IOS;
	int n;
	cin>>n;
	REP(i,n) cin>>s[i];
	int ans=0;
	REP(i,n){
		for(int j=0;j<SZ(s[i])-1;j++){
			if(s[i][j]=='A'&&s[i][j+1]=='B') ans++;
		}
	}
	int cnt1=0,cnt2=0,cnt3=0;
	REP(i,n){
		if(s[i][0]=='B'&&s[i].back()=='A') cnt3++;
		else if(s[i][0]=='B') cnt1++;
		else if(s[i].back()=='A') cnt2++;
	}
	if(cnt1==0&&cnt2==0&&cnt3){
		cout<<ans+cnt3-1<<'\n';
		return 0;
	}
	cout<<ans+cnt3+min(cnt1,cnt2);
	return 0;
}


Measured memory_bytes: 3072
import java.util.*;
import java.io.*;
import java.math.BigDecimal;
import java.awt.geom.*;
import static java.util.Arrays.*;

class Main{
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = Integer.parseInt(stdIn.next());
		int W = Integer.parseInt(stdIn.next());
		int H = Integer.parseInt(stdIn.next());
		int x = 0;
		int y = 0;
		int w = 0;
		int[] width = new int[W+1];
		int[] height = new int[H+1];
		boolean flag = false;
		for(int i=0;i<n;i++){
			x = Integer.parseInt(stdIn.next());
			y = Integer.parseInt(stdIn.next());
			w = Integer.parseInt(stdIn.next());
			boolean flag1 = false;
			boolean flag2 = false;
			int lx = Math.max(0,x-w);
			int hx = Math.min(W,x+w);
			int ly = Math.max(0,y-w);
			int hy = Math.min(H,y+w);
			width[lx]++;
			width[hx]--;
			height[ly]++;
			height[hy]--;
		}
		int count = 0;
		for(int i=0;i<W;i++){
			count += width[i];
			if(count<=0){
				flag = true;
			}
		}
		count = 0;
		for(int i=0;i<H;i++){
			count += height[i];
			if(count<=0 && flag){
				out.println("No");
				out.flush();
				return;
			}
		}
		out.println("Yes");
		out.flush();
	}
}

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

using namespace std;


int main()
{
    string S;
    int a,b;
    cin >> S;
    a = atoi(S.substr(0,2).c_str());
    b = atoi(S.substr(2,2).c_str());

 

    if(a > 12 || a == 0){ //YY
        if(b > 12 || b == 0)
        {
            cout << "NA" << endl;
        }else{
            cout << "YYMM" << endl;
        }
    }else{ // MM or YY

        if(a == 0 && b == 0)
        {
            cout << "NA" << endl;
            return 0;
        }

        if(b > 12)
        {
            cout << "MMYY" << endl;
        }else{
            if(b == 0)
            {
                cout << "MMYY" << endl;
                return 0;
            }
            cout << "AMBIGUOUS" << endl;
        }
    }
    
    return 0;

}

Measured memory_bytes: 256
from math import log
n = int(input())
A = list(map(int, input().split()))
num = {}
for a in A:
	if a in num:
		num[a] += 1
	else:
		num[a] = 1

ans = 0
cnt = int(log(max(A), 2)) + 5 
for i in range(cnt, 0, -1):
	b = {}
	for x in num:
		if 2 ** i - x in b:
			b[2 ** i - x] += 1
		else:
			b[2 ** i - x] = 1
	for x in num:
		if x in b and num[x] > 0:
			if x * 2 == 2 ** i:
				ans += num[x] // 2
				num[x] %= 2
			else:
				small = min(num[x], num[2 ** i - x])
				ans += small
				num[x] -= small
				num[2 ** i - x] -= small
print(ans)


Measured memory_bytes: 240160
#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,k,x,y;

int main(){
  ll ans=0;
  cin >> n >> k;

  cout<<(n/k+(n%k!=0))<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

int a[200010];

int main() {
	int N;
	cin >> N;
	for(int i=0; i<N; ++i) cin >> a[i];
	int cnt=0;
	for(int i=0; i<N; ++i){
		if(cnt+1==a[i]){
			++cnt;
		}
	}
	if(cnt==0) cout << -1 << endl;
	else cout << N-cnt << endl;
	return 0;
}

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

string divide[4]={"dream","dreamer","erase","eraser"};

int main(){
  string S;cin>>S;
  reverse(S.begin(),S.end());
  for (int i=0;i<4;++i){
    reverse(divide[i].begin(),divide[i].end());
  }
  bool can =true;
  for (int i=0;i<S.size();){
    bool can2 =false;
    for (int j=0;j<4;++j){
      string d=divide[j];
      if (S.substr(i,d.size())==d){
        can2=true;
        i+=d.size();
      }
    }
    if(!can2){
      can=false;
      break;
    }
  }
  if (can) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}
        
    

Measured memory_bytes: 512
/*
14:03 - 14:24 
14:24 - 14:46 debug
*/

#include<iostream>
#include<vector>
#include<algorithm>
#include<deque>
#include<climits>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define IINF (INT_MAX)
#define MAX 110

using namespace std;

struct Data{
  int x,y,cost;
  Data(int x=IINF,int y=IINF,int cost=IINF):x(x),y(y),cost(cost){}
};

int H,W,N,ix,iy,ox,oy;
int dx[] = {0,2,0,-2};
int dy[] = {2,0,-2,0};
bool G[MAX][MAX];
bool used[MAX][MAX];

inline bool isValid(int nx,int ny){ return ( 0 <= nx && nx <= 2*W && 0 <= ny && ny <= 2*H ); }

int getValue(){
  if( ix == ox && iy == oy )return 0;
  rep(i,2*H+1)rep(j,2*W+1)used[i][j] = false;
  deque<Data> deq;
  deq.push_back(Data(ix,iy,0));
  used[iy][ix] = true;
  while(!deq.empty()){
    Data data = deq.front(); deq.pop_front();
    int x = data.x, y = data.y;
    rep(i,4){
      int nx = x + dx[i],ny = y + dy[i];
      int mx = (x+nx) / 2, my = (y+ny) / 2;
      if(!isValid(nx,ny))continue;
      if( G[my][mx] )continue;
      if(used[ny][nx])continue;
      used[ny][nx] = true;
      if( nx == ox && ny == oy )return data.cost + 1;
      deq.push_back(Data(nx,ny,data.cost+1));
    }
  }
  return IINF;
}

int main(){

  cin >> W >> H >> N;
  rep(i,2*H+1)G[i][0] = G[i][2*W] = true;
  rep(i,2*W+1)G[0][i] = G[2*H][i] = true;
  rep(i,N){
    int sx,sy,dx,dy;
    cin >> sx >> sy >> dx >> dy;
    sx <<= 1, sy <<= 1, dx <<= 1, dy <<= 1;
    REP(y,min(sy,dy),max(sy,dy)+1)REP(x,min(sx,dx),max(sx,dx)+1) G[y][x] = true;
  }

  cin >> ix >> iy >> ox >> oy;
  ix <<= 1, iy <<= 1,ox <<= 1, oy <<= 1;
  ix++,iy++,ox++,oy++;

  int tmp = getValue();
  int ans = 0;
  rep(y,2*H+1)rep(x,2*W+1){
    if( y == 0 || x == 0 || y == 2*H || x == 2*W )continue;
    if( !(y&1) && !(x&1) )continue;
    if(  (y&1) &&  (x&1) )continue;
    if( G[y][x] )continue;
    G[y][x] = true;
    int cost = getValue();
    if(cost != IINF)ans = max(ans,cost-tmp);
    G[y][x] = false;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
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; }

int D;
vector<int> c(26); 
vector<vector<int>> s(365, vector<int>(26));

int cal_score(vector<int> t){
    vector<int> res(D);
    int satis = 0;
    vector<int> last(26, 0);
    rep(d, D){
        satis += s[d][t[d] - 1];
        last[t[d] - 1] = d + 1;
        rep(i, 26){
            satis -= c[i] * (d - last[i] + 1);
        }
        res[d] = satis;
    }
    return res[D - 1];
}

int main(){
    // input 
    cin >> D;
    rep(i, 26) cin >> c[i];
    rep(i, D){
        rep(j, 26){
            cin >> s[i][j];
        }
    }

    // greedy
    vector<int> last(26, 0);
    vector<int> res(D);

    rep(d, D){
        int max_plus = -10000;
        int use = -1;
        rep(i, 26){
            int tmp = s[d][i] + c[i] * (d - last[i] + 1);
            if(max_plus < tmp){
                max_plus = tmp;
                use = i;
            }
        }
        last[use] = d + 1;
        res[d] = use + 1;
    }

    int cur_score = cal_score(res);

    while((clock() / (double)CLOCKS_PER_SEC) < 1.5){
        int ch_d = rand() % D + 1;
        int ch_c = rand() % 26 + 1;
        int old_c = res[ch_d - 1];
        res[ch_d - 1] = ch_c;
        int new_score = cal_score(res);
        if(cur_score < new_score){
            cur_score = new_score;
        }else{
            res[ch_d - 1] = old_c;
        }
    }

    rep(i, D){
        cout << res[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 3704
use strict;

use strict;

$_ = <>;
chomp;

my ($n, $m) = split(/\s+/);

$_ = <>;
chomp;
my @height = split(/\s+/);

my @way;

for (my $i = 0; $i < $m; $i++) {
    $_ = <>;
    chomp;
    my ($p1, $p2) = split(/\s+/);
    $p1--;
    $p2--;
    if ($way[$p1]) {
	push(@{$way[$p1]}, $p2);
    } else {
	$way[$p1] = [ $p2 ];
    }
    if ($way[$p2]) {
	push(@{$way[$p2]}, $p1);
    } else {
	$way[$p2] = [ $p1 ];
    }
}

my $good = 0;
for (my $i = 0; $i < $n; $i++) {
    if ($way[$i]) {
	my $ng = 0;
	foreach my $p (@{$way[$i]}) {
	    if ($height[$i] > $height[$p]) {
	    } else {
		$ng++;
	    }
	}
	if ($ng == 0) {
	    $good++;
	}
    } else {
	$good++;
    }
}
    
print "$good\n";


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

int main() {
  ll x;
  cin >> x;
  ll year = 0;
  double yen = 100;
  while (yen < x) {
    yen *= 1.01;
    yen = floor(yen);
    year++;
  }
  cout << year << endl;
  return 0;
}


Measured memory_bytes: 3624
import math
n = int(input())
a = list(map(int, input().split()))

class BIT:
    def __init__(self, n):
        self.n = n
        self.bit = [0]*(n+1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.bit[i]
            i -= i&(-i)
        return s

    def add(self, i, x):
        while i <= self.n:
            self.bit[i] += x
            i += i&(-i)
            
a_sorted = sorted(list(set(a)))
left, right = 0, len(a_sorted) # number of unique elements of a
while right-left > 1: # bisection search: O(logA)
    mid = (left+right)//2 # target index
    num = 0 # number of ranges with majority >= a_sorted[mid]
    bit = BIT(2*n+1) # initialize BIT: #regsum = bit.sum(regsum(+n))
    sum_ = 0 # region sum
    bit.add(sum_+n, 1)
    for i in range(n): # O(n)
        sum_ += 1 if a[i] >= a_sorted[mid] else -1 # update region sum by comaprison
        num += bit.sum(sum_+n) # add #ranges by sum_+n: O(logn)
        bit.add(sum_+n, 1) # increment BIT element at sum_+n(=count of interested regions)
    # print(bit.bit, left, right)

    # update search range
    if num >= math.ceil(n*(n+1)//4):
        left = mid
    else:
        right = mid
print(a_sorted[left])


Measured memory_bytes: 88220
import java.util.*;
 
public class Main {
    public static void main(String[] args){
		int mod = 2019;
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		StringBuilder sb = new StringBuilder(s);
		sb.reverse();
		int[] a = new int[s.length()+1];
		a[0] = 0;
		int x = 1;
		for(int i=0; i<s.length(); i++){
			int tmp = (sb.charAt(i) - '0')*x;
			a[i+1] = (a[i] + tmp)%mod;
			x = x*10%mod;
		}
		Map<Integer, Integer> map = new HashMap<>();
		for(int i: a){
			Integer t = map.get(i);
			if(t == null){
				map.put(i, 1);
			} else {
				map.put(i, t+1);
			}
		}
		int ans = 0;
		for (Integer v : map.values()) {
			if(v > 1){
				ans += v*(v-1)/2;
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 41012
import math,sys,bisect,heapq
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
sys.setrecursionlimit(200000000)
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
def list2d(a, b, c): return [[c] * b for i in range(a)]
#def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
MOD = 1000000000 + 7
def Y(c):  print(["NO","YES"][c])
def y(c):  print(["no","yes"][c])
def Yy(c):  print(["No","Yes"][c])


G = defaultdict(list)
first = 1 #  if node starts from 1

def addEdge(a,b):
    G[a].append(b)
	
def DFSutil(node,vis,size):
    vis[node] = True
    for child in G.get(node,[]):
        if vis[child] ==  False:
            DFSutil(child,vis,size)
        size[node] = max(size[node],1 + size[child])
    
def findsubtree(first,N):
    vis = [False] * (N+1)
    size = [0]* (N+1)
    for i in range(1,N+1):
        if vis[i] == False:
            DFSutil(i,vis,size)
    return max(size)
        
N,M = ilele()
G = defaultdict(list)
for i in range(M):
    u,v =ilele()
    addEdge(u,v)
print(findsubtree(first,N)) #returns size of each node in the array

Measured memory_bytes: 159676
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b,acount=0,bcount=0;
  cin >> n >>a >>b;
  string s;
  cin >>s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='a'){
      acount++;
      if(acount+bcount<=a+b)cout <<"Yes"<<endl;
      else {
        cout <<"No"<<endl;
        acount--;
      }
    }
    else if(s[i]=='b'){
      bcount++;
      if(acount+bcount<=a+b && bcount<=b)cout <<"Yes"<<endl;
      else {
        cout <<"No"<<endl;
        bcount--;
      }
    }
    else cout <<"No"<<endl;
  }
}


Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define db(x)	{ cerr << #x << " = " << x << endl; }

int32_t main(){
	int a,b,c,d; cin>>a>>b>>c>>d;
	int f=0;
	while(a>0&&c>0){
		if(f==0){
			c=c-b;
			f=1;
		}else{
			a=a-d;
			f=0;
		}
	}
	if(f==0) cout<<"No";
	else cout<<"Yes";
return 0;
}
// g++ -std=c++17 -Wshadow -Wall -o "sol" "sol.cpp" -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG

Measured memory_bytes: 3632
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define MP make_pair
#define MT make_tuple
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

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


LL ret = 0;
string S;
int N;
void solve(int bits){
	LL tmp = 0;
	if(bits == (1 << (N))) return;
	int pre = 0;
	REP(i, N){
		if((1 << (N - 1 - i)) & bits){
			tmp += stoll(S.substr(pre, i - pre + 1));
			pre = i + 1;
		}
	}
	if(pre < N) tmp += stoll(S.substr(pre, N - pre));
	//cout << tmp << endl;
	ret += tmp;
	solve(bits + 1);
}

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

	cin >> S;

	N = S.length();

	solve(0);

	cout << ret / 2 << endl;

	return 0;
}


Measured memory_bytes: 384
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    double[] p = new double[n+1];
    for(int i=1;i<=n;i++)p[i]=sc.nextDouble();
    double[][] dp = new double[n+1][n+1];
    dp[1][1]=p[1];
    dp[1][0]=1-p[1];
    for(int i=2;i<=n;i++){
      for(int j=0;j<=i;j++)
        if(j==0)dp[i][j]=dp[i-1][0]*(1-p[i]);
        else dp[i][j]=dp[i-1][j-1]*p[i]+dp[i-1][j]*(1-p[i]);
    }
    /*
    for(int i=0;i<=n;i++) {
    	System.out.println(Arrays.toString(dp[i]));
    }
    */
    double ans = 0;
    for(int i=(n+1)/2;i<=n;i++)ans+=dp[n][i];
    System.out.println(ans);
  }
}

Measured memory_bytes: 123716
<?php

while (($line = trim(fgets(STDIN))) !== '') {
    $arr = array((float)$line);
    for ($i = 1; $i < 10; $i++) {
        $prev = $arr[$i - 1];
        if ($i % 2 === 1) {
            $arr[$i] = $prev * 2;
        } else {
            $arr[$i] = $prev / 3;
        }
    }
    echo array_sum($arr), PHP_EOL;
}

Measured memory_bytes: 6620
#include <bits/stdc++.h>
using namespace std;
#define N 110000
int n,ans;
int a[N];
int main()
{
	//freopen("tt.in","r",stdin);
	scanf("%d",&n);
	int now=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]==i)now++;
		else if(now)ans+=(now+1)/2,now=0;
	}
	if(now)ans+=(now+1)/2;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main(void){
   int n, i, p, d1, d2, D, Max, Max_p;
   scanf("%d", &n);
   while ( n ) {
      Max = Max_p = 0;
      for ( i = 0; i < n; i++ ) {
         scanf("%d %d %d", &p, &d1, &d2);
         D = d1 + d2;
         if ( D > Max) {
            Max = D;
            Max_p = p;
         }
      }
      printf("%d %d\n", Max_p, Max);
      scanf("%d", &n);
   }
   return 0;
}

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

using namespace std;

using int64 = long long;

struct FlowEdge {
  const int from, to;
  const int64 cap;  // Capacity
  FlowEdge(int from, int to, int64 cap) : from(from), to(to), cap(cap) {}
};

int64 MaxFlow(int n, const vector<FlowEdge>& edges, int s, int t) {
  int m = edges.size();
  
  vector<vector<tuple<FlowEdge, int>>> graph(n);
  vector<int64> res_caps(2 * m);  // Edge ID to residual capacity
  vector<int> to_reverse(2 * m, -1);  // Edge ID to the reverse edge ID
  for (int i = 0; i < m; i++) {
    const auto& edge = edges[i];
    graph[edge.from].push_back(make_tuple(edge, i));
    graph[edge.to].push_back(
        make_tuple(FlowEdge(edge.to, edge.from, 0), m + i));
    res_caps[i] = edge.cap;
    to_reverse[i] = m + i;
    to_reverse[m + i] = i;
  }

  int64 total = 0;
  while (true) {
    queue<int> q;
    vector<int> prevs(n, -1);
    vector<int> used_edges(n, -1);
    q.push(s);
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      for (const auto& edge_tuple : graph[v]) {
        FlowEdge edge = get<0>(edge_tuple);
        int edge_id = get<1>(edge_tuple);
        if (res_caps[edge_id] == 0 || prevs[edge.to] >= 0) continue;
        prevs[edge.to] = v;
        used_edges[edge.to] = edge_id;
        q.push(edge.to);
      }
    }

    if (prevs[t] == -1) return total;

    int cur = t;
    vector<int> path;
    while (cur != s) {
      path.push_back(used_edges[cur]);
      cur = prevs[cur];
    }

    int64 inc = INT64_MAX;
    for (int edge_id : path) {
      inc = min(inc, res_caps[edge_id]);
    }

    total += inc;

    for (int edge_id : path) {
      res_caps[edge_id] -= inc;
      res_caps[to_reverse[edge_id]] += inc;
    }
  }
}

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

  int n, m;
  cin >> n >> m;

  vector<FlowEdge> edges;
  for (int i = 0; i < m; i++) {
    int v1, v2;
    int64 c;
    cin >> v1 >> v2 >> c;
    edges.push_back(FlowEdge(v1, v2, c));
  }
  int64 max_flow = MaxFlow(n, edges, 0, n - 1);
  cout << max_flow << endl;
}



Measured memory_bytes: 3356
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */

int main() {
  ll n , x; cin >> n >> x;
  vector<ll> a(n);
  REP(i, n) cin >> a[i];

  sort(ALL(a));
  ll ans = 0;
  REP(i, n){
    if(x>=a[i] && i < n-1){
      ans++;
      x -= a[i];
    }else if(i == n-1 && x == a[i]){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>  // assert(x>=10), 部分点問題
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <set>

#define repl(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
#define SORT(v,n) sort(v,v+n)
#define VSORT(v) sort(all(x))
#define FILL(v, value) (v+(sizeof(v) / sizeof *(v)), value);
#define inf 999999999
#define dbg(x) cout<<#x<<":"<<x<<endl;
#define pb(a) push_back((a))
#define mp(a) make_pair((a))
#define pi 2*acos(0.0)
#define in scanf
#define out printf
#define fi first
#define se second
#define bit(n) (1LL<<(n))

using namespace std;

typedef long long llong;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;
typedef pair<llong, pll> plp;

const int MOD=1000000007;
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};  // 右下左上


int main(int argc, char**argv){
  int n;
  cin >> n;
  vector<string> v;
  rep(i, n){
    string tmp;
    cin >> tmp;
    v.push_back(tmp);
  }

  int num[n][30];
  rep(i, n) rep(j, 30) num[i][j] = 0;

  int ans[30];
  rep(i, 30) ans[i] = 0;

  rep(i, n){
    string s = v[i];
    rep(j, s.size()){
      num[i][s[j] - 'a']++;
      // dbg(n)
    }
  }


  rep(i, 30){
    int m = inf;
    rep(j, n){
      m = min(m, num[j][i]);
    }
    ans[i] = m;
  }

  // rep(i, n) rep(j, 30){
  //   dbg(num[i][j]);
  // }
  // rep(i, 30) dbg(ans[i]);

  string a = "abcdefghijklmnopqrstuvwxyzaaaaaaaaaa";
  rep(i, 30){
    int loop = ans[i];
    rep(j, loop){
      cout << a[i];
    }
  }
  cout << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define endl '\n'
using ll=long long;
 
const int INF=1e9+5;
const ll lim=(ll)3e16;
const int N=510000;
const int mod=1e9+7;
const ll oo=1e18+5;

	

int main(){
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
	ll n,a,b;
	cin>>n>>a>>b;
	if(a%2==b%2){
		cout<<abs(a-b)/2<<endl;
		return 0;
	}
	ll diff=abs(a-b);
	ll need=min({a-1,b-1,n-a,n-b});
	cout<<need+1+(diff-1)/2<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>
#define mp make_pair
#define maxn 100005
using namespace std;
const int inf = 0x3f3f3f3f;
const int neginf = 0xc0c0c0c0;
typedef long long ll;
typedef pair<int,int> P;
int n,v[maxn];
int cnt[maxn];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&v[i]);
	for(int i=1;i<=n;i+=2) cnt[v[i]]++;
	int maxi1,nxtmaxi1,num1;
	maxi1 = nxtmaxi1 = 0;
	for(int i=1;i<=100000;i++){
		if(cnt[i] > maxi1){
			num1 = i;
			nxtmaxi1 = maxi1;
			maxi1 = cnt[i];
		}else if(cnt[i] > nxtmaxi1){
			nxtmaxi1 = cnt[i];
		}
	}
	memset(cnt,0,sizeof(cnt));
	for(int i=2;i<=n;i+=2) cnt[v[i]]++;
	int maxi2,nxtmaxi2,num2;
	maxi2 = nxtmaxi2 = 0;
	for(int i=1;i<=100000;i++){
		if(cnt[i] > maxi2){
			num2 = i;
			nxtmaxi2 = maxi2;
			maxi2 = cnt[i];
		}else if(cnt[i] > nxtmaxi2){
			nxtmaxi2 = cnt[i];
		}
	}
	int ans;
	if(num1 == num2) ans = max(nxtmaxi1 + maxi2,maxi1 + nxtmaxi2);
	else ans = maxi1 + maxi2;
	printf("%d\n",n - ans);
	return 0;
}


Measured memory_bytes: 1024
package main

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

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	q := getNextInt(scanner)
	s := map[int]int{}
	for i := 0; i < q; i++ {
		t := getNextInt(scanner)
		x := getNextInt(scanner)
		if t == 0 {
			s[x] = 1
			fmt.Fprintln(writer, len(s))
			continue
		}
		fmt.Fprintln(writer, s[x])
	}
}



Measured memory_bytes: 13872
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    int m, f, r, total;
    char c;
    while (cin >> m >> f >> r && (m + f + r > -3))
    {
        total = m + f;
        if (m == -1 || f == -1)
            c = 'F';
        else if (total >= 80)
            c = 'A';
        else if (total >= 65)
            c = 'B';
        else if (total >= 50)
            c = 'C';
        else if (total >= 30)
        {
            if (r >= 50)
                c = 'C';
            else
                c = 'D';
        }
        else
            c = 'F';
        cout << c << endl;
    }
    return 0;
}



Measured memory_bytes: 3100
nk = [int(s) for s in input().split()]
n = nk[0]
k = nk[1]

p = [int(s)+1 for s in input().split()]
l = [sum(p[:k])]

for x in range(n-k):
  l.append(l[x]-p[x]+p[x+k])
print(max(l)/2)

Measured memory_bytes: 25188
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <cstdio>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif
using namespace std;
int main() {
  int a,b;
  cin >> a >> b;
  cout << a+1-b;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
sort(all(list));
sort(all(list), greater<int>());
//配列の内容表示
dout << "====listの内容====\n";
for (int i = 0; i < N; i++) dout << list[i] << endl;
dout << "====ここまで====\n";
*/


Measured memory_bytes: 256
N,T=map(int,input().split())
S=list(map(int,input().split()))
U=[]
for i in range(N-1):
    if S[i+1]-S[i]<T:
        U.append(S[i+1]-S[i])
    else:
        U.append(T)
U.append(T)

print(sum(U))

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

int main(){
  int loop = 0;
  int addValue = 0;
  int displayNum = 1;
  
  cin >> loop >> addValue;
  
  for(int i = 0; i < loop; i++){    
    if(displayNum * 2 - displayNum < addValue){
      displayNum *= 2;
    }
    else{
      displayNum += addValue;
    }
  } 
  cout << displayNum << endl;
}

Measured memory_bytes: 256
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

def enum_prime(n):
    if n < 2:
        return []
    if n == 2:
        return [2]
    L = list(range(2, n + 1))
    PL = []
    while True:
        PL.append(L[0])
        L = [i for i in L if i % PL[-1] != 0]
        if L[-1] < PL[-1] ** 2:
            return PL + L

primelist = enum_prime(999999)
for line in stdin:
    n = int(line)
    cnt = 0
    for p in primelist:
        if n < p:
            break
        cnt += 1
    print(cnt)

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

priority_queue<int> Q;

int main() {
    
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    int N, M;
    cin >> N >> M;

    for(int i=1; i<=N; i++)
    {
        int x;
        cin >> x;

        Q.push(x);
    }

    while(M--)
    {
        int x = Q.top();
        Q.pop();

        Q.push(x/2);
    }

    long long ans = 0;

    while(!Q.empty())
    {
        ans += Q.top();
        Q.pop();
    }

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


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    ll n;cin >> n;
    ll res = 0;
    res+=n/500 * 1000;
    res+=(n%500)/5 * 5;
    out(res);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
int main(){
    int a,b,c,x;
    cin >> a >> b >> c >> x;
    int cnt=0;
    for(int i=a;i>=0;i--){
        for(int j=b;j>=0;j--){
            for(int k=c;k>=0;k--){
                if(500*i+100*j+50*k==x) ++cnt;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
      	//データ取り込み
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
    	int M = sc.nextInt();
      	//String S = sc.next();
      	//int list[] = new int[N];
      	//for(int i=0;i<N;i++){
        //	list[i] = sc.nextInt();
        //}
      	//Arrays.sort(list);
      	if(N<=8&&M<=8){
        	System.out.println("Yay!");
        }else{
        	System.out.println(":(");
        }
      	
    }
}

Measured memory_bytes: 22996
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size)
#define MOD 1000000007
const long long mod = 1e9+7;
typedef vector<long long> Vl;
typedef vector<double> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<VS> VSS;  
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef long long ll;  //ll とdoubleは違う
// cout << << endl;
// cin >> ;
int main(){
    ll c=0,d=0,n,m1,n2,m2,min=100000,k=0,ans=0;
    string s,s2;
    cin >> n;
    VI a(n);
    rep(i,n) cin >> a[i];
    sort(ALL(a));
    for(int i=n-1;i>=0;i-=2){
        c += a[i];
        d += a[i-1];
    }
    cout << c-d <<endl; 
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define MAXN 55
int main(){
	int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
	int m,n;
	char map[MAXN][MAXN];
	cin>>m>>n;
	for(int i=0;i<m;i++){
		for(int j=0;j<n;j++){
			cin>>map[i][j];
		}
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<n;j++){
			if(map[i][j]=='#'){
				int flag=0;
				for(int k=0;k<4;k++){
					//	cout<<k;
					int nx=i+dx[k],ny=j+dy[k];
					if(nx>=0&&nx<m&&ny>=0&&ny<n&&map[nx][ny]=='#'){
						flag=1;
						break;
					}
				}
				if(flag==0){
					cout<<"No"<<endl;
					return 0;
				}
			}
			
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

namespace std {
	template<class Ty, size_t Ix>
	struct rank<std::array<Ty,Ix>>
		: integral_constant<size_t, rank<Ty>::value + 1>
	{	// determine number of dimensions of array _Ty
	};
}

template<typename T, typename U>
std::enable_if_t<std::rank<T>::value == 0> fill_all(T& arr, const U& v) {
	arr = v;
}
template<typename ARR, typename U>
std::enable_if_t<std::rank<ARR>::value != 0> fill_all(ARR& arr, const U& v) {
	for (auto& i : arr) {
		fill_all(i, v);
	}
}

int32_t N;
int32_t INF = 100100;
std::array<std::array<int32_t, 100>,100> dp;
std::array<std::array<int32_t, 100>, 100> dp2;
void WF() {
	for (size_t k = 0; k < N; k++)
		for (size_t i = 0; i < N; i++)
			for (size_t j = 0; j < N; j++)
	{
		dp[i][j] = std::min(dp[i][j], dp[i][k] + dp[k][j]);
	}
}

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	fill_all(dp, INF);
	in >> N;
	for (int32_t i = 0; i < N; i++)
	{
		int from,m;
		in >> from >> m; --from;
		dp[from][from] = 0;
		for (int32_t j = 0; j < m; j++)
		{
			int to;
			in >> to; --to;
			dp[from][to] = 1;
		}
	}

	WF();
	dp2 = dp;
	WF();
		for (int32_t i = 0; i < N; i++)
		{
			out << i + 1 << ' ' << (dp[0][i]!=INF? dp[0][i]:-1) << endl;
		}

	return 0;
}
#endif



Measured memory_bytes: 3280
#include <bits/stdc++.h>
#define pp pair<int,int>
#define fi first
#define si second
using namespace std;

int main() {
	// your code goes here
	int n,m;
	cin>>n>>m;
	vector<pp>v[n];
	for(int i=1,j=m+1;i<j;i++,j--){
		cout<<i<<' '<<j<<'\n';
	}
	for(int i=m+2,j=2*m+1;i<j;i++,j--){
		cout<<i<<' '<<j<<'\n';
	}
	return 0;
}

Measured memory_bytes: 7644
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

class unionfind {
private:
	int* parent;
public:
	unionfind(int nodes) {
		parent = new int[nodes];
		for(int i = 0;i < nodes;i++) parent[i] = -1;
	}
	~unionfind() {
		delete parent;
	}
	int root(int n) {
		if(parent[n] == -1) return n;
		int res = root(parent[n]);
		parent[n] = res;
		return res;
	}
	bool same(int a,int b) {
		return root(a) == root(b);
	}
	void merge(int a,int b) {
		parent[root(a)] = root(b);
	}
};

int main(void) {
	int v,e,s,t,w;
	cin >> v >> e;
	vector<pair<int,pair<int,int>>> path;
	for(int i = 0;i < e;i++) {
		cin >> s >> t >> w;
		path.push_back(make_pair(w,make_pair(s,t)));
	}
	sort(path.begin(),path.end());
	int res = 0;
	unionfind u = unionfind(v);
	for(auto& e:path) {
		if(!u.same(e.second.first,e.second.second)) {
			res += e.first;
			u.merge(e.second.first,e.second.second);
		}
	}
	cout << res << endl;
}



Measured memory_bytes: 4536
h = Hash.new
a = Array.new(3).map { Array.new(3){0} }

def fin
  puts 'Yes'
  exit
end

3.times do |i|
  gets.strip.split.each_with_index do |c, j|
    h[c] = [i, j]
  end
end

N = gets.strip.to_i

N.times do
  b = gets.strip
  if h.has_key?(b)
    x, y = h[b]
    a[x][y] = 1
  end
end

# 横
fin if a.map { |ah| ah.inject(:+) }.select { |n| n.eql?(3) }.size > 0 

# 縦
fin if a.transpose.map { |av| av.inject(:+) }.select { |n| n.eql?(3) }.size > 0

# 斜め
fin if (a[0][0] + a[1][1] + a[2][2]).eql?(3)
fin if (a[2][0] + a[1][1] + a[0][2]).eql?(3)

puts 'No'


Measured memory_bytes: 1788
import sys

k = int(sys.stdin.readline().rstrip())

def main(k):
    if k <= 9:
        print(k)
        return
    res = list(range(1, 10))
    k -= 9
    while True:
        nex = []
        for n in res:
            r = n % 10
            n *= 10
            for i in range(-1, 2):
                if 0 <= r + i <= 9:
                    nex.append(n + r + i)
                    k -= 1
                    if not k:
                        print(nex[-1])
                        return
        res = nex.copy()

if __name__ == '__main__':
    main(k)

Measured memory_bytes: 6180