akhauriyash/Code-Regression huggingface dataset:
def int_raw():
    return int(raw_input())

def ss_raw():
    return raw_input().split()

def ints_raw():
    return map(int, ss_raw())

INF = 1 << 29

N,Q  = ints_raw()
S = raw_input()
td =[]
for i in xrange(Q):
    td.append(ss_raw())
td = map(lambda b:(b[0],-1 if b[1]=="L" else 1),td)


def is_die_l(n):
    pos = n
    if pos < 0:
        return True
    for i in xrange(Q):
        if pos > N-1:
            return False
        if td[i][0]==S[pos]:
            pos+=td[i][1]
        if pos < 0:
            return True
    return False

def is_die_r(n):
    pos = n
    if pos > N-1:
        return True
    for i in xrange(Q):
        if pos < 0:
            return False
        if td[i][0]==S[pos]:
            pos+=td[i][1]
        if pos > N-1:
            return True
    return False

def ans():
    mostLeft = -1
    mostRight = N
    
    high = N-1
    if is_die_l(high):
        return 0
    while  (high-mostLeft)>1:
        mid = (mostLeft + high)/2
        if is_die_l(mid):
            mostLeft = mid
        else:
            high = mid
    mostLeft = high

    low =0 
    if is_die_r(low):
        return 0
    while  (mostRight-low)>1:
        mid = (mostRight + low)/2
        if is_die_r(mid):
            mostRight = mid
        else:
            low = mid
    mostRight = low
    
    return mostRight-mostLeft+1


print ans()


Measured memory_bytes: 56324
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
using ll = long long;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
}

void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}

vector<ll> divisor(ll n) {
    vector<ll> ret;
    for(ll 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);
}

int main() {
    ll N,K;
    cin >> N >> K;
    auto A = InputVec(N);
    ll sum = 0;
    for (int i = 0; i < N; ++i) {
        sum += A[i];
    }
    auto divs = divisor(sum);
    ll M = divs.size();
    for (int i = 0; i < M; ++i) {
        ll currentDiv = divs[M-1-i];
        //cout << currentDiv << endl;
        vector<ll> v;
        vector<ll> SS;
        for (int j = 0; j < N; ++j) {
            v.push_back(A[j] % currentDiv);
        }
        sort(v.begin(),v.end());
        SS.push_back(0);
        for (int k = 0; k < N; ++k) {
            SS.push_back(SS.back() + v[k]);
        }
        for (int k = 0; k < N; ++k) {
            ll A =SS[k];
            ll B = (N-k)*1ll*currentDiv-(SS[N]-SS[k]);
            if(max(A,B) <= K){
                cout << currentDiv << endl;
                return 0;
            }
        }

    }


}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        //最後の数値計算

        //入力部
        Scanner sc = new Scanner(System.in);
        int roopTimes = Integer.parseInt(sc.nextLine());

        int[] inputAllNumbers = new int[roopTimes + 1];//オーバーラン防止
        for (int i = 0; i < roopTimes; i++) {
            inputAllNumbers[i] = sc.nextInt();
        }


        //@TODO この書き方はまだ完全に理解しきれてないので要勉強
        //表記方法はメソッド参照(Java8からの書き方）、クラス名:メソッド名で呼び出す
        //あー、なんとなくわかった
        //これsortの方法としてStringのcompareToを呼び出してるってっていう、ものすごいストレートな書き方なんだな
        //いいなこれ、かっこいい

        //Hashsetの部分を通常の配列に変更
        Arrays.sort(inputAllNumbers,0,roopTimes);//0が末尾に来るようにしないと正しい答えが出ない

        System.out.println(countSearch(inputAllNumbers));
    }

    //線形探索メソッド
    //あんまり機能を詰め込むと汎用性がなくなるので、単純にカウントして回数を返すだけにする
    static int countSearch(int[] checkTarget) {
        int count = 0;

        for (int i = 0; i < checkTarget.length-1; i++) {
            if (checkTarget[i] == checkTarget[i+1]) {
                i++;
            }else{
                count++;
            }
        }
        return count;
    }
}


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

