akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

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

typedef long long lint;

using namespace std;

int main(){
  string S;
  cin>>S;
  string K="keyence";
  int ans=0;
  for(int i=0;i<K.length();i++){
    if(S[i]!=K[i])break;
    ans++;
  }
  for(int i=0;i<K.length();i++){
    if(S[S.length()-1-i]!=K[K.length()-1-i])break;
    ans++;
  }
  cerr<<ans<<endl;
  cout<<(ans>=7?"YES":"NO")<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin >> n >> k;
    int tmp;
    map<int,int> m;
    int count = 0;
    for(int i = 0;i < n;i++)
    {
        cin >> tmp;
        if(m.count(tmp))
        {
            m[tmp]++;
        }
        else
        {
            m.insert(make_pair(tmp,1));
            count++;
        }
    }
    if(count <= k)
    {
        cout << "0\n";
        return 0;
    }
    vector<int> v;
    for(auto x : m)
    {
        if(x.second != 0)
            v.push_back(x.second);
    }
    sort(v.begin(),v.end());
    int sum = 0;
    for(int i = 0;i < (int)v.size();++i)
    {
        sum += v[i];
        if(count - 1 <= k)
            break;
        count--;
    }
    cout << sum << '\n';
}

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

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

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/11  Problem: ABC 086 D / Link: http://abc086.contest.atcoder.jp/tasks/abc086_d  ----- */


template<typename T>
struct CumulativeSum2D {
	int H, W;
	vector< vector< T > >data;
	CumulativeSum2D(int H_, int W_) : data(H_ + 1, vector< T >(W_ + 1, 0)) { H = H_, W = W_; };
	inline void add(int y, int x, T val) {
		if (y > (int)data.size() || x > (int)data[0].size()) return;
		data[y + 1][x + 1] += val;
	}
	inline void build() {
		FOR(i, 0, H)FOR(j, 0, W)data[i + 1][j + 1] += data[i + 1][j];
		FOR(i, 0, H)FOR(j, 0, W)data[i + 1][j + 1] += data[i][j + 1];
	}
	inline T query(int y, int x) {
		return (data[y + 1][x + 1]);
	}
	inline T QUERY(int sy, int sx, int ty, int tx) {
		return data[ty][tx] - data[sy][tx] - data[ty][sx] + data[sy][sx];
	}
};



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

	LL N, K; cin >> N >> K;
	CumulativeSum2D<LL>B(4 * K, 4 * K);
	CumulativeSum2D<LL>W(4 * K, 4 * K);
	auto ADD = [&](CumulativeSum2D<LL> &C, LL y, LL x) {
		C.add(y, x, 1);
		C.add(y + 2 * K, x, 1);
		C.add(y, x + 2 * K, 1);
		C.add(y + 2 * K, x + 2 * K, 1);
	};
	FOR(i, 0, N) {
		LL x, y; char c;
		cin >> x >> y >> c;
		x %= 2 * K, y %= 2 * K;
		if (c == 'B')ADD(B, y, x);
		else ADD(W, y, x);
	}
	W.build();
	B.build();
	LL ans = 0LL;
	FOR(ky, 0, 2 * K) {
		FOR(kx, 0, 2 * K) {
			{
				LL ret = W.QUERY(ky, kx, ky + K, kx + K);
				ret += W.QUERY(ky + K, kx + K, ky + 2 * K, kx + 2 * K);
				ret += B.QUERY(ky, kx + K, ky + K, kx + 2 * K);
				ret += B.QUERY(ky + K, kx, ky + 2 * K, kx + K);
				ans = max(ans, ret);
			}
			{
				LL ret = B.QUERY(ky, kx, ky + K, kx + K);
				ret += B.QUERY(ky + K, kx + K, ky + 2 * K, kx + 2 * K);
				ret += W.QUERY(ky, kx + K, ky + K, kx + 2 * K);
				ret += W.QUERY(ky + K, kx, ky + 2 * K, kx + K);
				ans = max(ans, ret);
			}
		}
	}


	cout << (ans) << "\n";

	return 0;
}


Measured memory_bytes: 250624
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define per(i,n) for (int i=n-1; i>=0; --i)
#define all(a) a.begin(), a.end()
using namespace std;
using ll = long long;
using P  = pair<int,int>;
using vi = vector<int>;
using vv = vector<vi>;

int main(){
  int n; cin >> n;
  rep(i,n)cout<<"ACL";
  cout << endl;
    return 0;
}

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


int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;

  bool wint =false;
  while(a>0){
    c-=b;
//    cout<<"aokiHP="<<c<<endl;
    if(c<=0){
      wint =true;
      break;
    }
    a-=d;
//    cout<<"takaHP="<<c<<endl;

  }
  if(wint){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }

}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;

bool isLoop(string S){
    int L = S.length();
    bool ans =true;
    for(int i=0;i<=((L-2)/2);i++)
    {
        if(S[i]!=S[(L-1)-i]){
            ans=false;
        }
    }
    return ans;
}

int main(){

    string S,sub1,sub2;

    bool ans;

    cin >> S;

    sub1 = S.substr(0,(S.length()-1)/2);
    sub2 = S.substr((S.length()+1)/2);

    ans = isLoop(S)&&isLoop(sub1)&&isLoop(sub2);

    if(ans){
        cout << "Yes"<<endl;
    }else{
        cout << "No"<<endl;
    }


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    int N;cin>>N;
    if(N%2==0){
        cout<<N<<endl;
    }else{
        cout<<2*N<<endl;
    }
}


Measured memory_bytes: 3640
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

