akhauriyash/Code-Regression huggingface dataset:
N,S = map(int,input().split())
A = list(map(int,input().split()))

mod = 998244353

dp = [[0]*(S+1) for _ in range(N)]

dp[0][0] = 2
if A[0] <= S:
    dp[0][A[0]] = 1

for i in range(1,N):
    for j in range(S+1):
        if j-A[i] >= 0:
            dp[i][j] = dp[i-1][j-A[i]] + 2*dp[i-1][j]
        else:
            dp[i][j] = 2*dp[i-1][j]
        dp[i][j] %= mod

#print(dp)
print(dp[N-1][S])

Measured memory_bytes: 135376
h,w=map(int,input().split())
m=[]
for i in range(h):
  m.append(list(map(lambda x:int(x=="#"),list(input())))+[0])
m.append([0 for i in range(w+1)])
s=[[100000 for i in range(w+1)] for j in range(h+1)]
s[-1][0]=0
for i in range(h):
  for j in range(w):
    s[i][j]=min(s[i-1][j]+(not(m[i-1][j]) and m[i][j]),s[i][j-1]+(not(m[i][j-1]) and m[i][j]))
print(s[-2][-2])

Measured memory_bytes: 74252
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define all(x) (x.begin()),(x.end())
#define sz(x)  ((ll)x.size())
#define FAST_IO ios_base :: sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
using namespace std;
#ifdef LOCAL
#include "uj.h"
#endif
void tokenize(string str,const char delim,vector<string> & res){
	stringstream p(str);
	string token;
	while(getline(p,token,delim)){
		res.push_back(token);
	}
	return;
}

// Your workSpace ...

ll N;
ll f(ll a,ll b,ll c){
	return a*a + b*b + c*c + a*b + a*c + b*c;
}

const int maxn = 1e5;
vector<int> v(maxn);

void search(int x){
	for(int i = 1;i<=sqrt(x);i++){
		for(int j = 1;j<=sqrt(x);++j)
			for(int k = 1;k<=sqrt(x);++k){
					ll val = f(i,j,k);
					v[val]++;
			}
		}

}



void test_case(){
	cin >> N;
	search(N);
	for(int i = 1;i<=N;++i){
		cout << v[i] << endl;
	}
}
	


	





int main(){
	FAST_IO;
	int tt;
	//cin>>tt;
	tt = 1;
	while(tt--){
		test_case();
	}
#ifndef ONLINE_JUDGE
 	cerr << "Running Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 3720
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#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; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c; cin >> a >> b >> c;
    int ans = 1000000;
    rep (i, -50, 100) {
        int tmp = 0;
        if (i <= a) tmp += a - i; else tmp += (i - a) / 2 + 2 * ((i - a) % 2);
        if (i <= b) tmp += b - i; else tmp += (i - b) / 2 + 2 * ((i - b) % 2);
        if (i <= c) tmp += c - i; else tmp += (i - c) / 2 + 2 * ((i - c) % 2);
        if (chmin(ans, tmp)) eprintf("%d %d\n", ans, i);
    }
    cout << ans << "\n";
    return 0;
}

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

int main() 
{
    int n;
    cin >> n;
    map<int, int> mp_pair;
    map<int, int> mp_impair;
    for (int i=1; i<=n; i++)
    {
        int v;
        cin >> v;
        (i%2==0?mp_pair[v]++:mp_impair[v]++);
    }
    vector<pair<int,int>> v_pair;
    vector<pair<int,int>> v_impair;
    for (auto p:mp_pair)
        v_pair.push_back(make_pair(p.second, p.first));
    sort(v_pair.begin(), v_pair.end());
    for (auto p:mp_impair)
        v_impair.push_back(make_pair(p.second, p.first));
    sort(v_impair.begin(), v_impair.end());
    int sp = v_pair.size();
    int si = v_impair.size();
    if (v_pair[sp-1].second!=v_impair[si-1].second)
        cout << n/2-v_impair[si-1].first + n/2-v_pair[sp-1].first;
    else 
    {
        if (v_pair[sp-1].first == n/2 && v_pair[sp-1].first == n/2)
            cout << n/2;
        else cout << min(n/2-v_impair[si-1].first + n/2-v_pair[sp-2].first,
                    n/2-v_impair[si-2].first + n/2-v_pair[sp-1].first);
    }
    return 0;
}

Measured memory_bytes: 6136
S = input()
T = input()

N = len(T)
count = 0
count_list = []
index_list = []

if len(S)-len(T) != 0:
    for i in range(len(S)-N+1):
        index_list.append(S[0+i:N+i])

    for i in range(len(index_list)):
        count = 0
        for j in range(N):
            if index_list[i][j] == T[j]:
                count +=1
        count_list.append(count)
                
    print(N - max(count_list))
else:
    for i in range(N):
        if S[i] == T[i]:
            count += 1
    print(N - count)

Measured memory_bytes: 9084
/**
 * Created at 10:25 on 2019/03/05
 */

import java.util.*;

public class Main {

  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {

    int N = sc.nextInt();
    int M = sc.nextInt();
    String S = sc.next();
    String T = sc.next();

    int g = gcd(N, M);
    long L = lcm(N, M, g);
    int intervalS = (int)(L / M);
    int intervalT = (int)(L / N);

    for (int i=0; i<g; i++) {
      if (S.charAt(intervalS*i) != T.charAt(intervalT*i)) {
        System.out.println(-1);
        return;
      }
    }

    System.out.println(L);

  }