int main(){
  string s;
  cin >> s;
  if(s.at(0) == '7' || s.at(1) == '7' || s.at(2) == '7'){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 3616
#include <cstdio>
#include <string>
#include <vector>
#include <iostream>
#include <set>
#include <map>
#include <algorithm>
using namespace std;

int main(int argc, char **argv) {
    int n, k;
    scanf("%d%d", &n, &k);
    printf("%d\n", n - k + 1);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
using namespace std;
#define rep(i,x,n) for(int i=x;i<n;i++)
using ll=long long;

string ans;

void ps(int n,char a){
    for(int i=0;i<n;i++) ans+=a;
    return;
}

int sumd(int n){
    int res=0;
    while(n>0){
        res=n%10;
        n/=10;
    }
    return res;
}

int main(){
    int n,k;cin>>n>>k;
    int l[n];
    rep(i,0,n) cin>>l[i];
    sort(l,l+n,greater<int>());
    int ans=0;
    rep(i,0,k) ans+=l[i];
    cout<<ans<<endl;
}    

Measured memory_bytes: 888
from collections import defaultdict
import sys
input = sys.stdin.readline

s = input()
t = input()
ds = defaultdict(str)
dt = defaultdict(str)

ans = "Yes"
for c1, c2 in zip(s, t):
    if c1 not in ds:
        ds[c1] = c2
    else:
        if ds[c1] != c2:
            ans = "No"
    
    if c2 not in dt:
        dt[c2] = c1
    else:
        if dt[c2] != c1:
            ans = "No"
print(ans)

Measured memory_bytes: 3892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(long long i=0; i<(n); i++)
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; }


int main(){
    ll a,b,q; cin>>a>>b>>q;
    vector<ll> s(a), t(b);
    rep(i,a) cin>>s[i];
    rep(i,b) cin>>t[i];

    rep(i,q){
        ll x; cin>>x;
        auto itr1=lower_bound(s.begin(), s.end(), x);
        ll index1=itr1-s.begin();

        auto itr2=lower_bound(t.begin(), t.end(), x);
        ll index2=itr2-t.begin();

        vector<ll> tmp(4, 1e12);
        if(index1>0) tmp[0]=x-s[index1-1];
        if(index1<a) tmp[1]=s[index1]-x;

        if(index2>0) tmp[2]=x-t[index2-1];
        if(index2<b) tmp[3]=t[index2]-x;

        ll res=max(tmp[0], tmp[2]);
        chmin(res, max(tmp[1], tmp[3]));
        chmin(res, tmp[0] + 2 * tmp[3]);
        chmin(res, tmp[2] + 2 * tmp[1]);
        chmin(res, 2 * tmp[0] + tmp[3]);
        chmin(res, 2 * tmp[2] + tmp[1]);

        cout<<res<<endl;
    }
    return 0;
}

Measured memory_bytes: 2944
#include <stdio.h>


int main(void)
{	
	int i, n, a[100];
	
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf(" %d", &a[i]);
	}
	
	for(i=n-1; i>=0; i--){
		printf("%d", a[i]);
		if(i==0) break;
		printf(" ");
	}
	printf("\n");
	
	//getchar();
	//getchar();
	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>
#include <vector>
using namespace std;
#define PB push_back
const int N=1e5+10;
int two(int n){
    n<<=1;
    return n/10+n%10;
}
int main(){
    int a[10][2],n,m,temp;
    bool f=true,mul;
    vector<int> v;
    char c[N];
    scanf("%d",&n);
    scanf("%s",c);
    scanf("%d",&m);
    while(m--){
        scanf("%d",&temp);
        v.PB(temp);
    }
    for(int i=0;i<10;i++)a[i][0]=a[i][1]=0;
    a[0][!f]=1;
    mul=!(n&1);
    for(int i=0;i<n;i++){
        if(c[i]=='*'){
            for(int j=0;j<10;j++)a[j][f]=0;
            for(int j:v){
                temp=j;
                if(mul)temp=two(temp);
                for(int k=0;k<10;k++)a[k][f]+=a[(k+10-temp)%10][!f];
            }
        }
        else{
            temp=c[i]-'0';
            if(mul)temp=two(temp);
            for(int j=0;j<10;j++)a[j][f]=a[(j+10-temp)%10][!f];
        }
        f=!f;
        mul=!mul;
    }
    printf("%d\n",a[0][!f]);
}


Measured memory_bytes: 2848
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
	ll N,A,B; cin >> N >> A >> B;
	ll d = N/(A+B);
	ll r = N%(A+B);
	ll ans = d*A;
	if(r <= A) ans += r;
	else ans += A;
	cout << ans << endl;
}



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

using namespace std;

long long int MOD = 1000000007;

long long int dp[3300][3300];
int N;
string s;

int main(void) {

	cin >> N;

	s = "*";
	string tmp;
	cin >> tmp;
	s += tmp;

	for (int k = 0; k <= N - 1; k++) { dp[1][k] = 1; }

	for (int i = 2; i <= N; i++) {
		if (s[i-1] == '<') {
			for (int k = 1; k <= N; k++) {
				dp[i][0] += dp[i - 1][k]; dp[i][0] %= MOD;
				dp[i][k] += MOD-dp[i - 1][k]; dp[i][k] %= MOD; 
			}
		}
		else {
			for (int k = 0; k <= N; k++) {
				dp[i][k] += dp[i - 1][k]; dp[i][k] %= MOD;
				dp[i][k + N - k - i + 1] += MOD - dp[i - 1][k]; dp[i][k + N - k - i + 1] %= MOD;
			}
		}
		for (int k = 0; k <= N; k++) {
			dp[i][k+1] += dp[i][k];
			dp[i][k + 1] %= MOD;
		}
	}

	cout << (dp[N][0]+MOD)%MOD << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 78080
#include <bits/stdc++.h>
 
using namespace std;
 
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
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; }
 
const long long INF = 1LL << 60;
#define PI 3.14159265359 
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}
 
int gcd(int a, int b){
    if(b == 0) return a;
    else return gcd(b, a%b);
}
 
long long lcm (int a, int b){
    return  (long long) a*b /gcd(a,b);
}

long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }


int main(){
    int N,X,T;

    cin >> N >> X >> T;



    cout <<  ((N+(X-1))/X )*T <<  endl;
}



Measured memory_bytes: 3564
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define int int64_t
#define watch(x) cout << (#x) << " is " << (x) << endl

const int32_t MAX=1e9+7;
typedef vector<int> vi;
typedef vector<int64_t> vll;

int32_t main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed;

    //Problem code start

    string in;
    cin >> in;
    if(in[in.length()-1]=='s'){
        cout << in << "es";
    }else{
        cout << in << "s";
    }
    return 0;
}

Measured memory_bytes: 3552
s = input()

total_sum = 0
minus = 0
plus = 0
sum = 0

for i in s:
    if i == '<':
        if minus > 0:
            if plus < minus:
                sum = (int)((minus * (minus + 1) + plus * (plus - 1)) / 2)
            else:
                sum = (int)((minus * (minus - 1) + plus * (plus + 1)) / 2)
            minus = 0
            plus = 0
            total_sum = total_sum + sum
        plus = plus + 1
    else:
        minus = minus + 1

if plus < minus:
    sum = (int)((minus * (minus + 1) + plus * (plus - 1)) / 2)
else:
    sum = (int)((minus * (minus - 1) + plus * (plus + 1)) / 2)

print(total_sum + sum)


Measured memory_bytes: 4212
#include <queue>
#include <iostream>

using namespace std;

int main() {
    priority_queue<int> pq;
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        int t; cin >> t;
        pq.push(t);
    }
    while (m--) {
        int t = pq.top(); pq.pop();
        pq.push(t / 2);
    }
    long long ans = 0;
    while (pq.size()) {
        ans += pq.top(); pq.pop();
    }
    cout << ans << endl;
    return 0;
}

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

