akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
 
public class Main{
  
  public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    
    String ABCD = sc.next();
    char[] abcd = ABCD.toCharArray();
    
    int[] num =new int[4];
    for(int i = 0; i < abcd.length; i++){
      num[i] = Character.getNumericValue(abcd[i]);
    }
    
    
    if(num[0]+num[1]+num[2]+num[3]==7){
      System.out.println(num[0]+"+"+num[1]+"+"+num[2]+"+"+num[3]+"="+7);
    }else if(num[0]+num[1]+num[2]-num[3]==7){
      System.out.println(num[0]+"+"+num[1]+"+"+num[2]+"-"+num[3]+"="+7);
    }else if(num[0]+num[1]-num[2]-num[3]==7){
      System.out.println(num[0]+"+"+num[1]+"-"+num[2]+"-"+num[3]+"="+7);
    }else if(num[0]-num[1]-num[2]-num[3]==7){
      System.out.println(num[0]+"-"+num[1]+"-"+num[2]+"-"+num[3]+"="+7);
    }else if(num[0]-num[1]+num[2]-num[3]==7){
      System.out.println(num[0]+"-"+num[1]+"+"+num[2]+"-"+num[3]+"="+7);
    }else if(num[0]+num[1]-num[2]+num[3]==7){
      System.out.println(num[0]+"+"+num[1]+"-"+num[2]+"+"+num[3]+"="+7);
    }else if(num[0]-num[1]-num[2]+num[3]==7){
      System.out.println(num[0]+"-"+num[1]+"-"+num[2]+"+"+num[3]+"="+7);
    }else if(num[0]-num[1]+num[2]+num[3]==7){
      System.out.println(num[0]+"-"+num[1]+"+"+num[2]+"+"+num[3]+"="+7);
    }
      
  }  
}

Measured memory_bytes: 39448
#include <bits/stdc++.h>
#define intt long long
using namespace std;
int i,j;
vector<int>g[2050];
bool used[2050];
int level[2050];
vector<pair<int,int> >e;
int n,k,res=0;
void dfs(int node)
{
    used[node] = true;
    for ( int i : g[node] )
    {
        if ( !used[i] )
        {
            level[i] = level[node] + 1;
            if ( level[i] > k/2 )
                res++;
            dfs(i);
        }
    }
}
int main()
{
    cin >> n>> k;
    for ( i = 1; i < n ;i++ )
    {
        int x,y;
        cin >> x>> y;
        g[x].push_back(y);
        g[y].push_back(x);
        if ( k % 2 )
        {
            e.push_back({x,y});
        }
    }
    int ans = 1e9;
    if ( k % 2 )
    {
        for ( pair<int,int> i : e )
        {
            for ( j = 1;  j<= n ; j++ )
            {
                level[j]=used[j]=0;
            }
            res=0;
            used[i.first] = used[i.second] = true;
            dfs(i.first);
            dfs(i.second);
            ans = min(ans,res);
        }
        cout << ans << endl;
        return 0;
    }
    for ( i =1 ; i <= n; i++ )
    {
        for ( j = 1; j <= n ;j++ )
        {
            used[j] = false;
            level[j] = 0;
        }
        res=0;
        dfs(i);
        ans = min(ans,res);
    }
    cout << ans << endl;
}


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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
ll j5(ll a)
{
  return a*a*a*a*a;
}

int main()
{
  ll x;cin>>x;
  ll a,b;
  bool fin=false;
  for(a=0;a<=200;a++)
  {
    for(b=a;j5(a)-j5(b)<=1000000000;b--)
    {
      if(j5(a)-j5(b)==x)
      {
        cout<<a<<' '<<b<<endl;
        fin=true;
        break;
      }
    }
    if(fin)break;
  }
}



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

int main() {
  int N;
  cin >> N;
  vector<string> W(N);
  rep(i, N) cin >> W[i];
  bool check = true;
  rep(i, N-1){
    if (W[i][W[i].size()-1] != W[i+1][0]) check = false;
    else {
      for(int j=i+1; j<N; j++){
        if (W[i] == W[j]) check = false;
      }
    }
  }
  if (check) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<set>
#include<bitset>
#include<map>

#define fo(i,a,b) for(int i=a;i<=b;i++)
#define fd(i,a,b) for(int i=a;i>=b;i--)

using namespace std;

typedef long long LL;
typedef double db;

int get(){
	char ch;
	while(ch=getchar(),(ch<'0'||ch>'9')&&ch!='-');
	if (ch=='-'){
		int s=0;
		while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
		return -s;
	}
	int s=ch-'0';
	while(ch=getchar(),ch>='0'&&ch<='9')s=s*10+ch-'0';
	return s;
}

const int N = 17;
const int L = 32775;
const int INF = 2e+9;

int f[L][N],val[L];
int n,m;
struct edge{
	int x,y,l;
}e[N*N];
int d[N][N];

int main(){
	n=get();m=get();
	int sum=0;
	fo(i,1,m){
		e[i].x=get();e[i].y=get();e[i].l=get();
		sum+=e[i].l;
		d[e[i].x][e[i].y]=d[e[i].y][e[i].x]=e[i].l;
	}
	fo(t,1,(1<<n)-1){
		fo(i,1,m)
		if (((1<<(e[i].x-1))&t)>0&&((1<<(e[i].y-1))&t)>0)val[t]+=e[i].l;
	}
	fo(t,0,(1<<n)-1)fo(x,1,n)f[t][x]=-1;
	fo(t,1,(1<<(n-1))-1)
	if (t&1)f[t][1]=val[t];
	fo(t,1,(1<<n)-1)
		fo(x,1,n)
		if (f[t][x]>-1){
			int u=((1<<n)-1)^t;
			int p=u;
			for(;u;u=(u-1)&p)f[t^u][x]=max(f[t^u][x],f[t][x]+val[u|(1<<(x-1))]);
			fo(y,1,n)
			if ((t&(1<<(y-1)))==0&&d[x][y])f[t^(1<<(y-1))][y]=max(f[t^(1<<(y-1))][y],f[t][x]+d[x][y]);
		}
	printf("%d\n",sum-f[(1<<n)-1][n]);
	return 0;
}

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


/// File input & output /////
#define fRead(x)        freopen("x.txt","r",stdin)
#define fWrite(x)       freopen ("x.txt","w",stdout)

#define mt              make_tuple
#define ld              long double
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())


