akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{

    class Program
    {
        static void Main()
        {
            Solve();

            Console.ReadKey();
        }

        static void Solve()
        {
            var S = new string(GetStr().ToCharArray().Select(s => 'x').ToArray());

            Console.WriteLine(S);
        }

        


        static public string GetStr() { return Console.ReadLine(); }
        static public int GetInt() { return int.Parse(Console.ReadLine()); }
        static public long GetLong() { return long.Parse(Console.ReadLine()); }
        static public string[] GetStrArray() { return Console.ReadLine().Split(' '); }
        static public int[] GetIntArray() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
        static public long[] GetLongArray() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
        static public List<double> GetDoubleList() { return Console.ReadLine().Split(' ').Select(double.Parse).ToList(); }
        static public void WriteObjects<T>(IEnumerable<T> values) { foreach (var o in values) { Console.Write(o + " "); } }

        static bool eq<T, U>() => typeof(T).Equals(typeof(U));
        static T ct<T, U>(U a) => (T)Convert.ChangeType(a, typeof(T));
        static T cv<T>(string s) => eq<T, int>() ? ct<T, int>(int.Parse(s))
                           : eq<T, long>() ? ct<T, long>(long.Parse(s))
                           : eq<T, double>() ? ct<T, double>(double.Parse(s))
                           : eq<T, char>() ? ct<T, char>(s[0])
                                             : ct<T, string>(s);
        static void Multi<T>(out T a) => a = cv<T>(GetStr());
        static void Multi<T, U>(out T a, out U b)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]);
        }
        static void Multi<T, U, V>(out T a, out U b, out V c)
        {
            var ar = GetStrArray(); a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]);
        }
    }
}

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

signed main() {
  int n,k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n) cin >> a[i];

  ll sum = 0;
  ll p = 0;
  rep(i, n) {
    if(i<k-1) {
      sum += a[i];
    }
    else if (i==k-1) {
      sum += a[i];
      p = sum;
      sum -= a[i-k+1];
    }
    else {
      sum += a[i];
      if( sum > p) {
        puts("Yes");
      }
      else {
        puts("No");
      }
      p = sum;
      sum -= a[i-k+1];
    }
  }
}


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

int main() {
    string S, T;
    cin >> S >> T;

    int ans = 0;
    rep(i, S.size() - T.size() + 1) {
        int tong = 0;
        rep(j, T.size()) {
            if(S[i + j] == T[j]) {
                tong++;
            }
            ans = max(tong, ans);
        }
    }

    cout << T.size() - ans << endl;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1000000000000000000LL
#define MOD 1000000007
#define writeln(n) cout<<n<<endl;
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

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


int main()
{
    int n;//鳩の巣原理よりN+1回押すと絶対1つ以上かぶってる
    cin >> n;
    int ans = 0;
    bool used[n] = {0};
    int a[n];
    int now = 0;
    for(int i = 0; i < n; ++i){
        int b; cin >> b;
        a[i] = b - 1;
    }
    while(1){
        ++ans;
        if(a[now] == 1){
            cout << ans << endl;
            break;
        }else if(used[a[now]]){
            cout << -1 << endl;
            break;
        }else{
            used[a[now]] = 1;
            now = a[now];
        }
    }
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) (((x) < 0)?-(x):(x))
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

using cat = long long;

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int H, W, h, w;
	cin >> H >> W >> h >> w;
	cat cnt_max = 1LL * ((H-1)/h+1) * ((W-1)/w+1);
	cat cnt_min = 1LL * ((H-h)/h+1) * ((W-w)/w+1);
	if(cnt_max == cnt_min) {
		cout << "No\n";
		return 0;
	}
	cout << "Yes\n";
	for(int i = 0; i < H; i++) for(int j = 0; j < W; j++) {
		int s = (i % h) + (j % w);
		if(s > 0 && s < h-1+w-1) cout << "0";
		if(s == 0) cout << cnt_min+1;
		if(s == h-1+w-1) cout << -(cnt_min+2);
		cout << ((j == W-1) ? "\n" : " ");
	}
	return 0;
}

// look at my code
// my code is amazing


Measured memory_bytes: 2048
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int n, A[101000], B[101000];
int X[201000], cnt, C[201000], res;
vector<int>E[201000];
bool v[201000];
void DFS(int a){
    int i;
    v[a]=true;
    for(i=0;i<E[a].size();i++)if(!v[E[a][i]])DFS(E[a][i]);
}
int main(){
    int i, s = 0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&A[i]);
        s^=A[i];
    }
    A[n] = s;
    s = 0;
    for(i=0;i<n;i++){
        scanf("%d",&B[i]);
        s^=B[i];
    }
    B[n] = s;
    for(i=0;i<=n;i++){
        X[++cnt] = A[i];
        X[++cnt] = B[i];
    }
    sort(X+1,X+cnt+1);
    for(i=0;i<=n;i++){
        A[i] = lower_bound(X+1, X+cnt+1, A[i])-X;
        B[i] = lower_bound(X+1, X+cnt+1, B[i])-X;
    }
    for(i=0;i<=n;i++)C[A[i]]++,C[B[i]]--;
    for(i=1;i<=cnt;i++){
        if(C[i]){
            printf("-1\n");
            return 0;
        }
    }
    for(i=0;i<=n+1;i++){
        if(A[i]!=B[i])E[A[i]].push_back(B[i]), res++;
    }
    for(i=1;i<=cnt;i++){
        if(!v[i] && !E[i].empty()){
            DFS(i);
            res++;
        }
    }
    if(!E[A[n]].empty())res--;
    if(A[n]!=B[n])res--;
    printf("%d\n",res);
}

