akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define fs first
#define se second
#define M 1000000007

vector<ll>tree(100000,LLONG_MAX);
void build(ll s,ll e,ll p,vector<ll>&arr)
{
	if(s==e)
	{
		tree[p]=arr[s];
		return;
	}
	ll mid=(s+e)/2;
	build(s,mid,2*p+1,arr);
	build(mid+1,e,2*p+2,arr);
	tree[p]=min(tree[2*p+1],tree[2*p+2]);
}

ll query(ll s,ll e,ll l,ll u, ll p)
{
	if(e<l || s>u)
		return LLONG_MAX;
	else if(s<=l && u<=e && l<=u)
		return tree[p];
	ll mid=(l+u)/2;
	ll left=query(s,e,l,mid,2*p+1);
	ll right=query(s,e,mid+1,u,2*p+2);
	return min(left,right);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n;
	cin>>n;
	unordered_map<string,ll>um;
	ll m=0;
	for(ll i=0;i<n;i++)
	{
		string s;
		cin>>s;
		um[s]++;
		m=max(m,um[s]);
	}
	vector<pair<ll,string>>h;
	for(auto i:um)
	{
		string st=i.fs;
		ll num=i.se;
		h.pb({num,st});
	}
	sort(h.begin(),h.end());
	for(ll i=0;i<h.size();i++)
	{
		if(h[i].fs==m)
			cout<<h[i].se<<endl;
	}

}

Measured memory_bytes: 28484
import heapq
from collections import deque
from copy import copy
n,k = map(int,input().split())
d = deque(list(map(int,input().split())))
maxvalue = 0
for i in range(k+1):
    for j in range(k-i+1):
        jewel = []
        x = copy(d)
        for _ in range(i):
            if x:
                jewel.append(x.popleft())
        for _ in range(j):
            if x:
                jewel.append(x.pop())
        heapq.heapify(jewel)
        for _ in range(k-i-j):
            if jewel:
                a = heapq.heappop(jewel)
                if a >= 0:
                    jewel.append(a)
                    break
        maxvalue = max(maxvalue,sum(jewel))
print(maxvalue)

Measured memory_bytes: 56412
#include<iostream>
using namespace std;
int main(){
    int n;
    cin >> n;
    int cnt = 0;
    for(int i = 0; i < n; i++){
        int area;
        cin >> area;
        for(int x = 1; 2*x*x + 2*x <= area; x++){
            if((area-x)%(2*x+1) == 0){
                cnt++;
                break;
            }
        }
    }
    cout << n - cnt << endl;
}