#define FASTIO        ios_base::sync_with_stdio(0);cin.tie(nullptr);




///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
    return a.second>b.second;
}

///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}



///.............................................................TEMPLATE................................................./////

int main()
{
    FASTIO;

    int t;

    cin >> t;

    cout << setprecision(40) << 2*PI*t << endl;






    return 0;
}



Measured memory_bytes: 3804
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, _s, n) for(int i = _s, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;

#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;

int main() {
  int a, b;
  cin >> a >> b;
  string ans = "";
  if(a <= b) {
    REP(i, b) { ans.push_back(a + '0'); }
  } else {
    REP(i, a) { ans.push_back(b + '0'); }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {

    int n, m;
    cin >> n >> m;
    string ans = (n > m) ? "safe" : "unsafe";
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
def solve():
    n = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    ans = 0
    for i in range(n):
        if A[i] >= B[i]:
            ans += B[i]
        elif A[i] + A[i + 1] >= B[i]:
            ans += B[i]
            A[i + 1] = A[i] + A[i + 1] - B[i]
        else:
            ans += A[i] + A[i + 1]
            A[i + 1] = 0
    print(ans)


solve()


Measured memory_bytes: 24200
#include <stdio.h>
#include <string.h>
int main()
{
    int c = 0;
    char w[11];
    char t[1001];
    char end[] = {"END_OF_TEXT"};
    scanf("%s", w);
    do
    {
        scanf("%s", t);
        if (strcmp(t, end) != 0)
        {
            for (int i = 0; i < strlen(t); i++)
            {
                if (t[i] >= 'A' && t[i] <= 'Z')
                {
                    t[i] = t[i] + 32;
                }
            }
            if (strcmp(w, t) == 0)
            {
                c = c + 1;
            }
        }
    } while (strcmp(t, end) != 0);
    printf("%d\n", c);
    return 0;
}


Measured memory_bytes: 2148
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
int editDistance(string x,string y){
  int n=x.length(),m=y.length();
  int INF=n+m;
  vector<vector<int> > dp(n+1,vector<int>(m+1,INF));
  for(int i=0;i<=n;i++) dp[i][0]=i;
  for(int i=0;i<=m;i++) dp[0][i]=i;
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      dp[i][j]=min(dp[i][j],dp[i-1][j]+1);
      dp[i][j]=min(dp[i][j],dp[i][j-1]+1);
      dp[i][j]=min(dp[i][j],dp[i-1][j-1]+(x[i-1]!=y[j-1]));
    }
  }
  return dp[n][m];
}
//END CUT HERE
signed main(){
  string s1,s2;
  cin>>s1>>s2;
  cout<<editDistance(s1,s2)<<endl;
  return 0;
}

/*
  verified on 2017/07/13
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_E&lang=jp
*/

Measured memory_bytes: 6788
#include <bits/stdc++.h>
#define int long long int
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x) cout<<#x<<" = "<<(x)<<endl
#define COUT(x) cerr<<#x<<" = "; cout<<(x)<<endl

struct edge { int to, cost; };

const int INF = 1e18;
const int MOD = 1e9+7;

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

   bool flag = true;
   for (int i = 0; i < n; i++) {
      if (a[i] % 2 == 1) {
         flag = false;
         break;
      }
   }

   if (flag) {
      cout << "second" << endl;
   } else {
      cout << "first" << endl;
   }

   return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main()
{
  int N;
  cin >> N;
  int button[N+10];
  for(int i=1; i<=N; i++) cin >> button[i];
  
  int cnt;
  int now=1;
  int flg=0;

  for(;;){
    now = button[now];
    cnt++;
    if(now==2){
      flg=1;
      break;
    }
    if(cnt>N) break;
  }
  if(flg==1) cout << cnt << endl;
  else cout << -1 << endl;
}

Measured memory_bytes: 640
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    P = list(int(input()) for _ in range(n))
    cnt = [0] * (n + 1)
    for p in P:
        cnt[p] = cnt[p - 1] + 1

    res = n - max(cnt)
    print(res)


if __name__ == '__main__':
    resolve()


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

vector<long long>calc_divisor(long long n){
    vector<long long>res;
    for(long long i=1LL;i*i<=n;i++){
        if(n%i==0){
            res.push_back(i);
            long long j=n/i;
            if(j!=i)res.push_back(j);
        }
    }
    sort(res.begin(),res.end());
    return res;
}

int main(){
    long long N,M;
    cin>>N>>M;
    vector<long long> div=calc_divisor(M);
    long long res=1;
    for(auto d:div){
        if(d*N<=M)res=max(res,d);

    }
    cout<<res<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
#define MOD 1000000007
int main() {
  string s;
  cin >> s;
  int n = s.length();
  int p = 13;
  int ten = 1;

  vector<vector<int>> dp(n + 1, vector<int>(13, 0));
  for(int i = n - 1; i >= 0; i--) {
    if(s[i] == '?') {
      for(int j = 0; j <= 9; j++) {
        int a = j * ten % p;
        if(i == n - 1) {
          dp[i][a] = 1;
          dp[i][a] %= MOD;
        } else {
          for(int k = 0; k < 13; k++) {
            dp[i][(a + k) % p] += dp[i + 1][k];
            dp[i][(a + k) % p] %= MOD;
          }
        }
      }
    } else {
      int a = (s[i] - '0') * ten % p;
      if(i == n - 1) {
        dp[i][a] = 1;
      } else {
        for(int k = 0; k < 13; k++) {
          dp[i][(a + k) % p] += dp[i + 1][k];
          dp[i][(a + k) % p] %= MOD;
        }
      }
    }
    ten *= 10;
    ten %= p;
  }
  cout << dp[0][5] << '\n';
  return 0;
}

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


int main(int argc, const char * argv[]) {
    
    int n;
    while (cin >> n) {
        
        cout << "3C"  << setfill('0') << setw(2) << ((n % 39 == 0) ? 39 : n % 39) << endl;
        
    }
    
    return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=((ll)n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=((ll)a);i<((ll)n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vl a(n);cin>>a;
    rep(i,n)a[i]-=i+1;
    sort(all(a));
    ll ans=0;
    rep(i,n)ans+=abs(a[i]-a[n/2]);
    puta(ans);
    return 0;
}

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

int main()
{
	int n;
	cin>>n;
	int arr[n][3];
	for(int i=0;i<n;i++)
		for(int j=0;j<3;j++)
			cin>>arr[i][j];
	vector<int> dpa(n);	
	vector<int> dpb(n);
	vector<int> dpc(n);
	//vector<int> dp(n);
	dpa[0]=arr[0][0];
	dpb[0]=arr[0][1];
	dpc[0]=arr[0][2];
	//dp[0]=max(max(dpa[0],dpb[0]),dpc[0]);
	for(int i=1;i<n;i++)
	{
		dpa[i]=arr[i][0]+max(dpb[i-1],dpc[i-1]);
		dpb[i]=arr[i][1]+max(dpa[i-1],dpc[i-1]);
		dpc[i]=arr[i][2]+max(dpb[i-1],dpa[i-1]);
	//	dp[i]=max(max(dpa[i],dpb[i]),dpc[i]);
	}
	
	cout<<max(max(dpa[n-1],dpb[n-1]),dpc[n-1]);;
}

Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;

typedef long long ll;

long long GCD(long long a, long long b){if(b==0)return a;return GCD(b,a%b);}

int main() {
    int A, P; cin >> A >> P;
    int sum = A * 3 + P;
    cout << (sum / 2) << endl;
}


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

#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY 200000

int **mat;
int n;

void dijkstra();

int main(){
  int i, j;
  int u, k, v, c;
  
  scanf("%d",&n);

  mat = (int **)malloc(n * sizeof(int *));
  for(i=0; i<n; i++){
    mat[i] = (int *)malloc(n * sizeof(int));
    for(j=0; j<n; j++)
      mat[i][j] = -1;
  }
  
  for(i=0; i<n; i++){
    scanf("%d%d",&u ,&k);
    
    for(j=0; j<k; j++){
      scanf("%d%d",&v ,&c);
      mat[u][v] = c;
    }
    
  }

  dijkstra();
  
  for(i=0; i<n; i++)
    free(mat[i]);
  free(mat);
  return 0;
}

void dijkstra(){
  int *color, *d;
  int mincost;
  int u,v;
  int sum=0;
  int i;
  
  color = (int *)malloc(n * sizeof(int));
  d = (int *)malloc(n * sizeof(int));

  for(i=0; i<n; i++){
    color[i] = WHITE;
    d[i] = INFTY;
  }

  d[0] = 0;

  while(1){
    mincost = INFTY;

    for(i=0; i<n; i++){
      if(color[i]!=BLACK && d[i]<mincost){
	mincost = d[i];
	u = i;
      }
    }

    if(mincost == INFTY)
      break;

    color[u] = BLACK;

    for(v=0; v<n; v++){
      if(color[v]!=BLACK && mat[u][v]!=-1){
	if(d[u] + mat[u][v] < d[v]){
	  d[v] = d[u] + mat[u][v];
	  color[v] = GRAY;
	}
      }
    }
  }

  for(i=0; i<n; i++){
    printf("%d %d\n",i,d[i]);
  }

  free(color);
  free(d);
}



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

using namespace std;
#define taskname "A"
#define pb  push_back
#define mp  make_pair
#ifndef LOCAL
#define cerr if(0)cout
#endif

typedef long double ld;
typedef long long ll;
typedef pair<int,int> ii;
const int maxn = 2e5 + 5;
const int mod = 1e9 + 7;
int n, a[maxn];
map<int,int> mmap;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
        freopen(taskname".INP", "r",stdin);
        freopen(taskname".OUT", "w",stdout);
    }
    cin >> n;
    for(int i = 1 ; i <= n ; ++i){
        cin >> a[i];
        mmap[a[i]]++;
    }
    bool ok = 1;
    int d = *max_element(a + 1 , a + n + 1);
    for(int i = 0 ; i <= d ; ++i){
        mmap[max(i , d - i)]--;
    }
    for(auto & c : mmap){
        if(c.second < 0)ok = 0;
        if(c.second > 0 && c.first < (d / 2 +d % 2) + 1){
            ok = 0;
        }
    }
    if(ok)cout << "Possible";
    else cout << "Impossible";
}


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

int R, C;
int a[10][10000];

int solve() {
    int res = 0;
    for (int i = 0; i < (1 << R); i++) {
        int tmp = 0;
        for (int j = 0; j < C; j++) {
            int column = 0;
            for (int k = 0; k < R; k++) {
                //0ならカウント
                column += (a[k][j] + 1 + ((i & (1 << k)) >> k)) % 2;
            }
            column = max(column,R-column);
            tmp += column;
        }
        res = max(res,tmp);
    }
    return res;
}

int main() {
    //各クエリに対する応答
    while(cin>>R>>C) {
        if (R == 0 && C == 0) break;
        for (int i = 0; i < R; i++) {
            for (int j = 0; j < C; j++) {
                a[i][j] = 0;
                cin >> a[i][j];
            }
        }
        
        cout << solve() << "\n";
    }
}


Measured memory_bytes: 3388
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	long long s = 0;
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= n;j++){
			for(int k = 1;k <= n;k++){
				s += __gcd(i, __gcd(j, k));
			}
		}
	}
	cout << s;
	return 0;
}
 

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define int long long
const int inf = 3e9 + 7;

