akhauriyash/Code-Regression huggingface dataset:
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if lc == 1
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

aa = inputs[0][0]
bb = inputs[0][1]
str = inputs[1][0]

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

# body
if $debugFlag
  p aa
  p bb
  p str
end

stra = str[0..aa-1]
strb = str[aa+1..-1]

pd stra
pd strb

if stra =~ /[0-9]+/ and strb =~ /[0-9]+/ and str[aa] == '-' and str.length == (aa + bb + 1)
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 1788
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int h,w,n;
char fie[31][31][901];
bool flag;
bool used[31][31];
int dx[2]={1,-1};

bool check(int d){
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(fie[j][i][d]!='.')return false;
		}
	}
	return true;
}

bool bomb(int d){
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			fie[j][i][d+1]=fie[j][i][d];
		}
	}
	for(int i=h-1;i>=0;i--){
		for(int j=0;j<w;j++){
			if(fie[j][i][d+1]!='.'){
				int k=i;
				while(k+1<h && fie[j][k+1][d+1]=='.'){
					swap(fie[j][k][d+1],fie[j][k+1][d+1]);
					k++;
				}
			}
		}
	}
	memset(used,0,sizeof(used));
	bool flag2=false;
	for(int i=0;i<h;i++){
		int cnt=0;
		for(int j=0;j<w;j++){
			if(fie[j][i][d+1]=='.')cnt=0;
			else{
				if(j>0 && fie[j][i][d+1]==fie[j-1][i][d+1])cnt++;
				else cnt=1;
				if(cnt==n){
					flag2=true;
					for(int k=j-cnt+1;k<=j;k++){
						used[k][i]=true;
					}
				}
				if(cnt>n){
					used[j][i]=true;
				}
			}
		}
	}
	for(int j=0;j<w;j++){
		int cnt=0;
		for(int i=0;i<h;i++){
			if(fie[j][i][d+1]=='.')cnt=0;
			else{
				if(i>0 && fie[j][i][d+1]==fie[j][i-1][d+1])cnt++;
				else cnt=1;
				if(cnt==n){
					flag2=true;
					for(int k=i-cnt+1;k<=i;k++){
						used[j][k]=true;
					}
				}
				if(cnt>n){
					used[j][i]=true;
				}
			}
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(used[j][i])fie[j][i][d+1]='.';
		}
	}
	for(int i=h-1;i>=0;i--){
		for(int j=0;j<w;j++){
			if(fie[j][i][d+1]!='.'){
				int k=i;
				while(k+1<h && fie[j][k+1][d+1]=='.'){
					swap(fie[j][k][d+1],fie[j][k+1][d+1]);
					k++;
				}
			}
		}
	}
	return flag2;
}

void dfs(int d){
	/*
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			printf("%c",fie[j][i][d]);
		}
		printf("\n");
	}
	printf("%d\n",d);
	*/
	if(flag)return;
	if(check(d)){
		flag=true;
		return;
	}
	if(d>=1){
		if(bomb(d)){
			dfs(d+1);
		}
		return;
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			for(int k=0;k<2;k++){
				int nx=j+dx[k];
				if(nx>=0 && nx<w){
					swap(fie[j][i][d],fie[nx][i][d]);
					if(bomb(d)){
						dfs(d+1);
					}
					swap(fie[j][i][d],fie[nx][i][d]);
				}
			}	
		}
	}
}

int main(void){
	scanf("%d %d %d%*c",&h,&w,&n);
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			scanf("%c",&fie[j][i][0]);
		}
		scanf("%*c");
	}
	flag=false;
	dfs(0);
	printf("%s\n",flag?"YES":"NO");
	return 0;
}

Measured memory_bytes: 1832
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  if(k<a) cout << k << newl;
  else if(k<=a+b) cout << a << newl;
  else cout << a-(k-a-b) << newl;
  return 0;
}

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

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

const double EPS = 1e-10;

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

int n,m,s,t;

vector<ll> dijkstra(int s, vector<vector<Pi>> &G){
    vector<ll> dist(n,LINF);
    vector<bool> visited(n,false);
    priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> q;
    dist[s] = 0;
    visited[s] = true;
    q.push(make_pair(0,s));
    while(!q.empty()){
        auto p = q.top();
        ll p1 = p.first;
        int p2 = p.second;
        q.pop();
        if(p1 > dist[p2]) continue;
        visited[p2] = true;
        for(auto v : G[p2]){
            if(visited[v.first]) continue;
            if(dist[v.first] > dist[p2]+v.second){
                dist[v.first] = dist[p2]+v.second;
                q.push(make_pair(dist[v.first],v.first));
            }
        }
    }
    return dist;
}

int main(){
    cin >> n >> m >> s >> t;
    s--; t--;
    vector<vector<Pi>> G1(n),G2(n);
    rep(i,m){
        int u,v,a,b;
        cin >> u >> v >> a >> b;
        u--; v--;
        G1[u].emplace_back(v,a);
        G1[v].emplace_back(u,a);
        G2[u].emplace_back(v,b);
        G2[v].emplace_back(u,b);
    }
    vector<ll> dist1 = dijkstra(s,G1);
    vector<ll> dist2 = dijkstra(t,G2);

    vector<ll> ans(n);
    ans[n-1] = dist1[n-1]+dist2[n-1];
    for(int i = n-1; i >= 1; i--){
        ans[i-1] = min(ans[i],dist1[i-1]+dist2[i-1]);
    }
    rep(i,n){
        ans[i] = 1000000000000000-ans[i];
        cout << ans[i] << endl;
    }
}



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

