akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e17;
 
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
 
template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}
template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}

int A,B,C,D,E,F,G,N,M,R,Q,X,Y,Z;
string s,t;

signed main()
{
	IOS();
	cin>>R>>D>>X;
	rep(i,0,10){
		cout<<R*X-D<<endl;
		X = R*X-D;
	}
}

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


int main(void)
{
	//変数の宣言
	int n;
	int i,j,k;
	int sosu[5010];
	int count;
	
	//データの読み込み
	scanf("%d",&n);
	
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	//(だいたい)5000以下の素数を列挙した配列
	for(i=0;i<5000;i++){
		sosu[i]=i+2;
	}
	sosu[5000]=0;
	i=0;
	while(sosu[i]!=0){
		j=i+1;
		k=i+1;
		while(sosu[j]!=0){
			if(sosu[j]%sosu[i]!=0){
				sosu[k]=sosu[j];
				k++;
			}
			j++;
		}
		i++;
	}
	
	
	
//	printf("計算部分終了\n");
	
	//出力
	
	count=0;
	i=0;
	while(count<n){
		if(sosu[i]%10==1){
			printf("%d",sosu[i]);
			count++;
			if(count!=n) printf(" ");
		}
		i++;
	}
	
//	printf("結果の出力終了\n");
	
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
int main(void)
{
	int w, h, x, y, r;

	scanf("%d %d %d %d %d", &w, &h, &x, &y, &r);

	if(0 > x - r)
		printf("No\n");
	else if(0 > y - r)
		printf("No\n");
	else if(w < x + r)
		printf("No\n");
	else if(h < y + r)
		printf("No\n");
	else 
		printf("Yes\n");
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); 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; }
const ll MOD = 1e9+7;

const ll INF = 1e13;

int main(){
    int N;
    cin >> N;
    vector<int> H(N);
    REP(i,N){
        cin >> H[i];
    }

    vector<ll> DP(N+2, INF);
    DP[0] = 0;
    REP(i,N-1){
        chmin(DP[i+1], DP[i] + abs(H[i+1] - H[i]));
        if(i != N-2)
            chmin(DP[i+2], DP[i] + abs(H[i+2] - H[i]));
    }

    ll ans = DP[N-1];
    //REP(i,N+1) printf("%d : %lld\n", i, DP[i]);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1408
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
#include <numeric>
#include <iomanip>
#define M_PI acos(-1)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1000000007;
const int MAX_V = 201;
int now = 0;

const int MAX = 200000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
struct edge {
	int t;
	ll cost;
	edge(int _t, ll _cost) : t(_t)
		, cost(_cost) {
	}
};
bool isPrime(int n) {

	if (n == 1) return false;
	for (ll i = 2; i * i <= n; i++)
	{
		if (n % i == 0) return false;
	}
	return true;
}
void Solve() {
	
	int n;
	cin >> n;
	ll a[100010], b[100010];
	for (size_t i = 0; i < n; i++)
	{
		cin >> a[i] >> b[i];
	}

	ll res = 0;
	for (int i = n - 1; i >= 0; i--)
	{
		ll v = b[i] - (a[i] + res) % b[i];
		res += (v == b[i] ? 0 : v);
	}
	cout << res << endl;
}
int main() {
	Solve();
	return 0;
}



Measured memory_bytes: 1792
/*input
5 10 2

*/
#include <bits/stdc++.h>

using namespace std;

inline int f(int x, int m) {
  return x / m;
}

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

  int l, r, d; cin >> l >> r >> d;
  cout << f(r, d) - f(l - 1, d) << endl;

  return 0;
}

Measured memory_bytes: 3644
#include <stdio.h>

int main(void) {

  int sum, sub, mul;
  int a, b;
  int max;

  scanf("%d", &a);
 scanf("%d", &b);
 //printf("%d%d", a, b);

  sum = a+b;
  //printf("%d", sum);
  sub = a-b;
  //printf("%d", sub);
  mul = a*b;
  //printf("%d", mul);

  if(sum > sub) {
    max = sum;
  }
  else {
    max = sub;
  }

  if(max < mul) {
    max = mul;
  }

  printf("%d", max);

  return 0;

}