Measured memory_bytes: 13696
//Author: Fuadul Hasan(fuadul202@gmail.com)
#include<bits/stdc++.h>
using namespace std;

#define ll long long
const int N   = 2e5 + 5;

int main(){
	
	
	int n,k;
	cin>>n>>k;
	int a[n];
	int cnt = 0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		if(a[i] >= k)cnt++;
	}

	cout<<cnt<<endl;


	

	return 0;
}

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

using namespace std;

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

int ans[123][123];

int main() {
  int n, m, k;
  scanf("%d %d %d", &n, &m, &k);
  vector <int> a;
  for (int i = 1; i <= k; ++i) {
    int foo;
    scanf("%d", &foo);
    while (foo--) {
      a.push_back(i);
    }
  }
  memset(ans, 0, sizeof ans);
  int x = 0, y = 0;
  int dir = 0;
  for (int e : a) {
    ans[x][y] = e;
    int nx = x + dx[dir];
    int ny = y + dy[dir];
    if (nx < 0 || nx >= n || ny < 0 || ny >= m || ans[nx][ny] != 0) {
      dir = (dir + 1) % 4;
    }
    x += dx[dir];
    y += dy[dir];
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (j > 0) putchar(' ');
      printf("%d", ans[i][j]);
    }
    putchar('\n');
  }
}

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

int main() {
  int n;
  cin >> n;
  vector<int64_t> cnt(n, 0);
  vector<int64_t> as(n, 0), df(n, 0);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    as[i] = a;
    cnt[a-1]++;
  }

  int64_t sum = 0;
  for (int i = 0; i < n; i++) {
    df[i] = ((cnt[i] * (cnt[i] - 1)) / 2) - (((cnt[i] - 1) * (cnt[i] - 2)) / 2);
    sum += (cnt[i] * (cnt[i] - 1)) / 2;
  }

  for (int i = 0; i < n; i++) {
    int a = as[i];
    cout << sum - df[a-1] << endl;
  }
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
using namespace std;
int a[10010],sum=0;
int main(){
    int n,m,c=0;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
    }
    for(int i=0;i<n;i++){
        if(a[i]*4*m>=sum)
            c++;
    }
    if(c>=m)
        cout<<"Yes";
    else
        cout<<"No";

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a,b;
  cin >> a >> b;
  int count = 0;
  for(int i=0;i < 3;i++){
  if(a.at(i) == b.at(i))
    count++;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(void) {
    string S;
    cin >> S;
    int N = S.size();

    int64_t ans = 0;
    for(int bit=0; bit<(1<<N-1); bit++) {
        int last = 0;
        for(int i=0; i<N; i++) {
            if(bit >> i & 1) {
                ans += stoll(S.substr(last, i-last+1));
                last = i+1;
            }
        }
        ans += stoll(S.substr(last, N - last));
    }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll n, k;
ll h[101010];
ll dp[101010];
int main(){
    cin>>n>>k;
    REP(i, 0, n) cin>>h[i];
    REP(i, 1, n+200) dp[i]=inf;

    REP(i, 0, n-1){
        REP(j, 1, k+1){
            dp[i+j]=min(dp[i+j], dp[i]+abs(h[i]-h[i+j]));
        }
    }

    cout<<dp[n-1]<<endl;
    return 0;
}

Measured memory_bytes: 1792
import Control.Arrow
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = readLn >>= main'
    where
        main' n = breads >>= print . solve n 

-- |
-- >>> solve 5 [2, 2, 3, 5, 5]
-- 2
-- >>> solve 9 [1, 2, 3, 4, 5, 6, 7, 8, 9]
-- 0
-- >>> solve 6 [6, 5, 4, 3, 2, 1]
-- 18
-- >>> solve 7 [1, 1, 1, 1, 2, 3, 4]
-- 6
solve :: Int -> [Int] -> Int 
solve n as = minimum ys
    where
        xs = sort . map (\(a, i) -> a - i) $ zip as [1..]
        s = sum xs
        ys = build 0 n 0 s xs

        build a b c d (e : es) = (a - b) * e + d - c : build (a + 1) (b - 1) (c + e) (d - e) es
        build _ _ _ _ _ = []
        

breads :: IO [Int]
breads = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

Measured memory_bytes: 32124
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    long long a,s=0;
    map<long long ,long long>mp;
    mp[0]=1;
    long long ans=0;
    for(int i=1;i<=n;i++)
    {
        cin>>a;
        s+=a;
        ans+=mp[s];
         mp[s]++;
    }


    cout<<ans<<endl;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define ve vector
#define pq priority_queue
#define vi vector<int>
#define vl vector<long long>
#define vii vector<vector<int>>
using namespace std;
using ll = long long;
using ld = long double;
const ll mod = 1000000007;



int main()
{
    int n,k;
    cin >> n >> k;
    
    vector<pair<ll,int>> a(n);
    rep(i,n){
        cin >> a[i].se >> a[i].fi;
        a[i].se--;
    }
    
    sort(all(a));
    reverse(all(a));
    
    ll ans = 0;
    
    vector<int> f(n,0);

    priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> used;
    priority_queue<pair<ll,int>> next;

    ll now_ans = 0;
    ll now_num = 0;
    rep(i,k){
        if(f[a[i].se] == 0) now_num++;
        f[a[i].se]++;
        used.push(a[i]);
        now_ans += a[i].fi;
        ans = now_ans + now_num*now_num;
    }
    for (int i = k; i < n; i++) {
        if(f[a[i].se] == 0) {
            next.push(a[i]);
            f[a[i].se]++;
        }
    }
    
    while (!used.empty() && !next.empty()) {
        if(f[used.top().se] > 1){
            f[used.top().se]--;
            now_ans-=used.top().fi;
            now_ans += next.top().fi;
            now_num++;
            ans = max(ans,now_ans + now_num*now_num);
            next.pop();
        }
        
        used.pop();
    }

    out(ans);


    return 0;
}


Measured memory_bytes: 4468
using System;
 
namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
    string[] str=Console.ReadLine().Split(' ');
      int A=int.Parse(str[0]);
      string op=str[1];
      int B=int.Parse(str[2]);
      if(op=="+"){
        Console.WriteLine(A+B);
      }else{
        Console.WriteLine(A-B);
    }
    
  }
  }
}

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



