akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int a[5005];
int main()
{

    int i,j,k,l,t,z,n,r,x,y;
    cin>>n;
    map<string,int>m;
    string s;
    for(i=0;i<n;i++)
    {
        cin>>s;
        m[s]++;
    }
    cout<<"AC x "<<m["AC"]<<endl;
    cout<<"WA x "<<m["WA"]<<endl;
    cout<<"TLE x "<<m["TLE"]<<endl;
    cout<<"RE x "<<m["RE"]<<endl;
}


Measured memory_bytes: 3632
#!/usr/bin/env python3
import collections as cl
import sys


def II():
    return int(sys.stdin.readline())


def MI():
    return map(int, sys.stdin.readline().split())


def LI():
    return list(map(int, sys.stdin.readline().split()))


def main():
    _a, _b = input().split()

    a = _a * int(_b)
    b = _b * int(_a)
    print(a if a < b else b)


main()


Measured memory_bytes: 64912
// Charan Sriramula

#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long int ll;

const ll lg=14;
const ll N=1e5+5;
const ll INF=1e9;
const ll mod=1e9+7;
const double PI = 3.14159265358979323846;

#define ints(n) scanf("%d",&n)
#define intp(n) printf("%d\n",n)
#define longs(n) scanf("%lld",&n)
#define longp(n) printf("%lld\n",n)

#define f first
#define s second
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define mp(x,y) make_pair(x,y)
#define GCD(a,b) __gcd((a),(b))
#define all(v) v.begin(),v.end()
#define bits(x) __builtin_popcount(x)
#define LCM(a,b) ((a)*(b))/GCD((a),(b))
#define ms(dp,val) memset(dp,val,sizeof(dp))
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
template<typename T> T power(T x,T y,ll m){T ans=1;while(y>0){if(y&1LL) ans=(ans*x)%m;y>>=1LL;x=(x*x)%m;}return ans%m;}

ll n,W,w[N],v[N],dp[105][N];

ll F(ll idx,ll rem)
{
  if(rem<0){return -INF;}
  if(idx==n+1){return 0;}
  if(dp[idx][rem]!=-1){return dp[idx][rem];}
  ll x=v[idx]+F(idx+1,rem-w[idx]);
  ll y=F(idx+1,rem);
  return dp[idx][rem]=max(x,y);
}

int main()
{
  //ll n;
  cin>>n>>W;
  ms(dp,-1);
  for(ll i=1;i<=n;i++){cin>>w[i]>>v[i];}
  cout<<F(1,W)<<endl;
}


Measured memory_bytes: 82304
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    int x,a,b;
    cin >> x >> a >>b;
    if(a >= b){
        cout << "delicious" << endl;
    }
    else if (a+x >= b){
        cout << "safe" << endl;
    }else{
        cout << "dangerous" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	long long int lucas[87] = {0};
	int n;
	
	cin >> n;
	
	lucas[0] = 2;
	lucas[1] = 1;
	
	for (int i = 2; i <= n; i++) {
		lucas[i] = lucas[i-1] + lucas[i-2];
	}
	
	cout << lucas[n] << endl;
	
	return (0);
}

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

int main() {
    string N, M;
    cin >> N >> M;
    int n=N.length(), m=M.length();
    int dp[n+1][m+1];
    vector<vector<array<int,2>>> path(n+1, vector<array<int,2>>(m+1, {0,0}));
    memset(dp,0,sizeof(dp));
    for (int i=1;i<=n;i++) {
        for (int j=1;j<=m;j++) {
            if (N[i-1]==M[j-1]) {
                dp[i][j]=dp[i-1][j-1]+1;
                path[i][j]={-1,-1};
            }
            else {
                if (dp[i-1][j]>dp[i][j-1]) {
                    dp[i][j]=dp[i-1][j];
                    path[i][j]={-1,0};
                }
                else {
                    dp[i][j]=dp[i][j-1];
                    path[i][j]={0,-1};
                }
            }
        }
    }
    string lcs="";
    for (int i=n, j=m;i!=0&&j!=0;) {
        if (N[i-1]==M[j-1])
            lcs.push_back(N[i-1]);
        int ti=i, tj=j;
        i+=path[ti][tj][0];
        j+=path[ti][tj][1];
    }
    reverse(lcs.begin(), lcs.end());
    cout << lcs;
    return 0;
}

// f(n,m)=max(f(n-1,m) , f(n,m-1)) if N[n]!=M[m]
// f(n,m)=f(n-1,m-1)+1 if N[n]==M[m]


Measured memory_bytes: 108836
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b > 0:
        a = a % b
        a, b = b, a
    return a

def main():
    n, x = map(int, input().split())
    town = map(int, input().split())

    distance = (abs(x-y) for y in town)
    res = next(distance)
    for d in distance:
        if d % res != 0:
            res = gcd(res, d)

    print(res)

if __name__ == "__main__":
    main()

Measured memory_bytes: 11096
#include<bits/stdc++.h>
//#define int long long
#define loop(i, a, b) for(int i = a; i < b; i++)
#define rep(i, a) loop(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int MOD = 1e9 + 7, INF = 1e9;
using vi = vector <int>;
using vvi = vector <vi>;
//g++ -std==c++14

