akhauriyash/Code-Regression huggingface dataset:
#ifndef _TEMPLATE_ROOT
#define _TEMPLATE_ROOT
#include "bits/stdc++.h"
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define repl(i, a, b) for(ll i = a; i < (b); ++i)
#define repd(i, a, b) for(int i = a; i >= (b); --i)
#define repdl(i, a, b) for(ll i = a; i >= (b); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
#endif
#ifndef _TEMPLATE_IO
#define _TEMPLATE_IO

template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void writef(T ...tail) { write(tail...); cout << flush; }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }
template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  if (v.size()) {
    rep(i, 0, sz(v) - 1)
      out << v[i] << " ";
    out << v.back();
  }
  return out;
}
#endif
using namespace std;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

  int d, t, s;
  read(d, t, s);
  if (t * s >= d) write("Yes"); else write("No");
}



Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;

int main(){
  ll n; cin >> n;
  set<ll> a;

  bool ans = true;

  rep(i,n){
    ll x; cin >> x;
    if(a.count(x)) ans = false;
    a.insert(x);
  }

  if(ans) puts("YES");
  else puts("NO");

}

Measured memory_bytes: 9600
i=8;main(A,B,C,D){scanf("%1d%1d%1d%1d",&A,&B,&C,&D);while(i--)if(A+(i/4?-B:B)+(i/2%2?-C:C)+(i%2?-D:D)==7){char p[]={43,45};printf("%d%c%d%c%d%c%d=7\n",A,p[i/4],B,p[i/2%2],C,p[i%2],D);break;}}


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

using namespace std;

int MinCostTopDownDP(int source, int destination, int * height, vector<int> &Memo);


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

  vector<int> Memo(n, -1);
  cout << MinCostTopDownDP(0, n - 1, height, Memo) << endl;
  return 0;
}



int MinCostTopDownDP(int source, int destination, int * height, vector<int> &Memo) { // Memoized
  if (source < destination) {

    if (Memo[source] == -1) {
      
      if (source == destination - 1)
        return abs(height[source] - height[destination]);
      int min_cost = INFINITY;
      for (int i = 1; i <= 2; i++) {
        int this_route_min = MinCostTopDownDP(source + i, destination, height, Memo) + abs(height[source] - height[source + i]);
        min_cost = min(min_cost, this_route_min);
      }
      Memo[source] = min_cost;
    }
    return Memo[source];    
  }
  return 0;
}

Measured memory_bytes: 8832
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <iostream>
#define all(n) n.begin(),n.end()

using namespace std;
int main()
{
	set<string> nums;
	int n, i, k, j, h, len;
	string moto, mae="", ushiro="";
	scanf("%d", &n);
	for(i=0;i<n;i++){
		cin>>moto;
		len = moto.length();
		for(k = 1; k < len; k++){
			mae = moto.substr(0, k);
			ushiro = moto.substr(k, len-k);
			nums.insert(mae + ushiro);
			nums.insert(ushiro + mae);
			reverse(all(ushiro));
			nums.insert(mae + ushiro);
			nums.insert(ushiro + mae);
			reverse(all(mae));
			nums.insert(mae + ushiro);
			nums.insert(ushiro + mae);
			reverse(all(ushiro));
			nums.insert(mae + ushiro);
			nums.insert(ushiro + mae);
		}
		cout<<nums.size()<<endl;
		nums.clear();
	}
	return 0;
}

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

double A,B,X;

signed main()
{
  cin >> A >> B >> X;
  if(A*A*B/2 < X) { //台形
    double y = 2*X/(A*A) - B;
    double ans = atan((double)A/(B-y)) * 180 / Pi;
    ans = 90 - ans;
    printf("%.10f\n", ans);
  } else {
    double y = (double)2*X/(double)(A*B);
    double ans = atan((double)y/B) * 180 / Pi;
    ans = 90 - ans;
    printf("%.10f\n", ans);
  }
  return 0;
}


Measured memory_bytes: 512
n,q=map(int,input().split())

# 隣接グラフ
to=[[] for i in range(n)] 
ans=[0 for i in range(n)]


# 深さ優先探索(再帰)
def dfs(v, p=-1):
    global ans
    for u in to[v]:
        if u==p:
            continue
        ans[u]+=ans[v]
        dfs(u,v)

# 深さ優先探索(ループ)
def dfs2():
    global ans
    queue=list()
    visit=dict()

    queue.append(0)
    for v in queue:
        visit.setdefault(v,True)
        for u in to[v]:
            if u in visit:
                continue
            ans[u]+=ans[v]
            queue.append(u)