void test_case(){
	int n; cin>>n;
	vector<int>dis1, dis2;
	for(int i=0;i<n;i++){
		int x, y; cin>>x>>y;
		dis1.push_back(x + y);
		dis2.push_back(x - y);
	}
	sort(dis1.begin(), dis1.end());
	sort(dis2.begin(), dis2.end());
	int x = dis1[n-1] - dis1[0];
	int y = dis2[n-1] - dis2[0];
	cout<<max(x, y)<<endl;
	
}
		
 
signed main(){
	IOS;
	int t=1, i=1; 
	//cin>>t;
	while(t--){
		//cout<<"Case #"<<i<<": ";
		test_case();
		i++;
	}
}


Measured memory_bytes: 6656
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)

A, B = map(int, input().split())
ans = -1
for x in range(1100):
    if int(x*0.08) == A and int(x*0.10) == B:
        ans = x
        break

print(ans)


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

using namespace std;

#define int long long
#define ar array
#define vt vector
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define sz(x) (int)(x).size()

#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)

template<class T>
bool umin(T &a, const T &b) {
    return b < a ? a = b, 1 : 0;
}

template<class T>
bool umax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

template<class A>
void read(vt<A> &v);

template<class A, size_t S>
void read(ar<A, S> &a);

template<class T>
void read(T &x) {
    cin >> x;
}