using namespace std;

const int Nmax = 2e5 + 5;
const int Mod = 1e9 + 7;
const int oo = 1e9;

long long a, b, n;

int main()
{
/**
    #ifndef ONLINE_JUDGE

        ifstream cin("test.in");

    #endif // ONLINE_JUDGE
*/

    cin >> a >> b >> n;

    long long x = (b - 1 > n ? n : b - 1);

    cout << floor(a * x / b);
    return 0;
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
const int oo = 0x3f3f3f3f;
const long long ooo = 0x3f3f3f3f3f3f3f3fll;
template<class T> T abs(T x) { return x > 0 ? x : -x;}
template<class T>  inline T sqr(T x) {return x*x; }
template<class T>  T lcm(T a, T b){return b*a/__gcd(a, b);}
#define fi first
#define se second
#define mk make_pair
#define pb push_back
#define rep(i, a, n) for(int i=a; i <n; ++i)
#define per(i, a, n) for(int i=n-1; i>=a; --i)
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define uniq(c) (c).resize(unique(all(c)) - (c).begin())
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<vector<ll> >matrix;

const int MAX = 1e5 + 10;


int main() {
    long long n, m;
    scanf("%lld %lld", &n, &m);
    long long mi = min(n, m/2);
    long long ans = mi;
    m -= 2*mi;
    ans += m/4;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
const int MX = 200005;
#define RET(ans) {cout<<ans<<endl;return 0;} 

    // 二次元ベクターの基本
    /*
    vector<vector<int>> dp; // 宣言
    dp.resize(n); // 1次元めの要素数決定
    dp[i].push_back(int); // プッシュバック
    rep(i,n){
        sort(dp[i].begin(),dp[i].end()); // 二次元めを昇順ソート
    }
    */

    // 整数スキャン（複数）
    /*
    int x,y,z;
    scanf("%d%d%d",&x,&y,&z);

    // n個の整数のスキャン
    /*
    ll a[n] = {};
    rep(i,n){
        scanf("%lld",&a[i]);
    }
    */

    // 文字列スキャン
    /*
    string s; cin >> s;
    */

    // n個の文字列スキャン
    /*
    vector<string> slist;
    rep(i,n){
        string s; cin >> s;
        slist.push_back(s);
    }
    */

int main() {
    int r,g,b,n;
    cin >> r >> g >> b >> n;


    int ans = 0;

    rep(i,3001){
        rep(j,3001){
            int x = n - r*i - g*j;
            if(x==0){
                ans++;
            }else{
                if(x>0&&x%b==0){
                    ans++;
                }
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}
 
 


Measured memory_bytes: 256
A, V = gets.split(' ').map(&:to_i)
B, W = gets.split(' ').map(&:to_i)
T = gets.to_i

vr = V - W
if vr <= 0
    puts "NO"
    exit
end
xr = [A-B, B-A].max
puts ((T * vr >= xr) ? "YES" : "NO")

Measured memory_bytes: 14380
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<map>
#include <cstdint>
#include <boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define Endl endl
#define F first
#define S second

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

int digits(ll n) {
	int count = 0;
	while (n > 0) {
		n /= 10;
		count++;
	}
	return count;
}
int main() {
	int n;
	cin >> n;
	vector<int>alpha(26);
	rep(i, n) {
		string s;
		cin >> s;
		vector<int>alpha1(26);
		rep(j, s.size()) {
			int a = s[j];
			a -= 97;
			//cout << a << endl;
			if (i == 0) {
				alpha[a]++;
			}
			alpha1[a]++;
		}
		rep(j, 26) {
			//cout <<"p "<< alpha[j] << endl;
			//cout <<"ph"<< alpha1[j] << endl;
			alpha[j] = min(alpha[j], alpha1[j]);
		}
	}
//	cout << "a" << endl;
	rep(i, 26) {
		char a = 'a' + i;
		//cout << alpha[i] << endl;
		rep(j, alpha[i]) {
			cout << a ;
		}
	}
	cout << endl;
}

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

int main() {
	int n; cin >> n;
	int X = 0, Y = 0, T = 0;
	bool flag = true;
	for (int i = 0; i < n; i ++) {
		int t, x, y; cin >> t >> x >> y;
		int dis = abs(x-X) + abs(y-Y);
		if ((t - T) % 2 != dis % 2 || dis > t-T) {
			flag = false; 
		}
		T = t; X = x; Y = y;
	}
	if (flag) cout << "Yes\n"; 
	else cout << "No\n"; 
	return 0;
}

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

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

  int n = 0, w = 0, s = 0, e = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] == 'N') n++;
    if (S[i] == 'W') w++;
    if (S[i] == 'S') s++;
    if (S[i] == 'E') e++;
  }

  if (!n && s || n && !s || !w && e || w && !e) cout << "No" << endl;
  else cout << "Yes" << endl;

  return 0;
}

Measured memory_bytes: 256
/* vo00_05.cpp */
#include <iostream>
using namespace std;

int euclid(long long a, long long b);

int main()
{
	int c;
	long long a, b, d;

	while (true) {
		cin >> a >> b;
		if (cin.eof()) break;

		c = euclid(a, b);
		d = a * b / c;

		cout << c << ' ' << d << '\n';
	}

	return 0;
}

int euclid(long long a, long long b)
{
	if (a < b) { int temp = a; a = b; b = temp; }

	int r;
	while (b != 0) {

		r = a % b;
		a = b;
		b = r;

	}


	return a;
}

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

#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#define ll              long long int
#define ull             unsigned long long
#define vi              vector<int>
#define vl              vector<ll>
#define vvi             vector<vector<int> >
#define pi              pair<int,int>
#define vii             vector<pi>

#define sz(v)           ((int)(v).size())
#define all(s)          s.begin(),s.end()
#define allr(s)         s.rbegin(),s.rend()
#define unq(c)          (sort(all(c)), c.resize(distance(c.begin(),unique(all(c)))))
#define get_pos(c,x)    (lower_bound(all(c),x)-c.begin())

#define MS0(v)          memset((v), 0, sizeof((v)))
#define MS1(v)          memset((v), -1, sizeof((v)))
#define LEN(v)          strlen(v)

#define MP              make_pair
#define pb              push_back
#define pob             pop_back
#define ff              first
#define ss              second
#define sc              scanf
#define pf              printf
#define endl            "\n"

#define TEST_CASE       int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define PRINT_CASE      printf("Case %d: ",cs)

#define vpf(v)          for(int i=0;i<v.size();i++){cout<<v[i];if(i!=v.size()-1)cout<<" ";else cout<<"\n";}
#define vsc(v)          for(int i=0;i<v.size();i++)cin>>v[i];

#define REP(i, n)       for (int i = 0; i < (n); i++)
#define REPP(i, a, b)   for (int i = (a); i < (b); i++)
#define FOR(i, a, b)    for (int i = (a); i <= (b); i++)
#define FORS(i, s)      for (int i = 0; s[i]; i++)

#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fileio          freopen("in.txt","r",stdin);freopen("out.txt","w",stdout)

#define intlim          2147483648
#define infinity        (1LL<<50)

#define gcd(a, b)       __gcd(a, b)
#define lcm(a, b)       ((a)*((b)/gcd(a,b)))


int on_bit(int N,int pos){return N = N | (1<<pos);}
int off_bit(int N,int pos){return N = N & ~(1<<pos);}
bool check_bit(ll N,int pos){return (bool)(N & (1<<pos));}


#define start_clock     clock_t tStart = clock()
#define end_clock       printf("\n>>Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC)



//____________________________________________________________________________________________________________




int main(){ 
    int a, b, c;
    cin >> a >> b >> c;
    cout<<c<<" "<<a<<" "<<b<<"\n";
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define f first
#define s second
 
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> arr(4);
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        if(s == "AC") arr[0] += 1;
        else if(s == "WA") arr[1] += 1;
        else if(s == "TLE") arr[2] += 1;
        else arr[3] += 1;
    }
    cout << "AC" << " " << 'x' << " " << arr[0] << endl;
    cout << "WA" << " " << 'x' << " " << arr[1] << endl;
    cout << "TLE" << " " << 'x' << " " << arr[2] << endl;
    cout << "RE" << " " << 'x' << " " << arr[3] << endl;
}