Measured memory_bytes: 3096
x, k, d = map(int, input().split())
if abs(x) > d:
    tmp = min(abs(x) // d, k)
    if x < 0:
        x += d * tmp
        k -= tmp
    else:
        x -= d * tmp
        k -= tmp

ans = x
if k > 0 and x >= 0:
    if k % 2 != 0:
        ans = x - d
    else:
        ans = x
elif k > 0:
    if k % 2 != 0:
        ans = x + d
    else:
        ans = x

print(abs(ans))

Measured memory_bytes: 61856
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include <climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
struct P {
	ll pos, cost;
	bool operator<(const P &b) const{ return cost < b.cost; }
	bool operator>(const P &b) const{ return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const{ return cost < b.cost; }
	bool operator>(const E &b) const{ return cost > b.cost; }
};
struct H {
	ll x, y;
	bool operator<(const H &b) const{
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const{
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const{ return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const{ return (*this) != b; }
};
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ld mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int a[40];
signed main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;
		for (int j = 0; j < k; j++) {
			int t;
			cin >> t;
			a[t]++;
		}
	}
	int ans = 0;
	for (int i = 0; i < 40; i++) {
		if (a[i] == n) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
using namespace std;

string LCS(string &a,string &b){
	int m=a.size(),n=b.size();
	string ret="";
	int DP[m+1][n+1]={};
	for(int i=1;i<=m;i++){
		for(int j=1;j<=n;j++){
			if(a[i-1]==b[j-1]){
				DP[i][j]=1+DP[i-1][j-1];
			}else{
				DP[i][j]=max(DP[i-1][j],DP[i][j-1]);
			}
		}
	}
	int i=m,j=n;
	while(i>0 && j>0){
//		cerr<<"a";
		if(a[i-1]==b[j-1]){
			ret=a[i-1]+ret;
			i--,j--;
		}
		else if(DP[i-1][j]>DP[i][j-1]){
			i--;
		}
		else{
			j--;
		}
	}
	return ret;
}

int main(){
	string a,b;
	cin>>a>>b;
	cout<<LCS(a,b)<<endl;
	return 0;
}

Measured memory_bytes: 35456
import sys
import collections
import math
from collections import Counter
from collections import deque

n = int(input())
A = [int(x) for x in input().split()]

Q = deque()

f = True
if n % 2 == 0:
    f = not f

for a in A:
    if f:
        Q.appendleft(a)
    else:
        Q.append(a)
    f = not f

print(" ".join([str(q) for q in Q]))

sys.exit(0)


Measured memory_bytes: 29124
import java.util.*;

public class Main {
    static int WHITE = 0;
    static int GRAY = 1;
    static int BLACK = 2;

    static class kvPair {
        int point;
        int value;

        kvPair(int point, int value) {
            this.point = point;
            this.value = value;
        }
    }

    // 构建比较器
    static Comparator<kvPair> cKvPair=new Comparator<kvPair>() {
        public int compare(kvPair o1, kvPair o2) {
            if(o1.value!=o2.value) // 先比较边权值，按升序排序
                return o1.value-o2.value;
            else // 再比较点编号，按升序排序
                return o1.point-o2.point;
        }

    };

    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        ArrayList<ArrayList<kvPair>> adj = new ArrayList<>();
        for(int i = 0; i < n; i++) {
            adj.add(new ArrayList<kvPair>());
        }
        for (int i = 0; i < n; i++) {
            int u = input.nextInt();
            int k = input.nextInt();
            for (int j = 0; j < k; j++) {
                int v = input.nextInt();
                int c = input.nextInt();
                adj.get(u).add(new kvPair(v, c));
            }
        }

        Queue<kvPair> PQ = new PriorityQueue<>(cKvPair);
        int[] color = new int[n];
        int[] d = new int[n];

        for(int i = 0; i < n; i++) {
            d[i] = Integer.MAX_VALUE;
            color[i] = WHITE;
        }

        d[0] = 0;
        PQ.add(new kvPair(0,0));
        color[0] = GRAY;

        while(!PQ.isEmpty()){
            kvPair f = PQ.poll();
            int u = f.point;
            color[u] = BLACK;

            // 取出最小值，如果不是最短路径则忽略
            if(d[u] < f.value) continue;

            for(int i = 0; i < adj.get(u).size(); i++){
                int v = adj.get(u).get(i).point;
                if(color[v] == BLACK) continue;
                if(d[v] > d[u] + adj.get(u).get(i).value) {
                    d[v] = d[u] + adj.get(u).get(i).value;
                    PQ.add(new kvPair(v, d[v]));
                    color[v] = GRAY;
                }
            }
        }
        for(int i = 0; i < n; i++) {
            System.out.println(i + " " + d[i]);
        }
    }
}



Measured memory_bytes: 276928
a, b, c = map(int, input().split())
k = int(input())
list_ANS = [a, b, c]
list_ANS.sort(reverse=True)
d = list_ANS.pop(0)
for _ in range(k):
    d *= 2
list_ANS.append(d)
print(sum(list_ANS))

Measured memory_bytes: 3060
// ITP1_8_D Ring
import java.io.*;
 
class Main {
 
   public static void main(String[] args) {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 
      try {
         String s = br.readLine();
         String p = br.readLine();
         s = s + s;
         if (s.equals("") || p.equals(""))
            System.exit(0);
         if (s.indexOf(p) != -1)
            System.out.println("Yes");
         else
            System.out.println("No");
      }
 
      catch (Exception e) {
         System.err.println(e);
      }
   }
}

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

// repetition
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

// const value
// const ll MOD = 1e9 + 7;
// const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
// const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
inline ll toLL(string s) {
  ll v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T> inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}

template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  VI a(n);
  rep(i, n) cin >> a[i];
  sort(all(a), greater<>());
  ll ans = 0;
  rep(i, k) ans += a[i];
  cout << ans << "\n";
  return 0;
}


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

int main()
{
    int A, B, C;

    cin >> A >> B >> C;

    int result = C - ( A - B );
    if ( result > 0 )
    {
        cout << result << endl;
    }
    else
    {
        cout << 0 << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,a=0; cin>>n;
  int l[n],r[n]; for(int i=0; i<n; i++) cin>>l[i]>>r[i];
  for(int i=0; i<n; i++) a+=r[i]-l[i]+1;
  cout<<a;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<limits.h>

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define revrep(i,begin,end) for(int i=begin; i>end; i--)
#define lld long long int

#define MOD 1000000007
#define MAX 100001
long long int fac[MAX], finv[MAX], inv[MAX];
void MOD_COM_init(){
    fac[0] = 1;
    fac[1] = 1;
    finv[0] = 1;
    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 int MOD_combination(long long int n,long long int r){
    if(r<0||n<0){
        return 0;
    }
    if(n < r){
        return 0;
    }
    return (fac[n] * (finv[r] * finv[n-r] % MOD)) % MOD;
}

long long int MOD_pow(long long int a, long long int n){
    long long int res = 1;
    while(n>0){
        if(n&1){
            res = res*a % MOD;
        }
        a = a*a % MOD;
        n >>= 1;
    }
    return res;
}

int cmpAsc(const void* a, const void* b){
    long long int x = *(long long int*)a, y = *(long long int*)b;
    if(x > y){
        return 1;
    }
    if(x < y){
        return -1;
    }
    return 0;
}

int main(){
    int n, k;
    scanf("%d %d", &n, &k);
    lld a[n];
    rep(i, 0, n){
        scanf("%lld", &a[i]);
    }
    qsort(a, n, sizeof(lld), cmpAsc);
    MOD_COM_init();
    lld sum_max = 0;
    lld sum_min = 0;
    rep(i, 0, n){
        sum_max += MOD_combination((lld)(i), (lld)(k-1)) * a[i];
        if(sum_max < 0){
            sum_max += (-1 * sum_max + MOD - 1) / MOD * MOD;
        }
        sum_max %= MOD;
        sum_min += MOD_combination((lld)(n-i-1), (lld)(k-1)) * a[i];
        if(sum_min < 0){
            sum_min += (-1 * sum_min + MOD - 1) / MOD * MOD;
        }
        sum_min %= MOD;
    }
    lld ans = sum_max - sum_min;
    while(ans < 0){
        ans += MOD;
    }
    printf("%lld", ans);

    return 0;
}

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

int main(void)
{
    int n, x, y;
    cin >> n >> x >> y;
    
    vector<int> dis_v(n,0);
    for (int i = 1; i <= n; i++) {
        for (int j = i+1; j <= n; j++) {
            int dis = min(j-i, abs(x-i) + abs(j-y) + 1);
            dis_v.at(dis)++;
        }
    }
    
    for(int i = 1; i < n; i++) {
        cout << dis_v.at(i) << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, w, a[105], b[105];
ll dt[105][105][305], ans;

int main()
{
	scanf("%lld%lld",&n,&w);
	for(ll i=1;i<=n;i++) {
		scanf("%lld%lld",&a[i],&b[i]);
		for(ll j=0;j<=n;j++) {
			for(ll k=0;k<=3*n;k++) {
				dt[i][j][k] = dt[i-1][j][k];
			}
		}
		for(ll j=1;j<=n;j++) {
			for(ll k=a[i]-a[1];k<=3*n;k++) {
				dt[i][j][k] = max(dt[i][j][k], dt[i-1][j-1][k-a[i]+a[1]] + b[i]);
			}
		}
	}
	for(ll j=0;j<=n;j++) {
		for(ll k=0;k<=3*n;k++) {
			if(j*a[1]+k <= w) ans = max(ans, dt[n][j][k]);
		}
	}
	printf("%lld\n",ans);
}


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

ll n, k;

int main(){
	scanf("%lld%lld", &n, &k);
	ll ans = 0;
	for(ll i = k; i <= n+1; i++){
		ll mn = (i-1) * i / 2, mx = (n-i+1 + n) * i / 2;
		ans += (mx - mn + 1);
		ans %= 1000000007;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3764
from sys import stdin

input = stdin.readline

s = input().strip()
t = input().strip()

ns = len(s)
nt = len(t)

def cnt(a,b):
    return sum(1 for aa,bb in zip(a,b) if aa != bb)

res = nt
for i in range(ns - nt + 1):
    res = min(res,cnt(s[i:i+nt],t))

print(res)

Measured memory_bytes: 73436
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <stack>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#define int long long
#define ll long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
#define MIN -(9223372036854775807 / 2)
#define INF 9223372036854775807 / 2
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define mp make_pair


using namespace std;

std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

using Weight = int;
using Flow = int;
struct Edge {
	int src, dst;
	Weight weight;
	Flow cap;
	Edge() : src(0), dst(0), weight(0) {}
	Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph &g, int a, int b, Weight w = 1) {
	g[a].emplace_back(a, b, w);
	g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }

struct uf_tree {
	std::vector<int> parent;
	int __size;
	uf_tree(int size_) : parent(size_, -1), __size(size_) {}
	void unite(int x, int y) {
		if ((x = find(x)) != (y = find(y))) {
			if (parent[y] < parent[x]) std::swap(x, y);
			parent[x] += parent[y];
			parent[y] = x;
			__size--;
		}
	}
	bool is_same(int x, int y) { return find(x) == find(y); }
	int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
	int size(int x) { return -parent[find(x)]; }
	int size() { return __size; }
};

//!!!問題をちゃんと読む!!!
//!!!問題をちゃんと読め!!!
//!!!問題は読みましたか？!!!

string sts[100000];
signed main() {
	int N;
	cin >> N;
	
	//N = (m+1)p なる整数pを求めればOK、O(sqrt(N))
	vector<int> div;

	for (int p = 1; p * p <= N; p++) {
		if (N%p != 0) continue;
		if (p*p == N) {
			div.push_back(p);
		}
		else {
			div.push_back(p);
			div.push_back(N / p);
		}
	}

	int ans = 0;
	for (int p : div) {
		int m = N / p - 1;
		if (!(m > p)) continue;
		ans += m;
	}
	cout << ans << "\n";


	return 0;
}

Measured memory_bytes: 1152
// ~zaletaet~

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

#define fi first
#define se second
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define bpc __builtin_popcountl
#define fre(f) if(fopen(f".in", "r")) freopen(f".in", "r", stdin),freopen(f".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
using db = double;
using ld = long double;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <class T>
using p_queue = priority_queue<T, vector<T>, greater<T>>;
struct chash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + RANDOM);
  }
};

const ll N = 1e5 + 123, MOD = 1e9 + 7, oo = 1e9 + 9, INF = 1e18 + 9;
const db EPS = 1e-9, PI = acos(-1); // 3.14159265358979323846
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

int32_t main() {
  fre("");
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  
  int x, n;
  cin >> x >> n;
  set<int> s;
  for (int i = 1, x; i <= n; i++) {
    cin >> x;
    s.insert(x);
  }

  for (int d = 0; d <= 100000; d++) {
    if (!s.count(x - d)) {
      cout << x - d;
      return 0;
    }
    if (!s.count(x + d)) {
      cout << x + d;
      return 0;
    }
  }

  return 0;
}

// uniform_int_distribution<int>(l, r)(rng) -> random in range [l, r]
// assert(condition) -> if (condition == false) Runtime Error
// order_of_key(x) -> number of elements smaller than x
// *find_by_order(k) -> k-th element in 0-based indexation
// gp_hash_table<T, U, chash> -> fast unordered_map
// m.count(x) <-> (m.find(x) != m.end())


Measured memory_bytes: 3648
#include <iostream>

using namespace std;

int main()
{
    int h, w, n;
    n = 0;
    cin >> h >> w;

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            char c;
            cin >> c;
            if(c == '#'){
                n++;
            }
        }
    }

    if(n == h - 1 + w){
        cout << "Possible" << endl;
    }
    else{
        cout << "Impossible" << endl;
    }


    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10000000)
INF = 1<<32


def solve(N: int, W: "List[int]"):

    ans = INF
    for i in range(0, N-1):
        ans = min(ans, abs(sum(W[:i+1])-sum(W[i+1:])))

    print(ans)

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    W = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, W)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,co=0;
    double he=0;
    while(cin>>n){
        he=sqrt(n);
        int ser[n+1];
        for(int i=2;i<=n;i++)ser[i]=1;
        for(int i=2;i<=he;i++)if(ser[i]==1)for(int j=2;j*i<=n;j++)ser[i*j]=0;
        for(int i=2;i<=n;i++)if(ser[i]==1)co++;
        cout<<co<<endl;
        co=0;
    }
}

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

bool SortComp(long long int num1, long long int num2) { return num1 > num2 ? true : false; }

int main(void)
{
	while(1)
	{
		int num, pebble, winner;
		cin>>num>>pebble;

		if(!num && !pebble)
			break;

		bool check= true;
		int arr[50]= {};
		while(check)
		{
			for(int i= 0; i < num; i++)
			{
				if(pebble == 0)
				{
					pebble+= arr[i];
					arr[i]= 0;
				}
				else
				{
					pebble--;
					arr[i]++;

					if(pebble == 0)
					{
						for(int j= 0; j < num; j++)
						{
							if(i == j)
								continue;

							if(arr[j] != 0)
							{
								check= false;
								break;
							}
						}
						if(check)
						{
							winner= i;
							check= false;
							break;
						}
						else
							check= true;
					}
				}
			}
		}
		cout<<winner<<endl;
	}
	return 0;
}

Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s,t;
	cin>>s>>t;
	int cnt=0,lt=t.length(),ls=s.length();
	int m=1001;
	int sub=ls-lt;
	for (int i=0;i<=sub;i++)
	{
		for (int j=0;j<lt;j++)
		{
			if (s[i+j]!=t[j])
				cnt++;
		}
		m=min(m,cnt);
		cnt=0;
	}
	cout<<m;
} 

Measured memory_bytes: 3584
#include<stdio.h>
#include<stdio.h>
long compare(const void *a,const void *b){
  return *(long*)a-*(long*)b;
}

int main(){
  long n = 0;
  long a[200000] = {};
  long sorteda[200000] = {};
  long lowermid = 0;
  long highermid = 0;
  long i = 0;
  scanf("%ld",&n);
  for(i=0;i<n;i++){
    scanf("%lu",&a[i]);
  }
  memcpy(sorteda,a,sizeof(long)*n);
  qsort(sorteda,n,sizeof(long),compare);
  /*for(i=0;i<n;i++){
    printf("%ld\n",sorteda[i]);
  }*/
  lowermid = sorteda[n/2-1];
  highermid = sorteda[n/2];
  for(i=0;i<n;i++){
    if(a[i] >= highermid){
      printf("%d\n",lowermid);
    }else{
      printf("%d\n",highermid);
    }
  }
  return 0;
}
  

Measured memory_bytes: 5240
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_V = 310;  // デフォルトで頂点数の最大値は300

int main() {
    ll n, m, R;
    cin >> n >> m >> R;

    vl r(R);
    rep(i, R) {
        cin >> r[i];
        r[i]--;
    }
    
    vvl dist(MAX_V, vl(MAX_V));
    rep(i, n) {
        rep(j, n) {
            if(i != j) {
                dist[i][j] = INF;
            }
        }
    }
    
    rep(i, m) {
        ll a, b, cost;
        cin >> a >> b >> cost;
        a--;  b--;
        if(dist[a][b] > cost) {
            dist[a][b] = dist[b][a] = cost;
        }
    }

    rep(k, n) {
        rep(i, n) {
            rep(j, n) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    vl perm(R);
    rep(i, R) {
        perm[i] = i;
    }

    ll ans = INF;
    do {
        ll now = 0;
        rep(i, R-1) {
            now += dist[r[perm[i]]][r[perm[i+1]]];
        }
        chmin(ans, now);
    } while(next_permutation(all(perm)));

    out(ans);
    re0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define all(x) (x).begin(), (x).end()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end());

int main() {
  int N;
  string S;

  cin >> N >> S;

  int ans = 0;
  int m = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == 'I')
      ans++;
    else
      ans--;

    m = max(m, ans);
  }

  cout << m << endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
total=sum(a)
ideal=sum(a)/2
tmp=10**20
goukei=0
for i in range(n):
  goukei+=a[i]
  if tmp>abs(ideal-goukei):
    tmp=min(tmp,abs(ideal-goukei))
  else:
    break
print(int(tmp*2))

Measured memory_bytes: 26396
//#define LOCAL = 0

#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << "\t|";
  __f(comma + 1, args...);
}
 

#define print(x) for(auto it : x) cout<< it << " "; cout << endl;
typedef long long ll;
typedef unsigned long long ull;


int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    long long n, m, k; cin >> n >> m >> k;
    vector <ll> a = {0}, b = {0};
    for (int i = 0; i < n; i++) {
        ll x; cin >> x;
        a.push_back(x);
    }
    for (int i = 0; i < m; i++) {
        ll x; cin >> x;
        b.push_back(x);
    }
    for (int i = 1; i < n + 1; i++)
        a[i] = a[i] + a[i - 1];
    for (int i = 1; i < m + 1; i++)
        b[i] = b[i] + b[i - 1];
    
    long long ans = 0;
    for (int i = 0; i < n + 1; i++) {
        ll search = upper_bound(b.begin(), b.end(), k - a[i]) - b.begin();
        if (search > 0) search--;
        trace(i, search, a[i], b[search]);
        if (a[i] + b[search] <= k) {
            ans = max(ans, i + search);
        }
        if (a[i] > k) break;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7956
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;


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

	cin >> H >> W;
	int sy, sx, gy, gx;
	cin >> sy >> sx >> gy >> gx;
	sy--, sx--, gy--, gx--;
	vector<string>s(H);
	for (auto &i : s)cin >> i;
	vector<vector<int>>dis(H, vector<int>(W,MOD));
	deque<pair<int, int>>Q;
	Q.push_back({ sy,sx });
	dis[sy][sx] = 0;
	int dir[] = { 1,0,-1,0,1 };
	while (!Q.empty()) {
		int cy, cx;
		tie(cy, cx) = Q.front();
		Q.pop_front();
		for (int i = 0; i < 4; i++) {
			int ny = cy + dir[i];
			int nx = cx + dir[i + 1];
			//if (ny < 0 || nx < 0 || ny >= H || nx >= W)continue;
			//if (s[ny][nx] == '#')continue;
            if(unsigned(nx)<W&&unsigned(ny)<H&&s[ny][nx]=='.'){
			if (dis[ny][nx] > dis[cy][cx]) {
				dis[ny][nx] = dis[cy][cx];
				Q.push_front({ ny,nx });
			}
            }
		}
		for (int i = -2; i <= 2; i++) {
			for (int j = -2; j <= 2; j++) {
				int ny = cy + i;
				int nx = cx + j;
				//if (ny < 0 || nx < 0 || ny >= H || nx >= W)continue;
				//if (s[ny][nx] == '#')continue;
                if(unsigned(nx)<W&&unsigned(ny)<H&&s[ny][nx]=='.'){
				if (dis[ny][nx] > dis[cy][cx] + 1) {
					dis[ny][nx] = dis[cy][cx] + 1;
					Q.push_back({ ny,nx });
				}
                }
			}
		}
	}
	if (dis[gy][gx] == MOD)dis[gy][gx] = -1;
	cout << dis[gy][gx] << endl;
}


Measured memory_bytes: 8716
#include<stdio.h>
int main (void)
{
    int i,j,k=0,n,p=0,D[101]={0};
    while(scanf("%d",&n)!=EOF){
        D[n]++;
        k++;
    }
    for(i=k;i>0;i--){
        for(j=0;j<k;j++){
            if(D[j]==i){
                printf("%d\n",j);
                p=1;
            }
        }
        if(p==1)break;
    }
    return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
LL p = 1000000007ll;

int main(void)
{
  LL n;
  cin >> n;
  vector<pair<LL,LL>> a(n*2);
  for(auto &x:a) cin >> x.first;
  REP(i,n) a[i].second = 1;
  REP(i,n) a[n+i].second = -1;
  sort(a.begin(),a.end());
  LL answer=1;
  LL tmp = 0;
  for(auto x:a) {
    LL pat = x.second * tmp;
    if(pat<0) {
      answer *= -pat;
      answer %= p;
    }
    tmp += x.second;
  }
  cout << answer << endl;

  return 0;
}


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

string str;

map<char,int> mapa;

int main(){
	mapa['a'] = 0;
	mapa['b'] = 0;
	mapa['c'] = 0;
	cin >> str;
	int mini = 0x3f3f3f3f;
	for(auto &it: str){
		mapa[it] ++ ;
	}
	
	for(auto &it : mapa)
		mini = min(mini, mapa[it.first]);
	for(auto &it: mapa)
		it.second -= mini;
	int c = 0;
	
	for(auto &it: mapa){
		if(it.second >= 2)
			c = 100;
		else if(it.second)
			c++;
	}
	if(c <= 2)
		cout<<"YES";
	else
		cout<<"NO";
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const long long bound=1000000000LL;
vector <long long> arr;
void dfs(long long cur,bool f3,bool f5,bool f7)
{
    if(f3&&f5&&f7)
        arr.push_back(cur);
    if(cur>bound)
        return ;
    dfs(cur*10+3,true,f5,f7);
    dfs(cur*10+5,f3,true,f7);
    dfs(cur*10+7,f3,f5,true);
    return ;
}

void init()
{
    arr.clear();
    dfs(0,false,false,false);
    sort(arr.begin(),arr.end());
}

int main()
{
    init();
    long long x;
    while(scanf("%lld",&x)!=EOF)
    {
        int tmp=upper_bound(arr.begin(),arr.end(),x)-arr.begin();
        printf("%d\n",tmp);
    }
    return 0;
}

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

int main() {
  ll n,m;
  cin >> n >> m;
  ll a[n];
  for(int i=0; i<n; i++) cin >> a[i];
  vector<ll> v;
  for(int i=0; i<n; i++) {
    ll sum=0;
    for(int j=i; j<n; j++) {
      sum+=a[j];
      v.push_back(sum);
    }
  }
  ll ans=0;
  for(int i=40; i>=0; i--) {
    vector<ll> g;
    for(int j=0; j<v.size(); j++) {
      if(v[j]&(1LL<<i)) g.push_back(v[j]);
    }
    if(g.size()>=m) {
      v=g;
      ans|=1LL<<i;
    }
  }
  cout << ans << endl;
  return 0;
}


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

int main() {
	int a, b;
	cin >> a >> b;
	if (a == b) cout << "a == b" << endl;
	else if (a < b) cout << "a < b" << endl;
	else if (a > b) cout << "a > b" << endl;
	return 0;
}


Measured memory_bytes: 3096
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <bits/stdc++.h> // isupper, islower, isdigit, toupper, tolower
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, n) for (int i = (a); i < (n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> Pl;
typedef pair<int, int> P;

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

  ll R = 0;
  ll G = 0;
  ll B = 0;
  ll ans = 0;
  vector<char> nvec; //Nの各桁の数字を格納するベクター

  rep(i, N)
  {
    nvec.push_back(S.at(i));
    if (S.at(i) == 'R')
    {
      R++;
    }
    if (S.at(i) == 'G')
    {
      G++;
    }
    if (S.at(i) == 'B')
    {
      B++;
    }
  }
  ans = R * G * B;
  ll condition2 = 0;
  rep(i, N)
  {
    rep2(j, i + 1, N)
    {
      ll k = 2 * j - i ;
      if (k >= N)
      {
        continue;
      }
      else
      {
        if (S.at(i) != S.at(j) && S.at(j) != S.at(k) && S.at(k) != S.at(i))
        {
          condition2++;
        }
      }
    }
  }

  cout << ans - condition2 << endl;

  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll gcd(ll a,ll b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll INFS=1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);

int main() {
    string s;
  cin >> s;
 
  int len = s.size();
  int i = 0;
  reverse(s.begin(), s.end());
  while (i < len) {
    if (s.substr(i, 5) == "maerd")
      i += 5;
    else if (s.substr(i, 7) == "remaerd")
      i += 7;
    else if (s.substr(i, 5) == "esare")
      i += 5;
    else if (s.substr(i, 6) == "resare")
      i += 6;
    else {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;
 
  return 0;
}

Measured memory_bytes: 3712
#include <iostream>

using namespace std;

int main(){
    string n;
    cin >> n;
    int x=0;
    int sum=0;
    for(int i=0;i<n.size();i++){
        int num = n[i]-'0';
        sum+=num;
        x+=num;
        x*=10;
    }
    x/=10;
    //cout << x%sum << endl;
    //cout << x << sum << endl;
    if(!(x%sum))cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        
        final int N = Integer.parseInt(sc.next());
        long ans = IntStream.range(0, N).mapToObj(i -> sc.next()).distinct().count();
        out.println(ans);
        
        out.flush();
    }
}

Measured memory_bytes: 77120
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

string s;
int cnt[3];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> s;
  if (s.size() == 1) {
    cout << "YES" << endl;
    return 0;
  }
  for (int i = 0; i < s.size(); i++) {
    cnt[s[i] - 'a']++;
  }
  sort(cnt, cnt + 3);
  reverse(cnt, cnt + 3);
  vector<int> v;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j < 3; j++) {
      if (cnt[j] == 0) continue;
      int flag = 0;
      if (v.size() == 0) {
        flag = 1;
      } else {
        if (v.size() >= 1 && v[v.size() - 1] == j) continue;
        if (v.size() >= 2 && v[v.size() - 2] == j) continue;
        flag = 1;
      }
      if (flag) {
        v.emplace_back(j);
        cnt[j]--;
        break;
      }
    }
  }
  cout << (cnt[0] == 0 && cnt[1] == 0 && cnt[2] == 0 ? "YES" : "NO") << endl;

  return 0;
}

Measured memory_bytes: 972
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int K = Integer.parseInt(sc.next());
		ArrayList<Integer> list = new ArrayList<>();
		for(int i = 0; i< N; i++) {
			list.add(Integer.parseInt(sc.next()));
		}
		sc.close();

		//リストを降順にソート
		Collections.sort(list, Collections.reverseOrder());
		int sum = 0;
		for(int i = 0; i< K; i++) {
			sum += list.get(i);
		}
		System.out.println(sum);
	}

}

Measured memory_bytes: 21588
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		boolean[] broken = new boolean[n];
		Arrays.fill(broken, false);
		int m = sc.nextInt();
		for (int i = 0; i < m; i++) {
			broken[sc.nextInt() - 1] = true;
		}
		sc.close();
		long mod = 1000000007;
		long now = 0;// いま
		long prev1 = 1;// いっこまえ
		long prev2 = 0;// にこまえ
		for (int i = 0; i < n; i++) {
			if (!broken[i]) {
				now = prev1 + prev2;
				now %= mod;
			} else {
				now = 0;
			}
			prev2 = prev1;
			prev2 %= mod;
			prev1 = now;
			prev1 %= mod;
		}
		System.out.println(now);
	}
}


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