void read(double &d) {
    string t;
    read(t);
    d = stod(t);
}

void read(long double &d) {
    string t;
    read(t);
    d = stold(t);
}

template<class H, class... T>
void read(H &h, T &... t) {
    read(h);
    read(t...);
}

template<class A>
void read(vt<A> &x) {
    EACH(a, x)read(a);
}

template<class A, size_t S>
void read(array<A, S> &x) {
    EACH(a, x)read(a);
}

string to_string(char c) {
    return string(1, c);
}

string to_string(bool b) {
    return b ? "true" : "false";
}

string to_string(const char *s) {
    return string(s);
}

string to_string(string s) {
    return s;
}

string to_string(vt<bool> v) {
    string res;
    FOR(sz(v))res += char('0' + v[i]);
    return res;
}

template<size_t S>
string to_string(bitset<S> b) {
    string res;
    FOR(S)res += char('0' + b[i]);
    return res;
}

template<class T>
string to_string(T v) {
    bool f = 1;
    string res;
    EACH(x, v) {
        if (!f)
            res += ' ';
        f = 0;
        res += to_string(x);
    }
    return res;
}

template<class A>
void write(A x) {
    cout << to_string(x);
}

template<class H, class... T>
void write(const H &h, const T &... t) {
    write(h);
    write(t...);
}

void print() {
    write("\n");
}

template<class H, class... T>
void print(const H &h, const T &... t) {
    write(h);
    if (sizeof...(t))
        write(' ');
    print(t...);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n) {
    v = vt<T>(n, x);
}

template<class T, class U>
void vti(vt<T> &v, U x, size_t n, size_t m...) {
    v = vt<T>(n);
    EACH(a, v)vti(a, x, m);
}

void solve() {
    int n;
    string s;
    read(n, s);
    int ans = 0;
    int mx = 0;
    FOR(n) {
        ans += (s[i] == 'D') ? -1 : 1;
        mx = max(mx, ans);
    }
    print(mx);
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int tt = 1;
//    read(tt);
    FOR(tt) {
//        write("Case #", i + 1, ": ");
        solve();
    }
    
}



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

using namespace std;
using LL = long long;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e19;
const int MOD = (int)1e9 + 7;

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

    LL a, b, c;
    cin >> a >> b >> c;
    cout << b + min(c, a+b+1) << '\n';
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        String s = sc.next();
        String t = sc.next();
        int a = Integer.parseInt(sc.next());
        int b = Integer.parseInt(sc.next());
        String u = sc.next();
        
        if(s.equals(u)){
            System.out.println((a-1) + " " + b);
        }else{
            System.out.println(a + " " + (b-1));
        }
    }
}

Measured memory_bytes: 22612
N = int(input())
h = list(map(int,input().split()))
H = [0]*N
for i in range(1,N):
    if i == 1:
        H[i] = abs(h[1]-h[0])
    else:
        H[i] = min(H[i-1]+abs(h[i]-h[i-1]),H[i-2]+abs(h[i]-h[i-2]))
