akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstring>
#include <string>
#include <sstream>
#include <bitset>
using namespace std;
#define INF	100000000
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define lb lower_bound
#define ub upper_bound
#define SS stringstream
#define rep(i,n) for(int i = 0; i < n; i++)
#define SORT(x) sort((x).begin(), (x).end())
#define clr(a,b) memset((a),(b),sizeof(a))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<P> Vp;
typedef priority_queue<P, vector<P>, greater<P> > PQ;

int main(){
	int n;
	int a[100][100];
	scanf("%d", &n);
	rep(i,n) rep(j,n) scanf("%d", &a[i][j]);
	ll ans = 0;
	for(int i = 0; i < n; i++){
		for(int j = i+1; j < n; j++){
			ans += min(a[i][j],a[j][i]);
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 1228
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N; cin>>N;
  string S; cin>>S;
  int ans=0;
  rep(i,1,N){
    int sum=0;
    rep(j,0,N){
      int X=j-i;
      if(0<=X){
        if(S[X]==S[j]) sum=min(sum+1,i);
        else sum=0;
      }
      ans=max(ans,sum);
    }
  }
  cout<<ans<<endl;
  }



Measured memory_bytes: 256
import sys,collections
sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
K = I()
sum = 1
for i in range(1,N+1):
    sum += min(sum,K)
print(sum)


Measured memory_bytes: 3436
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <iomanip>
#include <ctype.h>

using namespace std;
using ll = long long;

#define rep(i,N) for(int i=0;i<(int)N;++i)

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

int main()
{
    string s, t, u;
    cin >> s >> t >> u;

    string S;
    S.push_back(toupper(s[0]));
    S.push_back(toupper(t[0]));
    S.push_back(toupper(u[0]));

    cout << S << endl;
}

Measured memory_bytes: 256
n=int(input())
l=[]
for i in range(1,n+1):
  t=list(str(i))
  l.append((t[0],t[-1]))
ans=0
for i in range(1,10):
  for j in range(1,10):
    ans+=l.count((str(i),str(j)))*l.count((str(j),str(i)))
print(ans)

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

int main(){
    int x,y;
    cin >> x >> y;
    cout << x+y/2 << endl;
     

    return 0;
}

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

#define FOR(i,a,b) for(int i = a; i < b; i++)
#define REP(i,n) FOR(i,0,n)
 
int main() {
 
  int N;
  cin >> N;
  string music[50];
  int len[50];
  string X;

  REP(i,N){
    cin >> music[i] >> len[i];
  }

  cin >> X;

  int mark = 1;
  REP(i,N){
    if(music[i] == X){
      mark += i;
      break;
    }
  }

  int SUM = 0;
  FOR(i,mark,N){
    SUM += len[i];
  }

  cout << SUM << endl;



  

 return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> treasure;

int main() {
    int n;
    ll d;
    cin >> n >> d;
    vector<treasure> treasures(n);
    for (int i = 0; i < n; i++) cin >> treasures[i].first >> treasures[i].second;

    vector<treasure> a(pow(3, n / 2));
    for (int i = 0; i < pow(3, n / 2); i++) {
        int tmp = i;
        ll price = 0, value = 0;
        for (int j = 0; j < n / 2; j++) {
            switch (tmp % 3) {
                case 0: {
                    price += treasures[j].first;
                    value += treasures[j].second;
                    break;
                }
                case 1: {
                    price -= treasures[j].first;
                    value -= treasures[j].second;
                    break;
                }
                default:
                    break;
            }
            tmp /= 3;
        }
        a[i].first = price, a[i].second = value;
    }
    sort(a.begin(), a.end(), greater<>());

    vector<treasure> b(pow(3, n - n / 2));
    for (int i = 0; i < pow(3, n - n / 2); i++) {
        int tmp = i;
        ll price = 0, value = 0;
        for (int j = 0; j < n - n / 2; j++) {
            switch (tmp % 3) {
                case 0: {
                    price += treasures[n / 2 + j].first;
                    value += treasures[n / 2 + j].second;
                    break;
                }
                case 1: {
                    price -= treasures[n / 2 + j].first;
                    value -= treasures[n / 2 + j].second;
                    break;
                }
                default:
                    break;
            }
            tmp /= 3;
        }
        b[i].first = price, b[i].second = value;
    }
    sort(b.begin(), b.end());

    int bindex = 0;
    ll ret = 0;
    deque<int> que;
    for (auto x:a) {
        ll upperLimit = d - x.first;
        while (bindex < b.size() && b[bindex].first <= upperLimit) {
            while (!que.empty() && b[que.back()].second <= b[bindex].second)que.pop_back();
            que.push_back(bindex);
            bindex++;
        }

        ll lowerLimit = -d - x.first;
        while (!que.empty() && b[que.front()].first < lowerLimit)que.pop_front();

        if (!que.empty())ret = max(ret, x.second + b[que.front()].second);
    }

    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 451524
#include <bits/stdc++.h>
using namespace std;
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;
 
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;
 
const int MAX = 1000000;
const int MOD = 1000000007;
 
int main(){
  ll n, x, m, ans=0;
  cin >> n >> x >> m;
  map<ll, int>mp;
  vector<ll>bflp,lp;
  bool flag = true;
  ll loop = 0, sum = 0;
  ll p = x;
  while(flag){
    mp[p]++;
    if(mp[p]==3){
      mp[p]--;
      flag = false;
      break;
    }
    p = p*p;
    p%= m;
  }
  ll cnt1=0;
  for(auto i :mp){
    if(i.second==1){
      cnt1++;
      //bflp.push_back(i.first);
    }else{
      loop++;
      //lp.push_back(i.first);
    }
  }
  p = x;
  lrep(i, 0, cnt1){
    bflp.push_back(p);
    p = p*p%m;
  }
  lrep(i, 0, loop){
    lp.push_back(p);
    p = p*p%m;
  }
  ll q1 = lp.size();
  ll q2 = bflp.size();
  if(q2>n){
    lrep(i, 0, n){
      ans += bflp[i];
    }
    cout << ans << endl;
    return 0;
  }else{
    lrep(i, 0, q2){
      ans += bflp[i];
    }
  }

  lrep(i, 0, q1){
    sum += lp[i];
  }

  ll r= (n-q2)/loop;
  ans += r*sum;
  ll r2= (n-q2)%loop;
  ll test =0;
  lrep(i, 0, r2){
    ans += lp[i];
    test +=  lp[i];
  }
  cout << ans << endl;
  //cout << mp.size() << endl;
  //cout << q1 << " " << q2<< endl;
  //cout << r << " " << r2 << " " << loop << " " << sum << endl;
  //cout << test << endl;
  //rep(i, 0, q1)cout << lp[i]<<" ";
  //cout << endl;
}

Measured memory_bytes: 7040
#include<bits/stdc++.h>
using namespace std;
int arr[100000+7];
int mark[100000+7];
int main(){
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>arr[i];
	for(int i=1;i<=m;i++){
		int x,y;
		cin>>x>>y;
		if(arr[x]>arr[y]) mark[y]=1;
		else if(arr[x]<arr[y]) mark[x]=1;
		else{
			mark[x]=1;
			mark[y]=1;
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(!mark[i]) ans++;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 4456
#include <stdio.h>

char isprime[1000001];

void eratosthenes(void){
    int x, y;
    for(x = 0; x <= 1000000; x++){
        isprime[x] = 1;
    }
    isprime[0] = isprime[1] = 0;
    for(x = 2; x * x <= 1000000; x++){
        if(isprime[x]){
            for(y = x * x; y <= 1000000; y += x){
                isprime[y] = 0;
            }
        }
    }
}

int N, L, p[30], dp[1000001];

int main(void){
    int x, y;
    eratosthenes();
    while(1){
        scanf("%d%d", &N, &L);
        if(N == 0 && L == 0) break;
        for(x = 0; x <= L; x++){
            dp[x] = 0;
        }
        for(x = 0; x < N; x++){
            scanf("%d", &p[x]);
        }
        dp[0] = 1;
        for(x = 0; x < N; x++){
            for(y = p[x]; y <= L; y++){
                dp[y] = dp[y] || dp[y-p[x]];
            }
        }
        for(x = L; x > 0; x--){
            if(isprime[x] && dp[x]){
                printf("%d\n", x);
                break;
            }
        }
        if(x == 0){
            puts("NA");
        }
    }
    return 0;
}

Measured memory_bytes: 5492
#include <stdio.h>
typedef int value_type; /* ソートするキーの型 */

/* x, y, z の中間値を返す */
value_type med3(value_type x, value_type y, value_type z) {
    if (x < y) {
        if (y < z) return y; else if (z < x) return x; else return z;
    } else {
        if (z < y) return y; else if (x < z) return x; else return z;
    }
}

/* クイックソート
 * a     : ソートする配列
 * left  : ソートするデータの開始位置
 * right : ソートするデータの終了位置
 */
void quicksort(value_type a[], int left, int right) {
    if (left < right) {
        int i = left, j = right;
        value_type tmp, pivot = med3(a[i], a[i + (j - i) / 2], a[j]); /* (i+j)/2 ではオーバーフローしてしまう */
        while (1) { /* a[] を pivot 以上と以下の集まりに分割する */
            while (a[i] < pivot) i++; /* a[i] >= pivot となる位置を検索 */
            while (pivot < a[j]) j--; /* a[j] <= pivot となる位置を検索 */
            if (i >= j) break;
            tmp = a[i]; a[i] = a[j]; a[j] = tmp; /* a[i], a[j] を交換 */
            i++; j--;
        }
        quicksort(a, left, i - 1);  /* 分割した左を再帰的にソート */
        quicksort(a, j + 1, right); /* 分割した右を再帰的にソート */
    }
}

int main(void){
  int i,n;
  int x[200000];
  int y[200000];
  
  scanf("%d",&n);
  for( i=0; i<n; i++){
    scanf("%d",&x[i]);
    y[i] = x[i];
  }
  
  quicksort( x, 0, n-1);
  
  for( i=0; i<n; i++){
    if( y[i] < x[ n/2 ] ) printf("%d\n",x[ n/2 ]);
    else                  printf("%d\n",x[ n/2 - 1 ]);
  }
  return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;

const int INF = 191919;

const int N = 1001;
vector<int> ch[N];
int dp[N][2];

const int X = 5005;
int cost[X], nx[X];

int main(){
    int n;
    cin >>n;
    vector<int> p(n);
    for(int i=1; i<n; ++i){
        cin >>p[i];
        --p[i];
        ch[p[i]].pb(i);
    }
    vector<int> x(n);
    rep(i,n) cin >>x[i];

    fill(dp[0],dp[N],INF);
    for(int i=n-1; i>=0; --i){
        if(ch[i].size()==0){
            rep(j,2) dp[i][j] = 0;
            continue;
        }

        // 頂点iをjで塗る
        rep(j,2){
            vector<int> fr;
            int same=0, other=0;
            // 子の塗り方
            for(int idx:ch[i]){
                if(dp[idx][j]==INF){
                    // idxを違う色で塗らないといけない
                    same += dp[idx][!j];
                    other += x[idx];
                }
                else if(dp[idx][!j]==INF){
                    // idxを同じ色で塗らないといけない
                    other += dp[idx][j];
                    same += x[idx];
                }
                else{
                    // どっちで塗っても良い
                    fr.pb(idx);
                }
            }
            if(same>x[i] || other>=INF) continue;

            // どっちで塗っても良い頂点たちの塗り方を考える
            fill(cost,cost+X,INF);
            cost[same]=other;
            for(int v:fr){
                fill(nx,nx+X,INF);
                for(int k=X-1; k>=0; --k)if(cost[k]<INF){
                    // vをiと同じ色で塗る
                    if(k+x[v]<X) nx[k+x[v]] = min(nx[k+x[v]], cost[k]+dp[v][j]);
                    // vをiと異なる色で塗る
                    if(k+dp[v][!j]<X) nx[k+dp[v][!j]] = min(nx[k+dp[v][!j]], cost[k]+x[v]);
                }
                rep(k,X) cost[k] = nx[k];
            }
            rep(k,x[i]+1) dp[i][j] = min(dp[i][j],cost[k]);

            // rep(k,x[i]+1)if(cost[k]<INF) printf("  cost[%d] = %d\n",k,cost[k]);
            // printf(" dp[%d][%d] = %d\n",i,j,dp[i][j]);
        }
    }

    string ans = "IMPOSSIBLE";
    rep(i,2)if(dp[0][i]<INF) ans = "POSSIBLE";
    cout << ans << endl;
    return 0;
}


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

const int inf = 2147483647;

struct dor {
    dor *l, *r;
    int dt, sh;
    dor() {
        l = r = NULL;
        dt = sh = inf;
    }
    
    void shp(int vl) {
        sh = min(sh, vl);
    }
    
    void sheps() {
        if(l == NULL) l = new dor();
        if(r == NULL) r = new dor();
        l->sh = min(l->sh, sh);
        r->sh = min(r->sh, sh);
        dt = min(dt, sh);
        sh = inf;
    }
    
    void pump() {
        dt = min(min(l->dt, l->sh), min(r->dt, r->sh));
    }
};

void upd(int l, int r, int sl, int sr, int val, dor *&t) {
    if(t == NULL) t = new dor();
    if(l > sr || r < sl) return;
    if(l >= sl && r <= sr) {
        t->shp(val);
        return;
    }
    upd(l, (l + r) / 2, sl, sr, val, t->l);
    upd((l + r) / 2 + 1, r, sl, sr, val, t->r);
    t->pump();
}

int rw(int l, int r, int si, dor *&t) {
    t->sheps();
    if(l == r) return min(t->dt, t->sh);
    if((l + r) / 2 >= si) return rw(l, (l + r) / 2, si, t->l);
    return rw((l + r) / 2 + 1, r, si, t->r);
}

int n, q, s, t, x, d, tp;
dor *root;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin >> n >> q;
    for(int i = 1; i <= n; ++i) {
        cin >> s >> t >> x;
        upd(0, 1e9, s - x, t - x - 1, x, root);
    }
    for(int i = 1; i <= q; ++i) {
        cin >> d;
        tp = rw(0, 1e9, d, root);
        if(tp == inf) tp = -1;
        cout << tp << endl;
    }
}

Measured memory_bytes: 401024
matrix = [list(map(int, input().split())) for _ in range(3)]
for j in range(2) :
  for i in range(3) :
    if(matrix[i][0] > 0 and matrix[i][1] > 0 and matrix[i][2] > 0) :
      matrix[i] = list(map(lambda x: x - min(matrix[i][0], matrix[i][1], matrix[i][2]), matrix[i]))
  matrix = [list(x) for x in zip(*matrix)]
if(matrix == [[0]*3]*3) : print("Yes")
else : print("No")

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

using namespace std;
const int N = 1e5 + 2;
int n, m;
vector<int>g[N];
bool on_path[N];

bool check(int endpoint) {
	for (int i = (int)g[endpoint].size() - 1; i >= 0; --i) {
		int vec = g[endpoint][i];
		if (!on_path[vec]) {
			swap(g[endpoint].back(), vec);
			return false;
		}
	}
	return true;
}

int main() {
	//freopen("hw.in", "r", stdin);
	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	deque<int>dq;
	dq.push_front(0);
	on_path[0] = true;
	while (!dq.empty()) {
		int a = dq.front(), b = dq.back(), add;
		bool good = true;
		if (!check(a)) {
			add = g[a].back();
			g[a].pop_back();
			dq.push_front(add);
			on_path[add] = true;
			good = false;
		}
		if (!check(b)) {
			add = g[b].back();
			g[b].pop_back();
			dq.push_back(add);
			on_path[add] = true;
			good = false;
		}
		if(good) break;
	}
	cout << dq.size() << '\n';
	for(; !dq.empty(); dq.pop_front()) {
			cout << dq.front() + 1 << ' ';
	}
	return 0;
}


Measured memory_bytes: 6784
fun ac107(args: Array<String>) {
    val (N, K) = args[0].split(" ").map { it.toInt() }
    println((N - 1) / (K - 1) + if ((N - 1) % (K - 1) == 0) 0 else 1)
}

fun main(args: Array<String>) {
    ac107(readLineList())
}

fun readLineList(): Array<String> {
    val lineList = mutableListOf<String>()
    while (true) {
        val line = readLine()
        if (line.isNullOrBlank()) {
            break
        } else {
            lineList.add(line!!)
        }
    }
    return lineList.toTypedArray()
}

Measured memory_bytes: 42040
N = int(input())
A = list(map(int, input().split()))
 
L = [0]*(N+2)
R = [0]*(N+2)
 
import fractions
 
for i in range(1,N+1):
    L[i] = fractions.gcd(L[i-1],A[i-1])
for i in range(0,N)[::-1]:
    R[i] = fractions.gcd(R[i+1],A[i])
 
M = [fractions.gcd(L[i-1],R[i]) for i in range(1,N+1)]
print(max(M))

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

using namespace std;

int main() {
    int h,w;
    cin >> h >> w;
    string map[51];
    for(int i = 0; i < h; i++) {
        cin >> map[i];
    }
    bool ok = true;
    int vx[] = {1,0,-1,0};
    int vy[] = {0,1,0,-1};
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if(map[i][j] == '#') {
                bool f = false;
                for(int k = 0; k < 4; k++) {
                    int tx = j + vx[k];
                    int ty = i + vy[k];
                    if(tx >= 0 && ty >= 0 && tx < w && ty < h && map[ty][tx] == '#') {
                        f = true;
                        break;
                    }
                }
                if(!f) ok = false;
            }
        }
    }

    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m;
	cin >> n >> m;
	int a[n][m], b[m];
	for (int i=0;i<n;i++){
		for (int j=0;j<m;j++){
			cin >> a[i][j];
		}
	}
	for (int i=0;i<m;i++) cin >> b[i];
	for (int i=0;i<n;i++){
		int ans = 0;
		for (int j=0;j<m;j++){
			ans += b[j] * a[i][j];
		}
		cout << ans << endl;
	}
}


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


 const int MAX = 1001;
const int MOD = 1000000007;



signed main(){
 
   int n;
   cin>>n;
   int x,y,ymax=0,xmin=MOD,xmax=0,ymin=MOD;
  pair<int,int> p[n];
   for(int i=0;i<n;i++){
       cin>>x>>y;
        if(x>y)swap(x,y);
        if(xmin>x)xmin=x;
        if(xmax<x)xmax=x;
        if(ymax<y)ymax=y;
        if(ymin>y)ymin=y;
        p[i]=make_pair(x,y);

   }
   sort(p,p+n);
   int ans=p[n-1].first-p[0].first;
   int c1=MOD,c2=p[n-1].first;
   for(int i=1;i<n;i++){
       c1=min(p[i-1].second,c1);
       c2=max(c2,p[i-1].second);
       ans=min(ans,-min(p[i].first,c1)+c2);
   }
   cout<<min((xmax-xmin)*(ymax-ymin),(ymax-xmin)*ans);
    return 0;
}

Measured memory_bytes: 3328
N = int(input())

A = list(map(int, input().split()))

B = [A[i] - (i + 1) for i in range(N)]

B.sort()


if N % 2 == 1:
  t = B[N // 2]
else:
  t = (B[N // 2] + B[N // 2 - 1]) // 2

su = sum([abs(i - t) for i in B])
print(su)


Measured memory_bytes: 26836
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<Edge>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
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;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

////////// 二項係数(N<=10^7) //////////

ll fac[MAX],finv[MAX],inv[MAX];
// fac[i] i!
// finv[i] i!の逆元
// inv[i] iの逆元

// テーブルを作る前処理
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(ll 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;
  }
}

// 二項係数計算
ll COM(ll n,ll k){
  if(n<k) return 0;
  if(n<0 || k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

//////////////////////////////////////////////////

int main(){
  COMinit();
  ll N,ans=0,L=1;
  cin>>N;
  map<ll,ll> M;
  ll A[N],B[N];
  REP(i,N){
    cin>>A[i];
    B[i]=A[i];
    for(int j=2; j<=sqrt(A[i]); j++){
      ll cnt=0;
      while(A[i]%j==0){
        cnt++;
        A[i]/=j;
      }
      chmax(M[j],cnt);
    }
    if(A[i]!=1) chmax(M[A[i]],1ll);
  }
  
  FORE(v,M){
    REP(i,v.second){
      L*=v.first;
      L%=MOD;
    }
  }
  
  REP(i,N){
    ans+=L*inv[B[i]];
    ans%=MOD;
    if(ans<0) ans+=MOD;
  }
  co(ans);
  return 0;
}

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

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define pb push_back
#define mp make_pair
#define INF 999999999
#define MOD 1000000007
#define sp ' '


//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef pair<long, long> pll;
typedef map<int, int> mint;
typedef set<int> sint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b, ll c){ll ans=1; rep(i, b){ans=ans*a%c;} return ans;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i] << endl;}}

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ddx[8] = {1,0,-1,0,1,-1,-1,1};
const int ddy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    ll sum = LLONG_MAX;

    for(ll i = 0; i <= 100000; ++i){
        sum = min(sum, 2*c*i + a*max(0LL, x-i) + b*max(0LL, y-i));
    }

    ppp(sum);



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
const long long mod = 1e9 + 7;
 
int main() {
  string s;
  cin >> s;
 
  vector<vector<long long>> dp(100005, vector<long long>(13, 0));
  dp[0][0] = 1;
  for ( int i = 0; i < s.size(); i++ ) {
    int c = ( s[i] != '?' ) ? s[i]-'0' : -1;
 
    for ( int j = 0; j < 10; j++ ) {
      if ( c != -1 && c != j ) { continue; }
      for ( int k = 0; k < 13; k++ ) {
        dp[i+1][(k*10+j)%13] += dp[i][k];
      }
    }
    for ( int j = 0; j < 13; j++ ) { dp[i+1][j] %= mod; }
  }
 
  cout << dp[s.size()][5] << endl;
  return 0;
}

Measured memory_bytes: 16720
#include<cstdio>
#include<algorithm>
using namespace std;

int main()
{
	char inp;
	int n,now=0,ans=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf(" %c",&inp);
		if(inp=='I') now++;
		else now--;
		ans=max(ans,now);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
using namespace std;
int main(void) {
    long n;
    long j;
    cin >> n;
    int k = 0, ans = 0;
    for(int i=floor(sqrt(n));i>=1;i--) {
        if(n%i == 0) {
            j = n/i;
            k = 0;
            while(j != 0) {
            k++;
            j = j / 10;
            }
            ans = k;
            break;
        }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll K,Q;
    cin >> K >> Q;
    vec<ll> D(K);
    for(int i=0;i<K;i++) cin >> D[i];

    auto solve = [&](ll N,ll X,ll M){
        vec<ll> A(K);
        for(int i=0;i<K;i++) A[i] = D[i]%M;
        ll res = 0;
        for(int i=0;i<K;i++) if(A[i]==0){
            if(N-i-2>=0) res += (N-i-2)/K+1;
        }
        res -= X/M;
        ll val = X;
        for(int i=0;i<K;i++){
            if(N-i-2>=0) val += ((N-i-2)/K+1)*A[i];
        }
        res += val/M;
        cout << N-1-res << "\n";
    };
    
    while(Q--){
        ll n,x,m;
        cin >> n >> x >> m;
        solve(n,x,m);
    }
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
#include<complex>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

int main() {
    int n; cin >> n;
    int a[n]; rep(i, n) cin >> a[i];
    //n - 1個以上の数に共通の約数で最大のもん
    //a[0], a[1]の約数にある
    set<int> div;
    rrep(i, 1, sqrt(a[0]) + 1) {
        if (a[0] % i == 0) div.insert(i);
        if (a[0] % (a[0] / i) == 0) div.insert(a[0] / i);
    }
    rrep(i, 1, sqrt(a[1]) + 1) {
        if (a[1] % i == 0) div.insert(i);
        if (a[1] % (a[1] / i) == 0) div.insert(a[1] / i);
    }
    int ans = 0;
    for (auto e : div){
        int c = 0;
        rep(i, n) if (a[i] % e == 0) c++;
        if (c >= n - 1) chmax(ans, e);
    }
    cout << ans << endl;
}


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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

ll x, y;

int main() {
	cin >> x >> y;
	ll cur = x;
	int ret = 1;

	while (cur * 2 <= y) {
		ret++;
		cur *= 2;
	}
	cout << ret << endl;

	return 0;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D - Wizard in Maze
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_H = 1000;
const int MAX_W = 1000;
const int MAX_N = MAX_H * MAX_W;
const int MAX_M = MAX_N * 25;
const int INF = 1 << 30;
const int dxs[] = { 1, 0, -1, 0 }, dys[] = { 0, -1, 0, 1 };

/* typedef */

typedef vector<int> vi;
typedef queue<int> qi;
typedef pair<int,int> pii;
typedef queue<pii> qpii;

/* global variables */

char fs[MAX_H][MAX_W + 4];
int gids[MAX_H][MAX_W];
bool bds[MAX_H][MAX_W];
pii es[MAX_M];
vi nbrs[MAX_N];
int ds[MAX_N];

/* subroutines */

/* main */

int main() {
  int h, w, sy, sx, gy, gx;
  scanf("%d%d%d%d%d%d", &h, &w, &sy, &sx, &gy, &gx);
  sy--, sx--, gy--, gx--;

  for (int y = 0; y < h; y++) scanf("%s", fs[y]);

  memset(gids, -1, sizeof(gids));
  int n = 0;
  for (int y = 0; y < h; y++)
    for (int x = 0; x < w; x++)
      if (fs[y][x] == '.' && gids[y][x] < 0) {
	int id = gids[y][x] = n++;
	qpii q;
	q.push(pii(x, y));

	while (! q.empty()) {
	  pii u = q.front(); q.pop();
	  int ux = u.first, uy = u.second;

	  for (int di = 0; di < 4; di++) {
	    int vx = ux + dxs[di], vy = uy + dys[di];
	    if (vx >= 0 && vx < w && vy >= 0 && vy < h) {
	      if (fs[vy][vx] == '#') bds[uy][ux] = true;
	      else if (gids[vy][vx] < 0) {
		gids[vy][vx] = id;
		q.push(pii(vx, vy));
	      }
	    }
	  }
	}
      }

  int m = 0;
  for (int y = 0; y < h; y++)
    for (int x = 0; x < w; x++)
      if (bds[y][x]) {
	int uid = gids[y][x];
	int minx = max(0, x - 2), maxx = min(w - 1, x + 2);
	int miny = max(0, y - 2), maxy = min(h - 1, y + 2);
	for (int vy = miny; vy <= maxy; vy++)
	  for (int vx = minx; vx <= maxx; vx++) {
	    int vid = gids[vy][vx];
	    if (vid >= 0 && vid != uid) {
	      int eu = uid, ev = vid;
	      if (eu > ev) swap(eu, ev);
	      es[m++] = pii(eu, ev);
	    }
	  }
      }

  sort(es, es + m);
  m = unique(es, es + m) - es;
  //printf("m=%d\n", m);

  for (int i = 0; i < m; i++) {
    int u = es[i].first, v = es[i].second;
    nbrs[u].push_back(v);
    nbrs[v].push_back(u);
  }

  int st = gids[sy][sx], gl = gids[gy][gx];
  memset(ds, -1, sizeof(ds));
  ds[st] = 0;

  qi q;
  q.push(st);

  while (! q.empty()) {
    int u = q.front(); q.pop();
    if (u == gl) break;

    int vd = ds[u] + 1;
    vi &nbru = nbrs[u];
    for (vi::iterator vit = nbru.begin(); vit != nbru.end(); vit++) {
      int v = *vit;
      if (ds[v] < 0) {
	ds[v] = vd;
	q.push(v);
      }
    }
  }

  printf("%d\n", ds[gl]);
  return 0;
}


Measured memory_bytes: 54256
#include<iostream>
#include <string>

using namespace std;
int main()
{
	int a, b, c, k;

	cin >> a;
	cin >> b;
	cin >> c;
	cin >> k;

	int choice = k;

	if (k > a) {
		k -= a;
		k -= b;
		if (k <= 0) {
			cout << a << endl;
			return 0;
		}
		else {
			cout << a - k << endl;
			return 0;
		}
	}
	else if (k <= a) {
		cout << choice << endl;
		return 0;
	}
	return 0;
}

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


int main(){
  int M, D;
  cin >> M >> D;
  
  int ans;
  for(int m=1; m<=M; m++){
    for(int d=22; d<=D; d++){
      int d1 = d%10;
      int d10 = d/10;
      if(d1<2 || d10<2) continue;
      if(d1*d10!=m) continue;
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
// atcoder/abc162/D/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  int n;
  str s;
  while (cin >> n >> s) {
    vec<int> r, g, b;
    for (int i = 0; i < s.size(); ++i) {
      if (s[i] == 'R') r.push_back(i);
      if (s[i] == 'G') g.push_back(i);
      if (s[i] == 'B') b.push_back(i);
    }

    lli z = 0;
    const int sum = (int)'R' + (int)'G' + (int)'B';
    for (int i = 0; i < s.size(); ++i) {
      for (int j = i + 1; j < s.size(); ++j) {
        if (s[i] != s[j]) {
          const char c = sum - s[i] - s[j];
          if (c == 'R') {
            int x = r.end() - lower_bound(r.begin(), r.end(), j + 1);
            int y = binary_search(r.begin(), r.end(), j + abs(i - j));
            z += x - y;
          }
          if (c == 'G') {
            int x = g.end() - lower_bound(g.begin(), g.end(), j + 1);
            int y = binary_search(g.begin(), g.end(), j + abs(i - j));
            z += x - y;
          }
          if (c == 'B') {
            int x = b.end() - lower_bound(b.begin(), b.end(), j + 1);
            int y = binary_search(b.begin(), b.end(), j + abs(i - j));
            z += x - y;
          }
        }
      }
    }
    cout << z << endl;
  }

  return 0;
}


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

#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using pint = pair<int, int>;
using pstring = pair<int, string>;
using Graph = vector<vector<char>>;
const ll d_x[4] = {-1, 1, 0, 0};
const ll d_y[4] = {0, 0, -1, 1};

int main() {
    ll ans;
    ll R, C; cin >> R >> C;
    Graph G(R, vector<char>(C));
    ll black = 0;
    for( ll i = 0; i < R; i++ ) {
        for( ll j = 0; j < C; j++ ) {
            char a; cin >> a;
            G.at(i).at(j) = a;
            if( a == '#' ) black++;
        }
    }

    vector<vector<ll>> dist(R, vector<ll>(C, -1));
    queue<pair<ll,ll>> q;

    dist.at(0).at(0) = 0;
    pair<ll, ll> s;
    s.first = 0; s.second = 0;
    q.push(s);

    while(!q.empty()) {
        pair<ll,ll> p = q.front();
        q.pop();
        // cout << p.first << ' ' << p.second << ' ' << dist.at(p.first).at(p.second) << endl;
        for( ll i = 0; i < 4; i++) {
            ll n_x = p.first + d_x[i], n_y = p.second + d_y[i];
            if( n_x < 0 || n_x >= R || n_y < 0 || n_y >= C ||
                G.at(n_x).at(n_y) == '#' ) continue;
            if( dist.at(n_x).at(n_y) != -1 ) continue;
            dist.at(n_x).at(n_y) = dist.at(p.first).at(p.second) + 1;
            s.first = n_x, s.second = n_y;
            q.push(s);
        }
    }

    if(dist.at(R-1).at(C-1) == -1) cout << -1 << endl;
    else cout << R * C - dist.at(R-1).at(C-1) -1 - black << endl;
    // for( ll i = 0; i < R; i++ ) {
    //     for( ll j = 0; j < C; j++ ) {
    //         cout << dist.at(i).at(j) << ' ';
    //     }
    //     cout << endl;
    // }

    return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
typedef long long ll;

int main(){

    int n; cin >> n;

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

    int b[n+1];
    b[0] = abs(a[0]);
    b[n] = abs(a[n-1]);
    for(int i=1; i<n; i++){
        b[i] = abs(a[i] - a[i-1]);
    }

    int c[n];
    c[0] = abs(a[1]);
    c[n-1] = abs(a[n-2]);
    for(int i=1; i<n-1; i++){
        c[i] = abs(a[i+1] - a[i-1]);
    }

    // for(int i=0; i<=n; i++){
    //     cout << b[i] << " ";
    // }
    // cout << endl;

    // for(int i=0; i<n; i++){
    //     cout << c[i] << " ";
    // }
    // cout << endl;

    int l[n] = {}, r[n] = {};
    
    l[0] = 0;
    for(int i=1; i<n; i++){
        l[i] = l[i-1] + b[i-1];
        // cout << l[i] << " ";
    }
    // cout << endl;

    r[n-1] = 0;
    for(int i=n-2; i>=0; i--){
        r[i] = r[i+1] + b[i+2];
        // cout << r[i] << " ";
    }
    // cout << endl;

    for(int i=0; i<n; i++){
        cout << l[i] + c[i] + r[i] << endl;
    }


    return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int q,w,e;
	cin>>q>>w;
	
	if(q==1&&w==2) cout<<'3';
	if(q==1&&w==3) cout<<'2';
	if(q==2&&w==3) cout<<'1';
	if(q==2&&w==1) cout<<'3';
	if(q==3&&w==1) cout<<'2';
	if(q==3&&w==2) cout<<'1';
 } 

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

int main(){
	int n,l;
	cin>>n>>l;
	vector<string>v(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
	}
	sort(v.begin(), v.end());
	for(int i=0;i<n;i++){
		cout<<v[i];
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string a, b;
    cin >> a >> b;
    for( int i = 0; i < a.size(); ++i ) {
        cout << a[i];
        if( i != b.size() ) cout << b[i];
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIL pair<int,LL>
#define PLI pair<LL,int>
#define PIII pair<int,PII>
#define PLL pair<LL,LL>
#define PLII pair<LL,PII>
#define VI vector<int>
#define VL vector<LL>
#define VPII vector<PII>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define EPS 0.00000000001
#define PI acos(-1)
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

const int MOD = 998244353;
const LL MX = 1e9;
const LL INF = 1e9;

void mod_inv(LL a, LL b, LL &x, LL &y)
{
    if(a == 0)
    {
        x = 0; y = 1;
        return;
    }

    LL x1, y1;
    mod_inv(b%a,a,x1,y1);
    y = x1;
    x = y1 - (b/a) * x1;
}

LL pow_mod(LL x, LL n)
{
    LL ans = 1;
    while(n)
    {
        if(n & 1) ans = (ans * x) % MOD;
        n = n/2;
        x = (x * x) % MOD;
    }
    return ans;
}

int main()
{
    //ofstream out("output.txt");
    //ifstream in("input.txt");
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    /*
    int t,n;
    cin>>t;
    loop(t1,1,t+1)
    {
        int a[n];
        loop(i,0,n) cin>>a[i];
    }
    */

    LL n,m,k;
    cin>>n>>m>>k;
    LL n1 = 1, ans = 0;
    loop(i,0,k+1)
    {
        //cout<<'\n'<<i<<'\n';
        if(i) n1 = (n1 * (n - i)) % MOD;
        if(i > 1)
        {
            LL x, y;
            mod_inv(i,MOD,x,y);
            x = (x + MOD) % MOD;
            n1 = (n1 * x) % MOD;
            //cout<<x<<'\n';
        }

        LL n2 = n - i;
        LL ans1 = (m * n1) % MOD;
        ans1 = (ans1 * pow_mod(m-1,n2-1)) % MOD;
        //cout<<n1<<' '<<ans1<<' '<<pow_mod(m-1,n2-1)<<'\n';
        ans = (ans + ans1) % MOD;
    }

    cout<<ans<<'\n';
    /*
    if(f) cout<<"Yes"<<'\n';
    else cout<<"No"<<'\n';
    */

    return 0;
}


Measured memory_bytes: 3616
n, m, r = gets.strip.split.map(&:to_i)
r = gets.strip.split.map(&:to_i)
abc = readlines.map{|line| line.strip.split.map(&:to_i) }

INF = 10**10
graph = Array.new(n+1) { [INF]*(n+1) }
abc.each do |from, to, cost|
  graph[from][to] = graph[to][from] = cost
end

(1..n).each do |via|
  (1..n).each do |from|
    (1..n).each do |to|
      graph[from][to] = graph[to][from] = graph[from][via] + graph[via][to] if graph[from][to] > graph[from][via] + graph[via][to]
    end
  end
end

(1..n).each do |i|
  graph[i][i]=0
end

p r.permutation(r.length).map {|arr| arr.each_cons(2).map{|f, t| graph[f][t] }.inject(:+) }.min



Measured memory_bytes: 7804
#include<iostream>
#include<cstring>

using namespace std;

int main()
{
	int k,a,b;
	cin>>k>>a>>b;
	for(int i=a; i<=b; i++) 
	{
		if(i % k == 0) 
		{
			puts("OK");
			return 0;
		}
	}
	puts("NG");
	return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <numeric>

using namespace std;

int field[50][50];
int h, w;

void myfill(int src, int dst) {
	for (int y = 0; y < h; ++y) {
		for (int x = 0; x < w; ++x) {
			if (field[y][x] == src) {
				field[y][x] = dst;
			}
		}
	}
}

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

	for (int i = 0;i< h; ++i) {
		string s;
		cin >> s;
		for (int j = 0; j < w; ++j) {
			if (s[j] == '.') {
				field[i][j] = -1;
			}else{
				field[i][j] = gcnt;
				gcnt++;
			}
		}
	}
	for (int y = 0; y < h; ++y) {
		for (int x = 0; x < w; ++x) {
			if (field[y][x] == -1) continue;
			int nx, ny;
			nx = x-1;
			ny = y;
			if (0 <= nx && nx < w && 0 <= ny && ny < h) {
				if (field[ny][nx] >= 0) {
					myfill(field[y][x], field[ny][nx]);
				}
			}
			nx = x;
			ny = y-1;
			if (0 <= nx && nx < w && 0 <= ny && ny < h) {
				if (field[ny][nx] >= 0) {
					myfill(field[y][x], field[ny][nx]);
				}
			}
		}
	}
	auto col = vector<int>(50 * 50 + 1, 0);
	for (int y = 0; y < h; ++y) {
		for (int x = 0; x < w; ++x) {
			if (field[y][x] == -1) continue;
			col[field[y][x]]++;
		}
	}
	bool flag = true;
	for (int item : col) {
		if (item == 1) {
			flag = false;
		}
	}
	if (flag) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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

int main(void)
{
    int D;
    cin >> D;

    vector<int> c(27,0);

    for(int i = 1; i <= 26; ++i)
    {
        int tmp;
        cin >> tmp;

        c[i] = tmp;
    }

    int s[D+1][27] = {};

    for(int i = 1; i <= D; ++i)
    {
        for(int j = 1; j <= 26; ++j)
        {
            int tmp;
            cin >> tmp;
            s[i][j] = tmp;
        }
    }
    
// question definition

    vector<int> t(D+1,0);
/*
    for(int i = 1; i <= D; ++i)
    {
        int tmp;
        cin >> tmp;
        t[i] = tmp;
    }
*/
    vector<int> lastd(27,0);
    vector<int> ccp(26,0);
    int ans=0;

    for(int i = 1; i <= D; ++i)
    {
        int ccm = 0;
        for(int j = 1; j <= 26; ++j)
        {
            ccm -= c[j]*(i - lastd[j]);
        }
        for(int j = 1; j <= 26; ++j)
        {
            ccp[j-1] = s[i][j] + ccm + c[j]*(i - lastd[j]);
        }
        
        std::vector<int>::iterator iter = std::max_element(ccp.begin(), ccp.end());
        int index = std::distance(ccp.begin(), iter);
        t[i] = index+1;
        lastd[t[i]] = i;

    }

    for(int i = 1; i <= D; ++i)
    {
        cout << t[i] << endl;
    }    

    return 0;
}



Measured memory_bytes: 3660
N,X=map(int,input().split())

from functools import lru_cache
import sys

sys.setrecursionlimit(10*20)

@lru_cache(maxsize=None)
def count(N):
    if N == 0:
        return 1
    else:
        return 3 + 2 * count(N-1)
    
@lru_cache(maxsize=None)
def calc(N,X):
    if N == 0:
        return 1
    center = count(N-1) + 1
    if X == 0 :
        return 0
    elif X < center:
        return calc(N-1,X-1)
    elif X == center:
        return calc(N-1,center-2) + 1
    elif X > center:
        return calc(N-1,X-center-1) + calc(N,center)
print(calc(N,X-1))

Measured memory_bytes: 43504
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int main() {
    int n, a, b; cin >> n >> a >> b;
    int p = 0;
    string s; cin >> s;
    int c1 = 0, c2 = 0, c3 = 0;
    rep(i,0,n) {
        if(s[i] == 'a') {
            c1++;
            if(p < a + b) cout << "Yes" << endl, p++;
            else cout << "No" << endl;
        }
        if(s[i] == 'b') {
            c2++;
            if(p < a + b && c2 <= b) cout << "Yes" << endl, p++;
            else cout << "No" << endl;
        }
        if(s[i] == 'c') {
            c3++;
            cout << "No" << endl;
        }
    }
    return 0;
}

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

int p[510][510];

int main()
{
	int n, m, q, l, r;
	int i, j;
	
	cin >> n >> m >> q;
	
	for (i = 0; i < m; i++)
	{
		cin >> l >> r;
		p[l][r]++; //this train runs between l and r
	}
	
	for (i = 1; i <= n; i++)
	{
		for (j = 1; j <= n; j++)
		{
			p[i][j] += p[i][j - 1]; // the trains that run one less is also within this range
		}
	}
	
	for (i = 1; i <= n; i++)
	{
		for (j = 1; j <= n; j++)
		{
			p[i][j] += p[i - 1][j]; // the trains that run one less is also within this range
		}
	}
	
	for (int i = 1; i <= q; i++) {
		cin >> l >> r;
		cout << p[r][r] + p[l - 1][l - 1] - p[l - 1][r] - p[r][l - 1] << endl;
		// add the trains that run only on r, and only on l - 1, and subtract the
		// miscellaneous cases.
	}
	
	
	
	return 0;
}

Measured memory_bytes: 1920