Measured memory_bytes: 128
#include<map>
#include<set>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<ctime>
#include<vector>
#include<bitset>
#include<string>
#include<cstdio>
#include<numeric>
#include<utility>
#include<sstream>
#include<cstdlib>
#include<iomanip>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#include<unordered_map>
#define _USE_MATH_DEFINES
#define inf 999999999999999999
#define rep(i,n,m) for(lli i=(lli)(n);i<(lli)(m);++i)
#define reep(i,n,m) for(int i=(int)(n);i<=(int)(m);++i)
#define per(i,m,n) for(lli i=(int)(m)-1;i>=(int)(n);--i)
#define st(n) sort(n.begin(), n.end())
#define rev(n) reverse(n.begin(),n.end())
#define ou(S) cout << S << endl
#define pb(n) push_back(n)
#define ue(N) N.erase(unique(N.begin(),N.end()),N.end());
#define nou(S) cout << S
#define hou(S) cout << setprecision(30) << S << endl
#define vec(K,L,N,S) vector<L> K(N,S)
#define dv(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define tv(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define maxx 5100000
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define endl "\n"
typedef long long int lli;
typedef unsigned long long int uli;
const uli mod = 1e9 + 7;
using namespace std;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	int n, k;
	cin >> n >> k;
	for(int i = 0; i < 1000000000; ++i) {
		if(pow(k, i)-1 >= n) {
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

// Min is for getting min of two ints.
func Min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

// Abs is for getting abs of an int.
func Abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func main() {
	var N, A, B, C int
	fmt.Scan(&N, &A, &B, &C)
	L := make([]int, N)
	for l := range(L) {
		fmt.Scan(&L[l])
	}
	minCost := 1 << 30
	for i := 0 ; i < 1 << uint(N * 2) ; i++ {
		j := i
		var a, b, c int;
		var used int
		for l := range(L) {
			flag := j & 3
			if 1 == flag {
				a += L[l]
				used++
			} else if 2 == flag {
				b += L[l]
				used++
			} else if 3 == flag {
				c += L[l]
				used++
			}
			j >>= 2
		}
		if 0 == a || 0 == b || 0 == c {
			continue
		}
		minCost = Min(minCost, (used - 3) * 10 + Abs(
			a - A) + Abs(b - B) + Abs(c - C))
	}
	fmt.Println(minCost)
}

Measured memory_bytes: 512
#include <iostream>
#include<math.h>
using namespace std;
int main(void){
    // Here your code !
    long long int n,a,b,max,min,ans;
    cin>>n>>a>>b;
    if(n!=1){
    max=a+b*(n-1);
    min=b+a*(n-1);
    ans=fmaxl(0,max-min+1);
    cout<<ans<<endl;
    }
    else{
        if(a==b)cout<<1<<endl;
        else{
            cout<<0<<endl;
        }
    }
}


Measured memory_bytes: 256
n,t = map(int,input().split())
c = [list(map(int,input().split())) for i in range(n)]

ans=10000
for i in c:
    if i[1] <= t and i[0] < ans:
        ans = i[0]

if ans == 10000:
    print('TLE')
else:
    print(ans)

Measured memory_bytes: 3060
x = int(input())
a = [1]
for i in [2, 3, 5, 6, 7, 10, 11, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 26, 27, 28, 29, 30, 31]:
    j = 2
    while i**j <= 1000:
        a.append(i**j)
        j += 1
a = sorted(a)
for k in a:
    if k<=x:
        ans = k
    else:
        break
        
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<math.h>
#include<vector>
#include<set>
#include<algorithm>
#include<ctype.h>
#include<unordered_set>
#include<string>
#include<iomanip>
#include<queue>
#include<limits>
#include<map>
#include<stack>
#include<iterator>
#include<deque>
#define MOD 1000000009
#define INF 9999999999999 
#define pb push_back
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;
ll ncr(ll n, ll r)
{
	ll i, ans = 1, k = 0;
	if (r == 0)
		return 1;
	else if (n < r)
		return 0;
	for (i = n; i >= n - r + 1; i--)
	{
		ans *= i;
		ans /= n - i + 1;
	}


	return ans;

}
bool visited[6] = { false };
int n = 6;
vector<int> adj[6];


void max_heapify(int a[100], int i)
{
	int l, r, largest = i;
	l = 2 * i + 1;
	r = 2 * i + 2;
	if (l<n && a[l]>a[i])
		largest = l;
	if (r<n && a[r]>a[l])
		largest = r;
	if (largest != i)
	{
		int k;
		k = a[i];
		a[i] = a[largest];
		a[largest] = k;
		max_heapify(a, largest);
	}

}
int power(ll x, ll y, ll p)
{
	int res = 1;
	x = x % p;

	while (y > 0)
	{

		if (y & 1)
			res = (res * x) % p;


		y = y >> 1;
		x = (x * x) % p;
	}
	return res;
}

bool square(ll n)
{
	double x;
	x = sqrt(n);
	if (x == floor(x))
		return true;
	else return false;
}


bool prime(ll n)
{
	ll i;
	for (i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
			return false;
	}
	return true;
}
void dfs(ll a, ll b, vector<pair<ll, ll>>adj[][1001], bool visited[][1001])
{
	visited[a][b] = true;
	for (auto u : adj[a][b])
	{
		if (!visited[get<0>(u)][get<1>(u)])
		{
			visited[get<0>(u)][get<1>(u)] = true;
			dfs(get<0>(u), get<1>(u), adj, visited);
		}
	}
}
ll modi(ll a, ll m)
{
	return power(a, m - 2, m);

}
void kmp(string s, ll pi[]) {
	int n = (int)s.length();
	pi[0] = 0;
	for (int i = 1; i < n; i++) {
		int j = pi[i - 1];
		while (j > 0 && s[i] != s[j])
			j = pi[j - 1];
		if (s[i] == s[j])
			j++;
		pi[i] = j;
	}

}
struct pair_hash {
	size_t operator()(const pair<int, int>& p) const noexcept {
		return hash<ll>() ((((ll)p.first) << 32) | ((ll)p.second));
	}
};


int main() {
	fast;
	ll a, b, c;
	cin >> a >> b >> c;
	if (4 * a * b < (c - a - b) * (c - a - b) && c - a - b > 0) {
		cout << "Yes\n";
	}
	else
		cout << "No\n";
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

int main()
{
	int x;
	int i;

	

	while (1) {
		scanf("%d", &x);
		if (x == 0) break; 
		x = 1000 - x;
		i = 0;
			 
	while (x >= 500 ) {
		i++;
		x -= 500;
	}
	while (x >= 100 ) {
		i++;
		x -= 100;
	}
	while (x >= 50 ) {
		i++;
		x -= 50;
	}
	while (x >= 10 ) {
		i++;
		x -= 10;
	}
	while (x >= 5 ) {
		i++;
		x -= 5;
	}
	while (x >= 1 ) {
		i++;
		x -= 1;
	}
	printf("%d\n", i);
	}
	
	return (0);
}

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

int main() {
	int n, k; cin >> n >> k;
	vector<int> h(n);
	rep(i, n) cin >> h[i];
	sort(h.rbegin(), h.rend());
	if (n <= k) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = 0;
	for (int i = k; i < n; ++i) {
		ans += h[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, a) for(int i=0; i<int(a); i++)
#define ALL(x) begin(x), end(x)
#define VI vector<int>
using namespace std;
typedef long long LL;

const int MAX_N=100005;

struct WeightedUnionFind {
    int n;
    int INF = 1e9;
    vector<int> par, sz, weight;

    WeightedUnionFind() {}
    WeightedUnionFind(int n_) : n(n_), par(n_, 0), sz(n_, 1), weight(n_, 0) { iota(begin(par), end(par), 0); }

    int find(int x) { 
        if(x==par[x]) return x;
        int y = find(par[x]);
        weight[x]+=weight[par[x]];
        return par[x]=y;
    }

    void unite(int x, int y, int w) {
        int px = find(x);
        int py = find(y);
        if(px == py) return;
        if(sz[px] < sz[py]) {
            swap(px, py);
            swap(x, y);
            w = -w;
        }
        sz[px] += sz[py];
        par[py] = px;
        weight[py] = weight[x] - w - weight[y];            
    }

    int same(int x, int y) { return find(x) == find(y); }

    int diff(int x, int y) { // x -> y
        if(same(x, y)) return weight[x]-weight[y];
        return INF;
    }
};

int main() {
    int n, m;
    cin >> n >> m;
    WeightedUnionFind wuf(n+1);

    while(m--) {
        int a, b, w;
        cin >> a >> b >> w;
        if(wuf.same(a,b)) {
            if(wuf.diff(a,b) != w) {
                cout << "No" << endl;
                return 0;
            }
        } else {
            wuf.unite(a,b,w);
        }
    }
    cout << "Yes" << endl;
    return 0; 
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define all(v) begin(v), end(v)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll n;
  cin >> n;
  
  vector<ll> a(n);  rep(i, 0, n) cin >> a.at(i);
  vector<ll> b(n);  rep(i, 0, n) cin >> b.at(i);
  vector<ll> c(n);  rep(i, 0, n) cin >> c.at(i);
  
  sort(all(a));
  sort(all(b));
  sort(all(c));
  
  ll ans = 0;
  rep(j, 0, n) {
    ll i = lower_bound(all(a), b.at(j)) -a.begin();
    ll k = upper_bound(all(c), b.at(j)) -c.begin();
    i = (i == 0 and a[i] >= b[j] ?0LL :i-1-0+1);
    k = (k==n-1 and b[j] >= c[k] ?0LL :n-1-k+1);
    ans += i*k;
  }
  
  cout << ans << "\n";
}

Measured memory_bytes: 2688
#インポート
import sys

#入力用
def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def ISS(): return sys.stdin.readline().rstrip().split()
def IS(): return sys.stdin.readline().rstrip()

Sa = list(IS())
Sb = list(IS())
Sc = list(IS())
x = "a"
while 0==0:
    if x == "a":
        if len(Sa)==0:
            print("A")
            break
        else:
            x = Sa.pop(0)
    elif x == "b":
        if len(Sb)==0:
            print("B")
            break
        else:
            x = Sb.pop(0)
    else:
        if len(Sc)==0:
            print("C")
            break
        else:
            x = Sc.pop(0)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << endl;
  err(++it, args...);
}
int max(int a , int  b){
  if(a > b) return a;
  else return b;

}
int min(int a , int b){
  if(a < b) return a;
  else return b;
}
bool cmp(pair < int , string >   a , pair < int , string >   b){
  if(a.first < b.first ) return true;
  else return false;
}
int ans=0;
void solve(int n , int val , int r , int x  , int y){
  //cout << n << " " << val << "++\n";
  if(val > r) return;
  if(n == -1) {
    int k = val&x;
    int kk = val&y;
    //cout << val << " " << k << " " << kk  << "+++\n";
    if(((val&x) !=0) && ((val&y)!=0)){
      if(ans==0) ans =val;
      else if(log(ans&x) + log(ans&y) < log(val&x) + log(val&y)) ans=val;
      else if(log(ans&x) + log(ans&y) == log(val&x) + log(val&y)){
       // cout << ans << " " << val << "++\n";
        if(ans > val) ans=val;
      }
    }
    return;
  }
  int m = val + (1LL<<n);
  solve(n-1,m,r , x,y);
  solve(n-1,val,r,x,y);
}
int c[105];
int a[105][105];
int b[105];
int32_t main(){  
  int n,m,x;
  cin >> n >> m >> x;
  for(int i = 0; i < n ; i++){
    cin >> c[i];
    for(int j = 0; j < m ; j++) cin >> a[i][j];
  }
int ans  = LLONG_MAX;
  for(int  i = 0; i < (1LL<<n) ; i++){
    for(int j = 0 ; j < m ; j++) b[j]=0;
    int res=0;
    for(int j = 0 ; j < n ; j++){
      if(((1LL << j)&i) > 0){
          res+=c[j];
          for(int k = 0  ; k < m ; k++) b[k]+=a[j][k];
      } 
    }
    int f=0;
    for(int j = 0 ; j  <m ;j++){
      if(b[j] < x){
        f=1;
      }
    }
    if(!f) ans = min(ans,res);
  }
  if(ans == LLONG_MAX) cout << "-1" << "\n";
  else cout << ans << "\n";
  return 0;
}
/*
10010
01011
11000

16+
*/

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9+7;
 
int main(){
    int n, a, b;
    cin >> n >> a >> b;

    cout << min(a*n, b) << endl;

    return 0;
}

Measured memory_bytes: 256
n,p = map(int, input().split())
s = list(map(int, list(input())))
if p in (2, 5):
  print(sum(i+1 for i in range(n) if s[i]%p == 0))
  exit(0) 
ans = g = 0
d = [0]*p
d[0] = 1
t = 1
for i in range(n-1,-1,-1):
    g = (g + s[i]*t)%p
    ans += d[g]
    d[g] += 1
    t = (t*10)%p
print(ans)

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

int main() {
  
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  
  int ans = 0;
  
  
   for(int i = 0; i < K; i++) {
     if(i < A) ans++;
     else if(i < A + B) continue;
     else ans--;
   }
  
  cout << ans << endl;
}

Measured memory_bytes: 3604
/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>
 
// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std
 
Jehian Norman Saviero;
 
// MACROS TYPE
typedef long l;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;
 
// MACROS FOR PRINT
#define nl printf("\n")
#define sp printf(" ")
 
// MACROS FOR ATTRIBUTE
#define fi first
#define se second
 
// MACROS FOR FUNCTION AND METHOD
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ALL(x) (x).begin(), (x).end()
#define ALLN(x,n) (x), (x)+(n)
#define CUBE(x) (SQR(x)*(x))
#define SET(x,y) for (int _qwe = sizeof(x)/sizeof(x[0]); _qwe; ) x[--_qwe] = (y)
#define SQR(x) ((x)*(x))
#define SSORT(x,sz) sort(ALLN(x,sz))
#define RESET(x) memset((x), 0, sizeof(x))
#define VSORT(x) sort(ALL(x))
 
// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)

int main() {
	ll N, A, B;
	scll(N), scll(A), scll(B);
	ll tot = N / (A + B);
	ll sisa = N % (A + B);
	sisa = min(sisa, A);
	printf("%lld\n", sisa + tot * A);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;

#define st              first
#define nd              second
#define pb              push_back
#define pf              push_front
#define all(a)          (a).begin(), (a).end()
#define lwb             lower_bound
#define upb             upper_bound
#define vvll            vector<vector<ll> >
#define Mset(s, n)      memset(s, n, sizeof(s))
#define Sz(a)           int((a).size())
#define Max(a, b, c)    max(max((ll)(a), (ll)(b)), (ll)(c))
#define Min(a, b, c)    min(min((ll)(a), (ll)(b)), (ll)(c))
#define Unique(a)       sort(all(a)); (a).resize(unique(all(a)) - (a).begin())

typedef long double ld;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

const ll MOD = 1e9 + 7;
const int oo = 2e9;
const ld PI = acos((ld) -1);
int Getbit(ll x, int k){return (x >> (k - 1)) & 1;}
ll Lcm(ll a, ll b) {return a / __gcd(a, b) * b;}
bool isPrime(ll n){for(ll i = 2; i * i <= n; i++){if(n % i == 0) return 0;} return (n > 1) ? 1 : 0;}
ll Powmod(ll n, ll k, ll p = MOD) {ll r = 1; for(; k; k /= 2, n = n * n % p){if(k & 1) r = r * n % p;} return r;}

const int N = 2e3 + 5;

ll n, m, k;
ll a[N][N];

void Solve(){
    cin >> m >> n >> k;
    int cnt = 0;
    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= n; j++){
            char c;
            cin >> c;
            if(c == '#'){
                a[i][j] = ++cnt;
            }
        }
        for(int j = 1; j <= n; j++){
            if(a[i][j - 1] && !a[i][j]){
                a[i][j] = a[i][j - 1];
            }
        }
        for(int j = n; j > 0; j--){
            if(a[i][j + 1] && !a[i][j]){
                a[i][j] = a[i][j + 1];
            }
        }
    }
    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= n; j++){
            if(a[i - 1][j] && !a[i][j]){
                a[i][j] = a[i - 1][j];
            }
        }
    }
    for(int i = m; i > 0; i--){
        for(int j = 1; j <= n; j++){
            if(a[i + 1][j] && !a[i][j]){
                a[i][j] = a[i + 1][j];
            }
        }
    }
    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= n; j++){
            cout << a[i][j] << " ";
        }
        cout << "\n";
    }

}