print(H[N-1])

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

int N;
int64_t K, A[100'000];
int64_t ans;

int main(){
    cin >> N >> K;
    for(int i=0;i<N;i++)    cin >> A[i];

    int64_t B = 0;
    for(int64_t i=1;i<=K;i=(i<<1)){
        int res = 0;
        for(int j=0;j<N;j++){
            if(A[j] & i)    res++;
        }
        if( (N+1)/2 > res ) B += i;
    }

    ans = 0;
    for(int64_t i=1;i<=K+1;i=(i<<1)){
        if((K+1) & i){
            int64_t X = K + 1 - i;
            X /= i;
            X *= i;
            X += B % i;
            int64_t res = 0;
            for(int j=0;j<N;j++)    res += X ^ A[j];
            ans = max(ans, res);
        }
    }

    cout << ans << endl;
}

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

using namespace std;

#define Rep(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(x)  (x).begin(), (x).end()
#define ll long long

ll n;
vector<char> c753 = { '3', '5', '7' };

ll dfs(string m) {
	if (stol(m.c_str()) > n)
		return 0;
	ll res = 1;
	for (char c: c753)
		if (m.find(c) == string::npos)
			res = 0;

	for (char c: c753)
		res += dfs(m + c);
	return res;
}

int main()
{
	cin >> n;

	cout << dfs("0") << endl;
}



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

int main() {
  ll N, ans = 0;
  cin >> N;
  for (int i = 2; i <= sqrt(N); i++) {
    if (N % i == 0) {
      int cnt = 0, t = 1;
      while (N % i == 0) {
        cnt++;
        N /= i;
        if (cnt == t) {
          ans++;
          t++;
          cnt = 0;
        }
      }
    }
  }
  cout << ans + (N > 1) << endl;
}

Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
#define ll long long
#define ld long double
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<ll> a(N+1), b(N);
	for(int i=0; i<=N; ++i) cin >> a[i];
	for(int i=0; i<N; ++i) cin >> b[i];
	ll ans=0;
	for(int i=0; i<N; ++i){
	    if(a[i]>b[i]){
	        ans += b[i];
	    }else{
	        ans += a[i];
	        b[i] -= a[i];
	        if(a[i+1]<=b[i]){
	            ans += a[i+1];
	            a[i+1]=0;
	        }else{
	            ans += b[i];
	            a[i+1] -= b[i];
	        }
	    }
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String s = scanner.next();
		long k = scanner.nextLong();
		for (char c: s.toCharArray()) {
			if (k==1) {
				System.out.println(c);
				break;
			}else if (c!='1'){
				System.out.println(c);
				break;
			}else k--;
		}
	}
}

Measured memory_bytes: 23124
red_p = []
blue_p = []
count = 0
n = int(input())
for i in range(n):
    a_ad, b_ad = map(int, input().split())
    red_p.append((a_ad, b_ad))
for i in range(n):
    c_ad, d_ad = map(int, input().split())
    blue_p.append((c_ad, d_ad))
red_p.sort(key = lambda x: x[1], reverse = True)
blue_p.sort()
for i in range(n):
    l = len(red_p)
    for k in range(l):
        if red_p[k][1] < blue_p[i][1] and red_p[k][0] < blue_p[i][0]:
            count += 1
            red_p = red_p[:k] + red_p[k+1:]
            break
print(count)


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

int main(){
  int h1, h2, k1, k2, a, b, c, d, H, K;

  cin >> h1 >> h2 >> k1 >> k2 >> a >> b >> c >> d;
  H = h1*a + (h1/10)*c + h2*b + (h2/20)*d;
  K = k1*a + (k1/10)*c + k2*b + (k2/20)*d;

  if ( H > K ) cout << "hiroshi" << endl;
  else if ( H < K ) cout << "kenjiro" << endl;
  else cout << "even" << endl;

  return 0;
}


Measured memory_bytes: 3120
import sys
input=lambda: sys.stdin.readline().rstrip()
k=int(input())
cur=0
for i in range(k):
  s=str(cur)
  n=len(s)
  if n<=1 or cur==10**n-1:
    cur+=1
  elif int(s[n-2])>=int(s[n-1]) and int(s[n-1])!=9:
    cur+=1
  elif int(s[n-2])>=int(s[n-1]) and int(s[n-1])==9:
    for j in range(n-1):
      if int(s[n-j-1])==9 or int(s[n-j-1])==int(s[n-j-2])+1:
        continue
      else:
        nn=j
        ret=s[:n-1-nn]
        ret+=str(int(s[n-1-nn])+1)
        break
    else:
      ret=str(int(s[0])+1)
      nn=n-1
    
    for j in range(nn):
      ret+=str(max(int(ret[-1])-1,0))
    cur=int(ret)
  else: 
    for j in range(1,n-1):
      if int(s[n-1-j-1])>=int(s[n-1-j]):
        nn=n-1-j
        ret=s[:nn]
        ret+=str(int(s[nn])+1)
        break
    else:
      nn=0
      ret=str(int(s[0])+1)
    for j in range(n-nn-1):
      ret+=str(max(int(ret[-1])-1,0))
    cur=int(ret)
print(cur)

Measured memory_bytes: 3188
#include <cstdio>