const int N = 100010;
typedef long long ll;

int a[N];
ll pre1[N], pre2[N];

int main(){
	int n, k;
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; ++ i){
		scanf("%d", &a[i]);
		pre1[i] = pre1[i - 1] + a[i];
		pre2[i] = pre2[i - 1] + std::max(a[i], 0);
	}
	ll ans = 0;
	for (int i = 1; i <= n - k + 1; ++ i){
		ans = std::max(ans, pre1[i + k - 1] - pre1[i - 1] + pre2[i - 1] + pre2[n] - pre2[i + k - 1]);
		ans = std::max(ans, pre2[i - 1] + pre2[n] - pre2[i + k - 1]);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
 
int main() {
  int n;
  cin >> n;
  map<char,int> now;
  string alpha = "abcdefghijklmnopqrstuvwxyz";
  rep(i,27) now[alpha[i]] = 51;
  rep(i,n){
    string a;
    map<char,int> b;
    rep(i,27) b[alpha[i]] = 0;
    cin >> a;
    rep(j,a.size()) b[a[j]] ++;
    for(auto j:b){
      now[j.first] = min(j.second,now[j.first]);
    }
  }
  char ans;
  for(auto i:now){
    if(i.second==51) continue;
    rep(j,i.second) cout << i.first;
  }
  cout << endl;
      
  
  return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>

using namespace std;

#define ALL(c) c.begin(),c.end()
#define RALL(c) c.rbegin(),c.rend()
#define SORT(x) sort((x).begin(),(x).end())
#define REP(i,x,y) for(int i=(x);i<(y);++i)
#define MP(a,b) make_pair((a),(b))
#define F_ first
#define S_ second

typedef long long int lli;
typedef pair<short,int> P;

const int INF=1<<30;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
//const long long int INF_=1<<60;

int M,N;
map<P,int> houses;
map<P,int> memo;

inline void MakeGraph(vector<vector<P> > &G,vector<vector<int> >&g){
	REP(y,0,N) REP(x,0,M){
		if(g[y][x]==1||g[y][x]==2){
			REP(i,0,4){
				int ny=y,nx=x;
				while(true){
					ny+=dy[i];
					nx+=dx[i];
					if(!(0<=ny&&ny<N&&0<=nx&&nx<M)) break;
					if(g[ny][nx]==1||g[ny][nx]==2){
						G[houses[MP(y,x)]].push_back(MP(i,houses[MP(ny,nx)]));
						break;
					}
				}
			}
		}
	}
}

inline int DFS(vector<vector<P> > &G,int house_num,int dir,int state){
	if((state&((1<<(houses.size()-1))-1))==((1<<(houses.size()-1))-1)&&house_num==0) return 1;
	int result1=0,result2=0;
	REP(i,0,G[house_num].size()){
		if(G[house_num][i].F_==dir&&(house_num==0||((state>>(house_num-1))&1)==1)) result1+=DFS(G,G[house_num][i].S_,dir,state);
		if((__builtin_popcount(state)>13||memo[MP(house_num,state)]==0)&&house_num!=0&&((state>>(house_num-1))&1)!=1){
			result2+=DFS(G,G[house_num][i].S_,G[house_num][i].F_,state|(1<<(house_num-1)));
		}
	}
	if(__builtin_popcount(state)<=13&&memo[MP(house_num,state)]==0) memo[MP(house_num,state)]=result2+1;
	return (__builtin_popcount(state)<=13?memo[MP(house_num,state)]:result2+1)+result1-1;
}

inline lli Solve(){
	houses.clear();
	memo.clear();
	vector<vector<int> > g(N,vector<int>(M));
	int cnt=1;
	REP(y,0,N) REP(x,0,M){
		cin >> g[y][x];
		if(g[y][x]==1){
			houses[MP(y,x)]=cnt;
			++cnt;
		}else if(g[y][x]==2) houses[MP(y,x)]=0;
	}
	vector<vector<P> > G(cnt);
	MakeGraph(G,g);
	lli ans=0;
	REP(i,0,G[0].size()){
		ans+=DFS(G,G[0][i].S_,G[0][i].F_,0);
	}
	return ans;
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	while(cin >> M >> N&&M&&N){
		cout << Solve() << endl;
	}
	return 0;
}

Measured memory_bytes: 49952
#include <iostream>
using namespace std;
int main()
{
  int gp[3][7] = {
    {1,3,5,7,8,10,12},
    {4,6,9,11},
    {2},
  };
  int x, y;
  cin >> x >> y;
  int xg= 0, yg = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < sizeof(gp[i])/sizeof(int); j++) {
      if (gp[i][j] == x) {
        xg = i;
      }
      if (gp[i][j] == y) {
        yg = i;
      }
    }
  }
  if (xg == yg) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3588
use proconio::input;
use std::cmp::Ordering;

fn main() {
    input! {
        k: usize,
        s: String,
    }

    solve(k, s);
}

fn solve(k: usize, s: String) {
    match s.len().cmp(&k) {
        Ordering::Greater => println!("{}...", &s[..k]),
        _ => println!("{}", s),
    }
}


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

int main() {
  int N,M;
  

  cin >> N >> M;
  
  if (N == M) {
    cout << "Yes" << endl;
  }
  else if (N != M) {
    cout << "No" << endl; 
  }
  
}

 











Measured memory_bytes: 256
<?php
fscanf(STDIN, '%d', $n);
$cnt = cnt753(7) + cnt753(5) + cnt753(3);
echo $cnt;

function cnt753($x)
{
    global $n;

    if ($x > $n) return 0;
    $sx = strval($x);

    $cnt = 0;

    if (substr_count($sx, '7') > 0 && substr_count($sx, '5') > 0 && substr_count($sx, '3') > 0) {
        $cnt++;
    }
    $cnt += cnt753((int) ('7' . $sx));
    $cnt += cnt753((int) ('5' . $sx));
    $cnt += cnt753((int) ('3' . $sx));
    return $cnt;
}

Measured memory_bytes: 5368
program ABC167_C
  integer(8)::N,M,X,cost,ans=10000000
  integer(8),allocatable::C(:),A(:,:),S(:)
  read(*,*)N,M,X
  allocate(C(N),A(N,M),S(M))
  do i=1,N
     read(*,*)C(i),A(i,:)
  end do
  do i=0,2**N-1
     S=0
     cost=0
     do j=0,N-1
        if(btest(i,j)) then  !iのj+1番目が1なら真
           do k=1,m
              S(k)=S(k)+A(j+1,k)
           end do
           cost=cost+C(j+1)
        end if
        if(minval(S)>=X) ans=min(cost,ans)
     end do
  end do
  if(ans==10000000) then
     write(*,*)'-1'
  else
     write(*,*)ans
  end if
end program ABC167_C

Measured memory_bytes: 2872
#include <iostream>

using namespace std;

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

	char X, Y;
	cin >> X >> Y;

	if (X > Y)
		cout << ">";
	else if (X == Y)
		cout << "=";
	else if (X < Y)
		cout << "<";
	
    return 0;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdio>
#include <complex>
#include <numeric>
#include <string.h>
#include <random>
#include <cmath>
#define rep(i,n) for (int i = 0; i < (int)n; i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<pi, pi> pp;
typedef pair<ll, ll> pl;
double PI = 3.141592653589793238462643383279;
const double EPS = 1e-9;
const ll MOD = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;

ll N, M, L;
ll D[300][300];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> M >> L;
    rep(i,N) rep(j,N) {
        D[i][j] = linf;
        if (i == j) D[i][j] = 0;
    }
    rep(i,M) {
        ll a, b, c; cin >> a >> b >> c;
        a--; b--;
        D[a][b] = c;
        D[b][a] = c;
    }
    rep(k,N) rep(i,N) rep(j,N) D[i][j] = min(D[i][j], D[i][k]+D[k][j]);
    rep(i,N) rep(j,N) D[i][j] = (D[i][j]<=L)?1:linf;
    rep(i,N) D[i][i] = 0;
    rep(k,N) rep(i,N) rep(j,N) D[i][j] = min(D[i][j], D[i][k]+D[k][j]);
    int Q;
    cin >> Q;
    rep(i,Q) {
        int S, T; cin >> S >> T;
        S--; T--;
        if (D[S][T] == linf) cout << -1 << endl;
        else cout << D[S][T]-1 << endl;
    }
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using PII = pair<ll,ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
ll MOD = 1000000007;

signed main() {
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    vector<vector<ll>> g(n);
    REP(i, n) FOR(j, i+1, n) {
        if(a[i] > a[j]) {
            g[i].push_back(j);
            g[j].push_back(i);
        }
    }

    ll cnt0, cnt1;
    vector<ll> col(n);
    function<bool(ll,ll)> dfs = [&](ll v, ll c) {
        if(c == -1) cnt0++;
        else cnt1++;
        col[v] = c;
        for(auto to: g[v]) {
            if(col[to] == c) return false;
            if(col[to] == 0 && !dfs(to, -c)) return false;
        }
        return true;
    };

    vector<PII> v;
    REP(i, n) {
        if(col[i] == 0) {
            cnt0 = cnt1 = 0;
            bool ret = dfs(i, -1);
            if(!ret) {
                cout << 0 << endl;
                return 0;
            }
            v.emplace_back(cnt0, cnt1);
        }
    }

    const ll sz = v.size();
    vector<ll> s(sz);
    REP(i, sz) s[i] = v[i].first + v[i].second;
    FOR(i, 1, sz) s[i] += s[i-1];

    vector<vector<ll>> dp(sz+1, vector<ll>(m+1));
    dp[0][0] = 1;
    REP(i, sz) REP(j, m+1) {
        if(j+v[i].first<=m && s[i]-j-v[i].first<=m) {
            (dp[i+1][j+v[i].first] += dp[i][j]) %= MOD;
        }
        if(j+v[i].second<=m && s[i]-j-v[i].second<=m) {
            (dp[i+1][j+v[i].second] += dp[i][j]) %= MOD;
        }
    }

    ll ret = 0;
    REP(i, m+1) (ret += dp[sz][i]) %= MOD;
    cout << ret << endl;
}


Measured memory_bytes: 101084
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>
#include<deque>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl
#define CE cout<<endl
#define pb push_back

ll n,m,a,b,c,x,y,z,aa[200010],ab[200010],ac[2];
bool r,ra,rb,rc[200010];
string s,sa,sb,sc;
char ca,cb,cc,cd[1010][1010];
vector<ll> va,vb,vc,vd,ve,vaa,vbb;
set<int> st;


int main(){
    cin>>s;
    if(s=="Sunny") C "Cloudy" E;
    if(s=="Cloudy") C "Rainy" E;
    if(s=="Rainy") C "Sunny" E;
}

Measured memory_bytes: 256
import sys
n = int(input())
m = int(input())

s = [m]
for i in range(1, n+1):
    a, b = map(int, input().split())
    m = m + a - b
    if m < 0:
        print(0)
        sys.exit(0)
    s.append(m)
print(max(s))


Measured memory_bytes: 5960
#include <stdio.h>

int main(void){
    int K,a,b,c,r,tmp,sum=0,i,j,k;
    
    scanf("%d",&K);
    
    for(i=1;i<=K;i++){
        for(j=1;j<=K;j++){
            for(k=1;k<=K;k++){
                
                a=i;
                b=j;
                c=k;
                
                
                if(a<b){
                    tmp=a;
                    a=b;
                    b=tmp;
                }
                
                r=a%b;
                while(r!=0){
                    a=b;
                    b=r;
                    r=a%b;
                }
                
                
                if(b<c){
                    tmp=b;
                    b=c;
                    c=tmp;
                }
                
                r=b%c;
                while(r!=0){
                    b=c;
                    c=r;
                    r=b%c;
                }
                
                sum=sum+c;
            }
        }
    }
    
    printf("%d\n",sum);
    
    return 0;
}

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

int main() {
    string s;
    cin >> s;
    int month = stoi(s.substr(5, 2));

    if (month > 4) cout << "TBD" << endl;
    else cout << "Heisei" << endl;

    return 0;
}


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

using namespace std;
string s[] = {"SUN" , "MON" , "TUE" , "WED" , "THU" , "FRI" , "SAT"};

int main()
{
    string t;  cin >> t;
        for(int i = 0;i<7;i++){
           if(t == s[i])  return cout << 7 - i , 0;
        }
    return 0;
}


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

int main() {
	int n, min = 10000000, max = -10000000;
	long long sum = 0;
	cin >> n;
	int i, b;

	for (i = 0; i < n; i++) {
		cin >> b;
		if (min > b) {
			min = b;
		}

		if (max < b) {
			max = b;
		}

		sum += b;
	}

	cout << min << " " << max << " " << sum << endl;

	return 0;
}


Measured memory_bytes: 3124
#include <iostream>
using namespace std;
long long a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z;
double A,B;
int main()
{
	cin>>n>>m;
	cout<<((n<m/2?n:m/2)+(h>m-n*2?h:m-n*2)/4)<<endl;
	return 0;
}

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;

const ll mod = 1000000007;
const double pi = 3.1415926535897932384626;

ll powmod(ll a, ll b) {ll res = 1; ll rem = a % mod; for (; b; b >>= 1) {if (b & 1) res = (res * rem) % mod; rem = (rem * rem) % mod;} return res;}

int main()
{
    //freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
    
    int n = 0;
    scanf("%d", &n);

    int _n = n;
    int __n = 0;

    for (int i = 1; i <= 3; ++i) {
	int a = n % 10;
	__n *= 10;
	__n += a;
	n /= 10;
    }

    if (_n == __n) puts("Yes");
    else puts("No");

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int n,ans=0;
    char s[50];
    
    scanf("%d",&n);
    scanf("%s",s);
    
    for(int i=0;i<n;i++){
        if(s[i]=='A'){
            if(i>n-2){break;}
            if(s[i+1]=='B'&&s[i+2]=='C'){ans++;}
        }
    }
    printf("%d",ans);
    
    return 0;
}


Measured memory_bytes: 128
import math
n = int(input())

def fac(m, p):
    step = 1 if p == 2 else 2
    for i in range(p, int(math.sqrt(m)+1), step):
        if m % i == 0:
            return i
    return m

result = str(n) + ":"
r = n
p = 2
while r != 1:
    p = fac(r,p)
    r = r//p
    result = result + " " + str(p)
print(result)

Measured memory_bytes: 7796
#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef unsigned long long ull;
int inf_int=2e9;
ll inf_ll=1e18;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define pb push_back
const double pi=3.1415926535898;
#define dout if(debug) cout
#define fi first
#define se second
#define sp setprecision
#define sz size()

bool debug=0;
const int MAXN=1e5+100000;
int mod=1e9+9;


#define rank asfalgalsglasgllzxdgl


void solve()
{
   int k,s;
   cin >> k >> s;
   ll ans=0;
   for(int i=0;i<=k && i<=s;++i)
   {
       int val=s-i;
       int l=max(val-k,0);
       int r=min(val,k);
       ans+=max(r-l+1,0);
   }
   cout << ans<<"\n";
}



#define FILE "stupid_rmq"
int main()
{
        #ifdef zxc
            freopen("input.txt","r",stdin);
    //       freopen("output.txt","w",stdout);
        #endif // zxc

    //    freopen(FILE".in","r",stdin);
   //   freopen(FILE".out","w",stdout);

       if(!debug)
       {
            ios_base::sync_with_stdio(0);
            cin.tie(0);
            cout.tie(0);
       }

        int t=1;
         while(t--)
            solve();

        return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<P ,ll> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9)+7;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int a, b;
    string s;
    cin >> s;
    
    a = stoi(s.substr(0,2));
    b = stoi(s.substr(2,2));
    if((a > 12 || a == 0) && b > 0 && b <= 12){
        cout << "YYMM" << endl;
    }
    else if (a > 0 && a <= 12 && (b > 12 || b == 0)){
        cout << "MMYY" << endl;
    }
    else if(a <= 12 && b <= 12 && a+b > 0){
        cout << "AMBIGUOUS" << endl;
    }
    else{
        cout << "NA" << endl;
    }
    return 0;
}