int main(void){
	int N,a[52],p=0,m=0,max=1;
	scanf("%d",&N);
	reg(i,1,N){
		scanf("%d",&a[i]);
		if(a[i]>0){
			p++;
		}else if(a[i]<0){
			m++;
		}
		if(abs(a[max])<abs(a[i]))max=i;
	}
	if(p==0 && m==0){//全て0
		printf("0\n");
	}else if(p==N){//全て正
		printf("%d\n",N-1);
		reg(i,1,N-1){
			printf("%d %d\n",i,i+1);
		}
	}else if(m==N){//全て負
		printf("%d\n",N-1);
		ireg(i,2,N){
			printf("%d %d\n",i,i-1);
		}
	}else{//その他
		//絶対値maxを足す
		printf("%d\n",2*(N-1));
		reg(i,1,N){
			if(i==max)continue;
			printf("%d %d\n",max,i);
		}
		if(a[max]>0){
			reg(i,1,N-1){
				printf("%d %d\n",i,i+1);
			}
		}else{
			ireg(i,2,N){
				printf("%d %d\n",i,i-1);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
#define inf 100000000/*10^8*/
#define rep(i,l,r) for(int i=l;i<=r;i++)

////////////////////////////////////////
void yes(){
    cout<<"POSSIBLE"<<endl;
}
void no(){
    cout<<"IMPOSSIBLE"<<endl;
}

int gcd(int a,int b){
    if(a>b)swap(a,b);
    if(a==0)return b;
    else return gcd(b%a,a);
}


int main(){
    int n,k;cin>>n>>k;
    int a[n],max=0;
    rep(i,0,n-1){
        cin>>a[i];
        if(max<a[i])max=a[i];
    }
    if(max<k){
        no();
        return 0;
    }
    int g=gcd(a[0],a[1]);
    rep(i,2,n-1){
        g=gcd(g,a[i]);
    }
    if((max-k)%g==0)yes();
    else no();
    
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> b(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> b[i];
  }
  int ans;
  if (n == 2) {
    ans = 2 * b[0];
  }
  else {
    ans = b.front() + b.back();
    for (int i = 0; i < n - 2; i++) {
      ans += min(b[i], b[i + 1]);
    }
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val (a, b, c) = readIntegerList()
    val k = readInteger()
    val ans = if (test(a, b, c, k)) "Yes" else "No"
    out.println(ans)
}

fun test(r: Int, g: Int, b: Int, n: Int): Boolean {
    if (n == 0) {
        return g in (r + 1) until b
    }

    if (g in (r + 1) until b) {
        return true
    }

    return test(r * 2, g, b, n - 1) || test(r, g * 2, b, n - 1) || test(r, g, b * 2, n - 1)
}

fun test(r: Int, g: Int, b: Int) = g in (r + 1) until b

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)




Measured memory_bytes: 36428
#include <stdio.h>

#define MAX 100

void scf(int *p, int N[]) {
  int n;
  for(int i=0; i<*p; ++i) {
    scanf("%d", &n);
    N[n] = 1;
  }
}

int main(void) {
  int N, X, Y, Z, i, cnt = 0;
  int A[MAX+1] = {0};
  int B[MAX+1] = {0};
  int C[MAX+1] = {0};

  scanf("%d", &N);

  scanf("%d", &X);
  scf(&X, A);
  scanf("%d", &Y);
  scf(&Y, B);
  scanf("%d", &Z);
  scf(&Z, C);

  for(i=0; i<=N; ++i) {
    if(A[i] == 0 && C[i] == 1) {
      ++cnt;
    }else if(B[i] == 1 && C[i] == 1) {
      ++cnt;
    }
  }

  printf("%d\n", cnt);

  return 0;
}



Measured memory_bytes: 2108
#include<cstdio>
#include<vector>
#include<cmath>
#include<complex>
#include<algorithm>

using namespace std;

typedef double Real;
typedef complex<Real> Point;

const Real PI=acos(-1.0);
const Real eps=1e-8;

template<class T> bool eq(T a, T b){
	return abs(a-b)<eps;
}

template<class T> int sgn(T a){
	if(eq(a,(T)0)) return 0;
	if(a>0) return 1;
	return -1;
}

struct Circle:vector<Real> {
	Point c;
	Real r;
	Circle(){}
	Circle(Point c,Real r):c(c),r(r){}
};

Real R;
Circle cs[110];
int N;

Point getPolar(Point c,Point r,Real ang){
	return c+r*Point(cos(ang),sin(ang));
}

Real normalize(Real x){
	while(x<-PI) x+=PI*2;
	while(x>PI) x-=PI*2;
	return x;
}

Real arg(Point p){
	return atan2(p.imag(),p.real());
}

void iCC(Circle &c,Circle &c2){
	if(eq(c.c,c2.c)) return;
	Real d=abs(c.c-c2.c);
	Real r=c.r,r2=c2.r;
	if(sgn(d-(r+r2))>0) return;
	else if(sgn(d-(r+r2))==0){//out tan
		Real ang=normalize(arg(c2.c-c.c));
		c.push_back(ang);
	}else if(sgn(d-abs(r-r2))>0){//inter two points
		Real ang=arg(c2.c-c.c);
		Real ang2=acos((r*r+d*d-r2*r2)/(2*r*d));
		c.push_back(normalize(ang+ang2));
		c.push_back(normalize(ang-ang2));
	}else if(sgn(d-abs(r-r2))==0){//in tan
		if(r>r2){
			c.push_back(normalize(arg(c2.c-c.c)));
		}else{
			c.push_back(normalize(-arg(c2.c-c.c)));
		}
	}
	else{//contained
		return;
	}
}

bool changeCircles(){
	for(int i=0;i<N;i++){
		cs[i].r=R-cs[i].r;
		if(cs[i].r<eps) return false;
	}
	return true;
}

void getAllPoints(){
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if(i==j) continue;
			iCC(cs[i],cs[j]);
		}
	}
	for(int i=0;i<N;i++){
		cs[i].push_back(0);
		cs[i].push_back(PI);
	}
}

bool checkValidity(Point p){
	for(int i=0;i<N;i++){
		Real d=abs(p-cs[i].c);
		if(sgn(d-cs[i].r)>0) return false;
	}
	return true;
}

Real calcLength(){
	Real len=0,ang_sum=0;
	for(int i=0;i<N;i++){
		sort(cs[i].begin(),cs[i].end());
		for(int j=0;j<cs[i].size();j++){
			Real ang1=cs[i][j];
			Real ang2=j+1==cs[i].size()?cs[i][0]+PI*2:cs[i][j+1];
			Real ang=(ang1+ang2)/2;
			Point p=getPolar(cs[i].c,cs[i].r,ang);
			bool flg=checkValidity(p);
			if(flg){
				len+=(cs[i].r+R)*(ang2-ang1);
				ang_sum+=(ang2-ang1);
			}
		}
	}
	if(ang_sum<eps) return 0;
	Real len2=R*(PI*2-ang_sum);
	Real res=len+len2;
	return res;
}

void solve(){
	bool flg=changeCircles();
	if(flg==false){
		printf("0.0\n");
		return;
	}
	getAllPoints();
	Real ans=calcLength();
	printf("%f\n",ans);
}

void input(){
	int r;
	scanf("%d%d",&N,&r);
	if(N==0) exit(0);
	R=r;
	for(int i=0;i<N;i++){
		int x,y,r;
		scanf("%d%d%d",&x,&y,&r);
		cs[i].clear();
		cs[i]=Circle(Point(x,y),r);
	}
}

int main(){
	while(true){
		input();
		solve();
	}
	return 0;
}

Measured memory_bytes: 1392
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;

template<typename T = long long>
T gcd(T a, T b) { return b ? gcd(b, a%b) : a; }

// value
int N;
int p[60];

void solve() {

	cin >> N;
	for (int i = 1; i <= N; i++) {
		cin >> p[i];
	}

	int ans = 0;

	for (int i = 1; i <= N; i++) {
		if (p[i] != i) ans++;
	}

	if (ans == 2 || ans == 0) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return;

}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	solve();

	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

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; }

template<class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template<class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template<class T, class V>
typename enable_if<is_class<T>::value == 0>::type fill(T &t, const V &v) {
    t = v;
}
template<class T, class V>
typename enable_if<is_class<T>::value != 0>::type fill(T &t, const V &v){
    for (auto &e : t) fill(e, v);
}

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }

#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }


int N;
vector<long long > B;


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

    while (cin >> N) {
        B.resize(N-1);
        for (int i = 0; i < N-1; ++i) cin >> B[i];

        long long res = B[0] + B.back();
        for (int i = 0; i + 1 < B.size(); ++i) {
            res += min(B[i], B[i+1]);
        }
        cout << res << endl;
    }
}


















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


#include "boost/multiprecision/cpp_int.hpp"
#include "boost/multiprecision/cpp_dec_float.hpp"
namespace mp = boost::multiprecision;
typedef mp::cpp_int LL;
typedef mp::number<mp::cpp_dec_float<1024>> DD;// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)

 
typedef long double dd;
//#define i_7 (ll)(1E9+7)
#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define rrep(i,r,l) for(ll i=r;i>=l;i--)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
#define endl "\n"  //インタラクティブで消す！！！！！！！！！！！！！！！！！！！！！
#define SORT(v) sort(v.begin(),v.end())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
#define POSL(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define POSU(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
template<class T,class S>
inline bool chmax(T &a, S b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T,class S>
inline bool chmin(T &a, S b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

void mod_print(ll k){
    ll P=1000;
    rep(y,1,P){
        ll x=mod(y*k);
        if(x+P>=i_7){
            x-=i_7;
        }
        if(abs(x)<=P){
            //cout<<x<<"/"<<y;
            cout<<setprecision(5)<<(dd)x/(dd)y;
            return;
        }
    }
    cout<<"nun"<<endl;
}
#define all(c) c.begin(),c.end()
//////////////////////////


int main(){fastio
    ll n;cin>>n;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    ll sum=0;
    rep(i,0,n-1){
        sum^=a[i];
    }
    rep(i,0,n-1){
        cout<<(sum^a[i])<<" ";
    }
    
    return 0;
}






Measured memory_bytes: 5224
#include "stdio.h"

int main( void )
{
    int i,j;
    int ld[10],tmp;

    for(i=0;i<10;i++){
        scanf("%d",&ld[i]);
    }
    for(i=0;i<10;i++){
        for(j=i+1;j<10;j++){
            if( ld[i]<ld[j] ){
                tmp = ld[i];
                ld[i] = ld[j];
                ld[j] = tmp;
            }
        }
    }

    printf("%d\n%d\n%d\n",ld[0],ld[1],ld[2]);
    
    return 0;
}

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

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

    return 0;
}


Measured memory_bytes: 256
from itertools import product as prod

n, m = map(int, input().split())
ks = [tuple(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))
ans = 0

for pattern in (prod((0, 1), repeat=n)):
    tmp = []
    for i in range(len(ks)):
        rep = 0
        for j in ks[i][1:]:
            if pattern[j - 1] == 1:
                rep += 1
        if (rep & 1) == p[i]:
            tmp.append(True)
        else:
            tmp.append(False)
    if all(tmp):
        ans += 1
print(ans)


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

#define ll long long
#define F first
#define S second
#define endl '\n'
#define pb push_back

using namespace std;

const ll limit = 266666333332 ;

int main()
{
  ios_base :: sync_with_stdio(0);
  cin.tie(0), cout.tie(0);

  int n ;
  cin >> n ;
  ll sum = 0 ;
  for(int i = 1; i <= n ; i++){
    if(i % 3 and i % 5) sum += i * 1LL ;
  }
  cout << sum << endl ; 
  return 0 ;
}


Measured memory_bytes: 3600
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

template<class T>
inline istream& operator >>( istream& s, vector<T>& v ) {
	for( size_t i = 0; i < v.size(); ++i ) { s >> v[i]; }
	return s;
}

template<class T>
inline ostream& operator <<( ostream& s, vector<T>& v ) {
	for( size_t i = 0; i < v.size(); ++i ) {
		if( i ) { s << ' '; }
		s << v[i];
	}
	return s;
}

int main() {
	ios_base::sync_with_stdio( false );

	int n;
	cin >> n;
	vector<int> a( n );
	cin >> a;
	int q;
	cin >> q;
	while( q-- > 0 ) {
		int k;
		cin >> k;
		cout << binary_search( a.begin(), a.end(), k ) << '\n';
	}

	return 0;
}



Measured memory_bytes: 3356
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

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

int main(){
  int W,H,C;
  cin >> W >> H >> C;
  i64 g = gcd(W,H);
  cout << W / g * H / g * C << endl;;
}



Measured memory_bytes: 3088
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <string>
#include <sstream>
#include <iomanip>
#include <complex>
using namespace std;

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

//x left to right
//y up to down
//(0,0) is left-up
int w,h;
int sx,sy,gx,gy;
struct G
{
	int grid[20][20];
	int x,y;
};
G Data;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,1,0,-1};
int ans = 114514;

