akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define int long long
#define double long double
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, n) for (int i = 1; i <= (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define dump(x) cerr << #x " = " << (x) << endl
using vint=vector<int>;
using vvint=vector<vint>;
using pint=pair<int, int>;
using vpint=vector<pint>;
template<typename T> using priority_queue_rev=priority_queue<T, vector<T>, greater<T>>;
constexpr double pi = 3.1415926535897932384626433832795028;
constexpr int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T1, typename T2> bool chmax(T1 &a, const T2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> bool chmin(T1 &a, const T2 &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct Setup {
    static constexpr int PREC = 20;
    Setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N, A, B, C, D;
string S;
signed main() {
    cin >> N >> A >> B >> C >> D;
    A--, B--, C--, D--;
    cin >> S;
    for (int i = A + 2; i < C; i++) {
        if (S[i - 1] == '#' && S[i] == '#') {
            cout << "No" << endl;
            return 0;
        }
    }
    for (int i = B + 2; i < D; i++) {
        if (S[i - 1] == '#' && S[i] == '#') {
            cout << "No" << endl;
            return 0;
        }
    }
    if (C > D) {
        for (int i = B; i <= D; i++) {
            if (S[i - 1] == '.' && S[i] == '.' && S[i + 1] == '.') {
                cout << "Yes" << endl;
                return 0;
            }
        }
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 640
#include<stdio.h>
 int main()
 {
     int a,b,c,temp=0;
     scanf("%d %d %d",&a,&b,&c);
     if(a>=1 && a<=100 && b>=1 && b<=100 && c>=1 && c<=100)
     {temp=b;
     b=a;


     a=c;

     c=temp;}
     printf("%d %d %d",a,b,c);
 }


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

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

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

class Edge {
public:
    int next;
    int weight;
    Edge() {}
    Edge(int n, int w) {
	next = n;
	weight = w;
    }
    bool operator< (const Edge &a) const {
	return weight < a.weight;
    }
};

struct Info {
    int dist;
    int node;
    int time;
    Info() {}
    Info(int d, int n, int t) {
	dist = d;
	node = n;
	time = t;
    }
    bool operator< (const Info &a) const {
	return dist > a.dist;
    }
};

signed main() {
    int N, M, L, K, A, H;
    while (cin >> N >> M >> L >> K >> A >> H) {
	if (N == 0) break;

	bool hosp[100];
	memset(hosp, false, sizeof(hosp));

	rep(i, L) {
	    int num;
	    cin >> num;
	    hosp[num] = true;
	}

	vector<Edge> nexts[100];
	rep(i, K) {
	    int X, Y, T;
	    cin >> X >> Y >> T;
	    nexts[X].push_back(Edge(Y, T));
	    nexts[Y].push_back(Edge(X, T));
	}
	rep(i, N) {
	    sort(all(nexts[i]));
	}

	int minDist[100][105];
	rep(i, N) rep(j, M + 1) minDist[i][j] = INT_MAX;

	priority_queue<Info> q;
	q.push(Info(0, A, M));
	bool help = true;
	while (!q.empty()) {
	    Info info = q.top(); q.pop();
	    //cout << "node:" << info.node << " time:" << info.time << " dist:" << info.dist << endl;
	    if (info.node == H) {
		cout << info.dist << endl;
		help = false;
		break;
	    }
	    if (info.dist > minDist[info.node][info.time]) continue;
	    for (auto it = nexts[info.node].begin(); it != nexts[info.node].end(); it++) {
		Edge &edge = *it;
		if (edge.weight > info.time) break;
		int ndist = info.dist + edge.weight;
		int ntime = info.time - edge.weight;
		while (ntime <= M) {
		    if (ndist >= minDist[edge.next][ntime]) break;
		    minDist[edge.next][ntime] = ndist;
		    q.push(Info(ndist, edge.next, ntime));
		    ntime++;
		    ndist++;
		    if (!hosp[edge.next]) break;
		}
	    }
	}
	if (help) {
	    cout << "Help!" << endl;
	}
    }

    return 0;
}

Measured memory_bytes: 3896
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
int read()
{  int f=1,x=0;
   char ch=getchar();
   for(;ch>'9'||ch<'0';ch=getchar())if(ch=='-') f=-1;
   for(;ch<='9'&&ch>='0';ch=getchar())x = x * 10 + ch - '0';
   return x*f;
}
int n,a[1000005],dis[1000005]={0},x,ans[1000005],p=1;
map<int,int>m;
int main()
{     cin>>n;
      for(int i=1;i<=n;i++)
      {  scanf("%d",&a[i]);
         int x=a[i];
         if(dis[x])
         {  dis[x]++;
            continue;
         }
         for(int j=x;j<=1000000;j+=x)
           dis[j]++;
      }
      int cnt=0;
      for(int i=1;i<=n;i++){if(dis[a[i]]==1)cnt++;}
      cout<<cnt;
}

Measured memory_bytes: 8456
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print :fiveam))
                 (shadow :run)
                 (use-package :fiveam)))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (let* ((n (read))
         (s (read-line))
         (r (loop for c across s
                  count (char= c #\R)))
         (b (- n r)))
    (write-line (if (> r b) "Yes" "No"))))

#-swank(main)


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

int main()
{
    int A, B, C;
    int cnt;
    int maxv;

    cin >> A >> B >> C;

    maxv = max( { A, B, C } );
    cnt = (maxv - A) / 2 + (maxv - B) / 2 + (maxv - C) / 2;

    A += (maxv - A) / 2 * 2;
    B += (maxv - B) / 2 * 2;
    C += (maxv - C) / 2 * 2;

    int num = (maxv != A) + (maxv != B) + (maxv != C);

    switch ( num ) {
        case 0 :
            cout << cnt << endl;
            break;
        case 1 :
            cout << cnt + 2 << endl;
            break;
        case 2 :
            cout << cnt + 1 << endl;
            break;
    }
    return (0);
}


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

int main()
{
    vector<int> v = { 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 };
    int k;
    cin >> k;
    cout << v[k - 1] << endl;
    return 0;
}


Measured memory_bytes: 256
M, D = map(int, input().split())
ans = 0

for d in range(10, D + 1):
  d_1 = d % 10
  d_10 = int(d / 10)
  if d_1 >= 2 and d_10 >= 2 and d_1 * d_10 <= M:
    ans += 1

print(ans)

Measured memory_bytes: 2940
n = int(input())
abc = [list(map(int, input().split())) for _ in range(n - 1)]
q, k = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(q)]

adj = [[] for _ in range(n)]
for a, b, c in abc:
    a -= 1
    b -= 1
    adj[a].append([b, c])
    adj[b].append([a, c])


def dfs(s):
    d = [-1] * n
    d[s] = 0
    stack = [s]

    while stack:
        u = stack.pop()
        for v, c in adj[u]:
            if d[v] == -1:
                d[v] = d[u] + c
                stack.append(v)

    return d


d = dfs(k - 1)

for x, y in xy:
    x -= 1
    y -= 1
    print(d[x] + d[y])


Measured memory_bytes: 90972
#include <iostream>
#include <vector>
#define FAST_IO                  \
    ios::sync_with_stdio(false); \
    cin.tie(NULL);               \
    cout.tie(NULL);
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define MOD 1000000007
#define MAX 1e9
#define MIN -1e9

using namespace std;

typedef long long ll;

ll dp[100005][3], a[100005][3];
int main()
{

    FAST_IO

    ll n;
    cin >> n;
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i][0] >> a[i][1] >> a[i][2];
    }
    dp[0][0] = a[0][0], dp[0][1] = a[0][1], dp[0][2] = a[0][2];
    for (ll i = 1; i < n; i++)
    {
        dp[i][0] = a[i][0] + max(dp[i - 1][1], dp[i - 1][2]);
        dp[i][1] = a[i][1] + max(dp[i - 1][0], dp[i - 1][2]);
        dp[i][2] = a[i][2] + max(dp[i - 1][1], dp[i - 1][0]);
    }
    cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2])) << endl;
}

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

