akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
 
int E[6] = {3,0,-2,2,0,-3};
int N[6] = {1,4,0,0,-4,-1};
int lsp[6] = {0,1,2,-2,-1,0};
 
 
void DICE(int a,int d[]){
     
int d2[6];
int i;
 
    if(a == 0){
    for(i = 0;i < 6; i++){
        d2[i] = d[i + E[i]];
        }
        }   
    if(a == 1){
    for(i = 0;i < 6; i++){
        d2[i] = d[i + N[i]];
        }
        }   
    memcpy(d,d2,6 * sizeof(int));
}
 
 
void l_spin(int d[]){
    int d2[6];
    int i;
     
    for(i = 0; i < 6; i++){
        d2[i] = d[i + lsp[i]];
    }
     
    memcpy(d,d2,6 * sizeof(int));
}
 
 
 
 
int main(void){
    int d[6];
    int n, i, a, b;
     
 
 
    for(i = 0; i < 6; i++){
scanf("%d",&d[i]);
}
 
scanf("%d",&n);
 
 
for(i = 0; i < n; i++){
scanf("%d",&a);
scanf("%d",&b);
 
 
while(1){
    DICE(0,d);
    if(d[0] == a) break;
    DICE(1,d);
    if(d[0] == a) break;
}
 
 
while(1){
    l_spin(d);
    if(d[1] == b) break;
}
 
 
printf("%d\n",d[2]);
 
}
 
return 0;
}


Measured memory_bytes: 2048
import numpy as np
N,M = list(map(int,input().split()))

A=[]
B=[]
for n in range(N):
    A_ = list(input())
    A.append(A_)
    
for m in range(M):
    B_ = list(input())
    B.append(B_)
    
B=np.array(B)

ans='No'
for n1 in range(N-M+1):
    for n2 in range(N-M+1):
        check = np.array(A)[n1:n1+M,n2:n2+M]
        c=np.unique(check == B)
        
        if False not in set(c):
            ans='Yes'
            break
            
print(ans)

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

#define FastRead        ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl            "\n"
#define sq(x)           ((x)*(x))
#define pi              acos(-1.0)
#define NUM             1000005

typedef long long ll;


