akhauriyash/Code-Regression huggingface dataset:
v, e, r = map(int, input().split())

vertex = [{'cost': float('inf'), 'dest': []} for _ in range(v)]
vertex[r]['cost'] = 0

for _ in range(e):
    v_id, dest, cost = map(int, input().split())
    vertex[v_id]['dest'].append((dest, cost))

import heapq

q = []
heapq.heapify(q)
heapq.heappush(q, (0, r))

while len(q) != 0:
    distance, v = heapq.heappop(q)

    if vertex[v]['cost'] < distance:
        continue

    for dest in vertex[v]['dest']:
        if vertex[dest[0]]['cost'] > vertex[v]['cost'] + dest[1]:
            c = vertex[v]['cost'] + dest[1]
            vertex[dest[0]]['cost'] = c
            heapq.heappush(q, (c, dest[0]))

for v in vertex:
    print(v['cost'] if v['cost'] != float('inf') else 'INF')



Measured memory_bytes: 113872
// {{{
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// }}}

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

static constexpr int mod = (int)1e9 + 7;
static constexpr int inf = 100100100;
static constexpr ll linf = 1e18;
static constexpr double eps = 1e-9;
static constexpr double pi = 3.14159265359;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rrep(i, n) for (ll i = n; i >= 0; --i)
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define pb push_back
#define ist insert
#define fst first
#define snd second


int main() {
    // cin.tie(0);
    // ios_base::sync_with_stdio(false);
    ll A, B, C;
    cin >> A >> B >> C;
    if (A + B < C) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
public static void main(String args[]){
	
	Scanner sc = new Scanner(System.in);
	int C = sc.nextInt();
	
	int a = C%500;
	int b = (a-(a%5));
	int c = (C-a)*2;
	
	System.out.println(b+c);
}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;
#define MOD 1000000007
#define INF 1000000
#define PI 3.14159265358979323846264338327950L
#define MAX_N 200010
#define lb lower_bound //[2,4)=lb(4)-lb(2);

int main()
{
  string S;cin>>S;
  ll n= S.size();
  vector<vector<ll>> DP(n+1,vector<ll>(15,0));
  //DP[i][j]=先頭i文字でj余る数の個数
  
  if (S[0]=='?')
  {
    for (int j=0;j<10;j++)
      DP[0][j]=1;
  }
  else
  {
    int first = S[0]-'0';
    for (int j=0;j<10;j++)
    {
      if (j==first) DP[0][j]=1;
      else DP[0][j]=0;
    }
  }
  
  for (int i=1;i<n;i++)
  {
    if (S[i]=='?')
    {
      for (int j=0;j<13;j++)
      {
        for (int d=0;d<10;d++)
        {
          DP[i][(j*10+d)%13] += DP[i-1][j];
          DP[i][(j*10+d)%13] %= MOD;
        }
      }
    }
    else
    {
      for (int j=0;j<13;j++)
      {
        int d = S[i]-'0';
        DP[i][(j*10+d)%13] += DP[i-1][j]; 
        DP[i][(j*10+d)%13] %= MOD;
      }
    }
  }
  
  /*
  for (int i=0;i<n;i++)
  {
    for (int j=0;j<13;j++)
      cout<<"DP["<<i<<"]["<<j<<"]="<<DP[i][j]<<endl;
  }*/
  
  cout<<DP[n-1][5]<<endl;
} 

Measured memory_bytes: 15232
#include<bits/stdc++.h>
using namespace std;
long long a[100100],b[100100];

struct node{
	int l,r;
};
bool cmp(node a,node b){
	return a.l<b.l;
}
bool operator<(node a,node b){
	return a.r<b.r;
}
priority_queue<node>q;
node e[100100];
long long cnt,ans;
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		scanf("%lld%lld",&a[i],&b[i]);
		e[++cnt].l=a[i];e[cnt].r=b[i];
	}
	sort(e+1,e+1+cnt,cmp);
	int cur=1;
	for(int i=1;i<=m;i++){
		while(cur<=n&&e[cur].l<=i)q.push(e[cur]),++cur;
		if(!q.empty()){
			node p=q.top();q.pop();ans+=p.r;
		}
	}
	printf("%lld",ans);
	return 0;
} 

