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

using namespace std;

long long power(long long base, long long p)
{
    long long answer = 1;

    while(p)
    {
        if(p%2)
            answer = answer*base;

        base = base*base;
        p = p >> 1;
    }

    return answer;
}

int main()
{
    long long no_of_numbers, product;
    cin >> no_of_numbers >> product;

    map <long long, int> exponent;
    for(long long i = 2; i*i <= product; i++)
    {
        while(product%i == 0)
        {
            exponent[i]++;
            product /= i;
        }
    }

    if(product > 1)
        exponent[product]++;

    long long gcd = 1;
    for(map <long long, int> :: iterator it = exponent.begin(); it != exponent.end(); it++)
    {
        int this_exponent = it->second;

        gcd *= power(it->first, this_exponent/no_of_numbers);
    }

    cout << gcd;
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 13 20:59:33 2016

@author: kt
"""
max=-1000
min=1000
N=input()
i=0
minx=0
l = map(int, raw_input().split())
sum=0
for var in l:
     sum+=var
sum=float(sum)/float(N)
isum=int(sum)
if sum==isum:
    minx=sum
elif isum+1-sum >sum-isum:
    minx=isum
else: 
    minx=isum+1
result=0
for var in l:
    result+=(var-minx)*(var-minx)
print int(result)

Measured memory_bytes: 2820
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

const long long MOD = 1000000007;

int main() {

  int N;
  cin>>N;

  long long ans = 1;
  for(int i=1; i<=N; i++){
    ans = (ans * i) % MOD;
  }

  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
import numpy as np

h, w = map(int, input().split())
s = np.empty((h, w), dtype='i8')
for i in range(h):
    s[i] = [i == '.' for i in list(input())]

right = np.copy(s)
left = np.copy(s)
for i in range(1, w):
    right[:, -i-1] = (right[:, -i] + 1) * s[:, -i-1]
    left[:, i] = (left[:, i-1] + 1) * s[:, i]
up = np.copy(s)
down = np.copy(s)
for i in range(1, h):
    up[i] = (up[i-1] + 1) * s[i]
    down[-i-1] = (down[-i] + 1) * s[-i-1]

print(np.max(right + left + up + down) - 3)


Measured memory_bytes: 214540
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  vector<int>in;
  int a;
  while(cin>>a){
    if(a)in.pb(a);
    else {
      cout<<in[in.size()-1]<<endl;
      in.erase(in.end()-1);
    }
  }
}

Measured memory_bytes: 1212
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
#include<string>
#include <cmath>

using namespace std;




int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long int A,B,C,K;
  cin >> A >> B >> C >> K;
  if(K % 2 == 0) {
    if(abs(A - B) > 1000000000000000000LL) {
      cout << "Unfair" << endl;
    }
    cout << A - B << endl;
  } else {
    if(abs(B - A) > 1000000000000000000LL) {
      cout << "Unfair" << endl;
    }
    cout << B - A << endl;
  }




}






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,int> pi;
typedef pair<lld,lld> pl;
typedef vector<int> vit;
typedef vector<vit> vitt;
typedef vector<lld> vlt;
typedef vector<vlt> vltt;
typedef vector<pi> vpit;
typedef vector<vpit> vpitt;
typedef long double ld;
#define x first
#define y second
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define mk(a,b) make_pair(a,b)
bool isrange(int y,int x,int n,int m){
	 if(0<=y&&y<n&&0<=x&&x<m) return true;
	 return false;
}
int dy[4] = {1,0,-1,0},dx[4]={0,1,0,-1},ddy[8] = {1,0,-1,0,1,1,-1,-1},ddx[8] = {0,1,0,-1,1,-1,1,-1};

int main(void){
	int n;
	scanf("%d",&n);
	if(n>=30) printf("Yes");
	else printf("No");
	return 0;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl '\n'
#define pb push_back
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
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<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const ll inf = 2e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

int dp[1 << 21];

signed main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	int n;
	cin >> n;
	int a[n][n];
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			cin >> a[i][j];
		}
	}
	dp[0] = 1;
	for(int mask = 1; mask < (1LL << n); mask++) {
		int cur = __builtin_popcount(mask);
		for(int j = 0; j < n; j++) {
			if(a[cur - 1][j] == 1 && (mask & (1LL << j))) {
				dp[mask] = (dp[mask] + dp[mask ^ (1LL << j)]) % mod;
			}
		}
	}
	cout << dp[(1 << n) - 1];

	return 0;
}

Measured memory_bytes: 19988
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define DUMP(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<": "<<(x)<<" (L"<<__LINE__<<")"<<endl
using namespace std;
using vint = vector<int>;
using vdouble = vector<double>;
using vstring = vector<string>;
using ll = long long;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

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


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


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

    string s;
    cin >> s;
    if(s=="BBB" or s=="AAA") cout << "No" << "\n";
    else cout << "Yes" << "\n";
    
}    


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <math.h>
#include <fstream>
#include <string>
#include <time.h>
#include <ctime>
#include <stdlib.h>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#pragma warning(disable : 4996)
using namespace std;

struct Node{
	int key;
    Node *prev;
	Node *next;
};

Node *nil;

void init(){
	nil = (Node *)malloc(sizeof(Node));
	nil->next=nil;
	nil->prev=nil;
}

void insert(int key){
	Node* x=(Node *)malloc(sizeof(Node));
	x->key=key;
	x->next=nil->next;
	nil->next->prev=x;
	nil->next=x;
	x->prev=nil;
}

Node* listSearch(int key){
	Node* cur = nil->next;
	while(cur != nil&&cur->key != key){
		cur = cur->next;
	}
	return cur;
}

void deleteNode(Node *t){
	if(t==nil)return;
	t->prev->next = t->next;
	t->next->prev = t->prev;
	free(t);
}

void deleteFirst(){
	deleteNode(nil->next);
}

void deleteLast(){
	deleteNode(nil->prev);
}

void deleteKey(int key){
	deleteNode(listSearch(key));
}

void print(){
	Node* cur = nil->next;
	while(cur != nil){
		if(cur != nil->next)printf(" "); 
		printf("%d",cur->key);
		cur = cur->next;
	}
	printf("\n");
}

int main(){

	int key,n;
	int size=0;
	char com[20];
	int np=0,nd=0;
	scanf("%d", &n);
	init();
	for(int i=0;i<n;i++){
		scanf("%s%d",com,&key);
		if(com[0]=='i'){insert(key);np++;size++;}
		else if(com[0]=='d'){
			if(strlen(com)>6){
				if(com[6]=='F')deleteFirst();
				else if(com[6]=='L')deleteLast();
			}
			else{
					deleteKey(key);nd++;
			}
			size--;
		}
	}

	print();

	return 0;
}

Measured memory_bytes: 32364
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////

ll dp[3010][3010];

int main() {
    string s, t; cin >> s >> t;
    s += '$', t += '%';

    memset(dp, 0, sizeof(dp));
    string ans = "";

    rep(i,s.size()) rep(j,t.size()) {
        if (s[i] == t[j]) {
            chmax(dp[i+1][j+1], dp[i][j]+1);
        }
        chmax(dp[i+1][j+1], dp[i+1][j]);
        chmax(dp[i+1][j+1], dp[i][j+1]);
    }
    
    int i = s.size()-1, j = t.size()-1;
    while (i > 0 && j > 0) {
        if (dp[i][j] == dp[i-1][j]) i--;
        else if (dp[i][j] == dp[i][j-1]) j--;
        else {
            ans = s[i-1]+ans;
            i--; j--;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 71040
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> bool max_self(T & a, const T & b){ 
  return b > a ? a = b, true : false; 
}
template<class T> bool min_self(T & a, const T & b){ 
  return b < a ? a = b, true : false;    
}
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);

int N, M;
LL total = 0;
vector<int> num;
vector<pair<int, int>> avail;

void solve(){
  int idx = 0;
  for(auto &ele : avail){
    for(int rep = 0; rep < ele.S; ++rep){
      if(num[idx] >= ele.F) break;
      num[idx] = ele.F;
      idx++;
      if(idx == N) goto out;
    }
  }

  out:
  for(int &ele : num) total += ele;
  cout << total << '\n';
  return;
}
    
int main(){
  FAST_IO
  cin >> N >> M;
  num.resize(N);
  avail.resize(M);
  for(int &ele : num) cin >> ele;
  for(auto &ele : avail) cin >> ele.S >> ele.F;

  sort(ALL(num));
  sort(ALLR(avail));

  solve();
  return 0;
}



Measured memory_bytes: 4428
#include<bits/stdc++.h>
using namespace std;
int main(){

    int n,minn,maxn;
    long long int sumn = 0;
    cin >> n;
    int a;
    cin >> a;
    minn = maxn = a;
    sumn += a;
    for(int i = 1; i < n; i++){
        cin >> a;
        if(minn > a){
            minn = a;
        }
        if(maxn < a){
            maxn = a;
        }
        sumn += a;
    }

    cout << minn << " " << maxn << " " << sumn << endl;

}


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

int main()
{
	int arr[5];
	for (int i = 0; i < 5; i++)
		cin >> arr[i];
	for(int i=0;i<5;i++)
		if (arr[i] == 0) {
			cout << i + 1;
			return 0;
		}

}

Measured memory_bytes: 3616
n, m = list(map(int, input().split()))
hs =  list(map(int, input().split()))
ans = [1]*n
for i in range(m):
    road = list(map(int, input().split()))
    if hs[road[0]-1] <= hs[road[1]-1]:
        ans[road[0]-1] = 0
    if hs[road[0]-1] >= hs[road[1]-1]:
        ans[road[1]-1] = 0
print(ans.count(1))


Measured memory_bytes: 19972
import sys
input = sys.stdin.buffer.readline
n,q=map(int,input().split())
import heapq
S=[]
D=dict()
for i in range(n):
  s,t,x=map(int,input().split())
  S.append((1,x,max(0,s-x)))
  S.append((-1,x,max(0,t-x)))
  D[x]=False
S.sort(key=lambda x:x[2])
X=[]
cur=0
for i in range(q):
  d=int(input())
  while cur<2*n:
    a,b,c=S[cur]
    if c>d:
      break
    else:
      cur+=1
      if a==1:
        heapq.heappush(X,b)
        D[b]=True
      else:
        D[b]=False
  while X:
    ans=heapq.heappop(X)
    if D[ans]:
      print(ans)
      heapq.heappush(X,ans)
      break
  if not X:
    print(-1)


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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

typedef struct node{
	int key=0;
	node *left=nullptr,*right=nullptr;
	node(){};
	node(int s):key(s){};
}node;

class BinarySearchTree{
private:
	node *root = new node;
	vector<int> inorder,preorder;
	int num_of_nodes=0;

	void getInsertPosition(node *now,int value){
		if(now->key>value){
			if(now->left==nullptr){
				node *tmp = new node;
				tmp->key=value;
				now->left=tmp;
			}else getInsertPosition(now->left, value);
		}else{
			if(now->right==nullptr){
				node *tmp = new node;
				tmp->key=value;
				now->right=tmp;
			}else getInsertPosition(now->right, value);
		}
	}
	void dfs(node *now){
		preorder.push_back(now->key);
		if(now->left!=nullptr)dfs(now->left);
		inorder.push_back(now->key);
		if(now->right!=nullptr)dfs(now->right);
		return;
	}
	void printVector(vector<int> a){
		for(auto x:a)cout<<" "<<x;
		cout<<endl;
	}
	bool containValue(node *now, int target){
		if(now->key==target)return true;
		if(now->left!=nullptr&&target<now->key)return containValue(now->left, target);
		if(now->right!=nullptr&&target>now->key)return containValue(now->right, target);
		return false;
	}
public:
	BinarySearchTree(){};
	void insert(int value){
		if(num_of_nodes==0){
			root->key=value;
			num_of_nodes++;
			return;
		}
		getInsertPosition(root, value);
	}
	
	void findValue(int value){
		cout<<(containValue(root,value)?"yes":"no")<<endl;
	}

	void solve(){
		inorder.clear(),preorder.clear();
		dfs(root);
		printVector(inorder);
		printVector(preorder);
	}
};


int main()
{
	int n;
	cin>>n;
	BinarySearchTree BST;
	rep(i,n){
		string command;
		cin>>command;
		if(command=="insert"){
			int value;
			cin>>value;
			BST.insert(value);
		}else if(command=="find"){
			int value;
			cin>>value;
			BST.findValue(value);
		}else{
			BST.solve();
		}
	}

	return 0;
}


Measured memory_bytes: 20328
#include <iostream>
#include <stdio.h>

using namespace std;

const int N = 1e5 + 5;
int a[N], b[N];
int L, R, n, m;
int pointer[N];

void enter()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= m; i++) {
        scanf("%d%d", &a[i], &b[i]);
        pointer[a[i]]++;
    }
}

void qsort(int l, int r, int a[], int b[]) {
    int i = l, j = r, x = a[(l + r) / 2];
    while (i <= j) {
        while (a[i] < x) i++;
        while (x < a[j]) j--;
        if (i <= j) {
            swap(a[i], a[j]);
            swap(b[i], b[j]);
            i++; j--;
        }
    }
    if (l < j) qsort(l, j, a, b);
    if (i < r) qsort(i, r, a, b);
}

void prepa() {
    qsort(1, m, a, b);
    for (int i = 1; i <= m; i += pointer[a[i]]) {
        int temp = pointer[a[i]];
        qsort(i, i + temp - 1, b, a);
    }
}

void solve() {
    L = a[1], R = b[1];
    for (int i = 2; i <= m; i++) {
        L = max(a[i], L);
        R = min(b[i], R);
    }
    printf("%d", max(R - L + 1, 0));
}

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


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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

  int N;
  Scd(N);
  ll sum = 0;
  vi a(1e5+1); Rep(i,N) Scd(a[0]), a[a[0]]++, sum += a[0];

  int Q;
  Scd(Q);
  int b,c;
  Rep(qqq,Q){
    Scd2(b,c);
    sum += 1ll*(c-b)*(a[b]);
    a[c] += a[b];
    a[b] = 0;
    printf("%lld\n", sum );
  }
  
}


Measured memory_bytes: 3800
while True:
    a, op, b = input().split()   
    a =int(a)                   
    b =int(b)                   


    if op=="?": 
        break
    else: 
     if op=="+":
      print(a + b)
     elif op=="-":
      print(a - b)
     elif op=="*":
      print(a * b)
     elif op=="/":
      print(a // b)


Measured memory_bytes: 5592
# inpute integer (x) along with integer sequence (n)
# finding the integer nearest to x within the given range 100
# no time i have to submit
x, n = map(int, input().split())  # take input from the user
P = list(map(int, input().split()))

for i in range(101):  # loop through the range
    length = x - i
    result = x + i
    if length not in P:
        print(length)
        break
    elif result not in P:
        print(result)
        break



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

using namespace std;

#define all(x) begin(x), end(x)

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using vi = vector<int>;

bool bad(int i, int j, int k) {
    return (i == 0 and j == 2 and k == 1)
        or (i == 0 and j == 1 and k == 2)
        or (i == 2 and j == 0 and k == 1);
}

bool bad(int i, int j, int k, int l) {
    return bad(i, j, k) or bad(j, k, l)
        or (i == 0 and k == 2 and l == 1)
        or (i == 0 and j == 2 and l == 1);
}

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

    // cannot contain
    // AGC
    // ACG
    // GAC
    // A.GC
    // AG.C
    //
    constexpr int MOD = 1e9 + 7;
    vector<vector<vi>> dp(4, vector<vi>(4, vi(4, 1)));
    dp[0][2][1] = 0;
    dp[0][1][2] = 0;
    dp[2][0][1] = 0;

    int n;
    cin >> n;
    for (int t = 4; t <= n; ++t) {
        vector<vector<vi>> ndp(4, vector<vi>(4, vi(4, 0)));
        for (int i = 0; i < 4; ++i) {
            for (int j = 0; j < 4; ++j) {
                for (int k = 0; k < 4; ++k) {
                    if (bad(i, j, k)) continue;

                    for (int l = 0; l < 4; ++l) {
                        if (bad(i, j, k, l)) continue;

                        ndp[j][k][l] += dp[i][j][k];
                        ndp[j][k][l] %= MOD;
                    }
                }
            }
        }

        swap(dp, ndp);
    }

    int ans = 0;
    for (int i = 0; i < 4; ++i) {
        for (int j = 0; j < 4; ++j) {
            for (int k = 0; k < 4; ++k) {
                ans += dp[i][j][k];
                ans %= MOD;
            }
        }
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n, m;
  cin >> n >> m;
  int onetime = m * 1900 + (n - m) * 100;
  cout << onetime * pow(2, m) << endl;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>

int a,b,d,k1,k2;

int extgcd(int a,int b,int &x,int &y)
{
    int d=a;
    if(b){
        d=extgcd(b,a%b,y,x);
        y-=(a/b) * x;
    }
    else
        x=1,y=0;
    return d;
}

int ab(int a)
{
    return (a<0)?-a:a;
}

int f(int la,int lb)
{
    return ab(la) + ab(lb);
}

int fun(int la,int lb)
{
    return a*ab(la) + b*ab(lb);
}

int main()
{
    while(~scanf("%d%d%d",&a,&b,&d),a+b+d)
    {
        int x,y;
        int gcd = extgcd(a,b,x,y);
        int k =  d/gcd;
        x *= k; y *= k;
        int dx = b/gcd, dy = a/gcd;

        int mina = f(x,y),minb = f(x,y),t1 = 0,t2 = 0,sum1 = -1,sum2 = -1;

        for(k1=1;;k1++)
        {
            if(f(x+k1*dx,y-k1*dy)>mina)
                break;
            else if(f(x+k1*dx,y-k1*dy)<mina)
                mina = f(x+k1*dx,y-k1*dy),sum1 = fun(x+k1*dx,y-k1*dy),t1 = k1;
            else{
                if(a*ab(x+k1*dx)+b*ab(y-k1*dy)<sum1)
                    mina = f(x+k1*dx,y-k1*dy),sum1 = fun(x+k1*dx,y-k1*dy),t1 = k1;

            }
        }
        int cnt = 0;
        for(k2=1;;k2++)
        {
            if(f(x-k2*dx,y+k2*dy)>minb)
                break;
            else if(f(x-k2*dx,y+k2*dy)<minb)
            {
                minb = f(x-k2*dx,y+k2*dy);
                t2 = k2;
                sum2 = fun(x-k2*dx,y+k2*dy);
            }
            else
            {
                if(a*ab(x-k2*dx)+b*ab(y+k2*dy)<sum2)
                {
                    minb = f(x-k2*dx,y+k2*dy);
                    t2 = k2;
                    sum2 = fun(x-k2*dx,y+k2*dy);
                }
            }
        }
        if(minb<mina)
            printf("%d %d\n",ab(x-t2*dx),ab(y+t2*dy));
        else if(minb>mina)
            printf("%d %d\n",ab(x+t1*dx),ab(y-t1*dy));
        else
        {
            if(a*ab(x+t1*dx)+b*ab(y-t1*dy)>a*ab(x-t2*dx)+b*ab(y+t2*dy))
                printf("%d %d\n",ab(x-t2*dx),ab(y+t2*dy));
            else
                printf("%d %d\n",ab(x+t1*dx),ab(y-t1*dy));
        }
    }
    return 0;
}

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

namespace AtCoder
{

    static class Program
    {
        static void Main()
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            //

            int A;int B;int C;
            Multi(out A, out B, out C);
            var ans = A;
            if (A == B)
            {
                ans = C;
            }
            if(A == C)
            {
                ans = B;
            }

            Console.WriteLine(ans);

            //
            Console.Out.Flush();
            Console.ReadKey();
        }

        static void Solve()
        {

        }


        static public string GetStr() { return Console.ReadLine().Trim(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public char[] GetCharArray() { return Console.ReadLine().Split(' ').Select(char.Parse).ToArray(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }
        static string yesno(this bool b) { return b ? "yes" : "no"; }
        static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c, out V d)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<V>(ar[3]);
        }
    }
}

Measured memory_bytes: 11348
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define NIL -1
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数

//-------------------------------------------------
// 
void yes(){
  cout <<"Yes"<<endl ;
}
void no(){
  cout <<"No"<<endl ;
}


//-------------------------------------------------
// メモ
/*






*/
//-------------------------------------------------


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n ;
  cin >> n ;
  vector<ll> a(n+1) ;
  vector<ll> b(n) ;
  ll ans = 0 ;
  REP(i,n+1){
    cin >> a[i] ;
  }
  REP(i,n){
    cin >> b[i] ;
  }
  REP(i,n){
    ans += min(a[i],b[i]) ;
    if(a[i]<=b[i]){
      b[i] -= a[i] ;
      if(a[i+1]>=b[i]){
        ans += b[i] ;
        a[i+1] -= b[i] ;
      }
      else{
        ans += a[i+1] ;
        a[i+1] = 0 ;
      }
    }
  }
  
  cout << ans <<endl ;
  
  
  
  
  return 0 ;
}



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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
#define loop(i, a) for (int i = 0; i < a; i++)
#define revloop(i, a) for (int i = a-1; i > -1; i--)
#define show(a) cout << a << "\n"
#define MOD 1000000007
#define V vector
#define S set
#define P pair
#define M map
#define PQ priority_queue


LL gcd(LL a, LL b) {
    if (!a) return b;
    return gcd(b%a, a);
}
LL lcm(LL a, LL b) {
    if (a > b) swap(a, b);
    return (a/gcd(a, b))*b;
}
int main() {
    //freopen("inputs.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int n;
    cin >> n;
    LL num[n];
    loop(i, n) cin >> num[i];
    LL l = 1;
    loop(i, n) l = lcm(l, num[i]);
    show(l);

    return 0;
}


Measured memory_bytes: 256
def solve():
    A, B, C = map(str, input().split())
    if A =="5" and B =="7" and C =="5":
        ans = "YES"
    elif A =="5" and B =="5" and C =="7":
        ans = "YES"
    elif A == "7" and B =="5" and C =="5":
        ans = "YES"
    else:
        ans = "NO"
    print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 2940
//minamoto
#include<bits/stdc++.h>
#define R register
#define inline __inline__ __attribute__((always_inline))
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
char buf[1<<21],*p1=buf,*p2=buf;
inline char getc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}
int read(){
    R int res,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(res=ch-'0';(ch=getc())>='0'&&ch<='9';res=res*10+ch-'0');
    return res*f;
}
int read(char *s){
	R int len=0;R char ch;while(((ch=getc())>'9'||ch<'0'));
	for(s[++len]=ch;(ch=getc())>='0'&&ch<='9';s[++len]=ch);
	return s[len+1]='\0',len;
}
double readdb()
{
    R double x=0,y=0.1,f=1;R char ch;
    while((ch=getc())>'9'||ch<'0')(ch=='-')&&(f=-1);
    for(x=ch-'0';(ch=getc())>='0'&&ch<='9';x=x*10+ch-'0');
    for(ch=='.'&&(ch=getc());ch>='0'&&ch<='9';x+=(ch-'0')*y,y*=0.1,ch=getc());
    return x*f;
}
char sr[1<<21],z[20];int K=-1,Z=0;
inline void Ot(){fwrite(sr,1,K+1,stdout),K=-1;}
void print(R int x){
    if(K>1<<20)Ot();if(x<0)sr[++K]='-',x=-x;
    while(z[++Z]=x%10+48,x/=10);
    while(sr[++K]=z[Z],--Z);sr[++K]='\n';
}
const int P=998244353;
inline int add(R int x,R int y){return x+y>=P?x+y-P:x+y;}
inline int dec(R int x,R int y){return x-y<0?x-y+P:x-y;}
inline int mul(R int x,R int y){return 1ll*x*y-1ll*x*y/P*P;}
int ksm(R int x,R int y){
	R int res=1;
	for(;y;y>>=1,x=mul(x,x))(y&1)?res=mul(res,x):0;
	return res;
}
const int N=4e5+5;
typedef long long ll;
char s[N];int n,tmp;ll res;
int main(){
	scanf("%s",s+1),n=strlen(s+1);
	fd(i,n,1)if(s[i]=='A')res+=tmp;
	else if(s[i]=='C'&&s[i-1]=='B')--i,++tmp;
	else tmp=0;
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define repo(i,N) for(int i = 1; i < (N); i++)
//#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (10);   小数点以下１０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//string s = to_string(int数);
//int n = stoi(string文字列);

int main() {
  string s;
  cin >>s;

  repo(i,s.size()) {
    if (s[i-1]=='A' && s[i]=='C') {
    cout << "Yes" << endl;
    return 0;
    }
  }
  
  cout << "No" << endl;
  
}


Measured memory_bytes: 256
#include<stdio.h>
typedef long long ll;
int main(){
    ll N,a[200010],b[200010]={0};
    scanf("%lld",&N);
    for(ll i=0;i<N-1;i++){
        scanf("%lld",&a[i]);

    }
    for(ll i=0;i<N-1;i++){
        b[a[i]-1]++;
    }
    for(ll i=0;i<N;i++){
        printf("%lld\n",b[i]);
    }
}

Measured memory_bytes: 4860
N=int(input())
*L,=map(int,input().split())

L.sort()
from bisect import*
i=0
ans=0
while i<N:
    j=i+1
    while j<N:
        ans+=bisect_left(L[j:],L[i]+L[j])-1
        j+=1
    i+=1

print(ans)

Measured memory_bytes: 74588
from collections import deque
import sys
input = sys.stdin.readline
def solve():
  n = int(input())
  query = [[] for _ in range(n)]
  for i in range(n-1):
    a,b = (int(i) for i in input().split())
    a -= 1
    b -= 1
    query[a].append((b,i))
    query[b].append((a,i))
  ans = 0
  for i in range(n):
    ans = max(ans,len(query[i]))
  print(ans)
  node = deque([])
  stack = [[] for _ in range(n)]
  for i in range(n):
    if len(query[i]) == ans:
      node.append((i,ans,100000))
      break
  for i in range(n):
    stack[i] = (len(query[i]))
  #print(stack)
  tmp = [-1]*(n-1)
  visit = [False]*n
  while node:
    #print(node)
    place,maxnode,last = node.popleft()
    donotuse = [last]
    for j,i in query[place]:
        if tmp[i] == -1:
          while maxnode in donotuse:
            maxnode -= 1
            if maxnode <= -1:
              maxnode = ans
          tmp[i] = maxnode
          donotuse.append(maxnode)
          maxnode -= 1
        
        if visit[j]:
          continue
        else:
          node.append((j,stack[j],tmp[i]))
    visit[place] = True
    
    
  for i in tmp:
    print(i)
solve()


Measured memory_bytes: 78880
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
from decimal import Decimal
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())


a = I()
print(a**3 + a**2 + a)

Measured memory_bytes: 27180
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

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

  int sum = 0;
  for(int i = 0; i < n; i++){
    for(int j = i + 1; j < n; j++){
      sum += d[i] * d[j];
    }
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val a, b = sc.nextInt
//  val xss = List.fill(rows, cols)(sc.nextInt)

  val ans =
    if (13 <= a) b
    else if (6 <= a && a <= 12) b / 2
    else 0

  println(ans)
}

Measured memory_bytes: 25412
# coding: utf-8

class Node:
    def __init__(self, me, left, right):
        self.me = me
        self.left = left
        self.right = right
        self.parent = None

class NodeTree:
    def __init__(self, root=None):
        self.root = root
        
    def insert(self,z):
        y = None
        x = self.root
        while x != None:
            y = x
            if z.me < x.me:
                x = x.left
            else:
                x = x.right
        z.parent = y
        
        if y == None:
            self.root = z
        elif z.me < y.me:
            y.left = z
        else:
            y.right = z

    def find(self, z):
        y = None
        x = self.root
        while True:
            if x.me == z.me:
                return True
            elif x.me > z.me:
                if x.left != None:
                    x = x.left
                else:
                    return False
            else:
                if x.right != None:
                    x = x.right
                else:
                    return False
            
    
    def getPreorder(self, node, ans):
        ans.append(node)
        if node.left != None:
            self.getPreorder(node.left, ans)
        if node.right != None:
            self.getPreorder(node.right, ans)
            
    def getInorder(self, node, ans):
        if node.left != None:
            self.getInorder(node.left, ans)
        ans.append(node)
        if node.right != None:
            self.getInorder(node.right, ans)

        
def printAns(ans):
    for a in ans:
        print(" " + str(a.me),end="")
    print()
    
m = int(input().rstrip())
nt = NodeTree()
for i in range(m):
    line = input().rstrip().split()
    if line[0] == "insert":
        nt.insert(Node(int(line[1]),None,None))
    elif line[0] == "find":
        if nt.find(Node(int(line[1]),None,None)):
            print("yes")
        else:
            print("no")
    else:
        ans = []
        nt.getInorder(nt.root,ans)
        printAns(ans)
        ans = []
        nt.getPreorder(nt.root,ans)
        printAns(ans)


Measured memory_bytes: 88384
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
const ll inv2=5e8+4;
int main()
{
	ll dp[3001][3001]={};
	int n, q;
	cin>>n>>q;
	int a[3001];
	for(int i=0; i<n; i++) cin>>a[i];
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			if(a[i]>a[j]) dp[i][j]=1;
		}
	}
	for(int i=0; i<q; i++){
		int x, y; cin>>x>>y;
		x--; y--;
		for(int j=0; j<n; j++){
			if(j==x || j==y) continue;
			dp[x][j]=dp[y][j]=(dp[x][j]+dp[y][j])*inv2%MOD;
			dp[j][x]=dp[j][y]=(dp[j][x]+dp[j][y])*inv2%MOD;
		}
		dp[x][y]=dp[y][x]=(dp[x][y]+dp[y][x])*inv2%MOD;
	}
	ll ans=0;
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			ans=(ans+dp[i][j])%MOD;
		}
	}
	for(int i=0; i<q; i++) ans=ans*2%MOD;
	cout<<ans<<endl;
	return 0;
}

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

int main() {
 int A; int B;
  cin>>A>>B;
  int N=1;
  if(B==1)
    cout<<0<<endl;
  else{
  while(N*A-(N-1)<B){
    N+=1;
  }
  cout<<N<<endl;
  }
}
  

Measured memory_bytes: 256
(* O(n) *)
let solve n hs =
  List.fold_left
    (fun ((sofar_max, count) as sofar) h ->
      if sofar_max <= h then (h, count + 1) else sofar)
    (0, 0)
    hs |> snd

let read_ints () = read_line () |> Str.split (Str.regexp " ") |> List.map int_of_string

let _ =
  let n = read_int () in
  let hs = read_ints () in
  solve n hs |> string_of_int |> print_endline

Measured memory_bytes: 4480
#include <map>
#include <algorithm>
#include <cassert>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> T inf;
template<> constexpr int inf<int> = 1e9;
template<> constexpr ll inf<ll> = 1e18;
template<> constexpr ld inf<ld> = 1e30;
#define DEBUG(X) cerr<<__LINE__<<" "<<#X<<": "<<X<<endl;
#define DUMP(A, n) for (auto x=begin(A); x!=begin(A)+n;x++){cout <<*x<< ' ';} cout<<endl;
#define DUMPP(A, n, m) for (auto x=begin(A); x != begin(A)+n;x++) {for (auto y=begin(*x); y != begin(*x)+m;)cout <<*y++<< ' '; cout<<endl;};
#define DUMPM(M) for (auto itr=mp.begin(); itr!=mp.end(); itr++) {cout<<itr->first<<" -> "<<itr->second<<endl;}
#define all(x) begin(x),end(x)
#define sci(x) int x;scanf("%d",&x);
#define scii(x, y) int x,y;scanf("%d%d",&x,&y);
#define scf(x) scanf("%d",&x),x!=0
#define scff(x, y) scanf("%d%d",&x,&y),x!=0&&y!=0
#define scdd(x, y) ld x,y;scanf("%Lf%Lf",&x,&y);
#define FOR(i,x,y) for(int i=(x);i<(int)(y);i++)
#define FORR(i,x,y) for(int i=(x);i<=(int)(y);i++)
#define REP(i,y) for(int i=0;i<(int)(y);i++)
#define REPP(i,y) for(int i=1;i<=(int)(y);i++)
#define fin(x,y) ld x,y; while(~scanf("%Lf,%Lf",&x,&y))

int main() {
  sci(N);
  int x = 0;
  int ans=0;
  REP(i,N) {
    char c;
    cin >> c;
    if (c=='I') {
      x++;
    } else x--;
    chmax(ans, x);
  }
  printf("%d\n",ans);
}


Measured memory_bytes: 256
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
map<pair<int,int>,int> m;
int x[110000];
int y[110000];
vector<pair<int,int> >v;
int dx[]={0,1,0,1};
int dy[]={0,0,1,1};
int main(){
	int a;
	scanf("%d",&a);
	for(int i=0;i<a;i++){
		int z;
		scanf("%d%d%d",x+i,y+i,&z);
		m[make_pair(x[i],y[i])]=z;
		v.push_back(make_pair(x[i],y[i]));
		v.push_back(make_pair(x[i]-1,y[i]));
		v.push_back(make_pair(x[i],y[i]-1));
		v.push_back(make_pair(x[i]-1,y[i]-1));
	}
	int ret=0;
	for(int i=0;i<v.size();i++){
		int X=v[i].first;
		int Y=v[i].second;
		int val=0;
		for(int j=0;j<4;j++){
			if(m.count(make_pair(X+dx[j],Y+dy[j])))val+=m[make_pair(X+dx[j],Y+dy[j])];
		}
		ret=max(ret,val);
	}
	printf("%d / 1\n",ret);
}

Measured memory_bytes: 11576
import sys
sys.setrecursionlimit(1000000000)
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
mlmis = lambda: [-int(x) for x in input().split()]
INF = float('inf')
#

def main():
    H,W,K=mis()
    S = [input() for i in range(H)]
    ranges = []
    u = b = 0
    while u < H:
        if '#' in S[b]:
            ranges.append(range(u, b+1))
            u = b = b+1
        elif b == H-1:
            last = ranges.pop()
            ranges.append(range(last[0], H))
            break
        else:
            b += 1
    c = 1
    for ran in ranges:
        l = r = 0
        s = []
        while l < W:
            s.append(c)
            if any(S[i][r]=='#' for i in ran):
                c += 1
                l = r = r+1
            elif r == W-1:
                for i, elem in enumerate(s):
                    if elem == c:
                        s[i] = c-1
                break
            else:
                r += 1
        for _ in ran:
            print(' '.join(map(str, s)))
        


main()


Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1000;

int n, k, ans = 0;
int a[MAX_N + 5];

int main()
{
	//ios_base::sync_with_stdio(0);
	//cin.tie(0); cout.tie(0);
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++)
    {
        scanf("%d", &a[i]);
    }
    sort(a, a+n);
    for (int i = 0; i < k; i++)
    {
        ans += a[i];
    }
    printf("%d\n", ans);
    return 0;
}


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

int main(){

    int H, N;
    cin >> H >> N;

    int A = 0, temp = 0;
    for (int i=0; i<N; i++){
        cin >> temp;
        A += temp;
    }

    if (A >= H){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
let modulo = 1000000007
let (+@) a b = (a + b) mod modulo
let (-@) a b = (a - b + modulo) mod modulo
let () =
  Scanf.scanf "%d %d" @@ fun n k ->
  let a = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  let dp = Array.init (n+1) (fun _ -> Array.make (k+1) 0) in
  for i = 0 to k do dp.(0).(i) <- 1 done;
  for i = 1 to n do
    dp.(i).(0) <- 1;
    for j = 1 to k do
      dp.(i).(j) <- dp.(i).(j-1) +@
        if j - a.(i-1) > 0 then dp.(i-1).(j) -@ dp.(i-1).(j - a.(i-1) - 1)
        else dp.(i-1).(j);
    done;
  done;
  Printf.printf "%d\n" (if k = 0 then dp.(n).(0) else dp.(n).(k) -@ dp.(n).(k-1))


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

long long n, a[100], b[100], c[100], ans;

int main(){
	ans=0;
	cin >> n;
	for (int i=0;i<n;i++) cin >> a[i];
	for (int i=1;i<=n;i++) cin >> b[i];
	for (int i=1;i<n;i++) cin >> c[i];
	for (int i=0;i<n;i++){
		ans+=b[a[i]];
		if (i<n-1 && (a[i]==a[i+1]-1)) ans+=c[a[i]];
//		cout << ans << "\n";
	}
	cout << ans << "\n";
}

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

int main() {
	int N, ans = INT_MAX;
	cin >> N;
	vector<int> W(N);
	for (int& i : W) cin >> i;
	for (int i = 1; i < N; ++i) W[i] += W[i - 1];
	for (int i = 0; i < N - 1; ++i) ans = min(abs(2 * W[i] - W.back()), ans);
	cout << ans;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
  using namespace std;
#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) int ab;cin>>ab;(p).push_back(ab);
#define vecpl2(p) long long ab;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main() {
	
	int N,K,X,Y;
	cin>>N>>K>>X>>Y;
	int ans=0;
  int i=1;
  while(i<=N){
    if(i<=K){
      ans+=X;
    }else{
      ans+=Y;
    }
    i++;
  }
	ce(ans)
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <math.h>

using namespace std;
bool p[100005];
bool a[100005];
int b[100005];
int main()
{
	memset(b,0,sizeof(b));
	p[1]=true;
	for(int i=2;i<=sqrt(100000);i++)
	{
	 	if(p[i]==false)
		{
			for(int j=i*i;j<=100000;j+=i)
			{
				p[j]=true;
			}
		}	
	}
	for(int i=2;i<=100000;i++)
	{
		if(i!=2&&p[i]==false&&p[(i+1)/2]==false)
		{
			a[i]=true;
		}
	}
	for(int i=2;i<=100000;i++)
	{
		if(a[i]==true) b[i]=b[i-1]+1;
		else b[i]=b[i-1];
	}
	int q;
	cin>>q;
	for(int i=1;i<=q;i++)
	{
		int l,r;
		cin>>l>>r;
		cout<<b[r]-b[l-1]<<endl;
	}
	return 0;
}

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

int main() {
    int n, l;
    cin >> n >> l;
    vector<string> data(n);
    for (auto &el: data) cin >> el;
    sort(begin(data), end(data));
    for (auto el: data) cout << el;
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N=0, M=0,ans=0;

    int max=0,min=0,pre,preN=0;

    cin>>N>>M;

    vector<pair<int,int>> vec(M);
    for(int i=0;i<M;i++){
        cin>>vec[i].second>>vec[i].first;
    }
    sort(vec.begin(),vec.end());

    
    pre=vec[0].first;
    preN=1;
    ans++;
    for(int k=0;k<M;k++){
        if(pre<=vec[k].second){
            ans++;
            pre=vec[k].first;
        }
    }


    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<string.h>
#include<string>
#include<set>
#include<limits.h>
#define P pair<int,int>
using namespace std;

vector<P>V[100000];
int a[200006];
signed main() {
	int n, c; cin >> n >> c;
	for (int i = 0; i < n; i++) {
		int x, y, z; cin >> x >> y >> z;
		x = x * 2 - 1; y *= 2;
		V[z - 1].push_back({ x,y });
	}
	for (int i = 0; i < c; i++) {
		sort(V[i].begin(), V[i].end());
		for (int j = 0; j < V[i].size(); j++) {
			if (j&&V[i][j].first < V[i][j - 1].second) {
				V[i][j].first++;
			}
			a[V[i][j].first]++;
			a[V[i][j].second]--;
		}
	}
	int ans = 0, sum = 0;
	for (int i = 0; i <= 200005; i++) {
		sum += a[i];
		ans = max(ans, sum);
	}
	cout << ans << endl;
}


Measured memory_bytes: 4608
#include<iostream>
using namespace std;
int main(){
	int n;
	while (cin >> n, n){
		int sort[100], hoge, cnt = 0;
		for (int i = 0; i < n; i++){
			cin >> sort[i];
		}
		for (int i = 0; i < n - 2; i++){
			for (int j = 0; j < n - 1 - i; j++){
				if (sort[j] > sort[j + 1]){
					hoge = sort[j];
					sort[j] = sort[j + 1];
					sort[j + 1] = hoge;
					cnt++;
				}
			}
		}
		cout << cnt << "\n";
	}
	return 0;
}

Measured memory_bytes: 1156
// 2018/01/05 Tazoe

#include <iostream>
using namespace std;

int main()
{
	while(true){
		int m, nmin, nmax;
		cin >> m >> nmin >> nmax;

		if(m==0 && nmin==0 && nmax==0)
			break;

		int P[200];
		for(int i=0; i<m; i++){
			cin >> P[i];
		}

		int gap = -1;			// ギャップの最大値
		int n = -1;			// 合格者の人数

		for(int i=nmin; i<=nmax; i++){
			int g = P[i-1]-P[i];		// ギャップ

			if(gap<=g){
				gap = g;
				n = i;
			}
		}

		cout << n << endl;
	}

	return 0;
}



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

int main() {
  int N;
  int dat;
  cin >> N;
  dat = N % 10;
  
  if(dat == 3)
  {
    cout << "bon" << endl;
  }
  else if(dat == 0 || dat == 1 || dat == 6|| dat == 8)
  {
    cout << "pon" << endl;
  }
  else
  {
    cout << "hon" << endl;
  }
}


Measured memory_bytes: 3624