  static long lcm(long a, long b, long g) {
    return a * b / g;
  }

  static int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a%b);
  }

}


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

int main(void){
	int n;
	long int a[200000]={0};
	long int c[200000]={0};
	long int d[200000]={0};
	long int e[200000]={0};
	long int dsum=0;
	int i;

	scanf("%d\n",&n);
	for(i=0;i<n;i++){
		scanf("%ld",&a[i]);
	}
	for(i=0;i<n;i++){
		c[a[i]]++;
	}
	for(i=0;i<=n;i++){
		if(c[i]>=2){
			d[i]=c[i]*(c[i]-1)/2;
			e[i]=(c[i]-1)*(c[i]-2)/2;
		}
		dsum+=d[i];
	}
	for(i=0;i<n;i++){
		printf("%ld\n",dsum-d[a[i]]+e[a[i]]);
	}
	return 0;
}


Measured memory_bytes: 8704
number=list(map(int,input().split()))
n,m,x=number[0],number[1],number[2]
books=[list(map(int,input().split())) for i in range(n)]
U=[x for i in range(m+1)]
U[0]=0
pattern=[]
answer=[]


for i in range(2**n):
    tmp=[False]*n
    for j in range(n):
        if (i>>j)&1:
            tmp[j]=True
    
    pattern.append(tmp)

for i in range(2**n):
    cost=0
    U=[x for i in range(m+1)]
    U[0]=0
    for j in range(n):
        if pattern[i][j]==True:
            cost+=books[j][0]
            for k in range(1,m+1):
                U[k]-=books[j][k]
                if max(U)==0:
                    answer.append(cost)
                    break
                    
if answer==[]:
    print(-1)
else:
    print(min(answer))
                

Measured memory_bytes: 75208
var
	k,q,i,j:Longint;
	n,x,m,ans,b,L,y:int64;
	d:Array[1..5000]of Longint;
begin
	read(k,q);
	for i:=1 to k do read(d[i]);
	for j:=1 to q do begin
		read(n,x,m);
		b:=x;
		for i:=1 to k do begin
			L:=(n-i-1+k)div k;
			y:=d[i]mod m;
			if y=0 then y:=m;
			inc(b,y*L);
		end;
		writeln(n-1-b div m+x div m);
	end;
end.


Measured memory_bytes: 256
sn = 50000.0**0.5.ceil
is_prime = [false, false] + [true]*(50000-1)
(2..sn).each do |i|
  next unless is_prime[i]
  (i*i).step(50000, i) do |j|
    is_prime[j] = false
  end
end
prime_list = (2..50000).to_a.select{ |i| is_prime[i] }

while n = gets.to_i do
  break if n == 0
  count = 0
  tmp = prime_list.dup
  l = tmp.shift
  h = tmp.pop
  until tmp.empty?
    if l + h == n
      count += 1
      l = tmp.shift
    elsif l + h < n
      l = tmp.shift
    elsif l + h > n
      h = tmp.pop
    end
  end
  count += 1 if l*2 == n or h*2 == n or l+h == n
  puts count
end

Measured memory_bytes: 7400
L,R=map(int,input().split())
a=(L-1)//2019
if (a+1)*2019<=R:
    print(0)
else:
    a=L%2019
    b=R%2019
    print(min([(i*j)%2019 for i in range(a,b+1) for j in range(i+1,b+1)]))

Measured memory_bytes: 75416
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define vi vector<int>
#define ll long long
#define pb push_back
#define fi first
#define se second
#define ii pair<int,int>
#define ll long long
const int MOD = 998244353;
const int INF  = 2e9 + 5;
const int LEN = 2e5 + 5;
typedef tree<
int, null_type,
less<int>, rb_tree_tag, tree_order_statistics_node_update>
ordered_set;
ordered_set s;
int p[10];
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    
    int a;
    cin>>a;

    for(int i = a;i > 0; i /= 10) {
        if(i % 10 == 7) {
            cout<<"Yes\n";
            return 0;
        }
    }

    cout<<"No\n";

    return 0;       
}

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