Measured memory_bytes: 3704
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
  uint64_t N;
  cin >> N;
  uint16_t k = 1;
  uint32_t res = 0;
  uint32_t dev = 10;
  for (uint32_t i = 1; i <= N; i++) {
    if (i % dev == 0) {
      i = (i * 10) - 1;
      dev *= 100;
    } else {
      res++;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(long i = 0; i < n; i++)
#define erep(i, n) for(long i = 1; i <= n; i++)
#define all(a) a.begin(), a.end()
#define show(ans)  cout << ans << endl;
const long MOD = 1000000007;


int main() {string s; long k;
cin >> s >> k;
long n = 0;
while(s[n] == '1' && n < s.size()) n++;
char ans;
if(k >= n+1){
    ans = s[n];
}
else ans = '1';
show(ans);

  return 0;
 
}



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

int main(){
	int n;
	int A[100020];
	cin >> n;
	for(int i=0; i<n; ++i){
	cin >> A[i];
	}
	int MAX=A[0];
	for(int i = 1; i < n; i++){
    if(A[i] > MAX) MAX = A[i];
    }
	int ANS=A[0];
	int diff=MAX;
	int MID;
	MID = MAX/2;
	for(int i=0; i<n; i++){
	int nowdiff= 0;
	nowdiff = abs(MID - A[i]);
	if(nowdiff<diff){
	diff = nowdiff;
	ANS = A[i];
	}

	}
	if (MAX == ANS){
	ANS =0;
	}
	cout << MAX << " " << ANS << endl;
	return 0;


}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using llong = long long int;

const static int MOD = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = 1LL << 31;
const static int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<llong> A(n);
    rep(i, n) cin >> A[i];

    llong a = A[0];
    for (int i = 1; i < (int)A.size(); ++i) {
        a ^= A[i];
    }

    if (a == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int n,k; cin>>n>>k;
    vector<int> p(n);
    rep(i,n) cin>>p[i];
    sort(btoe(p));
    int ans=0;
    rep(i,k) ans+=p[i];
    cout<<ans<<endl;
}

Measured memory_bytes: 3640
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#include <ctime>
#include <random>
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
typedef long long int ll;
const ll  MOD = 1000000007;
typedef pair<ll,ll> P;
const ll INF = 100100100100100100;

ll N,M;
ll A[100100], B[100100];
bool rootMem[100100];
vector<ll> V[100100];
ll ans[100100];
queue<ll> que;

ll ryunyu[100100];

int main() {
  cin >> N >> M;
  rep(i, N-1+M) {
    cin >> A[i] >> B[i];
    rootMem[B[i]] = true;
    V[A[i]].push_back(B[i]);
    ryunyu[B[i]]++;
  }
  rep(i, N) {
    if(!rootMem[i+1]) {
      cerr << "root: " << i+1 << endl;
      que.push(i+1);
      ans[i+1] = 0;
      break;
    }
  }
  
  while(!que.empty()) {
    ll l = que.size();
    rep(i,l) {
      ll index = que.front();
      que.pop();
      
      ll vecLen = V[index].size();
      rep(j,vecLen) {
        ll next = V[index][j];
        ryunyu[next]--;
        if (ryunyu[next] <= 0) {
          ans[next] = index;
          que.push(next);
        }
      }
    }
  }
  
  rep(i,N) {
    cout << ans[i+1] << endl;
  }
}

Measured memory_bytes: 10624
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

#define rep(i, o) for (int i = 0; i < (o); ++i)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
#define NUM 1e5

typedef long long ll;
typedef unsigned long long ull;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

const ll MOD = 1000000007;

int main() {
    ll n, m;
    cin >> n >> m;
    if (abs(n-m) > 1) { cout << 0 << endl; return 0; }

    ll fact_n = 1, fact_m = 1; 
    for (ll i = n; i > 0; i--) fact_n = (fact_n * i) % MOD;
    for (ll i = m; i > 0; i--) fact_m = (fact_m * i) % MOD;

    ll ans = 0;
    if (n == m) ans = (fact_n%MOD) * (fact_m%MOD) * 2;
    else ans = (fact_n%MOD) * (fact_m%MOD);
    cout << (ans%MOD) << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ABC143D - Triangles
  // key以上の要素のうち最も左側の要素を返す
  // ただし、要素が見つからなかった場合は、vec.end()を返すので、lower_boundを使用する時には注意
  // iter != vec.end()などと処理するか、事前に処理すると良い
  // distance()も使う
  int N; cin >> N;
  vector<int> L(N);
  REP(i, N) cin >> L[i];
  sort(L.begin(), L.end());
  ll ans = 0;
  for(int i = 0; i < N-2; i++){ // N-2まで
    for(int j = i + 1; j < N-1; j++){ // N-1まで
      if(L[i] + L[j] > L[N-1]){
        ans += N - j -1;
      }else{
        auto iter = lower_bound((L.begin()+j+1), L.end(), L[i]+L[j]);
        ans += distance((L.begin()+j+1), iter);
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
/*ITP1_4_A.c*/
#include<stdio.h>
int main(void){
   int a,b,d,r;
   scanf("%d %d",&a,&b);
   d=a/b;
   r=a%b;
   printf("%d %d %f\n",d,r,(double)a/b);
   return 0;
}

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

using lli = long long;
using pii = pair<int, int>;
using pll = pair<lli, lli>;
template <typename T>
using Vector = vector<vector<T>>;
template <typename T>
using Prior = priority_queue<T>;
template <typename T>
using prior = priority_queue<T, vector<T>, greater<T>>;

#define IOS() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define X first
#define Y second
#define Push push_back
#define ALL(x) x.begin(), x.end()
#define RALL(x) x.rbegin(), x.rend()

const lli mod = 1E9 + 7;

lli fpow(lli x, lli pow) {
	lli ans = 1;
	while (pow) {
		if (pow & 1) ans = ans * x % mod;
		x = x * x % mod;
		pow >>= 1;
	}
	return ans;
}

lli invmod(lli x) {
	return fpow(x, mod - 2);
}

void solve() {
	lli x, y;
	cin >> x >> y;
	if (x > y) swap(x, y);

	if (x * 2 < y) {
		cout << 0 << "\n";
		return;
	}

	if ((x + y) % 3) {
		cout << 0 << "\n";
		return;
	}

	lli steps = (x + y) / 3;
	/// x = a + 2(steps - a) ///
	/// x = 2(steps) - a ///

	lli right = 2 * steps - x;
	/// calculate C(steps, right) ///

	// printf("steps: %lld, right: %lld\n", steps, right);

	lli ans = 1;
	for (lli i = 1; i <= right; ++i) {
		ans *= (steps - i + 1); ans %= mod;
		ans *= invmod(i); ans %= mod;
	}

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

int main() {
	int t = 1;
	// cin >> t;
	while (t--) {
		solve();
	}
	return 0;
}

Measured memory_bytes: 256
s = input()

res = 0
for i in range(2**(len(s)-1)):
    pos = 0
    for j in range(len(s)-1):
        if (i >> j) & 1:
            res += int(s[pos:j+1])
            pos = j + 1
    res += int(s[pos:])

print(res)

Measured memory_bytes: 9144
#include<stdio.h>
#define N 100000

int a[N];

int partition(int p,int r){
  int x=a[r],i=p-1,j,n;

  for(j=p;j<r;j++){
    if(a[j]<=x){
      i++;
      n=a[i]; a[i]=a[j]; a[j]=n;
    }
  }
    n=a[i+1]; a[i+1]=a[r]; a[r]=n;

    return i+1;
}

int main(){
  int n,i,di;

  scanf("%d",&n);
  for(i=0;i<n;i++) scanf("%d",&a[i]);
  di=partition(0,n-1);

  for(i=0;i<di;i++) printf("%d ",a[i]);
  printf("[%d] ",a[i++]);
  for(;i<n-1;i++) printf("%d ",a[i]);
  printf("%d\n",a[i]);
  
  return 0;
}



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


#define li			long long int
#define rep(i,to)	for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)	for(li i=(li)(start);i<((li)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)		idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)	for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)		idp p2((x).F, (x).S)
#define dump(x,n)	idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)	idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)	idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)	idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)	rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)	rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li n;
li a[100100];

int main() {
	cin >> n;
	rin{cin >> a[i];}
	li res = 0;
	rep(i, n) {
		res += a[i] / 2;
		if (i < n - 1 && a[i] % 2 > 0 && a[i + 1] > 0) {
			res++;
			a[i + 1]--;
		}
	}
	cout << res << endl;

	return 0;
}

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

int main(){
  int n,cnt=0;
  string s;
  cin >> n >> s;
  for(int i=0;i<n-2;i++){
    if(s.at(i)=='A'&&s.at(i+1)=='B'&&s.at(i+2)=='C') cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define all(x) x.begin() , x.end()

typedef long long ll;
typedef long double ld;

using namespace std;

signed main(){
    int n , m;
    cin >> n >> m;
    int l = 1 , r = n;
    for(int i = 0 ; i < m ; ++i){
        int a , b;
        cin >> a >> b;
        l = max(a , l) , r = min(b , r);
    }
    cout << max(0 , r - l + 1);
    return 0;
}


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

int	main()
{
	int	A, B, K;
	cin >> A >> B >> K;
	int	C = min(A, B);
	int	cnt = 0;
	int	i;
	for (i = C; i > 0; --i) {
		if (A % i == 0 && B % i == 0) ++cnt;
		if (cnt == K) break;
	}
	cout << i << endl;
}	


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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<string>vst;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define all(ct) ct.begin() , ct.end()
#define endl "\n"
#define fr(i,a) for(auto i:a)
#define f(i,a,b) for(int i=a;i<b;++i)
#define fd(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define in(d,v) d.find(v)!=d.end()
#define mp make_pair
#define size(a) int(a.size())

const int mod = 1e9 + 7;
const ll inf = ll(1e15);
const double PI = acos(-1);

ll modexp(ll x,ll n,int md){
    if(n==0)return 1;
    if(n%2==0)return modexp((x*x)%md,n/2,md);
    return (x*modexp((x*x)%md,n/2,md))%md;
}


int main(){
    fastio;
    //clock_t tm = clock();
    ll n,k;
    cin>>k>>n;
    vl a(n);
    f(i,0,n)cin>>a[i];
    sort(all(a));
    ll ans=inf;
    f(i,0,n){
        ans=min(ans,(a[i]-a[(i+1)%n]+k)%k);
    }
    cout<<ans<<endl;
    //cout<<((clock()-tm)*1.0)/CLOCKS_PER_SEC<<endl;
}

Measured memory_bytes: 1792
def red_or_blue(N: int, s: str)->bool:
    red = sum(c == 'R' for c in s)
    return red > N - red


if __name__ == "__main__":
    N = int(input())
    s = input()
    yes = red_or_blue(N, s)
    print('Yes' if yes else 'No')


Measured memory_bytes: 2940
#include <iostream>
using namespace std;
int main(void){
    long long H,W,i,j,k,M;
    cin>>H>>W;
    string S[H];
    for(i=0;i<H;i++){
        cin>>S[i];
    }
    long long a[H][W],b[H][W];
    for(i=0;i<H;i++){
        for(j=0;j<W;j++){
            a[i][j]=0;
        }
    }
    for(i=0;i<H;i++){
        k=0;
        for(j=0;j<W;j++){
            if(S[i][j]=='.'){
                k++;
                a[i][j]=k;
            }else{
                k=0;
            }
        }
    }
    for(i=0;i<H;i++){
        for(j=W-2;j>-1;j--){
            if(a[i][j]*a[i][j+1]){
                a[i][j]=a[i][j+1];
            }
        }
    }
    
    
    for(i=0;i<H;i++){
        for(j=0;j<W;j++){
            b[i][j]=0;
        }
    }
    for(j=0;j<W;j++){
        k=0;
        for(i=0;i<H;i++){
            if(S[i][j]=='.'){
                k++;
                b[i][j]=k;
            }else{
                k=0;
            }
        }
    }
    for(j=0;j<W;j++){
        for(i=H-2;i>-1;i--){
            if(b[i][j]*b[i+1][j]){
                b[i][j]=b[i+1][j];
            }
        }
    }
    M=0;
    for(i=0;i<H;i++){
        for(j=0;j<W;j++){
            a[i][j]+=b[i][j]-1;
            M=max(M,a[i][j]);
        }
    }
    cout<<M<<endl;
}


Measured memory_bytes: 66816
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <algorithm>
#include <queue>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <numeric>
// #include <fstream>
 
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; }
 
const long long mod = 1e9 + 7;
 
int main()
{
    int k; std::cin >> k;
    long long int ans = 0;
    
    for(int c=1; c<=k; c++)
    {
        for(int b=1; b<=c; b++)
        {
            for(int a=1; a<=b; a++)
            {
                int temp = std::__gcd(a, b);
                temp = std::__gcd(temp, c);
                if(a==b && b==c && c==a)
                {
                    ans += temp;
                }
                else if(a!=b && b!=c && c!=a)
                {
                    ans += temp * 6;
                }
                else
                {
                    ans += temp * 3;
                }
            }
        }
    }

    std::cout << ans << std::endl;
    
    return 0;
}

Measured memory_bytes: 3636
import copy
h, w, K = map(int, input().split())
g = [list(input()) for i in range(h)]
ans = 0
for i in range(2**h):

    i = format(i, "0{}b".format(h))
    for j in range(2**w):
        j = format(j, "0{}b".format(w))

        c = copy.deepcopy(g)
        for k in range(h):
            if i[k] == "1":
                for l in range(w):
                    c[k][l] = "."
        for k in range(w):
            if j[k] == "1":
                for l in range(h):
                    c[l][k] = "."

        count = 0
        for a in range(h):
            for b in range(w):
                if c[a][b] == "#":
                    count += 1

        if count == K:
            ans += 1

print(ans)


Measured memory_bytes: 9332
#include<algorithm>
#include<iostream>
#include<cstring>
#include<iomanip>
#include<sstream>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#define rep(i,x,n) for(int i=x;i<=n;i++)
#define per(i,n,x) for(int i=n;i>=x;i--)
#define sz(a) int(a.size())
#define rson mid+1,r,p<<1|1
#define pii pair<int,int>
#define lson l,mid,p<<1
#define ll long long
#define pb push_back
#define mp make_pair
#define se second
#define fi first
using namespace std;
const double eps=1e-8;
const int mod=1e9+7;
const int N=1e7+10;
const int inf=1e9;
int k;
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>k;
	int res=0,flag=0;
	rep(i,1,N-1){
		res=res*10+7;
		res%=k;
		if(res==0){
			cout<<i<<endl;
			flag=1;
			break;
		}
	}
	if(!flag) cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N = 200010;
typedef long long ll;
int n,m;
ll A[N];
ll B[N];
ll K;
int main(){
  cin >> n >> m >> K;
  for(int i=1;i<=n;++i){
    ll a;
    cin >> a;
    A[i] = A[i-1]+a;
  }
  for(int i=1;i<=m;++i){
    ll b;
    cin >> b;
    B[i]=B[i-1]+b;
  }
  int ans = 0;
  for(int x=0;x<=n;++x){
    if(A[x]>K) break;
    int h=m, l=0;
    int y = m/2;
    for(int i=0;i<1000;++i){
      y=(h+l)/2;
      if(A[x]+B[y]>K)
	h=y;
      else
	l=y;
    }
    if(A[x]+B[h]<=K)
      ans = max(ans,x+h);      
    else if(A[x]+B[l]<=K)
      ans = max(ans,x+l);

  }
  cout << ans << endl;
  return 0;
}


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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (auto i=0; i<n; i++)
#define	Rep1(i, n)	for (auto i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int N, M, Q;

vector<vector<int>> a(50, vector<int> (4, 0));

int 	C(vector<int> &A) {
	int S=0;
	Rep0(i, Q)
		if (a.at(i).at(2)==A.at(a.at(i).at(1))-A.at(a.at(i).at(0)))
			S+=a.at(i).at(3);
	return S;
}

int	F(const vector<vector<int>> &a, const int ix, vector<int> &A, const int &M) {
	if (ix>N)
		return C(A);
	int S=0;
	for (int i=A.at(ix-1); i<=M; i++) {
		A.at(ix)=i;
		S=max(S, F(a, ix+1, A, M));
	}
	return S;
}

int	main() {
	cin >>N >>M >>Q;
	Rep0(i, Q)
		Rep0(j, 4)
			cin >>a.at(i).at(j);
	//
	int S=0;
	vector<int> A(N+1, 0);
	A.at(1)=1;
	cout <<F(a, 2, A, M) <<endl;
	return 0;
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <fstream>
#include <cstdio>
using namespace std;
// vector<pair<int,int> > v;
// cin.ignore();//twice getline(cin,s);
// g++ iterator.cpp -std=c++17
// cout<<(A + B == C ? "YES" : "NO")<<endl;
// __gcd(a,b)
// string s=to_string(i);
// sort(arr, arr+n, greater<int>());
// const long double pi = acos(-1.0);
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define vll vector<ll>
#define mll map<ll,ll >
#define mlli map<ll,ll>::iterator
#define size size()
#define endl "\n"
#define ll long long int
#define ld long double
void fast(){ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);}


int main(void)
{
	fast();
	ll a,b,n;
	cin>>a>>b>>n;
	ll ans;
	// v.v imp ques using functions...
	//  best in the editorial
	if(b-1>=n)		
	{
		 ans = floor((a*n)/b)-(a*floor(n/b));
	}
	else if(n>b-1)
	{
		 ans = floor(((a)*(b-1))/b)-(a*floor((b-1)/b));
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3588
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	string A[] = { "abcde","fghij","klmno","pqrst","uvwxy","z.?! " };
	for (string s; cin >> s;) {
		if (s.size() % 2) {
			cout << "NA" << endl;
			continue;
		}
		bool flag = false;
		string ans = "";
		for (int i = 0; i < s.size(); i += 2) {
			if (!('1' <= s[i] && s[i] <= '6' && '1' <= s[i + 1] && s[i + 1] <= '5')) {
				cout << "NA" << endl;
				flag = true;
				break;
			}
			ans += A[s[i] - '1'][s[i + 1] - '1'];
		}
		if (flag) {
			continue;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3104
# -*- coding: utf-8 -*-
"""
B - Training Camp
https://atcoder.jp/contests/abc055/tasks/abc055_b

"""
import sys


def solve(N):
    MOD = 10**9 + 7
    ans = 1
    for i in range(1, N+1):
        ans = (ans * i) % MOD
    return ans


def main(args):
    N = int(input())
    ans = solve(N)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 3064
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        l: usize, r: usize, d: usize
    }
    let ans = r / d - (l-1) / d;
    println!("{}", ans);
}


Measured memory_bytes: 2148
import math
from collections import namedtuple

Station = namedtuple('Station', 'c s f')

N = int(input())
stations = []
for _ in range(N - 1):
  c, s, f = map(int, input().split())
  stations.append(Station(c, s, f))

  
def measure(start):
  if start > len(stations) - 1:
    return 0
  
  time = 0
  for station in stations[start:]:
    depart_at = station.s\
      if station.s >= time\
      else math.ceil(time / station.f) * station.f
    time = depart_at + station.c
  return time

for i in range(N):
  print(measure(i))

Measured memory_bytes: 42076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

int main()
{
    int h, w, n;
    cin >> h >> w >> n;
    vector<int> a;
    int ans[h][w];
    for (int i = 0; i < n; i++)
    {
        int tmp;
        cin >> tmp;
        vector<int> hoge(tmp, i + 1);
        a.insert(a.end(), hoge.begin(), hoge.end());
    }
    int H, W;
    H = W = 0;
    for (int i = 0; i < h * w; i++)
    {
        if (W % 2 == 0)
        {
            ans[H][W] = a[i];
            if (H == h - 1)
                W++;
            else
                H++;
        }
        else
        {
            ans[H][W] = a[i];
            if (H == 0)
                W++;
            else
                H--;
        }
    }
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cout << ans[i][j];
            if (j != w - 1)
                cout << " ";
        }
        cout << "\n";
    }
}


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

int main(int argc, const char * argv[]) {
    double a, b;
    double originala, originalb;
    double gcd = 0, lcm = 0;
    
    while (scanf("%lf %lf", &a, &b) != EOF) {
        originala = a;
        originalb = b;
        while (1) {
            if (a != 0 && b != 0) {
                b = fmod(b, a);
                if (b != 0) {
                    a = fmod(a, b);
                }
            }
            if (a == 0 || b == 0) {
                if (a == 0) {
                    gcd = b;
                    break;
                } else if (b == 0) {
                    gcd = a;
                    break;
                }
            }
        }
        lcm = originala * originalb / gcd;
        printf("%.0lf %.0lf\n", gcd, lcm);
    }    return 0;
}


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

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

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


int main() {
	int n;
	cin >> n;
	int aa = n / 100;
	int bb = n % 100;
	bool not_yymm = false, not_mmyy = false;


	if (aa > 12 || aa==0) {
		not_mmyy = true;
	}
	if (bb > 12 || bb==0) {
		not_yymm = true;
	}

	if (not_mmyy && not_yymm) {
		ANS("NA")
	}
	else if (not_mmyy) {
		ANS("YYMM")
	}
	else if (not_yymm) {
		ANS("MMYY")
	}
	else {
		ANS("AMBIGUOUS")
	}
	
	
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int K, a, b, i;
  scanf("%d\n", &K);
  scanf("%d %d", &a, &b);
  
  for(i=a;i<=b;i++){
    if(i % K == 0){
      printf("OK");
      break;
    }
    if(i==b){
      printf("NG");
  }
  }
  return 0;
}

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

#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define mem(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sz(x) (int)x.size()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.14159265358979323846
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define endl '\n'

int main()
{
    

    int n;
    cin>>n;
    ll a[n+1];
    mem(a,0);
    vector<int> v;
    ffor(i,0,n)
    {
        int x;
        cin>>x;
        v.pb(x);
        a[x]++;
    }
    ll ans=0;
    ffor(i,1,n+1) ans+=(a[i])*(a[i]-1)/2;

    for(auto i:v)
    {
        cout<<ans-a[i]+1<<endl;
    }
    
    return 0;
}



Measured memory_bytes: 5108
#include<bits/stdc++.h>
using namespace std;
 
#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
void ans1(bool x){
  if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){
  if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){
  if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){
  if(x) cout<<y<<endl;else cout<<z<<endl;}   
 
 
int main(){
  ll i,j,k;
  ll result = -1 * INF;
  ll buf = 0;
  ll buf2 = 0;
  ll buf3 = 0;
  bool judge = true;
  ll n; cin >> n;
  ll f[n][10];
  for(i=0;i<n;i++){
    for(j=0;j<10;j++){
      cin>>f[i][j];
    }
  }
  ll p[n][11];
  for(i=0;i<n;i++){
    for(j=0;j<=10;j++){
      cin>>p[i][j];
    }
  }
  bitset<10> a;
  for(i=1;i<(1<<10);i++){
    a=i;
    buf=0;
    for(j=0;j<n;j++){
      buf2=0;
      for(k=0;k<10;k++){
        if(a[k]==1&&f[j][k]==1){
          buf2++;
        }
      }
      buf+=p[j][buf2];
    }
    chmax(result,buf);
  }
  cout<<result<<endl;
    
      
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)

// AtCoder Library(https://img.atcoder.jp/practice2/ac-library.zip)
// Reference: https://en.wikipedia.org/wiki/Fenwick_tree
// -> 一部改変(2020/09/08).
template <class T>
struct BIT{
public:
    BIT() : _n(0){}
    BIT(int n) : _n(n), data(n){}
    void add(int p, T x){
        assert(0 <= p && p < _n);
        p++;
        while(p <= _n){
            data[p - 1] += T(x);
            p += p & -p;
        }
    }
    
    T sum(int l, int r){
        assert(0 <= l && l <= r && r <= _n);
        return sum(r) - sum(l);
    }
    
private:
    int _n;
    vector<T> data;
    T sum(int r){
        T s = 0;
        while(r > 0){
            s += data[r - 1];
            r -= r & -r;
        }
        return s;
    }
};

int main(){
    
    // 1. 入力情報.
    int N, Q;
    scanf("%d %d", &N, &Q);
    
    // 2. 数列の準備.
    BIT<LL> ft(N + 1);
    rep(i, N){
        LL a;
        scanf("%lld", &a);
        ft.add(i, a);
    }
    
    // 3. クエリ回答.
    rep(i, Q){
        int t, x, y;
        scanf("%d %d %d", &t, &x, &y);
        if(t) printf("%lld\n", ft.sum(x, y));
        else  ft.add(x, (LL)y);
    }
    return 0;
    
}

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

struct Dice
{
	Dice(int d[6]){
		for(int i = 0; i < 6; ++i)
			n[i] = d[i];
	}
	void toN(){ shift( n[0], n[1], n[5], n[4] ); }
	void toS(){ shift( n[0], n[4], n[5], n[1] ); }
	void toW(){ shift( n[0], n[2], n[5], n[3] ); }
	void toE(){ shift( n[0], n[3], n[5], n[2] ); }
	void shift( int& a, int& b, int& c, int& d ){
		int t = a;
		a = b;
		b = c;
		c = d;
		d = t;
	}
	int n[6];
};

int main()
{
	int i, d[6] = {};
	for(i = 0; i < 6; ++i)
		cin >> d[i];

	Dice dice(d);
	char c;
	cin.get(c);
	while( cin.get(c) ){
		if( c == '\n' )
			break;
		switch(c)
		{
		case 'N': dice.toN(); break;
		case 'S': dice.toS(); break;
		case 'W': dice.toW(); break;
		case 'E': dice.toE(); break;
		}
	}

	cout << dice.n[0] << "\n";
	
	return 0;
}

Measured memory_bytes: 1164
a,b,k =map(int,input().split()) 
cnt = 0
arr=list(range(1,max(a,b)+1))
arr.reverse()
for x in arr:
  if (a % x == 0) and (b % x == 0):
    cnt +=1
    if cnt == k:
      print (x)
  
      
    
    



Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int h , a;
	cin>>h>>a;
	int arr[a];
	for(int i = 0 ; i < a ; i++)
	{
		cin>>arr[i];
	}
	while(h>0)
	{
		for(int i = 0; i < a; i++)
		{
			h = h-arr[i];
		}
		if(h>0)
		{
			cout<<"No";
			break;
		}
		else
		{
			cout<<"Yes";
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
using namespace std;
string Card;
int p[10]={0},N,f;
int main(){
    while(1){
        int c=0;
        cin>>N;
        if(N==0)break;
        cin>>Card;
        while(c<100){
            for(int j=0;j<N;j++,c++){
                if(c>=100)break;
                if(Card[c] =='M'){
                    p[j]++;
                }
                else if(Card[c]=='S'){
                    f+=1+p[j];
                    p[j] = 0;
                }
                else {
                    p[j]+=f+1;
                    f=0;
                }
            }
        }
        sort(p,p+N);
        for(int i=0;i<N;i++){
            cout<<p[i]<< " ";
            p[i]=0;
        }   
        cout<<f<<endl;
        Card='\0';
        f=0;
    }
    return 0;
}

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

int main()
{
    string a;
    cin>>a;
    if(a[0]=='S')
    {
        cout<<"Cloudy\n";
    }
    else if(a[0]=='R')
    {
        cout<<"Sunny\n";
    }
    else if(a[0]=='C')
    {
        cout<<"Rainy\n";
    }
    return 0;
}


Measured memory_bytes: 256
i=lambda:map(int,input().split())
h,w,n=i()
r=[0,1,2]
d={} 
while n:
	a,b=i();n-=1
	for j in r:
		for k in r:
			if w>=b+k>2<a+j<=h:d[(a+j,b+k)]=d.get((a+j,b+k),0)+1
c=[0]*10
for i in d:c[d[i]]+=1
c[0]=(h-2)*(w-2)-sum(c)
print(*c,sep="\n")

Measured memory_bytes: 166484
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<list>
#include<bitset>
#include<stack>
#include<memory>
#include<numeric>
using namespace std;
using namespace std::chrono;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*cout<<fixed<<setprecision(20);cin.tie(0);ios::sync_with_stdio(false);*/
const int mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-4;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(const vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(const vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	int n,mae=mod,ans=0;
	cin>>n;
	while(n--){
		string s;cin>>s;
		if(s=="E869120"){ans++;}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3208
main(){
  int a[101],i,j,n;
  char s[101][31];
  for(n=0;scanf("%s %d",s[n],&a[n])!=-1;n++);
  for(i=0;i<n;i++)
    for(j=i+1;j<n;j++)
      if(strcmp(s[i],s[j])==0){
	if(a[i]>a[j]){
	  a[100]=a[i];
	  a[i]=a[j];
	  a[j]=a[100];
	}
      }else if(strcmp(s[i],s[j])>0){
	sprintf(s[100],"%s",s[i]);
	sprintf(s[i],"%s",s[j]);
	sprintf(s[j],"%s",s[100]);
	a[100]=a[i];
	a[i]=a[j];
	a[j]=a[100];
      }
  sprintf(s[100],"");
  for(i=0;i<n;i++){
    if(strcmp(s[i],s[100])){
      sprintf(s[100],"%s",s[i]);
      if(i)
	puts("");
      printf("%s\n%d",s[i],a[i]);
    }else
      printf(" %d",a[i]);
  }
  puts("");
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define leadinz zero str.erase(0, min(str.find_first_not_of('0'), str.size()-1));
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
string text="abcdefghijklmnopqrstuvwxyz";
const int maxn=1e6+7;
//        .--------------.
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'
ll bin_pow(ll a,ll b,ll m)
{
    ll res=1;
    a%=m;
    while(b>0){
        if(b&1)res=res*a%m;
        b>>=1;
        a=a*a%m;
    }
    return res;
}
bool miller_rabin(ll d,ll n)
{
    ll a=2+rand()%(n-4);
    ll x=bin_pow(a,d,n);
    if(x==1 || x==n-1)return true;
    while(d!=n-1){
        x=(x*x)%n;
        d*=2;
        if(x==1)return false;
        if(x==n-1)return true;
    }
    return false;
}
bool prime(ll n,ll k)
{
    if(n==1 || n==4)return false;
    if(n<=3)return true;
    ll d=n-1;
    while(d%2==0)d/=2;
    for(int i=0;i<k;i++){
        if(!miller_rabin(d,n))return false;
    }
    return true;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    vector<int>v(26,100005);
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        vector<int>cnt(26,0);
        for(auto x: s)cnt[x-'a']++;
        for(int i=0;i<26;i++)v[i]=min(v[i],cnt[i]);
    }
    for(int i=0;i<26;i++){
        string k(v[i],i+'a');
        cout<<k;
    }
}


Measured memory_bytes: 256
#include<stdio.h>

int main (void)
{
        char b;

        scanf("%s",&b);
        if      (b=='A') printf("T\n");
        else if (b=='T') printf("A\n");
        else if (b=='C') printf("G\n");
        else if (b=='G') printf("C\n");
        return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n, m;
	cin >> n >> m;
	char a[50][50], b[50][50];
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < m; j++) {
			cin >> b[i][j];
		}
	}
	int f = 0;
	for (int i = 0; i <= n - m; i++) {
		for (int j = 0; j <= n - m; j++) {
			for (int k = 0; k < m; k++) {
				for (int l = 0; l < m; l++) {
					if (b[k][l] != a[i + k][j + l]) {
						f = 1;
					}
				}
			}
			if (f == 0) {
				cout << "Yes" << endl;
				return 0;
			}
			f = 0;
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 256
A, B, C, X, Y = map(int, input().split())
ans = 10**18
Z = max(X, Y)
for i in range(Z+1):
  price = 2*C*i + A*max(0, X-i) + B*max(0, Y-i)
  ans = min(ans, price)

print(ans)

Measured memory_bytes: 3060
"use strict";

function main(input){
  const args= input.trim().split(' ');
  const N= parseInt(args[0],10),
  A= parseInt(args[1],10),
  B= parseInt(args[2],10);

  const nums= Array.from(new Array(N),(v,i)=>++i).filter((i)=>{
    var n= i.toString().split('').reduce((x,a)=>x+parseInt(a),0);
    return (A<=n && n<=B);
  })
  console.log(nums.reduce((x,a)=>x+a,0));
  
}
main(require('fs').readFileSync('/dev/stdin','utf8'));


Measured memory_bytes: 23792
#define i(a,b) a=a<b?a:b
#define f(a) for(a=0;a++<n;)
d,a[101][101],b[101][101],u,v,c;main(n){scanf("%d%*d",&n);f(u)f(v)b[u][v]=1e8;for(;~scanf("%d%d%d",&u,&v,&c);a[u][v]=b[u][v]=b[v][u]=c);f(c)f(u)f(v)i(b[u][v],b[u][c]+b[c][v]);f(u)f(v)d+=a[u][v]>b[u][v];printf("%d\n",d);}

Measured memory_bytes: 256
import java.util.*;
public class Main {
   public static void main(String[] args) {  
      Scanner sc = new Scanner(System.in);
      long n = sc.nextLong();
      long m = sc.nextLong();
      
      long ans = (1900*m + 100*(n-m))*(long)Math.pow(2,m);
      System.out.println(ans);
   }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define LONGMAX 1e18
#define MOD 1000000007
#define mp make_pair
#define endl "\n"
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define fr(a,n) for(int i=a;i<n;i++)

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

	int n;
	cin>>n;

	vector<double> dp(n+1);
	//dp[i] denotes probability of getting i heads so far
	dp[0]=1;
	for( int i=0;i<n;i++)
	{
		double prob;
		cin>>prob;
		for(int j=i+1;j>=0;j--)
		{
			dp[j]=(j==0?0:dp[j-1]*prob) + dp[j]*(1-prob);
		}
	}

	double ans=0;
	for( int i=0;i<n+1;i++)
	{
		int tails=n-i;
		if(i>tails)
			ans+=dp[i];
	}
	cout<<fixed<<setprecision(10)<<ans<<endl;
}


Measured memory_bytes: 384
#include <algorithm>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cassert>
#include <functional>

using namespace std;

#define LOG(...) printf(__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define CLR(a) memset((a), 0 ,sizeof(a))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

const int MAX_BOOK = 1000;

int main() {
	int n;

	while(cin >> n, n){
		vector<pii> items;
		int readsum = 0, writesum = 0, readmax = 0;
		REP(i, n){
			int read, write;
			cin >> read >> write;
			readsum += read;
			writesum += write;
			readmax = max(readmax, read);

			items.push_back({read, write});
		}

		if(readsum > readmax * 2){
			cout << writesum + readsum << endl;
			continue;
		}

		SORT(items);

		int dpmax = 2 * readmax - readsum + 1;
		vi dp(dpmax, 0);
		dp[0] = 1;
		int X = 0;
		REP(i, n - 1){
			vi dp_stk(dpmax, 0);
			REP(j, dpmax){
				if(dp[j]){
					dp_stk[j] = 1;
					int idx = j + items[i].second;
					if(idx < dpmax){
						dp_stk[idx] = 1;
						X = max(X, idx);
					}
				}
			}

			dp = dp_stk;
		}

		int mods = writesum - X;
		cout << readmax * 2 + mods << endl;
	}
}

Measured memory_bytes: 1232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> VI;
 
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 (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()

const int MAX_K=100005;
const int INF=1e9+7;

struct edge{
    int to;
    int cost;
    edge(int to,int cost):to(to),cost(cost){}
};

vector<edge> G[MAX_K];

int k;

vector<int> dijkstra(int s){
    vector<int> d(k,INF);
    d[s]=0;
    priority_queue<P,vector<P>,greater<P>> pq;

    pq.push(P(0,s));

    while(pq.size()){
        P t=pq.top();pq.pop();
        int v=t.second;
        for(auto e:G[v]){
            if(d[v]+e.cost<d[e.to]){
                d[e.to]=d[v]+e.cost;
                pq.push(P(d[e.to],e.to));
            }
        }
    }
    return d;
}

int main(){
    cin>>k;
    rep(i,k){
        G[i].push_back(edge((i+1)%k,1));
        G[i].push_back(edge((i*10)%k,0));
    }
    auto ans=dijkstra(1);
    cout<<ans[0]+1<<endl;
}

Measured memory_bytes: 6780
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		long n = Long.parseLong(br.readLine());

		long a[] = new long[5];

		long min = Long.MAX_VALUE;
		for (int i = 0; i < 5; i++) {
			a[i] = Long.parseLong(br.readLine());
			min = Math.min(min, a[i]);
		}

		long ans = 4 + (n + min - 1) / min;

		System.out.println(ans);

	}
}

Measured memory_bytes: 32664