signed main(){
    int a,b,k;
    cin >> a>>b>>k;
    int t=0,p=min(a,b)+1;
    while(t<k){
        p--;
        if(a%p==0&&b%p==0){
            t++;
        }
        
    }
    cout << p;

    return 0;
}

Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        solve(System.in, System.out);
    }

    static void solve(InputStream is, PrintStream os) {
        // Your code here!
        Scanner sc = new Scanner(is);
        long ans = 0;

        int N = sc.nextInt();
        List<Integer> list = new ArrayList<>();
        for(int i = 0; i < N; i++) {
            list.add(sc.nextInt());
        }
        Collections.sort(list, Collections.reverseOrder());

        ans += list.get(0);
        int th = 1;
        int times = 1;
        while (times < N-1) {
            ans += list.get(th);
            times++;
            if(times == N-1) break;
            ans += list.get(th);
            times++;
            th++;
        }

        os.println(ans);
    }
}

Measured memory_bytes: 55388
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        if(a%2 == 0 && b%2 == 0) {
            System.out.println("Alice");
        } else if(a%2 != 0 && b%2 != 0) {
            System.out.println("Alice");
        } else if(a%2 == 0 && b%2 != 0) {
            System.out.println("Borys");
        } else if(a%2 != 0 && b%2 == 0) {
            System.out.println("Borys");
        } else {
            System.out.println("Draw");
        }
    }
}


Measured memory_bytes: 35860
package main

import "fmt"

func main() {
	var N, M int
	fmt.Scan(&N, &M)

	As := make([]string, N)
	Bs := make([]string, M)

	for i := 0; i < N; i++ {
		fmt.Scan(&As[i])
	}
	for i := 0; i < M; i++ {
		fmt.Scan(&Bs[i])
	}

	for sy := 0; sy < N-M+1; sy++ {
		for sx := 0; sx < N-M+1; sx++ {
			if match(As, Bs, sx, sy) {
				fmt.Println("Yes")
				return
			}
		}
	}
	fmt.Println("No")
}

func match(As, Bs []string, sx, sy int) bool {
	M := len(Bs)
	for y := 0; y < len(Bs); y++ {
		if As[sy+y][sx:sx+M] != Bs[y] {
			return false
		}
	}
	return true
}


Measured memory_bytes: 512
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>

using namespace std;
typedef long long ll;
ll dp[101][100001];

int main() {
   int N, W;
   cin >> N >> W;
   int w[N];
   ll v[N];
   for (int i = 0; i < N; i++) {
      cin >> w[i] >> v[i];
   }

   for (int j = 0; j <= W; j++) dp[N][j] = 0;
   for (int i = N - 1; i >= 0; i--) {
      for (int j = 0; j <= W; j++) {
         if (j < w[i]) dp[i][j] = dp[i + 1][j];
         else dp[i][j] = max(dp[i + 1][j], dp[i + 1][j - w[i]] + v[i]);
      }
   }
   cout << dp[0][W] << endl;
   return 0;
}


Measured memory_bytes: 79104
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    array<int, 3> v{};
    while(cin >> v[0] >> v[1] >> v[2], v[0]){
        int n;
        cin >> n;
        sort(v.begin(),v.end());
        for (int i = 0; i < n; ++i) {
            int r; cin >> r;
            if(v[0]*v[0]+v[1]*v[1] < 4*r*r) puts("OK");
            else puts("NA");
        }
    }
    return 0;
}


Measured memory_bytes: 3040
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define FI(i, a, b) for (int i = (a); i <= (b); ++i)
#define FD(i, b, a) for (int i = (b); i >= (a); --i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;

bool check(ll x, ll y) {
  if (x % y == 0) return check(x / y, y);
  return (x - 1) % y == 0;
}