int main(){
	int N,w[101],num1=0,num2=0,ans=100000,c;
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d",&w[i]);
	}

	for(int i=1;i<N;i++){
		num1=0;
		num2=0;
		for(int j=0;j<i;j++){
			num1+=w[j];
		}
		for(int k=i;k<N;k++){
			num2+=w[k];
		}
		c=abs(num1-num2);
		if(ans>c)ans=c;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
use proconio::input;

fn main() {
    input! {
        n: usize,
        x: usize,
        t: usize,
    }

    let mut ans = 0;

    if n % x == 0 {
        ans = (n / x) * t;
    } else {
        ans = ((n / x) + 1) * t;
    }

    println!("{}", ans);
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

const ll inf = 1e18;


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

    ll n;
    cin >> n;
    vll x(n);
    REP(i, n) cin >> x[i];
    ll l;
    cin >> l;

    // reach[k][i] : i から出発して 2^k 日で到達できる一番遠いホテル
    vvll reach(31, vll(n));

    REP(i, n){
        ll nxt = upper_bound(ALL(x), x[i] + l) - x.begin() - 1;
        reach[0][i] = nxt;
    }
    REP(k, 30){
        REP(i, n){
            reach[k + 1][i] = reach[k][reach[k][i]];
        }
    }
    ll q;
    cin >> q;
    ll a, b;
    while (q) {
        cin >> a >> b;
        a--, b--;
        if (a > b) swap(a, b);
        ll res = 1;
        REPR(k, 30){
            if (reach[k][a] < b) {
                res += (1 << k);
                a = reach[k][a];
            }
        }
        cout << res << endl;
        q--;
    }
    return 0;
}

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

int main() {
  ll x = 0,ans = 0,m = 0;
  cin >> x;
  ans = x / 11;
  ans = ans * 2;
  m = x % 11;
  if(m == 0){
    cout << ans;
    return 0;
  }
  if(m < 7){
    ans += 1;
    cout << ans;
    return 0;
  }
  else{
    ans += 2;
    cout << ans;
    return 0;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

int main() {
	s64 A, B, C;
	cin >> A >> B >> C;
	
	long double rAB = sqrt(A * B);
	
	if(C - B - A < 0) {
		cout << "No";	
	} else if(4 * A * B  < (C - B - A) * (C - B - A)) {
		cout << "Yes";
	} else {
		cout << "No";
	}
	
	return 0;
}

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

int main() {

  long long int n;
  cin >> n;

  vector< long long int > v;

  for ( long long int i = 0; i < n * 3; i++ ) {

    long long int in;
    cin >> in;
    v.push_back( in );

  }

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

  long long int ans = 0;
  long long int cnt = 0;

  for ( long long int i = v.size() - 2; i >= 0; i -= 2 ) {

    ans += v[i];
    cnt++;
    if ( cnt == n ) break;

  }

  cout << ans << endl;

  return 0;

}


Measured memory_bytes: 6256
#include <stdio.h>
int main()
{
	int a,b,c,n;
	scanf("%d%d%d",&a,&b,&c);
	if(a==b)
	{
		n=a;
		if(c!=n)
		printf("Yes");
		else
		printf("No");
	}
	else if(a==c)
	printf("Yes");
	else if(b==c)
	printf("Yes");
	else
	printf("No");
	return 0;
} 

Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <climits>
#include <functional>
#include <iostream>
#include <queue>
#include <string>
#include <numeric>
#include <vector>

using namespace std;
using ll = long long;
template<typename T> void print(T t) {cout << t << endl;}

int main() {
	string S; 
	cin >> S;
	int N = (int)S.length();
	vector<int> vec(N+1, 0);
	vector<int> zeroP;

	// seach zeroP
	if (S[0] == '<') zeroP.push_back(0);
	if (S[N - 1] == '>') zeroP.push_back(N);
	for (int i = 0; i < N - 1; i++) {
		if (S[i] == '>' && S[i + 1] == '<') zeroP.push_back(i + 1);
	}

	//sweep right
	for (int i : zeroP) {
		vec[i] = max(vec[i],0);
		for (int move = 0; i + move < N && S[i + move] == '<'; move++) {
			vec[i + move+1] = max(vec[i + move + 1], move+1);
		}
	}
	//sweep left
	for (int i : zeroP) {
		for (int move = 1; i - move >= 0 && S[i - move] == '>'; move++) {
			vec[i - move] = max(move, vec[i - move]);
		}
	}


	print(accumulate(vec.begin(), vec.end(), 0LL));

}

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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = rbegin(s); i != rend(s); ++i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.ne(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }
template<typename A, int N, typename T>
void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

int na, nb, m;
int a[100005], b[100005], x[100005], y[100005], c[100005];
void solve() {
    cin >> na >> nb >> m;
    rep(i, na) cin >> a[i];
    rep(i, nb) cin >> b[i];
    rep(i, m) cin >> x[i] >> y[i] >> c[i];

    int ans = iinf;
    rep(i, m) mins(ans, a[x[i] - 1] + b[y[i] - 1] - c[i]);

    sort(a, a + na);
    sort(b, b + nb);

    cout << min(ans, a[0] + b[0]) << endn;

}

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


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

int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<int> v(n);
  for (auto &e : v)
    cin >> e;
  sort(v.begin(), v.end());
  int t;
  cin >> t;
  int cnt = 0;
  while (t--) {
    int x;
    cin >> x;
    if (binary_search(v.begin(), v.end(), x))
      ++cnt;
  }
  cout << cnt << endl;
  return 0;
}



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

int calc_sat(int D, int N, vector<int> c, vector<vector<int>> s, vector<int> t) {
	vector<int> last(N,-1);
	int sat = 0;  // 満足度
	rep(d,D) {
		last[t[d]] = d;
		sat += s[d][t[d]];
		rep(i,N) {
			sat -= c[i] * (d-last[i]);
		}
	}
	return sat;
}

int main() {
	clock_t start = clock();

	int D;
	cin >> D;
	const int N = 26; // コンテストの種類
	vector<int> c(N);
	rep(i,N) cin >> c[i];
	vector<vector<int>> s(D, vector<int>(N));
	rep(i,D) rep(j,N) cin >> s[i][j];

	vector<int> t(D); // 開催するコンテスト

	int c_sum = 0;
	rep(i,N) c_sum += c[i];

	// 初期解
	if (c_sum>0) {
		rep(i,D) {
			int r = rand() % c_sum;
			int now_c_sum = 0;
			rep(j,N) {
				now_c_sum += c[j];
				if (r<=now_c_sum) {
					t[i] = j;
					break;
				}
			}
		}
	}
	else {
		rep(i,D) t[i] = rand() % 26;
	}

	int sat = calc_sat(D, N, c, s, t);

	// 改善
	double e_time;
	e_time = (double)(clock() - start) / CLOCKS_PER_SEC;
	while(e_time <= 1.95) {
		int new_d, new_q;
		new_d = rand() % D;
		new_q = rand() % N;
		int old = t[new_d];
		t[new_d] = new_q;
		int new_sat = calc_sat(D, N, c, s, t);
		if (new_sat > sat) {
			sat = new_sat;
		}
		else {
			t[new_d] = old;
		}
		e_time = (double)(clock() - start) / CLOCKS_PER_SEC;
	}


	// 出力
	rep(i,D) {
		printf("%d\n", t[i]+1);
	}

	return 0;
}


Measured memory_bytes: 3868
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+100;
struct node{
    int num;
    int id;
}p[N];
bool cmp(node a,node b){
    return a.num<b.num;
}
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
         cin>>p[i].num;
         p[i].id=i;
    }
    sort(p+1,p+n+1,cmp);
    for(int i=1;i<=n;i++){
        cout<<p[i].id<<' ';
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T &a, T b) {if (a < b) {a = b;return 1;}return 0;}
template<class T> inline bool chmin(T &a, T b) {if (a > b) {a = b;return 1;}return 0;}

int main() {
  string s,t;
  cin >> s >> t;
  int cnt = 0;
  rep(i,s.size()) {
    if (s.at(i) != t.at(i)) cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 3852
package main

import "fmt"

func main() {
	var A int
	fmt.Scan(&A)
	var B int
	fmt.Scan(&B)
	var X int
	fmt.Scan(&X)
	sum := A + B
	if sum > X && A <= X {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define ld long double
#define MOD 1000000007
#define nl cout << bl
#define rt ll Q[100005] = {0}
#define mp make_pair
#define test() \
    ull t;     \
    cin >> t;  \
    while (t--)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define s(ar, n) sort(ar, ar + n)
#define rs(ar, n) sort(ar, ar + n, greater<ll>())
#define oa(a, n)               \
    for (ll i = 0; i < n; i++) \
        cout << a[i] << " ";
#define cn(a, n)               \
    for (ll i = 0; i < n; i++) \
        cin >> a[i];
#define ov(a, n)                    \
    for (ll i = n - 1; i >= 0; i--) \
        cout << a[i] << " ";        \
    nl
#define ovp(a, n)              \
    for (ll i = 0; i < n; i++) \
        cout << a[i].ff << " " << a[i].ss << bl;
#define maxa(ar, N) *max_element(ar, ar + N)
#define mina(ar, N) *min_element(ar, ar + N)
#define present(c, x) ((c).find(x) != (c).end())
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
typedef pair<int, int> pii;
ll fast_exp(ll base, ll exp)
{
    ll res = 1;
    while (exp > 0)
    {
        if (exp % 2 == 1)
            res = (res * base) % MOD;
        base = (base * base) % MOD;
        exp /= 2;
    }
    return res % MOD;
}
ll fib(ll n)
{
    if (n < 2)
        return n;
    ll a = 0, b = 1, pre;
    int i = 1;
    while (i < n)
    {
        pre = (a + b) % MOD;
        a = b;
        b = pre;
        i++;
    }
    return pre;
}
ll fac(ll n)
{
    if (n % 2 == 0)
        return 2;

    for (ll i = 3; i * i <= n; i += 2)
    {
        if (n % i == 0)
            return i;
    }

    return n;
}
ll fact(ll n)
{
    if (n > 1)
        return n * fact(n - 1);
    else
        return 1;
}
bool sortbysec(const tuple<int, int, int> &a,
               const tuple<int, int, int> &b)
{
    return (get<1>(a) < get<1>(b));
}
int main()
{
    int n;
    cin >> n;
    int a[n];
    cin >> a[0];
    int xr = a[0];
    for (int i = 1; i < n; i++)
    {
        cin >> a[i];
        xr = xr ^ a[i];
    }
    for (int i = 0; i < n; i++)
    {
        int ans = xr ^ a[i];
        cout << ans << " ";
    }
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, k;
    cin >> n >> k;
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        long long a = i, b = ((k - i) % k + k) % k;
        if ((b * 2) % k == 0) {
            long long add = (n - b) / k + 1;
            if (b == 0) {
                add--;
            }

            ans += add * add;
        }
    }
    cout << ans << endl;

}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
    int x,y;
    cin>>x>>y;
    if(x>=10) {
        cout << "-1" << "\n";
    }
    else if(y>=10) {
        cout<<"-1"<<"\n";
    }
    else {
        cout << x*y << "\n";
    }
}


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

using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;

unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b; //あまりが0ならそれが、最大公約数
}

int main()
{
    ll A,B,C,D,CD,res;

    res = 0;

    ll tmp1,tmp2;
    ll C_size,D_size,CD_size;


    cin >> A >> B >> C >> D;


    //Cの数
    tmp1 = A/C;
    tmp2 = B/C;
    C_size = tmp2 -tmp1;
    if(A % C == 0)C_size++;

    tmp1 = A/D;
    tmp2 = B/D;
    D_size = tmp2 -tmp1;
    if(A % D == 0)D_size++;
    

    CD = C*D /euclidean_gcd(C,D);

    tmp1 = A/CD;
    tmp2 = B/CD;
    CD_size = tmp2 -tmp1;
    if(A % CD == 0)CD_size++;

    tmp1 = C_size + D_size - CD_size;
    tmp2 = B - A + 1;


    res = tmp2 - tmp1;

    cout << res << endl;

}



Measured memory_bytes: 256
s = input()
a = len(s)-1

for i in range(2**a):
    c = ["-"]*a
    t = ""
    for j in range(a):
        if ((i >> j) & 1):
            c[a-1-j] = "+"
        t = c[a-1-j] + s[a-j] + t
    t = s[0] + t
    
    if eval(t) == 7:
        t = t + "=7"
        print(t)
        break


Measured memory_bytes: 3060
package main
 
import (
	"bufio"
	"os"
	"strings"
	"sync"
)
 
const scBufSize = 1 * 1024 * 1024 // 1MB
 
var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, scBufSize), scBufSize)
	sc.Split(bufio.ScanWords)
	return sc
}()
var w = []string{"dream", "dreamer", "erase", "eraser"}
 