int main() {
    string S,T;
    cin >> S >> T;
    
    int N = S.size();
    
    map<int,int> m;
    bool flg = true;
    for ( int i = 0; i < N; ++i){
        int s = S[i] - 'a';
        int t = T[i] - 'a';
        ++s; ++t;
        if ( m[s] == 0 ){
            m[s] = t;
        } else {
            int u = m[s];
            if ( u != t ) flg = false;
        }
    }
    
    vector<int> c(27,0);
    for ( int i = 1; i <= 26; ++i){
        int x = m[i];
        if ( x == 0 ) continue;
        c[x] = c[x] + 1;
        //cout << "c[" << x << "] = " << c[x] << endl;
        if ( c[x] > 1 ) flg = false;
    }
    
    if ( flg ){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3920
n = int(input())

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

ans = 0
cnt = 0

s = 1
for i in range(n):
    ans += li[i]
    if ans <= 0 and s == -1:
        cnt += abs(ans) + 1
        ans = 1
    if ans >= 0 and s == 1:
        cnt += abs(ans) + 1
        ans = -1
    s *= -1
    
res1 = cnt


ans = 0
cnt = 0

    
s = -1
for i in range(n):
    ans += li[i]
    if ans <= 0 and s == -1:
        cnt += abs(ans) + 1
        ans = 1
    if ans >= 0 and s == 1:
        cnt += abs(ans) + 1
        ans = -1
    s *= -1
    
res2 = cnt

print(min(res1,res2))

Measured memory_bytes: 14648
from collections import deque

(n, m, k), aa, bb = [list(map(int, l.split())) for l in open(0)]

from itertools import accumulate

aaa = list(zip(list(accumulate([0]+aa)), range(len(aa)+1)))
bbb = list(zip(list(accumulate([0]+bb)), range(len(bb)+1)))

i = 0
j = len(bb)

ans = 0

while i<len(aaa) and j >= 0:
    aco, abo = aaa[i]
    bco, bbo = bbb[j]
    if aco+bco > k:
        j -= 1
        continue
    else:
        ans = max(abo+bbo, ans)
        i += 1

print(ans)

Measured memory_bytes: 145328
while True:
    table = input().split()

    a = int(table[0])
    op = table[1]
    b = int(table[2])

    if op == '?':
        break

    if op == '+':
        print(a+b)
    elif op == '-':
        print(a-b)
    elif op == '/':
        print(int(a/b))
    else:
        print(a*b)


Measured memory_bytes: 5596
#include <stdio.h>

const int MAXN = 3005;
const int MOD = (int)1e9 + 7;

char s[MAXN];
int dp[MAXN][MAXN];

int get_ans(int i, int l, int r) {
    int ans = dp[i][r];
    if (l > 0) ans -= dp[i][l - 1];

    return (ans % MOD + MOD) % MOD;
}

int main(void) {
    int n;

    scanf(" %d", &n);
    scanf(" %s", s);

    dp[0][0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= i; j++) {
            if (i == 0) break;

            if (s[i - 1] == '<') {
                dp[i][j] += get_ans(i - 1, 0, j - 1);
            } else {
                dp[i][j] += get_ans(i - 1, j, n - 1);
            }
            dp[i][j] %= MOD;
        }

        for (int j = 1; j < n; j++) {
            dp[i][j] += dp[i][j - 1];
            dp[i][j] %= MOD;
        }
    }
    printf("%d\n", dp[n - 1][n - 1]);

    return 0;
}


Measured memory_bytes: 35328
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define fi first
#define se second
#define mod 1000000007
#define all(v) v.begin(),v.end()
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define go_t int t;cin>>t;for(int tt=1;tt<=t;tt++)
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define trace2(x, y)             cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)       cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define trace5(a, b, c, d, e)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<endl;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; // order_of_key
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const ll inf = 0x3f3f3f3f3f3f3f3fll;//4x10e18
const int maxx = 3000000;
#define PI 3.14159265
int n,m,k;
int main()
{
    fastio;
    ll a,b;
    cin>>a>>b;
    if(a<=b)
        cout<<min(b-a,a)<<endl;
    else
    {
        ll dif = a-b;
        ll ti = dif/b;
        ll nw = a - ti*b;
        if(nw>b)
            nw = nw - b;
        a = nw;
        cout<<min(b-a,a)<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel.Design;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Schema;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<int> Slist() {
            var t = ReadLine();
            if (t.Trim().Length == 0) return new List<int>();
            return new List<int>(t.Split().Select(int.Parse)); }
        static void Main(string[] args)
        {
            var S = Sarray()[0];
            WriteLine(30 <= S ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 18840
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <list>
#include <queue>
#include <sstream>
#include <cmath>
#include <functional>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define reps(s,i,n) for(int i=s;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define skip(i,n,p) for(int i=0;i<n;i+=p)
#define all(a)  (a).begin(),(a).end()
#define int64 long long
#define debug cerr << __FILE__ << ":" << __LINE__ << endl;
#define INF 2147483647

struct Init {
    Init() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
        cout << fixed;
    }
} init;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {
    for(int i = 0; i < (int) v.size(); i++) {
        ostr << v[i] << (i + 1 != v.size() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const map<_K, _V>& v) {
    ostr << "{";
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << (*iter).first << ": " << (*iter).second << ", ";
    }
    ostr << "}";
    return ostr;
}

template <typename _K>
ostream& operator << (ostream& ostr, const set<_K>& v) {
    for (auto iter = v.begin(); iter != v.end(); ++iter) {
        ostr << *iter << (iter != v.end() ? " " : "");
    }
    return ostr;
}

template <typename _K, typename _V>
ostream& operator << (ostream& ostr, const pair<_K, _V>& v) {
    ostr << v.first << " " << v.second;
    return ostr;
}

int main() {
    int N; cin >> N;
    vector<int64> L(N); rep(i, N) cin >> L[i];

    sort(all(L));

    int counter = 1;
    rep(i, N-1) {
        if (L[i] * 2 >= L[i+1]) {
            counter += 1;
        } else {
            counter = 1;
        }
        L[i+1] += L[i];
    }

    cout << counter << endl;
}


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

int main() {
	long long A,B,C,D;
	cin>>A>>B>>C>>D;
	
	if(D<=A||D<=(A+B))
	{
		if(D<=A)
		{
			cout<<D<<endl;
		}
		else
		{
			cout<<A<<endl;
		}
	}
	else
	{
		
			cout<<(A-(D-(A+B)))<<endl;
		
		
	}
	
	
	return 0;
}

Measured memory_bytes: 3632
#include<functional>
#include<algorithm>
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,x,n) for(int i=x;i<n;i++)
#define pb push_back
#define MAX 100005


using namespace std;
const int INF=1000000007;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int NIL=-1;
struct node{
  int p,l,r;
};

 node T[MAX];
 int n,D[MAX];

 void print(int u){
   int i,c;
   cout<<"node "<<u<<": ";
   cout<<"parent = "<<T[u].p<<", ";
   cout<<"depth = "<<D[u]<<", ";

   if(T[u].p==NIL)cout<<"root, ";
   else if(T[u].l==NIL)cout<<"leaf, ";
   else cout<<"internal node, ";

   cout<<"[";

   for(i=0,c=T[u].l;c!=NIL;i++,c=T[c].r){
     if(i)cout<<", ";
     cout<<c;
   }
   cout<<"]"<<endl;
 }

int rec(int u,int p){
   D[u]=p;
   if(T[u].r!=NIL)rec(T[u].r,p);
   if(T[u].l!=NIL)rec(T[u].l,p+1);
 }

int main(){
  int d,v,c,l,r;
  cin>>n;
  for(int i=0;i<n;i++)T[i].p=T[i].l=T[i].r=NIL;

  for(int i=0;i<n;i++){
    cin>>v>>d;
    for(int j=0;j<d;j++){
      cin>>c;
      if(j==0)T[v].l=c;
      else T[l].r=c;
      l=c;
      T[c].p=v;
      }
    }
    for(int i=0;i<n;i++){
      if(T[i].p==NIL)r=i;
    }
    rec(r, 0);
    for(int i=0;i<n;i++)print(i);

  return 0;
}

Measured memory_bytes: 7748
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <string>
#include <string.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <stdlib.h>
using namespace std;
typedef long long int lld;
typedef long double ld;
vector<pair<int,lld> > v[333];
lld dp[333][333];
int dp2[333][333];
int vis[333];
lld l;
int n,m;
int main(void){
	for(int e=0;e<333;e++) for(int p=0;p<333;p++) if(e!=p) {
		dp[e][p] = 2e9;
		dp2[e][p] = 1e9;
	}
	scanf("%d%d%lld",&n,&m,&l);
	for(int e=0;e<m;e++){
		int a,b,c;
		scanf("%d%d%d",&a,&b,&c);
		if(c<=l){
			dp[a][b] = c;
			dp[b][a] = c;
		}
	}
	for(int e=1;e<=n;e++){
		for(int p=1;p<=n;p++){
			if(e==p) continue;
			for(int q=1;q<=n;q++){
				if(e==q||p==q) continue;
				if(dp[p][e]==2e9||dp[e][q]==2e9) continue;
				if(dp[p][e]+dp[e][q]<=l){
					dp[p][q] = min(dp[p][q],dp[p][e]+dp[e][q]);
				}
			}
		}
	}
	for(int e=1;e<=n;e++){
		for(int p=1;p<=n;p++){
			if(dp[e][p]!=2e9) dp2[e][p] = 1;
		}
	}
	for(int e=1;e<=n;e++){
		for(int p=1;p<=n;p++){
			if(e==p) continue;
			for(int q=1;q<=n;q++){
				if(e==q || p==q) continue;
				dp2[p][q] = min(dp2[p][q],dp2[p][e]+dp2[e][q]);
			}
		}
	}
	int q; 
	scanf("%d",&q);
	while(q--){
		int s,t;
		scanf("%d%d",&s,&t);
		if(dp2[s][t]==1e9) printf("-1\n");
		else{
			printf("%d\n",dp2[s][t]-1);
		}
	}
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int n;
    cin >> n;
    char s[n][n];
    rep(i,n){
        rep(j,n){
            cin >> s[i][j];
        }
    }

    int ans = 0;
    char t[n][n];
    
    rep(i,n){
        rep(j,n){
            rep(k,n){
                t[j][k] = s[j][(k + i)%n];
            }
        }
        int flag = 1;
        rep(j,n){
            rep(k,n){
                if(t[j][k] != t[k][j])flag = 0;
            }
        }
        ans += (n - i) * flag;
    }

    srep(i,1,n){
        rep(j,n){
            rep(k,n){
                t[j][k] = s[(j + i)%n][k];
            }
        }
        int flag = 1;
        rep(j,n){
            rep(k,n){
                if(t[j][k] != t[k][j])flag = 0;
            }
        }
        ans += (n - i) * flag;
    }

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


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

using namespace std;
#define REP(i, N) for(int i=0;i<N;i++)

int main() {
    int q[100010][2] = {0};
    int n, m, p;
    int ans = 0, pena = 0;
    string s;
    cin >> n >> m;
    REP(i, m) {
        cin >> p >> s;
        if (s == "WA") ++q[p][1];
        else {
            if (!q[p][0])pena += q[p][1];
            ++q[p][0];
        }
    }
    REP(i, n + 1) {
        if (q[i][0] > 0) ++ans;
    }
    cout << ans << ' ' << pena << endl;
}

Measured memory_bytes: 1152
#include<iostream>
#include<algorithm>
#include<functional>
#include<unordered_map>
#include<cmath>

using namespace std;

int mod_num_counter[2030];

int main()
{
  //fill(mod_num_counter,mod_num_counter+2030,0);
  
  int n,k;
  cin >> n >> k;
  
  bool has[n+1];
  
  for(int i=0;i<=n;i++)
  {
    has[i] = false;
  }
  
    for(int i=0;i<k;i++)
  {
    int d;
      cin >> d;
      for(int j=0;j<d;j++)
      {
        int p;
        cin >> p;
        has[p] = true;
      }
  }
  
  int ans=0;
  for(int i=1;i<=n;i++)
  {
    if(!has[i]) ans++;
  }
  
        cout << ans << endl;
    
  return 0;
}

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

using namespace std;
 
int main() {
    int a,b;cin>>a>>b;
    if(a>b) cout<<a+a-1;
    if(a==b)cout<<a+b;
    if(a<b) cout<<b+b-1;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long int
#define fi first
#define se second
#define pub push_back
#define pi pair<int,int>
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for(int i=(int)(l);i<(int)(r);i++)
#define repd(i, l, r) for (int i=(int)(l);i>=(int)(r);i--)
#define clrg(i, l, r) for(int i=(int)(l);i<(int)(r);i++)vis[i]=0,v[i].clear();
int power(int x, unsigned int y){int res = 1;while (y > 0){ if (y & 1){res = res*x;} y = y>>1;x = x*x;}return res;}
int powermod(int x, unsigned int y, int p){int res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1; x = (x*x) % p;}return res;}
#define print2d(mat,n,m){for(int i=0;i<(int)(n);i++){for(int j=0;j<(m);j++){cout<<mat[i][j]<<" ";}cout<< endl;}}
#define clr(a,x) memset(a,x,sizeof(a))
#define rr(v) for(auto &val:v)
#define print(v) for (const auto itr : v){cout<<itr<<' ';}cout<<"\n";
#define ln length()
#define sz size()
#define mod 1000000007
#define elif else if
int32_t main(){
   int n; cin>>n;
   vector<int> v(n),u(n);
   rep(i,0,n)cin>>v[i];
   rep(i,0,n)cin>>u[i];
   reverse(all(u));
   int l=0,r=n-1,c=-1;
   rep(i,0,n){
     if(u[i]==v[i]){
       l=i;
       c=v[i];
       break;
     }
   }
   repd(i,n-1,0){
     if(u[i]==v[i]){
       r=i;
       break;
     }
   }
   rep(i,0,n){
     if(u[i]!=c and v[i]!=c and l<=r){
       swap(u[i],u[l++]);
     }
   }
  if(l<=r)cout<<"No\n";
  else{ cout<<"Yes\n"; print(u);
  }
   return 0;
}
/*
Edge cases? n=1? a[i]<=0?
long vs int? 1LL? 64bits?
Re-read problem. Is it as easy as it seems?
KEEP CORRECTING AND SUBMITTING!
*/


Measured memory_bytes: 6400
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(i=a;i<b;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define vi vector < ll  int >
#define CLR(a) memset((a),0,sizeof(a))
#define mp make_pair
#define hell 1000000007`
using namespace std;

void solve()
{
 double i,j,k,y=0,ans=0,n,m=0,x,z,a,b;
 cin>>n;
 vector < double > v(n);
 rep(i,0,n) cin>>v[i];
 rep(i,0,n-1)
   {
       sort(all(v));
       k=v.size();
       m=v[0]+v[1];
       m/=2;
       v.erase(v.begin());
       v[0]=m;
   }
   cout<<v[0];

}



   signed main()
        {
            ios::sync_with_stdio(false);
            cin.tie(0);
            cout.tie(0);
            int t=1;
            //cin>>t;
            while(t--)
             solve();
        }


Measured memory_bytes: 256
package main

import "fmt"

func main() {
  var N, K, Q, A int
  fmt.Scan(&N, &K, &Q)
  x := make([]int, N)
  for i := 0; i < Q; i++ {
    fmt.Scan(&A)
    x[A-1]++
  }

  for a := range x {
    if Q < K + x[a] {
      fmt.Println("Yes")
    } else {
      fmt.Println("No")
    }
  }
}


Measured memory_bytes: 5888
from fractions import gcd

N = int(input())
A = [int(x) for x in input().split()]

L = [0] * (N + 1)
R = [0] * (N + 1)
for i in range(N):
    L[i + 1] = gcd(L[i], A[i])
for i in range(N - 1, 0, -1):
    R[i] = gcd(R[i + 1], A[i])

ans = 0
for i in range(N):
    ans = max(ans, gcd(L[i], R[i + 1]))
print(ans)


Measured memory_bytes: 16148
#include "bits/stdc++.h"
using namespace std;

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

struct UnionFind {
	vector<int> d;
	UnionFind(int n) {
		d = vector<int>(n, -1);
	}
	int root(int x) {
		if (d[x] < 0)return x;
		return d[x] = root(d[x]);
	}
	bool unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y)return false;
		if (d[x] > d[y])swap(x, y);
		d[x] += d[y];
		d[y] = x;
		return true;
	}
	int size(int x) {
		return -d[root(x)];
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
};

int main() {
	ll n, m, k;
	ll a, b, c, d;
	cin >> n >> m >> k;
	UnionFind u(n);
	vector<int> x(n + 1);
	vector<vector<ll>> y(n + 1);
	ll ans;

	rep(i, m) {
		cin >> a >> b;
		a -- ;	b--;
		x[a]++;
		x[b]++;
		u.unite(a, b);
	}
	rep(i, k) {
		cin >> c >> d;
		c--;		d--;
		y[c].push_back(d);
		y[d].push_back(c);
	}

	rep(i, n) {
		ans = u.size(i) - 1 - x[i];
		for (int s : y[i]) {
			if (u.same(i, s))ans--;
		}
		cout << ans << " ";
	}

	

	return 0;
}


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

#define mod 10e9+7
#define ll long long int

int f(int x){
    if(x%2==0)return x/2;
    else return x*3 + 1;
}

int main(void){
    int s;
    scanf("%d", &s);
    int mem[100000];
    for(int i = 0;i < 100000;i++){
        mem[i] = 0;
    }
    int count = 0;
    while(1){
        count++;
        if(mem[s]==1)break;
        mem[s] = 1;
        s = f(s);
    }
    printf("%d\n", count);
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll sa = 0, sb = 0, n, cnt = 0, t;
  cin >> n;
  vector<ll> a(n), b(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];

  rep(i, n) {
    if (a[i] > b[i]) {
      t = a[i] - b[i];
      cnt += t;
      b[i] += t;
    }
  }
  rep(i, n) {
    if (a[i] < b[i]) {
      t = (b[i] - a[i]) / 2;
      a[i] += t * 2;
      cnt -= t;
    }
  }

  cout << (cnt <= 0 ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010

char S[SIZE];
int ans[SIZE] = {};

int main() {

  scanf("%s", S);
  int N = strlen(S);

  set<int> Ls, Rs;

  for (int i=0; i<N; i++) {
    if (S[i] == 'L')
      Ls.insert(i);
    else
      Rs.insert(i);
  }


  for (int i=0; i<N; i++) {
    if (S[i] == 'L') {
      auto it = Rs.upper_bound(i);
      it--;
      int pos = *it;
      ans[pos + (i-pos)%2]++;
    } else {
      auto it = Ls.lower_bound(i);
      int pos = *it;
      ans[pos - (pos-i)%2]++;
    }
  }

  for (int i=0; i<N; i++) {
    printf("%d%c", ans[i], " \n"[i == N-1]);
  }

   return 0;
}


Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(register int i=st,i##end=ed;i<=i##end;++i)
#define DREP(i,st,ed) for(register int i=st,i##end=ed;i>=i##end;--i)
typedef long long ll;
template<typename T>inline bool chkmin(T &x,T y){return (y<x)?(x=y,1):0;}
template<typename T>inline bool chkmax(T &x,T y){return (y>x)?(x=y,1):0;}
inline int read(){
    int x;
    char c;
    int f=1;
    while((c=getchar())!='-' && (c>'9' || c<'0'));
    if(c=='-') f=-1,c=getchar();
    x=c^'0';
    while((c=getchar())>='0' && c<='9') x=(x<<1)+(x<<3)+(c^'0');
    return x*f;
}
inline ll readll(){
    ll x;
    char c;
    int f=1;
    while((c=getchar())!='-' && (c>'9' || c<'0'));
    if(c=='-') f=-1,c=getchar();
    x=c^'0';
    while((c=getchar())>='0' && c<='9') x=(x<<1ll)+(x<<3ll)+(c^'0');
    return x*f;
}
const int maxn=2e5+10;
vector<int> G[maxn];
int dis[maxn],dp[maxn],n;
int bfs(int S){
	REP(i,1,n) dis[i]=-1;
	dis[S]=0;
	queue<int> q;
	q.push(S);
	while(!q.empty()){
		int u=q.front();q.pop();
		for(int v:G[u])
			if(dis[v]==-1){
				dis[v]=dis[u]+1;
				q.push(v);
			}
	}
	int ans=0,num=S;
	REP(i,1,n) if(chkmax(ans,dis[i])) num=i;
	return num;
}
int main(){
	n=read();
	REP(i,1,n-1){
		int x=read(),y=read();
		G[x].push_back(y),G[y].push_back(x);
	}
	int S=bfs(1);
	int T=bfs(S);
	dp[0]=1,dp[1]=0;
	REP(i,2,n) dp[i]=1-dp[i-1]*dp[i-2];
	printf("%s\n",dp[dis[T]]?"First":"Second");
    return 0;
}

Measured memory_bytes: 14324
#include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(long i = long(a); i <= long(b); i++)
#define per(i, a, b) for(long i = long(a); i >= long(b); i--)
#define N 100005
typedef long long ll;
ll n, a[N], rai[N], lep[N], k;
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> k;
    ll neg = 0, pos = 0;
    rep(i, 1, n) {
        cin >> a[i];
        if (a[i] >= 0) {
            rai[++pos] = a[i];
        }

    }
    per(i, n, 1) {
        if (a[i] < 0) {
            lep[++neg] = - a[i];
        }
    }
    ll r = 1e9;
    rep(i, 0, k) {
        if (i > pos) break;
        int j = k - i;
        if (j > neg) continue;
        ll sum = min(2 * lep[j] + rai[i], lep[j] + 2 * rai[i]);
        r = min(r, sum);
    }
    cout << r ;
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(b%a == 0){
		cout<<a+b<<endl;
	}
	else{
		cout<<b-a<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <map>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <vector>
#include <queue>
#include <list>
#include <numeric>

using namespace std;
typedef long long ll;

/*迷路
const int INF = 50;

typedef pair<int,int> P;
char field[52][52];
int d[51][51];
int r,c;
int sx,sy;
int gx,gy;

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

int bfs(){
    queue<P> que;
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            d[i+1][j+1] = INF;
        }
    }
    que.push(P(sy,sx));
    d[sy][sx]=0;
while(que.size()){
    P p=que.front();
    que.pop();
    if(p.second==gx&&p.first==gy) break;
    for(int i=0;i<4;i++){
        int nx=p.second+dx[i];
        int ny=p.first+dy[i];

        if(1<=nx&&nx<=c&&1<=ny&&ny<=r&&field[ny][nx]!='#'&&d[ny][nx]==INF){
            que.push(P(ny,nx));
            d[ny][nx] = d[p.first][p.second] + 1;
        }
    }
}
return d[gy][gx];
}
*/

int main(){
  int n,m,a,b;
  cin>>n>>m>>a>>b;
  int x[n],y[m];
  for(int i = 0;i<n;i++) cin>>x[i];
  for(int i = 0; i<m;i++) cin>>y[i];
  int flag = 0;
  sort(x,x+n);
  sort(y,y+m);
  for(int i = 0; i<b;i++){
    if(a<i&&x[n-1]<i&&y[0]>=i)
    flag = 1;
  }
  if(flag) cout<<"No War"<<endl;
  else cout<<"War"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int N,A,B,C,D;
	char S[200001];
	scanf("%d %d %d %d %d",&N,&A,&B,&C,&D);
	int i;
	char dummy;
	scanf("%c",&dummy);
	for(i=1;i<=N;i++){
		scanf("%c",&S[i]);
	}
	int SA[200001];
	for(i=1;i<=N;i++){
		if(S[i]=='#'){
			SA[i]=1;
		}else{
			SA[i]=0;
		}
	}
	int ans;
	ans=0;
	if(C<D){
		for(i=A+1;i<D;i++){
			if(SA[i]*SA[i+1]==1){
				ans=1;
				break;
			}
		}
	}
	if(C>D){
		int j;
		j=1;
		for(i=B;i<=D;i++){
			if(SA[i-1]+SA[i]+SA[i+1]==0){
				j=0;
				goto jump1;
			}
		}
		jump1:
		if(j==1){
			ans=1;
		}
		for(i=A+1;i<C;i++){
			if(SA[i]*SA[i+1]==1){
				ans=1;
			}
			if(ans==1){
				break;
			}
		}
	}
	if(ans==0){
		printf("Yes");
	}else{
		printf("No");
	}
}


Measured memory_bytes: 1152
#include <iostream>

using namespace std;

void rwFile() {
    freopen("INP.inp", "r", stdin);
    freopen("OUT.out", "w", stdout);
}

void solve() {
    int n; cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++) cin >> arr[i];
    int res[n];
    res[0] = 0;
    res[1] = abs(arr[1] - arr[0]);
    for (int i = 2; i < n; i++) {
        res[i] = min(abs(arr[i - 1] - arr[i]) + res[i - 1], abs(arr[i] - arr[i - 2]) + res[i - 2]);
    }
    cout << res[n - 1];
}

int main()
{
    //rwFile();
    solve();
}


Measured memory_bytes: 1024
x, y = tuple(map(int, input().split()))
g1 = {1, 3, 5, 7, 8, 10, 12}
g2 = {4, 6, 9, 11}
g3 = {2}
if x in g1 and y in g1:
    print("Yes")
elif x in g2 and y in g2:
    print("Yes")
elif x in g3 and y in g3:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erase(unique(all(v)),v.end());
#define pvec(v) rep(i,v.size()){ cout << v[i] << " ";}
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
#define mod 1e9 + 7;
ll dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };

ll gcd(ll x, ll y)
{
	ll r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y)
{
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x * y);
}





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

	ll a=0, b=0, c=0, ans = 1, n, ret = 0, m, d;
	string s,t;
	cin >> n >> m;

	vector<P> v(m);
	rep(i, m) {
		cin >> a >> b;
		v[i] = make_pair(a, b);
	}
	
	sort(all(v));
	//rep(i, v.size()) cout << v[i].first << " " << v[i].second << endl;
	ll cut = M;

	rep(i, m) {
		ll p = v[i].first;
		if (cut <= p) {
			ans++;
			cut = M;
		}

		cut = min(cut, v[i].second);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <mutex>
#include <cmath>
#include <set>
#include <climits>

#define mod 1e9+7
#define mp make_pair
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
using ll = long long;
using pii = pair<int, int>;
 
int main(){
	int N;
	string S;
	cin >> N >> S;
	int ans = 0;
	rep(i, 1000){
		int c[3] = {i/100, (i%100)/10, i%10};
		int f = 0;
		rep(j, N){
			if(S[j] == ('0'+c[f])) f++;
			if(f == 3) break;
		}
		if(f == 3) ans++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000000000
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
constexpr int MOD = 1000000007;

void print(const std::vector<int>& v)
{
  std::for_each(v.begin(), v.end(), [](int x) {
    std::cout << x << " ";
  });
  std::cout << std::endl;
}

int main ()
{
    int N,K;cin>>N>>K;
    vector<int> A(N);
    REP(i,N) cin>>A[i];
    if((N-1)%(K-1)==0){
            cout<<(N-1)/(K-1)<<endl;
            return 0;
        }
        int hoge = (N-1)/(K-1);
        cout<<hoge+1<<endl;
        return 0;
}

Measured memory_bytes: 640
# 単調増加したらそこの山の高さは決まる。それ以外ならある高さ以内で自由に取れる。t,aで矛盾したら0
# 一人ずつ考えた
n = int(input())
t = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = 1
MOD = 10**9 + 7
a_fixed = [-1] * n
t_fixed = [-1] * n

t_fixed[0] = t[0]
for i in range(1, n):
    if t[i] > t[i - 1]:
        t_fixed[i] = t[i]

a_fixed[-1] = a[-1]
for i in range(n - 2, -1, -1):
    if a[i] > a[i + 1]:
        a_fixed[i] = a[i]


for i in range(n):
    if t_fixed[i] != -1 and a_fixed[i] != -1:
        if t_fixed[i] != a_fixed[i]:
            print(0)
            exit()

    # 片方の制約を満たしているか
    elif t_fixed[i] != -1:
        if t_fixed[i] > a[i]:
            print(0)
            exit()
    elif a_fixed[i] != -1:
        if a_fixed[i] > t[i]:
            print(0)
            exit()
    else:
        ans *= min(a[i], t[i])
        ans %= MOD
# print(fixed)
print(ans)


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

int main(void) {
  int N,M,K;
  cin >> N >> M >> K;

  for (int i = 0; i <= N; i++) {
    for (int j = 0; j <= M; j++) {
      int num = (M - j) * (N - i) + j * i;
      if (num == K) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}

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

#define rep(i,l,r) for(ll i=(l);i<(r);i++)
#define pb push_back
#define fi first
#define se second

using ll = long long;
using G = vector<vector<int>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const ll MOD = 1000000007;

ll GCD(ll x, ll y){
	return y ? GCD(y, x%y) : x;	
}
ll LCM(ll x, ll y){
	return x/GCD(x, y)*y;
}

int main() {
	ll n, m, k; cin >> n >> m >> k;
	ll a[200005], b[200005];
	ll asum = 0;
	ll bsum = 0;
	rep(i, 1, n+1) cin >> a[i];
	a[0] = 0;
	rep(i, 1, m+1){
		cin >> b[i];
		bsum += b[i];
	}
	ll ans = 0;
	ll bmax = m;
	rep(i, 0, n+1){
		asum += a[i];
		if(asum>k) break;
		else{
			for(ll j=bmax;j>=1;j--){
				if(asum+bsum<=k){
					bmax = j;
					ans = max(ans, i+j);
					break;
				}else{
					bsum -= b[j];
				}
			}
			if(bsum==0){
				ans = max(ans, i);
				bmax = 0;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6688
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 2e5+5;
const int mod = 1e9+7;

int n;
int x;
bool v[N];
int mem[N];

int go(int idx){
    if(v[idx])
        return 0;
    if(idx == n)
        return 1;
    if(idx > n)
        return 0;
    if(~mem[idx])
        return mem[idx];
    return mem[idx] = (go(idx + 1) + go(idx + 2)) % mod;
}

int main(){
    scanf("%d%d" , &n , &x);
    for(int i = 1; i <= x; i++){
        int a;
        scanf("%d" , &a);
        v[a] = 1;
    }
    memset(mem , -1 , sizeof mem);
    printf("%d\n" , go(0));
}

Measured memory_bytes: 4224
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
int find_digitnum(long long int x){
    int res=0;
    while(x>=1){
        res++;
        x /= 10;
    }
    return res;
}
int main(){
    long long int N; cin >> N;
    int ans=10;
    for (long long int i=1;i<=sqrt(N);i++){
        if (N%i==0) {
            long long int A = i;
            long long int B = N/i;
            ans = min(ans,max(find_digitnum(A),find_digitnum(B)));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
Def inf = sizeof(Def) == sizeof(long long) ?  2e18:1e9+10;
int dx[]={0,-1,0,1};
int dy[]={1,0,-1,0};
int d[1010][1010],dp[1010][1010];
int main(){
	int sosu[1100000]={1,1,0};//1 is not sosu
	for(int i=2;i*i<1100000;i++)if(sosu[i]==0)
	for(int j=i*2;j<1100000;j+=i)sosu[j]=1;
	
	int x=500,y=500,to=0,go=1,num=2;
	rep(i,1010)rep(j,1010)d[i][j]=0;
	d[x][y]=1;
	while(1){
		rep(i,2){
			rep(j,go){
				x+=dx[to];y+=dy[to];
				if(x<0||y<0||x>1009||y>1009)goto end;
				d[x][y]=num++;
			}
			to++;
			if(to==4)to=0;
		}
		go++;
	}
	end:;
	
//	loop(x,490,510){loop(y,490,510)cout<<" "<<d[x][y];cout<<endl;}
		
	int n,m;
	while(cin>>m>>n,n){
		rep(i,1010)rep(j,1010)dp[i][j]=-inf;
		rep(i,1010)rep(j,1010)if(d[i][j]==n)dp[i][j]=0;//!sosu[d[i][j]];
		rep(i,1009)loop(j,1,1009){
			int e=!sosu[d[i][j]];
			if(d[i][j]>m)e=0;
//			cout<<"! "<<i<<" "<<j<<endl;
			dp[i+1][j]=max(dp[i+1][j],dp[i][j]+e);
			dp[i+1][j-1]=max(dp[i+1][j-1],dp[i][j]+e);
			dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+e);
		}
		int ma=-1,a;
		rep(i,1010)rep(j,1010)if(d[i][j]<=m&&sosu[d[i][j]]==0){
			dp[i][j]++;
			if(dp[i][j]>ma){
				ma=dp[i][j];
				a=d[i][j];
			}else if(dp[i][j]==ma)a=max(a,d[i][j]);
		}
		if(ma==-1)ma=a=0;
		cout<<ma<<" "<<a<<endl;
		
	}
	
}









Measured memory_bytes: 15360
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
	ll n,x;cin>>n>>x;
	ll a[100010];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	ll ans=0;
	if(a[0]>x){
		ans+=a[0]-x;
		a[0]=x;
	}
	for(int i=1;i<n;i++){
		if(a[i-1]+a[i]>x){
			ans+=a[i-1]+a[i]-x;
			a[i]-=a[i-1]+a[i]-x;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define NCLR(a) memset((a), -1 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
typedef complex<double> P;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 1000000007;
static const int INF = 1 << 29;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { -1, 0, 1, 0, 1, -1, 1, -1 };
static const int dy[] = { 0, -1, 0, 1, 1, 1, -1, -1 };

//Union-Find木
#include <vector>

//Union-Find木
#include <vector>

struct Union_Find {
	vector<int> par;
	vector<int> rank;

	//初期化
	void init( int n ) {
		par.resize( n );
		rank.resize( n );
		for ( int i = 0; i < n; ++i ) {
			par[ i ] = i;
			rank[ i ] = 0;
		}
	}

	//木の根を探す
	int find( int s ) {
		if ( par[ s ] == s ) {
			return s;
		}
		return par[ s ] = find( par[ s ] );
	}

	//結合
	void unite( int x, int y ) {
		int a = find( x ), b = find( y );
		if ( a == b ) {
			return;
		}
		if ( rank[ x ] < rank[ y ] ) {
			par[ x ] = y;
		}
		else {
			par[ y ] = x;
			if ( rank[ x ] == rank[ y ] ) {
				++rank[ x ];
			}
		}
	}

	//二つの数の根が同じかどうか
	bool same( int x, int y ) {
		return find( x ) == find( y );
	}

	//サイズを返す
	unsigned int size() {
		return par.size();
	}
};


int main() {
	int n, m;
	Union_Find u;
	while ( ~scanf( "%d", &n ) && n ) {
		scanf( "%d", &m );
		VVI root( n, VI( n, INF ) );
		for ( int i = 0; i < m; i++ ) {
			int a, b, c;
			scanf( "%d,%d,%d", &a, &b, &c );
			root[ a ][ b ] = root[ b ][ a ] = c / 100 - 1;
		}
		u.init( n );
		int ans = 0;
		for ( int i = 1; i < n; i++ ) {
			int _min = INF, add;
			for ( int j = 0; j < n; j++ ) {
				if ( !u.same( 0, j ) ) {
					continue;
				}
				for ( int k = 1; k < n; k++ ) {
					if ( !u.same( 0, k ) && _min >= root[ j ][ k ] ) {
						add = k;
						_min = root[ j ][ k ];
					}
				}
			}
			u.unite( 0, add );
			ans += _min;
		}
		printf( "%d\n", ans );
	}
	return 0;
}

Measured memory_bytes: 1252
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const long long Maxn=1000+10,Maxm=30000+10,inf=0x3f3f3f3f;
long long n,m,m1,ans=inf;
long long w[Maxn],v[Maxn],f[Maxm];
int main()
{
//	freopen("in.txt","r",stdin);
	scanf("%lld%lld",&m,&n);
	
	for(long long i=1;i<=n;++i)
	{
		scanf("%lld%lld",w+i,v+i);
		m1=max(m1,w[i]);
	}
	fill(f+1,f+1+m+m1+1,inf);
	
	for(long long i=1;i<=n;++i)
	for(long long j=w[i];j<=m+m1;++j)
	f[j]=min(f[j],f[j-w[i]]+v[i]);
	for(long long i=0;i<=m1;++i)
	ans=min(ans,f[m+i]);
	
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
from itertools import product


def solve(string):
    n = string
    ans = 0
    for i in range(3, len(n) + 1):
        tmp = ("".join(x) for x in product("753", repeat=i) if "7" in x and "5" in x and "3" in x)
        ans += len([x for x in tmp if len(x) < len(n) or x <= n])
    return str(ans)


if __name__ == '__main__':
    print(solve(input()))


Measured memory_bytes: 4284