int main() {
  ll n;
  cin >> n;
  if (n == 2) return !printf("1\n");
  int ans = 2;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      if (check(n, i)) ++ans; 
      if (i * i != n) {
        if (check(n, n / i)) ++ans;
      }
    }
  }
  for (ll i = 2; i * i <= n - 1; ++i) {
    if ((n - 1) % i == 0) {
      ++ans;
      if (i * i != n - 1) ++ans;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100005
using namespace std;
int n,a[N],b[N];
void biu()
{
	puts("Impossible");
	exit(0);
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		scanf("%d",&a[i]),b[a[i]]++;
	sort(a+1,a+n+1);
	if (a[n]&1)
	{
		for (int i=1;i<=a[n]/2;i++)	
			if (b[i])biu();
		if (b[a[n]/2+1]!=2) biu();
		for (int i=a[n]/2+2;i<=a[n];i++)
			if (b[i]<2) biu();
		puts("Possible");
	}
	else
	{
		for (int i=1;i<a[n]/2;i++)	
			if (b[i])biu();
		if (b[a[n]/2]!=1) biu();
		for (int i=a[n]/2+1;i<=a[n];i++)
			if (b[i]<2) biu();
		puts("Possible");
	}
}

Measured memory_bytes: 256
n,x,y=map(int,input().split())
cnt=[0]*n
d=0
x-=1
y-=1
for i in range(n):
  for j in range(i+1,n):
    if x<=i<j<=y:
      d=min(j-i,i-x+1+y-j)
    elif i<=x<y<=j:
      d=min(j-i,x-i+1+j-y)
    elif x<=i<y<=j:
      d=min(j-i,i-x+1+j-y)
    elif i<=x<=j<=y:
      d=min(j-i,x-i+1+y-j)
    else:
      d=j-i
    cnt[d]+=1
print(*cnt[1:],sep='\n')

Measured memory_bytes: 47324
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n, m;
	char str[10001];
	
	while (scanf("%d %d", &n, &m) && n){
		memset(str, '#', sizeof(str));
		vector<int> used;
		str[n] = 0;
		for (int i = 0; i < m; i++){
			char p;
			scanf(" %c", &p);
			
			if (p == 'A'){
				for (int pos = 0; pos < n; pos++){
					if (str[pos] == '#'){
						str[pos] = 'A';
						used.push_back(pos);
						break;
					}
				}
			}
			if (p == 'B'){
				bool seated = false;
				for (int pos = n - 1; pos; pos--){
					if (str[pos] == '#' && (pos == 0 || str[pos - 1] != 'A')){
						str[pos] = 'B';
						used.push_back(pos);
						seated = true; break;
					}
				}
				if (!seated)
					for (int pos = 0; pos < n; pos++){
					if (str[pos] == '#'){
						str[pos] = 'B'; used.push_back(pos);
						break;
					}
				}
			}
			if (p == 'C'){
				if (i == 0){
					if (n & 1){
						str[(n + 1) / 2 - 1] = 'C';
						used.push_back((n + 1) / 2 - 1);
					}
					else {
						str[n / 2] = 'C';
						used.push_back(n / 2);
					}
				}
				else {
					for (int pos = 0; pos < n; pos++){
						if (str[pos] != '#'){
							if (pos + 1 < n && str[pos + 1] == '#'){
								str[pos + 1] = 'C';
								used.push_back(pos + 1);
								break;
							}
							if (pos - 1 >= 0 && str[pos - 1] == '#'){
								str[pos - 1] = 'C';
								used.push_back(pos - 1);
								break;
							}
						}
					}
				}
			}
			if (p == 'D'){
				if (i == 0){
					str[0] = 'D';
					used.push_back(0);
				}
				else {
					sort(used.begin(), used.end());
					int maxDist = -1, maxPos = -1;
					for (int pos = 0; pos < n; pos++){
						if (str[pos] == '#'){
							int a = upper_bound(used.begin(), used.end(), pos) - used.begin() - 1;
							int b = upper_bound(used.begin(), used.end(), pos) - used.begin();
							int tDist = 999999;
							if (a != -1) tDist = min(tDist, pos - used[a]);
							if (b != used.size()) tDist = min(tDist, used[b] - pos);
							if (tDist > maxDist){
								maxDist = tDist;
								maxPos = pos;
							}
						}
					}
					str[maxPos] = 'D';
					used.push_back(maxPos);
				}
			}
			if (0) printf("%s\n", str);
		}
		printf("%s\n", str);
	}
}

Measured memory_bytes: 1052
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
//increase stack size
#pragma comment(linker, "/STACK:16777216")

ll mxm() {return LLONG_MIN;}
template<typename... Args>
ll mxm(ll a, Args... args) { return max(a,mxm(args...)); }

ll mnm() {return LLONG_MAX;}
template<typename... Args>
ll mnm(ll a, Args... args) { return min(a,mnm(args...)); }

template<class T> ostream& operator<<(ostream& os,vector<T> V){
	os<<"[ ";for(auto v:V)os<<v<<" ";return os<<"]";
}
template<class L,class R> ostream& operator<<(ostream& os,pair<L,R> P){
	return os<<"("<<P.first<<","<<P.second<<")";
}

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__,__VA_ARGS__)
template<typename Arg1>
void __f(const char* name,Arg1&& arg1){
	cout<<name<<" : "<<arg1<<endl;
}
template <typename Arg1,typename... Args>
void __f(const char* names,Arg1&& arg1,Args&&... args){
	const char* comma=strchr(names+1,',');cout.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1,args...);
}
#else
#define trace(...) 1
#endif

#define ld long double
#define pll pair<ll,ll>
#define ii pair<int,int>
#define vll vector<ll>
#define vii vector<ii>
#define vi vector<int>
#define vpll vector<pll>
#define vld vector<ld>
#define vvld vector<vld>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvpll vector<vpll>
#define vvii vector<vii>
#define I insert
#define F first
#define S second
#define pb push_back
#define endl "\n"
#define all(x)	x.begin(),x.end()

const int mod=1e9+7;
// 128 bit: __int128
inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int sub(int a,int b){a-=b;if(a<0)a+=mod;return a;}
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int power(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline int inv(int a){return power(a,mod-2);}

struct compare{
	bool operator() (const int &a,const int &b) const{
		return a>b;
	}
};

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cout<<setprecision(25);
	int n, k;
	cin >> n >> k;
	int ans = 0;
	vi ways(k + 1);
	for(int i = k; i >= 1; i--){
		int b = k / i;
		ways[i] = power(b, n);
		for(int j = i + i; j <= k; j += i)
			ways[i] = sub(ways[i], ways[j]);
		ans = add(ans, mul(ways[i], i));
	}
	cout << ans << endl;
}