bool isinrange(int x,int y){
	return (x>-1&&y>-1&&x<w&&y<h);
}
int Simulate(int dir,G *gd){
	int movecnt = 0;
	while(1){
		gd->x += dx[dir]; gd->y += dy[dir];
		if(!isinrange(gd->x,gd->y)) return 0;
		
		if(gd->grid[gd->x][gd->y]==1){
			if(movecnt>0){
				gd->grid[gd->x][gd->y] = 0;
				gd->x -= dx[dir]; gd->y -= dy[dir];
				return 1;
			}else{
				return 0;
			}
		}else{
			if(gd->x==gx&&gd->y==gy) return 2;
		}
		movecnt++;
	}
}

void search(int cnt,G testgrid){
	if(cnt==10) return;
	REP(i,4){
		G bkgrid = testgrid;
		int rst = Simulate(i,&bkgrid);
		if(rst==1){
			search(cnt+1,bkgrid);
		}else if(rst==2){
			ans = min(ans,cnt+1);
		}
	}
}
int main(){
	while(1){
		ans = 114514;
		cin >> w >> h;
		if(w==0&&h==0) break;
		REP(i,h){
			REP(j,w){
				cin >> Data.grid[j][i];
				if(Data.grid[j][i]==2){
					Data.grid[j][i]=0;
					sx = j; sy = i;
				} 
				if(Data.grid[j][i]==3){
					Data.grid[j][i]=0;
					gx = j; gy = i;
				}
				Data.x = sx; Data.y = sy;
			}
		}
		search(0,Data);
	
		if(ans==114514) cout << -1 << endl;
		else cout << ans << endl;
	}
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
//#define int long long
struct POINT {
	int a, b;
};	

int id[1000][1000];
int sc[1000][1000];
int g[1000][1000];
int rev[1000][1000];
vector<POINT> bar;

signed main()
{
	int n, m, h, k;
	while (scanf("%d %d %d %d", &n, &m, &h, &k), n){
		memset(id, 0, sizeof(id));
		memset(sc, 0, sizeof(sc));
		memset(g, 0, sizeof(g));
		memset(rev, 0, sizeof(rev));
		bar.clear();
		
		h--;
		for (int i = 0; i < n; i++){
			id[i][0] = i;
			scanf("%d", &sc[i][h]);
		}
		for (int i = 0; i < m; i++){
			int a, b;
			scanf("%d %d", &a, &b);
			a--; b--;
			g  [a    ][b    ] = 1;
			g  [a + 1][b    ] = -1;
			rev[a    ][b + 1] = 1;
			rev[a + 1][b + 1] = -1;
			bar.push_back((POINT){a, b});
		}
		for (int i = 0; i < h; i++){
			for (int j = 0; j < n; j++){
				id[j + g[j][i]][i + 1] = id[j][i];
			}
		}
		for (int i = h; i > 0; i--){
			for (int j = 0; j < n; j++){
				sc[j + rev[j][i]][i - 1] = sc[j][i];
			}
		}
		
		int sum = 0;
		for (int i = 0; i < k; i++) sum += sc[i][0];
		int res = sum;
		for (int i = 0; i < bar.size(); i++){
			int tmp = sum;
			//printf("%d %d\n", id[bar[i].a][bar[i].b], id[bar[i].a + 1][bar[i].b]);
			if (id[bar[i].a][bar[i].b] < k && id[bar[i].a + 1][bar[i].b] >= k){
				tmp -= sc[bar[i].a][bar[i].b];
				tmp += sc[bar[i].a + 1][bar[i].b];
				res = min(res, tmp);
			}
			else if (id[bar[i].a][bar[i].b] >= k && id[bar[i].a + 1][bar[i].b] < k){
				tmp += sc[bar[i].a][bar[i].b];
				tmp -= sc[bar[i].a + 1][bar[i].b];
				res = min(res, tmp);
			}
		}
		printf("%d\n", res);
	}
	
	return 0;
}

Measured memory_bytes: 17724
n=gets.split.map(&:to_i)
ans=0

if n[0]>n[3]
  ans=n[3]
 else n[0]<n[3]
 v=n[0]
    if n[1]>(n[3]-n[0])
     ans=v
    else
     ans=v-(n[3]-n[0]-n[1])
     end
 end

puts ans


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

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

	vector<int> a(N);

	for (int I = 0; I < N; I++) {
		cin >> a.at(I);
	}
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());

	int ptA = 0, ptB = 0;
	for (int I = 0; I < N; I++) {
		if (I % 2 == 0) ptA += a.at(I);
		else ptB += a.at(I);
	}

	cout << ptA - ptB << endl;
}

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