Measured memory_bytes: 384
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let s: String = read();

    let his = ["hi", "hihi", "hihihi", "hihihihi", "hihihihihi"];
    let ans = if his.contains(&&s.as_str()) {
        "Yes"
    } else {
        "No"
    };
    println!("{}", ans);
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
    vector<ll>x(5);
    for (int i = 0; i < 5; ++i) {
        cin >>x[i];
    }
    for (int j = 0; j <5; ++j) {
        if(x[j]==0)cout <<j+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
int main() {
	string s;
	cin >> s;
	while (s.size() > 1) {
		s.erase(s.size() - 1);
		if (s.size() % 2 == 0) {
			if (s.substr(0, s.size() / 2) == s.substr(s.size() / 2, s.size() / 2)) {
				cout << s.size() << endl;
				return 0;
			}
		}
	}
}

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

int main() {
  
  int N, Nd;
  int count = 0;
  int maxcount = 0;
  int max;
  cin >> N;
  
  for(int i=1; i <= N; i++) {
    Nd = i;
    count = 0;
    while((Nd % 2) == 0) {
        Nd = Nd / 2;
        count++;
    }
    if(maxcount <= count) {
      max = i;
      maxcount = count;
    }
  }
  
  cout << max << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
    long long int a, b, c;
    cin>>a>>b>>c;
    long long int d=c-a-b;
    if(d>=0&&4*a*b<d*d){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<set>
#include<cctype>
using namespace std;

int main(void){
	ios::sync_with_stdio(false); cin.tie(0);
	
	int i,k,a,b;
	cin>>k>>a>>b;
	if(a>=b-2){
		cout<<k+1<<endl;
		return 0;
	}
	long long int bis=1,money=0;
	for(i=0;i<k;i++){
		if(money>0){
			money--;
			bis+=b;
		}
		else if(i==k-1) bis++;
		else if(bis>=a){
			bis-=a;
			money++;
		}
		else bis++;
	}
	cout<<bis<<endl;
	
	
	
	
	
	return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("O3", "no-stack-protector")
//#pragma GCC target("sse4", "avx", "popcnt", "lzcnt", "sse3", "sse4.1", "sse4.2", "sse2", "tune=native")
//#pragma GCC optimize ("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using old = long double;

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, a, b;
    cin >> n >> a >> b;
    vector<int> cnt(3);
    while (n--) {
        int p;
        cin >> p;
        if (p <= a) {
            ++cnt[0];
        }
        if (p > a && p <= b) {
            ++cnt[1];
        }
        if (p > b) {
            ++cnt[2];
        }
    }
    cout << *min_element(cnt.begin(), cnt.end());
    return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    n=int(input())
    A=list(map(int,input().split()))
    cum_A=[0]*(n+1) #Aの[0,i)の和
    for i in range(1,n+1):
        cum_A[i]=cum_A[i-1]+A[i-1]
    dp=[[0]*(n+1) for _ in range(n+1)]  #[i,j)をまとめるために必要なコストの最小値
    for length in range(2,n+1):
        for i in range(n-length+1):
            j=i+length #右側
            res=10**20
            for k in range(i+1,j):#区間[i,k)と[k,j)に分ける
                res=min(res,dp[i][k]+dp[k][j])
            dp[i][j]=res+cum_A[j]-cum_A[i]
    print(dp[0][n])


if __name__=='__main__':
    main()

Measured memory_bytes: 41968
/*
by:-  
                     _ __ ___ 119574 
                    | '__/ __| 
                    | |  \__ \ 
                    |_|  |___/ 
                    

*/ 

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double db;
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i,n) for (ll i = 0; i < n; ++i) 
#define endl "\n"
const ll mod=1e9+7;
const db eps=1e-9;
const double pi=acos(-1);

void solve(){
    ll a,b,c;
    cin>>a>>b>>c;
    
    for(ll i=0;i<10;i++){
        c=c*a-b;
        cout<<c<<endl;
    }


	return;
}
signed main(){
	IOS;
	ll t=1;
// 	cin>>t;
	while(t--)solve();
fflush(stdout);return 0;
}

Measured memory_bytes: 256
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n = ii()
A = iil()

prod = 1
for item in A:
    prod *= item

frac = 0
for item in A:
    frac += prod//item

print(prod/frac)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int nth_bit(int64_t num, int n){
    return num&(1<<n);
}
 
int main(){
    int H, W, K;
    cin >> H >> W >> K;
    string S[6];
    for(int i=0; i<H; i++) cin >> S[i];
 
    int ans = 0;
    for(int a=0; a<(1<<H); a++) for(int b=0; b<(1<<W); b++){
        int cnt = 0;
        for(int i=0; i<H; i++) for(int j=0; j<W; j++) if(nth_bit(a, i) && nth_bit(b, j) && S[i][j] == '#') cnt++;
        if(cnt == K) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using P=pair<int,int>;
using G=vector<vector<int>>;
using ll=long long;

int main(){
  int n,k; cin>>n>>k;
  ll h[n+1000];
  for(int i=0;i<n;i++) cin>>h[i];
  vector<ll> dp(n+1000,100000000007);

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

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

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

using namespace std;

const ll mod=1000000007;
const ll inf=1e18;

int main(){

  ll a;
  string s;
  cin >> a >>s;
  if(a>=3200)cout << s << endl;
  else cout << "red" << endl;

}

Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=1e9+7;
ll fp(ll b, ll e){
	ll rs=1ll;
	for(;e>0;e/=2, b=(b*b)%mod)
		if(e%2==1) rs=(rs*b)%mod;
	return rs;
}
ll fc[2000005], iv[2000005];
ll c(int i, int j){
	ll res=(fc[i]*iv[j])%mod;
	res=(res*iv[i-j])%mod;
	return res;
}
int32_t main(){
	fc[0]=1ll;
	for(int i=1; i<2000005; i++) fc[i]=(fc[i-1]*i)%mod;
	iv[2000004]=fp(fc[2000004], mod-2);
	for(int i=2000003; i>=0; i--) iv[i]=(iv[i+1]*(i+1))%mod;
	int k, n; cin>>k;
	string s; cin>>s; n=s.size();
	ll ans=0ll;
	for(int i=n; i<=k+n; i++)
		(ans+=(c(k+n, i)*fp(25, k+n-i)))%=mod;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 36588
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) {
		try(BufferedReader bf = new BufferedReader(new InputStreamReader(System.in))){
			int max = 100010;
			//探索用配列
			int[] target = new int[max];
			Arrays.fill(target, 1);
			target[0] = 0;
			target[1] = 0;

			int sqrt = (int)Math.sqrt(target.length);
			for(int i=2; i<=sqrt; i++) {
				int firstNum = i;
				if (target[i] == 1) {
					for (int j=i*firstNum; j<target.length; j+=firstNum) {
						target[j] = 0;
					}
				}
			}
			int[] a = new int[max];
			for (int i=2; i<target.length; i++) {
				if(i%2==0) continue;
		        if (target[i]==1 && target[(i+1)/2]==1) {
		            a[i] = 1;
		        }
		    }
			//累積和
			int[] sum = new int[max+1];
			for(int i = 0;i < max;i++) {
				sum[i+1] = sum[i] + a[i];
			}
			//Query処理
			int Q = Integer.parseInt(bf.readLine());
			for(int q = 0;q < Q;q++) {
				String[] s = bf.readLine().split(" ");
				int l = Integer.parseInt(s[0]);
				int r = Integer.parseInt(s[1])+1;
				System.out.println(sum[r] - sum[l]);
			}
		}catch(IOException ioe) {
			ioe.getMessage();
		}
	}
}

Measured memory_bytes: 57148
/*
	Copyright: razouq (c)
	Author: Anass BENDARSI
	Date: 09/06/2017 12:59:05
	flamers will **** you
*/
#include<bits/stdc++.h>
//#include<flamers.h>
#define ull unsigned long long
using namespace std;

int main(){
	int a, b;
	cin>>a>>b;
	if(a + b >= 10) cout<<"error"<<endl;
	else cout<<a+b<<endl;
	return 0;
}


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

int findSumOfDigits(int n){
  int sum = 0;
  while (n > 0){
    sum += n % 10;
    n /= 10;
  }
  return sum;
}


int main(){
  int N, A, B;
  cin >> N >> A >> B;
  int counts, sum, one, ten, hund, thou, tenth;
  counts = 0;

  for (int i = 1; i <= N; i++){
    //one = i % 10;
    //ten = (i % 100 - one) / 10;
    //hund = ( i % 1000 - i % 100) / 100;
    //tenth = i / 10000;
    //thou = i / 1000 - tenth * 10;
    //sum = one + ten + hund + tenth + thou;
    sum = findSumOfDigits(i);
    if (sum >= A && sum <= B)
      counts += i;
  }
  cout << counts << endl;
}

Measured memory_bytes: 256
x,n = map(int,input().split())
if n == 0:
    print(x)
else:
    li = list(map(int,input().split()))
    for i in range(0, 101):
        up = x + i
        down = x - i
        if down not in li:
            print(down)
            break
        elif up not in li:
            print(up)
            break

Measured memory_bytes: 9216
from collections import Counter
def main():
    N = int(input())
    A = list(map(int, input().split()))
    m = max(list(Counter(A).values()))
    d = Counter(Counter(A).values())
    l = []
    t = 0
    for i in range(m, 0, -1):
        t += d[i]
        l.append(t)
    l.reverse()
    t = 0
    r = []
    for i in range(N):
        if m > i:
            t += l[i]
        r.append(t//(i+1))
    p = -1
    a = []
    for i, v in enumerate(reversed(r)):
        if p != v:
            a.append((v, N-i))
        p = v
    a.append((N, 0))
    t = 0
    aa = []
    for i in range(1, N+1):
        if a[t][0] < i:
            t += 1
        aa.append(a[t][1])
    for i in aa:
        print(i)
main()


Measured memory_bytes: 123568
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
	while(true){
		int H, W;
		cin >> H >> W;
		if(H == 0){
			return EXIT_SUCCESS;
		}
		for(int i = 0; i < H; i++){
			if(i % 2 == 0){
				for(int j = 0; j < W; j++){
					if(j %  2 == 0){
						cout  << '#';
					}else{
						cout << '.';
					}
				}
			}else{
				for(int j = 0; j < W; j++){
					if(j %  2 == 0){
						cout  << '.';
					}else{
						cout << '#';
					}
				}
			}
			cout << '\n';
		}
		cout << '\n';
	}
}



Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define loop(i,n) for(int i=0;i<n;i++)
int N, heights[100005], k;
int dp[100005];
int main()
{
    fill(dp, dp + 100004, 1000000000);
    cin >> N >> k;
    loop(i, N)
    {
        cin >> heights[i];
    }
    if (N == 1)
    { 
        cout << 0;
        return 0; 
    }
    //dp[1] += abs(heights[0] - heights[1]);
    dp[0] = 0;
    for (int i=1;i<N;i++)
    {
        loop(j, min(k,i)) 
        {
            dp[i] = min(dp[i], dp[i - j - 1] + abs(heights[i] - heights[i - j - 1]));
        }
    }
    //cout << dp[1] << " ";
    cout << dp[N - 1];
}

/*int main()
{

}*/



Measured memory_bytes: 1024
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var s = input.ReadLine();

        int b = 0;
        int r = 0;
        foreach(var c in s) {
            if (c == '0') b++;
            else r++;
        }

        return Math.Min(b, r)*2;
    }
}

Measured memory_bytes: 13140
import sys
n = int(input())
A = list(map(int,sys.stdin))
cnt = 0
G = [int((2.15**i-1)/1.15)for i in range(17,0,-1)]
G = [v for v in G if v <= n]
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        v = A[i]
        j = i - g
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j = j - g
            cnt += 1
        A[j+g] = v
for g in G:
    insertionSort(A, n, g)
print(len(G))
print(*G)
print(cnt)
print('\n'.join(map(str,A)))


Measured memory_bytes: 126016
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <utility>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <climits>
#include <numeric>
#include<stdio.h>
#include <queue>
#include <iomanip>
#include <float.h>
#include <set>
#include<functional>
#include <stack>
#include <time.h>
#include <climits>
#include <bitset>
#include <cmath>
using namespace std;
long long gcd(long long a, long long b) {
	if (a < b) gcd(b, a);
	long long  r;
	while ((r = a%b)) {
		a = b;
		b = r;
	}
	return b;
}
long long lcm(long long a, long long b) {
	return a / gcd(a, b) * b;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

long long modinv(long long a, long long mod) {
	long long b = mod, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t*b; swap(a, b);
		u -= t*v; swap(u, v);
	}
	u %= mod;
	if (u < 0) u += mod;
	return u;
}
inline long long mod(long long a, long long m) {
	return (a % m + m) % m;
}

// 拡張 Euclid の互除法
// ap + bq = gcd(a, b) となる (p, q) を求め、d = gcd(a, b) をリターンします
long long extGcd(long long a, long long b, long long &p, long long &q) {
	if (b == 0) { p = 1; q = 0; return a; }
	long long d = extGcd(b, a%b, q, p);
	q -= a / b * p;
	return d;
}

// 中国剰余定理
// リターン値を (r, m) とすると解は x ≡ r (mod. m)
// 解なしの場合は (0, -1) をリターン
//amari,mod,amari,mod
pair<long long, long long> ChineseRem(long long b1, long long m1, long long b2, long long m2) {
	long long p, q;
	long long d = extGcd(m1, m2, p, q); // p is inv of m1/d (mod. m2/d)
	if ((b2 - b1) % d != 0) return make_pair(0, -1);
	long long m = m1 * (m2 / d); // lcm of (m1, m2)
	long long tmp = (b2 - b1) / d * p % (m2 / d);
	long long r = mod(b1 + m1 * tmp, m);
	return make_pair(r, m);
}
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, l, q;
	cin >> n;
	int x[100005];
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	cin >> l >> q;
	int d[100004][30];
	for (int i = 0; i < n; i++) {
		if (l + x[i] >= x[n-1]) {
			d[i][0] = n - 1;
		}
		else {
			d[i][0] = upper_bound(x, x + n, l + x[i]) - x-1;
		}
	}
	for (int z = 1; z < 25; z++) {
		for (int i = 0; i < n; i++) {
			d[i][z] = d[d[i][z - 1]][z - 1];
		}
	}
	int a, b;
	for (int i = 0; i < q; i++) {
		cin >> a >> b;
		a -= 1;
		b -= 1;
		if (a > b) {
			swap(a, b);
		}
		int ub = n-1;
		int lb = 0;
		while (ub - lb > 1) {
			int mid = (ub + lb) / 2;
			int now = a;
			int mid2 = mid;
			while (mid2 > 0) {
				int tmp = 1;
				int cnt = 0;
				while (tmp <= mid2) {
					tmp *= 2;
					cnt += 1;
				}
				tmp /= 2;
				cnt -= 1;
				now = d[now][cnt];
				mid2 -= tmp;
			}
			if (now >= b)ub = mid;
			else lb = mid;
		}
		cout << ub<<"\n";
	}
}


Measured memory_bytes: 12928
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double db;
#define go(u) for(int i = head[u], v = e[i].to; i; i=e[i].lst, v=e[i].to)
#define rep(i, a, b) for(int i = a; i <= b; ++i)
#define pb push_back
#define re(x) memset(x, 0, sizeof x)
inline int gi() {
    int x = 0,f = 1;
    char ch = getchar();
    while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getchar();}
    while(isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 48; ch = getchar();}
    return x * f;
}
template <typename T> inline bool Max(T &a, T b){return a < b ? a = b, 1 : 0;}
template <typename T> inline bool Min(T &a, T b){return a > b ? a = b, 1 : 0;}
const int N = 1e5 + 7;
int n, Q, tp;
LL stk[N], val[N], ans[N];
void calc(LL x, LL v) {
	if(!x) return;
	int p = upper_bound(stk + 1, stk + 1 + tp, x) - stk - 1;
	if(!p) { ans[1] += v, ans[x + 1] -= v;}
	else {
		val[p] += (x / stk[p]) * v;
		calc(x % stk[p], v);
	}
}
int main() {
#ifdef fwat
	freopen("data.in", "r", stdin);
#endif
	scanf("%d%d", &n, &Q);
	stk[tp = 1] = n;
	rep(i, 1, Q) {
		LL x;
		scanf("%lld", &x);
		for(; tp && stk[tp] >= x; --tp);
		stk[++tp] = x;
	}
	val[tp] = 1;
	for(int i = tp; i >= 2; --i) {
		val[i - 1] += val[i] * (stk[i] / stk[i - 1]);
		calc(stk[i] % stk[i - 1], val[i]);
	}
	ans[1] += val[1];
	ans[stk[1] + 1] -= val[1];
	rep(i, 1, n) {
		ans[i] += ans[i - 1];
		printf("%lld\n", ans[i]);
	}
	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int n,a;
	cin>>n>>a;
	double loga = log(1.0*n);
	int ans = LINF;
	for(int k=0;k<=40;k++){
		int ng = 0, ok = (1LL<<40);
		while( ok - ng > 1 ){
			int mid = ( ok + ng ) / 2;
			double cur = log( 1.0 * mid ) * (k + 1);
			if( cur >= loga ){
				ok = mid;
			}
			else{
				ng = mid;
			}
		}
		int c = 1, cnt = 0;
		for(int i=1;i<=k+1;i++){
			c *= ok;
		}
		while( (c/ok)*(ok-1) >= n ){
			cnt++;
			c = (c/ok) * (ok-1);
		}
		int tmp = a*k + ok*(k+1) - cnt;
		if( ans > tmp ) ans = tmp;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 512
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String x = sc.next();
        long cnt = 0;
        long s = 0;
        int n = x.length();
        for (int i = 0; i < n; i++) {
            if (x.charAt(i) == 'S') {
                s++;
            }
            if (x.charAt(i) == 'T') {
                s--;
                if (s < 0) {
                    s = 0;
                    continue;
                }
                cnt++;
            }
        }
        long ans = n - 2 * cnt;
        System.out.println(ans);
    }
}


Measured memory_bytes: 28048
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;

int main(){
  int x,l,t[10],mi,ma;
  bool f;
  map<int,int> a;

  while(scanf("%d%d",&x,&l),x||l){
    a.clear();
    f = true;
    for(int n=1;f;n++){
      a[x] = n;
      for(int i=0;i<l;i++){
	t[i] = x%10; x /= 10;
      }

      sort(t,t+l);
      mi = ma = 0;
      for(int i=0;i<l;i++){
	mi *= 10; mi += t[i];
        ma *= 10; ma += t[l-1-i];
      }

      x = ma - mi;
      if(a[x]){
	printf("%d %d %d\n",a[x]-1,x,n-a[x]+1);
	f = false;
      }
    }
  }
}

Measured memory_bytes: 0