Measured memory_bytes: 3688
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i = 0 ; i < n ; ++i)
#define rep1(i,n) for(int i = 1 ; i <= n ; ++i)
using namespace std;
typedef long long ll;
int n;
ll a[3010];
ll dp[3010][3010];
bool f[3010][3010];
ll rec(int i,int j){
  if(f[i][j]) return dp[i][j];
  f[i][j] = true;
  if(i==j) return dp[i][j] = a[i];
  return dp[i][j] = max( a[i] - rec(i+1,j) , a[j] - rec(i,j-1));
}
int main()
{
  cin >> n;
  rep(i,n) cin >> a[i];
  
  rep(i,n) rep(j,n) f[i][j] = false;

  cout << rec(0,n-1) << "\n";
  
  return 0;
}


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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge>>;

int main()
{
 int a, b;
 cin>> a>>b;
 if(a > b) {
     REP(i, a) cout << b;
 } else {
     REP(i,b) cout << a;
 }
 cout << endl;


}

Measured memory_bytes: 256
N=int(input())
A=[int(i) for i in input().split()]
a=[1-A[0]]
if a[0]<0:
    print(-1)
    exit()
for k in range(N):
    ak=a[-1]
    a.append(2*ak-A[k+1])
    if a[-1]<0:
        print(-1)
        exit()
    if a[-1]>10**17:
        break
M=len(a)
for k in range(N,0,-1):
    if k-1<M:
        A[k-1]=A[k-1]+min(A[k],a[k-1])
    else:
        A[k-1]=A[k-1]+A[k]
print(sum(A))

Measured memory_bytes: 20140
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstring>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) {
	if (a<b) { return gcd(b, a); }
	else if (a%b) { return gcd(b, a%b); }
	else { return b; }
}
int main() {
	ll N, M;
	cin >> N >> M;
  	ll x=5;
	ll sum = 1900 * M + 100 * (N - M);
  	sum*=pow(2,M);
	cout << sum << endl;
}








Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>

typedef long long ll;
using namespace std;

char S[20];

int main()
{
	int N;
	scanf("%d", &N);
	printf("%d\n", ((1 + N)*N) / 2);
	
	return 0;
}


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

int main(void){
    int N,T,i,j;
    int temp;
    int *a,*b;
    int ans=0,flag=0;
    //input
    scanf("%d%d",&N,&T);
    a = (int *)malloc(N * sizeof(int));
    b = (int *)malloc(N * sizeof(int));
    for(i=0;i<N;i++){
        scanf("%d %d",&a[i],&b[i]);
    }

    //sort
    for(i=0;i<N;i++){
        for(j=N-1;j>i;j--){
            if(a[j] < a[j-1]){
                temp=a[j];
                a[j]=a[j-1];
                a[j-1]=temp;
                temp=b[j];
                b[j]=b[j-1];
                b[j-1]=temp;
            }
        }
    }

    //seach a[i]<=T
    for(i=0;i<N;i++){
        if(b[i]<=T){
            ans=a[i];
            break;
        }
        else if(i==N-1){
            flag=1;
        }
    }

    if(flag==1){
        printf("TLE");
    }
    else{
        printf("%d",ans);
    }
}
            



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define LOOP(val, times)   for(val = 0; val < (times); val++)
int main(){
  int n;
  cin>>n;
  vector<int> a(n);
  int i;
  LOOP(i,n){
    cin>>a[i];
  }
  int maxa=a[0];
  int ans=1;
  for(int i=1;i<n;i++){
    
    if(maxa<=a[i]){
      ans++;
    }
    
    if(maxa<a[i]){
      maxa=a[i];
    }
  }
  cout<<ans<<endl;
}

    
    

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

using namespace std;

const int N = 2'500;

int n, m, p;
vector<pair<int, int>> g[N], g_rev[N];

int dist[N];
bool changed[N];

bool visited[N];

bool dfs(int u) {
    visited[u] = true;
    if (dist[u] != INT_MAX && changed[u]) {
        cerr << u << endl;
        return true;
    }
    for (auto vw : g_rev[u]) {
        int v = vw.first;
        if (visited[v]) continue;
        if (dfs(v)) return true;
    }
    return false;
}