var done = make(chan interface{}, 1)
var wg = &sync.WaitGroup{}
 
func main() {
	s := scans()
 
	wg.Add(1)
	go check(done, s)
	wg.Wait()
  
	select {
	case <-done:
		os.Stdout.WriteString("YES")
	default:
		os.Stdout.WriteString("NO")
	}
 
}
 
func scans() string {
	sc.Scan()
	return sc.Text()
}
 
func check(done chan<- interface{}, s string) {
	defer wg.Done()
	for _, v := range w {
		if v == s {
			done <- struct{}{}
			return
		}
		if strings.HasPrefix(s, v) {
			wg.Add(1)
			go check(done, s[len(v):])
		}
	}
}

Measured memory_bytes: 1152
import sys
import numpy as np
from numba import njit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit('(i4[::1],i4,i8[::1])', cache=True)
def main(A, B, C):
    counts = np.zeros(1 << 18, np.int32)
    popcount = np.zeros(1 << B, np.int32)
    for i in range(B):
        popcount[1 << i:1 << i + 1] = popcount[:1 << i] + 1

    answer = 0
    for i in range(1 << B):
        k = popcount[i]
        t = 0
        for x in A & i:
            n = counts[x]
            counts[x] += 1
            t -= C[n]
            t += C[n + 1]
        for x in A & i:
            counts[x] = 0
        if k & 1:
            t = -t
        answer += t
    return answer