int main(){
	int a, b;
	cin >> a >> b;
	if( (a >= 0 && b <= 0) || (a <= 0 && b >= 0))
			cout << "Zero" << endl;
	else if(a > 0 && b > 0)
		cout << "Positive" << endl;
	else{
		if( (b - a == 0) || (b - a) % 2 == 1 )
			cout << "Positive" << endl;
		else
			cout << "Negative" << endl;
	}
}

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

const ll MAX = 1e6;
const ll MOD = 1e9 + 7;

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

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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() {
    ll mod = 1e9 + 7;
    ll N, M;
    cin >> N >> M;
    vector<ll> a(M);
    rep(i, M) cin >> a[i];

    vector<ll> steps(N + 1, 0);
    rep(i, M - 1) if (a[i] == a[i + 1] - 1) {
        cout << 0 << endl;
        return 0;
    }
    rep(i, M - 1) steps[a[i + 1] - a[i] - 2]++;
    if (M > 0) {
        steps[a[0] - 1]++;
        steps[N - a[M - 1] - 1]++;
    } else {
        steps[N]++;
    }
    COMinit();
    ll ans = 1;
    rep(i, N + 1) {
        if (steps[i] == 0) continue;
        ll two_max = i / 2, way = 0;
        rep(two, two_max + 1) {
            ll one = i - 2 * two;
            way += COM(one + two, two);
            way %= mod;
        }
        rep(j, steps[i]) ans = (ans * way) % mod;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 24832
from math import ceil
from fractions import gcd

a, b = map(int, input().split())
c = gcd(a, b)
count = 1
for num in range(2, ceil(c**0.5) + 1):
  if c % num == 0:
    count += 1
    while c % num == 0:
      c = c // num
if c > 1:
  count += 1
print(count)

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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;


int main() {

    int n, k;
    cin >> n >> k;

    int ans = k;
    fo(i, n - 1) ans *= (k - 1);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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


int main(){
    int n, m, x;
    cin >> n >> m >> x;
    int c[n], a[n][m];
    rep(i, n){
        cin >> c[i];
        rep(j, m) cin >> a[i][j];
    }
    int ans = 1000000000;
    for (int i = 0; i < (1 << n); i++){
        int num[m];
        int sm = 0;
        fill(num, num + m, 0);
        for (int j = 0; j < n; j++){
            if(((i >> j) & 1) == 1){
                sm += c[j];
                rep(k, m){
                    num[k] += a[j][k];
                }
            }
        }
        bool flag = true;
        rep(j, m){
            if(num[j] < x) flag = false;
        }
        if(flag){
            ans = min(ans, sm);
        }
    }
    if(ans == 1000000000){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
    
}


Measured memory_bytes: 3636
#include <cstdio>
#include <algorithm>

using namespace std;

int main()
{
    int a, b, c, x, y;
    scanf("%d %d %d %d %d", &a, &b, &c, &x, &y);

    int ans = 0;
    if (a + b > c * 2)
    {
        int cup = min(x, y);
        ans = cup * c * 2;
        x -= cup;
        y -= cup;
        if (a > c * 2)
        {
            ans += x * c * 2;
        }
        else
        {
            ans += x * a;
        }
        if (b > c * 2)
        {
            ans += y * c * 2;
        }
        else
        {
            ans += y * b;
        }
    }
    else
    {
        ans = a * x + b * y;
    }

    printf("%d\n", ans);
    return 0;
}

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

using namespace std;

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

#define F first
#define S second

const int MAXN = 2e5 + 10;
const int C = 1e5;

int n, tl[MAXN], tr[MAXN], c[2][MAXN];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) cin >> tl[i] >> tr[i], tl[i] += C, tr[i] += C, c[0][tl[i]]++, c[1][tr[i]]++;
	for (int i = MAXN-2; ~i; i--) c[0][i] += c[0][i+1];
	for (int i = 1; i < MAXN; i++) c[1][i] += c[1][i-1];
	ll ans = 0;
	for (int i = 0; i + 1 < MAXN; i++)
		if (i + 1 <= C){
			int temp = min(c[1][i], 1 + c[0][i+1]);
			ans += temp;
		}
		else{
			int temp = min(c[0][i+1], 1 + c[1][i]);
			ans += temp;
		}
	cout << ans*2 << "\n";
	return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define REP(i,s,e) for(int i=(s); i<(e);i++)
#define rep(i,n) REP(i,0,n)
#define rep1(i,n) REP(i,1,n)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;
const LL LLINF = 1e16;

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

    if(k == 1){
        cout << 0 << endl;
    }else{
        cout << n-k << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i, a, n) for(int i=(int)(n-1);i>=a;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    cin >> a >> b;

    set<int> S;
    rep(i, 1, 51) S.insert(i);

    auto check = [&]() {
        rep(j, 0, n) {
            vector<bool> dp(51);
            dp[a[j]] = true;
            rrep(k, 0, 51) {
                if (!dp[k]) continue;
                fore(x, S) {
                    dp[k % x] = true;
                }
            }
            if (!dp[b[j]]) {
                return false;
            }
        }
        return true;
    };

    if (!check()) {
        cout << -1 << endl;
        return 0;
    }

    rrep(i, 1, 51) {
        S.erase(i);
        if (!check())
            S.insert(i);
    }

    int ans = 0;
    fore(x, S) ans += 1LL << x;
    cout << ans << endl;
    return (0^_^0);
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s,t="";
  cin>>s;
  for(int i=0;i<3;i++){
    if(s[i]=='1')t+='9';
    else t+='1';
  }
  cout<<t<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);i++)
#define FOR(i,n,m) for(int i=n;i<int(m);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
using namespace std;

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

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

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

const ll mod=1e9+7;
const int INF=INT_MAX/2;
const int N_MAX=100010;

int main(){
	ll n,k;
	cin>>n>>k;
	ll cnt=0;
	for(ll a=1;a<=n;a++){
		if(2*a>=k && (2*a)%k==0){
			ll s=(n+a)/k-a/k;
			cnt+=s*s;
		}
	}
	cout<<cnt<<endl;
	return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

h,w = LI()
a = [input() for _ in range(h)]
check_h = [True]*h
check_w = [True]*w
for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            break
    else:
        check_h[i] = False
for i in range(w):
    for j in range(h):
        if a[j][i] == '#':
            break
    else:
        check_w[i] = False

ans = []
for i in range(h):
    if check_h[i]:
        s = ''
        for j in range(w):
            if check_w[j]:
                s += a[i][j]
        ans.append(s)
for i in ans:
    print(i)

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

typedef long long ll;
typedef pair<ll,int> P;
ll const INF = INT64_MAX;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

struct edge {
    ll w;int u;int v;
    bool operator<(const edge& a) const {
        return w < a.w;
    }
};

struct SegmentTree {
private:
    int n;
    vector<P> node;
public:
    SegmentTree(vector<P> v) {
        int sz = v.size();
        n = 1;
        while (n < sz) n *= 2;
        node.resize(2*n-1,P(INF,-1));
        for (int i = 0;i < sz;++i) node[i+n-1] = v[i];
        for (int i = n-2;i >= 0;--i) node[i] = min(node[2*i+1],node[2*i+2]);
    }
    void update(int x,P val) {
        x += (n-1);
        node[x] = val;
        while (x > 0) {
            x = (x-1)/2;
            node[x] = min(node[2*x+1],node[2*x+2]);
        }
    }

    P getmin(int a,int b,int k = 0,int l = 0,int r = -1) {
        if (r < 0) r = n;
        if (r <= a || b <= l) return P(INF,-1);
        if (a <= l && r <= b) return node[k];
        P vl = getmin(a,b,2*k+1,l,(l+r)/2);
        P vr = getmin(a,b,2*k+2,(l+r)/2,r);
        return min(vl,vr);
    }
};

struct UnionFind {
private:
    vector<int> par,depth;
public:
    UnionFind (int n) {
        par.resize(n);
        depth = vector<int>(n,0);
        for (int i = 0;i < n;++i) par[i] = i;
    }

    int find(int x) {
        if (par[x] == x) return x;
        else return par[x] = find(par[x]);
    }

    void unite(int x,int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (depth[x] < depth[y]) par[x] = y;
        else {
            par[y] = x;
            if (depth[x] == depth[y]) depth[x]++;
        }
    }

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


int main() {
    int n;
    ll d,ans = 0;
    cin >> n >> d;
    vector<ll> a(n);
    multimap<ll,int> b;
    vector<edge> edgelist;
    SegmentTree segL(vector<P>(n,P(INF,-1))),segR(vector<P>(n,P(INF,-1)));
    UnionFind kruskal(n);
    
    for (int i = 0;i < n;++i) cin >> a[i];
    for (int i = 0;i < n;++i) b.insert(P(a[i],i));

    for (auto it = b.begin();it != b.end();++it) {
        ll s = it->first;
        int i = it->second;
        P mnL = segL.getmin(0,i),mnR = segR.getmin(i,n);
        if (mnL.first < INF) {
            int j = mnL.second;
            edgelist.push_back(edge{a[i]+a[j]+(ll)(i-j)*d,i,j});
        }
        if (mnR.first < INF) {
            int j = mnR.second;
            edgelist.push_back(edge{a[i]+a[j]+(ll)(j-i)*d,i,j});
        }
        segL.update(i,P(a[i]+(ll)(n-i)*d,i));
        segR.update(i,P(a[i]+(ll)i*d,i));
    }

    sort(edgelist.begin(),edgelist.end());
    for (edge e : edgelist) {
        if (kruskal.same(e.u,e.v)) continue;
        ans += e.w;
        kruskal.unite(e.u,e.v);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 46548
// A.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char *argv[]) {
	int n, x;
	cin >> n >> x;
	vector<int> a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	int ans = 0;
	for (int i = 0; i < n - 1; ++i) {
		if (x >= a[i]) {
			++ans;
			x -= a[i];
		}
	}
	if (x == a[n - 1]) {
		++ans;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 888
#include <iostream>
#include <stdlib.h>
#include <queue>
using namespace std;
typedef pair<int, int> P;
const int INF = 1000 * 1000;
const int MAX_N = 1024;
int W, H, N;
char map[MAX_N][MAX_N];
int sx[10], sy[10];
int ex[10], ey[10];
int d[MAX_N][MAX_N];
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
int BFS(int sx, int sy, int ex, int ey) {
	queue<P> que;
	for (int i = 0; i < W; i++) {
		for (int j = 0; j < H; j++) {
			d[i][j] = INF;
		}
	}
	que.push(P(sx, sy));
	d[sx][sy] = 0;
	while (que.size())
	{
		P p = que.front();
		que.pop();
		if (p.first == ex && p.second == ey)
			break;
		for (int i = 0; i < 4; i++) {
			int nx = p.first + dx[i];
			int ny = p.second + dy[i];
			if (nx >= 0 && nx < W&&ny >= 0 && ny < H&&map[nx][ny] != 'X'&&d[nx][ny]==INF) {
				que.push(P(nx, ny));
				d[nx][ny] = d[p.first][p.second] + 1;
			}
		}


	}
	return d[ex][ey];
}
int main() {
	while (cin >> W >> H >> N) {
		int ans = 0;
		for (int i = 0; i < W; i++)
			for (int j = 0; j < H; j++) {
				cin >> map[i][j];
				if (map[i][j] == 'S') {
					sx[0] = i;
					sy[0] = j;
				}
			}
		for (int i = 0; i < W; i++)
			for (int j = 0; j < H; j++) {
				if (map[i][j] > 48 && map[i][j] < 58) {
					sx[map[i][j] - 48] = i;
					sy[map[i][j] - 48] = j;
				}
			}
		for (int i = 0; i < N; i++) {

			ans += BFS(sx[i], sy[i], sx[i + 1], sy[i + 1]);

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


Measured memory_bytes: 8100
#include<iostream>
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int util(vector<vector<char>>&grid)
{
  int h=grid.size(),w=grid[0].size();
  long long dp[h][w];
  for(int i=0;i<h;i++)
  {
    for(int j=0;j<w;j++)
    dp[i][j]=0;
  }
  dp[0][0]=1;
  for(int i=1;i<h;i++)
    if(grid[i][0]!='#')
    dp[i][0]=dp[i-1][0];
  for(int j=1;j<w;j++)
    if(grid[0][j]!='#')
    dp[0][j]=dp[0][j-1];
  for(int i=1;i<h;i++)
  {
    for(int j=1;j<w;j++)
    {
      if(grid[i][j]!='#')
      dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
    }
  }
  return dp[h-1][w-1]%mod;
}
int main()
{
  int h,w;
  cin>>h>>w;
  vector<vector<char>> grid;
  for(int i=0;i<h;i++)
  {
    vector<char> temp;
    for(int j=0;j<w;j++)
    {
      char c;
      cin>>c;
      temp.push_back(c);
    }
    grid.push_back(temp);
  }
  int ans=util(grid);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 9088
#[allow(unused_macros)]
macro_rules ! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( stdin . lock ( ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , mut $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let mut $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[allow(unused_macros)]
macro_rules ! vecs { ( $ init : expr ; $ ( $ dim : expr ) ;* ) => { vecs ! ( $ ( $ dim ) ;* => $ init ) } ; ( $ head : expr ; $ ( $ tail : expr ) ;* => $ init : expr ) => { vec ! [ vecs ! ( $ ( $ tail ) ;* => $ init ) ; $ head ] } ; ( $ head : expr => $ init : expr ) => { vec ! [ $ init ; $ head ] } ; }

fn main() {
    input! {
        h: usize, w: usize,
        a: [chars; h]
    }
    let mut b = vecs!['0';h+2;w+2];
    for i in 0..b.len() {
        for j in 0..b[0].len() {
            if i == 0 || j == 0 || i == h+1 || j == w+1 {
                b[i][j] = '#';
            } else {
                b[i][j] = a[i-1][j-1];
            }
        }
    }
    for i in 0..b.len() {
        for j in 0..b[0].len() {
            print!("{}", b[i][j]);
        }
        println!("");
    }
}


Measured memory_bytes: 4352
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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 pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
const int N = pow(10, 6);

vector<bool> isp(N + 1, true);

void sieve()
{
    isp[0] = false;
    isp[1] = false;
    for (int i = 2; pow(i, 2) <= N; i++)
    {
        if (isp[i])
            for (int j = 2; i * j <= N; j++)
                isp[i * j] = false;
    }
} //N以下の整数をふるってくれます
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    sieve();
    V prime;
    rep(i,isp.size()){
        if(isp[i])
            prime.push_back(i);
    }
    ll x;
    cin >> x;
   // cout<<x<<endl;
 //  cout<<x<<endl;
  //cout<<prime[0]<<endl;
 //  cout<<lower_bound(all(isp), x)-isp.begin()<<endl;
    cout << prime[lower_bound(all(prime), x)-prime.begin()] << endl;
}


Measured memory_bytes: 2032
#import <iostream>
using namespace std;
int main(){
	int A,B,count,temp1,temp2;
	cin>>A>>B;
	for(int i=A;i<=B;i++){
		if(i/10000==i%10){
			temp1=i/1000;
			temp2=i/10;
			if(temp1%10==temp2%10){
				count++;
			}
		}
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
using namespace std;

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

    vector<pair<int,string>> v;
    rep(i,m)
    {
        int p; string s; cin>>p>>s;
        v.push_back(make_pair(p,s));
    }

    vpii w;
    rep(i,n)
    {
        w.push_back(make_pair(0,0));
    }

    rep(i,m)
    {
        if(v[i].second=="WA"&&w[v[i].first-1].second!=1)w[v[i].first-1].first++;
        if(v[i].second=="AC")w[v[i].first-1].second=1;
    }

    int ac=0,wa=0;
    rep(i,n)
    {
        if(w[i].second==1)
        {
            ac++;
            wa+=w[i].first;
        }
    }
    cout<<ac<<" "<<wa<<endl;

}

Measured memory_bytes: 8304
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 26 20:57:12 2020

@author: Kanaru Sato
"""

n = int(input())

dic = {}

for i in range(n):
    s = input()
    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 1

print(len(dic))

Measured memory_bytes: 35212
#include <cstdio>
#include <cctype>
#include <queue>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long
#define reg register
#define rep(i, a, b) for (reg int i = (a), i##end = (b); i <= i##end; ++i)
#define dep(i, a, b) for (reg int i = (a), i##end = (b); i >= i##end; --i)

template <typename _typer> inline _typer read() {
    _typer init = 0;
    char ch = getchar(), k = 0;
    for ( ; !isdigit(ch); ch = getchar()) k = (ch == '-');
    for ( ; isdigit(ch); ch = getchar())
        init = (init << 3) + (init << 1) + (ch ^ 48);
    return k ? -init : init;
}
const ll N = 25005, INF = 1e17;
const ll M = 50005;

#define int ll

int n, m, p;

struct EDGE {
    int to, nex, cost;
} edge[M], Tedge[M];
int head[N], cntedge, Thead[N], cntTedge;
void Addedge(int u, int v, int w) {
    edge[++cntedge] = (EDGE) { v, head[u], w };
    head[u] = cntedge;
}
void AddTedge(int u, int v, int w) {
    Tedge[++cntTedge] = (EDGE) { v, Thead[u], w };
    Thead[u] = cntTedge;
}

queue < int > Q;
int dis[N], cnt[N], inq[N], vis[N], Can[N];
int SPFA() {
    if (!Can[1]) return -1;
    rep (i, 1, n) dis[i] = -INF;
    Q.push(1), inq[1] = true, dis[1] = 0;
    while (!Q.empty()) {
        int u = Q.front(); Q.pop(), inq[u] = false;
        vis[u] = true;
        if ((++cnt[u]) > n) return -1;
        for (int i = head[u], v; i; i = edge[i].nex) {
            v = edge[i].to;
            if (!Can[v]) continue;
            if (dis[v] < dis[u] + edge[i].cost) {
                dis[v] = dis[u] + edge[i].cost;
                if (!inq[v]) Q.push(v), inq[v] = true;
            }
        }
    }
    return max(1ll * 0, dis[n]);
}

void Make() {
    queue < int > Q;
    Q.push(n), Can[n] = true;
    while (!Q.empty()) {
        int u = Q.front(); Q.pop();
        Can[u] = true;
        for (int i = Thead[u], v; i; i = Tedge[i].nex) {
            v = Tedge[i].to;
            if (!Can[v]) Q.push(v);
        }
    }
}

signed main() {
    n = read<int>(), m = read<int>(), p = read<int>();
    rep (i, 1, m) {
        int x = read<int>(), y = read<int>(), c = read<int>();
        Addedge(x, y, c - p), AddTedge(y, x, c - p);
    }
    Make();
    cout << SPFA() << endl;
    return 0;
}



Measured memory_bytes: 7168
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n, a = 0; cin >> n;
	a += n / 100000000; a += n % 10;
	a += n % 100000000 / 10000000; a += n % 100 / 10;
	a += n % 10000000 / 1000000; a += n % 1000/ 100;
	a += n % 1000000 / 100000; a += n % 10000 / 1000;
	a += n % 100000 / 10000;
	if (n%a == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	cin >> n;
}

Measured memory_bytes: 256
n = int(input())
taro = 0
hanako = 0

for i in range(n):
    sc = input().split()
    if sc[0] > sc[1]:
        taro += 3
    elif sc[0] < sc[1]:
        hanako += 3
    else:
        taro += 1
        hanako += 1
print(taro, hanako)


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

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			string s = Console.ReadLine();
			int n = s.Length;

			for (int i = 1; i < n - 1; i++) {
				string t = s.Substring(0, n - i);
				int m = t.Length;
				if (m % 2 != 0) {
					continue;
				}

				bool ok = true;
				int l = m / 2;
				for (int j = 0; j < l; j++) {
					if (t[j] != t[j + l]) {
						ok = false;
						break;
					}
				}

				if (ok) {
					Console.WriteLine(n - i);
					return;
				}
			}
		}
	}
}

Measured memory_bytes: 13140
#include <iostream>

using namespace std;

int main() {
    int h, w;
    while (true) {
        cin >> h >> w;
        if (h == 0 && w == 0) break;
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) cout << (i % 2 == j % 2 ? '#' : '.');
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}



Measured memory_bytes: 3116
N,M = map(int,input().split())
dp = [1 for i in range(N)]
trace = [0 for i in range(N)]
trace[0] = 1
for i in range(M):
    x,y = map(int,input().split())
    dp[y-1] += 1
    dp[x-1] -= 1
    if trace[x-1] >= 1:
        trace[y-1] = max(trace[y-1]+1,0)
    if dp[x-1] == 0:
        trace[x-1] = 0

print(len(trace) - trace.count(0))



Measured memory_bytes: 4656
import sys
import heapq
from typing import Callable, List, NoReturn, Set


def dijkstra(n, path) -> List[int]:
    total_cost: List[int] = [10**5] * (n + 1)
    total_cost[1] = 0

    pointers: List[int] = [-1] * (n + 1)
    pointers[1] = 0

    not_checked: Set[int] = set(range(1, n + 1))
    checked: Set[int] = set()
    cur_node: int = 1
    h: List = []

    while not_checked:
        checked.add(cur_node)
        not_checked -= {cur_node}

        for next_node in path[cur_node]:
            if next_node in not_checked:
                heapq.heappush(h, (total_cost[cur_node] + 1, next_node, cur_node))

        if not_checked:
            cost, next_node, prev_node = heapq.heappop(h)  # type: int, int, int

            while next_node in checked:
                cost, next_node, prev_node = heapq.heappop(h)

            cur_node = next_node
            total_cost[cur_node] = cost
            pointers[cur_node] = prev_node

    return pointers


def main() -> NoReturn:
    readline: Callable[[], str] = sys.stdin.readline

    n, m = map(int, readline().rstrip().split())  # type: int, int
    path: List[List[int]] = []
    for _ in range(n + 1):
        path.append([])
    for _ in range(m):
        a, b = map(int, readline().rstrip().split())  # type: int, int
        (path[a]).append(b)
        (path[b]).append(a)

    print("Yes")
    pointers: List[int] = dijkstra(n, path)
    for i in range(2, n + 1):
        print(pointers[i])


if __name__ == '__main__':
    main()


Measured memory_bytes: 128592
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<cmath>
#include<iomanip>
#include<functional>
using namespace std;

int INF = 1e9 + 7;

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

int main() {
	int sx, sy, tx, ty;
	cin >> sx >> sy >> tx >> ty;

	for (int i = 1; i <= ty - sy; i++) cout << 'U';
	for (int i = 1; i <= tx - sx; i++) cout << 'R';
	for (int i = 1; i <= ty - sy; i++) cout << 'D';
	for (int i = 1; i <= tx - sx + 1; i++) cout << 'L';
	for (int i = 1; i <= ty - sy + 1; i++) cout << 'U';
	for (int i = 1; i <= tx - sx + 1; i++) cout << 'R';
	cout << 'D';
	cout << 'R';
	for (int i = 1; i <= ty - sy + 1; i++) cout << 'D';
	for (int i = 1; i <= tx - sx + 1; i++) cout << 'L';
	cout << 'U' << endl;
}

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

int main()
{
    int a, b, k;
    cin >> a >> b >> k;
    int co = min(a, b);
    vector<int> vec;
    for (int i = 0; i < co; i++)
    {
        if (a % (i + 1) == 0 && b % (i + 1) == 0)
        {
            vec.push_back(i+1);
        }
    }
    sort(vec.begin(), vec.end(),greater<int>());
    cout << vec[k-1] << endl;
}

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

long long dp[200001][3][3], mod = 998244353, a = 1, N, sum, th[200001];

// dp[i][j][k] 0~i 和のmod3がj i番目がk 連続あり

int main(){
	string S; cin >> S; N = S.size();
	if(N == 2){
		if(S[0] == S[1]) cout << 1 << endl;
		else cout << 2 << endl;
	}else if(N == 3){
		if(S[0] == S[1] && S[1] == S[2]) cout << 1 << endl;
		else if(S[0] != S[1] && S[1] != S[2] && S[2] != S[0]){
			cout << 3 << endl;
		}else{
			if(S[0] == S[1] || S[1] == S[2]) cout << 6 << endl;
			else cout << 7 << endl;
		}
	}else{
		int c = 1;
		for(int i=0; i<N-1; i++){
			if(S[i] != S[i+1]) c = 0;
		}
		if(c){
			cout << 1 << endl;
			return 0;
		}
		for(int i=0; i<N; i++){
			if(S[i] == 'b') sum = (sum + 1) % 3;
			if(S[i] == 'c') sum = (sum + 2) % 3;
		}
		th[0] = 1;
		for(int i=1; i<=N; i++) th[i] = th[i-1] * 3 % mod;
		dp[1][0][0] = 1, dp[1][1][2] = 1, dp[1][2][1] = 1;
		for(int i=2; i<N; i++){
			for(int j=0; j<3; j++){
				for(int k=0; k<3; k++){
					for(int l=0; l<3; l++){
						if(k != l){
							dp[i][j][k] = (dp[i][j][k] + dp[i-1][(j-k+3)%3][l]) % mod;
						}else{
							dp[i][j][k] = (dp[i][j][k] + th[i-2]) % mod;
						}
					}
				}
			}
		}
		int f = 1;
		for(int i=0; i<N-1; i++){
			if(S[i] == S[i+1]) f = 0;
		}
		cout << (dp[N-1][sum][0] + dp[N-1][sum][1] + dp[N-1][sum][2] + f) % mod << endl;
	}
	return 0;
}


Measured memory_bytes: 16132
#include <bits/stdc++.h>
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define dbV(arr) cout << #arr << "=[ "; \
for(auto i:arr) cout << i << " "; cout << "]\n";
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define repF(i,a,n) for(int i = (a); i <= (n); ++i)
#define repB(i,a,n) for(int i = (a); i >= (n); --i)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define umii unordered_map<int,int>
#define umll unordered_map<ll,ll>
#define mii map<int,int>
#define mll map<ll,ll>
#define seti set<int>
#define setl set<ll>
#define pb push_back
#define F first
#define S second
#define MOD 1000000007
#define all(z) z.begin(),z.end()
using namespace std;
using ll = long long;
ll solve(vector<pair<int, ll>> &item, int n, int w) {
	int vSum = 0;
	for (auto i : item) vSum += i.S;
	ll dp[n + 1][vSum + 1];
	repF(i, 0, n) {
		repF(j, 0, vSum) {
			if (!i or !j) {
				if (!i) dp[i][j] = w + 1;
				if (!j) dp[i][j] = 0;
			}
			else {
				if (item[i - 1].S <= j)
					dp[i][j] = min(item[i - 1].F + dp[i - 1][j - item[i - 1].S], dp[i - 1][j]);
				else
					dp[i][j] = dp[i - 1][j];
			}
			//cout << dp[i][j] << " ";
		}
		//cout << endl;
	}
	int ans = 0;
	rep(i, vSum + 1)
	if (dp[n][i] <= w)
		ans = max(ans, i);
	return ans;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n, w; cin >> n >> w;
	vector<pair<int, ll>> item(n);
	rep(i, n) cin >> item[i].F >> item[i].S;
	cout << solve(item, n, w) << '\n';
	return 0;
}

Measured memory_bytes: 82520
#include <stdio.h>

int main() {
    int N;
    scanf("%d", &N);

    int a,b,c;

    a = N / 100;
    b = (N % 100) / 10;
    c = N % 10;

    if(a == 7 || b == 7 || c == 7) {
        printf("Yes");
    } else {
        printf("No");
    }

    return 0;
}

Measured memory_bytes: 1728
//ABC101A
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;

int main(){
	string s;
	cin >> s;
	int ans = 0;
	for(int i=0;i<s.size();i++){
		if(s.at(i) == '+'){
			ans++;
		}else{
			ans--;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> ii;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef vector <ii> vii;
typedef vector <vii> vvii;
#define endl '\n'
#define PB push_back
#define MP make_pair
#define fr first
#define sc second
#define OO (1000000000)         // ToDo
#define EPS (1e-9)              // ToDo
#define MOD (1000000007)        // ToDo
#define all(v) ((v).begin()),((v).end())
#define WT(x) cout<< #x <<" = "<<"\""<< (x) <<"\""<<endl
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
void read_file(bool outToFile = true){
#ifdef LOCAL_TEST
    freopen("in", "rt", stdin);
    if(outToFile)
    freopen("out", "wt", stdout);
#endif
}
//
int n;
const int MAXN = 50+99;
ll A[MAXN];
typedef pair <ll, ll> pll;
//
int main()
{
    read_file();
    while(scanf("%d", &n) != -1)
    {
        for(int i=0; i<n; i++)
            scanf("%lld\n", &A[i]);
        
        ll ans = 0;
        while(true)
        {
            sort(A, A+n, greater<ll>());
            ll a = A[0];
            if(a <= n-1) break;
            
            ll x = a/n;
            A[0] = a - x * n;
            ans += x;
            for(int i=1; i<n; i++) A[i] += x;
        }
        
        printf("%lld\n", ans);
    }
}


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

int main(){
    int n,q;
    char b,c;
    cin>>n>>q;
    cin>>b;
    vector<int> s(n+1);
    for(int i=2;i<=n;i++){
        cin>> c;
            if(c=='C' && b=='A')
                s[i]++;
            s[i] += s[i-1];
            b = c;
    }

    for(int i=0;i<q;i++){
        int a,b;
        cin>>a>>b;
        cout<<s[b] - s[a]<<endl;
    }

}

Measured memory_bytes: 1280
#include<algorithm>
#include<cassert>
#include<climits>
#include<cmath>
#include<cstring>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;

using lint = long long;
using P = pair<int, int>;
using LLP = pair<long long, long long>;

#define REP(i, x, n) for(int i = (x), i##_len = int(n) ; i < i##_len ; ++i)
#define rep(i, n) for(int i = 0, i##_len = int(n) ; i < i##_len ; ++i)
#define reps(i, n) for(int i = 1, i##_len = int(n) ; i <= i##_len ; ++i)
#define rrep(i, n) for(int i = int(n) - 1 ; i >= 0 ; --i)
#define rreps(i, n) for(int i = int(n) ; i > 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())
#define SORT_INV(x) sort((x).rbegin(), (x).rend())
#define TWINS(x) cout << ((x) ? "Yay!" : ":(") << endl

constexpr int IINF = (1 << 30) - 1;
constexpr long long LLINF = 1LL << 61;
constexpr double EPS = 1e-8;

const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

template<typename T>
bool chmax(T& a, T b, bool equal = false){
    if(a < b || equal && a == b){
        a = b;
        return true;
    }
    return false;
}

template<typename T>
bool chmin(T& a, T b, bool equal = false){
    if(b < a || equal && a == b){
        a = b;
        return true;
    }
    return false;
}

struct edge{
    int to;
    lint cost;
};

struct node{
    int id;
    lint cost;

    bool operator<(const node& rhs) const {
        return cost > rhs.cost;
    }
};

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

    int n, m, s, t;
    cin >> n >> m >> s >> t;
    --s;
    --t;

    vector< vector<edge> > g(n);
    rep(i, m){
        int a, b, c;
        lint d;
        cin >> a >> b >> c >> d;
        --a;
        --b;
        --c;
        g[a].push_back({b, d});
        g[b].push_back({a, d});
        g[b].push_back({c, d});
        g[c].push_back({b, d});
        g[c].push_back({a, d});
        g[a].push_back({c, d});
    }

    vector<lint> cost(n, LLINF);
    cost[s] = 0;
    priority_queue<node> que;
    que.push({s, 0LL});

    while(!que.empty()){
        node now = que.top();
        que.pop();
        if(cost[now.id] < now.cost){
            continue;
        }
        for(auto e : g[now.id]){
            if(chmin(cost[e.to], now.cost + e.cost)){
                que.push({e.to, now.cost + e.cost});
            }
        }
    }

    cout << cost[t] << endl;

    return 0;
}


Measured memory_bytes: 23692
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <functional>
#include <set>
#include <numeric>
#define ll long long int
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll M=1000010;

int main() {
	ll N, ans=0;
	set<int> st;

	cin >> N;
	vector <ll> a(N);
	rep(i,N) cin >> a[i];
	vector <ll> con(M);

	for(int i:a){
		if (con[i] != 0){
			con[i]=2;
			continue;
		}
		for (int k = i; k < M; k += i)	con[k]++;
	}

	for (int i : a){
		if (con[i] == 1)ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 12688
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vl = vector<ll>;  // long longの1次元の型に vl という別名をつける
using vvl = vector<vl>; // long longの2次元の型に vvl という別名をつける
int MOD = 1000000007; //10^9 + 7

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; }

// 無限大の値
const ll  lINF = 1LL << 60;
const int iINF = 1 << 29;

int main(void){
  int x,a,b;
  cin >> x >> a >> b;
  if(a-b>=0) cout << "delicious" << endl;
  else if(b-a>x) cout << "dangerous" << endl;
  else cout << "safe" << endl;
  return 0;
} 

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

uint64_t get_rand_range(uint64_t min_val, uint64_t max_val) {
    static std::mt19937_64 mt64(0);

    std::uniform_int_distribution<uint64_t> get_rand_uni_int( min_val, max_val );

    return get_rand_uni_int(mt64);
}
  
int main() {
  int D;
  cin >> D;
  
  for (int i = 0; i < D; i++) {
    int ans = get_rand_range(1, 26);
    cout << ans << endl;
  }
}

Measured memory_bytes: 3632
N,M = map(int,input().split())
numbers = []
money = 0
for i in range(M):
    a,b = map(int,input().split())
    numbers.append(a)
numbers.sort(reverse = True)
for j in range(M-1):
    if numbers[j] < N:
        money += N-numbers[j]
print(money)

        
    
    


Measured memory_bytes: 5616
#include<bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);
  
using namespace std;
 
const ll inf = 1e18;
const ll N = 1e5;
const ll bits = 62;
const ll mod = 1e9+7;
const ld pi = 3.14159265358979323846;

struct mons{
    ll h,x;

    bool operator < (mons other) const {
        return x < other.x;
    }
};

struct coord{
    ll x;
    ll a;

    bool operator < (coord other) const {
        return x > other.x;
    }
};


int main(){
    FASTIO;
    PRECISION;

    ll n,d,a;
    cin>>n>>d>>a;

    vector<mons>arr(n);

    for(int i=0;i<n;i++){
        cin>>arr[i].x>>arr[i].h;
    }

    sort(arr.begin(),arr.end());

    ll cx=-1,b=0;
    priority_queue<coord>pq;
    coord temp;

    ll ans = 0;


    for(int i=0;i<n;i++){
        // remove non overlapping bombs
        while(!pq.empty() && pq.top().x<arr[i].x){
            temp = pq.top();
            b-=temp.a;
            pq.pop();
        }

        arr[i].h-=b;

        // drop more bombs
        if(arr[i].h>0){
            ll req = arr[i].h / a;
            if(req*a<arr[i].h) req++;

            ans+=req;
            b+=req*a;

            // add new bomb
            temp.a = req*a;
            temp.x = arr[i].x + 2LL*d;

            pq.push(temp);
        }
        

    }

    cout<<ans<<"\n";

}

Measured memory_bytes: 5620
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>

using namespace std;

#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF (int)(1e9+10)
#define LLINF (lint)(1e18+10)

int solve(int a, int b, int c, int cnt){
    if(a%2 == 1 || b%2 == 1 || c%2 == 1){
        return cnt;
    }
    if(a == b && b == c){
        return -1;
    }
    return solve(a/2+b/2, b/2+c/2, c/2+a/2, cnt+1);
}

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int ans = solve(a, b, c, 0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    long[] a = new long[N];
    for (int i = 0; i < N; i++) {
      a[i] = scanner.nextLong();
    }

    int l = 0;
    long sum = 0;
    long xor = 0;
    long count = 0;
    for (int r = 0; r < N; r++) {
      sum += a[r];
      xor ^= a[r];
      if (sum == xor) {
        count += r - l + 1;
        continue;
      }
      while (sum != xor) {
        sum -= a[l];
        xor ^= a[l];
        l++;
      }
      count += r - l + 1;
    }

    System.out.println(count);
  }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>


template <class T> void chmin(T&a, const T&b) { a = min(a,b); }
template <class T> void chmax(T&a, const T&b) { a = max(a,b); }

const double EPS =1e-9;
const long INF =999999999;
const long MOD =1000000007; //10^9+7
#define PI 3.14159265258979

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

int fn(ll N){
	int counter=0;

	while(N!=0){
		N/=10;
		counter++;
	}
	return counter;
}

int main(void){
	ll N;
	int result;
	cin>>N;
	
	result=fn(N);
	
	for(ll i=2LL;i*i<=N;i++){
		if(N%i!=0) continue;
		ll B=N/i;

		chmin(result,max(fn(i),fn(B)));
	}

	cout<<result<<endl;

	return 0;
}



Measured memory_bytes: 256