akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
bool prime[d5];
void era(){
    for(int i=0;i<d5;i++)prime[i]=true;
    prime[0]=prime[1]=false;
    for(int i=0;i<d5;i++){
        if(!prime[i])continue;
        for(int j=2*i;j<d5;j+=i)prime[j]=false;
    }
}
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    era();
    int x;
    cin>>x;
    for(int i=x;i<d5;i++){
        if(prime[i]){
            cout<<i<<endl;
            return 0;
        }
    }
}

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

int main(){
    ll A,B,N; cin>>A>>B>>N;
    
    ll ans=0;
    if(N<B){
        ans = (A*N)/B - A*(N/B);
    }else{
        ans =(A*(B-1))/B - A*((B-1)/B);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 3596
#include <stdio.h>

int main(void)
{
	char str[10001];
	int joi, ioi;
	int k;
	
	while (scanf("%s", str) != EOF){
		joi = ioi = 0;
		
		k = 0;
		while (str[k] != '\0'){
			if (str[k + 1] == 'O' && str[k + 2] == 'I'){
				if (str[k] == 'J'){
					joi++;
				}
				else if (str[k] == 'I') {
					ioi++;
				}
			}
			k++;
		}
		
		printf("%d\n%d\n", joi, ioi);
	}
	
	return (0);
}

			

Measured memory_bytes: 552
#include <set>
#include <string>
#include <iostream>
using namespace std;

int main() {
	set<string> s;
	int n = 0; 
	cin >> n;
	for (int i = 1; i <= n; i++) {
		string str;
		cin >> str;
		s.insert(str);
	}
	cout << s.size() << endl;
	return 0;
}

Measured memory_bytes: 19060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n,k,ans=0,mod=998244353;
  cin >> n >> k;
  vector<long> l(k),r(k),dp(n+1),ruisekiwa(n+1);
  for(long i=0;i<k;i++) cin >> l[i] >> r[i];
  dp[1]=1;
  ruisekiwa[1]=1;
  for(long i=2;i<=n;i++) {
    for(long j=0;j<k;j++) {
      dp[i]=(dp[i]+ruisekiwa[max(0L,i-l[j])]+mod-ruisekiwa[max(0L,i-r[j]-1)])%mod;
    }
    ruisekiwa[i]=(ruisekiwa[i-1]+dp[i])%mod;
  }
  cout << dp[n] << endl;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

// ------------------------------------------------------------------------------------------

const ll MOD = 1e9+7;
int N;
int a[111111];
map<int, int> mp;

ll f(ll x) {
   ll ret = 2;
   while (x > 0) {
      // ret *= 2;
      ret = ((ret%MOD) * (2%MOD)) % MOD;
      debug(ret)
      x /= 10;
   }
   return ret;
}

ll t(ll a, ll b) {
   ll ans = 1;
   while (b > 0) {
      if (b&1) {
         // ans *= a;
         ans = ((ans%MOD) * (a%MOD)) % MOD;
      }
      // a *= a;
      a = ((a%MOD) * (a%MOD)) % MOD;
      b /= 2;
   }
   return ans;
}

int v1[111111];
int v2[111111];

int main() {
   cin >> N;
   rep (i, N) {
      cin >> a[i];
      v1[a[i]]++;
   }

   bool ok = true;
   if (N&1) {
      if (v1[0] != 1) ok = false;
      for (int i = 2; i < N; i+=2) {
         if (v1[i] != 2) ok = false;
      }
   } else {
      for (int i = 1; i <= N; i+=2) {
         if (v1[i] != 2) ok = false;
      }
   }

   if (ok) {
      cout << t(2, N/2) % MOD << endl;
   } else {
      cout << 0 << endl;
   }

   return 0;
}

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

struct IO {
  IO &operator>>(int &x) {
    char c;
    do
      c = std::cin.rdbuf()->sbumpc();
    while (!isdigit(c));
    for (x = 0; isdigit(c); c = std::cin.rdbuf()->sbumpc())
      x = x * 10 + (c ^ 48);
    return *this;
  }
} io;

const int MAX_N = 100000;

int f[MAX_N + 1], h[MAX_N + 1];

int main() {
  int n, k;
  io >> n >> k;
  for (int i = 1; i <= n; ++i) io >> h[i];
  memset(f, 0x3f, sizeof(int) * (n + 1));
  f[1] = 0;
  for (int i = 2; i <= n; ++i) {
    for (int j = 1; j <= k && i - j >= 1; ++j) {
      f[i] = std::min(f[i], f[i - j] + std::abs(h[i] - h[i - j]));
    }
  }
  std::cout << f[n];
  return 0;
}

Measured memory_bytes: 1024
(N , M) = gets.split.map(&:to_i)
array = []
Evaluation = Struct.new(:x,:y,:z)
N.times { (x,y,z) = gets.split.map(&:to_i); array.push(Evaluation.new(x,y,z)) }
ret = [0]
m1 = [1,-1]
m2 = [1,-1]
m3 = [1,-1]
m1.each {|tmp1| m2.each {|tmp2| m3.each{|tmp3| ret.push(array.map {|r| r.x*tmp1+r.y*tmp2+r.z*tmp3 }.sort {|a,b| b <=> a }[0...M].inject(:+)) if M > 0 }}}
puts ret.max

Measured memory_bytes: 2040
N,Ma,Mb = map(int,input().split())
dp = [[[10**9 for i in range(401)] for j in range(401)] for k in range(N+1)]
dp[0][0][0] = 0
for i in range(1,N+1):
    a,b,c = map(int,input().split())
    for j in range(401):
        for k in range(401):
            if j < a:
                dp[i][j][k] = dp[i-1][j][k]
            else:
                if k < b:
                    dp[i][j][k] = dp[i-1][j][k]
                else:
                    dp[i][j][k] = min(dp[i-1][j][k],dp[i-1][j-a][k-b] + c)
m = max(Ma,Mb)
import math
n = math.floor(400 / m)
ans = 10**9
for i in range(1,400):
    x = Ma*i
    y = Mb*i
    if x > 400:
        break
    if y > 400:
        break
    ans = min(dp[N][x][y],ans)
if ans == 10**9:
    print(-1)
    quit()
print(ans)

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

using namespace std;

#define db(x) cout << (x) << '\n';
#define all(x) x.begin(),x.end()
#define UNIQUE(x) sort(all(x)),x.resize(unique(all(x))-x.begin())
#define LB(v,x) lower_bound(all(v),x)
#define UB(v,x) upper_bound(all(v),x)
#define endl "\n"
#define F first
#define S second
#define PB push_back
#define PF push_front
#define int long long
#define double long double
#define trick int m = (l+r)>>1,lc=n<<1,rc=lc|1

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

int dy[]={0,1,1,1,0,-1,-1,-1};
int dx[]={-1,-1,0,1,1,1,0,-1};
const int maxn = 1e5;
const int OO = 1e18;
const int mod = 1e9 + 7;
const double PI = acos(-1);

void maxself(int &a,int b)
{a=max(a,b);}
void minself(int &a,int b)
{a=min(a,b);}

vector<vi> g(maxn);


int32_t main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

//	freopen("name.in","r",stdin);
//	freopen("name.out","w",stdout);
	
	int n;
	cin >> n;
	int ans = n/2;
	if(n%2==1)
	ans++;
	cout << ans ;

	return 0;
}



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

using namespace std;


#define int long long


main(){

	int n; cin >> n;


	vector <int> l(n);

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


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


	int ans = 0;

	for(int i = 0; i < n; i++){
		for(int j = i + 1; j < n; j++){
			auto it = lower_bound(l.begin(), l.end(), l[i] + l[j]) - l.begin();


			ans += it - j - 1;

		}
	}


	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cassert>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repd(i, n) for (int i = n; i >= 1; i--)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
typedef long long int ll;
typedef pair<ll, ll> p;


int main() {
	int a, b;
	cin >> a >> b;
	cout << max(a + b, max(a - b, a*b));
	return 0;
}

//Ctrl+Aを使わない

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(ll i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;

using namespace std;
#define N 1000010
ll cnt[N];
int main(){
    ll n,p;
    cin>>n>>p;
    if(n==1){
	cout<<p<<endl;
	return 0;
    }
    ll ans=1;
    for(ll i=2;i<=N;i++){
	ll cnt=0;
	while(p%i==0){
	    cnt++;
	    if(cnt==n){
		ans*=i;
		cnt=0;
	    }
	    p/=i;
	}
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
n , m = map(int, input().split())
h = list(map(int,input().split()))
x = [1]*n
for i in range(m):
    a , b = map(int, input().split())
    if h[a-1]==h[b-1]:
        x[a-1]=0
        x[b-1]=0
    elif h[a-1]>h[b-1]:
        x[b-1]=0
    else:
        x[a-1]=0
print(sum(x))


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

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

int main(){
    string s,t;
    cin >> s >> t;
    string u = t. substr(0,t.length()-1);

//    cout << t.substr(0,t.length()-1) << endl;

    if(s == u){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
using namespace std;
int main(){
  int n;cin>>n;
  int a[n];
  for(int i = 0; n > i; i++){
    cin>>a[i];
  }
  int q;cin>>q;
  for(int i = 0; q > i; i++){
    int t;cin>>t;
    if(a[t-1]+1!=a[t])a[t-1]=min(a[t-1]+1,2019);
  }
  for(int i = 0; n > i; i++){
    cout << a[i] << endl;
  }
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
typedef long long ll;
#define mod 1000000007
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vll vector <ll>
#define vii vector <int>
#define vpii vector <pii>
#define vpll vector <pll>
#define ff first
#define ss second
#define matrix vector <vll>
#define all(v) v.begin(),v.end()
#define PQ priority_queue
using namespace std;
ll pow(ll a, ll b){
	ll res = 1;
	while(b > 0){
		if(b&1) res*=a;
		b/=2;
		a*=a;
	}
	return res;
}
int main()
{
	//ios::sync_with_stdio(0);
	//cin.tie(0);
	int n, d;
  	cin >> n >> d;
  	int cnt = 0;
  	int p = 0;
  	while(p < n){
    	p+=(2*d+1);
      	cnt++;
    }
  	cout << cnt << "\n";
  return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
X = list(map(int, input().split()))

X.sort(reverse=True)
count = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [-1] * (N + 1)
dp[0] = 0

for a in X:
    n = count[a]
    for i in range(N - n + 1):
        if dp[i] == -1:
            continue
        dp[i + n] = max(dp[i + n], dp[i] * 10 + a)

print(dp[-1])


Measured memory_bytes: 96380
//   __________________
//  | ________________ |
//  ||          ____  ||
//  ||   /\    |      ||
//  ||  /__\   |      ||
//  || /    \  |____  ||
//  ||________________||
//  |__________________|
//  \\#################\\
//   \\#################\\
//    \        ____       \
//     \_______\___\_______\
// An AC a day keeps the doctor away.

#pragma GCC optimize("Ofast")
#pragma loop_opt(on)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) 0//(cerr<<#x<<" = "<<(x)<<'\n')
#define all(v) begin(v),end(v)
#define siz(v) (ll(v.size()))
#define get_pos(v,x) (lower_bound(all(v),x)-begin(v))
#define pb emplace_back
#define ff first
#define ss second
#define mid (l+(r-l>>1))
#define rep(i,n) for(int i = 0; i < (n); i++)
#define REP(i,n) for(int i = 1; i <= (n); i++)

using namespace std;
using namespace __gnu_pbds;
typedef int64_t ll;
typedef uint64_t ull;
typedef long double ld;
typedef pair<ll,ll> pll;
template <typename T> using rkt = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
constexpr ld PI = acos(-1), eps = 1e-8;
constexpr ll N = 502525, INF = 1e18, MOD = 998244353, K = 2;
constexpr inline ll cdiv(ll x, ll m) { return (x+m-1)/m; } // ceiling divide, x/m for flooring divide
template <typename T> void M(T &x, ll m = MOD){x%=m; if(x<0) x+=m;}

ll n,v[N],k;
signed main(){
    ios_base::sync_with_stdio(0), cin.tie(0);
  	cin >> n;
  	cout << n*n*3 << '\n';
}


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

def main():
    S = input()
    K = int(input())

    m = -1
    c = ''
    for i in range(len(S)):
        if S[i] == '1':
            m = i
        else:
            c = S[i]
            break

    m += 1


    print('1' if K <= m else c)


if __name__ == '__main__':
    main()



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

int main(void) {
    string S,T;
    cin>>S>>T;
    if (S == T) {
        cout << "Yes" << endl;
    } else {
        bool flg = false;
        string initial = S;
        while (true) {
            string ST = S.substr(S.size() - 1, 1) + S.substr(0, S.size() - 1);
            if (initial == ST) break;
            if (ST == T) flg = true;
            S = ST;
        }
        if (flg) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import math, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**20
def I(): return int(input())
def F(): return float(input())
def S(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()

def resolve():
    A, B, K = LI()

    d = math.gcd(A, B)
    ans = 0
    for i in range(d, 0, -1):
        if A % i == B % i == 0:
            K -= 1
        if K == 0:
            ans = i
            break

    print(ans)

if __name__ == '__main__':
    resolve()

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



int main(){
    int K,A,B;
    cin>>K>>A>>B;
    if(A%K==0){
        cout<<"OK"<<endl;
    }
    else if((A/K+1)*K<=B){
        cout<<"OK"<<endl;
    }
    else{
        cout<<"NG"<<endl;
    }
    
}

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

const int maxn = 2000 + 10;
int n, l[maxn], s[maxn][maxn], ans;

int main(int argc, const char *argv[])
{
  scanf("%d", &n);
  for(int i = 1; i <= n; ++i) scanf("%d", l + i);
  for(int i = 1; i <= n; ++i) {
    for(int j = i; j <= n; ++j) ++s[i][l[j]];
    for(int j = 0; j < maxn; ++j) s[i][j] = s[i][j] + s[i][j - 1];
  }
  for(int i = 1; i <= n; ++i) for(int j = i + 1; j <= n; ++j) {
    ans = ans + (s[j + 1][l[i] + l[j] - 1] - s[j + 1][abs(l[i] - l[j])]);
  }
  return 0 & printf("%d\n", ans);
}

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

using namespace std;
using ll = long long;

const ll INF = 1e9;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll S; cin >> S;
	cout << 0 << ' ' << 0 << ' ' << INF << ' ' << 1 << ' ' << INF*((S-1)/INF+1)-S << ' ' << (S-1)/INF+1 << '\n';
	return 0;
}

Measured memory_bytes: 256
#pragma region

#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define _rep3(i, begin, end) for (register int i = (begin); i < (end); i++)
#define _irep3(i, begin, end) for (register int i = (end)-1; i >= (begin); i--)
#define _rep2(i, n) _rep3(i, 0, n)
#define _irep2(i, n) _irep3(i, 0, n)
#define _overload3(_1, _2, _3, name, ...) name
#define rep(...) _overload3(__VA_ARGS__, _rep3, _rep2, )(__VA_ARGS__)
#define irep(...) _overload3(__VA_ARGS__, _irep3, _irep2, )(__VA_ARGS__)
#define out(x) cout << (x) << '\n';
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;
typedef long long ll;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "vec[ ";
  rep(i, vec.size()) i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}

#pragma endregion

#define MOD 1000000007
#define INF 2147483647

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16);

  long A, B, K;
  cin >> A >> B >> K;
  if (K < A) {
    A -= K;
  } else if (K < A + B) {
    B -= K - A;
    A = 0;
  } else {
    A = 0;
    B = 0;
  }
  cout << A << " " << B << "\n";
}


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

require 'matrix'

if __FILE__ == $0 then
	n, m, l = gets.split.map(&:to_i)

	matA = Matrix.rows((1..n).map { gets.split.map(&:to_i) })
	matB = Matrix.rows((1..m).map { gets.split.map(&:to_i) })

	for col in (matA*matB).to_a do
		puts col.join(' ')
	end
end



Measured memory_bytes: 7672
#include <math.h>
#include <stdio.h>
#include <bitset>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  string S;
  cin >> S;
  int count = 0;
  int max = 0;
  for (int i = 0; i < (int)S.size(); i++) {
    if (S[i] == 'A' || S[i] == 'C' || S[i] == 'G' || S[i] == 'T') {
      count++;
    } else {
      if (max < count) {
        max = count;
      }
      count = 0;
    }
  }
  if (max < count) {
    max = count;
  }
  cout << max << endl;
}

Measured memory_bytes: 3604
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;

	if (a < c && c < b)
		cout << "Yes";
	else if (a > c && c > b)
		cout << "Yes";
	else cout << "No";
}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())

signed main(){

	string s;
	cin>>s;

	for(lli i=0;i<s.size();i++){
		if(i%2==1){
			if(s.at(i)=='R'){
				cout<<"No"<<endl;
				return 0;
			}
		}
		else{
			if(s.at(i)=='L'){
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	cout<<"Yes"<<endl;


	return 0;
}

Measured memory_bytes: 256
length = gets.to_i
while length != 0
  c = Array.new(length)
  p1 = Array.new(length)
  s = gets.split.map { |e| e.to_i }
  c = Marshal.load(Marshal.dump(s))
  time = 0
  while true
    i = 0
    time += 1
    p1 = Marshal.load(Marshal.dump(c))
    p1.each { |e|
      c[i] = p1.select {|g| g == e}.size
      i += 1
    }
    break if p1 == c
  end
  p time-1
  puts p1.join(" ")
  length = gets.to_i
end

Measured memory_bytes: 6500
# http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2013

from itertools import accumulate

def getsec(s):
    # hh:mm:ss 23:59:59までかな 23*3600+59*60+59=86399
    h, m, s = map(int, s.split(":"))
    return h * 3600 + m * 60 + s

def solve(n):
    A = [0] * 90000
    for _ in range(n):
        ai, bi = input().split()
        ai, bi = getsec(ai), getsec(bi)
        A[ai] += 1
        A[bi] -= 1
    
    cA = accumulate(A)
    print(max(cA))


while True:
    n = int(input())
    if n == 0:
        break
    solve(n)


Measured memory_bytes: 6356
#include <iostream>
#include <vector>
#include <iomanip>
#include <stack>
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <iterator>
#include <string>
#include <cstring>
//#include <fstream>
#include <complex>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n;i>0;i--)
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define SORT(v) sort((v).begin(),(v).end())
const ll INF = (1LL << 50);
typedef pair<int, int> P;

int main() {

	ll n, a, b;
	cin >> n >> a >> b;

	ll d = n / (a + b);
	ll e = n % (a + b);

	if (e <= a) cout << e + d * a << endl;
	else cout << d * a + a << endl;

	return 0;

}

Measured memory_bytes: 256
from itertools import accumulate

n,k = map(int,input().split())
P = list(map(int,input().split()))

# 期待値の前計算
expP = [(P[i]+1)/2 for i in range(n)]

# 累積和の計算
acc = [0]+ list(accumulate(expP)) # 0を忘れずに

# 隣接する K 項の和の計算
ans = 0
for i in range(n-k+1):
  ans = max(ans,acc[i+k]-acc[i])
print(ans)

Measured memory_bytes: 26236
Var R,G,B:Longint;
Begin
        //Assign(Input,'A.INP'); Reset(Input);
        //Assign(Output,'A.OUT'); Rewrite(Output);
        Readln(R,G,B);
        B:=R*100+G*10+B;
        If B mod 4=0 Then Write('YES') Else Write('NO');
        //Close(Input);
        //Close(Output);
End.


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a;
  cin >> a;
  vector<int> vec(a);
  int ans = 0;
  for (int i = 0; i < a; i++) cin >> vec[i];
  for (int i = 0; i < a; i++) {
    if (vec[vec[i] - 1] == i + 1 && vec[i] != i + 1) ans++;
  }
  cout << ans / 2 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<long long> vll;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

int main() {
  ll n;
  cin >> n;

  vll a(n), b(0);
  for (ll i = 0; i < n; i++) cin >> a[i];

  if (n % 2 == 0) {
    for (ll i = 0; i < n / 2; i++) {
      b.push_back(a[n - 1 - i * 2]);
    }
    for (ll i = 0; i < n / 2; i++) {
      b.push_back(a[i * 2]);
    }
  }
  else {
    for (ll i = 0; i <= n / 2; i++) {
      b.push_back(a[n - 1 - i * 2]);
    }
    for (ll i = 0; i < n / 2; i++) {
      b.push_back(a[1 + i * 2]);
    }
  }

  for (ll i = 0; i < n - 1; i++) cout << b[i] << " ";
  cout << b[n - 1] << endl;
}

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

bool BinarySearch(int a[], int n, int key){ //計算量はO(logn)
    int left = 0;
    int right = n;
    while(left < right){
        int mid = (left + right)/2;
        if(a[mid] == key) return true;
        else if(a[mid] > key){
            right = mid;
        }else{
            left = mid+1;
        }
    }
    return false;
}

int main(){
    int n;
    cin >> n;
    int A[100010];
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }
    int k;
    cin >> k;
    int T[50010];
    for(int i = 0; i < k; i++){
        cin >> T[i];
    }
    int ans = 0;
    
    for(int i = 0; i < k; i++){
        if(BinarySearch(A,n,T[i])) ans++;
    }
    
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;
typedef pair<int,int> P;
int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  int n, i;
  cin >> n >> i;
  int ans = n - i + 1;
  cout << ans << endl;
  return 0;
}


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

#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); 

#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846

const int N =1e5+5;

int mod= 1e9+7;
int dx[4]={0,0,+1,-1};
int dy[4]={+1,-1,0,0};

void solve(){
  int n;
  cin>>n;
  vi v(n,0);

 int ct=0,maxi=0;

  rep(i,0,n)
	   cin>>v[i];
 
  rep(i,1,n){
    if(v[i]<=v[i-1]){
      ct++;
	  continue;
	}
	maxi=max(ct,maxi);
	ct=0;  
  }

  maxi=max(ct,maxi);  
  
  /*rep(i,0,n){
	int f=0;
 rep(j,i+1,n){
   if(v[j]!=v[j])
	   break;
   f++:
  }
  
 maxi=max()
}*/
  cout<<maxi<<endl;

}

int32_t main() {
	cool;
	int t=1;
	//cin>>t;
	while(t--)
		solve();


	return 0;	  
}

Measured memory_bytes: 1024
#include<stdio.h>
int main(void){
	int H,R;
	scanf("%d %d",&H,&R);
	if(H+R==0) printf("0\n");
	else if(H+R>0) printf("1\n");
	else if(H+R<0) printf("-1\n");
	return 0;
}


Measured memory_bytes: 2044
#define rep(i,x) for (int i = 0; i < x; i++)
#define mod 1000000007
#define MOD 998244353
#define inf 1e20
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <math.h>
#include <complex>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> p;
typedef complex<double> com;


int main() {
	int a, b, c;
	cin >> a >> b >> c;
	cout << (a + b + 1 >= c ? b + c : 2 * b + a + 1) << endl;
	return 0;
}
//Ctrl+Aを使わない

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<stack>
#include<queue>
#include<numeric>
#include<algorithm>
#include<string>
#include<map>
#include<bitset>
#include<set>
#include<cmath>
//#define int long long
#define inf 1145141919ll
#define oku 1000000007ll
using namespace std;
int a,b,c,d;
int dx[]={0,-1,0,1,0};
struct A{
	A *e;
	int temp;

};
struct B{
	A *src;
	A *dst;
	int cost;
};
struct C{
	int u;
	int v;
	int len;
	C(int x,int y,int z):u(x),v(y),len(z){}
};
int i,j,k,n;
int p[2000],q[2000],r[2][2001][2001];
signed main(){
	cin>>a>>b;
	n=inf;
	if(a<b){
		if(a>=0){
			n=b-a;
		}else{
			if(b>=0){
				n=b-a;
				n=min(n,abs(b+a)+1);
			}else{
				n=b-a;
			}
		}
	}else{
		if(a>=0){
			if(b>=0){
				n=b+a+1;
				n=min(n,a-b+2);
			}else{
				n=abs(a+b)+1;
			}
		}else{
			n=-b+a+2;
		}
	}
	cout<<n<<endl;
}

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

int main(){
    ll X;
    cin >> X;
    
    ll num500 = X / 500;
    X = X - num500 * 500;
    ll num5 = X / 5;
    
    cout << num500 * 1000 + num5 * 5 << endl;
    return 0;
}

Measured memory_bytes: 768
using System;
using System.Linq;
using System.Collections.Generic;

namespace ConsoleApp2
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int[] NK = Read(Console.ReadLine());
            int N = NK[0];
            int K = NK[1];

            double[] expecteds = new double[N];
            string[] read = Console.ReadLine().Split(' ');

            for (int i = 0; i < N; i++)
            {
                expecteds[i] = (1 + double.Parse(read[i])) / 2;
            }

            double maxE = 0;
            double currentE = 0;

            for (int i = 0; i < K; i++)
            {
                maxE += expecteds[i];
            }
            currentE = maxE;

            for (int i = 1; i < N-K+1; i++)
            {
                currentE = currentE - expecteds[i - 1] + expecteds[K + i - 1];
                maxE = Math.Max(maxE, currentE);
            }

            Console.WriteLine(maxE);
            Console.ReadLine();
        }

        private static int[] Read(string input)
        {
            string[] strings = input.Split(' ');
            int num = strings.Length;
            int[] ints = new int[num];
            for (int i = 0; i < num; i++)
            {
                ints[i] = int.Parse(strings[i]);
            }
            
            return ints;
        }


    }


}


Measured memory_bytes: 30044
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n,i,m;
	double s=100;
	cin>>n;
	m=100;
	for(i=1;;i++)
	{
		s=m*1.01;
		m=s/1;
		if(m>=n)
		{
			cout<<i<<endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll>Q;

map<P,set<ll> > s; 
ll di[20][20][20];

ll ans = 0;
ll n,m,q;

void dfs(ll len,ll now,vector<ll> &S){
  if(len==n){
    ll tmp = 0;
    for(ll j=0;j<n;j++){
      //cout<<S[j];
      for(ll k=j+1;k<n;k++){
        ll c = S[k]-S[j];
        set<ll> T = s[P(j,k)];
        if(T.count(c)==1)tmp+=di[j][k][c];
      }
    }
    //cout<<endl;
    ans = max(ans,tmp);
    return;
  }
  for(ll j=now;j<=m;j++){
    vector<ll> T;
    T =S;
    T.push_back(j);
    dfs(len+1,j,T);
  }
}

int main(void){
  cin>>n>>m>>q;
  for(ll i=0;i<q;i++){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    a--;
    b--;
    s[P(a,b)].insert(c);
    di[a][b][c]=d;
  }
  vector<ll> seq;
  dfs(0,1,seq);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;


int U[505000], V[505000];

int main(void) {

	int N;

	cin >> N;

	string S, tmp;
	cin >> tmp;

	S = "*" + tmp + "*";

	int ans = 300000;


	for (int i = 1; i <= N; i++) {
		if (S[i] != '.') { U[i] = U[i-1] + 1; }
		else { U[i] = U[i - 1]; }
	}

	for (int i = N; i >= 1; i--) {
		if (S[i] != '#') { V[i] = V[i + 1] + 1; }
		else { V[i] = V[i + 1]; }
	}


	for (int i = 0; i <= N; i++) {
		//cout << "U[" << i << "]= " << U[i] << "  V[" << i + 1 << "]= " << V[i + 1] << endl;
		ans = min(U[i] + V[i + 1], ans);
	}

	cout << ans << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 2308
#include <iostream>
#include <algorithm>

using namespace std;

void solve()
{
	int a, b, c, d, e;
	while (cin >> a >> b >> c >> d >> e, a || b || c || d || e)
	{
		int na, nb, nc;
		cin >> na >> nb >> nc;
		int sum = a * na + b * nb + c * nc;

		if (nc >= d)
		{
			sum = min(sum, a * na + b * nb + e * nc);
		}
		else
		{
			sum = min(sum, a * na + b * nb + e * d);
			if (nb + nc >= d)
			{
				int k = d - nc;
				sum = min(sum, a * na + b * (nb - k) + e * d);
			}
			else if (na + nb + nc >= d)
			{
				int j = d - nb - nc;
				sum = min(sum, (na - j) * a + e * d);
			}
			else
			{
				sum = min(sum, e * d);
			}
		}
		cout << sum << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

int main(void){
  int N;
  string S;
  cin >> N >> S;
  
  int ls = 0, rd = 0;
  for (char c: S) {
    if (c == '.') { rd++; }
  }
  int ans = rd;
  for (char c: S) {
    if (c == '#' ) {
      ls++;
    } else {
      rd--;
    }
    if (ls+rd < ans) { ans = ls+rd; }
  }
  
  cout << ans;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
     string str,s;

     cin>>s>>str;
     int t=0,i;

     for(i=0;i<s.size();i++){

        if(s[i]==str[i])t++;

     }

     cout<<t<<endl;
    return 0;
    }

Measured memory_bytes: 256
import sys
from collections import defaultdict, deque, Counter
import math
 
# import copy
from bisect import bisect_left, bisect_right
# import heapq
 
# sys.setrecursionlimit(1000000)
 
# input aliases
input = sys.stdin.readline
 
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]
 
INF = 10 ** 20
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def main():
    n, a, b = getList()
    mx = min(a, b)
    mn = max(a + b - n, 0)
    print(mx, mn)

if __name__ == "__main__":
    main()
   

Measured memory_bytes: 65564
open Printf open Scanf
open Array

let () = scanf " %d %d %d" @@ fun a b c ->
  if a<b then (
    for i=a to b do
      if i=c then (
        printf "Yes"; exit 0
      )
    done;
    printf "No"
  ) else (
    for i=b to a do
      if i=c then (
        printf "Yes"; exit 0
      )
    done;
    printf "No"
  )



Measured memory_bytes: 384
#if 0
accept?????????
40?????????????????£???

???????????¨??????????????¢?´¢???????????????????????????

???????????????????????????????????°????????????????????????
31-169584????????????????????????????????¨??£??????????????????????????£????????§????????????????????????????????????

#endif


#include <queue>
#include <iostream>
using namespace std;
int w,h;
const int dx[]={1,0,-1,0}, dy[]={0,-1,0,1};
char mat[100][100];

bool valid(int x,int y)
{
    return (x>=0)&&(x<w)&&(y>=0)&&(y<h)&&(mat[x][y]!='#');
}

void bfs(int x,int y) {
  int sum=1;
  queue<pair<int,int> >Q;// ??´??°????????????????????\????????????
  pair<int,int>p;//?????????
  p=make_pair(x,y);
  Q.push(p);
  while (! Q.empty()) {
    pair<int,int> cur = Q.front(); // ??????????´????????????????
    Q.pop();
    for (int i=0;i<4;i++) { //??????????????????????????????4?????????
      if (valid(cur.first+dx[i],cur.second+dy[i])) { //????????????????????????????????£??????
	Q.push(make_pair(cur.first+dx[i],cur.second+dy[i])); // dst ????¨???????????????????
	sum++;
	mat[cur.first+dx[i]][cur.second+dy[i]]='#';//2??????????????¢
      }
    }
    mat[cur.first][cur.second]='#';//2??????????????¢
  }
  cout<<sum<<endl;
}


int main() {
  int x,y;
  while(cin>>w>>h && w!=0){
    for(int j=0;j<h;++j){
        for(int i=0;i<w;++i){
            cin >> mat[i][j];
            if(mat[i][j]=='@'){//???????±???´???
                x=i,y=j;
            }
        }
    }
    bfs(x,y);
  }
}

Measured memory_bytes: 3044
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define watch(x) cout << (#x) << " is " << (x) << endl

typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
typedef pair< double,double> dd;
#define pb push_back
#define eb emplace_back
#define sz(a) (int)a.size()
#define all(c) c.begin(),c.end()
#define FOR(i,a,b) for(i=a; i<b; i++)
#define FORR(i,a,b) for(i=a;i>=b;i--)
#define REP(i,n) FOR(i,0,n)
#define x first
#define y second
#define mp make_pair

const int INF = 1000000007;
const long long INFLL = (ll)INF * (ll)INF;

int32_t main()
{
	IOS;
	int n,d,flag=0;
	cin>>n;
	while(n)
	{
		d=n%10;
		if(d==7)
		{
			flag=1;
		}
		n=n/10;
	}
	if(flag)
	{
		cout<<"Yes";
	}
	else
	cout<<"No";
	return 0;
}


Measured memory_bytes: 3608
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
 
#include<bits/stdc++.h>
 
using namespace std;
#define ll long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define ull unsigned long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define ff first
#define ss second
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0); 
#define nl "\n"
#define sz(a) (int)(a).size() 
#define all(a) (a).begin(),(a).end()
#define fl(a,x) memset(a,x,sizeof(a));
#define pt(a,x) cout << get<x>(a) << " " ;  
#define mt make_tuple 
#define vec vector
 
#define int long long 
 
const int mod = (int) 1e9 + 7 ;
const int MOD = (int) 998244353 ;
const int INF = (int) 1e18 ;
 
typedef vector<int> vii;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef vector<vector<int> > vv;
 
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
 
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
const int N = 2e5 + 5 ;
int a[N], dp[N] , n , BIT[N] , h[N];

void update(int x, int val) {
      for(; x <= n; x += x&-x)
        BIT[x] = max(BIT[x], val) ;
}
int query(int x) {
     int mx = 0 ; 
     for(; x > 0; x -= x&-x)
        mx = max(mx , BIT[x]) ;
     return mx;
}
void solve(int test) {
	
	cin >> n ;
	rep(i,1,n+1) cin >> h[i] ;
	rep(i,1,n+1) cin >> a[i] ;

	dp[1] = a[1] ;
	update(h[1], a[1]) ;

	rep(i,2,n+1) {
		dp[i] = a[i] + query(h[i]-1) ;
		update(h[i] , dp[i]) ;
	}

	int ans = 0 ;

	rep(i,1,n+1) ans = max(ans , dp[i]);

	cout << ans ; 
}
 
int32_t main() {

    fast; 
	int t=1;
	// cin>>t;
	rep(i,0,t) {
		solve(i) ;
	}
 
	// cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}

Measured memory_bytes: 9868
#include <iostream>
#include <vector>

using WNode = std::pair<uint32_t, uint32_t>;
using WGraph = std::vector<std::vector<WNode>>;

int main() {
  uint32_t N = 0;
  std::cin >> N;
  WGraph G(N);
  for (size_t i = 0; i < N; i++) {
    uint32_t K = 0;
    std::cin >> i >> K;
    for (size_t j = 0; j < K; j++) {
      uint32_t node = 0, cost = 0;
      std::cin >> node >> cost;
      G[i].push_back({node, cost});
    }
  }

  const uint32_t start = 0;
  std::vector<uint32_t> min_cost(N, -1);
  min_cost[start] = 0;
  std::vector<uint32_t> prev_node(N, -1);
  prev_node[start] = start;
  std::vector<bool> visit(N, false);
  for (size_t i = 0; i < N; i++) {
    uint32_t current = 0, min = -1;
    for (size_t j = 0; j < N; j++) {
      if (visit[j] || min_cost[j] >= min) continue;
      min = min_cost[j];
      current = j;
    }
    visit[current] = true;

    for (auto &&g : G[current]) {
      if (min_cost[g.first] <= g.second + min_cost[current]) continue;
      min_cost[g.first] = g.second + min_cost[current];
      prev_node[g.first] = current;
    }
  }

  for (size_t i = 0; i < N; i++) {
    std::cout << i << " " << min_cost[i] << std::endl;
  }

  return 0;
}


Measured memory_bytes: 3136
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

li = LIST(2)
if 1 not in li:
    print(1)
elif 2 not in li:
    print(2)
else:
    print(3)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            for (int k = 1, t = i ^ j;; k++, t >>= 1) {
                if (t & 1) {
                    cout << k << " \n"[j == n - 1];
                    break;
                }
            }
        }
    }

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

	int H, W, K, x[2], y[2];
	cin >> H >> W >> K;
	REP(i, 2) {
		cin >> x[i] >> y[i];
		x[i]--;
		y[i]--;
	}
	vector<string> c(H);
	REP(i, H) { cin >> c[i]; }
	vector<vector<int>> cost(H, vector<int>(W, INT_MAX));
	cost[x[0]][y[0]] = 0;
	using T = tuple<int, int, int>;
	priority_queue<T, vector<T>, greater<T>> pq;
	pq.emplace(0, x[0], y[0]);
	int dx[4] = {1, 0, -1, 0};
	int dy[4] = {0, 1, 0, -1};
	while (!pq.empty()) {
		int d, u, v;
		tie(d, u, v) = pq.top();
		pq.pop();
		if (d > cost[u][v]) continue;
		REP(i, 4) {
			FOR(j, 1, K + 1) {
				int s = u + j * dx[i];
				int t = v + j * dy[i];
				if (s >= 0 && s < H && t >= 0 && t < W) {
					if (c[s][t] == '@' || d + 1 > cost[s][t]) break;
					if (d + 1 < cost[s][t]) {
						cost[s][t] = d + 1;
						pq.emplace(cost[s][t], s, t);
					}
				}
			}
		}
	}
	if (cost[x[1]][y[1]] == INT_MAX) {
		cout << -1 << endl;
	} else {
		cout << cost[x[1]][y[1]] << endl;
	}

	return 0;
}


Measured memory_bytes: 12080
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
using namespace std;

struct TEdge {
    int From;
    int To;
    int Type;
    int Cost;
};

bool operator < (const TEdge& lhs, const TEdge& rhs) {
    return lhs.Cost > rhs.Cost;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n[2];
    cin >> n[0] >> n[1];

    vector<int> p[2];
    for (int i = 0; i < 2; ++i) {
        p[i].resize(n[i]);
        for (int j = 0; j < n[i]; ++j) {
            cin >> p[i][j];
        }
    }

    int cn[2];
    for (int i = 0; i < 2; ++i) {
        cn[i] = n[i] + 1;
    }

    priority_queue<TEdge> q;
    for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < n[i]; ++j) {
            q.push(TEdge{j, j + 1, i, p[i][j]});
        }
    }

    long long cost = 0;
    while (!q.empty()) {
        TEdge e = q.top();
        q.pop();

        cost += 1LL * e.Cost * cn[1 - e.Type];

        cn[e.Type] -= 1;
    }

    cout << cost << endl;

    return 0;
}

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

int main()
{
  int N;
  cin >> N;
  vector<vector<int>> a(N, vector<int>(N, -1));
  for (int i = 0; i < N; i++)
  {
    int A;
    cin >> A;
    for (int j = 0; j < A; j++)
    {
      int x, y;
      cin >> x >> y;
      x--;
      a[i][x] = y;
    }
  }
  int ans = 0;
  for (int bit = 0; bit < (1 << N); bit++)
  {
    vector<int> b(N, -1);
    int cnt = 0;
    bool ng = false;
    for (int i = 0; i < N; i++)
    {
      if (bit & (1 << i))
      {
        if (b[i] == -1)
        b[i] = 1;
        else if (b[i] != 1) {
          ng = true;
          break;
        }
        for (int j = 0; j < N; j++)
        {
          if (a[i][j] != -1)
          {
            if (b[j] == -1)
            {
              b[j] = a[i][j];
            }
            else
            {
              if (b[j] != a[i][j])
              {
                ng = true;
                break;
              }
            }
          }
        }
        if (ng)
          break;
      } else {
        if (b[i] == -1) b[i] = 0;
        else {
          if (b[i] != 0) ng = true;
        }
      }
    }
    if (!ng)
    {
      for (int i = 0; i < 15; i++)
      {
        if (b[i] == 1) {
          cnt++;
        }
      }
      ans = max(ans, cnt);
    }
  }
  cout << ans << endl;
}


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

int main() {
  int n, m, a = 0, lmax, rmin;
  cin >> n >> m;
  int l[m], r[m];
  bool ans[n+1];
  for ( int i = 0; i < m; i++ ) {
    cin >> l[i] >> r[i];
  }
  for ( int i = 1; i <= n; i++ ) {
    ans[i] = true;
  }
  lmax = l[0]; rmin = r[0];
  for ( int i = 1; i < m; i++ ) {
    lmax = ( l[i] > lmax ) ? l[i] : lmax;
    rmin = ( r[i] < rmin ) ? r[i] : rmin;
  }

  for ( int i = 1; i <= n; i++ ) {
    if ( !(lmax <= i && i <= rmin) ) {
      ans[i] = false;
    }
  }
  for ( int i = 1; i <= n; i++ ) {
    if (ans[i]) { a++; }
  }

  cout << a << endl;
  return 0;
}

Measured memory_bytes: 1152
n = int(input())
arr = list(map(int,input().split()))

base = 1
flag = True
for i in range(n):
    base *= arr[i]
    if base > 10**18:
        flag = False
        break

if flag:
    print(base)
else:
    if 0 in arr:
        print(0)
    else:
        print(-1)

Measured memory_bytes: 84460
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
int n;
int main(){
	scanf("%d",&n);
	if(n==3)return puts("2 5 63"),0;
	fp(i,1,n)if(i%3!=1&&((n-i)&1^1)&&(((n-i)<<1)-1)*3<=30000){
		fp(k,1,i)printf("%d ",k<<1);
		fp(k,1,n-i)printf("%d ",((k<<1)-1)*3);
		return 0;
	}
	puts("QAQ");
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;
ll f(ll h)
{
  if (h == 1)
  {
    return 1;
  }
  else
  {
    return 2 * f(h / 2) + 1;
  }
}

int main()
{
  ll H;
  cin >> H;
  cout << f(H) << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n,m;
  cin>>n>>m;
  vector<int>values;
  vector<int>dist;
  for(int i=0;i<m;i++){
    int x;
    cin>>x;
    values.push_back(x);
  }
  sort(values.begin(),values.end());
  for(int i=1;i<m;i++){
    dist.push_back(values[i]-values[i-1]);
  }
  sort(dist.begin(),dist.end());
  int ans = 0;
  for(int i=0;i<m-n;i++){
    ans+=dist[i];
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1400
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef vector<int> vi;
struct pos {
  int row;
  int column;
};
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Sort(a) sort(a.begin(), a.end())
const int INF = 1 << 30;
const ll MOD = 1000000007;
int main(void) {
  string enc, sub;
  cin >> enc >> sub;

  bool find = false;
  for (int i = enc.size() - sub.size(); i >= 0; i--) {
    bool ok = true;
    for (int j = 0; j < sub.size(); j++) {
      if (enc[i + j] == '?' || enc[i + j] == sub[j]) continue;

      ok = false;
      break;
    }

    if (!ok) continue;

    for (int j = 0; j < sub.size(); j++) {
      enc[i + j] = sub[j];
    }

    find = true;
    break;
  }

  if (find) {
    for (int i = 0; i < enc.size(); i++) {
      if (enc[i] == '?') enc[i] = 'a';
    }
    cout << enc << endl;
    return 0;
  }

  cout << "UNRESTORABLE" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>

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

    std::sort(s.begin(), s.end());
    std::sort(t.begin(), t.end());
    std::reverse(t.begin(), t.end());
    // std::cout << s << " " << t << " " << (s < t) <<std::endl;
    std::cout <<  ((s < t)?("Yes"):("No")) << std::endl;
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

# --- ワーシャルフロイド
def warshall_floyd(dp):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                dp[i][j] = min(dp[i][j] , dp[i][k] + dp[k][j])
    return dp

n, m = map(int, input().split())
d = [[float("inf")]*n for i in range(n)]

abc = [tuple(map(int,input().split())) for i in range(m)]
for a,b,c in abc:
    a,b = a-1,b-1
    d[a][b] = c
    d[b][a] = c

for i in range(n):
    d[i][i] = 0

warshall_floyd(d)

ans = m

for i, (a,b,c) in enumerate(abc):
    a,b = a-1,b-1
    for j in range(n):
        if  d[j][a] + c == d[j][b]:
            ans-=1
            break

print(ans)




Measured memory_bytes: 3440
n = int(input())
a = list(map(int,input().split()))
b = [a[i]+i+1 for i in range(n)]
c = [j+1-a[j] for j in range(n)]
b.sort()
c.sort()
b.append(float("inf"))
c.append(float("inf"))
i = 0
j = 0
count = 0
bc = 1
cc = 1
while True:
  if b[i] > c[j]:
    j += 1
  elif b[i] < c[j]:
    i += 1
  else:
    if b[i] == b[i+1]:
      bc += 1
      i += 1
    elif c[j] == c[j+1]:
      cc += 1
      j += 1
    else:
      count += bc*cc
      bc = 1
      cc = 1
      i += 1
      j += 1
  if i >= n and j >= n:
    break
  if i == n+1:
    i = n
  if j == n+1:
    j = n
print(count)
    
  
  


Measured memory_bytes: 114832