int main(){
    Speed;
    int query = 1; //cin >> query;
    while(query--){
        Solve();
    }
}





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

int main() {
    int h, w;

    while (true) {
        cin >> h >> w;
        if (h == 0 && w == 0) break;

        rep(i,h) {
            rep(i,w) cout << '#';
            cout << endl;
        }

        cout << endl;
    }
}


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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair



int N, M, Q;

int L[200000], R[200000];
int imo[502][502];

void prepare() {
    // mset(imo, 0);
    rep(i,M){
        int from = L[i], to = R[i];
        ++imo[from][to];
    }

    rep1(c,N) {
        imo[N][c] += imo[N][c-1];
    }
    for (int r=N-1; r>0; --r){
        // rep(c,N+1) {
        for(int c=0; c<=N; ++c) {
            imo[r][c+1] += imo[r][c];
        // }
        // rep(c,N+1) {
            imo[r][c] += imo[r+1][c];
        }
    }
}

int main() {
    scanf("%d %d %d", &N, &M, &Q);
    rep(i,M) {
        scanf("%d %d", &L[i], &R[i]);
    }

    prepare();

    rep(i,Q) {
        int p,q;
        scanf("%d %d", &p, &q);
        printf("%d\n", imo[p][q]);
    }
    return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
  ll n, a, b;
  cin >> n >> a >> b;
  ll t = a + b;
  ll m = n / t;
  ll ans = m * a;
  ans += min(n % t, a);
  cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define MAX 2000001
#define INF 100000001

int S[MAX],size = 0;

int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i + 1;
}