int main() {
    cin >> n >> m >> p;
    for (int i = 0; i < m; ++i) {
        int a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        g[a].emplace_back(b, p - c);
        g_rev[b].emplace_back(a, p - c);
    }

    fill(dist, dist + n, INT_MAX);
    dist[0] = 0;
    for (int i = 0; i < n - 1; ++i) {
        for (int u = 0; u < n; ++u) {
            if (dist[u] == INT_MAX) continue;
            for (auto vw : g[u]) {
                int v, w;
                tie(v, w) = vw;
                dist[v] = min(dist[v], dist[u] + w);
            }
        }
    }

    for (int u = 0; u < n; ++u) {
        if (dist[u] == INT_MAX) continue;
        for (auto vw : g[u]) {
            int v, w;
            tie(v, w) = vw;
            if (dist[u] + w < dist[v]) changed[v] = true;
        }
    }

    if (dist[n - 1] == INT_MAX || dfs(n - 1)) {
        cout << -1;
    } else {
        cout << max(-dist[n - 1], 0);
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if ((a + b + c) >= 22) {cout << "bust" << endl;}
	else {cout << "win" << endl;}
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    
    public static boolean[] alr;
    
    public static List<List<Integer>> list = new ArrayList<>();

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        alr = new boolean[N];
        for (int i = 0; i < N; i++) {
            list.add(new ArrayList<>());
        }
        for (int i = 0; i < M; i++) {
            int A = sc.nextInt()-1;
            int B = sc.nextInt()-1;
            list.get(A).add(B);
            list.get(B).add(A);
        }
        int max = 0;
        for (int i = 0; i < list.size(); i++) {
            if (alr[i]) {
                continue;
            } else {
                alr[i] = true;
            }
            List<Integer> lst = list.get(i);
            int count = count(lst);
            max = Math.max(max, count);
        }
        System.out.println(max+1);
    }
    
    private static int count(List<Integer> lst) {
        int friends = 0;
        for (Integer i : lst) {
            if (alr[i]) {
                continue;
            } else {
                alr[i] = true;
                friends++;
            }           
            friends += count(list.get(i));
        }
        return friends;
    }
}


Measured memory_bytes: 101964
s = input()
lst = []
for c in s:
    lst.append(int(c))

for i in range(2**3):
    x = lst[0]
    s = format(i,'b').rjust(3,'0')
    
    for j in range(3):
        if s[j] == '1':
            x += lst[j+1]
        else:
            x -= lst[j+1]
    
    if x==7:
        ss = s
        break

ans = ''
for i in range(3):
    ans += str(lst[i])
    if ss[i] == '1':
        ans += '+'
    else:
        ans += '-'
else:
    ans += str(lst[3]) + '=7'
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>

using namespace std;

#define ll long long
#define db double
#define clr(a, b) memset(a, b, sizeof(a))

const int maxn = 5e5 + 10;
const int inf = 0x7ffffff;

void solve()
{
    ll x=100;
    ll n;
    int cnt = 0;
    cin >> n;
    while (1)
    {
        x = x*1.01;
        cnt++;
        if(n<=x)
        {
            cout << cnt << "\n";
            return;
        }
    }

}

int main()
{
    //freopen("out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T = 1;
    //cin >> T;
    while(T-- > 0)
        solve();

}

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