int main(){

    int n,k;
    cin>>n>>k;
    vector<int> h(n),dp(n,2147483647);
    dp[0]=0;
    for(int i=0;i<n;i++) cin>>h[i];

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




    return 0;
}

Measured memory_bytes: 1024
//  s.at(0) = toupper(s.at(0));//小文字なら大文字へ//大文字の場合はそのまま
//  s.at(i) = tolower(s.at(i));//大文字なら小文字へ//小文字の場合はそのまま
//s配列に格納した単語を、辞書順にソートする
//getline(cin, s);
//  sort(s.begin(), s.end());
//  string t = "keyence";//で文字列入力ができる
//s.empty() //emptyなら1を出力 入っていれば0を出力
/*//ABC018-B 部分的にreverseをかける解法
int main() {
  string s;
  cin >> s;
  int n;
  cin >> n;
  vector<int>a(n);
  vector<int>b(n);
  rep(i,n) cin>>a.at(i)>>b.at(i);
  rep(i,n)a.at(i)--;
  rep(i,n)b.at(i)--;
  string t;
  rep(i,n){
    t = s;
    for(int k=0;k<=b.at(i)-a.at(i);k++){
      t.at(a.at(i)+k) = s.at(b.at(i)-k);
    }
    s = t;
  }
  cout << s << endl;
}
*///ABC018-B
//  string s;
//  cin >> s;
//  cout << s.at(0) <<endl;
//  cout << s.at(0)-'0' <<endl;
//  Aが16？
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(ll a, ll b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

ll lcm(ll a, ll b)
{
   return a * b / gcd(a, b);
}
int kan_hyaku(int n){
  int kurai = 0;
  for(int i=0;i<3;i++){
    kurai = n%10;
    n /=10;
  }
  return kurai;
}
int kan_ju(int n){
  int kurai = 0;
  for(int i=0;i<2;i++){
    kurai = n%10;
    n /=10;
  }
  return kurai;
}
int kan_ichi(int n){
  int kurai = 0;
  for(int i=0;i<1;i++){
    kurai = n%10;
    n /=10;
  }
  return kurai;
}
int main() {
  int n;
  cin >> n;
  vector<ll>a(n);
  vector<ll>b(n);
  rep(i,n) cin>> a.at(i) >> b.at(i);
  ll sum = 0;
  for(int k=n-1;k>=0;k--){
//    ll k = n - i - 1;
    ll po = b.at(k) - (a.at(k) + sum ) % b.at(k);
    if(po < b.at(k)){
      sum += po;
    }
  }
  cout << sum << endl;
}
/*
  for(int i=n-1;i>=0;i--){
    if(a.at(i)+sum <= b.at(i) ){
      sum += b.at(i) - (a.at(i)+sum);
    }
    else{
      ll num = (a.at(i)+sum) % b.at(i);
      if(num != 0){
        sum += b.at(i) - num;
      }
    }
  }
  cout << sum << endl;
}
*/

Measured memory_bytes: 4816
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <fstream>
#include <numeric>

using namespace std;

#define max(a,b) a > b ? a : b
#define min(a,b) a < b ? a : b

//#define M_PI 3.1415926535

int main()
{
    double R;

    cin >> R;

    cout << 2 * M_PI * R << endl;

    return 0;
}

Measured memory_bytes: 3788
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
//#include "C:\code\all.h"
#define rep(i,n) for(i = 0; i < n; i++)
using namespace std;


int main(){
  int i,j,k;
  int sx,tx,sy,ty;
  cin>>sx >> sy>>tx>>ty;

  string ans = "";
  int dx,dy;
  dx = tx - sx; dy = ty - sy;
  cout << string(dx,'R') << string(dy,'U');
  cout << string(dx,'L') << string(dy,'D');
  cout << 'D' << string(dx+1,'R') << string(dy+1,'U') << 'L';
  cout << 'U' << string(dx+1,'L') << string(dy+1,'D') << 'R';
  
}




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

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

const int N = 1e5 + 10;
int x;
bool isP[N];

void init() {
  memset(isP, true, sizeof isP);
  for (int i = 2; i < N; ++i) {
    if (isP[i]) {
      for (int j = i + i; j < N; j += i) {
        isP[j] = false;
      }
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  init();
  cin >> x;
  while (!isP[x]) {
    x++;
  }
  cout << x << endl;
  
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, a, b) for(int i = (a); i < (b); ++i)

int main()
{
    int N;
    scanf("%d", &N);
    ll res = 0;
    REP(i, 0, N) {
        ll a;
        scanf("%lld", &a);
        res += a-1;
    }
    printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdlib>
#include<iostream>
#include<vector>
#include<map>
#include<cmath>
using namespace std;
char S[3];
int main(int argc, char const *argv[])
{
cin>>S;
int ans=0;
for(int i=0;i<sizeof(S)/sizeof(char);i++){
    if(S[i]=='1'){
        ans++;
    }
}
cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
//Author : Sidiq Tri Pratikto
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(v) v.begin(), v.end()

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
//order_of_key(x) = number of elements stricly smaller than x
//find_by_order(x) = return x-th largest element
typedef long long LL;
const LL MOD = 1e9 + 7;
const double PI = 2 * acos(0);
LL dp[2020];

int main() {
	string s;
	cin >> s;
	LL tmp = 1;
	int l1 = s.length();
	vector<int> v;
	for (int i = l1 - 1; i >= 0; i--) {
		LL x = (tmp * (s[i] - '0')) % 2019;
		v.pb(x);
		tmp *= 10;
		tmp %= 2019;
	}
	dp[0] = 1;
	LL pre = 0, ans = 0;
	while (!v.empty()) {
		pre += v.back();
		pre %= 2019;
		v.pop_back();
		ans += dp[pre];
		dp[pre]++;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 4500
N, K = gets.split.map(&:to_i)
ABs = readlines.map{|l| l.split.map(&:to_i)}

ans, s = nil, 0
ABs.sort_by{|a, b| a}.each do |a, b|
  s += b
  if s >= K
    ans = a
    break
  end
end
puts ans

Measured memory_bytes: 19832
import java.io.*;
import java.util.*;
import java.lang.Math;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        Integer[] a = new Integer[n];
        for(int i = 0; i < n; ++i){
            a[i] = sc.nextInt();
        }
        Arrays.sort(a, Collections.reverseOrder());
        Integer sum = 0;
        for(int i = 0; i < k; ++i){
            sum += a[i];
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 21844
#include<iostream>
using namespace std;
int main()
{
int n,t,x,y,px=0,py=0,pt=0,r;
bool c;
cin>>n;
while(n--)
{
c=false;
cin>>t>>x>>y;
r=(t-pt-x+px-y+py);
if(r>=0)
{
if(r%2==0)
{c=true;}
}
if(!c)
{
puts("No");
return 0;
}
pt=t;
px=x;
py=y;
}
puts("Yes");
return 0;
}

Measured memory_bytes: 256
s = input()
 
x = s.count("dreamerase")
a = s.count("dreamer") - x
b = s.count("dream") - a 
c = s.count("eraser")
d = s.count("erase") - c

if a*7 + b*5 + c*6 + d*5 == len(s):
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3188
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int k, a, b;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> k >> a >> b;
    for (int i = a; i <= b; i++) {
        if (i % k == 0) {
            cout << "OK\n";
            return 0;
        }
    }
    cout << "NG\n";
    //system("pause");
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	int w, a, b, ans;
	cin >> w >> a >> b;
	if (b < a) {
		if (b + w < a) ans = abs(a - (b + w));
		else ans = 0;
	}
	if (b >= a) {
		if (b <= a + w) ans = 0;
		else ans = abs(b - (a + w));
	}
	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import bisect


def solve(N: int, L: "List[int]"):
    L.sort()
    cnt=0
    for a_i in range(N):
        for b_i in range(a_i+1, N):
            c_r = bisect.bisect_left(L, L[a_i]+L[b_i])
            cnt += c_r - b_i - 1
    return cnt


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, L))

if __name__ == '__main__':
    main()


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



int main(){
    string s;
    cin >> s;
    int ans[s.size()];

    for(int i=0;s.size()>i;i++)ans[i]=0;
    
    int r = 0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='R'){
            r++;
        }else if(s[i-1]=='R'){
            ans[i]+=r/2;
            ans[i-1]+=r/2;
            if(r%2==1)ans[i-1]++;
            r=0;
        }
    }
    int l = 0;
    for(int i=s.size()-1;i>=0;i--){
        if(s[i]=='L'){
            l++;
        }else if(s[i+1]=='L'){
            ans[i]+=l/2;
            ans[i+1]+=l/2;
            if(l%2==1)ans[i+1]++;
            l=0;
        }
    }

    for(int i=0;s.size()>i;i++)cout << ans[i] << " ";
    cout << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
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; }
const double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

    int T1, T2, A1, A2, B1, B2;
	cin >> T1 >> T2 >> A1 >> A2 >> B1 >> B2;
	if(A1 > B1){
		swap(A1, B1);
		swap(A2, B2);
	}
	if(A1*T1 + A2*T2 < B1*T1+B2*T2){
		cout << 0 << endl;
	}
	else if(A1*T1 + A2*T2 == B1*T1+B2*T2){
		cout << "infinity" << endl;
	}
	else{
		int W1 = (B1-A1)*T1;
		int sum = (A1*T1+A2*T2) - (B1*T1+B2*T2);
		if(W1 % sum == 0) cout << W1/sum*2 << endl;
		else cout << W1/sum*2+1 << endl;
	}
}

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

int main (){
    string s, t ;
    int col=0 ;
    cin >> s >> t ;
    int len = s.length() ;
    for (int i=0, j=0; i < len ; i++, j++){
        if (t[j]==s[i]) col++ ;
    }
    if (col== len) cout << "Yes" ;
    else cout << "No" ;
}

Measured memory_bytes: 3620
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  int w, h;
  while (cin >> w >> h, w) {
    vvi a(h, vi(w - 1)), b(h - 1, vi(w));
    rep(i, 2 * h - 1) {
      if (even(i)) rep(j, w - 1) cin >> a[i / 2][j];
      if (odd(i)) rep(j, w) cin >> b[i / 2][j];
    }
    queue<tuple<int, int, int>> q;
    q.emplace(0, 0, 1);
    vvi visited(h, vi(w));
    while (q.size()) {
      int i, j, d;
      tie(i, j, d) = q.front();
      q.pop();
      if (visited[i][j]) continue;
      visited[i][j] = true;
      if (i == h - 1 && j == w - 1) {
        cout << d << endl;
        goto next;
      }
      if (i > 0 && !b[i - 1][j]) q.emplace(i - 1, j, d + 1);
      if (j > 0 && !a[i][j - 1]) q.emplace(i, j - 1, d + 1);
      if (i < h - 1 && !b[i][j]) q.emplace(i + 1, j, d + 1);
      if (j < w - 1 && !a[i][j]) q.emplace(i, j + 1, d + 1);
    }
    cout << 0 << endl;
  next:;
  }
}

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

int main() {
  int a,b,c,d,L,R;
  cin >> a >> b >> c >> d;
  L = a + b;
  R = c + d;
  
  if (L > R) {
    cout << "Left" << endl;
  }
  else if (R > L) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
typedef long long ll;

int N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

bool MM(char a, char b){
    if(a == '0' && b != '0') return true;
    if(a == '1'){
        if(b == '0' || b == '1' || b == '2' ) return true;
    }
    return false;
}

int main() {
    cin>>S;
    bool ue = MM(S.at(0),S.at(1));
    bool shita = MM(S.at(2),S.at(3));
    if(ue&&shita){
        cout<<"AMBIGUOUS"<<endl;
        return 0;
    }
    if(ue){
        cout<<"MMYY"<<endl;
        return 0;
    }
    if(shita){
        cout<<"YYMM"<<endl;
        return 0;
    }
    cout<<"NA"<<endl;
    return 0;

}

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

int main(){
  int n;
  string A(52,'?');
  for(int i = 0; i < 26; ++i) A[i] = 'a'+i;
  for(int i = 0; i < 26; ++i) A[i+26] = 'A'+i;
  map<char,int> M;
  for(int i = 0; i < 52; ++i) M[A[i]] = i;
  while(cin >> n, n){
    vector<int> K(n);
    for(int i = 0; i < n; ++i) cin >> K[i];
    string s;
    cin >> s;
    for(size_t i = 0; i < s.length(); ++i){
      cout << A[(M[s[i]]+52-K[i%n])%52];
    }
    cout << endl;
  }
}



Measured memory_bytes: 3232
#include<stdio.h>
int main(){
	int x,y,i;
	while(i==0){
		scanf("%d %d",&x,&y);
		if(x==0&&y==0){
			break;
		}
		if(x<=y){
			printf("%d %d\n",x,y);
		}
		else{
			printf("%d %d\n",y,x);
		}
	}
	return 0;
}

Measured memory_bytes: 596
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;

    vector<long long> v;
    long long vi;
    for (int i = 0; i < n; ++i)
    {
        cin >> vi;
        v.push_back(vi);
    }

    if (k >= n)
    {
        cout << 0;
        return 0;
    }

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

    long long total = 0;
    for (int i = 0; i < n-k; ++i)
    {
        total += v[i];
    }
    cout << total;

    return 0;
}

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

int main(){
    string s;
    cin >> s;
    string t = "";
    vector<int> cnt;
    bool flag = true;
    int tmp = 0;
    for (int i = 0; i < s.size(); i++){
        if (s[i] != 'x') {
            t += s[i];
            if (flag){
                cnt.push_back(tmp);
                tmp = 0;
                flag = false;
            }
            else cnt.push_back(0);
        }
        else {
            if (flag) tmp++;
            else {
                tmp = 1;
                flag = true;
            }
        }
    }
    cnt.push_back(tmp);
    flag = true;
    for (int i = 0; i < t.size(); i++){
        if (t[i] != t[t.size() - i - 1]) flag = false;
    }
    if (!flag){
        cout << - 1 << endl;
        return 0;
    }
    int ans = 0;
    for (int i = 0; i < cnt.size(); i++) ans += abs(cnt[i] - cnt[cnt.size() - i - 1]);
    cout << ans / 2 << endl;
}

Measured memory_bytes: 1148
s = str(input())

ans = ''
for i in range(8):
  bin_str = format(i, '03b')
  #print(bin_str)

  total = int(s[0])
  formula = s[0]
  for oper, num in zip(bin_str, s[1:]):
    if int(oper) == 1:
      total += int(num)
      formula += '+' + str(num)
    else:
      total -= int(num)
      formula += '-' + str(num)

  if total == 7:
    ans = formula
    break

print(ans + '=7')

Measured memory_bytes: 3064
/*
    Sk arman Hossain
    University of Barisal

    Problem :
    Solution :
 */
#include<bits/stdc++.h>
#define nl cout<<"\n";
#define N 200001
#define PR pair<ll,ll>
#define sf1(n) cin>>n
#define sf2(n, m) cin>>n>>m
#define sf3(n, m,k ) cin>>n>>m>>k
#define pfn(n) printf("%d\n",n)s
#define pf1(n) printf("%d ",n)
#define pfl1(n) printf("%lld ",n)
#define pfln(n) printf("%lld\n",n)
#define pfu(n) printf("%llu\n",n)
#define pfs(s) printf("%s",s)
#define YES cout<<"YES\n"
#define NO cout<<"NO\n"
#define minus1 printf("-1\n")
#define PB push_back
#define PI 3.1415926536
#define VST(v) sort(v.begin(),v.end())
#define VSTcmp(v,cmp) sort(v.begin(),v.end(),cmp)
#define fori(i,n) for(;i<n;i++)
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define MP make_pair
#define ff first
#define ss second
#define tt third
#define mod 1000000007
#define T(n) printf("test %d\n",n)
int dx[] = {0,0,1,-1,2,2,-2,-2,1,-1,1,-1};
int dy[] = {1,-1,0,0,1,-1,1,-1,2,2,-2,-2};
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;


vector<ll>V,V2,V3;
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//    /freopen("1input.txt","r",stdin);
//    /freopen("1output.txt","w",stdout);
    ll tcase=1;
    //sf1(tcase);
    //cin>>tcase;
    for(ll test=1; test<=tcase; test++)
    {
        ll a,b,d;
        cin>>a>>b>>d;
        ll ans=(b/d)-(a-1)/d;
        cout<<ans<<"\n";
    }
///*****************************  ALHAMDULILLAH  *****************************/
}



Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define fi first
#define se second
#define show(x) cerr<<#x<<"="<<x<<"\n"
typedef long long ll;
template<typename T>
void print_to(std::ostream &os,const char *,const char *tail,const T &fst){
  os<<fst<<tail;
}
template<typename Fst,typename... Rst>
void print_to(std::ostream &os,const char *del,const char *tail,const Fst &fst,const Rst &... rst){
  os<<fst<<del;
  print_to(os,del,tail,rst...);
}
template<typename Iter>
void print_to_(std::ostream &os,const char *del,const char *tail,Iter bgn,Iter end){
  for(Iter it=bgn;it!=end;){
    os<<*it;
    if(++it!=end)os<<del;
    else os<<tail;
  }
}
template<typename Fst,typename... Rst>
void println(const Fst &fst,const Rst &... rst){
  print_to(std::cout,"\n","\n",fst,rst...);
}
template<typename Fst,typename... Rst>
void print(const Fst &fst,const Rst &... rst){
  print_to(std::cout," ","\n",fst,rst...);
}
template<typename Iter>
void println_(Iter bgn,Iter end){
  print_to_(std::cout," ","\n",bgn,end);
}
using namespace std;
//const ll MOD=(ll)1e9+7;
//const ll inf=(ll)1e14;
const int dy[]={1,0,-1};
const int dx[]={1,0,-1};
int n,m,h,w;
string s;
ll a[200001],b[200001];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
  FILE *stream1;
  //FILE *stream2;
  stream1=freopen("in","r",stdin);
  //stream2=freopen("out","w",stdout);
  if(stream1==NULL)return 0;
  //if(stream2==NULL)return 0;
#endif
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  for(int i=0;i<n;i++){
    cin>>b[i];
  }
  ll t=1;
  ll ans=0;
  for(int i=0;i<30;i++){
    if(i!=0)t*=2;
    vector<int> v1,v2;
    for(int j=0;j<n;j++){
      v1.push_back(a[j]%(2*t));
      v2.push_back(b[j]%(2*t));
    }
    sort(v2.begin(),v2.end());
    int res=0;
    for(int j=0;j<n;j++){
      int x=lower_bound(v2.begin(),v2.end(),t-v1[j])-v2.begin();
      int y=lower_bound(v2.begin(),v2.end(),2*t-v1[j])-v2.begin();
      int z=lower_bound(v2.begin(),v2.end(),3*t-v1[j])-v2.begin();
      res+=y-x;
      res+=n-z;
    }
    if(res&1){
      ans+=t;
    }
  }
  print(ans);
#ifdef LOCAL_DEFINE
  cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
  fclose(stream1);
  //fclose(stream2);
#endif
  return 0;
}