void maxHeapify(int i){
  int l,r,largest,kari;
  l = left(i);
  r = right(i);
  if(l <= size && S[l] > S[i]) largest = l;
  else largest = i;
  if(r <= size && S[r] > S[largest]) largest = r; 

  if(largest != i){
    kari = S[i];
    S[i] = S[largest];
    S[largest] = kari;
    maxHeapify(largest);
  }
}

void increaseKey(int i, int key){
  int kari;
  if(key < S[i]) printf("new key is smaller than current key\n");
  S[i] = key;
  while(i>1 && S[parent(i)] < S[i]){
    kari = S[i];
  S[i] = S[parent(i)];
  S[parent(i)] = kari;
  i = parent(i);
  }
}

void insert(int key){
  size += 1;
  S[size] = -INF;
  increaseKey(size,key);
}

int extractMax(){
  int max;
  if(size < 1) printf("heap underflow\n");
  max = S[1];
  S[1] = S[size];
  size--;
  maxHeapify(1);
  return max;
}

int main(){
  int i,key;
  char order[10];
  while(1){
    scanf("%s",order);
    if(strcmp(order,"insert") == 0){
      scanf("%d",&key);
      insert(key);
    }
    else if(strcmp(order,"extract") == 0){
      printf("%d\n",extractMax());
    }
    else if(strcmp(order,"end") == 0){
      break;
    }
  }

  return 0;

}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

