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


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

	//freopen("input.txt","r",stdin);

	long long int n,k,a,b;

	cin>>n>>k;
	if(n == 0)
		cout<<0<<endl;
	else{
		a = n % k;
		b = abs(a - k);

		b = min(a,b);
		cout<<b<<endl;
	}

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(void){
  int N,sum=0,min=0,x=0;
  int W[100];
  scanf("%d",&N);
  for(int i=0;i<N;i++){
    scanf("%d",&W[i]);
    sum+=W[i];
  }
  for(int j=0;j<N-1;j++){
    x+=W[j];
    sum-=W[j];
    if(j==0 || abs(sum-x)<min){
      min=abs(sum-x);
    }
  }
  printf("%d\n",min);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1e9+7;
const ll INF = 1e18;
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll n;
  cin >> n;
  vector<ll> d(n);
  rep(i,n) cin >> d[i];
  ll m;
  cin >> m;
  vector<ll> t(m);
  rep(i,m) cin >> t[i];
  sort(All(d));
  sort(All(t));

  ll now = 0;
  for (ll i = 0; i < m; ++i) {
    for (ll j = now; j < n+1; ++j) {
      if (j == n) {
        cout << "NO\n";
        return 0;
      }
      if (t[i] == d[now]) {
        ++now;
        break;
      }  
      else ++now;
    }
  }
  cout << "YES\n";

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

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

bool usedA[8];
bool usedB[8];
bool usedC[16];
bool usedD[16];

char t[8][8];


bool dfs(int y,int x,int cnt){
  if(y==8){
    return (cnt==8);
  }
  if(x==8){
    return dfs(y+1,0,cnt);
  }
  if( usedA[y] || usedB[x] || usedC[y+x] || usedD[y-x+8] ){
    return dfs(y,x+1,cnt);
  }
  t[y][x]='Q';
  usedA[y]=usedB[x]=usedC[y+x]=usedD[y-x+8]=true;
  if( dfs(y,x+1,cnt+1) )return true;
  usedA[y]=usedB[x]=usedC[y+x]=usedD[y-x+8]=false;
  t[y][x]='.';
  if( dfs(y,x+1,cnt) )return true;
  return false;
}

int main(){
  for(int i=0;i<8;i++)
    for(int j=0;j<8;j++)
      t[i][j]='.';

  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    int y,x;
    cin>>y>>x;
    t[y][x]='Q';
    usedA[y]=usedB[x]=usedC[y+x]=usedD[y-x+8]=true;
  }
  dfs(0,0,n);
  for(int i=0;i<8;i++){
    for(int j=0;j<8;j++){
      cout<<t[i][j];
    }
    cout<<endl;
  }
  return 0;
}



Measured memory_bytes: 3084
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;


int main(){
    int A,P;
cin>>A>>P;
    cout<<(3*A+P)/2;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
const ld EPS = 1e-10;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

int main(){
    int N;
    cin >> N;
    int X[N], memo[N];
    rep(i, N) cin >> X[i];
    rep(i, N) memo[i] = X[i];
    sort(X, X+N);
    int l = X[N/2-1], r = X[N/2];
    rep(i, N){
        if(memo[i] <= l) cout << r << endl;
        else cout << l << endl;
    }
}

Measured memory_bytes: 3712
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define fi first
#define se second
set<string> c;
map<ll,ll> mp;
const ll inf=100000000000000000;
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}