Measured memory_bytes: 6380
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  int a[59];
  cin>>n>>k;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  sort(a,a+n);
  reverse(a,a+n);
  int sum=0;
  for(int i=0;i<k;i++){
    sum+=a[i];
  }
  cout<<sum<<endl;
  return(0);
}


Measured memory_bytes: 256
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    double c=(a+b)/2.0;
    if((int)c==c)
      System.out.println((int)c);
    else 
      System.out.println("IMPOSSIBLE");

	}
}

Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main() {
    long long N, A, B;
    cin >> N >> A >> B;
    
    long long res;
    if (A > B || (N == 1 && A != B)) res = 0;
    else res = (B - A) * N -2 * (B - A) +1; 
    cout << res << endl;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    gcd_L = [0]*(N+2)
    gcd_R = [0]*(N+2)

    def gcd(x, y):
        if y == 0:
            return x
        while y != 0:
            x, y = y, x % y
        return x

    for i, a in enumerate(A):
        gcd_L[i+1] = gcd(gcd_L[i], a)
    for i, a in enumerate(A[::-1], start=1):
        gcd_R[-(i+1)] = gcd(gcd_R[-i], a)
    gcd_R[0] = gcd_R[1]
    gcd_L[-1] = gcd_L[-2]
    # print(gcd_L, gcd_R)
    ans = 0
    for i in range(1, N+1):
        cur = gcd(gcd_L[i-1], gcd_R[i+1])
        ans = max(ans, cur)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 63984