akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rint register int 
#define IL inline
#define rep(i,h,t) for (ll i=h;i<=t;i++)
#define dep(i,t,h) for (ll i=t;i>=h;i--)
#define ll long long
const int N=1e6;
ll a[N],b[50],n,k,c[50],dp[50][2];
int main()
{
  ios::sync_with_stdio(false);
  cin>>n>>k;
  rep(i,1,n)
  { 
    cin>>a[i];
    dep(j,40,0)
      if ((a[i]>>j)&1) b[j]++;
  }
  dep(j,40,0)
    if ((k>>j)&1) c[j]=1;
  dp[41][1]=-1e18;
  dep(j,40,0)
  {
    if (c[j]==0)
    {
      dp[j][1]=dp[j+1][1]+max(b[j],n-b[j])*(1ll<<j);
      dp[j][0]=dp[j+1][0]+b[j]*(1ll<<j); 
    } else
    {
      dp[j][1]=max(dp[j+1][1]+max(b[j],n-b[j])*(1ll<<j),dp[j+1][0]+b[j]*(1ll<<j));
      dp[j][0]=dp[j+1][0]+(n-b[j])*(1ll<<j);
    }
  } 
  cout<<max(dp[0][0],dp[0][1])<<endl;
  return 0; 
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int n,a[200]={},cnt=0,ans=1e9;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a[i];
    cnt=0;
    while(a[i]%2==0) {
      cnt++;
      a[i]/=2;
    }
    ans=min(ans,cnt);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003,INF=1<<30;

int main(){
    
    int H,W,D;cin>>H>>W>>D;
    vector<pair<int,int>> A(H*W);
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            int a;cin>>a;a--;
            A[a]=make_pair(i,j);
        }
    }
    vector<int> dis[D];
    for(int i=0;i<D;i++){
        int sum=0;
        for(int j=0;i+j*D<H*W;j++){
            if(j) sum+=abs(A[i+(j-1)*D].first-A[i+j*D].first)+abs(A[i+(j-1)*D].second-A[i+j*D].second);
            dis[i].push_back(sum);
        }
    }
    
    int Q;cin>>Q;
    
    for(int i=0;i<Q;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        int p=a%D,x=a/D,y=b/D;
        cout<<dis[p][y]-dis[p][x]<<endl;
    }
}