int main(){
ll h,w;
cin>>h>>w;
ll res=inf;
for(int i=1;i<h;i++){
    ll sa=i*w,sb=(h-i)*(w/2),sc=(h-i)*(w-w/2);
    ll ma=max(sa,max(sb,sc)),mi=min(sa,min(sb,sc));
    res=min(res,ma-mi);
}
for(int i=1;i<h;i++){
    ll sa=i*w,sb=((h-i)/2)*w,sc=((h-i)-(h-i)/2)*w;
    ll ma=max(sa,max(sb,sc)),mi=min(sa,min(sb,sc));
    res=min(res,ma-mi);
}
for(int i=1;i<w;i++){
    ll sa=i*h,sb=(w-i)*(h/2),sc=(w-i)*(h-h/2);
    ll ma=max(sa,max(sb,sc)),mi=min(sa,min(sb,sc));
    res=min(res,ma-mi);
}
for(int i=1;i<w;i++){
    ll sa=i*h,sb=((w-i)/2)*h,sc=((w-i)-(w-i)/2)*h;
    ll ma=max(sa,max(sb,sc)),mi=min(sa,min(sb,sc));
    res=min(res,ma-mi);
}
cout<<res<<endl;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
ans=0
b=[]
for k in range(2*n):
 for i in range(2*n):
  if a[i]==min(a):
    b.append(a[i])
    a[i]=101
for s in range(n):
  ans+=b[2*s]
print(ans)

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

int main(){
    int num,a,b;
    string str1,str2,str3;
    cin >> str1 >> num;
    
    for(int i = 0;i < num;++i){
        cin >> str2;
        if(str2 == "replace"){
            cin >> a >> b >> str3;
            str1.replace(a, (b - a) + 1, str3);
        }else if(str2 == "reverse"){
            cin >> a >> b;
            string tmp = str1.substr(a,(b - a) + 1);
            reverse(tmp.begin(), tmp.end());
            str1.erase(a,(b - a) + 1);
            str1.insert(a, tmp);
        }else if(str2 == "print"){
            cin >> a >> b;
            cout << str1.substr(a,(b - a) + 1) << endl;
        }
    }
}



Measured memory_bytes: 3192
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main(void){
    string c1;
    string c2;

    cin >> c1 >> c2;

    reverse(c2.begin(),c2.end());

    if(c1==c2)cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(N)]
cd = [tuple(map(int, input().split())) for _ in range(M)]

for a, b in ab:
    best = float('inf')
    result = -1
    for i in range(M):
        c, d = cd[i]
        t = abs(a - c) + abs(b - d)
        if t < best:
            result = i + 1
            best = t
    print(result)


Measured memory_bytes: 3064
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n = ni()
x = list(li())

med1 = sorted(x)[n//2 - 1]
med2 = sorted(x)[n//2]

for xi in x:
    if xi <= med1:
        print(med2)
    else:
        print(med1)       

Measured memory_bytes: 26756
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int, int> P;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector<P> Vec(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> Vec[i].second >> Vec[i].first;
		}
		sort(Vec.begin(), Vec.end());
		int sum = 0;
		bool flag = true;
		for(int i = 0; i < n; ++i)
		{
			sum += Vec[i].second;
			if(sum > Vec[i].first)
			{
				cout << "No" << endl;
				flag = false;
				break;
			}
		}
		if(flag)
		{
			cout << "Yes" << endl;
		}
	}
}

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

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s1,s2,s3;
  cin>>s1>>s2>>s3;
  cout<<char(s1[0]-32);
  cout<<char(s2[0]-32);
  cout<<char(s3[0]-32)<<endl;
  return(0);
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define repc(i, s, t) for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.setf(ios_base::fixed);
    cout.precision(12);

    var(int, H, W, h, w);
    print(H * W - h * W - H * w + h * w);

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iostream>
#include <stack>
 
using namespace std;
 
int main(){
    long n;
    scanf("%ld", &n);
    long n2 = n;

    set<long> ds;
    for(long i = 2; i*i <= n; ++i){
        while(n % i == 0){
            vector<long> tmp;
            tmp.push_back(i);
            for(long x : ds){ tmp.push_back(i * x); }
            for(long x : tmp){ ds.insert(x); }
            n /= i;
        }
    }
    vector<long> tmp;
    tmp.push_back(n);
    for(long x : ds){ tmp.push_back(n * x); }
    for(long x : tmp){ ds.insert(x); }

    long ans = 0;
    for(long tmp : ds){
        long m = tmp - 1;
        long r = n2 / tmp;
        if(r < m){
            ans += m;
        }
    }
    printf("%ld\n", ans);
    return 0;
}

Measured memory_bytes: 640
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cmath>
#include<ctime>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<iostream>
#include<algorithm>
#define LL long long
#define add_edge(u,v) nxt[++cnt]=head[u],head[u]=cnt,to[cnt]=v
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
char ch;bool fs;void re(int& x)
{
	while(ch=getchar(),ch<33);
	if(ch=='-')fs=1,x=0;else fs=0,x=ch-48;
	while(ch=getchar(),ch>33)x=x*10+ch-48;
	if(fs)x=-x;	
}
using namespace std;
int n,l,r;
char s[200001];
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1,now=0;i<=n;++i)
		now+=s[i]=='T'?1:-1,l=max(l,now);
	for(int i=n,now=0;i;--i)
		now+=s[i]=='T'?-1:1,r=max(r,now);
	printf("%d\n",l+r);
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;

void Onaka(vector<vector<int>> &G, vector<bool> &B, int k) {
    B.at(k) = true;
    for (int i = 0; i < G.at(k).size(); i++) {
        int a = G.at(k).at(i);
        if (B.at(a)) {
            continue;
        }
        Onaka(G, B, a);
    }
    return;
}