N, K, S, T = map(int, readline().split())
A = np.array(readline().split(), np.int32)

def convert_problem(S, T, A):
    ng = np.zeros(len(A), np.bool)
    B = np.zeros_like(A)
    n = 0
    for i in range(18):
        s, t = (S >> i) & 1, (T >> i) & 1
        if (s, t) == (0, 0):
            ng |= ((A >> i) & 1) == 1
        elif (s, t) == (1, 1):
            ng |= ((A >> i) & 1) == 0
        elif (s, t) == (1, 0):
            print(0)
            exit()
        else:
            B += ((A >> i) & 1) << n
            n += 1
    return B[~ng], n

A, B = convert_problem(S, T, A)

C = np.zeros((100, 100), np.int64)
C[0, 0] = 1
for n in range(1, 100):
    C[n, :-1] += C[n - 1, :-1]
    C[n, 1:] += C[n - 1, :-1]
C = C[:, 1:K + 1].sum(axis=1)

print(main(A, B, C))

Measured memory_bytes: 110324
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <iostream>
#include <string>
using namespace std;

class Mults{
public:
  int getMults(int l, int r, int d){
    int ct = 0;
    for(int i=l;i<=r;i++){
      if((i%d)==0){
	ct++;
      }
    }
    return ct;
  }
};
vector<string>split(string s, char delim){
  int len = s.length();
  string currStr = "";
  vector<string>retVec;
  for(int i = 0;i<len;i++){
    char ch = s[i];
    if(ch==delim){
      retVec.push_back(currStr);
      currStr = "";
    }else{
      currStr += ch;
    }
  }
  retVec.push_back(currStr);
  return retVec;
}



vector<int>strToIntVec(string s){
  int len = s.length();
  //  s = s.substr(1,len-2);
  vector<string>strVec = split(s,' ');
  vector<int>retVec;
  for(int i=0;i<strVec.size();i++){
    int el = atoi(strVec[i].c_str());
    retVec.push_back(el);
  }
  return retVec;
}

int main(int argc, const char*argv[]){
  Mults m;
  string lrdLn;
  getline(cin,lrdLn);
  vector<int>lrdVec = strToIntVec(lrdLn);
  int nMults = m.getMults(lrdVec[0],lrdVec[1],lrdVec[2]);
  cout<<nMults<<endl;
  return 0;
}


Measured memory_bytes: 3624
//
//  Created by Vijay Bhati on 19/02/20.
//  Copyright © 2019 Vijay Bhati. All rights reserved.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <stdio.h>
#include <cstdlib>
#include <map>
#include <sstream>
#include <set>
#include <iomanip>
#include <list>
#include <stack>
#include <queue>
#include <bitset>
#include <numeric>
#include <functional>
#include <unordered_set>
#include <unordered_map>
#include <cstdio>
#include <cmath>
#include <climits>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cassert>
#include <memory>
#define ll long long
#define ull unsigned long long
#define pi acos(-1.0)
#define rf freopen("in.txt", "r", stdin);
#define ld long double
#define all(v) v.begin(),v.end()
#define pb push_back
#define P pair<ll, ll>
#define ff first
#define ss second
#define F first
#define S second
#define MOD 1000000007
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)

using namespace std;

ll max(ll a, ll b) {
    return a > b ? a : b;
}