Measured memory_bytes: 6144
N=int(input())
A=list(map(int,input().split()))
if N%2==0:
	for i in range (N):
		if A[i]%2 != 1:
			print(0)
			exit()
	print((2**(N//2))%(10**9+7))
else:
	for i in range (N):
		if A[i]%2!=0:
			print(0)
			exit()
	if min(A)!=0 or A.count(0)!=1:
		print(0)
		exit()
	else:
		print((2**((N-1)//2))%(10**9+7))

Measured memory_bytes: 13812
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
#include <set>
#include <map>
#include <unordered_map>
#include <cassert>
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define fast_io(); std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

int main(){
    int n;
    std::cin >> n;
    std::vector<int> a(n,0);
    rep(i,n) std::cin >> a[i];

    a.erase(std::unique(a.begin(), a.end()), a.end());

    int ans = 1;
    for(int i=1; i<a.size()-1; i++){
        if(a[i-1]<=a[i] && a[i]<=a[i+1]) continue;
        if(a[i-1]>=a[i] && a[i]>=a[i+1]) continue;
        ans++;
        i++;
    }

    std::cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3740
#include<iostream>
#include<cstdio>
#include<ios>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<string>
#include<list>
#include<utility>
#include<tuple>
#include<map>
#include<unordered_map>
#include<complex>
#include<set>
#define itn int
#define retrun return
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
using namespace std;
typedef long long llong;
llong gcd(llong a, llong b) {
	if (a < b) std::swap(a, b);
	if (a % b == 0) return b;
	else return gcd(b, a % b);
}
llong lcm(llong a, llong b) {
	llong g = gcd(a, b);
	return a * b / g;
}
const llong MOD = 1000000007;
typedef pair<int, int> pii;
//ここまで共通
llong A, B;
llong ANS = 1;
int main() {
	cin >> A >> B;
	llong C = gcd(A, B);
	llong D = C;
	for (llong i = 2; i <= C; i++) {
		if (C < i * i && i <= C) {
			ANS++;
			break;
		}
		if (C % i == 0) {
			ANS++;
		}
		while (C % i == 0) {
			C /= i;
		}
	}
	cout << ANS << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;
int main() {
  int A, B;
  cin >> A >> B;
  if (A < B) {
	  swap(A, B);
	}
  int ans = A + max(A - 1, B);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; ++i) cin >> a[i];
  auto b = a;
  sort(b.begin(), b.end());
  assert(a == b);
  a.erase(unique(a.begin(), a.end()), a.end());
  for(int i = 0; i < (int)a.size(); ++i) cout << a[i] << " \n"[i==(int)a.size()-1];

  return 0;
}


Measured memory_bytes: 3616
using System;
using System.Linq;
using System.Collections.Generic;
public class Hello
{

    public static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        int ans = 0;
        int max = -1;
        int count = 0;
        int stok = 0;
        for (int i = 1; i <= N; i++)
        {
            count = 0;
            stok = i;
            while (true)
            {
                if (stok % 2 == 1) break;
                stok = stok / 2;
                count++;
            }
            if (max < count)
            {
                max = count;
                ans = i;
            }
        }
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n;
int a[100100];
ll sum;
int ch[100100];//1:↑↑,0:↑↓

int main(){
	cin>>n;
	a[0]=0;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	a[n+1]=0;
	for(int i=0;i<=n;i++){
		sum+=(ll)abs(a[i+1]-a[i]);
	}
	for(int i=1;i<=n;i++){
		if((a[i]-a[i-1])*(a[i+1]-a[i])>0){
			ch[i]=1;
		}else{
			ch[i]=0;
		}
	}
	
	for(int i=1;i<=n;i++){
		if(ch[i]){
			cout<<sum<<endl;
		}else{
			cout<<sum-abs(a[i]-a[i-1])-abs(a[i+1]-a[i])+abs(a[i+1]-a[i-1])<<endl;
		}
	}
	return 0;
}
	

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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back
#define sqr(a) ((a) * (a))
#define sz(a) int(a.size())
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i = 0; i < int(n); i++) 
#define fore(i, l, r) for(int i = int(l); i < int(r); i++)

typedef long long li;
typedef long double ld;
typedef pair<int, int> pt;

template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.x << ", " << a.y << ")";
}

template <class A> ostream& operator << (ostream& out, const vector<A> &v) {
	out << "[";
	forn(i, sz(v)) {
		if(i) out << ", ";
		out << v[i];
	}
	return out << "]";
}

mt19937 rnd(time(NULL));
mt19937_64 rnd64(time(NULL));

const int INF = int(1e9);
const li INF64 = li(1e18);
const int MOD = INF + 7;
const ld EPS = 1e-9;
const ld PI = acos(-1.0);

const int N = (1 << 17) + 13;

int n, a, b;

bool read () {
	if (scanf("%d%d%d", &n, &a, &b) != 3)
		return false;
	return true;
}

int ans[N];

int del(int a, int x){
	return (a & ((1 << x) - 1)) | ((a & (~((1 << (x + 1)) - 1))) >> 1);
}

int ins(int a, int x, int val){
	return (a & ((1 << x) - 1)) | (val << x) | ((a & (~((1 << x) - 1))) << 1);
}

void calc(int l, int r, int a, int b){
	if (l == r - 2){
		ans[l] = a;
		ans[l + 1] = b;
		return;
	}
	int m = (l + r) / 2;
	int x = __builtin_ctz(a ^ b);
	int ax = del(a, x);
	int bx = del(b, x);
	int c = ax ^ 1;
	calc(l, m, ax, c);
	calc(m, r, c, bx);
	fore(i, l, m)
		ans[i] = ins(ans[i], x, (a >> x) & 1);
	fore(i, m, r)
		ans[i] = ins(ans[i], x, (b >> x) & 1);
}

void solve(){
	calc(0, 1 << n, a, b);
	
	bool ok = sz(set<int>(ans, ans + (1 << n))) == (1 << n);
	ok &= *max_element(ans, ans + (1 << n)) == (1 << n) - 1;
	ok &= (ans[0] == a);
	ok &= (ans[(1 << n) - 1] == b);
	forn(i, (1 << n) - 1) ok &= (__builtin_popcount(ans[i] ^ ans[i + 1]) == 1);
	
	if (ok){
		puts("YES");
		forn(i, 1 << n)
			printf("%d ", ans[i]);
		puts("");
	}
	else{
		puts("NO");
	}
}

int main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	
	int tt = clock();
	
#endif
	
	cerr.precision(15);
	cout.precision(15);
	cerr << fixed;
	cout << fixed;

#ifdef _DEBUG
	while(read()) {	
#else
	if(read()) {
#endif
		solve();
		
#ifdef _DEBUG
	cerr << "TIME = " << clock() - tt << endl;
	tt = clock();
#endif

	}
}

Measured memory_bytes: 7680
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
const long long MOD = 1000000007;
const long double pi = (acos(-1));
#define pb push_back

//最大最小の入れ替え
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (ll i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (ll i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

//切り上げの割り算は(a + b - 1) / bでできる

//ここから
int main(){
    ll N;
    cin>>N;
    vl vec(N);
    rep(i,N) vec[i]=i+1;
    vl P(N);
    vl Q(N);
    rep(i,N) cin>>P[i];
    rep(i,N) cin>>Q[i];
    ll p,q;
    ll count=0;
    do{
        count++;
        if(vec==P){
            p=count;
        }
        if(vec==Q){
            q=count;
        }
    }while(next_permutation(all(vec)));
    cout<<abs(p-q)<<endl;
}

Measured memory_bytes: 256
fn main() {
    proconio::input! {
    a:usize,
    b:[usize;a],
  }
    let mut c=1;
    let mut d=0;
    for i in 0..a {
        c=b[c-1];
        d+=1;
        if c==2 {println!("{}",d);std::process::exit(0)}
    }
    println!("-1");
}

Measured memory_bytes: 3540
#include "iostream"

using namespace std;
long long int N, M, K, Q, W, H;
long long int ans;

int main() {
	ios::sync_with_stdio(false);
	cin >> N;
	int num[100001] = {};
	bool used[100001] = {};
	used[1] = true;
	for (int i = 1; i <= N; i++)cin >> num[i];
	int current = num[1];
	ans = 1;
	while (!used[current]) {
		if (current == 2) {
			cout << ans << endl;
			return 0;
		}
		used[current] = true;
		current = num[current];
		ans++;
		
	}
	cout << "-1\n";
	return 0;
}

Measured memory_bytes: 768
import math

A, B, C, D = map(int, input().split())

#on which turn do they die
takahashi = math.ceil(A / D)
aoki = math.ceil(C / B)
#print(takahashi)
#print(aoki)

if takahashi >= aoki:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9160
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N = int(input())

def check_ans(nums):
    cnt = 0
    for num in nums:
        num = int(num)
        if num == cnt:
            cnt += 1
        elif num < cnt:
            pass
        else:
            return False
    return True

def make_anss(anss, n):
    new_anss = []
    ns = [str(i) for i in range(n + 1)]
    for ans in anss:
        for n in ns:
            p_anss = ans + n
            if check_ans(p_anss):
                new_anss.append(p_anss)
    return new_anss

anss = ["0"]
for i in range(N - 1):
    anss = make_anss(anss, i + 1)

dics = {
    "0": "a",
    "1": "b",
    "2": "c",
    "3":"d",
    "4":"e",
    "5":"f",
    "6":"g",
    "7":"h",
    "8":"i",
    "9":"j"
    }

for ans in anss:
    print(ans.translate(str.maketrans(dics)))




    

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

long long sum;
int a[200001],cnt[200001];

int main(){
	int n;
	cin>>n;
	for (int i=0;i<n;i++){
		cin>>a[i];
		cnt[a[i]]++;
	}
	for (int i=0;i<=n;i++)
		sum+=(long long)cnt[i]*(cnt[i]-1)/2;
	for (int i=0;i<n;i++)
		cout<<sum-cnt[a[i]]+1<<endl;
	return 0;
}

Measured memory_bytes: 3712
#include<iostream>
#include<cstdio>
#define MAX 100001
using namespace std;

int A[MAX];
int n;

void update(int x, int y){
    A[x] = y;
}

void find(int x, int y){
    
    int mini = A[x];
    
    for(int i=x; i<=y; i++){
        if( mini > A[i]){
            mini = A[i];
            //cout << mini << " ";
        }
        
        
    }
    cout <<mini << endl;
    
    
}


int main(){
    int q, a, b, com;
    
    int fir = 1;
    for(int i=0; i<31; i++){
        fir = fir*2;
    }
    fir = fir -1;
    
    cin >> n >> q;
    for(int i=0; i<n; i++){
        A[i]  = fir;
    }
    
    for(int i=0; i<q; i++){
        cin >> com >> a >> b;
        
        if(com == 0){
            update(a, b);
        }else if( com == 1){
            find(a,b);
        }
    }
    
    return 0;
}


Measured memory_bytes: 3468
#! /usr/bin/env python
# coding: utf-8


def slove(n, a1, a2):
    a3 = []
    for i in range(n):
        a1[i] = int(a1[i])
        a2[i] = int(a2[i])
        a3.append(0)
    a1.append(0)
    a2.append(0)
    a3.append(0)

    a = [a1, a2, a3]
    dp = [[0 for i in range(n+1)] for j in range(3)]

    dp[0][0] = a1[0]
    for i in range(2):
        for j in range(n):
            dp[i][j+1] = max(dp[i][j] + a[i][j+1], dp[i][j+1])
            dp[i+1][j] = max(dp[i][j] + a[i+1][j], dp[i+1][j])
            dp[i+1][j+1] = max(max(dp[i][j+1], dp[i+1][j]) + a[i+1][j+1], dp[i+1][j+1])

    return dp[1][n-1]

if __name__ == "__main__":
    n = int(input())
    a1 = input().split(" ")
    a2 = input().split(" ")

    print(slove(n, a1, a2))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=10000000007;
string s;
 bool ch(int i,char a){
    return (s[i]==a || s[i]=='?');
  }

int main(){
  string t;
  cin>>s>>t;
 
  string ans;
  rep(i,51) ans.append("z");
  string con=ans;
  rep(i,s.size()-t.size()+1){
    int c=0;
    string now=s;
    if(ch(i,t[0])){
      rep(j,t.size()){
        if(!(ch(i+j,t[j]))) break;
        now[i+j]=t[j];
        c++;
      }
    }
    if(c==t.size()){
      rep(j,s.size()){
        if(now[j]=='?'){
          now[j]='a';
        }
      }
      ans=min(now,ans);
    }
  }
  if(ans==con){cout<<"UNRESTORABLE"<<endl;}
  else{cout<<ans<<endl;}
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
    #include<ext/pb_ds/assoc_container.hpp> 
    #include<ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    using namespace std;
    template <typename T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
    #define int long long  
    typedef long double ld;
    #define pb push_back
    #define f(i,a,b) for(int i=a;i<b;i++)
    #define fd(i,a,b) for(int i=a-1;i>=b;i--)
    #define pf push_front
    #define fi first
    #define se second
    #define ps(x,y)         fixed<<setprecision(y)<<x
    #define INF 1e10
    const double pi=3.14159265358979323;
    const int mod=998244353;
    const int MAX=1000000+5;
    int p[MAX]={0};

     int gcd(int a, int b) 
    { 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
    } 
    void swap(int a,int b)
    {
      int temp=a;
      a=b;
      b=temp;
    } 
    int  binpow(int  a,int  b) 
    {
    int res = 1;
    while (b > 0) {
        if (b%2 == 1)
            res = (res * a)%mod;
        a = (a* a)% mod;
        b >>= 1;
    }
    return res;
}
    int modinv(int y)
    {
        return binpow(y,mod-2);
    }

    int fact[500000+5];
    void precal()
    {
    fact[0]=1;
    for(int i=1;i<500000+5;i++)
    {
        fact[i]=(i*fact[i-1])%mod;
    }
}
    bool isPrime(int n) 
    { 
    // Corner cases 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
   
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
    } 
    int mm[200000+5];
    int vis[200000+5]={0};
    signed main() {

 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);  
    #ifndef ONLINE_JUDGE
      if(fopen("INPUT.txt","r"))
      {
      freopen ("INPUT.txt" , "r" , stdin);
      freopen ("OUTPUT.txt" , "w" , stdout); 
      }
    #endif  
    // -------------------------------------Code starts here--------------------------------------------------------------------- 
    int t=1; 
   // cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        pair<pair<string , int>, int > p[n];
        f(i,0,n)
        {
            string a;
            int b;
            cin>>a>>b;
            p[i].fi.fi=a;
            p[i].fi.se=-1*b;
            p[i].se=i+1;
        }
        sort(p,p+n);
        f(i,0,n)
        {
            cout<<p[i].se<<endl;
        }
    }
}



Measured memory_bytes: 3640
s = input()
count_c = 0

if s[0] == 'A':
  if s[2:-1].count('C') == 1:
    for i in range(1, len(s)):
      if 97 <= ord(s[i]) <= 122:
        continue
      else:
        count_c += 1
      if count_c > 1:
        print("WA")
  else:
    print("WA")
else:
  print("WA")

if count_c == 1:
  print("AC")


Measured memory_bytes: 3060
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
using namespace std;

int main()
{
    const char *Positive = "Positive";
    const char *Negative = "Negative";
    const char *Zero = "Zero";

    int a, b;
    if (scanf("%d%d", &a, &b) < 2) return 0;

    if (0 < a && b != 0) printf("%s\n", Positive);
    else if (a <= 0 && 0 <= b) printf("%s\n", Zero);
    else if ((b - a + 1) % 2 == 0) printf("%s\n", Positive);
    else printf("%s\n", Negative);

    return 0;
}


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

using namespace std;

int main(int argc, const char *argv[]) {
  int h, w, cnt = 0;
  cin >> h >> w;

  vector<vector<char>> s(h, vector<char>(w));
  for (auto &r : s) {
    for (auto &c : r) {
      cin >> c;
      cnt += c == '#';
    }
  }

  vector<vector<int>> costs(h, vector<int>(w, -1));
  queue<array<int, 3>> q;
  q.push({0, 0, 0});
  while (!q.empty()) {
    auto [i, j, cost] = q.front();
    q.pop();
    if (i < 0 || i > h - 1 || j < 0 || j > w - 1 || costs[i][j] != -1 ||
        s[i][j] == '#') {
      continue;
    }

    costs[i][j] = cost;
    q.push({i - 1, j, cost + 1});
    q.push({i + 1, j, cost + 1});
    q.push({i, j - 1, cost + 1});
    q.push({i, j + 1, cost + 1});
  }

  int cost = costs[h - 1][w - 1];
  if (cost < 0) {
    cout << -1 << '\n';
  } else {
    cout << h * w - (cost + 1) - cnt << '\n';
  }

  return 0;
}

Measured memory_bytes: 3660
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
#include<map>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back
#define mod 1000000007


int N,Q;
char S[500010];
set<int> alphabets_appear[100];


signed main(){
    scanf("%lld %s %lld",&N,S,&Q);
    rep(i,N){
        alphabets_appear[S[i]-'a'].insert(i);
    }
    rep(i,Q){
        int type;
        scanf("%lld",&type);
        if(type==1){
            int t1;char t2;
            scanf("%lld %c\n",&t1,&t2);t1--;
            if(S[t1]==t2)continue;
            alphabets_appear[S[t1]-'a'].erase(t1);
            S[t1]=t2;
            alphabets_appear[t2-'a'].insert(t1);
        }else{
            int ans=0;
            int t1;int t2;
            scanf("%lld %lld\n",&t1,&t2);t1--;t2--;
            for(char i='a';i<='z';i++){
                auto itr=alphabets_appear[i-'a'].lower_bound(t1);
                if(itr==alphabets_appear[i-'a'].end())continue;
                //printf("%c:%lld-",i,*itr);
                if(*itr<=t2)ans++;
            }
            printf("%lld\n",ans);
        }
    }
    return 0;
}


Measured memory_bytes: 24192
#include <iostream>
#include <cctype>
#include <stdio.h>
using namespace std;

char ch;
int main(){
	long long count[30] = {0};
	int num;
	while(scanf("%c",&ch) != EOF){
		if(islower(ch)){
			num = ch-'a';
		}else if(isupper(ch)){
			num = ch-'A';
		}else{
			continue;
		}
		count[num]++;
	}
	for(int i=0;i<=25;i++){
		printf("%c : %d\n",'a' + i,count[i]);
	}
}


Measured memory_bytes: 3188
// abc134c: Exception Handling
#include <stdio.h>
#include <stdlib.h>
#define MAX 200000

int desc(const void *a, const void *b) {
  return *(int *)b - *(int *)a;
}

int main(){
  int n,a[MAX],s[MAX];
  scanf("%d",&n);

  for(int i=0;i<n;i++){
    scanf("%d,",a+i);
    s[i] = a[i];
  }

  qsort(s,n,sizeof(int),desc);

  for(int i=0;i<n;i++){
    int max = 0;
    if(a[i]==s[0]){
        max = s[1];
    }else{
      max = s[0];
    }
    printf("%d\n",max);
  }
  return 0;
}

Measured memory_bytes: 3120
S = input()
pos_a = -1
pos_z = -1
for i in range(len(S)):
  if S[i] == 'A' and pos_a < 0:
    pos_a = i
  if S[len(S)-i-1] == 'Z' and pos_z < 0:
    pos_z = len(S)-i-1
  if pos_a >= 0 and pos_z > 0:
    break
print(pos_z-pos_a+1)


Measured memory_bytes: 3516
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

N, K = getNM()

def cmb_1(n, r):
    if n < r:
        return 0
    r = min(n - r, r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

cnt = cmb_1(N - 1, 2) - K

if cnt < 0:
    print(-1)
    exit()

dist = [[float('inf')] * N for i in range(N)]
for i in range(N):
    dist[i][i] = 0
query = [[1, i] for i in range(2, N + 1)]

for a, b in combinations([i for i in range(2, N + 1)], 2):
    if cnt == 0:
        break
    query.append([a, b])
    cnt -= 1

print(len(query))
for i in query:
    print(*i)

"""
for a,b in query:
    dist[a - 1][b - 1] = 1
    dist[b - 1][a - 1] = 1

def warshall_floyd(dist):
    for k in range(N):
        # i:start j:goal k:中間地点でループ回す
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
    return dist

warshall_floyd(dist)

for i in dist:
    print(i)
"""

Measured memory_bytes: 85592
package main

import (
	"fmt"
)

func main() {

	var n, h, w int
	var a, b int
	count := 0

	fmt.Scan(&n, &h, &w)

	for i := 0; i < n; i++ {
		fmt.Scan(&a, &b)
		a /= h
		b /= w
		if a > b {
			count += b
		} else {
			count += a
		}
	}

	fmt.Println(count)

}


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

using namespace std;

typedef long long ll;

int main(){
	int n, a;
	cin >> n;
	int t[n+1];
	set<ll> s;
	ll ans = 0;
	for(int i = 0; i < n; i++)cin >> a, t[a] = i+1;
	for(int i = 1; i <= n; i++){
		ll l, u;
		auto itr = s.upper_bound(t[i]);
		if(itr == s.end())l = n+1;
		else l = *itr;
		if(itr == s.begin())u = 0;
		else u = *(--itr);
		s.insert(t[i]);
		ans += (t[i]-u)*(l-t[i])*i;
	}
	cout << ans << endl;
    return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void solve() {
    int N, K;
    cin >> N >> K;
    vector<int> p(N);
    for (int i=0; i<N; ++i) cin >> p[i];

    sort(p.begin(), p.end());
    int res = 0;
    for (int i=0; i<K; ++i) res += p[i];
    cout << res << '\n';
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
//typedef pair<int,int> P;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=1000000007;

int x;

int main(){
    cin>>x;

    cout<<!x<<endl;
}

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

int main(){
    int h;
    while(cin>>h){
        if(h==0) return 0;
        int ans=0;
        int s[11][5];
        for (int i = 0; i < h; i++)for(int j=0;j<5;j++)
        {
            cin>>s[i][j];
        }
        int ff=0;
        bool flag=true;
        while(flag){
            flag=false;
            int l=0,r=0;
            for(int i=0;i<h;i++){
                l=0,r=0;
                for(int j=1;j<5;j++){
                    if(s[i][j]!=0 && s[i][j]==s[i][j-1]) r=j;
                    else {
                        if(r-l>=2){
                            flag=true;
                            ans+=(int)(r-l+1)*(s[i][r]);
                            for(int k=i;k>0;k--){
                                for(int h=l;h<=r;h++){
                                    s[k][h]=s[k-1][h];
                                }
                            }
                            for(int h=l;h<=r;h++) s[0][h]=0;
                        }
                        l=j;
                    }
                }
                //r=4;
                if(4-l>=2){
                    flag=true;
                    ans+=(int)(4-l+1)*(s[i][4]);
                    for(int k=i;k>0;k--){
                        for(int h=l;h<=r;h++){  
                            s[k][h]=s[k-1][h];
                        }
                    }
                    for(int h=l;h<=r;h++) s[0][h]=0;
                }
            }
            //cerr<<l<<" "<<r<<endl;
        }
        /*cerr<<endl;
        for(int i=0;i<h;i++){
            for(int j=0;j<5;j++)cerr<<s[i][j]<<" ";
            cerr<<endl;
        }*/

        cout<<ans<<endl;
        
    }
}



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

int main(){
    int N,tf;
    cin >> N;
    string k;
    tf = 0;
    for (int i=0;i<N;i++){
        cin >> k;
        if(k == "Y"){
            tf = 1;
        }
    }
    if(tf == 1){
        cout << "Four" << endl;
    }
    else{
        cout << "Three" << endl;
    }
    return 0;
}

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

typedef long long llong;

int main(int argc, const char * argv[]) {
    int N;
    
    cin >> N;
    
    vector<llong> a(N * 3);
    for (llong i = 0; i < N * 3; i++) cin >> a[i];
    
    sort(a.begin(), a.end(), greater<llong>());
    
    llong sum = 0;
    for (llong i = 1; i < 2 * N; i+=2) {
        sum += a[i];
    }
    
    cout << sum << endl;
    
    return 0;
}

Measured memory_bytes: 2560
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;
use nalgebra::max;

#[fastout]
fn main() {
    input! {
    w: f64,
    h: f64,
    x: f64,
    y: f64
    }
    let ans = w * h / 2.0;
    let t = if w / 2.0 == x && h / 2.0 == y { 1 } else { 0 };
    println!("{} {}", ans, t);
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i, n) cin >> s[i];

    map<string, int> mp;
    rep(i, n) mp[s[i]]++;

    printf("AC x %d\n", mp["AC"]);
    printf("WA x %d\n", mp["WA"]);
    printf("TLE x %d\n", mp["TLE"]);
    printf("RE x %d\n", mp["RE"]);
    return 0;
}

Measured memory_bytes: 6360
#include <iostream>
#include <iomanip>
using namespace std;
int main(void){
    int a,b;
    while(1){
        cin>>a>>b;
        if(a==0){
            break;
        }
        for(int y=1;y<=a;y++){
            for(int x=1;x<=b;x++){
                if(y%2!=0){
                    if(x%2!=0){
                        cout<<"#";
                    }else{
                        cout<<".";
                    }
                }else{
                    if(x%2!=0){
                        cout<<".";
                    }else{
                        cout<<"#";
                    }
                }
            }
            cout<<endl;
        }
        cout<<endl;
    }
}


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

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

//prototype declaration
int getint();
long long getllint();
double getdint();
char getch();
void setstring(char *s);
void showint(int i);
void showllint(long long i);
void showdouble(double i);
void showchar(char c);
void showstring(char *s);

int myPower(int a, int n) { // aのn乗の計算
	int x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

int min(int a, int b) {
	return a < b ? a : b;
}

struct restInfo {
	char name[20];
	int value;
	int num;
};

int main(void) {
	int n, i, j, k;
	n = getint();
	struct restInfo restData[n], temp;
	ROOP(i, n) {
		scanf("%s %d", restData[i].name, &restData[i].value);
		restData[i].num = i+1;
	}
	for(i = 0;i < n - 1;i++){
		for(j = i + 1;j < n;j++){
			if (!strcmp(restData[i].name, restData[j].name)) {
				if (restData[i].value < restData[j].value) {
					temp = restData[i];
					restData[i] = restData[j];
					restData[j] = temp;
				}
			} else if (strcmp(restData[i].name, restData[j].name) > 0) {
				temp = restData[i];
				restData[i] = restData[j];
				restData[j] = temp;
			}
		}
	}

	ROOP(i, n) {
		showint(restData[i].num);
	}
	return 0;
}

int getint() {
	int i;
	scanf("%d", &i);
	return i;
}

long long getllint() {
	long long i;
	scanf("%lld", &i);
	return i;
}

double getdint() {
	double i;
	scanf("%lf", &i);
	return i;
}

char getch() {
	char c;
	scanf("%c", &c);
	return c;
}

void setstring(char *s) {
	scanf("%s", s);
}

void showint(int i) {
	printf("%d\n", i);
}

void showllint(long long i) {
	printf("%lld\n", i);
}

void showdouble(double i) {
	printf("%lf\n", i);
}

void showchar(char c) {
	printf("%c\n", c);
}

void showstring(char *s) {
	printf("%s\n", s);
}


Measured memory_bytes: 128
# ワープありなしでそれぞれBFSする

import sys
import itertools
from collections import deque

h, w = map(int, sys.stdin.readline().split())
cy, cx = map(lambda x: int(x)-1, sys.stdin.readline().split())
gy, gx = map(lambda x: int(x)-1, sys.stdin.readline().split())
graph = [list(sys.stdin.readline().rstrip()) for _ in range(h)]

distance = [[10**17 for _ in range(w)] for _ in range(h)]
walk = ((1,0), (0,1), (-1, 0), (0, -1))
warp = list(itertools.product(range(-2, 3), repeat=2))

que = deque()
que.append((cy, cx))
distance[cy][cx] = 0

while que:
    y, x = que.popleft()

    # ワープなしでBFS
    for dx, dy in walk:
        nx = x + dx
        ny = y + dy
        if (nx < 0) or (nx > w-1) or (ny < 0) or (ny > h-1): continue
        if (graph[ny][nx] == '.') and (distance[ny][nx] > distance[y][x]):
            distance[ny][nx] = distance[y][x]
            que.appendleft((ny, nx))

    # ワープ使用でBFS
    for dx, dy in warp:
        nx = x + dx
        ny = y + dy
        if (nx < 0) or (nx > w-1) or (ny < 0) or (ny > h-1): continue
        if (graph[ny][nx] == '.') and (distance[ny][nx] > distance[y][x]+1):
            distance[ny][nx] = distance[y][x]+1
            que.append((ny, nx))

print(distance[gy][gx] if distance[gy][gx] != 10**17 else -1)


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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

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

  int n, m;
  cin >> n >> m;

  vi h(n+1);
  rep(i,1,n+1) cin >> h[i];

  vi ans(n+1, 1);
  rep(i,0,m) {
    int a, b;
    cin >> a >> b;

    if (h[a] >= h[b]) ans[b] = 0;
    if (h[b] >= h[a]) ans[a] = 0;
  }

  cout << accumulate(all(ans), 0)-1 << '\n';
}

Measured memory_bytes: 3992
N,M = readline.chomp.split.map(&:to_i)
if N >= M
  puts '0'
  exit
end
xs = readline.chomp.split.map(&:to_i).sort
ds = (xs.size-1).times.each.map {|i| xs[i+1]-xs[i] }.sort
puts ds[0..(M-1-(N-1)-1)].inject(:+)


Measured memory_bytes: 11888
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
using namespace std;
int main() {
	int a, b, c, d, x, y;
	cin >> a >> b >> c >> d;
	if (a >= b)
		x = b;
	else
		x = a;
	if (c >= d)
		y = d;
	else
		y = c;
	cout << x + y << "\n";
}

Measured memory_bytes: 3588
N,K = map(lambda x: int(x),input().split())
r,s,p = map(lambda x: int(x),input().split())
T = input()
dic={}
for i in range(K):
  txt=""
  idx=i
  while idx<N:
    txt = txt+T[idx]
    idx += K
  dic[i] = txt
toWin = {"r":"p","s":"r","p":"s"}
scoretable = {"r":{"r":0,"s":0,"p":p},
              "s":{"r":r,"s":0,"p":0},
              "p":{"r":0,"s":s,"p":0},
             }
def katite(txt):
  best = txt.translate(str.maketrans({"r":toWin["r"],"s":toWin["s"],"p":toWin["p"]}))
  return best

def Score(txt):
  first = txt[0]
  prev_score = scoretable[first]
  nexthand = {"r":["s","p"],"s":["r","p"],"p":["s","r"]}
  
  for c in txt[1:]:
    next_score = {k:v for k,v in prev_score.items()}
    score = scoretable[c]#achievable score
    for prevhand in prev_score.keys():
      for nh in nexthand[prevhand]:
        s = score[nh]
        next_score[nh] = max(prev_score[prevhand]+s,next_score[nh])
    prev_score = next_score
  return prev_score
    
    
    
ans=0    

for i in range(K):
  #print(dic[i])
  ans += max(Score(dic[i]).values())

print(ans)



Measured memory_bytes: 15836
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pint = pair<int,int>;
ll mod = 1000000007,mod2 = 998244353;

void chmin(long long &a, long long b) { if (a > b) a = b; }
void chmax(long long &a, long long b) { if (a < b) a = b; }
const long long INF = 1LL<<60;
ll gcd(ll a,ll b){
    if(b == 0) return a;
    else return gcd(b,a%b);
}

//重みある時
using Edge = pair<int,int>;
using Graph = vector<vector<Edge> >;

vector<bool> beki(1010);

int main() {
    int n,ans = 0;
    string s;
    cin >> n >> s;
    for (int i = 0; i < s.size(); ++i) {
        if(s[i] != s[i+1]){
            ans++;
        }
    }

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


Measured memory_bytes: 512
//DPL_1B

#include <iostream>
using namespace std;

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

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

  int DP[N+1][W+1];

  for(int j=0; j<=W; j++){
    DP[0][j] = 0;
  }

  for(int i=1; i<=N; i++){
    for(int j=0; j<=W; j++){
      if(j<w[i-1]){
        DP[i][j] = DP[i-1][j];
      }else{
        if(DP[i-1][j]>DP[i-1][j-w[i-1]]+v[i-1]){
          DP[i][j] = DP[i-1][j];
        }else{
          DP[i][j] = DP[i-1][j-w[i-1]]+v[i-1];
        }
      }
    }
  }

  cout << DP[N][W] <<endl;

  return 0;

}

Measured memory_bytes: 7020
#include<bits/stdc++.h>
#define ll long long
#define inf 100000000
#define pii pair<ll,ll>
#define magic ios_base::sync_with_stdio(false);cin.tie(nullptr)
using namespace std;
#define forn(i,n) for(ll i=1;i<=n;i++)
#define forRn(i,n) for(ll i=n;i>=1;i--)
#define forz(i,n) for(ll i=0;i<n;i++)
#define forRz(i,n) for(ll i=n-1;i>=0;i--)
#define forab(i,a,b) for(ll i=a;i<=b;i++)
#define mod 10007
#define has 3
ll gcd(ll x,ll y){ return y==0?x:gcd(y,x%y); }
ll lcm(ll x,ll y){ return x/gcd(x,y)*y; }


int main(void)
{
    magic;
    ll N,D;
    cin>>N>>D;
    D*=2;
    D++;
    ll ans = 0;
    ans = N/D;
    if(N%D) ans++;
    cout<<ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long     ll;
#define fast          ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define last          freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fr            first
#define sc            second
#define lcm(a,b)      (a*b)/__gcd(a,b)
#define com(i,n)      for(int i=0;i<n;i++)
#define dom(i,n)      for(int i=1;i<=n;i++)
#define mom(i,n)      for(int i=n;i>=0;i--)
#define sortI(a,n)    sort(a,a+n)
#define sortD(a,n)    sort(a,a+n,greater<int>())
#define sortvi(a)     sort(a.begin(),a.end())
#define sortvd(a)     sort(a.begin(),a.end(),greater<int>())
#define sumall(a,x)   accumulate(a.begin(),a.end(),x)
#define pi            3.14159265358979323846264338327950
#define endl          '\n'
using namespace std;
int main()
{
     ll n;
     cin>>n;
     ll k=7%n;
     dom(i,n)
     {
          if(k%n==0)
          {
               cout << i << endl;
               return 0;
          }
          k=(k*10+7)%n;
     }
     cout << -1 << endl;
}


Measured memory_bytes: 3600
from collections import deque

h, w = map(int, input().split())
maze = [list(input()) for _ in range(h)]
direction = [(1, 0), (0, 1), (-1, 0), (0, -1)]

max_step = 0
for i in range(h):
    for j in range(w):
        largest_step = 0
#        print("start: ", i, j)
        if maze[i][j] == "#":
            continue
        visited = [[False] * w for _ in range(h)]
        plan = deque()
        step = 1
        plan.appendleft((i, j, step))
        visited[i][j] = True
        while plan:
            y, x, step = plan.pop()
            for next_direction in direction:
                next_y = y + next_direction[0]
                next_x = x + next_direction[1]
                if -1 == next_x or next_x == w or -1 == next_y or next_y == h or maze[next_y][next_x] == "#" or visited[next_y][next_x]:
                    continue
                visited[next_y][next_x] = True
                if step > largest_step:
                    largest_step = step
                plan.appendleft((next_y, next_x, step + 1))
        if largest_step > max_step:
            max_step = largest_step

print(max_step)


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); ++i)
const int N = 100000, ONE_KUURU = 12;

vector<double> E;

void init(){
    E.assign(N+1, 0.0);
    vector<vector<double> > dp(N+2, vector<double>(ONE_KUURU + 1));
    dp[1][0] = 1.0;
    for(int i=1; i<=N; ++i){
        E[i] += E[i-1];
        rep(j, ONE_KUURU){
            dp[i+1][j+1] += dp[i][j] * (1.0 / (1 << j));
            dp[i+1][0] += dp[i][j] * (1.0 - 1.0 / (1 << j));
            E[i] += dp[i][j] * (1.0 / (1 << j));
        }
    }
}

int main(){
    init();
    for(int n; cin >> n, n; cout << fixed << setprecision(9) << E[n] << '\n');
    return 0;
}

Measured memory_bytes: 14932
import itertools
data = []
for i in range(3):
    a,b = map(int,input().split())
    data.append([a,b])
    data.append([b,a])

seq = [1,2,3,4]
test = list(itertools.permutations(seq))
check = False
for i in range(len(test)):
    temp = True
    for k in range(3):
        if [test[i][k],test[i][k+1]] not in data:
            temp = False
            break
    if temp:
        check = True
        break
if check:
    print("YES")
else:
    print("NO")
    

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;

const long long INFLL = 1LL << 60;
const int INFI = 1000000000;


int main(){
    int D,N; cin >> D >>N;
    long long ans = pow(100,D)*N;
    if(N==100) ans = pow(100,D)*(101);
    cout << ans << endl;
}




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

struct MyList{
	int data;
	MyList *next;
};

class MyQueue{
	MyList *head;
	MyList *tail;
public:
	MyQueue();
	~MyQueue();
	void enqueue(int data);
	int dequeue();
	bool isEmpty();
};
MyQueue::MyQueue()
{
	head = NULL;
	tail = NULL;
}
MyQueue::~MyQueue()
{
	while (head)
		dequeue();
}
void MyQueue::enqueue(int data)
{
	if (!head){
		head = new MyList;
		head->data = data;
		head->next = NULL;
		tail = head;
		return;
	}

	tail->next = new MyList;
	tail = tail->next;
	tail->data = data;
	tail->next = NULL;
	return;
}
int MyQueue::dequeue()
{
	int temp;
	MyList *lTemp;

	if (!head){
		cout << "error" << endl;
		return 0;
	}
	if (!head->next){
		temp = head->data;
		delete head;
		head = NULL;
		tail = NULL;
		return temp;
	}
	temp = head->data;
	lTemp = head;
	head = head->next;
	delete lTemp;
	lTemp = NULL;
	return temp;
}
bool MyQueue::isEmpty()
{
	if (!head) return false;
	else return true;
}

int main()
{
	MyQueue *queue = new MyQueue;
	int x;
	int count = 1;

	while (true){
		cin >> x;
		if (!x) break;
		queue->enqueue(x);
	}

	while (queue->isEmpty()) cout << "Case " << count++ << ": " << queue->dequeue() << endl;

	return 0;
}

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

int main(void){
    int n;
    while(cin >> n, n){
        int k[110];
        for(int i=0; i<n; i++){
            cin >> k[i];
        }
        string s;
        cin >> s;
        for(int i=0; i<s.size(); i++){
            int p=0;
            if('a'<=s[i]&&s[i]<='z'){
                p=s[i]-'a';
            }
            else{
                p=s[i]-'A'+26;
            }
            p-=k[i%n];
            if(p<0){
                p+=52;
            }
            if(p<26){
                s[i]=p+'a';
            }
            else{
                s[i]=p+'A'-26;
            }
        }
        cout << s << "\n";
        
    }
}



Measured memory_bytes: 3184
#include<iostream>
#include<string>
#include<math.h>
using namespace std;
int main(){
    int N, X;
    int m[1010];
    int minm=1000;
    int count=0;
    cin >> N >> X;
    int Xrate=X;
    for(int i=0; i<N; i++){
        cin >> m[i];
        Xrate-=m[i];
        if(m[i]<minm){
            minm=m[i];
        }
        count++;
        //cout << "m[i]=" << m[i] << "    count=" << count << endl;
    }
    //cout << "Xrate=" << Xrate << endl;
    while(Xrate>=0){
        Xrate-=minm;
        count++;
        //cout << "Xrate=" << Xrate << "    count=" << count << endl;
    }
    cout << count-1 << endl;
    return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int W = int.Parse(input[0]);
            int a = int.Parse(input[1]);
            int b = int.Parse(input[2]);

            int left = (a < b) ? a : b;
            int right = (a > b) ? a : b;

            if (right <= left + W)
            {
                Console.WriteLine("0");
            }
            else
            {
                Console.WriteLine(right - (left + W));
            }
        }
    }
}


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

using namespace std;


#define PI 3.14159265
#define int long long



main(){


	int n, m, c; cin >> n >> m >> c;


	vector <int> b(m);

	vector < vector <int> > a(n, vector <int>(m));


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

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


	int cnt = 0;

	for(int i = 0; i < n; i++){
		int sum = 0;
		for(int j = 0; j < m; j++){
			sum += b[j] * a[i][j];
		}

		if(sum + c > 0){
			cnt++;
		}
	}


	cout << cnt << endl;


	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n,i,j,x,d1,d2,y;
    cin>>n>>x>>y;
    ll diff,res = y-x;
    vector<ll> a(n+1,0LL);
    for(i=1;i<=n;i++)
    {
    	for(j=i+1;j<=n;j++)
    	{
    		diff = j-i;
    		if(i<=x)
    		{
    			if(j<y)
    			{
    				d1 = diff; 
					d2 = (y-i)-res+1LL;
					d2+=(y-j);
				}
				else
				{
					d1 = diff;
	    			d1-=(res);
	    			d1++;
	    			d2 = diff;
				}
    		
    			diff = min(d1,d2);
			}
			else
			{
				if(j<y)
				{
					d1 = diff;
					d2 = i - x;
					d2++;
					d2 +=(y-j); 
				}
				else
				{
					d1 = diff;
					d2 = i - x;
					d2++;
					d2 +=(j-y);
				}
				
				diff = min(d1,d2);
			}
			a[diff]++;
	//		cout<<i<<" "<<j<<" "<<diff<<"\n";
		}
	}
	for(i=1;i<n;i++)
	{
		cout<<a[i]<<"\n";
	}
	return 0;
    
}

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

struct UnionFind {
	vector<int>data;

	UnionFind(int n) :data(n) { for (auto&& x : data)x = -1; }

	int find(int k) {
		if (data[k] < 0)return k;
		return data[k] = find(data[k]);
	}

	bool unite(int x, int y) {
		x = find(x), y = find(y);
		if (x == y)return false;
		if (data[x] > data[y])swap(x, y);
		data[x] += data[y];
		data[y] = x;
		return true;
	}

	int size(int k) {
		return -data[find(k)];
	}
};

int main() {
	int n, m; cin >> n >> m;
	UnionFind uf(n);
	int ans = n - m;
	while (m--) {
		int x, y, z; cin >> x >> y >> z;
		x--; y--;
		if (uf.find(x) == uf.find(y)) {
			ans++;
		}
		else {
			uf.unite(x, y);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640