Measured memory_bytes: 3636
#include<iostream>

using namespace std;

int main(){
	int H, W;
	for (int i = 0; i < 100000; i++){
		cin >> H >> W;
		if (H == 0 && W == 0){
			break;
		}
		if (W % 2 == 0 && H % 2 == 0){
			for (int i = 0; i < H / 2; i++){
				for (int i = 0; i < W / 2; i++){
					cout << "#.";
				}
				cout << endl;
				for (int i = 0; i < W / 2; i++){
					cout << ".#";
				}
				cout << endl;
			}
		}
		if (W % 2 == 0 && H % 2 != 0){
			for (int i = 0; i < H / 2; i++){
				for (int i = 0; i < W / 2; i++){
					cout << "#.";
				}
				cout << endl;
				for (int i = 0; i < W / 2; i++){
					cout << ".#";
				}
				cout << endl;
			}
			for (int i = 0; i < W / 2; i++){
				cout << "#.";
			}
			cout << endl;
		}
		if (W % 2 != 0 && H % 2 == 0){
			for (int i = 0; i < H / 2; i++){
				for (int i = 0; i < W / 2; i++){
					cout << "#.";
				}
				cout << "#" << endl;
				for (int i = 0; i < W / 2; i++){
					cout << ".#";
				}
				cout << "." << endl;
			}
		}
		if (W % 2 != 0 && H % 2 != 0){
			for (int i = 0; i < H / 2; i++){
				for (int i = 0; i < W / 2; i++){
					cout << "#.";
				}
				cout << "#" << endl;
				for (int i = 0; i < W / 2; i++){
					cout << ".#";
				}
				cout << "." << endl;
			}
			for (int i = 0; i < W / 2; i++){
				cout << "#.";
			}
			cout << "#" << endl;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3096
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
const long long INF = 1LL << 60;

int main() {
	int H, W;
	cin >> H >> W;
	vector<string> S(H);
	REP(i, H) {
		cin >> S[i];
	}

	vector<vector<int>> hor(H, vector<int>(W, 0));
	vector<vector<int>> ver(H, vector<int>(W, 0));

	REP(i, H) {
		REP(j, W) {
			if (S[i][j] == '#') {
				continue;
			}
			int num = 1;
			if (W <= j + 1) {
				hor[i][j] = 1;
				continue;
			}
			while (S[i][j + 1] == '.') {
				num++; j++;
				if (W <= j + 1) {
					break;
				}
			}
			for (int k = j; k > j - num; k--) {
				hor[i][k] = num;
			}
		}
	}

	REP(i, W) {
		REP(j, H) {
			if (S[j][i] == '#') {
				continue;
			}
			int num = 1;
			if (H <= j + 1) {
				ver[j][i] = 1;
				continue;
			}
			while (S[j + 1][i] == '.') {
				num++; j++;
				if (H <= j + 1) {
					break;
				}
			}
			for (int k = j; k > j - num; k--) {
				ver[k][i] = num;
			}
		}
	}

	int ans = -1;
	REP(i, H) {
		REP(j, W) {
			if (hor[i][j] == 0 || ver[i][j] == 0) {
				continue;
			}
			int now = hor[i][j] + ver[i][j] - 1;
			ans = max(ans, now);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 35712
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner in = new java.util.Scanner(System.in);
		char[] S = in.nextLine().toCharArray();
		char[] T = in.nextLine().toCharArray();
		
		int count = 0;
		for(int i=0; i<S.length; i++) {
			count = 0;
			
			for(int j=0; j<T.length - i; j++) {
				if((int)S[j] == (int)T[j+i]) {
					count++;
				}else {
					break;
				}
			}
			for(int j=T.length-i, k=0; j<T.length; j++,k++) {
				if((int)S[j] == (int)T[k]) {
					count++;
				}else {
					break;
				}
			}
			if(count == S.length) {
				System.out.print("Yes");
				System.exit(0);
			}
		}
		System.out.print("No");
		
	}
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

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

int main(void)
{
    ll K;
    cin >> K;
    ll ans = 0;
    Rep(i,1,K+1)Rep(j,1,K+1)Rep(k,1,K+1){
        ans += gcd(i, gcd(j,k));
    }
    pr(ans);
}

Measured memory_bytes: 3624
import java.io.*;
//import java.math.BigDecimal;
//import java.lang.reflect.Array;
//import java.util.Arrays;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			String line = br.readLine();
			do {
				String[] in = line.split(" ", 0);
				//???????????????????¨????
				int a = Integer.parseInt(in[0]);
				int b = Integer.parseInt(in[1]);
				while (a != b){
					if(a > b){
						a = a- b;
					}else{
						b = b - a;
					}
				}
				long out2 = Long.parseLong(in[0]) * Long.parseLong(in[1]) / a;
				System.out.println(a + " " + out2);
				//???????????§??????
				line = br.readLine();
			} while (line != null);

		} catch (Exception e) {
			// TODO: handle exception
			System.exit(0);
		}

	}

}

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

int main() {
    string s; cin >> s;
    const int n = s.size();

    int ans = 0;
    for(int l = 0; l < n; ++l) {
        for(int r = l + 2; r < n; ++r) {
            if(s[l] != '(' || s[r] != ')') continue;
            bool ok = true, found = false;
            int cnt = 0;
            for(int i = l + 1; i <= r - 1; ++i) {
                if(s[i] == '(') cnt += 1;
                if(s[i] == ')') cnt -= 1;
                if(s[i] == '*') found = true;
                ok &= cnt >= 0;
            }
            ans += ok && cnt == 0 && found;
        }
    }

    cout << ans << endl;
}



Measured memory_bytes: 3204
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <math.h>
#include <queue>
#include <stack>
using namespace std;
int main(void){
    long N,M;
    cin>>N>>M;
    if(N>=2&&M>=2){cout<<(N-2)*(M-2);}
    else if((N==1||M==1)&&N!=M){cout<<N*M-2;}
    else {cout<<1;}
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define moca(a, s, b) a=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
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;}
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/

class Edge {
public:
  ll t, w;
  Edge() {}
  Edge(ll t, ll w): t(t), w(w) {}
};


ll N, M;
vector<Edge> g[MAX];
ll d[MAX];

void dijkstra(ll s) {
  ll i, u;
  ll clr[MAX]={};
  priority_queue<pll> q;
  for(i=0; i<N; i++) d[i]=INF;
  d[s]=0;
  q.push({0, s});
    
  while(q.size()) {
    pll f=q.top(); q.pop();
    u=f.second;
    clr[u]=1;
    if(d[u]<-f.first) continue;
        
    for(i=0; i<g[u].size(); i++) {
      Edge e=g[u][i];
      if(clr[e.t] || d[e.t]<=d[u]+e.w) continue;
      
      d[e.t]=d[u]+e.w;
      q.push({-d[e.t], e.t});
    }
  }
}

int main(void) {
  ll i, j, k;
  
  cin >> N >> M;
  for(i=0; i<M; i++) {
    ll a, b;
    cin >> a >> b;
    a--; b--;
    g[a].push_back(Edge(b, 1));
    g[b].push_back(Edge(a, 1));
  }
  
  dijkstra(0);
  vector<ll> dis[MAX*2];
  for(i=0; i<N; i++) {
    dis[d[i]].push_back(i);
  }
  
  ll ans[MAX]={};
  for(i=1; i<N; i++) {
    for(j=0; j<g[i].size(); j++) {
      ll v=g[i][j].t;
      if(d[v]==d[i]-1) ans[i]=v;
    }
  }
  
  pt("Yes");
  for(i=1; i<N; i++) pt(ans[i]+1);
  
  
}
 
 


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

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'

using namespace std;

const int N = 2e5;
vector<int> v[N];
int dp[N][3];

int max_point(int i,int n, int fl=-1){
	if(i==n) return 0;

	if(dp[i][fl]!=-1) return dp[i][fl];

	
	int one = max_point(i+1,n,(fl+1)%3);
	int two = max_point(i+1,n,(fl+2)%3);

	return dp[i][fl] = v[i][fl]+max(one,two);


}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  	
  	int n;
  	cin>>n;
  	int a;
  	memset(dp,-1,sizeof(dp));
  	for(int i=0; i<n; i++) {
  		for(int j=0; j<3; j++) {
  			cin>>a;
  		  v[i].push_back(a);
  		}
  	}

  	int ans = INT_MIN;
  	ans = max(max_point(0,n,0),max(max_point(0,n,1),max_point(0,n,2)));

  	cout<<ans;


    return 0;
}

Measured memory_bytes: 16640
import java.util.*;
import java.io.*;

import static java.lang.Character.isUpperCase;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        if(N%2==0)
        {
            System.out.println(N/2);

        }
        else
            {
                System.out.println(N/2+1);
            }
    }


 }












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