std::map<long long, int> primeFact(long long n) {
    std::map<long long, int> res;
    for (long long i=2; i*i<=n; i++) {
        while (n%i == 0) {
            res[i]++;
            n /= i;
        }
    }
    if (n != 1) {
        res[n] = 1;
    }
    return res;
}

void solve() {
    ll n;
    cin >> n;

    auto pf = primeFact(n);
    int res = 0;
    for (auto p : pf) {
        int num = p.second;
        for (int i=1; i<100; ++i) {
            if (num < i*(i+1)/2) {
                res += i-1;
                break;
            }
        }
    }
    cout << res << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#include<string>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long int
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))//memset only use to initialize 0 or -1 no other number.
#define pii pair<int,int>
#define pll pair<ll,ll>
#define INF 1e9
#define INFL 1e18
//#define mod 1000000007
#define mod 998244353
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds; 
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> os_pair;

ll power(ll x,ll n){ll res =1;while(n>0){if(n%2==1){res=res*x;}x=x*x;n=n/2;}return res;}
ll powm(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

//cout<< fixed << setprecision(10)


int main(){

    fast
    int T;
    T=1;
    //cin>>T;
    while(T--){
    	int x,n,i,j;
    	cin>>x>>n;
    	set<int>s;
    	for(i=0;i<n;i++)
    	{
    		int y;
    		cin>>y;
    		s.insert(y);
		}
		for(i=0;i<200;i++)
		{
			if(s.find(x-i)==s.end())
			{
				cout<<x-i;
				return 0;
			}
			if(s.find(x+i)==s.end())
			{
				cout<<x+i;
				return 0;
			}
		}
    	
    	

}
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define all(x) x.begin(), x.end()
#define MOD 1000000007
#define vi vector < int >
#define pii pair < int, int >
#define INF (int)1e9
#define pb push_back
#define fastIO ios::sync_with_stdio(0); cin.tie(0);

int n;
vector < vi > arr;

int cache[100010][2];

//0 - Black, 1 - White

int dpSol(int i, bool color, int parent)
{
    if(arr[i].empty())
    {
        if(color)
            return 2;
        return 1;
    }
    
    int &res = cache[i][color];
    if(res != -1)
        return res;
    
    ll ans = 1;
    for(int it : arr[i])
    {
        if(it != parent)
        {
            if(color == 0)
                ans = (ans * dpSol(it, 1, i)) % MOD;
            else
            {
                int temp = ((ll)dpSol(it, 1, i) + dpSol(it, 0, i)) % MOD;
                ans = (ans * temp) % MOD;
            }
        }
    }
    
    return res = (int)ans;
}

int main()
{
    fastIO
    cin >> n;
    
    arr = vector < vi >(n + 1);
    for(int i = 0; i < n - 1; ++i)
    {
        int u, v;
        cin >> u >> v;
        arr[u].push_back(v);
        arr[v].push_back(u);
    }
    
    memset(cache, -1, sizeof(cache));
    
    if(n == 1)
        cout << 2;
    else
        cout << (dpSol(1, 0, 0) + dpSol(1, 1, 0)) % MOD;

    return 0;
}

Measured memory_bytes: 14848
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
using namespace std;
#define INF 100000000
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define rep(i, n) for(int (i)=1; (i)<=(n); (i)++)
typedef pair<int, int> P;
typedef long long ll;
int main(){
    int N;
    cin >> N;
    int res = N;
    while(res > 0)  res -= 1000;
    cout << abs(res) << endl;
    return 0;
}

Measured memory_bytes: 3612
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 1e5 + 10;
int R , C , n , vis[N + N];
ll a[N + N];
vector<pii> g[N + N];
ll MinR , MinC;

void dfs(int c,ll num) {
  vis[c] = true;
  a[c] = num;
  if(c < R) MinR = min(MinR , num);
  else MinC = min(MinC , num);
  for(auto e : g[c]) {
    int t = e.fi;
    int x = e.se;
    if(vis[t]) {
      if(a[c] + a[t] != x) {
        puts("No");
        exit(0);
      }
    } else {
      dfs(t , x - num);
    }
  }
}

int main(){
  scanf("%d%d%d",&R,&C,&n);
  rep(i,0,n) {
    int r , c , a;
    scanf("%d%d%d",&r,&c,&a);
    --r;--c;
    c += R;
    g[r].pb(mp(c , a));
    g[c].pb(mp(r , a));
  }
  rep(i,0,R+C) if(!vis[i]) {
    MinR=MinC=1ll<<60;
    dfs(i,0);
    if(MinR+MinC<0) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 15104
#include<bits/stdc++.h>
#define ll long long int

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  string s,t;
  cin >> s >> t;

  ll k=0;
  map<char,vector<ll>> v;
  for(int i=0;i<s.size();i++){
    v[s[i]].push_back(i);      //とある文字がsの何番目にあるか(0-indexed)
  }
  for(int i=0;i<t.size();i++){
    if(v[t[i]].size())k++;
  }

  ll l;

  if(k!=t.size())cout << -1 << endl;
  else{
    k=-1;//いまsの何番目を見ているか
    ll p=0;//sを何回結合したか
    for(int i=0;i<t.size();i++){
      l=lower_bound(v[t[i]].begin(),v[t[i]].end(),k+1)-v[t[i]].begin();
      if(l==v[t[i]].end()-v[t[i]].begin()){
        p++;
        k=v[t[i]][0];
      }
      else{
        k=v[t[i]][l];
      }
    }

    cout << p*s.size()+k+1 << endl;

  }

}

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

#define ld long double
#define ll long long
 
int main(){
    /*#ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        //freopen("test.txt","r",stdin);
        //freopen("output.txt","w",stdout);
    #endif*/
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;

    int n,c = 0;cin>>n;
    for(int i = 1;i <= n;i++){
        int a;cin>>a;
        if(a != i){
            c++;
        }
    }
    if(c > 2){
        cout<<"NO";
    }
    else {
        cout<<"YES";
    }

    /*#ifndef ONLINE_JUDGE
        cout << "\nTime Elapsed : " << 1.0 * clock() << " ms\n";
    #endif*/
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <algorithm>
#include <functional>

using namespace std;

int main() {
  string s, t;
  int ans = 0;
  cin >> s;
  cin >> t;

  for (int i = 0; i < s.length(); i++) {
    if (s[i] != t[i]) {
      ans++;
    }
  }

  cout << ans;
  
  return 0;
}


Measured memory_bytes: 3564
package main
import (
    "bufio"
    "fmt"
    "os"
    "strconv"
)

func main () {
    sc := bufio.NewScanner(os.Stdin)
    sc.Split(bufio.ScanWords)

    // Get input "n" and "q"
    var n int
    var q int
    if sc.Scan() { n, _ = strconv.Atoi(sc.Text()) }
    if sc.Scan() { q, _ = strconv.Atoi(sc.Text()) }

    // Get input array
    var inName []string
    var inTime []int
    inName = make([]string, n)
    inTime = make([]int, n)
    for i := 0; i < n; i++ {
        if sc.Scan() { inName[i] = sc.Text() }
        if sc.Scan() { inTime[i], _ = strconv.Atoi(sc.Text()) }
    }

    // Preparation
    var progress int = 0    // the number of finished process each loop
    var fin int = 0         // the total number of finished process
    var isFirst bool = true
    var total int = 0

    // Carry out
    for {
        for i := 0; i < n - fin; i++ {
            inTime[i] -= q
            if inTime[i] < 1 && isFirst {
                isFirst = false
                total += q + inTime[i]
                progress++
                fmt.Printf("%s %d\n", inName[i], total)
                continue
            } else if inTime[i] > 0 && isFirst {
                total += q
            }
            if inTime[i] > 0 && !isFirst {
                total += q
                inTime[i], inTime[i-progress] = inTime[i-progress], inTime[i]
                inName[i], inName[i-progress] = inName[i-progress], inName[i]
            } else if inTime[i] < 1 && !isFirst {
                total += q + inTime[i]
                fmt.Printf("%s %d\n", inName[i], total)
                progress++
            }
        }
        isFirst = true
        fin += progress
        progress = 0
        if n == fin { break }
    }
}



Measured memory_bytes: 3984
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}

int main() {
	int n; cin >> n;
	if (n <= 9) {
		cout << n << endl;
	}
	else if (n <= 99) {
		cout << 9 << endl;
	}
	else if (n <= 999) {
		cout << 9 + (n - 99) << endl;
	}
	else if (n <= 9999) {
		cout << 909 << endl;
	}
	else if (n <= 99999) {
		cout << 909 + (n - 9999) << endl;
	}
	else {
		cout << 90909 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7; //924844033 1000000000 + 9;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum, ans,dp[3100][3100],a[220000], b[220000];
string str, ss;
bool f[200000];
char c[4000][4000];
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost; };
struct edge {
	LL from, to, cost;
};
vector<vector<Edge>>vec;
vector<edge>ed;
vector<LL>v;
map<string, LL>ma;
set<LL>st[200000];

void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
	}
	for (int len = 1; len <= n; len++) {
		for (int i = 0; i + len <= n; i++) {
			int j = i + len;
			if ((n - len) % 2 == 0) {
				dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j - 1]);
			}
			else {
				dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j - 1]);
			}
		}
	}
	cout << dp[0][n] << endl;
	return 0;
}