int main(){
    int n,m;
    for(;;){
        scanf("%d %d",&n,&m);
        if(n == 0 && m == 0){
            break;
        }
        int a[n];
        for(int i = 0; i < n; i++){
            scanf(" %d",&a[i]);
        }

        int max = 0;
        for(int i = 0; i < n; i++){
            for(int j = i + 1; j < n; j++){
                if(a[i] + a[j] <= m && a[i] + a[j] >= max){
                max = a[i] + a[j];
                }
            }
        }
        if(max != 0){
            printf("%d",max);
        }else{
            printf("NONE");
        }
        printf("\n");
    }

    return 0;
}


Measured memory_bytes: 2760
#include<iostream>

using namespace std;

char i_c(int m,int f,int r){
    if(m==-1 || f==-1){
        return 'F';
    }
    else if(m+f >=80){
        return 'A';
    }
    else if(m+f >=65 && m+f <80){
        return 'B';
    }
    else if(m+f >=50 && m+f <65){
        return 'C';
    }
    else if(m+f >=30 && m+f <50){
        if(r>=50){
            return 'C';
        }
        else{
            return 'D';
        }
    }
    else if(m+f <30){
        return 'F';
    }
}

int main(){
    while(1){
        int m,f,r;
        cin >> m >> f >> r;
        
        if(m== -1 && f== -1 && r== -1)break;
        
        char x=i_c(m,f,r);
        cout << x <<endl;
        
    }
    
    
    return 0;
}


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