int main(){
    int N;
    cin >> N;
    int ans;
    ans = pow(N,3);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include<cstdio>
#include<cstdlib>
using namespace std;
const int maxn=200010;
char a[maxn],b[maxn];

int ca[4],cb[4],n,m,N,sx,sy;
int main(){
    scanf("%d%d",&n,&m);
    scanf("%d%d%d%s%s",&N,&sx,&sy,a+1,b+1);
    //puts(a+1);
    //puts(b+1);
    /*for(int i=1,x,y;i<=N;++i){
        if(a[i]=='L')++ca[0];
        else if(a[i]=='R')++ca[1];
        else if(a[i]=='U')++ca[2];
        else ++ca[3];
        if(sy+ca[1]-cb[0]>m){ans=1;break;}
        if(sy+cb[1]-ca[0]<=0){ans=1;break;}
        if(sx+ca[2]-cb[3]>n){ans=1;break;}
        if(sx+cb[2]-ca[3]<=0){ans=1;break;}
        if(b[i]=='L')++cb[0];
        else if(b[i]=='R')++cb[1];
        else if(b[i]=='U')++cb[2];
        else ++cb[3];
        if(sy+ca[1]-cb[0]>m){ans=1;break;}
        if(sy+cb[1]-ca[0]<=0){ans=1;break;}
        if(sx+ca[2]-cb[3]>n){ans=1;break;}
        if(sx+cb[2]-ca[3]<=0){ans=1;break;}
    }*/
    for(int i=1,y=sy;i<=N;++i){
        if(a[i]=='L')--y;
        if(y<=0)goto A;
        if(b[i]=='R'&&y<m)++y;
    }
    for(int i=1,y=sy;i<=N;++i){
        if(a[i]=='R')++y;
        if(y>m)goto A;
        if(b[i]=='L'&&y>1)--y;
    }
    for(int i=1,x=sx;i<=N;++i){
        if(a[i]=='D')++x;
        if(x>n)goto A;
        if(b[i]=='U'&&x>1)--x;
    }
    for(int i=1,x=sx;i<=N;++i){
        if(a[i]=='U')--x;
        if(x<=0)goto A;
        if(b[i]=='D'&&x<n)++x;
    }
    goto B;
    A:puts("NO");
    exit(0);
    B:puts("YES");
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcountll(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
using namespace std;
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
void vok()
{
    FAST
    FO
    FI
}
int main()
{
    vok();
    ll n,k;
    IN n>>k;
    vll a(n);
    bitset<50> b[n];
    loop(i,0,n)
    {
        IN a[i];
        bitset<50> temp(a[i]);
        b[i]=temp;
    }
    bitset<50> ans(0);
    rloop(i,49,0)
    {
        int countt=0;
        loop(j,0,n)
        {
            if(b[j][i])
            {
                countt++;
            }
          	//cout<<"";
        }
        ans[i]=1;
        if((countt*2)<n && ans.to_ullong()<=k)
        {
            //Do Nothing
        }
        else
        {
            ans[i]=0;
        }
    }
    ll fans=0LL;
    ll X=ans.to_ullong();
    loop(i,0,n)
    {
      	//cout<<"";
        fans+=(X^a[i]);
    }
    OUT fans<<endl
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
int solve(int,int);
int m[20];
int n;
int main(){
  int i,k,b,h[200];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&m[i]);
  }
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d",&h[i]);
  }
  for(i=0;i<k;i++){
  b=solve(0,h[i]);
  if(b==1) printf("yes\n");
  else if(b==0) printf("no\n");
  }
  return 0;
}


int solve(int j,int o)
{
  int res;
  if(o==0) return 1;
  if (j>=n){
    return 0;
  }
  res=solve(j+1,o) || solve(j+1, o-m[j]);
  return res;
}

Measured memory_bytes: 580
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <list>
#include <unordered_set>
#include <tuple>
#include <cmath>
#include <limits>
#include <type_traits>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <regex>
#include <random>
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
#define rep(i,n)for(ll i=0;i<n;++i)
#define exout(x) printf("%.10f\n", x)
const double pi = acos(-1.0);
const ll MOD = 1000000007;
const ll INF = 1e18;
const ll MAX_N = 201010;

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

ll dx[4] = { 0,0,-1,1 };
ll dy[4] = { -1,1,0,0 };
ll ans[110][110];
bool flag[2][110];
using edge = struct { ll to;ll cost; };
vector<edge>tree[101010];
ll depth[101010];

void dfs(ll v, ll p, ll d) {
	depth[v] = d;
	for (auto &nv : tree[v]) {
		if (nv.to == p)continue;
		dfs(nv.to, v, d + nv.cost);
	}
}

//long longしか使わない
//素数は1より大きい
//lower_boundは指定したkey以上の要素の一番左のイテレータをかえす
//upper_boundは指定したkeyより大きい要素の一番左のイテレータをかえす
int main() {
	ll n;
	cin >> n;
	rep(i, n-1) {
		ll a, b, c;
		cin >> a >> b >> c;
		a--, b--;
		tree[a].push_back({ b,c });
		tree[b].push_back({ a,c });
	}
	ll q, k;
	cin >> q >> k;
	k--;
	dfs(k, -1, 0);
	rep(i, q) {
		ll x, y;
		cin >> x >> y;
		x--, y--;
		cout << depth[x] + depth[y] << endl;
	}
	return 0;
}


Measured memory_bytes: 16080
N=int(input())
DX=list(map(int,input().split()))
D=DX[0]
X=DX[1]
A = [int(input()) for i in range(N)]
cnt=0
for j in range(len(A)):
    for k in range(D):
        if 1+A[j]*k>D:
            break;
        cnt=cnt+1

print(X+cnt)


Measured memory_bytes: 3060
import sys
from fractions import gcd

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
N = ir()
A = lr()
lcm = 1
answer = 0
for a in A:
    coef =  a // gcd(lcm, a)
    answer *= coef
    lcm *= coef
    answer += lcm // a

print(answer%MOD)


Measured memory_bytes: 67928
import sys
import math


def input():
    return sys.stdin.readline().rstrip()


def main():
    N=int(input())

    k=0
    for i in range(N):
        d,e =map(int,input().split())
        if e==d:
            k+=1
        else:
            k=0
        if k==3:
            print("Yes")
            exit()

    print("No")






if __name__ == "__main__":
    main()

# \n


Measured memory_bytes: 62088
import math
a,b,x = map(int,input().split())
if (a*a*b/2) < x:
  tan = 2*(a*a*b-x)/(a*a*a)
  arctan = math.atan(tan)
  print(math.degrees(arctan))
else:
  tan = a*b*b/(2*x)
  arctan = math.atan(tan)
  print(math.degrees(arctan))


Measured memory_bytes: 3060
from collections import deque
from heapq import heappop, heappush

import numpy as np

from numba import njit


@njit('UniTuple(i8[:],4)(i1[:],i8,i8,i8)')
def reachable(field, h2, w2, k):
    # 各マスから上下左右にどこまで行けるか
    hw = h2 * w2
    up = np.full(hw, -1, dtype=np.int64)
    dw = np.full(hw, -1, dtype=np.int64)
    lf = np.full(hw, -1, dtype=np.int64)
    rg = np.full(hw, -1, dtype=np.int64)
    lf_tmp = -1
    for i in range(w2, hw - w2):
        if field[i]:
            if lf_tmp == -1:
                lf_tmp = i
            lf[i] = max(lf_tmp, i - k)
        else:
            lf_tmp = -1
    rg_tmp = -1
    for i in range(hw - w2, w2 - 1, -1):
        if field[i]:
            if rg_tmp == -1:
                rg_tmp = i
            rg[i] = min(rg_tmp, i + k)
        else:
            rg_tmp = -1
    wk = w2 * k
    for j in range(1, w2):
        up_tmp = -1
        for i in range(j, hw, w2):
            if field[i]:
                if up_tmp == -1:
                    up_tmp = i
                up[i] = max(up_tmp, i - wk)
            else:
                up_tmp = -1
        dw_tmp = 0
        for i in range(hw - w2 + j, w2 - 1, -w2):
            if field[i]:
                if dw_tmp == -1:
                    dw_tmp = i
                dw[i] = min(dw_tmp, i + wk)
            else:
                dw_tmp = -1
    return up, dw, lf, rg


@njit('i8(i8,i8,i8,i1[:],i8,i8,i8,i8)')
def solve(h2, w2, k, field, x1, y1, x2, y2):
    s = x1 * w2 + y1
    t = x2 * w2 + y2
    up, dw, lf, rg = reachable(field, h2, w2, k)

    INF = 10 ** 18
    ans = [[INF, INF] for _ in field]
    ans[s][0] = ans[s][1] = 0

    q = [(0, s)]
    while q:
        cost, v = heappop(q)
        if v == t:
            return cost
        nc = cost + 1

        for u in range(up[v], v, w2):
            if ans[u][0] <= nc:
                break
            ans[u][0] = nc
            heappush(q, (nc, u))

        for u in range(dw[v], v, -w2):
            if ans[u][0] <= nc:
                break
            ans[u][0] = nc
            heappush(q, (nc, u))

        for u in range(lf[v], v, 1):
            if ans[u][1] <= nc:
                break
            ans[u][1] = nc
            heappush(q, (nc, u))

        for u in range(rg[v], v, -1):
            if ans[u][1] <= nc:
                break
            ans[u][1] = nc
            heappush(q, (nc, u))

    return -1


h, w, k = map(int, input().split())
x1, y1, x2, y2 = map(int, input().split())
h2 = h + 2
w2 = w + 2

field_tmp = [input() for _ in range(h)]
field = [0] * w2
for row in field_tmp:
    field.append(0)
    field.extend(map('@.'.index, row))
    field.append(0)
field.extend([0] * w2)
field = np.array(field, dtype=np.int8)
print(solve(h2, w2, k, field, x1, y1, x2, y2))


Measured memory_bytes: 549972
#include <bits/stdc++.h>
#define boost ios_base::sync_with_stdio(false), cin.tie(NULL);

using namespace std;
const int N = 500;
const int X[] = {1,0,-1,0,1,-1,1,-1};
const int Y[] = {0,1,0,-1,1,1,-1,-1};
const int mod = 1e9 + 7;
const long long INF = 1e15;
const int inf = 1e9;

long long a[N];

long long dp[N][N];

bool u[N][N];

long long pref[N];

long long sum (int l, int r) {
	if (l > r) return 0ll;
	return pref[r] - (l ? pref[l - 1] : 0ll);
}

long long solve (int l, int r) {
	if (l >= r) return 0ll;
	if (r - l == 1) return sum (l, r);
	if (u[l][r]) return dp[l][r];
	u[l][r] = 1;
	dp[l][r] = INF;
	for (int k = l ; k <= r - 1 ; ++ k) {
		dp[l][r] = min (dp[l][r], solve (l, k) + solve (k + 1, r) + sum (l, r));
	}
	return dp[l][r];
}

int main () {
	boost;
	int n;
	cin >> n;
	for (int i = 0 ; i < n ; ++ i) {
		cin >> a[i];
		pref[i] += a[i];
		pref[i + 1] = pref[i];
	}
	cout << solve (0, n - 1);
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
#define fr(x,i,n) for(int x = i; x < n; ++x)
#define fb(x,i,n) for(int x = i; x >= n; --x)
#define pr pair<int,int>
#define ll long long int
const int mod=1e9+7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string ans="No";
    int n;
    cin>>n;
    while(n>0){
        if(n%10==7)
        ans="Yes";
        n/=10;
    }
    cout<<ans;
}


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define sz(x) int(x.size())
using ll = long long;
const ll LLINF = numeric_limits<long long>::max();
const int mod = 1000000007;
const int INF = 1001001001;

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

int main()
{
    int k;
    cin >> k;
    int sum=0;
    for(int i=1;i<=k;i++){
        for(int j=1;j<=k;j++){
            for(int c=1;c<=k;c++){
                sum += GCD(i,GCD(j,c));

            }
        }
    }
    cout <<sum;
    return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;

/**
 * Prison
 */
public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            int N = sc.nextInt();
            int M = sc.nextInt();

            int L_MAX = 0;
            int R_MIN = N + 1;
            for (int i = 0; i < M; i++) {
                L_MAX = Math.max(L_MAX, sc.nextInt());
                R_MIN = Math.min(R_MIN, sc.nextInt());
            }

            if (L_MAX <= R_MIN) {
                System.out.println(R_MIN - L_MAX + 1);
            } else {
                System.out.println(0);
            }
        }
    }

}