ll min(ll a, ll b) {
    return a > b ? b : a;
}

ll __gcd(ll a, ll b) {
    if (a == 0) {
        return b;
    }
    return __gcd(b%a, a);
}

ll find_power(ll a, ll b) {
    ll ans = 1;
    while (b > 0) {
        if (b & 1) {
            ans = (ans * a) % 1000000007;
        }
        b = b >> 1;
        a = (a * a) % 1000000007;
    }
    return ans;
}


int main() {
#ifdef __APPLE__
    const clock_t begin_time = clock();
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    
    ll n;
    cin >> n;
    vector <int> h(n, 0);
    
    for (int i = 0; i < n; i++) {
        cin >> h[i];
    }
    
    int dp[n+1];
    
    memset(dp, 0, sizeof(dp));
    
    for (int i = 1; i < n; i++) {
        dp[i] = dp[i-1] + abs(h[i] - h[i-1]);
        if (i >= 2) {
            dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
        }
    }
    
    cout << dp[n-1] << endl;
    
    
#ifdef __APPLE__
    cout << endl;
    cout << "Time : ";
    cout << float( clock () - begin_time ) / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}


Measured memory_bytes: 1024
N, K = gets.chomp.split.map(&:to_i)
ans = 0
MOD = 10**9 + 7

def comb(n, r)
  r = n - r if n - r < r
  res = 1

  1.upto(r) do |i|
    # 整数にするため分母がiを維持して計算する
    res = res * (n - r + i)/i
  end
  res
end

ans = Hash.new(0)

1.upto(K) do |i|
  break if N- K + 1 < i


  ans[i] = comb(N-K+1, i) * comb(K-1, i - 1) % MOD
end


1.upto(K) do |i|
  puts ans[i]
end


Measured memory_bytes: 2172
n, m = map(int, input().split())
h = [int(i) for i in input().split()]

observatorys = [[] for i in range(n)]
for i in range(m):
    a, b = map(lambda x: int(x) - 1, input().split())
    if a in observatorys[b]:
        continue
    
    if b in observatorys[a]:
        continue
    
    observatorys[a].append(b)
    observatorys[b].append(a)
    
ans = 0
for i in range(n):
    flg = False
    for ob in observatorys[i]:
        if h[i] <= h[ob]:
            flg = True
            break
    if flg:
        continue
    
    ans += 1

print(ans)

Measured memory_bytes: 90796
#include <iostream>
#include<vector>
#include<algorithm>
#include<set>

using namespace std;






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

	int set[3] = {-1,-1,-1};


	for (int i = 0; i <= N; i++)
	{
		for (int j = 0; i + j <= N; j++)
		{
			int k = N - i - j;
			int z = 10000 * i + 5000 * j + 1000 * k;
			if (z == Y)
			{
				set[0] = i;
				set[1] = j;
				set[2] = k;
				goto loopend;
			}
			else if(z > Y)
			{
				break;
			}
		}
	}

loopend:
	cout << set[0] << ' ' << set[1] << ' ' << set[2];

}



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

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

int main() {
    ll n,a,b;
    cin >> n >> a >> b;
    if(a > b){
        cout << 0 << endl;
        return 0;
    }
    if(a == b && n == 1){
        cout << 1 << endl;
    }else if(a != b && n == 1){
        cout << 0 << endl;
    }else{
        cout << n*(b-a)+2*a-2*b+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int y = scan.nextInt();
		int groX=0;
		int groY=0;

		if(x==4||x==6||x==9||x==11) {
			groX=2;
		}else if(x==2) {
			groX=3;
		}else {
			groX=1;
		}

		if(y==4||y==6||y==9||y==11) {
			groY=2;
		}else if(y==2) {
			groY=3;
		}else {
			groY=1;
		}

		if(groX==groY) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 21716
#include<cstdio>
#include<cstring>
using namespace std;

char c[1010];
int n;

int main()
{
	scanf("%s",c);
	scanf("%d",&n);
	int a=strlen(c);
	for(int i=0;i<a;i++){
		if(i%n==0)printf("%c",c[i]);
	}
	return 0;
}


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

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i,N) for(int i=0; i<N; i++)
#define cinv(v,N) vector<int> v(N); for(int i=0; i<N; i++){ cin >> v[i]; }
#define mt make_tuple
const ll MOD2 = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  //input
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N; cin >> N;
  vector<ll> a(N), s(N,0);
  FOR(i,N){ cin >> a[i]; }
  for(int i=0; i<N; i++){
    if(i!=0){
      s[i] = s[i-1] + a[i]; 
    }else{
      s[i] = a[i];
    }
  }
  
  //main
  ll ans = 0;
  if(s[N-1]%2 == 0){
    auto itr = lower_bound(s.begin(), s.end(), s[N-1]/2);
    ans += (min(abs(s[N-1]/2-(*prev(itr))), abs(-s[N-1]/2+(*itr))))*2;
  }else{
    ll anst = 0, ansu = 0;
    vector<ll> t(N), u(N);
    FOR(i,N){ t[i] = s[i]-1; u[i] = s[i]+1; }
    auto itrt = lower_bound(t.begin(), t.end(), t[N-1]/2);
    anst += (min(abs(t[N-1]/2-(*prev(itrt))), abs(-t[N-1]/2+(*itrt))) )*2;
    auto itru = lower_bound(u.begin(), u.end(), u[N-1]/2);
    ansu += (min(abs(u[N-1]/2-(*prev(itru))), abs(-u[N-1]/2+(*itru))) )*2;
    ans = min(anst,ansu)+1;
  }
  
  // output
  cout << ans << endl;
  
  return 0;
}

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