int N,H,d[100000],h[100000],sum[100000];
signed main(){
    cin>>N>>H;
    rep(i,N-1)cin>>d[i]>>h[i];

    sum[0]=H;
    rep(i,N-1)sum[i+1]=sum[i]-d[i];
    int D=0;

    int ans=0,idx=0;
    deque<int>deq;
    rep(i,N-1){

        if(H-(sum[i]-D)<=h[i]){
            deq.clear();
            idx=i;
        }
        else{
            while(deq.size()&&h[deq.back()]<=h[i])deq.pop_back();
            deq.push_back(i);
        }

        while(sum[i+1]-D<=0){
            if(deq.size()&&H-(sum[idx]-D)<=h[deq.front()]){
                int j=deq.front();
                int t=min((H-(sum[j]-D))/h[j],(D-sum[i+1])/h[j]+1);
                ans+=t;
                D-=t*h[j];
            }
            else{
                ans++;
                D-=H-(sum[idx]-D);
            }
            while(deq.size()&&H-(sum[deq.front()]-D)<h[deq.front()]){
                    idx=deq.front();
                    deq.pop_front();
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3556
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function main()
  a,b=pM(split(readline()))
  s=chomp(readline())
  suu=['0','1','2','3','4','5','6','7','8','9']
  flag=true
  for i=1:a
    if !(s[i] in suu)
      flag=false
    end
  end
  if s[a+1] != '-'
    flag=false
  end
  for i=a+2:a+b+1
    if !(s[i] in suu)
      flag=false
    end
  end
  println(flag ? "Yes" : "No")
end
main()
if isdefined(Base, :mystdin);close(mystdin);end

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

void code()
{
    ll k,x;
    cin>>k>>x;
    if(k*500>=x)
    cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

}

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll t=1;
    // cin>>t
    while(t--)
    {
        code();
    }
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main{

    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] s = new int[N];
        int sum = 0;
        int count = 0;
        for(int i = 0; i < N; i++){
            s[i] = sc.nextInt();
            sum += s[i];
            if(s[i] % 10 == 0)
                count++;
        }
        sc.close();

        if(count == N){
            System.out.println(0);
        } else {
            if(sum % 10 != 0){
                System.out.println(sum);
            } else {
                Arrays.sort(s);
                int i = 0;
                while(s[i] % 10 == 0)
                    i++;
                System.out.println(sum - s[i]);
            }
        }
    }
}

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

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> vec(N);
    rep(i,N){
        cin >> vec[i];
    }
    int ans = 500000000;
    rep(i, N - K + 1){
        ans = min(ans, max(vec[i],-1 * vec[i]) + vec[i + K - 1] - vec[i]);
        ans = min(ans, max(vec[i + K - 1], -1 * vec[i + K - 1]) + vec[i + K - 1] - vec[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
int main(){
    int n,p;
    int odd = 0, even = 0;
    cin >> n >> p;
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        if(a%2 == 1)
            odd++;
        else
            even++;
    }
    ll ans = 0;
    if(odd == 0)
        ans += p == 0;
    else
        ans += 1LL<<(odd-1);
    ans *= 1LL<<even;
    cout << ans << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn = 310;
int a[maxn][maxn], f[maxn][maxn], vis[maxn];
int n, m, L;
//void dfs(int u, int nod, int res, int cnt) {
/*if (res >= 0) {
	f[u][nod] = cnt;//0x3f3f;
	//vis[nod] = 1;
}
else {
	f[u][nod] = ++cnt;
	res=L;
}
vis[nod] = 1;
for (int i = 1; i <= n; ++i) {
	if (vis[i] || a[nod][i] == 0)continue;
	dfs(u, i, res - a[nod][i], cnt);
}*/
struct dat {
	int id, cnt, res;
	dat() {};
	dat(int id, int cnt, int res):
		id(id), cnt(cnt), res(res) {};
};
bool operator < (dat a, dat b) {
	if (a.cnt != b.cnt) {
		return a.cnt < b.cnt;
	}
	else if (a.res != b.res) {
		return a.res > b.res;
	}
	return a.id < b.id;
}
void bfs(int id) {
	priority_queue<dat> Q;
	Q.push(dat(id, 0, L));
	dat u;
	for (int nod; !Q.empty();) {
		u = Q.top();
		nod = u.id;
		if (vis[nod])continue;
		vis[nod] = 1;
		f[id][nod] = u.cnt;
		Q.pop();
		for (int i = 1; i <= n; ++i) {
			if (vis[i] || a[nod][i] == 0)continue;
			if (u.res - a[nod][i] >= 0)Q.push(dat(i, u.cnt, u.res - a[nod][i]));
			else Q.push(dat(i, u.cnt + 1, L - a[nod][i]));
		}
	}
}
void solve() {
	scanf("%d%d%d", &n, &m, &L);
	memset(f, 0x3f, sizeof f);
	memset(a, 0x3f, sizeof a);
	for (int i = 1; i <= n; ++i)a[i][i] = 0;
	for (int i = 1, u, v, w; i <= m; ++i) {
		scanf("%d%d%d", &u, &v, &w);
		a[u][v] = a[v][u] = w;
	}
	for (int k = 1; k <= n; ++k)
		for (int i = 1; i <= n; ++i)
			for (int j = 1; j <= n; ++j)
				if (a[i][j] > a[k][j] + a[i][k]) {
					a[i][j] = a[k][j] + a[i][k];
				}
	for (int i = 1; i <= n; ++i) {
		//	memset(vis, 0, sizeof vis);
		//	bfs(i);
		//dfs(i, i, L, 0);
		for (int j = 1; j <= n; ++j) {
			if (a[i][j] <= L)f[i][j] = 1;
			//if(if()a[i][j]<=L)a[i][j]=1;
		}
	}
	for (int k = 1; k <= n; ++k)
		for (int i = 1; i <= n; ++i)
			for (int j = 1; j <= n; ++j)
				if (f[i][j] > f[i][k] + f[k][j]) {
					f[i][j] = f[i][k] + f[k][j];
					//if(f[i][k]==f[k][j])
				}
}
void query() {
	int Q, s, t;
	for (scanf("%d", &Q); Q--;) {
		scanf("%d%d", &s, &t);
		if (f[s][t] == f[0][0])puts("-1");
		else printf("%d\n", f[s][t] - 1);
	}
}
int main() {
	solve();
	query();
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,-1,sizeof(x))
const int INF = 1000000001;

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(a+b>=c) cout << "Yes"<<endl;
  else cout << "No" <<endl;
}

Measured memory_bytes: 256
/* author: Tarek */ 
#include <bits/stdc++.h>
using namespace std;
//typedef long long ll;
//typedef pair<int, int> pii;
//typedef pair<ll, int> pli;
//typedef pair<ll, ll> pll;
//typedef long double ld;
//#define mp make_pair
int main()
{
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
long long h;
cin>>h;
int sum = log2(h);
sum++;
cout<<(1LL*1<<sum)-1<<"\n";
return 0;
}



Measured memory_bytes: 256
#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 ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;

// ユーグリッド互除法
ll GCD(ll a, ll b)
{
  if(b == 0) return a;
  else return GCD(b, a % b);
}

// 最小公倍数
ll LCM(ll a, ll b)
{
  ll g = GCD(a,b);
  return a*(b/g);
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll a,b;
  cin >> a >> b;
  
  cout << LCM(a,b) << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
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 mod = 1000000007;
int dp[2010];
int main() {
    int n;
    cin >> n;
    dp[0] = 1;
    int x = 0;
    for(int i = 2;i<n;i++) {
        dp[i+1] = (dp[i-2] + x)%mod;
        x += dp[i-2];
        x %= mod;
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 3588
//written by libra9z
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cstring>
#include <cmath>
#include <cstdlib>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i,n) for (int i=0;i<(n);i++)
#define repit(it,a) for (__typeof(a.begin()) it=a.begin();it!=a.end();++it)
#define RET(p,x) return p<<x<<endl,0
#define all(a) (a).begin(),(a).end()
#define reunique(v) v.erase(unique(all(v)),v.end())
#define sz(a) (int)a.size()
#define sqr(x) ((x)*(x))
const int inf=1e9;
const ll lnf=1e18;
const int mod=1e9+7;
ll h,w;
string s[15];
string t[15];
bool ans;
void check()
{
	map <string,ll> cnt;
	rep(j,w)
	{
		string s;
		rep(i,h)
		{
			if (t[i][j]=='@') s+=t[h-1-i][j];
			else s+=t[i][j];
		}
		string t=s;
		reverse(all(t));
		cnt[min(s,t)]++;
	}
	bool flag=false;
	for (auto &p:cnt)
	{
		string s=p.first;
		string t=s;
		reverse(all(t));
		if (p.second%2==0) continue;
		if (s!=t) return;
		if (flag) return;
		flag=true;
	}
	ans=true;
}
void dfs(ll b,ll k)
{
	if (b==0)
	{
		check();
		return;
	}
	ll p=0;
	while (~b>>p&1) p++;
	t[k]=s[p];
	for (ll i=p+1;i<h;i++)
	{
		if (b>>i&1)
		{
			t[h-1-k]=s[i];
			dfs(b^(1<<p)^(1<<i),k+1);
		}
	}
}
int main()
{
	ios_base::sync_with_stdio(0);cin.tie();cout.tie();
	cout<<setprecision(15);
	cin>>h>>w;
	rep(i,h) cin>>s[i];
	if (h&1)
	{
		s[h]=string(w,'@');
		h++;
	}
	dfs((1<<h)-1,0);
	if (ans) cout<<"YES\n";
	else cout<<"NO\n";
	return 0;
}

Measured memory_bytes: 384
N, M, X, Y = map(int, input().split())
x = sorted(list(map(int, input().split())),reverse=True)
y = sorted(list(map(int, input().split())))

if x[0] > X and y[0] <= Y and y[0] > x[0]:
  print("No War")
else:
  print("War")

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

ll calc_two(ll x) {
  ll cnt = 0;
  while (x % 2 == 0) {
    x /= 2;
    cnt++;
  }
  return cnt;
}

int main(void) {
  ll n, m;
  cin >> n >> m;
  ll a[n];
  rep (i, n) {
    cin >> a[i];
    a[i] /= 2;
  }

  int num_2 = calc_two(a[0]);
  rep (i, n) {
    if (calc_two(a[i]) != num_2) {
      cout << 0 << endl;
      return 0;
    }
  }

  
  ll LCM = 1;
  rep (i, n) {
    LCM = LCM * a[i] / __gcd(a[i], LCM);
  }

  
  cout << m / LCM - m / (LCM * 2) << endl;
  return 0;
}

Measured memory_bytes: 1024
n=int(input())
#A,B,C=map(int,input().split())
S=[]
C={}
for a in range(n):
    s=input()
    if not s in C:
        C[s]=1
    else:
        C[s]+=1
A=[]
for a,b in C.items():
    A.append([b,a])
A.sort(key=lambda x:(-x[0],x[1]))
max_=A[0][0]
for a in A:
    if(a[0]!=max_):break
    print(a[1])
    
 
 

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

typedef long long int ll;
ll MOD = 1000000007;

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

  ll ans, i;
  if (s[0] == t[0]) {
    i = 1;
    ans = 3;
  } else {
    i = 2;
    ans = 6;
  }

  for (; i < s.size(); i++) {
    if (s[i] == t[i]) {
      if (s[i - 1] == t[i - 1])  // ||
        ans = ans * 2 % MOD;
      else  // =|
        ans = ans % MOD;
    } else {
      if (s[i - 1] == t[i - 1])  // |=
        ans = ans * 2 % MOD;
      else  // ==
        ans = ans * 3 % MOD;
      i++;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
const int MAXN=105;

int n;
int a[MAXN];

int main()
{
	scanf("%d",&n);
	int cnt=0,ans=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",a+i);
		if(a[i]==a[i-1])
			cnt++;
		else
			ans+=cnt/2,cnt=1;
	}
	ans+=cnt/2;
	printf("%d\n",ans);
	
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long ll;
typedef pair<ll,ll> P;


int d, p[11], c[11], g;

int dfs(int now, int sum, int cnt, bool used){
	if(sum >= g) return cnt;
	if(now == d) return INF;
	
	if(used){
		return min(dfs(now+1, sum, cnt, used), dfs(now+1, sum+(now+1)*p[now]+c[now], cnt+p[now], used));
	}
	int ans = min(dfs(now+1, sum, cnt, used), dfs(now+1, sum+(now+1)*p[now]+c[now], cnt+p[now], used));
	for(int i = 1; i < p[now]; i++){
		ans = min(ans, dfs(now+1, sum+(now+1)*i, cnt+i, 1));
	}
	return ans;
}

int main(){
	cin >> d >> g;
	g /= 100;
	for(int i = 0; i < d; i++){
		cin >> p[i] >> c[i];
		c[i] /= 100;
	}
	
	cout << dfs(0,0,0,0) << endl;
	
	return 0;
}

Measured memory_bytes: 256
n=int(input())
k=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(k[n-1])


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define Int int64_t

using namespace std;

int main() {
	int x[3];
	for (int i = 0; i < 3; ++i) { cin >> x[i]; }
	int K;
	cin >> K;

	while (K > 0 && x[0] >= x[1]) {
		x[1] *= 2;
		--K;
	}
	while (K > 0 && x[1] >= x[2]) {
		x[2] *= 2;
		--K;
	}

	if (x[0] < x[1] && x[1] < x[2]) { cout << "Yes\n"; }
	else { cout << "No\n"; }

	return 0;
}


Measured memory_bytes: 3632
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
template<typename T=ll>inline T in(istream&is=cin){T ret;is>>ret;return ret;}
template<typename T>inline auto vec2(typename vector<T>::size_type h,typename vector<T>::size_type w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}

int main()
{
    cout<<(char)(in<char>()+1)<<endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
	char str[200];
	int n,i;
	int count=0;
	scanf("%d",&n);
	getchar();
	for(i=0;i<n;i++){
		scanf("%c",&str[i]);
		getchar();
	}
//	printf("%s\n",str);
	for(i=0;i<n;i++){
		if(str[i]=='P'){
			count++;
			break;
		}
	}
	for(i=0;i<n;i++){
		if(str[i]=='W'){
			count++;
			break;
		}
	}
	for(i=0;i<n;i++){
		if(str[i]=='Y'){
			count++;
			break;
		}
	}
	for(i=0;i<n;i++){
		if(str[i]=='G'){
			count++;
			break;
		}
	}
	if(count==4){
		printf("Four\n");
	}
	else if(count==3){
		printf("Three\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
int main(){
  int N;
  std::cin >> N;
  std::vector<int> A(N), B(N), C(N-1);
  for(int& a: A){
    std::cin >> a;
    a--;
  }
  for(int& b: B){
    std::cin >> b;
  }
  for(int& c: C){
    std::cin >> c;
  }
  
  int sum = 0;
  for(int b: B){
  	sum += b;
  }
  for(int i=0; i<A.size() - 1; i++){
    if(A[i+1] - A[i] == 1){
      sum += C[A[i]];
    }
  }
  std::cout << sum << std::endl;
}

Measured memory_bytes: 256