using namespace std;

#define REP(var, n)  for (decltype(n) var = 0; var < (n); var++)
#define RREP(var, n)  for (auto var = n - 1; var != static_cast<decltype(var)>(-1); var--)
#define FOR(var, a, b)  for (auto var = (a); var < (b); var++)
#define RFOR(var, a, b)  for (auto var = b - 1; var != a; var--)

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;

#define all(c) begin(c),end(c)

template<typename T>
std::ostream &operator<<(std::ostream &out, const std::vector<T> &v) {
    if (!v.empty()) {
        out << '[';
        std::copy(v.begin(), v.end(), std::ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}

auto solve() {
    ll N, K;
    cin >> N >> K;
    vll a(N);
    for (auto &&e:a) cin >> e;
    ll all_nums = N * (N + 1) / 2;

    vll sums;
    REP(i, N) {
        ll sum = 0;
        FOR(j, i, N) {
            sum += a[j];
            sums.push_back(sum);
        }
    }

    vi inds(all_nums);
    REP(i, all_nums) inds[i] = i;

    vi ok;
    RREP(dig, 60) {
        vi next_inds;
        for (auto &&ind:inds) {
            if (((sums[ind] >> dig) % 2) == 1) {
                next_inds.push_back(ind);
            }
        }
        if (next_inds.size() >= K) {
            ok.push_back(dig);
            inds = next_inds;
        }
    }

    ll res = 0;
    for(auto&&e:ok) {
        res += (1ll<<e);
    }

    return res;
}

int main() {
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 7152
///╔══╗
///╚╗╔╝
///╔╝╚(¯`v´¯)
///╚══╝`.¸.´farzin


#include <bits/stdc++.h>

#define int int64_t
#define pb push_back
#define ibsws ios_base::sync_with_stdio
#define gcd __gcd
#define s second
#define f first
typedef std::pair<int,int> pii ;

using namespace std;

const int N=1e3+1e1, mod=1e9+7;
bool a[N][N];
int n,m,dp[N][N];
string s;

int32_t main(){
	ibsws(true==false);
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>s;
        for(int j=0;j<m;j++){
            a[i][j+1]=(s[j]=='.')?1:0;
        }
    }
    dp[1][1]=1;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(a[i][j]){
                dp[i][j]+=dp[i-1][j];
                dp[i][j]%=mod;
                dp[i][j]+=dp[i][j-1];
                dp[i][j]%=mod;
            }
        }
    }
    cout<<dp[n][m];
}


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