int main() {
    int N, M, ans = 0;
    cin >> N >> M;
    vector<Pint> A(M);
    for (int i = 0; i < M; i++) {
        cin >> A.at(i).first >> A.at(i).second;
    }
    for (int i = 0; i < M; i++) {
        vector<vector<int>> G(N);
        for (int j = 0; j < M; j++) {
            if (i == j) {
                continue;
            }
            G.at(A.at(j).first - 1).emplace_back(A.at(j).second - 1);
            G.at(A.at(j).second - 1).emplace_back(A.at(j).first - 1);
        }
        vector<bool> B(N, false);
        Onaka(G, B, 0);
        for (int i = 0; i < N; i++) {
            if (!B.at(i)) {
                ans++;
                break;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
a = list(input())

n = len(a)
cnt = {}
for c in a:
    if c in cnt:
        cnt[c] += 1
    else:
        cnt[c] = 1

ans = n * (n + 1) // 2 + 1
for c in cnt:
    k = cnt[c]
    ans -= k * (k + 1) // 2

print(ans)

Measured memory_bytes: 62064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,k,i,x,j,mn;
    cin>>k>>n;
    vector < long long > v;
    for(i=0;i<n;i++)
    {
        cin>>x;
        v.push_back(x);
        if(x>0)
        v.push_back(x-k);
    }
    sort(v.begin(),v.end());
    mn=INT_MAX;
    i=n-1;
    j=0;
    while(i<v.size())
    {
        
        mn=min(mn,v[i]-v[j]);
       // cout<<v[i]<<" "<<v[j]<<" "<<v[i]-v[j]<<"\n";
        i++;
        j++;
    }
    cout<<mn<<"\n";
    
    return 0;
}

Measured memory_bytes: 6556
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;
     
void main() {
    auto s = readln.split.map!(to!int);
    auto H = s[0];
    auto W = s[1];
    auto D = s[2];
     
    auto N = max(H, W) * 3;
    auto B = new int[][](N, N);
    int[] colors = [1, 2, 3, 4];
     
    for (int i = 0; i * D < N; ++i)
        for (int j = 0; j * D < N; ++j)
            for (int a = 0; a < D; a++)
                for (int b = 0; b < D; b++)
                    if (i * D + a < N && j * D + b < N)
                        B[i*D+a][j*D+b] = colors[i%2*2+j%2];
     
        
    auto ans = new int[][](H, W);
    auto color = " RYGB";
        
    foreach (i; 0..H) {
        foreach (j; 0..W) {
            int ni = i + j;
            int nj = i - j + W;
            ans[i][j] = B[ni][nj];
        }
    }
     
    ans.each!(an => an.map!(a => color[a]).writeln);
}


Measured memory_bytes: 15484
#include<bits/stdc++.h>
using namespace std;
int N;
int s[100];
char t[100][10];
int u[100],v[100],w[100];

int num[1000];

int s2i(string str){
  stringstream ss;
  ss<<str;
  int res;
  ss>>res;
  return res;
}

int change(int x){
  if(0<=x){
    return x;
  }else{
    return num[-x];
  }
}

void setvalue(int x,int y){
  assert( x<0 );
  num[-x]=y;
}

int main(){

  set<char> st;
  map<int,int> lp;  
  scanf("%d",&N);
  for(int i=0;i<N;i++){
    scanf("%d",&s[i]);
    assert( lp.count(s[i]) == 0 );
    lp[ s[i] ] = i;
    
    scanf("%s",t[i]);
    string a,b,c;
    
    if(t[i][0]=='A'){
      cin>>a>>b>>c;
      if('a'<=a[0]&&a[0]<='z')u[i]=-1*(int)a[0],st.insert(a[0]);
      else assert(0);
      
      if('a'<=b[0]&&b[0]<='z')v[i]=-1*(int)b[0],st.insert(b[0]);
      else v[i]=s2i(b);

      if('a'<=c[0]&&c[0]<='z')w[i]=-1*(int)c[0],st.insert(c[0]);
      else w[i]=s2i(c);

    }else if(t[i][0]=='S'&&t[i][1]=='U'){
      cin>>a>>b>>c;
      if('a'<=a[0]&&a[0]<='z')u[i]=-1*(int)a[0],st.insert(a[0]);
      else assert(0);
      
      if('a'<=b[0]&&b[0]<='z')v[i]=-1*(int)b[0],st.insert(b[0]);
      else v[i]=s2i(b);

      if('a'<=c[0]&&c[0]<='z')w[i]=-1*(int)c[0],st.insert(c[0]);
      else w[i]=s2i(c);

      
    }else if(t[i][0]=='S'&&t[i][1]=='E'){
      cin>>a>>b;
      if('a'<=a[0]&&a[0]<='z')u[i]=-1*(int)a[0],st.insert(a[0]);
      else assert(0);

      if('a'<=b[0]&&b[0]<='z')v[i]=-1*(int)b[0],st.insert(b[0]);
      else v[i]=s2i(b);
      
    }else if(t[i][0]=='I'){
      cin>>a>>b;
      if('a'<=a[0]&&a[0]<='z')u[i]=-1*(int)a[0],st.insert(a[0]);
      else assert(0);

      if('a'<=b[0]&&b[0]<='z')assert(0);
      else v[i]=s2i(b);

      
    }else if(t[i][0]=='H'){
      
    }else assert(0);
  }

  int mx=60000000;
  int p=0,cc=0;
  while(cc < mx){
    
    if(t[p][0]=='A'){
      int value=change(v[p])+change(w[p]);
      if(value<0 || 16<=value)break;
      setvalue(u[p],value);
      p++;
    }else if(t[p][0]=='S'&&t[p][1]=='U'){
      int value=change(v[p])-change(w[p]);
      if(value<0 || 16<=value)break;
      setvalue(u[p],value);
      p++;
    }else if(t[p][0]=='S'&&t[p][1]=='E'){
      int value=change(v[p]);
      if(value<0 || 16<=value)break;
      setvalue(u[p],value);
      p++;
    }else if(t[p][0]=='I'){
      int value=change(u[p]);
      if(value > 0 ){
        int next=change(v[p]);
        if( lp.count( next ) == 0 )break;
        p=lp[next];
      }else{
        p++;
      }


    }else if(t[p][0]=='H'){
      break;
    }else assert(0);

    
    cc++;
    if(p==N)break;
  }
  
  if(cc<mx){
    set<char> :: iterator it;
    for(it=st.begin();it!=st.end();it++){
      int f=*it;
      printf("%c=%d\n", *it, change(-f) );
    }
  }else{
    printf("inf\n");
  }
  
  return 0;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a=0,b=0;
    cin>>a>>b;
    if(a+b==15)
    	cout<<"+";
    else if(a*b==15)
    	cout<<"*";
    else
    	cout<<"x";
    cout<<endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int kazu = 0;
  cin >> kazu;
  vector <int> rennga(kazu);
  for(int i = 0;i <= kazu - 1;i++){
    cin >> rennga[i];
  }
  int kotae = 0;
  int saidai = 0;
  int rennzoku = 0;
  int ok = 0;
  int ima = 0;
  for(int i = 0;i <= kazu - 1;i++){
    if(rennga[i] == 1){
      	rennzoku = 1;
      	ima = 2;
    	for(int j = i + 1;j <= kazu - 1;j++){
     		if(rennga[j] == ima){
              rennzoku++;
              ima++;
            }
    	}
      	if(saidai < rennzoku){
          ok = 1;
          saidai = rennzoku;
        }
      	i = kazu;
    }
  }
  kotae = kazu - saidai;
  if(ok == 0){
    kotae = -1;
  }
  cout << kotae << endl;
}

Measured memory_bytes: 1024
int main(void){
	int a = 0;
	int b = 0;
	int i = 0;
	int j = 0;

	while (1){
		scanf("%d %d", &a, &b);
		if (a == 0 && b == 0){
			break;
		}else{
			for (i = 0; i < a; i++){
				for (j = 0; j < b; j++){
					if (i == 0 || i == a-1){
						printf("%c", '#');
					}
					else{
						if (j == 0 || j == b-1){
							printf("%c", '#');
						}
						else{
							printf("%c", '.');
						}
					}
				}
				printf("\n");
			}
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 572
/* https://atcoder.jp/contests/abc124/tasks/abc124_b */

#include <iostream>
#include <vector>

/* {{{ Variables */
int N;
std::vector<int> H;
/* }}} */

int main(int argc, char *argv[])
{
  /* {{{ Input */
  std::cin >> N;

  H = std::vector<int>(N);

  for (int& e: H)
    std::cin >> e;
  /* }}} */

  /* {{{ Output */
  int num = 0;
  int max_h = 0;

  for (int& e: H) {
    if (e >= max_h) {
      max_h = e;
      num++;
    }
  }

  std::cout << num << std::endl;
  /* }}} */

  return 0;
}


Measured memory_bytes: 256
from bisect import bisect


def main():
    N = int(input())
    A = [-int(input()) for _ in range(N)]
    L = [A[0]]
    for a in A[1:]:
        if a >= L[-1]:
            L.append(a)
        else:
            L[bisect(L, a)] = a
    print(len(L))


if __name__ == "__main__":
    main()


Measured memory_bytes: 8604
import Data.List

main :: IO ()
main = do
    s <- getLine :: IO String
    print . fst $ foldl' (\(c, l) q-> case (l>0, q) of
        (True, 'g') -> (c+1, l-1)
        (True, 'p') -> (c,   l-1)
        (False,'g') -> (c,   l+1)
        (False,'p') -> (c-1, l+1)) (0,0) s

Measured memory_bytes: 7548
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

from operator import mul
from functools import reduce



def main():
    n, k = list(map(int, input().split()))
    modulo = 1000_000_000 + 7

    def cmb(n, r):
        if n < r:
            return 0
        r = min(n - r, r)
        if r == 0:
            return 1
        numer = reduce(mul, range(n, n - r, -1))
        denom = reduce(mul, range(1, r + 1))
        return numer // denom % modulo

    for i in range(1, k+1):
        # i分割する方法
        a = cmb(k-1, i-1)
        # 赤のボールを分割する方法
        b = cmb(n-k+1, i)
        print(a * b % modulo)

main()

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

int main()
{
  string a, b;
  cin >> a >> b;
  int chk = atoi(a.append(b).c_str());
  for (int i=0; i<=100100; ++i) {
    if (i*i == chk) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){
	int a[3][3],i,j,flag=1;
	for(i = 0; i < 3; i++){
		for(j = 0; j < 3; j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(i = 0; i < 2; i++){
		for(j = 0; j < 2; j++){
			if(a[i][j] - a[i+1][j] != a[i][j+1] - a[i+1][j+1]){
				flag = 0;
			}
		}
	}
	flag ? printf("Yes\n") : printf("No\n");
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <algorithm>

using namespace std;

bool check(vector<long> F, vector<long> v, long val, long src)
{
    int i = 0;
    for (vector<long>::iterator itr = v.begin(); itr != v.end(); itr++, i++)
    {
        long temp = *itr;
        if (temp > val)
        {
            long temp2 = temp - val;
            if (temp2 % F[i] == 0)
            {
                temp2 = temp2 / F[i];
            }
            else
            {
                temp2 = temp2 / F[i] + 1;
            }
            src -= temp2;
            if (src < 0) return false;
        }
    }
    return true;
}

int main(void)
{
    int N;
    long K;
    cin >> N >> K;
    vector<long> A(N), F(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++)
    {
        cin >> F[i];
    }
    sort(A.begin(), A.end());
    sort(F.begin(), F.end(), greater<long>());
    vector<long> C(N);
    for (int i = 0; i < N; i++)
    {
        C[i] = A[i] * F[i];
    }
    long left = 0;
    long right = *max_element(C.begin(), C.end());
    while (left < right)
    {
        long mid = (left + right) / 2;
        if (check(F, C, mid, K))
        {
            right = mid;
        }
        else
        {
            left = mid + 1;
        }
    }
    cout << left << endl;
    return 0;
}

Measured memory_bytes: 8120
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

int a[510][510];

// [lb, ub]
void rec(int lb, int ub, int depth){
    if(lb == ub) return ;
    int mid = (lb + ub) / 2;

    // [lb, mid] ↔ [mid + 1, ub]
    for(int i=lb; i<=mid; i++){
        for(int j=mid+1; j<=ub; j++){
            a[i][j] = depth;
        }
    }

    rec(lb, mid, depth + 1);
    rec(mid + 1, ub, depth + 1);
}

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

    int n; cin>>n;

    rec(1, n, 1);

    for(int i=1; i<=n-1; i++){
        for(int j=i+1; j<=n; j++){
            cout << a[i][j] << " \n"[j == n];
        }
    }
}

Measured memory_bytes: 1536
import sys, math
input = sys.stdin.readline

def main():
    A, B, C, D = map(int, input().split())
    t = math.ceil(C / B)
    a = math.ceil(A / D)

    if t <= a:
        print("Yes")
    else:
        print("No")

if __name__ == '__main__':
    main()

Measured memory_bytes: 9180
//Streamline

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define nxvarep(n,x,a) ll n,x;cin>>n>>x;vector<ll>a(m);rep(i,0,m)cin>>a[i]
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
#define cout15(a) printf("%.15f\n",a)
template<class T>inline bool chmin(T& a,T b,bool f){
if(f==1){if(a>b){a=b;return true;}return false;}
else if(f==0){if(a<b){a=b;return true;}return false;}return false;}
typedef pair<ll,string> p;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

int main (){
    nxvarep(n,m,x);
    if(n>=m){
        cout<<0<<nnn;
        return 0;
    }
    sort(range(x));
    ll ma =0;
    vector<ll>d(m);
    rep(i,0,m-1){
        d[i]=abs(x[i]-x[i+1]);
    }
    sort(range(d),greater<int>());
    ll ans = x[m-1]-x[0];
    rep(i,0,n-1)ans-=d[i];
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 1792
//secreterror
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(ll i=0;i<n;i++)
#define rev(i, n) for(ll i=n-1;i>=0;i--)
#define forr(i, x, y) for(ll i=x;i<y;i++)
#define f first
#define s second
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vpii vector<pair<int,int>>

int main()
{
    ll n,w;
    cin>>n>>w;

    vector<ll>wigh(n);
    vector<ll>val(n);

    for(int i=0;i<n;i++){
        cin>>wigh[i]>>val[i];
    }

    ll dp[n+1][w+1]={0};

    for(int i=0;i<=n;i++){
        for(int j=0;j<=w;j++){

            if(i==0||j==0){
                dp[i][j]=0;
            }
            else if(wigh[i-1]>j){
                dp[i][j]=dp[i-1][j];
            }
            else
            {
                dp[i][j]=max(dp[i-1][j],dp[i-1][j-wigh[i-1]]+val[i-1]);
            }
            
        }
    }
    cout<<dp[n][w]<<endl;

}

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

using namespace std;

int main() {

    string s;
    cin >> s;

    int c, d;
    c = d = 0;

    for (size_t i = 0; i < s.size(); i++) {
        if (s[i] == '1')
            c += 1;
        else
            d += 1;
    }

    cout << s.size() - abs(d - c) << '\n';
    return 0;
}


Measured memory_bytes: 512
# coding: utf-8

N = int(input())

if N % 2 == 1:
    print(0)
else:
    h = []
    i = 1
    j = 1
    while i != 0:
        i = N // (5**j * 2)
        h += [i]
        j += 1
    s = 0
    for x in h:
        s += x
    print(s)

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

using namespace std;

using ll = long long;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s;
    cin >> s;
    char c = s[0];
    int cnt = 1;
    int ans = 0;
    for (int i = 1; i < n; i++) {
        if (s[i] != c) {
            ans++;
            c = s[i];
            cnt = 1;
        } else {
            cnt++;
        }
    }
    if (cnt > 0) ans++;
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
mt19937 rng(time(NULL));

const int D = 365, N = 26;
int d;
ll c[N+1];
ll s[D+1][N+1];
ll last[N];
int contest[D];

ll calc(int idx, int x) {
	ll ans = 0;
	ll l = idx-1, r = idx+1;
	ll len, len2;
	while(l > 0 && contest[l] != contest[idx]) l--;
	len = idx - l;
	while(r <= d && contest[r] != contest[idx]) r++;
	len2 = r - idx;
	ans -= s[idx][contest[idx]];
	ans -= c[contest[idx]] * len * len2;
	ll tmp = contest[idx];
	contest[idx] = x;

	l = idx-1, r = idx+1;
	while(l > 0 && contest[l] != contest[idx]) l--;
	len = idx - l;
	while(r <= d && contest[r] != contest[idx]) r++;
	len2 = r - idx;
	ans += s[idx][x];
	ans += c[x] * len * len2;
	contest[idx] = tmp;
	return ans;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> d;
	for(int i = 1; i <= N; i++)
		cin >> c[i];
	for(int i = 1; i <= d; i++) {
		for(int j = 1; j <= N; j++)
			cin >> s[i][j];
	}
	memset(last, 0, sizeof last);
	ll ans = 0;
	for(int i = 1; i <= d; i++) {
		ll penalty = 0;
		for(int j = 1; j <= 26; j++)
			penalty += c[j] * (last[j] - i);
		ll best = -1, idx = -1;
		for(int j = 1; j <= 26; j++) {
			ll cur = s[i][j] - penalty + c[j] * (i - last[j]);
			if(best < cur)
				best = cur, idx = j;
		}
		last[idx] = i;
		ans += best;
		contest[i] = idx;
	}

	for(int i = 0; i < 120000; i++) {
		int idx = rng() % d + 1;
		for(int to = 1; to <= 26; to++) if(to != contest[idx]) {
			ll change = calc(idx, to);
			if(change > 0) {
				contest[idx] = to;
				ans += change;
			}
		}
	}

	for(int i = 1; i <= d; i++)
		cout << contest[i] << '\n';

	return 0;
}

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

namespace ABC073A
{
	class Program
	{
		static void Main(string[] args)
		{
			String n;                           //文字列型変数ｎ

			n = Console.ReadLine();

			if (n[0] == '9' || n[1] == '9')
				Console.WriteLine("Yes");

			else
				Console.WriteLine("No");

			Console.ReadKey();



		//	int n;                              //整数型変数ｎ

	    //  n = int.Parse(Console.ReadLine());
		
		// if(n%10 == 9 || n/10 == 9)
		//         Console.WriteLine("Yes")


		}
	}
}


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

int main(){
	int N, K;
	std::cin >> N >> K;
	std::vector<int> h(N);
	for(auto&v:h)std::cin >> v;
	std::vector<int> dp(N,INT_MAX-2000);
	dp[0]=0;
	for(int i=0;i<N;++i){
		for(int k=1;k<=K;++k){
			if(i+k<N)dp[i+k]=std::min(dp[i+k],dp[i]+std::abs(h[i+k]-h[i]));
		}
	}
	std::cout << dp[N-1] << std::endl;
}


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

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

    if(2*k>b-a) {
        for(int i=a; i<=b; i++) cout<<i<<endl;
        return 0;
    }

    for(int i=a; i<a+k; i++) cout<<i<<endl;
    for(int i=b-k+1; i<=b; i++) cout<<i<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  int a;
  string s;
  cin >> a;
  cin >> s;
  if(a>=3200){
    cout << s << endl;
  }else{
    cout << "red" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
N = int(input())
A =  []
l1 = input().split()
for i in l1:
    A.append(int(i))
B = []
l2 = input().split()
for i in l2:
    B.append(int(i))
if sum(A) < sum(B):
    print(-1)
else:
    z = 0
    ar1 = []
    ar2 = []
    for i in range(N):
        if A[i] < B[i] :
            ar1.append(B[i] - A[i])
        if A[i] > B[i]:
            ar2.append(A[i] - B[i])
    if len(ar1) == 0:
        print(0)
    else:
        s = sum(ar1)
        ar2.sort(reverse = True)
        temp = 0
        b = 0
        for  i in range(len(ar2)):
            temp += ar2[i]
            if temp >= s:
                b = i+1
                break
        print(len(ar1)+b)


Measured memory_bytes: 30068
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  string S,T;
  cin >> S >> T;
  int count;
  if(S[0]==T[0]){count++;}
  if(S[1]==T[1]){count++;}
  if(S[2]==T[2]){count++;}
  cout << count << endl;
}


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

using namespace std;

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

struct UnionFind {
	vector<int> par;
	vector<int> rank;
	
	UnionFind() {}
	UnionFind(int n) {
		init(n);
	}
	
	void init(int n) {
		par.resize(n);
		REP(i, n) par[i] = i;
		rank.resize(n, 0);
	}
	
	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	
	void unite(int x, int y) {
		x = find(x);
		y = find(y);
		if (x == y) return;
		
		if (rank[x] > rank[y]) swap(x, y);
		par[x] = y;
		if (rank[x] == rank[y]) rank[x]++;
	}
};

int main() {
	int h, w;
	
	while (cin >> h >> w, h || w) {
		string str[100];
		REP(i, h) cin >> str[i];
		
		UnionFind uf(h * w);
		REP(i, h) REP(j, w) {
			if (i < h - 1 && str[i][j] == str[i + 1][j]) uf.unite(i * w + j, (i + 1) * w + j);
			if (j < w - 1 && str[i][j] == str[i][j + 1]) uf.unite(i * w + j, i * w + j + 1);
		}
		
		set<int> s;
		REP(i, h * w) s.insert(uf.find(i));
		cout << s.size() << endl;
	}
	return 0;
}

Measured memory_bytes: 1344
#include<stdio.h>
#include<iostream>
int main()
{
    int N;
    while(scanf("%d",&N)==1)
    {
        int array_1[N];
        int array_2[N];
        int array_3[N];
        int s=0;
        for(int a=0;a<N;a++)
        {
            scanf("%d",&array_1[a]);
        }
        for(int a=0;a<N;a++)
        {
            if(array_1[a]%2==0)
            {
                array_2[a]=array_1[a];
                continue;
            }
            if(array_1[a]%2==1)
            {
                array_2[a]=0;
                continue;
            }

        }
        for(int a=0;a<N;a++)
        {
            if(array_2[a]%3==0 || array_2[a]%5==0)
            {
                array_3[a]=0;
            }
            else
                array_3[a]=1;
        }
        for(int a=0;a<N;a++)
        {
            s=s+array_3[a];
        }
        if(s>0)
            printf("DENIED");
        else
            printf("APPROVED");
    }
    return 0;
}


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

struct Node
{
	int key;
	Node* parent;
	Node* left;
	Node* right;
};

Node* root_ptr = NULL;

void insert(int key)
{
	Node* x_ptr = root_ptr;
	Node* y_ptr = NULL;
	Node* z_ptr = new Node();
	if (z_ptr == NULL) {
		cout << "記憶域の確保に失敗しました。" << endl;
		return;
	}
	z_ptr->key = key;

	while (x_ptr != NULL) {
		y_ptr = x_ptr;
		if (z_ptr->key < x_ptr->key) x_ptr = x_ptr->left;
		else x_ptr = x_ptr->right;
	}
	z_ptr->parent = y_ptr;

	if (y_ptr == NULL) root_ptr = z_ptr;
	else {
		if (z_ptr->key < y_ptr->key) y_ptr->left = z_ptr;
		else y_ptr->right = z_ptr;
	}
}

// 左部分木->根->右部分木
void print_inorder(Node* ptr)
{
	if (ptr == NULL) return;
	print_inorder(ptr->left);
	cout << " " << ptr->key;
	print_inorder(ptr->right);
}

// 根->左部分木->右部分木
void print_preorder(Node* ptr)
{
	if (ptr == NULL) return;
	cout << " " << ptr->key;
	print_preorder(ptr->left);
	print_preorder(ptr->right);
}

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

	for (int i = 0; i < n; i++) {
		string cmd;
		cin >> cmd;
		if (cmd == "insert") {
			int key;
			cin >> key;
			insert(key);
		}
		else {
			print_inorder(root_ptr);	cout << endl;
			print_preorder(root_ptr);	cout << endl;
		}
	}
}


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

int main () {
	int H , W ;
	cin >> H >> W ;
    char board[H][W] ;
	for(int i = 0 ; i < H ; i++ ){
		for(int j = 0 ; j < W ; j++ ){
			cin >> board[i][j] ;
		}
	}
	int countH[H] = {} , countW[W] = {} ;
	for(int i = 0 ; i < H ; i++ ){
		for(int j = 0 ; j < W ; j++ ){
			if(board[i][j]=='#')countH[i]=1 ;
		}
	}
	for(int i = 0 ; i < W ; i++ ){
		for(int j = 0 ; j < H ; j++ ){
			if(board[j][i]=='#')countW[i]=1 ;
		}
	}
	for(int i = 0 ; i < H ; i++ ){
		for(int j = 0 ; j < W ; j++ ){
			if(countH[i]==1&&countW[j]==1) cout << board[i][j];
		}
		if(countH[i]==1)cout << endl ;
	}
	//for(int i = 0 ; i < H ; i++ ) cout << countH[i] ;
	//for(int i = 0 ; i < W ; i++ ) cout << countW[i] ;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <functional>
using namespace std;
int main(){

	int A, B, C, D, E;
	cin >> A;
	cin >> B;
	cin >> C;
	cin >> D;
	cin >> E;
	int Atena, Btena, Ctena, Dtena, Etena;
	Atena = A % 10;
	Btena = B % 10;
	Ctena = C % 10;
	Dtena = D % 10;
	Etena = E % 10;
	int Ahosei, Bhosei, Chosei, Dhosei, Ehosei;
	if(Atena != 0){Ahosei = A + (10-Atena);}else{Ahosei = A;}
	if(Btena != 0){Bhosei = B + (10-Btena);}else{Bhosei = B;}
	if(Ctena != 0){Chosei = C + (10-Ctena);}else{Chosei = C;}
	if(Dtena != 0){Dhosei = D + (10-Dtena);}else{Dhosei = D;}
	if(Etena != 0){Ehosei = E + (10-Etena);}else{Ehosei = E;}
	int ans;
	int minn;
	if(Atena != 0){minn = Atena;}
	if(minn > Btena && Btena != 0){minn = Btena;}
	if(minn > Ctena&& Ctena != 0){minn = Ctena;}
	if(minn > Dtena&& Dtena != 0){minn = Dtena;}
	if(minn > Etena&& Etena != 0){minn = Etena;}
	if(Atena == minn){
		ans = Bhosei + Chosei + Dhosei + Ehosei + A;
	}
	else if(Btena == minn){
		ans = Ahosei + Chosei + Dhosei + Ehosei + B;
	}
	else if(Ctena == minn){
		ans = Ahosei + Bhosei + Dhosei + Ehosei + C;
	}
	else if(Dtena == minn){
		ans = Ahosei + Bhosei + Chosei + Ehosei + D;
	}
	else if(Etena == minn){
		ans = Ahosei + Bhosei + Chosei + Dhosei + E;
	}
	cout << ans << endl;



}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

void solve()
{
	int n;
	int count = 1;
	while(cin >> n, n)
	{
		vector<int> x(n);
		vector<int> y(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> x[i] >> y[i];
		}
		double Area = 0;
		for(int i = 1; i < n - 1; ++i)
		{
			double x1 = x[i] - x[0];
			double y1 = y[i] - y[0];
			double x2 = x[i + 1] - x[0];
			double y2 = y[i + 1] - y[0];

			Area += x1 * y2 - x2 * y1;
		}
		printf("%d %.1f\n", count, fabs(Area) / 2);
		++count;
	}
}

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

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

int main() {
    long n;

    cin >> n;

    long i = 0;
    long j = 0;
    long cnt = 1;
    int tmp_num = sqrt(n);
    bool okflg = false;
    while ( 1 ) {
        if ( n % tmp_num == 0 ) {
            break;
        }
        tmp_num--;
    }
    i = tmp_num;
    j = n / tmp_num;
    cout << i + j - 2 << endl;

//    cout << i + j << endl;
//    }
//    long i = 1;
//    long j = 1;
//    while ( 1 ) {
//        long next_i = i + 1;
//        long next_j = j + 1;
//        if ( n == next_i * j ) {
//            i++;
//            break;
//        }
//        else if ( n == i * next_j ) {
//            j++;
//            break;
//        }
//        if ( n - i * next_j < n - next_i * j ) {
//            if ( n % next_j == 0 | n % i == 0 ) {
//                j++;
//            }
//            else {
//                i++;
//            }
//        }
//        else {
//            if ( n % next_i == 0 | n % j == 0 ) {
//                i++;
//            }
//            else {
//                j++;
//            }
//        }
////        cout << i << " " << j << endl;
////        cout << i * j << endl;
//    }

    return 0;
}

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

# PyPy3 2.4はPython 3.2.5互換. math.log2はPython 3.3で追加.
from math import log, floor

L = int(input())

N = floor(log(L, 2)) + 1
edge = []

# 長さ0の辺
for i in range(1, N):
    edge.append((i, i+1, 0))

# 長さ2**(i-1)の辺
for i in range(1, N):
    edge.append((i, i+1, 2**(i-1)))

# ここまでで長さ0,...,X-1のパスが完成
X = 2 ** (N-1)

# 残りの辺
while L > X:
    r = floor(log(L - X, 2))
    edge.append((r + 1, N, X))
    X += 2 ** r

# 出力
M = len(edge)
print(N, M)
for e in edge:
    print(' '.join(map(str, e)))

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

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

    ll n, a[5], m = 1000000000000000;
    cin >> n;
    
    rep(i, 5){
        cin >> a[i];
        m = min(m, a[i]);
    }
    
    ll b = n / m;
    ll mod = n % m;
    
    ll ans = 5 + (b-1) + ((mod == 0)? 0 : 1);
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N>>M;
  vector<int> road(M*2);
  for(int i=0;i<M*2;i++){
    cin>>road.at(i);
  }
  for(int i=1;i<=N;i++){
    int count=0;
    for(int j=0;j<M*2;j++){
      if(road.at(j)==i){
        count++;
      }
    }cout<<count<<endl;
  }
}

Measured memory_bytes: 256
S=input()
l=list(S)
N=len(S)
count=0
for i in range(1,N):
  if l[i]==l[i-1]:
    count+=1
    if l[i]=="0":
      l[i]="1"
    else:
      l[i]="0"

#T="".join(l)

#print(T)
print(count)

Measured memory_bytes: 3956
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
const int N = 3005;

int n;
double p[N], dp[N][N];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	for (int i = 1; i <= n; ++i)
		cin >> p[i];
	dp[1][1] = p[1];
	dp[1][0] = 1.0 - p[1];
	for (int i = 2; i <= n; ++i)
	for (int j = 0; j <= i; ++j) {
		if (j) dp[i][j] += dp[i - 1][j - 1] * p[i];
		dp[i][j] += dp[i - 1][j] * (1.0 - p[i]);
	}
	double ans = 0;
	for (int i = (n >> 1) + 1; i <= n; ++i)
		ans += dp[n][i];
	printf("%.12lf\n", ans);
}

Measured memory_bytes: 69120
#include<stdio.h>
int main(){

  int A[100][100],B[100],C[100];
  int i,j,n,m;


  scanf("%d%d",&n,&m);
  for(i=0;i<n;i++){
    for(j=0;j<m;j++){
      scanf("%d",&A[i][j]);
    }
}


  for(j=0;j<m;j++){
    scanf("%d",&B[j]);
  }

   for(i=0;i<n;i++){
     C[i]=0;
    for(j=0;j<m;j++){
      C[i] += A[i][j]*B[j];
    }}

     for(i=0;i<n;i++){

       printf("%d",C[i]);
       printf("\n");
     }

     return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cmath>
#include<string>
#include<fstream>
#include<vector>
#include<algorithm>
using namespace std;


int main()
{
    string s;
    long long k;
    cin>>s;
    cin>>k;
    int pfx1=0;
    for(int i=0; i<s.length(); i++)
    {
        if(s[i]=='1') pfx1++;
        else break;
    }
    if(k>pfx1) cout<<s[pfx1];
    else cout<<"1"<<endl;
    
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
using namespace std;
typedef pair<int,int> pp;

int N;
const int MAX_N = 100005;
char a[MAX_N];
vector<pp> ans;

void push_edge(int x,int y){
	ans.push_back({x,y});
}

void solve(){
	for(int i=1;i<N/2+(N%2);i++){
		push_edge(1,1+i);
	}
	int n = 1, m = N/2+(N%2)-1;
	for(int i=N/2;i>0;i--){
		if(a[i-1]=='1'){
			push_edge(n,n+m+1);
			n += m+1;
			m=0;
		}else{
			m++;
			push_edge(n,n+m);
		}
	}
}

int main(){
	scanf("%s",a);
	N = strlen(a);

	if(a[N-1]=='1' || a[0]=='0'){
		puts("-1");
		return 0;
	}
	for(int i=0;i<N-1;i++){
		if(a[i]!=a[N-i-2]){
			puts("-1");
			return 0;
		}
	}

	solve();
	for(pp i:ans){
		printf("%d %d\n",i.first,i.second);
	}

	return 0;
}

Measured memory_bytes: 2164
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

ll dup(ll a, ll b) { return (a+b-1) / b;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll n, a, b, c, d, e;
    cin >> n >> a >> b >> c >> d >> e;
    ll ans = 4 + max({dup(n, a), dup(n, b), dup(n, c), dup(n, d), dup(n, e)});
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <cassert>

#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
//#include <boost/foreach.hpp>
//#include <boost/range/algorithm.hpp>
#define rep(i,j,k) for(int i=(int)j;i<(int)k;i++)
#define ll long long
#define Sort(v) sort(all(v))
#define INF 1000000000
#define END return 0
#define pb push_back
#define se second
#define fi first
#define pb push_back
#define all(v) (v).begin() , (v).end()
#define MP make_pair
#define MOD 1000000007LL
using namespace std;
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};

int main (){
    int q;cin>>q;
    multiset<int> st;
    rep(i,0,q){
        int a,b;cin>>a>>b;
        if(a==0){
            st.insert(b);
            cout<<st.size()<<endl;
        }else if(a==1){
            cout<<st.count(b)<<endl;
        }else if(a==2){
            st.erase(b);
        }else {
            int r;cin>>r;
            auto low=st.lower_bound(b);
            auto high=st.upper_bound(r);
            for(auto it=low;it!=high;it++)cout<<*it<<endl;
            
            
        }
    }
    
    
}



/*

*/



Measured memory_bytes: 12340
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int mod=1000000007;

int main()
{

  ios::sync_with_stdio(0);
  cin.tie(0);
  string s;
  cin>>s;
  ll sum=0;
  for(int i=0; i<s.size(); i++){
    sum=sum+s[i]-'0';
  }
  if(sum%9==0){cout<<"Yes";}
  else{cout<<"No";}

  return 0;
}

Measured memory_bytes: 3756
n = int(input())
a = list(map(int, input().split()))
 
i, k = 0, 2
p, q, r, s = 0, a[0], a[1], sum(a[2:])
ans = sum(a)
for j in range(1, n-2):
    q += a[j]
    while abs((q-a[i]) - (p+a[i])) < abs(q - p):
        p += a[i]
        q -= a[i]
        i += 1
 
    r -= a[j]
    while abs((s-a[k]) - (r+a[k])) < abs(s - r):
        r += a[k]
        s -= a[k]
        k += 1
 
    pqrs = [p, q, r, s]
    ans = min(ans, abs(max(pqrs) - min(pqrs)))
    # print(i, j, k, ans, pqrs)
    
print(ans)

Measured memory_bytes: 24684