int main()
{
    FastRead

    ll x = 0,ans = 0;
    string s;

	cin >> s;

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

		if (s[i] == 'W') {
			ans += x;
		}
		else {
			x++;

		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3784
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>

using namespace std;



int main(){

    int n;
    cin >> n;
    int a;
    for(int i=0; i<n; i++){
        cin >> a;
        if(a%2 == 1){
            continue;
        }
        if(a%3 != 0 and a%5 != 0){
            cout << "DENIED" << endl;
            return  0;
        }
    }

    cout << "APPROVED" << endl;

}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

const ll lim = 100100;
using edge = struct{ll to; ll cost;};
vector<edge> tree[lim];
ll depth[lim];

void dfs(ll ver, ll par, ll dep){
    depth[ver] = dep;
    for (auto& e : tree[ver]) {
        if(e.to == par) continue;
        dfs(e.to, ver, dep+e.cost);
    }
}

int main(){
    int N; cin >> N;
    REP(i, N-1){
        ll a, b, c; cin >> a >> b >> c; a--; b--;
        tree[a].pb({b,c});
        tree[b].pb({a,c});
    }
    ll Q, K; cin >> Q >> K;
    K--;
    dfs(K, -1, 0);
    REP(i, Q){
        ll x, y; cin >> x >> y; x--; y--;
        cout << depth[x] + depth[y] << endl;
    }
    return 0;
}


Measured memory_bytes: 14336
n = gets.to_i
x,y = [],[]
n.times do
  xn,yn = gets.split(' ').map(&:to_i)
  x << xn
  y << yn
end
fact = (1..n).inject(:*)
pem = (0...n).to_a.permutation(n).to_a
s = []
sum = 0
pem.each do |ar|
  (1...n).each do |i|
    _x = x[ar[i]] -x[ar[i-1]]
    _y = y[ar[i]] -y[ar[i-1]]
    sum += Math.sqrt(_x**2+_y**2)
  end
end

puts sum/fact

Measured memory_bytes: 8188
#include <iostream>

using namespace std;

int main()
{
	int num[1000000];
	for (int i = 0; i < 1000000; i++) {
		num[i] = 1;
	}
	num[0] = 0;
	num[1] = 0;

	for (int i = 2; i < 1000000; i++) {
		for (int j = 2; i * j < 1000000; j++) {
			num[i * j] = 0;
		}
	}

	int n;
	while (cin >> n) {
		int ans = 0;
		for (int i = n; i >= 2; i--) {
			if (num[i]) {
				ans++;
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 5064
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll n, k; cin >> n >> k;
  vector<ll> vec(n+1);
  for (ll i = 0; i < n; i++) {
    ll a; cin >> a;
    vec[a]++;
  }
  sort(vec.begin(), vec.end(), greater<ll>());
  ll sum = 0;
  for (ll i = k; i <= n; i++) sum += vec[i];
  cout << sum << endl;

  return 0;
}



Measured memory_bytes: 4752
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
//const int mod = ;

int a, b;
int d[105][105];

bool ok(int i, int j, int x, int y) {
  int c = d[i][j] - i*x - j*y;
  for (int i1 = 1; i1 <= a; ++i1) for (int j1 = 1; j1 <= b; ++j1) {
    if (c + i1 * x + j1 * y < d[i1][j1]) {
      return 0;
    }
  }
//  cerr << i << ' ' << j << ' ' << x << ' ' << y << ' ' << c << endl;
  return 1;
}

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  cin >> a >> b;
  int maxd = 0;
  for (int i = 1; i <= a; ++i) for (int j = 1; j <= b; ++j) {
    cin >> d[i][j];
    maxd = max(maxd, d[i][j]);
    if ((i > 1 && d[i][j] < d[i-1][j]) || (j > 1 && d[i][j] < d[i][j-1])) {
      cout << "Impossible\n"; return 0;
    }
  }
  vector<vii> res(a + 1, vii(b + 1));
  int T = maxd;
  for (int i = 1; i <= a; ++i) for (int j = 1; j <= b; ++j) {
    bool found = 0;
    for (int x = 0; x <= T && !found; ++x) for (int y = 0; i*x+j*y <= d[i][j]; ++y) {
      if (ok(i, j, x, y)) {
        res[i][j] = pii(x, y);
        found = 1; break;
      }
    }
    if (!found) {
      cout << "Impossible\n"; return 0;
    }
  }
  cout << "Possible\n";
  int s = 0, t = 2 * (T + 1) - 1;
  vector<array<int, 3>> e;
  for (int i = 0; i < T; ++i) {
    e.push_back({i, i + 1, -1});
    e.push_back({t - i - 1, t - i, -2});
  }
  set<pii> used;
  for (int i = 1; i <= a; ++i) for (int j = 1; j <= b; ++j) {
    if (used.count(res[i][j])) continue;
    used.insert(res[i][j]);
    int c = d[i][j] - res[i][j].first * i - res[i][j].second * j;
    assert(c >= 0 && c <= 100);
    e.push_back({res[i][j].first, t - res[i][j].second, c});
  }
/*  for (int i = 1; i <= a; ++i) for (int j = 1; j <= b; ++j) {

  }*/
  cout << t + 1 << ' ' << e.size() << endl;
  for (auto v : e) {
    cout << v[0] + 1 << ' ' << v[1] + 1 << ' ';
    if (v[2] >= 0) cout << v[2];
    else cout << (v[2] == -1 ? "X" : "Y");
    cout << endl;
  }
  cout << s + 1 << ' ' << t + 1 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
static constexpr int MOD = 1000000007;

int64_t cnt[ 26 ];

int main() {
	ios_base::sync_with_stdio( false );
	cin.tie( nullptr );
	int n; cin >> n;
	string ss; cin >> ss;
	for ( auto c : ss )
		cnt[ c - 'a' ]++;
	int64_t ans = 1;
	for ( int i = 0 ; i < 26 ; ++ i )
		ans = ans * ( cnt[ i ] + 1 ) % MOD;
	ans += MOD - 1;
	cout << ans % MOD << '\n';
	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
const ll MOD = 1e9+7; ll LLINF = 1LL << 60; int INF = INT_MAX;

//

int main(){
      ll n; cin>>n;
      vector<ll> a(n);
      rep(i,0,n) cin>>a[i];
      ll ans=0;
      rep(i,0,n){
            ans+=a[i]-1;
      } 
      cout<<ans<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics;
using System.Dynamic;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;

namespace atcorder
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
            // 何通りあるか
            int ans = 0;
            for(int i = 0; i < N; i++)
            {
                for(int j = i + 1; j < N;j++)
                {
                    ans += intArray[i] * intArray[j];
                }
            }
            Console.WriteLine(ans);
        }
    } 
}


//文字配列の取得
//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];

//文字列の取得
//string s = Console.ReadLine();

//数字配列の取得
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];

//数字の取得
//int N = int.Parse(Console.ReadLine());

//リスト型(int)の取得
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());

//出力
//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.WriteLine(cnt);



Measured memory_bytes: 28304
#include <stdio.h>
#define MAX 100000

int binarySearch(int);

int S[MAX],T[MAX],n=0;

int main(){

	int i,q,count=0;

	scanf("%d",&n);

	for(i=0;i<n;i++){
		scanf("%d",&S[i]);
	}

	scanf("%d",&q);
	
	for(i=0;i<q;i++){
		scanf("%d",&T[i]);
	}

	for(i=0;i<q;i++){
		count += binarySearch(T[i]);
	}

	printf("%d\n",count);
	return 0;
}


int binarySearch(int key){
	int right=n,left=0,mid;

	while(left < right){
		mid = (left + right) / 2;
		if (S[mid] == key){
			return 1;
		}
		else if (key < S[mid]){
			right = mid;
		}
		else {
			left = mid + 1;
		}
	}
	return 0;
}

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

struct status{
  vector<int> ans;
  vector<long long> last;
};

bool operator< (pair<long long, status> l, pair<long long, status> r){
  if(l.first != r.first) return l.first < r.first;
  return l.first < r.first;
}

int main() {
  int d;
  cin >> d;
  vector<long long> c(26);
  for(int i = 0; i < 26; i++) cin >> c.at(i);
  vector<vector<long long>> s(d, vector<long long> (26));
  for(int i = 0; i < d; i++){
    for(int j = 0; j < 26; j++) cin >> s.at(i).at(j);
  }
  
  priority_queue<pair<long long, status>> beam;
  vector<int> an(0);
  vector<long long> la(26, 0);
  status sta = {an, la};
  beam.push({(long long)0, sta});
  for(int day = 0; day < d; day++){
    priority_queue<pair<long long, status>> now;
    
    while(beam.size() > 0){
      long long score = beam.top().first;
      auto state = beam.top().second;
      beam.pop();
      state.ans.push_back(0);
      
      for(int i = 0; i < 26; i++){
        long long sum = score;
        auto n = state;
        n.last.at(i) = day;
        n.ans.at(day) = i + 1;
        
        sum += s.at(day).at(i);
        for(int j = 0; j < 26; j++){
          sum -= c.at(j) * (day - n.last.at(j));
        }
        
        now.push({sum, n});
      }
    }
    for(int i = 0; i < 10; i++){
      if(now.size() <= 0) break;
      beam.push(now.top());
      now.pop();
    }
  }
  
  auto res = beam.top().second.ans;
  for(auto now : res) cout << now << endl;
}


Measured memory_bytes: 4460
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define RFOR(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define REP(i,n) FOR(i,0,(n))
#define REPS(i,n) FOR(i,1,(n)+1)
#define RREP(i,n) RFOR(i,0,(n))
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
#define FI first
#define SE second
#define PB push_back
#define EB emplace_back
#define SZ(x) (int)(x).size()
#define BN(x) ((1<<x)-1)
#define DUP(x,y) (((x)+(y)-1)/(y))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const ll mod = 1e9+7;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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

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 main () {
  int N; cin >> N;
  vll T(N); REP(i,N) cin >> T[i];

  ll ans = 1LL;
  REP(i,N) {
    ans = lcm(ans,T[i]);
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	private static Scanner sc=new Scanner(System.in);
	private static String a=sc.next();
	private static String b=sc.next();
	public static void main(String[] args){
		if((a.equals("H")&&b.equals("H"))||(a.equals("D")&&b.equals("D"))){
			System.out.println("H");
		}
		if((a.equals("H")&&b.equals("D"))||(a.equals("D")&&b.equals("H"))){
			System.out.println("D");
		}
	}
}

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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

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

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int N;
    string s;
    cin >> N >> s;
    int r = 0;
    for(int i = 0; i < N; ++i) {
        if(s[i] == 'R') ++r;
    }

    int res = 0;
    for(int i = 0; i < N; ++i) {
        if(s[i] == 'R' && i >= r) ++res;
    }
    cout << res << endl;
    return 0;
}



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

int main(int argc, char const *argv[]) {
  long int N;
  long int C[501], S[501], F[501];
  cin >> N;
  for (int i = 0; i < N-1; i++) cin >> C[i] >> S[i] >> F[i];

  for (int i = 0; i < N; i++) {
    int t = 0;
    for (int j = i; j < N-1; j++) {
      if (t < S[j]) t = S[j];
      else if (t%F[j] == 0) ;
      else t = t + F[j] - t%F[j];
      t += C[j];
    }
    cout << t << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N >> M;

	//vector<int> A(M*2);
	vector<int> res(N,0);
  	int temp1 = 0;
  	int temp2 = 0;
	for(int i=0;i<M;i++){
		cin >> temp1;
		cin >> temp2;
      	res.at(temp1-1)++;
      	res.at(temp2-1)++;
	}
	for(int i=0;i<N;i++){
		cout << res.at(i) << endl;
	}
}

Measured memory_bytes: 256
N = int(input())
p = tuple(map(int, input().split()))

cont = 0
ans = 0
for idx, pi in enumerate(p):
    i = idx + 1

    if i == pi:
        cont += 1
    else:
        ans += (cont + 1) // 2
        cont = 0

ans += (cont + 1) // 2
print(ans)


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

void solve() {
  int n, m, a, b;
  cin >> n >> m;
  vector<vector<int>> g(n);
  rep(i, m) {
    cin >> a >> b;
    --a; --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  
  int all_visit = (1 << n) - 1;
  function<int(int, int)> dfs = [&] (int u, int visit) {
    int res = 0;
    for (int v : g[u]) {
      int nvisit = visit | (1 << v);
      if (nvisit == visit) continue;
      if (nvisit == all_visit) {
        res += 1;
      } else {
        res += dfs(v, nvisit);
      }
    }
    return res;
  };
  cout << dfs(0, 1) << endl;
}

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

Measured memory_bytes: 256
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(3**12)


N = int(input())
S = list(map(int,input().split()))

num_query = int(input())
T = list(map(int,input().split()))

ans = 0
for i in range(num_query):
    tmp = T[i]
    L = 0
    R = len(S)-1
    mid = (L+R)//2

    while L <= R:
        if S[mid] == tmp:
            ans += 1
            break
        elif S[mid] > tmp:
            R = mid-1
        else:
            L = mid+1

        mid = (L+R)//2

print("%d"%(ans))


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

int cp(int n, int i, int j)
{
    if (done[i][j] == 1)
    {
        return memo[i][j];
    }

    int count = 0;
    ;
    rep(ee, n)
    {
        int y = ee + 1;
        // string s = to_string(y + 1);
        // int uj = s[s.size() - 1] - '0';
        // int ui = s[0] - '0'; //先頭
        int uj = 0;
        int ui = 0;
        uj = (y) % 10;
        int h = 0;
        while (y >= 10)
        {
            h++;
            y /= 10;
        }
        ui = y;

        if (ui == i && uj == j)
        {
            count += 1;
        }
    }
    memo[i][j] = count;
    done[i][j] = 1;
    return count;
}

int main()
{
    ll n;
    cin >> n;
    ll count = 0;
    rep(i, 10)
    {
        rep(j, 10)
        {
            int cij = 0; //先頭がiで後がj
            int cji = 0; //先頭がjで後がi
            if (i == 0)
            {
                continue;
            }
            cij = cp(n, i, j);

            cji = cp(n, j, i);
            count += cij * cji;
        }
    }
    cout << count << endl;
}

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

int main()
{

    long long int n,k,rem,ans;

    cin>>n>>k;

    if(n%k==0)
    	cout<<"0"<<endl;

    else
    {
    	rem=n%k;
    	ans=min(rem,abs(rem-k));
    	cout<<ans<<endl;
    }

return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

const int MM = 1e9 + 7;
const double eps = 1e-8;
const int MAXN = 2e6 + 10;

int n, m;

void prework(){

}

void read(){

}

void solve(int casi){
	ll x;
	cin>>x;
	ll y = x / 11;
	y *= 2;
	x %= 11;
	if (x == 0);
	else if (x <= 6) y++;
	else y += 2;
	cout<<y<<endl;
}

void printans(){

}


int main(){
	prework();
	int T = 1;
//	cin>>T;
	for(int i = 1; i <= T; i++){
		read();
		solve(i);
		printans();
	}
	return 0;
}




Measured memory_bytes: 256
main = do
  ns <- fmap (fmap (read :: String -> Int) . words) . lines <$> getContents
  let n = head $ head ns
  let a = head $ last ns
  putStrLn $ solve n a

solve :: Int -> Int -> String
solve n a = if calc n a then "Yes" else "No"

calc :: Int -> Int -> Bool
calc n a = m <= a
  where
    m = mod n 500

Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define sz(x) (int)x.size()
typedef pair<int,int>pii;
const int mxN=3e3+10,M=1e9+7;

double dp[mxN];
int n;
double x;
// LONG LONG CASE
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    dp[0]=1;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x;
        
        for(int j=i+1;j>=0;j--){
            //cout<<j<<" "<<dp[j]<<"\n";
            dp[j]=(j==0?0: dp[j-1]*x) + dp[j]*(1-x);
        }
    }
    double ans=0;
    for(int i=n/2+1;i<=n;i++){
        ans+=dp[i];
    }
    cout<<fixed<<setprecision(10)<<ans;

}

Measured memory_bytes: 256
//
//  main.cpp
//  ABC_171_D
//
//  Created by Joe Mori on 2020/06/24.
//  Copyright © 2020 Joe Mori. All rights reserved.
//

#include <iostream>
#include<bits/stdc++.h>
int main() {
    // insert code here...
    int N;
    std::vector <int>count(100101,0);
    std::cin>>N;
    long long int ans=0;
    std::vector<int>a(N);
    for(int i=0;i<N;i++){
        std::cin>>a[i];
        ans+=a[i];
        
    }
    std::sort(a.begin(),a.end());
    for(int i:a){
        count[i]++;
    }
    int Q;
    std::cin>>Q;
    int b,c;
    for(int i=0;i<Q;i++){
        std::cin>>b>>c;
        ans+=count[b]*c-count[b]*b;
        count[c]+=count[b];
        count[b]=0;
        std::cout<<ans<<std::endl;
    }
    return 0;
}


Measured memory_bytes: 4036
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";

vector<int> G[100005];

int main() {

    ll MOD = 1e9 + 7;
    CIN(ll, N);
    CIN(ll, K);
    vector<int> visits(N, 0);

    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    ll ans = K;
    visits[0] = 1;

    queue<int> q;
    q.push(0);

    while (!q.empty()) {
        int p = q.front();
        q.pop();

        ll temp = K - 2;
        if ( p == 0 ) temp = K - 1;

        for (int i = 0; i < G[p].size(); i++) {
            if (visits[G[p][i]] == 0) {
                ans = (ans * temp) % MOD;
                temp--;

                visits[G[p][i]] = 1;
                q.push(G[p][i]);
            }
        }
    }

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 6904
#include<stdio.h>
int main(){
	int n,k;
	while(scanf("%d%d",&n,&k)!=EOF){
		n=n+k;
		k=0;
		while(n!=0){
			n=n/10;
			++k;
		}
		printf("%d\n",k);
	}
	return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;

int const N = 50001;

/*void dfs(int u, int c)
{
    connect[u] = c;
    rep(i, G[u].size())
    {
        if (connect[G[u][i]] == -1)
        {
            dfs(G[u][i], c);
        }
    }
    return;
}*/

int main()
{
    int n, m;
    cin >> n >> m;
    int p[n] = {};
    vector<vector<int>> G(n, vector<int>());
    vector<int> connect(n, -1);
    rep(i, n)
    {
        cin >> p[i];
        p[i]--;
    }

    rep(i, n)
        connect[i] = -1;

    rep(i, m)
    {
        int x, y;
        cin >> x >> y;
        x--, y--;
        G[x].push_back(y);
        G[y].push_back(x);
    }
    int cnt = 0;

    rep(u, n)
    {
        if (connect[u] != -1)
            continue;
        queue<int> q;
        q.push(u);
        cnt++;
        while (!q.empty())
        {

            int v = q.front();
            connect[v] = cnt;
            q.pop();
            rep(i, G[v].size())
            {
                if (connect[G[v][i]] == -1)
                    q.push(G[v][i]);
            }
        }
    }

    int ans = 0;
    rep(i, n) if (connect[i] == connect[p[i]]) ans++;

    OP(ans);

    return 0;
}

Measured memory_bytes: 6528
n=int(input())
a=[int(i) for i in input().split()]
ans=chk=0
for i in a:
    ans+=abs(chk-i)
    chk=i
ans+=abs(a[-1])
for i in range(n):
    x=ans
    if i==0:
        x-=abs(a[0])
        x-=abs(a[0]-a[1])
        x+=abs(a[1])
    elif i==n-1:
        x-=abs(a[-1])
        x-=abs(a[-1]-a[-2])
        x+=abs(a[-2])
    else:
        x-=abs(a[i-1]-a[i])
        x-=abs(a[i+1]-a[i])
        x+=abs(a[i-1]-a[i+1])
    print(x)

Measured memory_bytes: 64236
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <climits>
using namespace std;

vector<long long int> arr;

long long count1=0;


 int one=0;

int main() {
    int n;
     cin>>n;
    for(int i =0; i<n; i++){
        long long a;
        cin>>a;
        arr.push_back(a);
        count1+=a;
        one+=n-1;
    }
    int flag=0;
   long long int mindiff= LLONG_MAX;
    long long int b=0;
    int point;
   for(int i =0; i<n;i++){
      b+=arr[i];
      long long a = abs(count1- b -b);

      if(a<mindiff){
          point =i;
          if(count1- b -b >0){
              flag=0;
              mindiff=a;
          }
          else
              flag=1;
              mindiff=a;
      }
      else{
          break;
      }


   }
   int c=0;
   for(int j=n-1; j>=0;j--){
      c+=arr[j];
       long long a =abs(count1-c-c);
       if(a<mindiff) {
           mindiff=a;
       }

   }

 

 
    cout<<mindiff;


    return 0;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rep(i,n) for(int (i)=1;(i)<=(int)(n);(i)++)
#define forn(i,n,m) for(int (i)=(n);i<=(int)(m);(i)++)
#define pb push_back
#define mp make_pair
#define re return
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
using namespace std;
const int INF=1e9;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef queue <int> qi;
int n;
int a[200200];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	sort(a,a+n);
	for(int i=0;i<n-1;i++)
		if(a[i]==a[i+1]){
			cout<<"NO"<<endl;
			return 0;
		}
	cout<<"YES"<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) { 
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }
bool f(int y, int m, int d) {
  if(y < 2019) return true;
  if(y > 2019) return false;
  return (m <= 4);
}
int main() {
  int y, m, d;
  scanf("%d/%d/%d", &y, &m, &d);
  TorF(f(y,m,d),"Heisei", "TBD");
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;
 
#define rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int A, B; std::cin >> A >> B;
  std::set<int> s; s.insert(1); s.insert(2); s.insert(3);
  s.erase(A); s.erase(B);
  std::cout << *s.begin() << std::endl;
  return 0;
}


Measured memory_bytes: 256
<?php
  list($o) = explode(" ", trim(fgets(STDIN)));
  list($e) = explode(" ", trim(fgets(STDIN)));

  $n=strlen($o);
  $n+=strlen($e);
  
  for($i=0;$i<$n;$i++){
    if($i%2==0){
      echo $o[intdiv($i,2)];
    }else{
      echo $e[intdiv($i,2)];
    }
  }

Measured memory_bytes: 16324
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a - b <= 1 && b - a <= 1) System.out.println("Yay!");
		else System.out.println(":(");
	}
}


Measured memory_bytes: 21844
N = int(input())
fn = [0]*N

for x in range(1,100):
  for y in range(1,100):
    for z in range(1,100):
      n=x**2+y**2+z**2+x*y+y*z+z*x
      if n<=N:
        fn[n-1]+=1

print(*fn,sep="\n")

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

int main(){
    int n;
    cin >> n;
    int ac=0, wa=0, tle=0, re=0;
    
    rep(i, n){
        string s;
        cin >> s;
        switch(s[0]){
            case 'A':
            ac++;
            break;
            case 'W':
            wa++;
            break;
            case 'T':
            tle++;
            break;
            case 'R':
            re++;
            break;
        }
    }
    
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
}

Measured memory_bytes: 3644
#include<iostream>
#include<queue>
#include<cassert>
using namespace std;
#define rep(i, n) for ( int i = 0; i < n; i++ )
int W, H;
char G[62][22];
bool stable, V[62][22];

pair<double, int> dfs(int y, int x, char ch){
  double c = 0.0;
  int cnt = 0;
  queue<pair<int, int> > Q;
  V[y][x] = true;
  pair<int, int> u;
  static const int dy[4] = {0, -1, 0, 1};
  static const int dx[4] = {1, 0, -1, 0};
  int ny, nx;
  int minx = x, maxx = x+1;
  for (Q.push(make_pair(y, x)); !Q.empty(); ){
    u = Q.front(); Q.pop();
    int b = u.first+1;
    if ( u.first == H-1 || (b < H && G[b][u.second] != '.' && G[b][u.second] != ch )){
      minx = min(minx, u.second);
      maxx = max(maxx, u.second+1);
    }
    c += u.second + 0.5;
    cnt++;
    rep(r, 4){
      ny = u.first + dy[r];
      nx = u.second + dx[r];
      if ( ny < 0 || nx < 0 || ny > H-1 || nx > W-1) continue;
      if ( V[ny][nx] ) continue;
      if ( G[ny][nx] == ch ){
	V[ny][nx] = true;
	Q.push(make_pair(ny, nx));
      } else if ( G[ny][nx] != '.' && r == 1 ) {
	pair<double, int> np = dfs(ny, nx, G[ny][nx]);
	c += np.first;
	cnt += np.second;
      }
    }
  }

  if ( ! ( minx < c/cnt && c/cnt < maxx ) ) stable = false;

  return make_pair(c, cnt);
}

main(){
  while( cin >> W >> H && W ){
    rep(i, H) rep(j, W) { cin >> G[i][j]; V[i][j] = false; }
    stable = true;
    rep(j, W){ 
      if ( G[H-1][j] != '.' ){
	dfs(H-1, j, G[H-1][j]);
	break;
      }
    }
    cout << (stable?"STABLE":"UNSTABLE") << endl;
  }
}

Measured memory_bytes: 0
// #define LOCAL
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;0 <= i; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x)+1; i++)
#define rreps(i,x) for(ll i = (ll)(x); 1 <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char c) {return to_string((string) &c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,m; cin >> n >> m;
    ll v,p; cin >> v >> p;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    sort(all(a), greater<>());
    vector<ll> sum(n+1);
    rep(i,n)sum[i+1] = sum[i] + a[i];
    map<ll, bool> mp;
    rep(i,n){
        ll k = min(v, n - i);
        ll t = v - k - p + 1;
        ll num = i - p + 1;
        if(i < p){
            mp[a[i]] = true;
            continue;
        }
        if(a[p-1] > a[i] + m){
            mp[a[i]] |= false;
            continue;
        }
        if((a[i] + m) * num - (sum[i] - sum[p-1]) < m * t){
            mp[a[i]] |= false;
            continue;
        }
        mp[a[i]] |= true;
        debug(i, a[i]);
    }

    ll ans = 0;
    rep(i,n){
        if(mp[a[i]])ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 8064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        if(s.matches("(hi)+")){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!$BDs=P;~$K%3%a%s%H%"%&%H(B!!
#ifdef DEBUG_
#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

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

    template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int mod = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);
const int MAX_H = 110, MAX_W = 110;
int H,W,N; 
int ans[MAX_H][MAX_W];

void proc(int x, int y, int a){
    if(a == 1){
        REP(i,x){
            REP(j,W){
                ans[i][j] = 1;
            }
        }
    }else if(a == 2){
        FOR(i,x,H) REP(j,H){
            ans[i][j] = 1;
        }
    }else if(a == 3){
        REP(i,H) REP(j,y){
            ans[i][j] = 1;
        }
    }else{
        REP(i,H) FOR(j,y,W){
            ans[i][j] = 1;
        }
    }
}

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    cin >> H >> W >> N;
    REP(i,N){
        int x,y,a; cin >> x >> y >> a;
        proc(x,y,a);
    }
    LL res = 0;
    REP(i,H){
        REP(j,W){
            if(ans[i][j] == 0) res++;

        }
    }
    cout << res << endl;

}

Measured memory_bytes: 256
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define ull unsigned long long
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
using namespace std;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b;
	cin>>a>>b;
	if (a * b % 2 == 1)cout << "Odd" << endl;
	else cout << "Even" << endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int main() {
	int a[5];
	for (int i=1;i<=4;i++) scanf("%d",&a[i]);
	sort(a+1,a+4+1);
	if (a[1]==1&&a[2]==4&&a[3]==7&&a[4]==9) puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <iomanip>
#include <cstring>
#include <math.h>
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
using namespace std;

int swap(int &a,int &b){
	int c;
	c=a;
	a=b;
	b=c;

	return 0;
}



int main(){
	while(1){
		int y,x;
		cin>>y>>x;
		if(x==0&&y==0)
			break;
		for(int i=1;i<=y;i++){
			for(int j=1;j<=x;j++){
				bool hen;
				hen=(j>1&&j<x);
				hen=hen&&(i>1&&i<y);
				if(hen)
					cout<<'.';
				else
					cout<<'#';

			}
			cout<<endl;
		}
		cout<<endl;

	}

	return 0;
}

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

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RFOR(i, a, b) for (int i = (int)(b - 1); i >= (int)(a); --i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x) * (x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
    int N, M;
    while (cin >> N >> M, N|M) {
        vector<pair<pii, string>> Q;
        REP(i, N) {
            string s;
            int era, western;
            cin >> s >> era >> western;
            Q.push_back({{western, era}, s});
            Q.push_back({{western-era+1, 1}, s});
        }
        SORT(Q);
        REP(i, M) {
            int q;
            cin >> q;
            if (q < Q[0].first.first || q > Q[SZ(Q)-1].first.first) {
                cout << "Unknown" << endl;
            } else {
                bool found = false;
                FOR(i, 1, SZ(Q)) {
                    if (Q[i-1].second == Q[i].second &&
                        Q[i-1].first.first <= q && q <= Q[i].first.first) {
                        int d = q - Q[i-1].first.first;
                        cout << Q[i-1].second << " " << Q[i-1].first.second + d << endl;
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    cout << "Unknown" << endl;
                }
            }
        }
    }
}

Measured memory_bytes: 3072
def solve():
    from collections import deque
    def dfs(start, turn=False):
        path = deque()
        path.append(start)
    
        bridge_lengths = deque()
        bridge_lengths.append(0)
        
        unvisited = [True] * (n + 1)
        unvisited[start] = False
        
        rest = core_islands_num - 1
        diameter = 0
        end_point = start
        
        while True:
            u = path[-1]
            for i, d in adj_list[u]:
                if unvisited[i]:
                    path.append(i)
                    unvisited[i] = False
                    rest -= 1
                    bridge_lengths.append(d)
                    break
            else:
                distance = sum(bridge_lengths)
                if diameter < distance:
                    diameter = distance
                    end_point = u
                if rest == 0:
                    break
                path.pop()
                bridge_lengths.pop()
    
        if turn:
            return diameter
        else:
            return end_point
    
    import sys
    file_input = sys.stdin
    while True:
        n = int(file_input.readline())
        if n == 0:
            break
        
        p = list(map(int, file_input.readline().split()))
        d = list(map(int, file_input.readline().split()))
        
        end_bridges_weight = 0
        core_islands_num = n
        adj_list = [[] for i in range(n + 1)]
        s = 1
        for i1, i2, b_l in zip(range(2, n + 1), p, d):
            if i1 not in p[i1-1:]:
                end_bridges_weight += b_l
                core_islands_num -= 1
            else:
                s = i1
                adj_list[i1].append((i2, b_l))
                adj_list[i2].append((i1, b_l))
        if p.count(1) == 1:
            del adj_list[2][0]
            end_bridges_weight += d[0]
            core_islands_num -= 1
        
        e = dfs(s)
        dm = dfs(e, turn=True)
        
        ans = sum(d) * 3 - end_bridges_weight * 2 - dm
        print(ans)

solve()


Measured memory_bytes: 6312
#include <iostream>

using namespace std;

int main() {
    int N, flag = 1, a;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> a;
        if (!(a & 1)) {
            if (!(a % 3 == 0 || a % 5 == 0)) {
                flag = 0;
                break;
            }
        }
    }
    if (flag) {
        cout << "APPROVED" << endl;
    } else {
        cout << "DENIED" << endl;
    }
}

Measured memory_bytes: 256
import sys,heapq
from collections import deque,defaultdict
printn = lambda x: sys.stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True  and False
R = 10**9 + 7
def ddprint(x):
  if DBG:
    print(x)

n,m = inm()
s = inl()
t = inl()
dp = [ [0] * (m+1) for i in range(n) ]
dp[0][0] = 1 if s[0]==t[0] else 0
for i in range(1,n):
    dp[i][0] = dp[i-1][0] + (1 if s[i]==t[0] else 0)
for j in range(1,m):
    dp[0][j] = dp[0][j-1] + (1 if s[0]==t[j] else 0)

sh = defaultdict(list)
for i in range(1,n):
    sh[s[i]].append(i)

for j in range(1,m):
    x = 0
    acc = [0] * (n+1)
    for z in sh[t[j]]:  # s[z]==t[j]
        x = (x+dp[z-1][j-1]+1)%R  # z>0
        acc[z] = x
    for i in range(1,n):
        acc[i] = (acc[i-1] if acc[i]==0 else acc[i])

    for i in range(1,n):
        x = dp[i][j-1]
        #for z in sh[t[j]]:  # s[z]==t[j]
        #  if z<=i:
        #    x = (x+dp[z-1][j-1]+1)%R  # z>0
        x += acc[i]
        if t[j]==s[0]:
            x += 1
        dp[i][j] = x%R

if DBG:
    for i in range(n):
        print(dp[i])
print((dp[n-1][m-1]+1)%R)


Measured memory_bytes: 76892
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
#define debug(x) cerr << x << endl
typedef long long ll;
typedef pair<ll, ll> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
int INF = 1001001001;

//Segment tree
struct SegmentTree
{
	int n = 1;
	vector<int> dat;

	SegmentTree(int N)
	{
		init(N);
	}

	void init(int n_)
	{
		while (n < n_)n *= 2;
		dat.resize(2 * n - 1);
		rep(i, sz(dat))dat[i] = 0;
	}

	void update(int k, int a) 
	{
		k += n - 1;
		dat[k] += a;
		while (k > 0)
		{
			k = (k - 1) / 2;
			dat[k] += a;
		}
	}

	int query(int a, int b, int k, int l, int r)
	{
		if (r <= a || b <= l)return 0;
		if (a <= l && r <= b)return dat[k];
		else
		{
			auto val_l = query(a, b, 2 * k + 1, l, (l + r) / 2);
			auto val_r = query(a, b, 2 * k + 2, (l + r) / 2, r);
			return val_l + val_r;
		}
	}
};

void solve()
{
	int n; cin >> n;
	string s; cin >> s;
	int q; cin >> q;
	vector<int> ans;
	vector<SegmentTree> segtrees(26,SegmentTree(n));
	rep(i, n)
	{
		segtrees[s[i]-'a'].update(i, 1);
	}
	rep(i, q)
	{
		int query;
		cin >> query;
		if(query == 1)
		{
			int iq;
			char cq;
			cin >> iq >> cq;
			iq--;
			segtrees[s[iq]-'a'].update(iq,-1);
			segtrees[cq-'a'].update(iq, 1);
			s[iq] = cq;
		}
		else
		{
			int l, r;
			cin >> l >> r;
			l--,r--;
			int tmp = 0;
			rep(i, 26)
			{
				if(segtrees[i].query(l,r+1,0,0,segtrees[i].n)>0)tmp++;
			}
			ans.push_back(tmp);
		}
	}
	rep(i, sz(ans))cout << ans[i] << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 111516