#define MIN(X, Y) (((X) < (Y)) ? (X) : (Y))
#define MAX(X, Y) (((X) > (Y)) ? (X) : (Y))
#define ll long long

int main(void)
{
    int a,b,cc;
    char c;
    while(1)
    {
        scanf("%d%d%d",&a,&b,&cc);
        if(a+b+cc==-3)
            break;
        if(a==-1||b==-1)
            c='F';
        else if(a+b>=80)
            c='A';
        else if(a+b>=65)
            c='B';
        else if(a+b>=50)
            c='C';
        else if(a+b>=30 && cc<50)
            c='D';
        else if(a+b>=30 && cc>=50)
            c='C';
        else if(a+b<30)
            c='F';
        printf("%c\n",c);
    }
    return 0;
}




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

int main() {
	int N,r=0;
	cin >> N;
	vector<int> A1(N),A2(N);
	
	rep(i,N) {
		cin >> A1.at(i);
		if(i != 0)
			A1.at(i) += A1.at(i-1);
	}
	rep(i,N)
		cin >> A2.at(i);
	rep(i,N-1)
		A2.at(N-2-i) += A2.at(N-1-i);
	
	rep(i,N)
		r = max(r, A1.at(i)+A2.at(i));
	
	cout << r << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main () {
  int H, W, K;
  cin >> H >> W >> K;
  char mp[10][10];
  vector<int>bl_h(H, 0);
  vector<int>bl_w(W, 0);
  for (int i = 0; i < H; i ++) {
    for (int j = 0; j < W; j ++) {
      cin >> mp[i][j];
      if (mp[i][j] == '#') {
        bl_h[i] ++;
        bl_w[j] ++;
        K --;
      }
    }
  }
  //cout << K << endl;
  int cal_h[10];
  int cal_w[10];
  int ans = 0;
  for (int i = 0; i < 1 << H; i ++) {
    for (int j = 0; j < 1 << W; j ++) {
      int i_ = i;
      int j_ = j;
      int si_h = 0;
      int si_w = 0;
      int kj = 0;
      for (int k = 0; k < H; k ++) {
        if (i_ % 2) {
          cal_h[si_h] = k;
          si_h ++;
          kj += bl_h[k];
        }
        i_ /= 2;
      }
      for (int k = 0; k < W; k ++) {
        if (j_ % 2) {
          cal_w[si_w] = k;
          si_w ++;
          kj += bl_w[k];
        }
        j_ /= 2;
      }
      //int al = kj;
      //cout << kj << endl;
      int s = (si_h * W) + (si_w * H) - (si_h * si_w);
      for (int k = 0; k < si_h; k ++) {
        for (int l = 0; l < si_w; l ++) {
          if (mp[cal_h[k]][cal_w[l]] == '#') {
            kj --;
          }
        }
      }
      //cout << al - kj << endl;
      if (kj + K == 0) ans ++;
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 3624
from fractions import gcd
n = int(input())
a = list(map(int,input().split()))
lg = [a[0]]
rg = [a[-1]]
for i in range(n-1):
    lg.append(gcd(lg[-1],a[i+1]))
    rg.append(gcd(rg[-1],a[-i-2]))
rg.reverse()
ans = 0
for i in range(n):
    if i == 0:
        ans = rg[i+1]
    elif i == n-1:
        ans = max(ans,lg[i-1])
    else:
        ans = max(ans,gcd(lg[i-1],rg[i+1]))

print(ans)

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;
ll h,w,k, num = 0;

void solve(ll sup, ll inf, vector<string>& s, vector<vector<ll>>& ans)
{   
    ll i,j;
    vector<ll> p;
    for(i = sup;i <= inf;++i){
        rep(j,w){
            if(s.at(i).at(j) == '#') p.push_back(j);
        }
    }
    sort(all(p));

    for(i = 0;i < p.size();++i){
        ll v1 = 0, v2 = w-1;
        if(i >= 1) v1 = p.at(i-1)+1;
        if(i < (ll)p.size()-1) v2 = p.at(i);
        ++num;
        for(j = sup;j <= inf;++j){
            for(ll k = v1;k <= v2;++k) ans.at(j).at(k) = num;
        }
    }
}

int main()
{
    ll i,j;
    cin >> h >> w >> k;
    vector<string> s(h);
    for(i = 0;i < h;++i){
        cin >> s.at(i);
    }
    vector<vector<ll>> sharp(h);
    for(i = 0;i < h;++i){
        rep(j,w){
            if(s.at(i).at(j) == '#') sharp.at(i).push_back(j);
        }
    }
    vector<ll> gyou;
    for(i = 0;i < h;++i){
        if(sharp.at(i).size() != 0){
            gyou.push_back(i);
        }
    }

    vector<vector<ll>> ans(h,vector<ll>(w));
    for(i = 0;i < gyou.size();++i){
        ll v1 = 0, v2 = h - 1;
        if(i >= 1) v1 = gyou.at(i-1)+1;
        if(i < (ll)gyou.size()-1) v2 = gyou.at(i);

        solve(v1, v2, s, ans);
    }
    
    for(i = 0;i < h;++i){
        rep(j,w-1){
            cout << ans.at(i).at(j) << " ";
        }
        cout << ans.at(i).at(j) << endl;
    }


    return 0;
}

Measured memory_bytes: 5684
#include <bits/stdc++.h>
using namespace std;
inline void read (int &x) {
    char ch = getchar(); int f = 0; x = 0;
    while (!isdigit(ch)) { if (ch == '-') f = 1; ch = getchar(); }
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); if (f) x = -x;
}
signed main() {
    int ha, ma, hb, mb, k;
    read (ha), read (ma), read (hb), read (mb), read (k);
    int res = (hb - ha) * 60 + (mb - ma) - k;
    while (res < 0) res += 24 * 60;
    return printf ("%d\n", res), 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 45;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  vector<ll> dp(n, INF64);
  rep(i, n) {
    *lower_bound(ALL(dp), a[i]) = a[i];
  }
  cout << distance(dp.begin(), lower_bound(ALL(dp), INF64)) << endl;
}


Measured memory_bytes: 4404
#include <iostream>

using namespace std;

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

  int a[m];

  int sum = 0;
  for(int i = 0; i < m; i++){
    cin >> a[i];

    sum += a[i];
  }

  if(n - sum >= 0){
    cout << n - sum << endl;
  }
  else{
    cout << "-1" << endl;
  }

  return 0;
}

Measured memory_bytes: 3632
n=int(input())
a=[list(map(int,input().split()))for _ in range(n)]
def f():
 for i in range(n-1):
  d=a[i][:];d[3],d[4]=d[4],d[3]
  for j in range(i+1,n):
   e=a[j][:];e[3],e[4]=e[4],e[3]
   for p in('012345','152043','215304','302541','410352','514320'):
    f=[d[int(k)]for k in p]
    if f[0]==e[0]and f[5]==e[5]:
     f=f[1:5]*2
     for k in range(4):
      if f[k:k+4]==e[1:5]:return'No'
 return'Yes'
print(f())


Measured memory_bytes: 5608
#include <bits/stdc++.h>
 
#define pb push_back
#define lp(i,a,b) for(int i = a;i<b;i++)
#define ll long long
#define pii pair<int,int>
#define ff first
#define ss second
#define mk make_pair
#define sz size()
 
const int MAXN = 110 ; 
 
using namespace std ;

char str[MAXN] ;

int main()
{
	
	scanf("%s", str) ;
	
	int n = strlen(str) ;
	
	bool ok = true ;
	
	lp(i,0,n)
		if( (i%2 == 0 && str[i] == 'L') || ( i%2 == 1 && str[i] == 'R' ) ) ok = false;
	
	printf("%s\n", ok ? "Yes" : "No" ) ;
	
}









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

#define INT_MAX 2000000000

typedef struct node {
  typedef struct edge {
    node *next;
    int heavy;
  } edge;
  vector<edge> edges;
  long int val;
  bool checked;
  int ax;
} node;

long int xmin;
long int ymin;

bool check(node *v,node *bef){
  v->checked = true;
  vector<node::edge>::iterator it;
  for(it = v->edges.begin(); it != v->edges.end(); ++it){
    if((*it).next != bef){
      if((*it).next->checked){
        if(v->val + (*it).next->val != (*it).heavy){
          return false;
        }
      }else{
        (*it).next->val = (*it).heavy - v->val;
        if((*it).next->ax == 0){
          xmin = min(xmin, (*it).next->val);
        }else{
          ymin = min(ymin, (*it).next->val);
        }
        if(!check((*it).next, v)){
          return false;
        }
      }
    }
  }
  return true;
}

int main(int argc, char *argv[]){
  int R, C;
  int N;
  cin >> R >> C;
  cin >> N;
  node x[R];
  node y[C];
  int i;
  for(i=0; i<R; ++i){
    x[i].checked = false;
    x[i].ax = 0;
  }
  for(i=0; i<C; ++i){
    y[i].checked = false;
    y[i].ax = 1;
  }
  int r, c, a;
  for(i=0; i<N; ++i){
    cin >> r >> c >> a;
    
    node::edge e1;
    e1.next = &y[c-1];
    e1.heavy = a;
    x[r-1].edges.push_back(e1);
    
    node::edge e2;
    e2.next = &x[r-1];
    e2.heavy = a;
    y[c-1].edges.push_back(e2);
  }
  for(i=0; i<R; ++i){
    if(!x[i].checked){
      if(x[i].edges.size() > 0){
        x[i].val = 0;
        xmin = 0;
        ymin = INT_MAX;
        if(check(&x[i], NULL)){
          if(xmin + ymin < 0){
            cout << "No" << endl;
            return 0;
          }
        }else{
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

int main() {
  int a;
  ll b, n;
  cin >> a >> b >> n;

  if (n < b) {
    // x should be n
  }

  ll x = min(n, b - 1);
  ll ans = floor((a * x) / b) - (a * floor(x / b));
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3584