# 隣接グラフ作成
for _ in range(n-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    to[a].append(b)
    to[b].append(a)

for _ in range(q):
    p,x=map(int,input().split())
    p-=1
    ans[p]+=x

#dfs(0)
dfs2()

for i in ans:
    print(i)

Measured memory_bytes: 68940
import collections
n,m=map(int,input().split())
A=[]
for i in range(n):
    a=list(map(int,input().split()))
    for k in range(a[0]):
        A.append(a[k+1])
B=collections.Counter(A)
c=0
for j in B.keys():
    if B[j]==n:
        c+=1
print(c)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

typedef tuple<ll, ll, ll> T;

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

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;cin>>n;
    vector<ll> a(n);
    REP(i,n) cin>>a[i];
    ll ans=a[0];
    for(int i=0;i<n;i++){
        ans = gcd(a[i],ans);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
int cnt,s[16][16],n;
void func(int y,int x){
	if(cnt==n*n+1)
	;
	else if(s[y][x]==0){
		s[y++][x++]=cnt++;
		if(y>n)
			y-=n;
		if(x>n)
			x-=n;
		func(y,x);
	}
	else {
		y++;x--;
		if(y>n)
			y-=n;
		if(x<1)
			x+=n;
		func(y,x);
	}
}
int main(){
	while(1){
		std::cin>>n;
		for(int i=1;i<=n;i++)
			for(int j=1;j<=n;j++)
			s[i][j]=0;
		if(n==0)
			break;
		cnt=1;
		func(n/2+2,n/2+1);
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++)
			std::printf("%4d",s[i][j]);
			std::cout<<std::endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#!/usr/local/bin/ruby
i=gets.split

w=i[0].to_i
h=i[1].to_i
x=i[2].to_i
y=i[3].to_i
r=i[4].to_i

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

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

using ll = long long;

void solve(std::string S, std::string T){
    int cnt = 1e9;
    for(int i = 0;i < (S.size() - T.size()) + 1;i++){
        int current = 0;
        for(int j = 0;j < T.size();j++){
            if(S[i + j] != T[j])current++;
        }
        cnt = min(current, cnt);
    }
    cout<<cnt<<endl;
}

int main(){
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll MOD = 1e9+7;

#define vec     vector<int>
#define vecll   vector<ll>
#define vec2    vector<vector<int>>
#define vec2ll  vector<vector<ll>>
#define vpair   vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define vecst   vector<string>
#define vecb    vector<bool>

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mpair(v1, v2)    make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt((ok ? "Yes" : "No"));}
//----------------------------------------------------------------
#define bitrep(i, n)     for(ll i=0; i<(ll) (1<<n); i++)
#define bis(i, j)        i & (1<<j)

int main(void) {
  ll n, m, x;
  cin >> n >> m >> x;
  ll c[n];
  ll a[n][m];
  rep(i,n){
    cin >> c[i];
    rep(j,m){
      cin >> a[i][j];
    }
  }

  ll ans=1e10;
  bitrep(i, n){
    ll cost=0;
    bool ok=true;
    vecll rikai(m,0);
    rep(j, n){
      if(bis(i,j)){
        cost+=c[j];
        rep(k,m){
          rikai[k] += a[j][k];
        }
      }
    }
    rep(k,m){
      if(rikai[k]<x) ok=false;
    }
    if(ok) chmin(ans, cost);
  }

  prt(ans>1e9 ? -1 : ans);

}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N;
    scanf("%d",&N);
    int A=0;
    bool OK=1;
    for(int i=0;i<N;i++) {
        string S;
        cin>>S;
        if(S=="A") A++;
        if(S=="Un") {
            if(A==0) OK=0; else A--;
        } 
    }
    if(A==0&&OK) printf("YES\n"); else printf("NO\n");
}

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

typedef pair<int,int> P;
int main(){
  int W,H,N;
  cin >> W >> H >> N;


  P p[1001];
  for(int i=0; i<N; i++){
    cin >> p[i].first >> p[i].second;
  }

  int x = p[0].first , y = p[0].second;

  int ans = 0;
  for(int i=1; i<N; i++){
    int x2 = p[i].first, y2 = p[i].second;

    if(x <= x2 && y <= y2){
      int diff = min(abs(x-x2),abs(y-y2));
      x += diff;
      y += diff;
      ans += diff;
    }

    else if(x >= x2 && y >= y2){
      int diff = min(abs(x-x2),abs(y-y2));
      x -= diff;
      y -= diff;
      ans += diff;
    }

    ans += abs(x - x2) + abs(y - y2);

    x = x2, y = y2;

  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1168
#include <set>
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <limits>
#include <map>
#include <numeric>

#define ll long long
using namespace std;
static ll imin = std::numeric_limits<ll>::min();
static ll imax = std::numeric_limits<ll>::max();
#define rep(i, n) for(int i = 0; i<n; ++i)
#define rep1(i, n) for(int i = 1; i<n; ++i)
#define debug(x) cout << #x << ":" << x << "\n";
#define all(v) v.begin(), v.end()

template<class T>
std::ostream& operator << (std::ostream& os, std::vector<T>& vec){
  std::size_t n = vec.size();
  if(n == 0){
    return os;
  }
  for(int i = 0; i<n - 1; ++i){
    os << vec[i] << " ";
  }
  os << vec[n - 1];
  os << std::endl;
  return os;
}
ll H, W;
vector<vector<ll>> s;
set<pair<ll, ll>> visited;
ll res = 0;
ll wc = 0, bc = 0;

inline bool is_visited(ll x, ll y){
  return visited.find(make_pair(x, y)) != visited.end();
}
ll visitFromBlack(ll x, ll y, ll accum);
ll visitFromWhite(ll x, ll y, ll accum){
  wc++;
  // cout << "W" << x << " " << y << endl;
  visited.insert(make_pair(x, y));
  if(x != 0 && !is_visited(x - 1, y) && s[x - 1][y] == 1){
    // cout << x - 1 << " " << y << endl;
    visitFromBlack(x - 1, y, accum);
  }
  if(y != 0 && !is_visited(x, y - 1) && s[x][y - 1] == 1){
    // cout << x << " " << y - 1 << endl;
    visitFromBlack(x, y - 1, accum);
  }
  if(x < H - 1 && !is_visited(x + 1, y) && s[x + 1][y] == 1){
    // cout << x + 1 << " " << y << endl;
    visitFromBlack(x + 1, y, accum);
  }
  if(y < W - 1 && !is_visited(x, y + 1) && s[x][y + 1] == 1){
    // cout << x << " " << y + 1 << endl;
    visitFromBlack(x, y + 1, accum);
  }
  return accum;
}
ll visitFromBlack(ll x, ll y, ll accum){
  // cout <<  "B" << x << " " << y << endl;
  visited.insert(make_pair(x, y));
  bc++;
  if(x != 0 && !is_visited(x - 1, y) && s[x - 1][y] == 0){
    // cout << x - 1 << " " << y << endl;
    visitFromWhite(x - 1, y, accum);
  }
  if(y != 0 && !is_visited(x, y - 1) && s[x][y - 1] == 0){
    // cout << x << " " << y - 1 << endl;
    visitFromWhite(x, y - 1, accum);
  }
  if(x < H - 1 && !is_visited(x + 1, y) && s[x + 1][y] == 0){
    // cout << x + 1 << " " << y << endl;
    visitFromWhite(x + 1, y, accum);
  }
  if(y < W - 1 && !is_visited(x, y + 1) && s[x][y + 1] == 0){
    // cout << x << " " << y + 1 << endl;
    visitFromWhite(x, y + 1, accum);
  }
  return accum;
}

#ifndef BOOST_TEST_MAIN
int main(int const argc, char const** argv){

  cin >> H >> W;
  s.resize(H);
  rep(x, H){
    s[x].resize(W);
  }
  rep(x, H){
    rep(y, W){
      char c;
      cin >> c;
      if(c == '#'){
        s[x][y] = 1;
      }else{
        s[x][y] = 0;
      }
    }
  }

  vector<vector<ll>> cs;
  
   rep(x, H){
    rep(y, W){
      if(s[x][y] == 1){
        // debug(s);
        // debug(x);
        // debug(y);
        // cout << "B" << endl;
        // for(auto && x:visited){
        //   cout << x.first << " " << x.second << endl;
        // }
        wc = 0;
        bc = 0;
        visitFromBlack(x, y, 0);
        // debug(p);
        res += wc * bc;
      }
    }
  }
  
  cout << res;
  
}
#endif


Measured memory_bytes: 21504
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int k;
    scanf("%d",&k);
    getchar();
    char str[1007];
    scanf("%s",str);
    int length =strlen(str);
    if(length<=k){
        printf("%s\n",str);
    }
    else{
        for (int i = 0; i < k; i++)
        {
            printf("%c",str[i]);
        }
        printf("...\n");
    }
    return 0;
}

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

using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, v) for(auto& a : v)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

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

ll big = 1000000007ll;
ll big2 = 1000000009ll;
ll n,m,q,T,k;

ll xm,ym;
ll xm2,ym2;

ll i1, i2;

vector<ll> X;
vector<ll> Y;

vector<ll> X2;
vector<ll> Y2;
vector<ll> ind;

bool comp(ll i, ll j){
return Y2[i] < Y2[j];
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);

    ll a,b,c,d;

    cin >> n;
    ll ma = 0;
    for(ll c1 = 0; c1 < n; c1++){
        cin >> a >> b;
        X.push_back(a);
        Y.push_back(b);
        if(max(a,b) > ma){
            ma = max(a,b);
            i1 = c1;
        }
    }

    if(n == 1){
        cout << "0\n";
    }
    else{
        ll mi = big*big;
        for(ll c1 = 0; c1 < n; c1++){
            if(min(X[c1] , Y[c1]) < mi && c1 != i1){
                mi = min(X[c1] , Y[c1]);
                i2 = c1;
            }
        }

        ll ans = big*big;

        xm = max(X[i1],Y[i1]);
        if(xm == X[i1]){
            ym = Y[i1];
        }
        else{
            ym = X[i1];
        }

        ym2 = min(X[i2],Y[i2]);
        if(ym2 == X[i2]){
            xm2 = Y[i2];
        }
        else{
            xm2 = X[i2];
        }

        ll xmin,xmax,ymin,ymax;
        xmin = min(xm,xm2);
        xmax = max(xm,xm2);
        ymin = min(ym,ym2);
        ymax = max(ym,ym2);

        for(ll c1 = 0; c1 < n; c1++){
            if(c1 != i1 && c1 != i2){
                ll x = max(X[c1],Y[c1]);
                ll y = min(X[c1],Y[c1]);
                xmin = min(xmin,x);
                xmax = max(xmax,x);
                ymin = min(ymin,y);
                ymax = max(ymax,y);

            }
        }

        ans = min(ans , (xmax-xmin) * (ymax-ymin));


        ll temp = xm2;
        xm2 = ym2;
        ym2 = temp;
        xmin = min(xm,xm2);
        xmax = max(xm,xm2);
        ymin = min(ym,ym2);
        ymax = max(ym,ym2);

        for(ll c1 = 0; c1 < n; c1++){

            if(c1 != i1 && c1 != i2){
                ind.push_back(ind.size());
                X2.push_back(max(X[c1],Y[c1]));
                Y2.push_back(min(X[c1],Y[c1]));
            }

        }

        sort(all(ind),comp);

        for(ll c1 = 0; c1 < n-2; c1++){
            ll x = X2[c1];
            ll y = Y2[c1];
            ymax = max(ymax, y);
        }

        ll oldy = ymin;

        for(ll c1 = 0; c1 < n-2; c1++){
            ymin = min(Y2[ind[c1]],oldy);
            ans = min(ans, (xmax-xmin) * (ymax-ymin));
            ymax = max(ymax, X2[ind[c1]]);
            oldy = min(oldy , X2[ind[c1]]);
        }

        cout << ans << "\n";

    }

    return 0;
}


Measured memory_bytes: 9572
a,b=map(int,input().split())
l1=list(map(int,input().split()))

l2=list(sorted(l1,reverse=True))
suml=sum(l2)
#print(l2[1])

if suml<=4*b*l2[b-1]:
    #print(suml)
    #print(4*b*l2[b-1])

    print("Yes")
else:
    #print(suml)
    #print(4*b*l2[b-1])
    print("No")

Measured memory_bytes: 3060
N = int(input())
H = [int(x) for x in input().split()]
ans = 0
num = 0
for i in range(N-1):
  if(H[i]>=H[i+1]):
    num += 1
  else:
    ans = max(ans, num)
    num = 0
ans = max(ans, num)
print(ans)

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

int main()
{
	int n,m,p;
	int ta,tb,tc;
	int ans;
	int temp;
	long long int inf=1000000000;
	cin>>n>>m>>p;
	vector<int> dist(n,inf);
	dist[0]=0;
	vector<vector<pair<int,int>>> graph(n);
	for (int i = 0; i < m; i++) {
		cin>>ta>>tb>>tc;
		graph[ta-1].push_back(make_pair(tb-1,-(tc-p)));
	}
	for (int i = 0; i < 2*n; i++) {
		for (int j = 0; j < n; j++) {
			for (int k = 0; k < graph[j].size(); k++) {
				if (dist[j]!=inf&&dist[j]+graph[j][k].second<dist[graph[j][k].first]) {
					dist[graph[j][k].first]=dist[j]+graph[j][k].second;
					if (i>=n) {
						dist[graph[j][k].first]=-inf;
					}
				}
			}
		}
	}
	if (dist[n-1]==-inf) {
		ans=-1;
	}else if (dist[n-1]>0) {
		ans=0;	
	}else {
		ans=-dist[n-1];
	}
	cout<<ans<<endl;
}

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

using namespace std;

typedef long long ll;

int main() {
  ll n,a,b;
  scanf("%lld%lld%lld",&n,&a,&b);
  if ((a^b)&1) printf("%lld\n",(b-a-1)/2+min(a,n-b+1));
  else printf("%lld\n",(b-a)/2);
  return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 200200;

#define PI acos(-1)
typedef long long ll;
#define INF 0x3f3f3f3f
int mod = 1000000007;
typedef pair<int, int> pii;
pii rec[N];
int ans[N];
int main()
{
	//freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	 // freopen("output.txt", "w", stdout);
	int n;
	while (~scanf("%d", &n))
	{
		for (int i = 1; i <= n; i++)
		{
			int x;
			scanf("%d", &x);
			rec[i].first = x;
			rec[i].second = i;
		}
		sort(rec+1, rec + n + 1);
		int mid = (n)>>1;
		for (int i = 1; i <= n; i++)
		{
			int ix = rec[i].second;
			if (i <= mid)
				ans[ix] = rec[mid+1].first;
			else
				ans[ix] = rec[mid].first;
		}
		for (int i = 1; i <= n; i++)
			printf("%d\n", ans[i]);
	}
    return 0;
}

Measured memory_bytes: 4480
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b;
	cin>>a>>b;
	
	if(a*b<=0) cout<<"Zero"<<endl;
	else if(a>0&&b>0) cout<<"Positive"<<endl;
	else if(a<0&&b<0)
	{
		if(abs(a+b)%2==0) cout<<"Negative"<<endl;
		else cout<<"Positive"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
s = list(input())
mod = 2019
tot = [0]
ans = 0
dp = [0 for _ in range(2020)]
dp[0] = 1
for i in range(len(s)):
    nx = tot[i] + int(s[i])*(pow(10,(len(s)-i),mod))
    nx %= mod
    if dp[nx] != 0:
        ans += dp[nx]
    dp[nx] += 1
    tot.append(nx)
print(ans)

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  i64 n;
  cin >> n;
  if (n & 1) {
    cout << 0 << endl;
    return;
  }
  i64 cnt = 0;
  for (int i = 0; exp(5ll, i) * 10 <= n; i++) {
    cnt += n / (exp(5ll, i) * 10);
  }
  cout << cnt << endl;
}


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

#define MAX 256
int main(){
    int left[200];
    int right[200];
    int i,j;
    int digits;
    double log;
    char str[MAX], *tp;

    /* input */
    while (fgets(str,MAX,stdin) != NULL)
    {
        tp = strtok(str, " ");
        left[i] = atoi(tp);
        tp = strtok(NULL, "\n");
        right[i] = atoi(tp);
        i++;
    }

    for(j = 0; j < i; j ++)
    {
        log = log10(left[j] + right[j]);
        digits = log + 1;
        printf("%d\n",digits);
    }

    return 0;
}

Measured memory_bytes: 572
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
struct Edge{ll from, to, cost;};
struct node{ll cost, to;
  bool friend operator>(node a, node b){
    return a.cost>b.cost;
  }
};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}


ll N;
vector<llvec> e;
llvec d;

ll ind(ll i, ll j){
  if(i>j)swap(i, j);
  return (2*N-i)*(i-1)/2 + (j-i)-1;
}

ll dfs(ll s){
  d[s]=-10;
  ll ans = 0;
  rep(i, e[s].size()){
    if(d[e[s][i]]==-10){
      return -10;
    }else if(d[e[s][i]]==0){
      ll tmp = dfs(e[s][i]);
      if(tmp==-10){
        return -10;
      }
      ans =max(ans, tmp);
    }else{
      ans = max(d[e[s][i]], ans);
    }
  }
  d[s] = ans + 1;
  return d[s];
}

/**************************************
 ** A main function starts from here  **
 ***************************************/
int main(){
  cin >> N;
  vector<llvec> a(N);
  llvec count(N*(N-1)/2, 0);
  ll N2 = N*(N-1)/2;
  rep(i, N){
    a[i]=llvec(N-1);
    rep(j, N-1){
      cin >> a[i][j];
    }
  }

  e = vector<llvec>(N*(N-1)/2);
  
  rep(i, N){
    rep(j, N-2){
      e[ind(i+1, a[i][j])].push_back(ind(i+1, a[i][j+1]));
      count[ind(i+1, a[i][j+1])]++;
    }
  }
  set<ll> start;
  rep(i, N2){
    if(count[i]==0){
      start.insert(i);
      //cout << i << endl;
    }
  }

  d = llvec(N2, 0);
  ll ans = -1;
  for(auto ist: start){
    ll tmp = dfs(ist);
    if(tmp==-10){
      ans = -1;
      break;
    }
    ans = max(ans, tmp);
  }

  cout << ans;
  return 0;
}


Measured memory_bytes: 43264
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <string>
#include <cctype>
#include <cassert>
#include <memory>
#include <memory.h>
using namespace std;

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

int A[50010];
int B[50010];
int order[50010];
bool useR[50010];
bool useC[50010];

int main(){
  int r, c, q;
  while(cin >> r >> c >> q && (r || c|| q)){
    memset(useR, false, sizeof(useR));
    memset(useC, false, sizeof(useC));
    ll res = 0;
    rep(i, q){
      cin >> A[i] >> B[i] >> order[i];
    }
    rep(i, q){
      int d = q - 1 - i;
      if(!A[d]){
	// R
	if(useR[B[d]]) continue;
	useR[B[d]] = true;
	if(order[d]) res += c;
	r--;
      }else{
	//C
	if(useC[B[d]]) continue;
	useC[B[d]] = true;
	if(order[d]) res += r;
	c--;
      }
    }
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 0
import java.io.*;
import java.util.*;

class Main{
    public static void main(String[] args){
        solve();
    }

    public static void solve(){
        Scanner sc = new Scanner(System.in);
     	int n = sc.nextInt();   
     	int m = sc.nextInt();
     	long ans = 1;
     	long mod = (long)Math.pow(10, 9) + 7;
     	if(n==m){
     		for(int i=n;i>0;i--){
     			ans = ((ans * (long)i) % mod) * (long)i % mod;
     		}
     		ans = (ans * 2) % mod;
     	}
     	else if((int)Math.abs(n-m)==1){
     		for(int i=(int)Math.min(n, m);i>0;i--){
     			ans = ((ans * (long)i) % mod) * (long)i % mod;	
     		}
     		ans = (ans * (long)Math.max(n, m)) % mod;
     	}
     	else{
     		ans = 0;
     	}

     	System.out.println(ans);
    }
}

Measured memory_bytes: 23764
N, A, B, C, D = map(int, input().split())
S = input()

s = A
f = B
flag = True
if C < D:
    if '##' in S[A-1:C]:
        flag = False
    if '##' in S[B-1:D]:
        flag = False

else:
    if S[D - 2] == '#':
        if '...' not in S[B-2:D]:
            flag = False
    if '##' in S[A-1:C]:
        flag = False
ans = 'Yes' if flag else 'No'
print(ans)

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

typedef long long ll;
const int maxn=2e5+10;
int n,a[maxn];
ll sum[maxn],ans=1e18;

inline ll calc(ll a,ll b,ll c){
	return abs(2*sum[b]-sum[a-1]-sum[c]);
}
inline void work(int a,int b,ll&x,ll&xx){
	int l=a,r=b;
	while(l<r){
		int midl=(l+l+r)/3,midr=(l+r+r+2)/3;
		if(calc(a,midl,b)<calc(a,midr,b))
			r=midr-1;
		else
			l=midl+1;
	}
	x=min(sum[b]-sum[l],sum[l]-sum[a-1]);
	xx=max(sum[b]-sum[l],sum[l]-sum[a-1]);
}

int main(){
	cin>>n;
	for(int i=1;i<=n;++i){
		cin>>a[i];
		sum[i]=sum[i-1]+a[i];
	}
	for(int i=2;i+2<=n;++i){
		ll x[4]={};
		work(1,i,x[0],x[1]);
		work(i+1,n,x[2],x[3]);
		sort(x,x+4);
		ans=min(ans,x[3]-x[0]);
	}
	cout<<ans<<endl;
	return 0;
}


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

int main() {
int n,k;
cin >> n >> k;
if(n%k==0) cout << 0<< endl;
else cout << 1<< endl;
}
  


Measured memory_bytes: 256
import itertools as it
H,W,K =map(int,input().split())
C =[]
sharph =[]
sharpw=[]
for i in range(H):
    ci =list(input())
    C.append(ci)
    sharph.append(ci.count("#"))
    
for i in range(W):
    sharpw.append(0)
    for j in range(H):
        if C[j][i] == "#":
            sharpw[i] += 1
sumC =sum(sharpw)

count =0
for h,w in it.product(range(2**H ), range(2**W)):
    a,b,double =0,0,0
    for i in range(H):
        a += int(format(h ,"06b")[- i-1])*sharph[i]
    for j in range(W):
        b += int(format(w ,"06b")[-j -1])*sharpw[j]
    for c,d in it.product(range(1,H+1),range(1,W+1)):
        if int(format(h ,"06b")[- c])== 1and int(format(w ,"06b")[- d]) ==1:
            if C[c-1][d-1] =="#":
                double += 1
    if sumC - a -b + double ==K:
        
        count +=1
    
        

            
print(count)


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

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

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

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

int main(){
    int N;
    cin >> N;

    if (N % 10 == 7 || N / 10 % 10 == 7 || N / 100 % 10 == 7) {
        puts("Yes");
    } else {
        puts("No");
    }
}

Measured memory_bytes: 3636
import math
import queue
import bisect
import heapq
import time
import itertools

mod = int(1e9+7)

def swap(a,b):
    return (b,a)

def gcd(a,b): #最大公約数
    if (a<b):
        a,b = swap(a,b)
    if (b==0):
        return a
    else:
        return gcd(b,a%b)

def divisors(a): # 約数列挙
    divisors = []
    for i in range(1,int(a**0.5)+1):
        if a%i==0:
            divisors.append(i)
            if i!=a//i:
                divisors.append(a//i)
    return divisors

def is_prime(a): #素数判定
    if a<2:
        return False
    elif a==2:
        return True
    elif a%2==0:
        return False
    sqrt_num = int(a**0.5)
    for i in range(3,sqrt_num+1,2):
        if a%i==0:
            return False
    return True

def prime_num(a): #素数列挙
    pn = [2]
    for i in range(3,int(a**0.5),2):
        prime = True
        for j in pn:
            if i%j==0:
                prime = False
                break
        if prime:
            pn.append(i)
    return pn

def main():
    a,op,b = input().split()
    if op=='+':
        print(int(a)+int(b))
    else:
        print(int(a)-int(b))
    return

if __name__=='__main__':
    main()

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

int main() {
  int N;
  cin >> N;

  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  vector<int> B(N);
  for (int i = 0; i < N; i++) cin >> B.at(i);
  vector<int> C(N);
  for (int i = 0; i < N; i++) cin >> C.at(i);

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

  long long ans = 0;
  for (int i = 0; i < N; i++) {
    long long a = lower_bound(A.begin(), A.end(), B.at(i)) - A.begin();
    long long b = C.end() - upper_bound(C.begin(), C.end(), B.at(i));
    ans += a * b;
  }

  cout << ans << endl;
}

Measured memory_bytes: 1408
def main(k):
    size, res = 1, 7 % k
    while res and size <= 1_000_000:
        res = (res * 10 + 7) % k
        size += 1
    return -1 if size > 1_000_000 else size


if __name__ == '__main__':
    k = int(input())
    print(main(k))


Measured memory_bytes: 9164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define mem(x,v) memset(x,v,sizeof(x))
#define Rep(i,a,b) for(register int i=(a);i<=int(b);++i)
#define rep(i,a,b) for(register int i=(a);i<int(b);++i)
#define Dep(i,a,b) for(register int i=(a);i>=int(b);--i)
#define gc getchar
#define pc putchar
#define fi first
#define se second
inline ll read(){
    ll x=0,f=1;char c=gc();
    for(;!isdigit(c);c=gc())if(c=='-')f=-1;
    for(;isdigit(c);c=gc())x=(x<<1)+(x<<3)+(c^48);
    return x*f;
}
inline void write(ll x){if(x<0)x=-x,pc('-');if(x>=10)write(x/10);putchar(x%10+'0');}
inline void writeln(ll x){write(x);pc('\n');}
inline void wri(ll x){write(x);pc(' ');}
const int maxn = 5500;
ll c[maxn],f[maxn],ans;
int vis[maxn];
int n,a[maxn];
ll A,B,C;
ll query(int x){
    ll ans = 1ll<<60;
    Rep(i,1,x) ans=min(ans,c[i]);
    return ans;
}
void add(ll x,ll v){
    c[x] = v;
}
void modify(ll x,ll C,ll T){
    Rep(i,x+1,n) if(vis[i] <= T)
        c[i] += C;
}
int main(){
//    freopen("A.in","r",stdin);
//    freopen("A.out","w",stdout);
    n = read(),A = read(),B = read();
//    writeln(A);
//    writeln(B);
//    if(A<=B) return 0;
    Rep(i,1,n) a[i] = read();
    if(A>B){
        swap(A,B);
        reverse(a+1,a+1+n);
        Rep(i,1,n) a[i] = n-a[i]+1;
    }
    C = min(A,B);assert(C==A);
    ans = 1ll << 60;
    Rep(i,1,n) vis[a[i]] = i;
    Rep(i,1,n){//A是右移，B是左移 
        f[i] = min((i - 1) * A,query(a[i]) + i * C - C);
        modify(a[i],B - C,i);
        c[a[i]] = f[i] - i * C;
        ans = min(ans,f[i] + B * (n - i));
    }writeln(ans);
    return 0;
}
//f[3] = f[2]
//[3,4,6,9]

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(){
    int a;
    int b;
    
    cin>>a;
    cin>>b;
  if(a<b){cout<<"a < b"<<endl;} 
  else if(a>b) {cout<<"a > b"<<endl;}
  else {cout<<"a == b"<<endl;}
  
  
 
  
  

  
  
  
  
 
     
    
    
   
   
   return 0;
}



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

using namespace std;

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

int main(){
  int n, Q;
  cin >> n >> Q;
  vector<uint64_t> c(n);
  vector<vector<int> > e(n);
  REP(i, n - 1){
    int a, b;
    cin >> a >> b;
    --a, --b;
    e[a].push_back(b), e[b].push_back(a);
  }
  REP(i, Q){
    int a, b;
    cin >> a >> b;
    --a;
    c[a] += b;
  }
  vector<uint64_t> r(n);
  queue<pair<int, int> > q;
  q.push(make_pair(0, -1));
  while(!q.empty()){
    int x, b;
    tie(x, b) = q.front();
    q.pop();
    if(b == -1){
      r[x] = c[x];
    }else{
      r[x] = c[x] + r[b];
    }
    for(auto y: e[x]) if(y != b){
      q.push(make_pair(y, x));
    }
  }
  REP(i, n){
    if(i > 0){
      cout << ' ';
    }
    cout << r[i];
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 18676
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
char q[101][101];
int n, m;
int d[4] = { 0,1, 0, -1 };
int s[4] = { 1, 0, -1, 0 };
void dfs(int x, int y, char c){
	q[x][y] = '1';
	for (int i = 0; i < 4; i++){
		int nx = d[i] + x;
		int ny = s[i] + y;
		if (0 <= nx <= n && 0 <= ny <= m&&q[nx][ny] == c){ dfs(nx, ny, q[nx][ny]); }
	}
}
int main(){
	

	while (1){
		int res = 0;
		cin >> n >> m;
		if (n == 0 && m == 0)break;
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= m; j++){
				cin >> q[i][j];
			}
			getchar();
		}
		for (int i = 1; i <= n; i++){
			for (int j = 1; j <= m; j++){
				if (q[i][j] != '1'){ 
					dfs(i, j, q[i][j]); res++;
				}
			}
		}
		cout << res << endl;

	}
	return 0;
}

Measured memory_bytes: 1636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

#define int ll

#define _GLIBCXX_DEBUG

#define REP(i,n) for (int i = 0; i < (n); ++i)
#define REPD(i,n) for (int i = (n-1); i >= 0; --i)
#define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define debug(x) cerr << #x << ": " << x << '\n'
#define hyphen() cerr << "--\n"

#define ALL(vec) (vec).begin(), (vec).end()
#define REVALL(vec) (vec).rbegin(), (vec).rend()

#define fst first
#define pb push_back

const int MOD = (int)1e9 + 7;
const int INF = numeric_limits<int>::max();

signed main() {
    int A, B, X;

    cin >> A >> B >> X;

    int ans;
    if (A == 0) {
        ans = (B / X) + 1;
    } else {
        ans = (B / X) - (A-1) / X;
    }
    cout << ans << endl;

}


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

const int STEP_NUM = 4;
const int STEP[STEP_NUM][STEP_NUM] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};

const int MAX_SIZE = 1000;
char field[MAX_SIZE + 1][MAX_SIZE + 1];

const int MAXN = 10;
int locationsX[MAXN];
int locationsY[MAXN];
 
int H, W, N;

int get_shortest_distance(int current_HP)
{
	int sx = locationsX[current_HP-1];
	int sy = locationsY[current_HP-1];
	int ex = locationsX[current_HP];
	int ey = locationsY[current_HP];

	bool is_visit[H + 1][W + 1];
	for(int i=0;i<H;i++)
		for(int j=0;j<W;j++)
			is_visit[i][j]=false;

	std::set<std::pair<int,int>> frontier;
	frontier.insert(std::pair<int,int>{sx,sy});
	for(int step=0;step<100000000;step++)
	{
		for(auto p:frontier)
		{
			if(p.first==ex && p.second==ey)	return step;
			is_visit[p.first][p.second] = true;
		}
		std::set<std::pair<int,int>> next_frontier;
		for(auto p:frontier)
		{
			for(int i=0;i<STEP_NUM;i++)
			{
				int nx = p.first+STEP[i][0];
				int ny = p.second+STEP[i][1];
				if(nx<0 || H<=nx) 		continue;
				if(ny<0 || W<=ny) 		continue;
				if(field[nx][ny]=='X') 	continue;
				if(is_visit[nx][ny]) 	continue;
				next_frontier.insert(std::make_pair(nx,ny));
			}
		}
		frontier = next_frontier;
	}
	return -1;
}

int solve()
{
	int total_step = 0;
	for(int i=1;i<N+1;i++)
		total_step += get_shortest_distance(i);
	return total_step;
}

int main()
{
	scanf("%d %d %d", &H, &W, &N);
	for(int i=0; i<H; i++)
		scanf("%s", field[i]);
	for(int i=0; i<H; i++)
		for(int j=0; j<W; j++)
		{
			int HP=-1;
			if(field[i][j]=='S')	HP=0;
			if(field[i][j]=='1')	HP=1;
			if(field[i][j]=='2')	HP=2;
			if(field[i][j]=='3')	HP=3;
			if(field[i][j]=='4')	HP=4;
			if(field[i][j]=='5')	HP=5;
			if(field[i][j]=='6')	HP=6;
			if(field[i][j]=='7')	HP=7;
			if(field[i][j]=='8')	HP=8;
			if(field[i][j]=='9')	HP=9;
			if(HP!=-1)
			{
				locationsX[HP]=i;
				locationsY[HP]=j;
			}
		}
	printf("%d\n", solve());
	return 0;
}

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

#define int long long

inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') f = -1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
	return x * f;
}

const int N = 3005;
const int P = 998244353;
int f[N];

signed main()
{
	int n = read(), s = read();
	f[0] = 1;
	for (int i = 1; i <= n; ++i)
	{
		int x = read();
		for (int i = s; i >= 0; --i)
		{
			if (i + x <= s) (f[i + x] += f[i]) %= P;
			(f[i] *= 2) %= P;
		}
	}
	printf("%d\n", f[s]);
	
	return 0;
}


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

long _gcd(long  b,long r);

int main(void) {

	long    A,B;

	scanf("%ld %ld",&A,&B);

	if(A>B) printf("\n %lld",(long long)A*B/_gcd(A,B));
	else    printf("\n %lld",(long long)A*B/_gcd(B,A));

	return 0;
}

// 最大公約数
long _gcd(long b,long r) {
	if(!r) return(b);
	return (_gcd(r,b%r));
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
#define out(n) cout << (n) << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    string s; cin >> s;
    int x, y;
    cin >> x >> y;

    vector<int> vx,vy;
    int tcount = 0;
    int fcount = 0;
    REP(i,s.size()+1) {
        if (i == s.size() || s[i] == 'T') {
            if (tcount % 2 == 0) vx.push_back(fcount);
            else vy.push_back(fcount);
            tcount++;
            fcount = 0;
        } else {
            fcount++;
        }
    }

    vector<map<int,bool>> dpx(vx.size()+1),dpy(vy.size()+1);
    dpx[0][0] = true;
    dpy[0][0] = true;
    
    REP(i,vx.size()) {
        for(auto m:dpx[i]) {
            dpx[i+1][m.first+vx[i]] = true;
            if (i != 0) dpx[i+1][m.first-vx[i]] = true;
        }
    }

    REP(i,vy.size()) {
        for(auto m:dpy[i]) {
            dpy[i+1][m.first+vy[i]] = true;
            dpy[i+1][m.first-vy[i]] = true;
        }
    }
    
    ATYN(dpx[vx.size()][x] && dpy[vy.size()][y])

    return 0;
}

Measured memory_bytes: 232320
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
const ll mod = (ll)(1e9) + 7;

enum ntype {
	OR, ALT, MATERIAL,
};

struct node_t {
	ntype t;
	int op;
};

vector<node_t> nodes;
vector<int> to_edge[1005];
ll n;
ll ans[1005];

ll dfs(int v) {
	if (ans[v] != -1) return ans[v];
	
	ll ret;
	
	if (nodes[v].t == OR) {
		ret = 0;
		for (int i = 1; i < (1 << to_edge[v].size()); i++) {
			ll tmp = 1;
			ll ref = i;
			
			for (int j = 0; ref; j++) {
				if (ref & 1) {
					tmp *= dfs(to_edge[v][j]);
					tmp %= mod;
				}
				ref >>= 1;
			}
			
			ret += tmp;
			ret %= mod;
		}
	}
	else if (nodes[v].t == ALT) {
		ret = 0;
		for (int i = 0; i < to_edge[v].size(); i++) {
			ret += dfs(to_edge[v][i]);
			ret %= mod;
		}
	}
	else if (nodes[v].t == MATERIAL) {
		ret = 1;
		for (int i = 0; i < to_edge[v].size(); i++) {
			ret *= dfs(to_edge[v][i]);
			ret %= mod;
		}
	}
	
	return ans[v] = (ret + nodes[v].op) % mod;
}

int main() {
	cin >> n;
	nodes.resize(n + 1);
	
	for (int i = 0; i <= n; i++) {
		ans[i] = -1;
	}
	
	for (int i = 1; i <= n; i++) {
		string s;
		cin >> s;
		
		if (s[0] == 'E') {
			nodes[i].t = MATERIAL;
		}
		else if (s[0] == 'R') {
			nodes[i].t = OR;
		}
		else if (s[0] == 'A') {
			nodes[i].t = ALT;
		}
		
		if (s[1] == '?') {
			nodes[i].op = 1;
		}
	}
	
	for (int i = 1; i < n; i++) {
		ll s, t;
		cin >> s >> t;
		to_edge[s].push_back(t);
	}
	
	cout << dfs(1) << endl;
	
	return 0;
}


Measured memory_bytes: 3284
#include <iostream>

int main()
{
    int a, b;
    std::cin >> a >> b;

    const char *comparator =
        ( a < b ) ? "<" :
        ( a > b ) ? ">" :
        "==";
    std::cout
        << "a "
        << comparator
        << " b"
        << std::endl;
    return 0;
}

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

const int mod = 1000*1000*1000+7;

int N, M;

int cc[302][302][302];
int dp(int st, int c, int m) {
    if(m == 0) return st == N;
    int &ret = cc[st][c][m];
    if(ret != -1) return ret;

    ret = 1LL * c * dp(st, c, m - 1) % mod;
    if(c) ret += 1LL * st * dp(st + c, 0, m - 1) % mod, ret %= mod;
    if(c == 0) ret += 1LL * st * dp(st, c, m - 1) % mod, ret %= mod;
    if(st + c < N) ret += 1LL * (N - st - c) * dp(st, c + 1, m - 1) % mod, ret %= mod;
    return ret;
}

int main() {
    cin >> N >> M;
    memset(cc, -1, sizeof(cc));
    cout << dp(1, 0, M);
}


Measured memory_bytes: 107904
#include <iostream>
#include <string.h>
using namespace std;
char A[104],B[105],C[105];
int main()
{
    int a,b,c;
    int la,lb,lc;

    while(cin>>A>>B>>C)
    {
        int tmp;
        la=strlen(A);
        lb=strlen(B);
        lc=strlen(C);
        tmp=1;
        a=b=c=-1;
        while(1)
        {
            if(a==la)
            {
                cout<<"A"<<endl;
                break;
            }
            else if(b==lb)
            {
                cout<<"B"<<endl;
                break;
            }
            else if(c==lc)
            {
                cout<<"C"<<endl;
                break;
            }
            if(tmp==1)
            {
                  a++;
                tmp=A[a]-'a'+1;


            }
            else if(tmp==2)
            {
                 b++;
                tmp=B[b]-'a'+1;

            }
            else if(tmp==3)
            {
               c++;
                tmp=C[c]-'a'+1;

            }
        }
        //cout<<(a+b)*h/2<<endl;
    }
    return 0;
}
//China

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	//min(a,b)...a,bの小さいほう
	//max(a,b)...     大きいほう
	int a;
	int b;
	int c;
	int d;
	int e;
	std::cin >> a >> b;
	if (a % 3 == 0) {
		cout << "Possible" << "\n";
	}
	else if (b % 3 == 0) {
		cout << "Possible" << "\n";
	}
	else if ((a + b) % 3 == 0) {
		cout << "Possible" << "\n";
	}
	else {
		cout << "Impossible" << "\n";
	}
	
	std::cin >> e;
}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define bit(n) (1LL << (n))

typedef long long ll;

using namespace std;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n,i;
  cin>>n>>i;
  
  cout<<n-i+1;
  
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<set>
using namespace std;
int main()
{
	set<int> st;
	int n,x;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d",&x);
		if(st.count(x)==0)
			st.insert(x);
		else st.erase(x);
	}
	printf("%d\n",st.size());
	return 0;
}