using namespace std;

#define endl '\n'

const int nax = 2e5 + 1;

int main(){

  ios_base :: sync_with_stdio(false);
  cin.tie(NULL);

  int n;
  cin >> n;
  vector <int> vet(n);
  int mx = 0;

  for(int i=0;i<n;i++)
    cin >> vet[i], mx = max(mx,vet[i]);

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

  vector <int> ans(mx+1,0);

  for(int i=0;i<n;i++){
    int cur = vet[i];
    for(int k=cur;k<=mx;k+=cur){
      ans[k]++;
    }
  }

  int resp = 0;

  for(int i=0;i<n;i++)
    if(ans[vet[i]] == 1)
      resp++;

  cout << resp << endl;
 
  return 0;
}

Measured memory_bytes: 7892
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>

using namespace std;

class cDigitNumber
{
public:
	int count(int, int);
};

int cDigitNumber::count(int a, int b)
{
	long long t = a + b;
	int count = 0;
	while (t >= 10)
	{
		++count;
		t /= 10;
	}
	return ++count;
}

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

	cDigitNumber cdn;
	int a, b;

	while (1)
	{
		cin >> a >> b;
		if (cin.fail()) break;
		cout << cdn.count(a, b) << endl;
	}

	return 0;
}

Measured memory_bytes: 3076
pub fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

pub fn read_vec2<T: std::str::FromStr>(n: usize) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

pub fn read_col<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| read()).collect()
}

fn main() {
    let k: usize = read();
    let av: Vec<u64> = read_vec();

    let mut mn = 2;
    let mut mx = 2;

    for i in (0..k).rev() {
        let a = av[i];
        let tmp1 = (mn - 1) / a + 1;
        let tmp2 = mx / a + 1;
        mn = a * tmp1;
        mx = a * tmp2 - 1;
        if mn > mx {
            println!("-1");
            return;
        }
    }

    println!("{} {}", mn, mx);
}


Measured memory_bytes: 8444
/*    特徴    */

/*    教訓    */

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld  = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-10; //微調整用（EPSより小さいと0と判定など）

int ii() { int x; if (scanf("%d", &x)==1) return x; else return 0; }
long long il() { long long x; if (scanf("%lld", &x)==1) return x; else return 0; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //動作未確認
void br() { putchar('\n'); }

// #define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
int lcm(int a, int b){return a / gcd(a, b) * b;}
#define begin_end(a) a.begin(),a.end() //sort(begin_end(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll) (n) ; i++ )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define p_b push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに


// coutによるpairの出力（空白区切り）
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutによるvectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " "; //"\t"に変えるとTabで見やすく区切る
  }
  return s;
}
// coutによる多次元vectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

//最大値、最小値の更新。更新したor等しければtrueを返す
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

//4近傍（上下左右） rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};

// -------- template end - //


// - library ------------- //



// --------- library end - //


int main(){

  char c = ic();
  if (c <= 'Z' && c >= 'A') cout << 'A' << endl;
  else cout << 'a' << endl;



  
}

Measured memory_bytes: 3588
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
using namespace std;

#define REP(i, n) for(int i=0; i<(int)n; ++i)
#define FOR(i,c) for(__typeof((c).begin())i = (c).begin(); i != (c).end(); ++i)
#define ALL(c) (c).begin() , (c).end()

int main() {
  int dx[8] = {-1,-1,-1,0,0,1,1,1};
  int dy[8] = {-1,0,1,-1,1,-1,0,1};

  int h,w;
  while(cin>>h>>w, h||w) {
    set<string> ap;
    char ba[h][w];
    REP(i, h) {
      REP(j, w) {
        cin >> ba[i][j];
      }
    }

    string ans = "";
    REP(i, h) {
      REP(j, w) {
        REP(k, 8) {
          string str = "";
          int y = i;
          int x = j;
          do {
            str += string(1,ba[y][x]);

            if(ap.find(str) != ap.end()) {
//                            cout<<str<<endl;
              if(ans == "" || ans.length() < str.length()
                 || (ans.length() == str.length() && str < ans))
                ans = str;
            }
            if(str.length() > 1) ap.insert(str);

            y += dy[k];
            x += dx[k];
            if (x<0) x = w-1;
            if (x>=w) x = 0;
            if (y<0) y = h-1;
            if (y>=h) y = 0;
            //cout << k << " " << j <<" " << i << " " << x << " " << y << endl;
            if (i==y && j==x) break;
          } while(1);


//                    cout << str << endl;
        }
      }
    }

    if(ans.length() == 0) ans = "0";
    cout<<ans<<endl;
  }
}

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

int main(void) {
  int H, W;
  string a[101];
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < W + 2; i++) {
    cout << '#';
  }
  cout << endl;
  for (int i = 0; i < H; i++) {
    cout << '#' << a[i] << '#' << endl;
  }
  for (int i = 0; i < W + 2; i++) {
    cout << '#';
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(M)]
ab.sort(key=lambda x:x[1])
tmp = ab[0][1]-1
ans = 1
for i in range(1,M):
  if ab[i][0] <= tmp:
    continue
  else:
    ans += 1
    tmp = ab[i][1]-1
print(ans)  