Measured memory_bytes: 88320
#include <iostream>
#include <sstream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int main(void){
	int h,w;cin >> h >> w;cin.ignore();
	vector <string> image(h+2);
	string edge = "";
	for(int i=0; i<w+2; i++) edge+="#";

	image[0] = edge;
	image[h+1] = edge;
	for(int i=1; i<h+1; i++){
		string row;
		cin >> row;
		image[i] = "#"+row+"#";
	}
	for(int i=0; i<h+2; i++){
		cout << image[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc118/tasks/abc118_c

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

//------------------------------------------------------------------------------
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}

//------------------------------------------------------------------------------
const int N_MAX = 1e5;
const int A_I_MAX = 1e9;

int N;
int A[N_MAX];

void solve() {
  int ans = A[0];
  FOR(i, 1, N - 1) ans = gcd(ans, A[i]);
  printf("%d\n", ans);
}

void input() {
  scanf("%d", &N);
  REP(i, N) scanf("%d", A + i);
}

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


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

int main(){
  int N; cin >> N;
  int count=0;
  int now=1;
  for(int i=0;i<N;i++){
    int a; cin >> a;
    if(a==now){
      now++;
    }
    else count++;
  }
  if(now==1){
    cout << -1 << endl;
  }
  else cout << count << endl;
}
    
    
    

Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;
int N,Q;
string S;
ll A[100010],C[100010],AC[100010];

int main(){
    cin >> N >> Q >> S;
    for(int i=1;i<N;i++){
        if(S[i-1]=='A' && S[i]=='C') AC[i+1]++;
        AC[i+1] += AC[i];
    }
    int l,r;
    for(int i=0;i<Q;i++){
        cin >> l >> r;
        cout << AC[r]-AC[l] << endl;
    }
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define reps(i, m, n) for (int i = m; i <= n; ++i)

using i64 = long long;
using pii = pair<i64, i64>;

template<class A, class B>inline bool chmax(A &a, const B &b){return b > a ? a = b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b < a ? a = b,1 : 0;}

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  string s;
  cin >> s;

  map<char, int> cnt;
  for (auto e : s) cnt[e]++;

  cout << (cnt['a'] == 1 && cnt['b'] == 1 && cnt['c'] == 1 ? "Yes" : "No") << "\n";
  return 0;
}

Measured memory_bytes: 256
from itertools import combinations as cmbs
from sys import stdin


def main():
    c = {"M":0,"A":0,"R":0,"C":0,"H":0}
    for si in map(lambda s:s[0],stdin):
        if si in c:
            c[si] += 1
    print(sum(i*j*k for i,j,k in cmbs(c.values(),r=3)))


main()


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

#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int h,w,n;
  cin >> h >> w >> n;
  int sy,sx;
  cin >> sy >> sx;
  sy--,sx--;
  string s,t;
  cin >> s >> t;
  stack<pair<int,int>> xp,yp;
  for(int i=0;i<n;i++){
    switch(s[i]){
    case 'L':
      xp.push({0,0});
      break;
    case 'R':
      xp.push({1,0});
      break;
    case 'U':
      yp.push({0,0});
      break;
    case 'D':
      yp.push({1,0});
      break;
    }
    switch(t[i]){
    case 'L':
      xp.push({0,1});
      break;
    case 'R':
      xp.push({1,1});
      break;
    case 'U':
      yp.push({0,1});
      break;
    case 'D':
      yp.push({1,1});
      break;
    }
  }
  int l=0,r=w;
  while(!xp.empty()){
    auto p = xp.top();
    xp.pop();
    if(p.second){
      if(p.first){
        l--;
      }else{
        r++;
      }
    }else{
      if(p.first){
        r--;
      }else{
        l++;
      }
    }
    l = max(0,l);
    r = min(w,r);
    if(l==r){
      cout << "NO" << endl;
      return 0;
    }
  }
  if(sx<l||r<=sx){
    cout << "NO" << endl;
    return 0;
  }
  l=0,r=h;
  while(!yp.empty()){
    auto p = yp.top();
    yp.pop();
    if(p.second){
      if(p.first){
        l--;
      }else{
        r++;
      }
    }else{
      if(p.first){
        r--;
      }else{
        l++;
      }
    }
    l = max(0,l);
    r = min(h,r);
    if(l==r){
      cout << "NO" << endl;
      return 0;
    }
  }
  if(sy<l||r<=sy){
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 3976
#include<cstdio>
#include<cstdlib>
#include<map>

#define SIZE 100
#define FAIL 0

int N;
long long x[SIZE], y[SIZE], h[SIZE];

long long isAnswer(long long CX, long long CY) {
  long long H = FAIL;
  for(int i=0;i<N;i++)
    {
      if( h[i] == 0LL )
	continue;
      long long ecchi = h[i] + llabs(x[i]-CX) + llabs(y[i]-CY);
      if( ecchi == 0LL )
	continue;
      if( H == FAIL )
	H = ecchi;
      else
	if( H != ecchi )
	  return FAIL;
    }
  return H;
}

int main() {
  ;;"Input <- N";;;scanf("%d",&N);;;;;
  for(int i=0;i<N;i++)
    {
      ;;"Input <- X Y H";;;scanf("%lld %lld %lld",&x[i],&y[i],&h[i]);;;;;
    }
  std::map<long long,int> reg;
  std::map<long long, std::pair<long long, long long>> reg2;
  for(long long CX=0;CX<=100;CX++)
    {
      for(long long CY=0;CY<=100;CY++)
	{
	  long long H;
	  if( ( H = isAnswer(CX,CY) ) != FAIL )
	    {
	      //printf("%lld %lld %lld\n",CX,CY,H);
	      //return 0;
	      reg[H] += 1;
	      reg2[H] = std::pair<long long, long long>(CX,CY);
	    }
	}
    }
  for(auto iter : reg) {
    if( iter.second == 1 ) {
      long long H = iter.first;
      long long X = reg2[H].first;
      long long Y = reg2[H].second;
      printf("%lld %lld %lld\n",X,Y,H);
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 3252
module Main (main) where

import qualified Data.ByteString.Char8 as C8
import Data.Bool
import Data.Maybe

main :: IO ()
main = do
  [x,y] <- readInts
  print . showAnswer $ solve (x,y)

type Input  = (Int, Int)
type Output = Int

solve :: Input -> Output
solve (x,y) = x + (y `div` 2)

showAnswer :: Output -> Answer
showAnswer = Number

-- utils
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

data Answer
  = YesNo Bool
  | YESNO Bool
  | AB Bool
  | Number Int
  | String String
  | Compare Ordering
  | Compare2 Ordering

instance Show Answer where
  show (YesNo b)    = bool "No" "Yes" b
  show (YESNO b)    = bool "NO" "YES" b
  show (AB b)       = bool "B"  "A" b
  show (Number i)   = show i
  show (String s)   = s
  show (Compare o)  = ordering "<" "=" ">" o
  show (Compare2 o) = ordering "Right" "Balanced" "Left" o

ordering :: a -> a -> a -> Ordering -> a
ordering lt eq gt o = case o of
  LT -> lt
  EQ -> eq
  GT -> gt

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

int main(){
    int N;
    cin >> N;
    vector<i64> A(N);
    vector<i64> B(N);

    rep(i, N) cin >> A[i] >> B[i];

    sort(A.begin(), A.end());
    sort(B.begin(), B.end());

    auto median = [](const vector<i64> v) -> i64 {
        const int L = v.size();
        if(v.size() % 2) return v[L/2];
        return (v[L/2-1] + v[L/2]);
    };

    if(N%2) cout << max<i64>(median(B)-median(A) + 1, 1) << endl;
    else cout << max<i64>(median(B)-median(A) + 1, 1) << endl;
}


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

// B

int getKeta(int n){
    int res = 1;
    while( n > 9 ){
        n /= 10;
        res++;
    }
    return res;
}

string itoa(int n){
    string res;
    if( n == 0 ) return "0";
    while( n > 0 ){
        res += string(1, n % 10 + '0');
        n /= 10;
    }
    reverse(res.begin(), res.end());
    return res;
}

int main(){
    int a0, L, i;
    map<string, int> mm;

    while( cin >> a0 >> L, a0 | L ){
        mm.clear();
        // a0の桁数
        int k = L - getKeta(a0);
        string s = string(k, '0') + itoa(a0);
        
        string minS, maxS;
        
        mm[s] = 0;
        for(i=1; i<30; i++){
            sort(s.begin(), s.end());
            minS = s;
            sort(s.rbegin(), s.rend());
            maxS = s;

            int tmp = atoi(maxS.c_str()) - atoi(minS.c_str());
            s = string(L - getKeta(tmp), '0') + itoa(tmp);
            //cout << i << " : " << maxS << " - " << minS << " = " << s << endl;
            if( mm.count(s) ) break;
            mm[s] = i;
            
        }

        cout << mm[s] << " " << atoi(s.c_str()) << " " << (i - mm[s]) <<  endl;
    }
    
    return 0;
}

Measured memory_bytes: 0