Measured memory_bytes: 4992
#!/usr/bin/env python3
import sys


def two_pointers(N, S):
    end = 1
    start = 0
    max_length = 0

    while start < N:
        if end-start > N-end:
            break
        subword = S[start:end]
        if subword in S[end:]:
            max_length = max(max_length, len(subword))
            end += 1
        else:
            start += 1
            if start == end:
                end += 1
    return max_length


def solve(N: int, S: str):
    print(two_pointers(N, S))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto nm = readln.split.to!(int[]);
    auto N = nm[0];
    auto M = nm[1];
    int[][] ss;
    ss.length = M;
    foreach (i; 0..M) {
        auto ks = readln.split.to!(int[]);
        foreach (s; ks[1..$]) ss[i] ~= s-1;
    }
    auto ps = readln.split.to!(int[]);

    int r;
    foreach (x; 0..1<<N) {
        foreach (i; 0..M) {
            int c;
            foreach (s; ss[i]) if (x & (1<<s)) ++c;
            if (c%2 != ps[i]) goto ng;
        }
        ++r;
        ng:
    }

    writeln(r);
}

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


int main(){

    string s;
    int k;
    cin >> k;
    cin >> s;

    if(s.size() <= k){
        cout << s << endl;
    }
    else{
        for(int i = 0; i < k; i++) cout << s[i];

        cout << "..." << endl;
    }

    return 0;
}

Measured memory_bytes: 3628