Measured memory_bytes: 29084
function Main(input) {
  var K = parseInt(input.split('\n')[0].trim());
  var S = input.split('\n')[1].trim();

  if (S.length <= K) {
    console.log(S);
  } else {
    console.log(S.substring(0, K) + '...');
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29628
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    string s;
    cin >> s;
    if (s[0] == s[1] && s[1] == s[2]) {
        cout << "Yes" << endl;
    }
    else if (s[1] == s[2] && s[2] == s[3]) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define repn(i, x) for (int i = 1; i <= (int)(x); i++)
#define repr(i, x) for (int i = ((int)(x) - 1); i >= 0; i--)
#define reprn(i, x) for (int i = ((int)(x)); i > 0; i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long int64;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;
void solve() {
	int64 k, n; cin >> k >> n;
	vector<int64> a(n);
	rep (i, n) {
		cin >> a[i];
	}
	vector<int64> dist(n);
	for (int64 i = 0; i < (n - 1); ++i) {
		dist[i] = abs(a[i + 1] - a[i]);
	}	
	dist[n - 1] = (k - a[n - 1]) + a[0];
	sort(all(dist));
	int64 ans = 0;
	for (int i = 0; i < (n - 1); ++i) {
		ans += dist[i];
	}
	cout << ans << endl;
	return;
}

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

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

typedef long long LL;

template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar.size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}

vector<vector<char> > board;
int h,w;

map<char, pair<int, int> > dirmap;

pair<int, int> slide(int x, int y, char dir){
    // 壁にぶつかる
    if (x < 0) {
        return make_pair(0,y);
    }else if (x >= w){
        return make_pair(w-1,y);
    }else if (y < 0){
        return make_pair(x,0);
    }else if (y >= h){
        return make_pair(x,h-1);
    }

    if (board[y][x] == '#') {
        pair<int, int> pos;
        pos = slide(x+dirmap[dir].first, y+dirmap[dir].second, dir);
        // cout << pos.first << " " << pos.second << endl;
        return make_pair(pos.first, pos.second);
    }else{
        return make_pair(x,y);
    }
}

int main(int argc, char const* argv[])
{
    int n;
    cin >> n;

    vector<int> pos(n+1);
    pos.push_back(0);
    for (int i = 1; i < n+1; i++) {
        cin >> pos[i];
    }
    
    vector<int> cost;
    int sum=0;
    for (int i = 0; i < n+1; i++) {
        cost.push_back(abs(pos[i] - pos[(i+1) % (n+1)]));
        sum += cost[i];
    }

    for (int i = 1; i < n+1; i++) {
        cout << sum - cost[i-1] - cost[i] + abs(pos[i-1] - pos[(i+1) % (n+1)]) << endl;
    }

    return 0;
}


Measured memory_bytes: 2552
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] argv) throws IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ");
        int n = Integer.parseInt(str[0]);
        int W = Integer.parseInt(str[1]);

        int[] v = new int[n];
        int[] w = new int[n];
        for (int i = 0; i < n; i++) {
            str = br.readLine().split(" ");
            v[i] = Integer.parseInt(str[0]);
            w[i] = Integer.parseInt(str[1]);
        }

        int[][] dp = new int[n+1][W+1];
        for(int i=0; i<n+1; i++) dp[i][0] = 0;
        for(int i=0; i<W+1; i++) dp[n][i] = 0;

        for(int i=n-1; i>=0; i--){
            for(int j=0; j<=W; j++){
                if(w[i] > j){
                    dp[i][j] = dp[i+1][j];
                } else {
                    dp[i][j] = Integer.max(dp[i+1][j], dp[i][j-w[i]] + v[i]);
                }
            }
        }

        System.out.println(dp[0][W]);

    }
}

Measured memory_bytes: 29300
from collections import defaultdict
n, m = map(int, raw_input().split())
A = map(int, raw_input().split())
prefix = [-1]*n
prefix[0] = A[0]
for i in range(1, n):
    prefix[i] = A[i] + prefix[i-1]
modulos = map(lambda x: x % m, prefix)
hashTable = defaultdict(int)
for modulo in modulos:
    hashTable[modulo] += 1
res = 0
for k, v in hashTable.items():
    if v >= 2:
        res += v*(v-1) /2
    if k == 0:
        res += v
print res

Measured memory_bytes: 21404
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 367
#define INF 100000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 100005;
const int MOD = 1000000007;
int main(){
    int n,m;
    cin>>n>>m;
    vector<int>a(n);
    int sum=0;
    REP(i,n){
        IN(a[i]);
        sum+=a[i];
    }
    int cnt=0;
    REP(i,n){
        if((sum+4*m-1)/(4*m)<=a[i])cnt++;
    }
    if(cnt>=m)OUT("Yes");
    else OUT("No");
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
/*
string S_str[H];
cins(S_str, S_str + H);
S_str[i][j];
*/
inline int at(ll x, int k){ return (x >> k) & 1; }
#define rep(i, n) for(ll i = 0; i < n; i++)


int main(){
  ll n;
  cin >>n;
  int a= n/100;
  int b =(n-(a*100))/10;
  int c = n-(a*100)-(b*10);
  if(a==7||b==7||c==7){
  cout << "Yes"<<endl;
}
else{
  cout << "No"<<endl;
}


}


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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
Int mod = 1e9+7;
//Int mod = 998244353;

int main() {
    string s;
    cin >> s;
    string t(s.size(), 'x');
    dump(t);
    return 0;
}


Measured memory_bytes: 256