#include <cmath>    //floor ceil
#include <cstdlib>  //abs
#include <cstdio>
#include <climits>  //INT_MAX
#include <cstring>
#define endl "\n"
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define lli long long int
#define lui long unsigned int
//#define int long long
#define MOD 1000000007
#define input(a,n) for (int i=0;i<n;i++) scanf("%d",&a[i]);
#define output(a,n) for (int i=0;i<n;i++) printf("%d ",a[i]);
#define rajnikant bool ios_base::sync_with_stdio(false); cin.tie(0);
#include <vector>
#define pb push_back
#define vi vector<int>
#include <map>
#define mp make_pair
#define mii map<int,int>
mii m,m1;
#include <set>
set<int>::iterator its;
#define f first
#define s second
#define all(v) v.begin(),v.end()
#include <stack>
/*---------------------------------------------------CODE STARTS FROM HERE---------------------------------------------------*/

int main () {
    int tt=1,t;
    //cin >> tt;
    while(tt--) {
        string s;
        cin >> s;
        int n=s.size();
        if(s[n-1]=='s') s +="es";
        else s += 's';
        cout<<s;
    }
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cmath>

using namespace std;
#define MAXN 12
#define MAX 100000

int C[MAXN];
int A[MAXN][MAX+1];
int score[MAXN];

void init(){
  for(int i=0;i<MAXN;i++){
    score[i] = 0;
  }
}

bool check(int X,int N){
  int num = 0;
  for(int i=0;i<N;i++){
    //cout << score[i] << " " << i << endl;
    if(score[i] < X){
      return false;
    }
  }
  //cout << num << endl;
  return true;
}

int main(void){
  int N,M,X;
  cin >> N >> M >> X;
  int ans = (MAXN+1)*MAX;
  int bits = pow(2,N+1);
  for(int i=0;i<N;i++){
    for(int j=0;j<=M;j++){
      int tmp;
      cin >> tmp;
      A[i][j] = tmp;
    }
  }
  int r = MAX+2;
  int l = 0;
  bool ansflag = false;
  init();
  bool change = false;
  // cが実行可能か見る
  int num = 0;
  for(int i = 0;i<bits;i++){
    int num = i;
    int count = 0;
    int money = 0;
    init();
    while(num > 0){
      if(num%2 == 1){
	//countの本を買う
	money += A[count][0];
	for(int j=0;j<M;j++){
	  score[j] += A[count][j+1];
	}
      }
      num = num >> 1;
      count++;
      //cout << money << endl;
    }
    bool flag = check(X,M);
    if(flag){
      change = true;
      ansflag = true;
      if(ans > money){
	ans = money;
      }
    }
  }
  
  if(ansflag){
    cout << ans << endl;
  }else{
    cout << -1 << endl;
  }
  return 0;
}


Measured memory_bytes: 4064
#include <bits/stdc++.h>
using namespace std;
int main(){
	int e;
	while(cin>>e,e){
		int ans=100000000;
		for(int z=0;z*z*z<=e;z++){
			for(int y=0;y*y<=e-z*z*z;y++){
				ans=min(ans,e-z*z*z-y*y+y+z);
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
	string s;cin>>s;
	int n=s.length();
	if(s[0]!='1'||s[n-1]!='0'){
		cout<<-1<<endl;
		return 0;
	}
	bool f=true;
	for(int i=0;i<n/2;i++){
		if(s[i]!=s[n-i-2])f=false;
	}
	if(!f){
		cout<<-1<<endl;
		return 0;
	}
	int id=2;
	cout<<1<<" "<<2<<endl;
	for(int i=1;i<n/2;i++){
		cout<<id<<" "<<i+2<<endl;
		if(s[i]=='1'){
			id=i+2;
		}
	}
	for(int i=n/2+1;i<n;i++){
		cout<<id<<" "<<i+1<<endl;
	}
}


Measured memory_bytes: 1664
from collections import deque

K = int(input())
G = [-1 for k in range(K)]

Q = deque()
Q.append([1,1])
while len(Q) > 0:
    p = Q.popleft()
    x, d = p[0], p[1]
    if G[x] == -1:
        G[x] = d
        Q.append([(x+1)%K,d+1])
        Q.appendleft([(x*10)%K,d])

print(G[0])


Measured memory_bytes: 17512
#from pprint import pprint
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from copy import deepcopy
#from itertools
#import sys 
#sys.setrecursionlimit(N) #N回まで再起を許可する。
 
# = map(int,input().split())
 
# = list(map(int,input().split()))
 
# = [list(map(int,input().split())) for _ in range(XXXX)]
from sys import stdin


def main():
    input = stdin.readline
    
    h,n = map(int,input().split())
    
    ab= [list(map(int,input().split())) for _ in range(n)]
    
    dp = [[100000001 for _ in range(h+1)] for _ in range(n+1)]
    #dp[i][j]はi番目のものを選んだ時かつダメージ送料がjだったときの最小MP、
    
    
    for i in range(1,n+1):
        dp[i][0] = 0
        for j in range(h+1):
            a = ab[i-1][0]
            b = ab[i-1][1]
            dp[i][j] = min(dp[i][j],dp[i-1][j])
            if j+a <= h:
                dp[i][j+a] = min(dp[i][j] + b, dp[i-1][j+a], dp[i][j+a])
            elif j+a > h:
                dp[i][h] = min(dp[i][j] + b, dp[i-1][h], dp[i][h])

    
    print(dp[-1][-1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 126684
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
using namespace std;
signed main() {
	int n; cin >> n;
	bool b = 0;
	for1(i, 9)if (n%i == 0 && n / i <= 9)b = 1;
	cout << (b ? "Yes\n" : "No\n");
}

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

int main(void){
	int a,b,a1,a2,b1,b2,min,tmp;
	int x[4];

	while(cin>>a>>b && (a||b)){
		min = 999999999;
		for(a1=1,a2=a;a1<=a2;a1++,a2=a/a1){
			if(a%a1!=0) continue;
			for(b1=1,b2=b;b1<=b2;b1++,b2=b/b1){
				if(b%b1!=0) continue;
				x[0]=a1,x[1]=a2,x[2]=b1,x[3]=b2;
				sort(x,x+4);
				if((tmp = pow(x[1]-x[0],2)+pow(x[2]-x[1],2)+pow(x[3]-x[2],2)) < min)min = tmp;
			}
		}
		cout<<min<<endl;
	}

	return 0;
}

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

int main()
{
  int x, y, z;
  cin >> x >> y >> z;
  cout << z << " " << x << " " << y  << endl;
}

Measured memory_bytes: 3572
def f(s):
    if s == "A":
        return A
    elif s == "B":
        return B
    elif s == "C":
        return C


def inc(s):
    global A, B, C

    if s == "A":
        A += 1
    elif s == "B":
        B += 1
    elif s == "C":
        C += 1


def dec(s):
    global A, B, C

    if s == "A":
        A -= 1
    elif s == "B":
        B -= 1
    elif s == "C":
        C -= 1


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

if A + B + C == 0:
    print("No")

elif A + B + C == 1:
    ans = []
    for _ in range(N):
        s = input()
        if f(s[0]) == f(s[1]) == 0:
            print("No")
            exit()
        else:
            if f(s[0]) == 1:
                ans.append(s[1])
                dec(s[0])
                inc(s[1])
            elif f(s[1]) == 1:
                ans.append(s[0])
                inc(s[0])
                dec(s[1])
    print("Yes")
    for i in range(N):
        print(ans[i])

elif A + B + C >= 2:
    s = []
    for i in range(N):
        s.append(input())

    # 共に0を選ぶことは初手でしか起こり得ない
    # 2回目以降は、0は1個以下
    if f(s[0][0]) == f(s[0][1]) == 0:
        print("No")
        exit()

    ans = []
    for i in range(len(s)):
        if f(s[i][0]) >= 1 and f(s[i][1]) == 0:
            ans.append(s[i][1])
            dec(s[i][0])
            inc(s[i][1])
        elif f(s[i][0]) == 0 and f(s[i][1]) >= 1:
            ans.append(s[i][0])
            inc(s[i][0])
            dec(s[i][1])
        # (1,1,0)の状態で(1,1)を選んだ時 and 最後の手ではない and 次に違う手が予定されている
        elif (A + B + C == 2) and (f(s[i][0]) == f(s[i][1]) == 1) and (i < N - 1):
            # s[i][0]を次に操作する場合
            if s[i][0] == s[i + 1][0] or s[i][0] == s[i + 1][1]:
                ans.append(s[i][0])
                inc(s[i][0])
                dec(s[i][1])
            # s[i][1]を次に操作する場合
            elif s[i][1] == s[i + 1][0] or s[i][1] == s[i + 1][1]:
                ans.append(s[i][1])
                dec(s[i][0])
                inc(s[i][1])
        else:
            if f(s[i][0]) <= f(s[i][1]):
                ans.append(s[i][0])
                inc(s[i][0])
                dec(s[i][1])
            else:
                ans.append(s[i][1])
                inc(s[i][1])
                dec(s[i][0])

    print("Yes")
    # print(ans)
    for i in range(N):
        print(ans[i])


Measured memory_bytes: 93396
import std.stdio, std.conv, std.functional, std.string;
import std.algorithm, std.array, std.container, std.range, std.typecons;
import std.numeric, std.math, std.random;
import core.bitop;

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto K = RD;
	auto h = RDA;
	long ans;
	foreach (i; 0..N)
	{
		if (h[i] >= K)
			++ans;
	}

	writeln(ans);
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 4360
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<iomanip>
#include<limits>
#include<deque>
#include<map>
#include<list>
#include<set>
#include <unordered_set>
#include<vector>
#include<cmath>
#include<cstdio>
#include<memory>
#include<bitset>
#include<stack>
#include<functional>
#include<queue>
#include<regex>
#include<time.h>

using namespace std;


#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl

#define Tof(x) (x) ? Yes : No
#define TOF(x) (x) ? YES : NO
#define tof(x) (x) ? yes : no

using ll = long long;

//constexpr ll MOD = 1000000007;
constexpr ll INF = 1050000000;


/*vectorの要素を全部確認するやつだよ。普通に拡張for文したほうがいいよ。

for (vector<int>::iterator itr = ans.begin(); itr != ans.end(); ++itr) {
	cout << *itr << " ";
}

*/


/*for文でx,yを上下左右確認するやつだよ。正直使いづらいよ。

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


for (int i = 0; i < 4; i++) {
	int ny = y + dy[i];
	int nx = x + dx[i];
}

*/


/*繰り返し二乗法だよ。modもとってくれるよ。n^kをmodで割った余りでやってくれるよ。

ll POW_MOD(ll n, ll k, ll mod) {
	ll r = 1;

	for (; k > 0; k >>= 1) {
		if (k & 1) {
			r = (r * n) % mod;
		}
		n = (n * n) % mod;
	}
	return r;
}

*/


/*実行開始からの経過時間を表すよ。

while (clock() < 1900000) {  }

*/


/*まだ使えないテクニックのメモだよ。

for (int bit = 0; bit < (1<<n); ++bit)//bit全探索用のfor文だよ

*/


/*2重for文書くのめんどくなった時用だよ。

for (int i = 0; i < h; ++i) {
	for (int j = 0; j < w; ++j) {

	}
}

*/


int main() {
	int n, k; cin >> n >> k;
	int x[114514];

	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}
	int ans = INF;
	for (int i = 0; i + k - 1 < n; i++) {
		int tmp=x[i+k-1]-x[i] + min(abs(x[i]), abs(x[i + k - 1])); 
		ans = min(ans, tmp);
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 640
#include <stdio.h>

int flag[200005];

int main() {

	int N, x;

	scanf("%d %d",&N,&x);

	int i;

	if (x == 1 || x == (2 * N) - 1) {
		printf("No\n");
	}
	else if (N == 2) {
		printf("Yes\n");
		printf("1\n2\n3\n");
	}
	else {
		printf("Yes\n");
		if (x == 2) {
			int cnt = 5;
			for (i = 0; i < (2 * N) - 1; i++) {
				if (i == (((2 * N) - 1) / 2) - 1) {
					printf("3\n");
				}
				else if (i == (((2 * N) - 1) / 2)) {
					printf("2\n");
				}
				else if (i == (((2 * N) - 1) / 2) + 1) {
					printf("1\n");
				}
				else if (i == (((2 * N) - 1) / 2) + 2) {
					printf("4\n");
				}
				else {
					printf("%d\n",cnt);
					cnt++;
				}
			}
		}
		else {
			flag[x - 2] = 1;
			flag[x - 1] = 1;
			flag[x] = 1;
			flag[x + 1] = 1;
			int cnt = 1;
			for (i = 0; i < (2 * N) - 1; i++) {
				if (i == (((2 * N) - 1) / 2) - 1) {
					printf("%d\n",x-1);
				}
				else if (i == (((2 * N) - 1) / 2)) {
					printf("%d\n",x);
				}
				else if (i == (((2 * N) - 1) / 2) + 1) {
					printf("%d\n",x+1);
				}
				else if (i == (((2 * N) - 1) / 2) + 2) {
					printf("%d\n",x-2);
				}
				else {
					while (1) {
						if (flag[cnt] == 0) { break; }
						cnt++;
					}
					printf("%d\n", cnt);
					cnt++;
				}
			}
		}
	}

	return 0;
}


Measured memory_bytes: 1408
#include<iostream>
 using namespace std;
 int main (){
     int a,b;
     char op;
     while(1){
     	cin>> a >> op >> b;
     	if(op == '?') break;
     	else if(op =='+') cout<< a+b <<endl;
     	else if(op == '-') cout<< a-b <<endl;
     	else if(op == '*') cout<< a*b <<endl;
     	else if(op == '/') cout<< a/b << endl;
     	
     }
 }

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <numeric>
#include <math.h>

using namespace std;



void func()
{
	int N;
	cin >> N;
	double JPY = 0, BTC = 0;
	for (int i = 0; i < N; ++i)
	{
		string S;
		double money;
		cin >> money >> S;
		
		if (S == "JPY")
			JPY += money;
		else
			BTC += money;
	}
	cout << JPY + BTC * 380000 << endl;

	return;
}

int main() {

//	while (1)
		func();
	return 0;
}


Measured memory_bytes: 3264
#include <iostream>
#include <vector>
#include <string>
#include <numeric>

using namespace std;

void sum(const int& h, const int& w, const int& d, vector<vector<int>>& hsum, const vector<string>& s) {
    for (int i=0; i<w; i++) {
        int j = 0;
        for (int k=0; k<h; k++) {
            hsum[j][i] += s[k][i] == '1';
            if (d>>k&1) j++;
        }
    }
}

int main() {
    int h,w,k;
    cin >> h >> w >> k;
    vector<string> s(h);
    for (int i=0; i<h; i++) cin >> s[i];

    int ans = INT_MAX;
    for (int i=0; i<(1<<(h-1)); i++) {
        int th = __builtin_popcount(i)+1;
        vector<vector<int>> hsum(th, vector<int>(w, 0));
        sum(h,w,i,hsum,s);


        int cnt = th - 1;
        vector<int> wsum(th,0);
        for (int j=0; j<w; j++) {
            bool f = false;
            for (int l=0; l<th; l++) {
                if (hsum[l][j] > k) {
                    cnt = INT_MAX;
                    goto B;
                }

                wsum[l] += hsum[l][j];
                if (wsum[l] > k) {
                    f = true;
                    break;
                }
            }

            if (f) {
                for (int l=0; l<th; l++) {
                    wsum[l] = hsum[l][j];
                }
                cnt++;
            }
        }
        B:
        ans = min(ans, cnt);
    }

    cout << ans << endl;
}

Measured memory_bytes: 3164
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int INF = 100000000;
int n;
int cost[20][20];
int dp[100000];

// ùÉKê½¸_WS
int rec(int S) {
  // ùÉ¶ÝµÄ¢é
  if (dp[S] >= 0) return dp[S];

  // SÄÌ¸_ðÁ½
  if (S == (1<<n)-1) {
    return dp[S] = 0;
  }
  // Ü¾ÁÄ¢È¢¸_ª¶Ý·é
  int res = INF;
  for (int i = 0; i < n; i += 1) {
    if (!(S>>i & 1)) {
      // Ú®·éêÌÅ¬RXgð²×é
      int min_cost = cost[i][0];
      for (int j = 1; j <= n; j += 1) {
        // ùÉNAµÄ¢éê
        if (S>>(j-1) & 1) {
          min_cost = min(min_cost, cost[i][j]);
        }
      }
      res = min(res, rec(S|1<<i) + min_cost);
    }
  }
  return dp[S] = res;
}

void solve() {
  memset(dp, -1, sizeof dp);
  for(int i=0;i<n;i++)
  for(int j=0;j<=n;j++)
  cin>>cost[i][j];
  
  cout<<rec(0)<<endl;
}

int main (int argc, char const* argv[]) {
  while (cin>>n, n) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 1256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <string>
#include <stdio.h>
#include <cmath>
#include <limits.h>
using namespace std;

typedef long long ll;

#define min(a, b) (((a) < (b))? (a):(b))
#define max(a, b) (((a) > (b))? (a):(b))
#define REP(i, a, n) for(int i=(a); i<(n); ++i)
#define rep(i, n) REP(i, 0, (n))
#define square(a) (a)*(a)
#define pb push_back


int main(void) {
    
    string s,ss;
    cin >> s;
    rep(i,s.size()){
        if(i % 2 != 0) continue;
        ss += s[i];
    }
    cout << ss << endl;
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var a = Array.ConvertAll(Console.ReadLine().Split(), int.Parse).ToList();
            double mid = a.Max() / 2.0;
            double temp = double.MaxValue;
            int ans = -1;
            for(int i = n-1; i >= 0; i--)
            {
                if(Math.Abs(a[i] - mid) < temp)
                {
                    temp = Math.Abs(a[i] - mid);
                    ans = a[i];
                }
            }
            Console.WriteLine("{0} {1}",a.Max(),ans);
        }
    }
}

Measured memory_bytes: 20192