Measured memory_bytes: 65240
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
#include <iomanip>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;


ll pow(ll a, ll b) {
  if (b == 0) {
    return 1;
  } else if (b % 2 == 0) {
    ll d = pow(a, b / 2);
    return (d * d) % MOD;
  } else {
    ll d = pow(a, b - 1);
    return (a * d) % MOD;
  }
}

ll fact[NMAX+1];
ll invfact[NMAX+1];

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

    fact[0] = 1;
    for(int i = 1; i <= NMAX+1; i++){
        fact[i] = fact[i-1]*i%MOD;
    }
    invfact[NMAX+1] = pow(fact[NMAX+1], MOD-2);
    invfact[0] = 1;
    for(int i = NMAX; i > 0; i--){
        invfact[i] = invfact[i+1]*(i+1)%MOD;
    }

    ll ans = 0;
    ll n = 1;
    while(n*3 <= s){
        ll diff = s - n*3;
        ll tmp = (fact[diff+n-1]*invfact[diff]) %MOD;
        tmp *= invfact[n-1];
        tmp %= MOD;
        ans += tmp;
        ans %= MOD;
        n++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5132
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int M = scan.nextInt();
        long digits_length = 0;
        long digits_sum = 0;
        for (int i = 0; i < M; i++) {
            int d = scan.nextInt();
            long c = scan.nextLong();
            digits_length += c;
            digits_sum += d * c;
        }
        long ans = (digits_length - 1) + (digits_sum - 1)/ 9;
        System.out.println(ans);
    }
}


Measured memory_bytes: 93204