akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
stack<char>cube;
int main()
{
    int cnt=0;
    int i;
    char s[100005];
    scanf("%s",s);
    int len=strlen(s);
    for(i=0;i<=len-1;i++)
    {
        if(cube.empty()||cube.top()==s[i])cube.push(s[i]);
        else
        {
            cube.pop();
            cnt+=2;
        }
    }
    printf("%d",cnt);
    return 0;
}



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

int main() {
  int n;
  cin >> n;
  while(n--) {
    int a[10],b=0,c=0,i;
    for(i=0; i<10; i++) cin >> a[i];
    for(i=0; i<10; i++) {
      if(a[i]>b && a[i]>c) {
	if(b>c) b=a[i];
	else c=a[i];
      }
      else if(a[i]>b && a[i]<c) b=a[i];
      else if(a[i]<b && a[i]>c) c=a[i];
      else break;
    }
    if(i==10) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 1152
#include <stdio.h>
#include <string.h>
int line[200],temp[199],n;
void cut(int k){
    memcpy(temp,line,k*4);
    memcpy(line,line+k,(2*n-k)*4);
    memcpy(line+(2*n-k),temp,k*4);
}
void riffle(void){
    int i,t;
    memcpy(temp,line,n*4);
    for(t=0,i=0;i<n;i++){
        line[t++]=temp[i];
        line[t++]=line[n+i];
    }
}
int main(void){
    int c,k,i;
    scanf("%d",&n);
    for(i=1;i<=2*n;i++)line[i-1]=i;
    scanf("%d",&c);
    while(c--){
        scanf("%d",&k);
        k==0?riffle():cut(k);
    }
    for(i=0;i<2*n;i++)
        printf("%d\n",line[i]);
    return 0;
}

Measured memory_bytes: 2660
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*) array, (T*) (array + N), val);
}
pii Dir [] = {
	{ 1,0 },{ 0,1 }
};

ll lcm(ll m, ll n)
{
	return m * n / gcd(m, n);
}
signed main() {
	int n;

	while (scanf("%d", &n) != EOF) {
		if (!n)
			break;
		vector<int> pa(n,-1);
		vector<pair<pii,pii>> mob(n);
		REP(i, n) {
			int a, b, c, d;

			scnaf("%d %d %d %d", &a, &b, &c, &d);
			c--; d--;
			if (c >= 0) {
				pa[c] = i;
			}
			if (d >= 0) {
				pa[d] = i;
			}
			mob[i] = { {a,b},{c,d} };
		}
		while (1) {
			bool f = 0;
			REP(i, mob.size()) {
				if (mob[i].second.first < 0 && mob[i].second.second < 0) {
					if (pa[i] < 0)
						continue;
					if (mob[pa[i]].second.first >= 0 || mob[pa[i]].second.second >= 0) {
						int lc = lcm(mob[i].first.first*-mob[i].second.first, mob[i].first.second*-mob[i].second.second);
						int sum = lc / mob[i].first.first + lc / mob[i].first.second;
						if (mob[pa[i]].second.first == i) {
							mob[pa[i]].second.first = -sum;
						}
						else if (mob[pa[i]].second.second == i) {
							mob[pa[i]].second.second = -sum;
						}
						f = 1;
					}
				}
			}
			if (!f) {
				REP(i, n) {
					if (pa[i] == -1) {
						int lc = lcm(mob[i].first.first*-mob[i].second.first, mob[i].first.second*-mob[i].second.second);
						int sum = lc / mob[i].first.first + lc / mob[i].first.second;
						pritnf("%d\n", sum);
						break;
					}
				}
				break;
			}
		}
	}


	return 0;
}

Measured memory_bytes: 3136
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cctype>


using namespace std;
#define modd 1000000007


typedef pair<long long, long long> pl;


typedef string::const_iterator State;
class ParseError {};




#define ll long long




class UnionFind {
public:
	vector <ll> par;
	vector <ll> siz;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL){
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};


class SegmentTree {
private:
	int n;
	vector <ll> node;

public:
	// 元の配列　v をセグメントツリーで表現する。
	SegmentTree(vector<ll> v) {
		//最下段のノード数は元配列のサイズ以上になる最小の2冪->これをnとおく。
		//セグ木全体で必要なノード数は2n-1個である。
		int sz = v.size();
		n = 1; 
		while (n < sz)n *= 2;

	}

};




long long N, M, K, a, b, c, d, e, H, W, L;
ll A[200005] = {};
ll B[100005] = {};
ll C[300005] = {};
bool f, ff;
string S,T;
set <long long>sll;
pl bufpl;
vector <long long>vl[2][100005];
vector <long long>vll[100005];
vector <pl>vpl;
vector <string> vs;
set<ll> llset;
multiset<ll> llmset;


/*
struct ST
{
	long long Kati;
	int bangou;

	bool operator<(const ST& another) const
	{
		return Kati < another.Kati;//比較
	};

};



/*vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/


long long modinv(long long aa, long long mm) {
	long long bb = mm, uu = 1, vv = 0;
	while (bb) {
		long long tt = aa / bb;
		aa -= tt * bb; swap(aa, bb);
		uu -= tt * vv; swap(uu, vv);
	}
	uu %= mm;
	if (uu < 0) uu += mm;
	return uu;
}



ll minn, maxx;
double ansa;
bool fl[30] = {};



string ss, sss;


int main() {


	cin >> a >> b >> c;


	e = 0;
	for (;;) {
		if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) {
			break;
		}
		e++;
		A[0] = (a + b) / 2;
		A[1] = (b + c) / 2;
		A[2] = (c + a) / 2;
		a = A[0];
		b = A[1];
		c = A[2];

		if (a == b && b == c) {
			e = -1;
			break;
		}
	}

	
	cout << e << endl;
	return 0;

}


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

int n;
long long sum = 0, ans = 0, cur = 0, cnt = 0, a[200010];
int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
        a[i] += a[i-1];
    }
    sort(a, a + n+1);
    for(int i = 0; i <= n; i++) {
        if(a[i] == cur) cnt++;
        else {
            ans += cnt*(cnt-1)/2;
            cur = a[i], cnt = 1;
        }
    }
    ans += cnt*(cnt-1)/2;
    printf("%lld", ans);
}


Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <iostream>
#include <iterator>
#include <vector>

using i64 = long long;

struct item_t {
  i64 w;
  i64 v;

  bool operator<(const item_t &r) const { return w < r.w; }
  void operator+=(const item_t &r) {
    w += r.w;
    v += r.v;
  }
};

struct node_t {
  i64 rem;
  i64 v;
  int id;

  bool operator<(const node_t &r) const { return rem < r.rem; }
  void operator+=(const item_t &r) {
    rem -= r.w;
    v += r.v;
  }
};

template <class T>
std::vector<T> merge(const std::vector<T> &a, const std::vector<T> &b) {
  std::vector<T> ret;
  std::merge(a.begin(), a.end(), b.begin(), b.end(), std::back_inserter(ret));
  return ret;
}

template <class T>
std::vector<T> add(const std::vector<T> &a, const item_t &x) {
  auto b = a;
  for (T &e : b) {
    e += x;
  }
  return merge(a, b);
}

void chmax(i64 &a, i64 b) { a = std::max(a, b); }

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

  int n;
  std::cin >> n;

  const int mid = std::min<int>(n + 1, std::ceil(std::pow(n, 2.0 / 3)) + 1);

  std::vector<item_t> item(n + 1);
  for (int i = 1; i <= n; ++i) {
    std::cin >> item[i].v >> item[i].w;
  }

  std::vector<std::vector<item_t>> shallow(mid);
  shallow[0].push_back({0, 0});
  for (int i = 1; i < mid; ++i) {
    shallow[i] = add(shallow[i / 2], item[i]);
  }

  int q;
  std::cin >> q;

  std::vector<std::vector<node_t>> deep(n + 1);
  for (int i = 0; i < q; ++i) {
    int v;
    i64 l;
    std::cin >> v >> l;
    deep[v].push_back({l, 0, i});
  }
  for (auto &e : deep) {
    std::sort(e.begin(), e.end());
  }
  for (int i = n; i >= mid; --i) {
    deep[i] = add(deep[i], item[i]);
    deep[i / 2] = merge(deep[i / 2], deep[i]);
  }

  std::vector<i64> ans(q, 0);
  for (int i = 1; i < mid; ++i) {
    auto si = shallow[i].begin();
    const auto se = shallow[i].end();
    auto di = deep[i].begin();
    const auto de = deep[i].end();

    i64 vmax = std::numeric_limits<i64>::lowest() / 2;

    while (si != se || di != de) {
      if (si != se && (di == de || si->w <= di->rem)) {
        chmax(vmax, si->v);
        ++si;
      } else {
        chmax(ans[di->id], vmax + di->v);
        ++di;
      }
    }
  }

  for (const i64 e : ans) {
    std::cout << e << "\n";
  }

  return 0;
}


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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define ALL(name) name.begin(),name.end()
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

int H, W, K;
vector<string> S;

// この行の # がある場所
vector< vector<int> > isExist;

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

    cin >> H >> W >> K;
    S.resize(H);
    REP(i, H) {
        cin >> S[i];
    }

    isExist.assign(H, vector<int>());
    REP(i, H) {
        REP(j, W) {
            if(S[i][j] == '#') {
                isExist[i].push_back(j);
            }
        }
    }

    int cnt = 1;
    vector< vector<int> > ans(H, vector<int>(W, 0));

    REP(i, H) {
        if(isExist[i].size() == 0) { continue; }
        bool isFirst = true;
        for(auto& pos : isExist[i]) {
            if(isFirst) {
                isFirst = false;
                // 左も埋める
                for(int j = pos - 1; j >= 0; --j) {
                    assert(S[i][j] != '#');
                    ans[i][j] = cnt;
                }
            }
            // 右を埋める
            ans[i][pos] = cnt;
            for(int j = pos + 1; j < W; ++j) {
                if(S[i][j] == '#') { break; }
                ans[i][j] = cnt;
            }
            cnt++;
        }
    }
    // # がなかった行は、あった行をコピーする
    // 下にコピー
    int latest = -1;
    REP(i, H) {
        if(isExist[i].size() > 0) {
            latest = i;
            continue;
        }
        if(latest >= 0) {
            REP(j, W) {
                ans[i][j] = ans[latest][j];
            }
        }
    }
    // 上にコピー
    latest = -1;
    for(int i = H - 1; i >= 0; --i) {
        if(isExist[i].size() > 0) {
            latest = i;
            continue;
        }
        if(latest >= 0) {
            REP(j, W) {
                ans[i][j] = ans[latest][j];
            }
        }
    }

    REP(i, H) {
        REP(j, W) {
            printf("%lld%c", ans[i][j], (j == W-1) ? '\n' : ' ');
        }
    }

    return 0;
}


Measured memory_bytes: 2816
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//




int main() {

    int n, q; cin >> n >> q;
    string s; cin >> s;
    int l[q], r[q];
    rep(i,q) cin >> l[i] >> r[i];

    int dp[n];
    rep(i,n) dp[i] = 0;
    for (int i = 1; i < n; ++i) {
        dp[i] = dp[i-1];
        if (s[i-1] == 'A' && s[i] == 'C') ++dp[i]; 
    }
    rep(i,q) {
        out(dp[r[i]-1] - dp[l[i]-1]);
    }
    
    return 0;
}










Measured memory_bytes: 2240
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
template<class T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<class T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
const int INF = 1e18, MOD = 1e9 + 7;
struct UnionFind {
    vector<int> t;
    UnionFind(int size): t(size, -1) {}
    int root(int x) {return t[x] < 0 ? x : t[x] = root(t[x]);}
    int size(int x) {return -t[root(x)];}
    bool isSame(int x, int y) {return root(x) == root(y);}
    bool unite(int x, int y) {
        x = root(x), y = root(y);
        if(x != y) {
            if(t[y] < t[x]) swap(x, y);
            t[x] += t[y], t[y] = x;
        }
        return x != y;
    }
};
signed main() {
    INCANT;
    int n, c[11111], a, b, res = 0, g[11111] = {}, itr = -1, root;
    cin>>n;
    UnionFind uf(n);
    queue<pair<int, int>> q;
    rep(i, n - 1) {
        cin>>a>>b;
        a--, b--;
        q.push({a, b});
    }
    rep(i, n) {
        cin>>c[i];
        res += c[i];
    }
    sort(c, c + n);
    reverse(c, c + n);
    cout<<res - c[0]<<endl;
    root = q.front().first;
    g[q.front().first] = c[++itr];
    g[q.front().second] = c[++itr];
    uf.unite(q.front().first, q.front().second);
    q.pop();
    while(!q.empty()) {
        queue<pair<int, int>> tmp;
        while(!q.empty()) {
            if(uf.isSame(root, q.front().first)) {
                g[q.front().second] = c[++itr];
                uf.unite(q.front().first, q.front().second);
            } else if(uf.isSame(root, q.front().second)) {
                g[q.front().first] = c[++itr];
                uf.unite(q.front().first, q.front().second);
            } else {
                tmp.push(q.front());
            }
            q.pop();
        }
        q = tmp;
    }
    rep(i, n) {
        cout<<g[i]<<' ';
    }
    cout<<endl;
}


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


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int hand[] = new int[256];
		final int LEFT = 0;
		final int RIGHT = 1;
		Arrays.fill(hand, RIGHT);
		hand['q'] = LEFT;
		hand['w'] = LEFT;
		hand['e'] = LEFT;
		hand['r'] = LEFT;
		hand['t'] = LEFT;
		hand['a'] = LEFT;
		hand['s'] = LEFT;
		hand['d'] = LEFT;
		hand['f'] = LEFT;
		hand['g'] = LEFT;
		hand['z'] = LEFT;
		hand['x'] = LEFT;
		hand['c'] = LEFT;
		hand['v'] = LEFT;
		hand['b'] = LEFT;
		
		while(true){
			String input = br.readLine();
			
			if(input.equals("#")){
				break;
			}
			
			int currentHand = hand[input.charAt(0)];
			
			int change = 0;
			for(int i = 1; i < input.length() ; i++){
				if(currentHand != hand[input.charAt(i)]){
					change++;
					currentHand = hand[input.charAt(i)];
				}
			}
			
			System.out.println(change);
		}
	}

}

Measured memory_bytes: 24568
A = [int(x) for x in input().split()]
C5 =0
C7 =0
for i in range(3):
    if A[i] == 5:
        C5 += 1
    if A[i] == 7:
        C7 += 1

if C5 == 2 and C7 ==1:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 2940
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
c = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [[-1, -1] for i in range(n+1)]

dp[0] = [0, 0]
for i in range(1, n+1):
    for ai in a:
        ci = c[ai]
        if i - ci >= 0 and dp[i-ci][0] != -1:
            if dp[i][0] < dp[i-ci][0] + 1:
                dp[i] = [dp[i-ci][0] + 1, ai]
i = n
ans = []
while i > 0:
    ai = dp[i][1]
    ans.append(ai)
    i -= c[ai]
print("".join(map(str, ans)))


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

typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,P> P2;
const ll INF=100000000000000001;

int main() {


	int a,b,c;
	cin>>a>>b>>c;
	if(a<=c&&b>=c){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	//
//	cin>>n;
//	int total=1;
//	for(int i=0;i<n;i++)total=(total*2)%1000000007;
//	for(int i=1;i<n+1;i++){
//		cin>>p[i];
//		R[p[i]].push_back(i);
//	}
//	queue<int> que;
//	que.push(0);
//	while(!que.empty()){
//		int p=que.front();que.pop();
//		int sum=0;
//		for(auto it:R[p]){
//			sum+=R[it].size();
//		}
//		int k=n-sum;
//	}
	return 0;
}


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

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> c(n);
    int a[n][m];
    rep(i,n){
        cin >> c[i];
        rep(j,m) cin >> a[i][j];
    }
    
    int ans = INF;
    rep(s,1<<n){
        int cost = 0;
        vector<int> d(m);
        rep(i,n){
            if(s>>i&1){
                cost += c[i];
                rep(j,m) d[j] += a[i][j];
            }
        }
        bool ok = true;
        rep(j,m) if(d[j] < x) ok = false;
        if(ok) ans = min(ans,cost);
    } 
    if(ans == INF){
        cout << -1 << endl;
    }else{
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3624
import java.util.Scanner;

class Main {

	int[][] s = new int [5][11];

	int[][] t = new int [5][11];

	int[][] c = new int [5][11];

	int[][] d = new int [5][11];

	int n = 0, b = 0, f = 0, r = 0, v = 0, i = 0, k = 0;

	public void of() {

		Scanner sc = new Scanner(System.in);

		n = sc.nextInt();

		for(i = 1; i <= n; i++) {

			b = sc.nextInt();

			f = sc.nextInt();

			r = sc.nextInt();

			v = sc.nextInt();

			switch(b) {

				case 1:

					s[f][r] += v;

					break;

				case 2:

					t[f][r] += v;

					break;

				case 3:

					c[f][r] += v;

					break;

				case 4:

					d[f][r] += v;

					break;

				default:

					break;

			}

		}

		
		for(n = 1; n <= 4; n++) {

			for(i = 1; i < 4; i++) {

				for(k = 1; k < 11; k++) {

					switch(n) {

						case 1:

							System.out.printf(" %d",s[i][k]);

							break;

						case 2:

							System.out.printf(" %d",t[i][k]);

							break;

						case 3:

							System.out.printf(" %d",c[i][k]);

							break;

						case 4:

							System.out.printf(" %d",d[i][k]);

							break;

						default:

							break;

					}

				}

				System.out.println();

			}

			if(n < 4) {

			System.out.println("####################");

			}

		}

	}

	public static void main(String[] args) {

		new Main().of();

	}

}

Measured memory_bytes: 30484
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define maxn 25
using namespace std;
int n;
int a[maxn];
bool chk(int a,int b,int c){
	if(b!=max(a,max(b,c))){
		if(b!=min(a,min(b,c))){
			return 1;
		}
		else if (a+b+c-b*2==max(a,max(b,c)))
			return 1;
	}
	return 0;
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	int ans=0;
	for(int i=2;i<n;i++){
		if(chk(a[i-1],a[i],a[i+1]))
			ans++;
	}
	cout<<ans;
	return 0;
}

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

int main() {
	
    char b  ;    
    cin >> b  ;
  
  if(b=='A')   cout << 'T' ;
  if(b=='T')   cout << 'A' ;
  if(b=='G')   cout << 'C' ;
  if(b=='C')   cout << 'G' ;

  cout << endl ;
  
  	return 0;
}


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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                int volume = int.Parse(Console.ReadLine());

                if (volume == 0) break;

                int minPrice = int.MaxValue;

                for (int c = 0; c <= volume; c += 500)
                {
                    int rest = volume - c;

                    for (int b = 0; b <= rest; b += 300)
                    {
                        int a = rest - b;

                        if (a % 200 != 0) continue;

                        int na = a / 200;
                        int nb = b / 300;
                        int nc = c / 500;

                        int price = na * 380 + nb * 550 + nc * 850;

                        int ma = na / 5;
                        int mb = nb / 4;
                        int mc = nc / 3;

                        int discount = ma * 380 + mb * 330 + mc * 306;

                        price -= discount;

                        minPrice = Math.Min(minPrice, price);
                    }
                }
                sb.AppendLine(minPrice.ToString());
            }
            Console.Write(sb);
        }
    }
}

Measured memory_bytes: 9108
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <stack>
#include <cctype>
#include <complex>
#include <vector>
#include <algorithm>

using namespace std;


bool solve(){

	string str;
	cin>> str;
	int n=str.size();
	for(int i=n-1;i>=0;i--){
		cout<< str[i];
	}
	cout<< endl;
	
	return true;
}

int main(){
	cout.setf(ios::fixed);
	cout.precision(10);
	solve();

	return 0;
}

 

Measured memory_bytes: 1172
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;

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

constexpr double EPS = 1e-5;
struct point {
	double x, y;
	explicit point(double x_ = 0, double y_ = 0):x(x_), y(y_) {}

	inline point operator+(const point &p) const {
		return point(x + p.x, y + p.y);
	}

	inline point operator-(const point &p) const {
		return point(x - p.x, y - p.y);
	}

	inline point operator*(double s) const {
		return point(x * s, y * s);
	}

	inline bool operator<(const point &p) const {
		return x + EPS < p.x || (abs(x - p.x) < EPS && y + EPS < p.y);
	}
};

inline double norm(const point &p) {
	return p.x * p.x + p.y * p.y;
}

inline double dot(const point &a, const point &b) {
	return a.x * b.x + a.y * b.y;
}

inline double cross(const point &a, const point &b) {
	return a.x * b.y - a.y * b.x;
}

inline int ccw(const point &a, point b, point c) {
	b = b - a;
	c = c - a;
	const double t = cross(b, c);
	if(t > EPS) return 1;
	if(t < -EPS) return -1;
	if(dot(b, c) < 0) return 2;
	if(norm(b) < norm(c)) return -2;
	return 0;
}

typedef vector<point> polygon;

struct segment {
	point a, b;
	segment(const point &a_, const point &b_):a(a_), b(b_) {}
};

inline bool intersect(const segment &s, const point &p) {
	return ccw(s.a, s.b, p) == 0;
}

inline bool intersect(const segment &s, const segment &t) {
	return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0
		&& ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0;
}

inline point crosspoint(const segment &s, const segment &t) {
	const double tmp = cross(s.b - s.a, t.b - t.a);
	if(abs(tmp) < EPS) {
		if(intersect(s, t.a)) return t.a;
		if(intersect(s, t.b)) return t.b;
		if(intersect(t, s.a)) return t.a;
		return s.b;
	}
	return t.a + (t.b - t.a) * (cross(s.b - s.a, s.b - t.a) / tmp);
}

constexpr int MAX = 2000;
constexpr int INF = INT_MAX;

int solve(const polygon &P) {
	const int n = P.size();
	vector<segment> segments;
	segments.reserve(n);

	point prev = P.back();
	for(const auto &curr : P) {
		segments.emplace_back(prev, curr);
		prev = curr;
	}

	int ans = 0;
	for(int y = -MAX; y <= MAX; ++y) {
		segment s1(point(-INF, y + EPS), point(INF, y + EPS));
		segment s2(point(-INF, y + 1 - EPS), point(INF, y + 1 - EPS));

		vector<pair<point, point>> cp;
		for(const auto &s : segments) {
			if(intersect(s, s1) && intersect(s, s2)) {
				const point p1 = crosspoint(s, s1);
				const point p2 = crosspoint(s, s2);
				cp.emplace_back(min(p1, p2), max(p1, p2));
			}
		}

		sort(ALL(cp));

		int prev_R = -MAX;
		for(int i = 0; i < static_cast<int>(cp.size()); i += 2) {
			const int L = max<int>(floor(cp[i].first.x), prev_R);
			const int R = ceil(cp[i + 1].second.x);
			ans += R - L;
			prev_R = R;
		}
	}

	return ans;
}

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

	for(int n; cin >> n && n;) {
		polygon P;
		P.reserve(n);

		rep(i, n) {
			int x, y;
			cin >> x >> y;
			P.emplace_back(x, y);
		}

		cout << solve(P) << endl;
	}
	return EXIT_SUCCESS;
}

Measured memory_bytes: 1232
using System;
using System.Collections.Generic;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            long N = long.Parse(Console.ReadLine());
            string ans = "";
            // 一番右の桁に注目する
            // Nが偶数なら一番右は0, 奇数なら1
            // なぜなら1を表現できるのは一番左のビットだけだから
            // 一番左がわかればNを1bit right shiftして同じことを考える
            while (N != 0)
            {
                if (N % 2 != 0)
                {
                    N--;
                    ans = "1" + ans;
                }
                else
                {
                    ans = "0" + ans;
                }
                N /= -2;
            }
            if (ans == "") ans = "0";
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
using System;
using System.Linq;

namespace ConsoleApp1111
{
    class Program
    {
        static void Main(string[] args)
        {
            var aa = Console.ReadLine().Trim().Split(' ');
            var s = aa[0];
            var t = aa[1];
            var ab = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var a = ab[0];
            var b = ab[1];
            var u = Console.ReadLine().Trim();
            if (u == s)
            {
                a--;
            }
            else
            {
                b--;
            }

            Console.WriteLine(string.Format("{0} {1}", a, b));
        }
    }
}


Measured memory_bytes: 11348
#define _USE_MATH_DEFINES
#include<iostream>
#include<iomanip>
#include<cmath>

using namespace std;

double a, b, x;

int main(){
  cin >> a >> b >> x;
  double ans;
  if(x >= a * a * b / 2){
    ans = atan(2 * (a * a * b - x) / (a * a * a)) * 180 / M_PI;
  }else{
    ans = atan(a * b * b / (2 * x)) * 180 / M_PI;
  }

  cout << setprecision(10) << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
using ll = long long;
template <class T> using vec = vector<T>;
using vi   = vector<int>;
using vvi  = vector<vi>;
using vvvi = vector<vvi>;
using pii  = pair<int, int>;


// Constants
#define INF 1e9

// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval<newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin


// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second

// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!
ll ceil(ll x, ll y){
  ll q = x / y;
  if (q * y < x) ++q;
  return q;
}
// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  ll N=IN();
  vector<ll> a(5); rep(i,5) cin >> a[i];
  ll m = numeric_limits<ll>::max();
  //dump(N,a);
  rep(i,a.size()){
    if(a[i]<m) m=a[i];
  }
  //dump(N%m, N, m);
  ll g = ceil(N,m); // #group
  cout << g - 1L + 5L << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
using namespace std;
typedef long long ll;
vector<ll> g[200005];
#define pi 3.14159265358979
ll ok[200005]={0};
ll n,m; 
int main()
{
	ll k;
	string s;
	cin>>k>>s;
	for(ll i=0;i<k&&i<s.size();i++) cout<<s[i];
	if(k<s.size()) printf("...");
}

Measured memory_bytes: 8416
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val A, B, K = sc.nextInt()
  val length = (B - A + 1) min K
  LazyList.from(A).take(length)
    .concat(LazyList.from(B, -1).take(length).reverse)
    .distinct
    .foreach(println)
}


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

int main(void)
{
    int k, s;
    int x, y, z;
    int ans=0;

    cin>>k>>s;

    for(x=0;x<=k;x++){
        for(y=0;y<=k;y++){
            z = s-x-y;
            if(z>=0&&z<=k){
                ans++;
            }

        }
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/abc151_d.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int H, W;
int solve(vector<vector<char>> &c, P s) {
  priority_queue<pair<int, P>, vector<pair<int, P>>, greater<pair<int, P>>> que;
  que.push({0, s});

  vector<vector<int>> m(H, vector<int>(W, -1));
  int _max = -1;
  while (que.size()) {
    auto val = que.top();
    que.pop();

    int cnt = val.first;

    int i = val.second.first;
    int j = val.second.second;
    if (m[i][j] != -1) continue;
    _max = max(_max, cnt);

    m[i][j] = cnt;
    if (i - 1 >= 0 && c[i - 1][j] == '.') que.push({cnt + 1, {i - 1, j}});
    if (i + 1 < H && c[i + 1][j] == '.') que.push({cnt + 1, {i + 1, j}});
    if (j - 1 >= 0 && c[i][j - 1] == '.') que.push({cnt + 1, {i, j - 1}});
    if (j + 1 < W && c[i][j + 1] == '.') que.push({cnt + 1, {i, j + 1}});
  }
  return _max;
}

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  cin >> H >> W;

  vector<vector<char>> c(H, vector<char>(W));
  rep(i, H) rep(j, W) { cin >> c[i][j]; }

  int ans = 0;

  rep(i, H) rep(j, W) {
    if (c[i][j] == '#') continue;
    int tmp = solve(c, {i, j});
    // printf("%d %d/ cnt:%d\n", i, j, tmp);
    ans = max(ans, tmp);
  }

  cout << ans << endl;
}

Measured memory_bytes: 3656
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int n, sum = 0, ans = 0, ans2 = 0; cin >> n;
	vector<int> x(n);
	for (int i = 0; i < n; i++) {
		cin >> x.at(i);
		sum += x.at(i);
	}
	int ave = sum / n;
	int ave2 = sum / n + 1;
	for (int i = 0; i < n; i++) {
		ans += (x.at(i) - ave) * (x.at(i) - ave);
	}
	if (sum % n == 0) {
		cout << ans << endl;
		return 0;
	}
	for (int i = 0; i < n; i++) {
		ans2 += (x.at(i) - ave2) * (x.at(i) - ave2);
	}
	cout << min(ans, ans2) << endl;
}

Measured memory_bytes: 3624
h, w = gets.split.map(&:to_i)
c = gets.split.map(&:to_i)
d = gets.split.map(&:to_i)
s = []
s << [-1] * (w + 4)
s << [-1] * (w + 4)
h.times do
  s << [-1] * 2 + gets.chomp.chars.map { _1 == '#' ? -1 : 0} + [-1] * 2
end
s << [-1] * (w + 4)
s << [-1] * (w + 4)
u =[[-2, -2], [-2, -1], [-2, 0], [-2, 1], [-2, 2],
    [-1, -2], [-1, -1], [-1, 1], [-1, 2],
    [0, -2], [0, 2],
    [1, -2], [1, -1], [1, 1], [1, 2],
    [2, -2], [2, -1], [2, 0], [2, 1], [2, 2]
  ]
que = []
wqu = []
que << [c[0] + 1, c[1] + 1]
s[c[0] + 1][c[1] + 1] = 1
while que.size > 0 || wqu.size > 0
  while que.size > 0
    y, x = que.shift
    cnt = s[y][x]
#    puts "y=#{y} x=#{x} cnt=#{cnt}"
    if s[y + 1][x] == 0
      s[y + 1][x] = cnt
      que << [y + 1, x]
    elsif s[y + 1][x] == -1
      wqu << [y, x]
    end
    if s[y - 1][x] == 0
      s[y - 1][x] = cnt
      que << [y - 1, x]
    elsif s[y - 1][x] == -1
      wqu << [y, x]
    end
    if s[y][x + 1] == 0
      s[y][x + 1] = cnt
      que << [y, x + 1]
    elsif s[y][x + 1] == -1
      wqu << [y, x]
    end
    if s[y][x - 1] == 0
      s[y][x - 1] = cnt
      que << [y, x - 1]
    elsif s[y][x - 1] == -1
      wqu << [y, x]
    end
  end
  while wqu.size > 0
    y, x = wqu.shift
    cnt = s[y][x]
#    puts "y=#{y} x=#{x} cnt=#{cnt} wqu"
    u.each do |j, i|
      if s[y + j][x + i] == 0
        s[y + j][x + i] = cnt + 1
        que << [y + j, x + i]
      end
    end
  end
end
puts s[d[0] + 1][d[1] + 1] - 1

Measured memory_bytes: 25816
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0; return gcd(a, b, x, y);}
ll modpow(lll a,lll n,ll m){if(a==0)return a;lll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
map<int, int> m;
int n, k, a;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> k;
  ll s = 0, ans = 0;
  m[0] = 1;
  FOR(i, 0, n){
    cin >> a;
    s = (s + a) % k;
    ans += m[s];
    m[s] += 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3200
from collections import deque
import sys

n, m = map(int, input().split())

graph = [[] for _ in range(3*n+1)]

for i in range(m):
    a, b = map(int, input().split())
    graph[a].append(b+n)
    graph[a+n].append(b+2*n)
    graph[a+2*n].append(b)

dist = [-3] * (3*n+1)
dist[0] = 0
s, t = map(int, input().split())
dist[s] = 0

d = deque()
d.append(s)

while d:
    v = d.popleft()
    for i in graph[v]:
        if dist[i] != -3:
            continue
        dist[i] = dist[v] + 1
        d.append(i)

print(dist[t]//3)

Measured memory_bytes: 61376
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,D,X;
  cin >> N >> D >> X;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < D; i++){
    for (int j = 0; j < N; j++){
      if (i % A[j] == 0) X++;
    }
  }
  cout << X;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
char  S[100000];
int j,i,num=0;
  scanf("%s", S);
  for(j=0;S[j]!='\0';j++);
  for(i=1;i<=j;i++){
    if(S[i]==S[i-1]){
      if(S[i]=='0'){
        S[i]='1';
      }
     else{
        S[i]='0';
      }
      num++;
    }
  }
  printf("%d",num);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MD 1000000007
typedef long long int ll;
typedef pair<ll,ll> P;
template <typename T> std::string tostr(const T& t){std::ostringstream os; os<<t; return os.str();}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int main(){
    string s;
    cin>>s;
    int n=s.length();
    bool ans=false;
    for(int i=0;i<n;i++){
        for(int j=i;j<n;j++){
            string tmp=s.substr(0,i);
            tmp+=s.substr(j);
            if(tmp=="keyence"){
                cout<<"YES"<<endl;
                return 0;
            }
        }
    }
    cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=4e6+1;
int n,A[N],sum,ans;
bitset<N> B;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&A[i]);
        sum+=A[i];
    }
    B[0]=1;
    for(int i=1;i<=n;i++){
        B|=(B<<A[i]);
    }
    for(int i=(sum+1)/2;i<=sum;i++){
        if(B[i]){
            cout<<i;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  if (S.size() > K) {
    S = S.substr(0, K) + "...";
  }

  cout << S << endl;

  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
long long n,m,l=0,lmax;
char s[100005],t[100005],x[100005];
long long gb(long long  a,long long  b)
{
	long long  m=a,n=b,c,d;
	while(1){//循环的辗转相除法 
		c=a%b;
		a=b;
		b=c;
		if(b==0){
			break;
		}
	}
	c=m/a;d=n/a;
	n=c*d*a;
	return n;
}
int main()
{
	cin>>n>>m;
	l=gb(n,m);
	long long i,j;
	for(i=1;i<=100004;i++)
		x[i]='0';
	long long flag=0,result=0;
	scanf("%s",s+1);
	scanf("%s",t+1);
	if(s[1]!=t[1]){
		cout<<"-1";
		return 0;
	}
	long long k1=l/n,k2=l/m;
	j=1;
	long long  sn=1,tn=1;
	for(i=1;i<=10000000000&&sn<=n;i+=k1,sn++)
	{
		if(flag)
			break;
		for(;j<=10000000000&&tn<=m;j+=k2,tn++)
		{
			if(j>i)
				break;
			if(j<i)
				continue;
			if(j==i)
			{
				if(s[sn]!=t[tn])
				{
					flag=1;
					cout<<"-1";
					break;
				}
			}
		}
	}
	if(flag==0)
		cout<<l;
 } 

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

int main(){
    int h,w;
    while ((bool) true){
        cin >> h >> w;
        if (h == 0){
            break;
        };
        for (int i = 0; i < w; i++){
            cout << '#';
        };
        cout << "" << endl;
        for (int i = 0; i < h-2; i++){
            cout << '#';
            for (int j = 0; j < w-2; j++){
            cout << '.';
            };
            cout << '#' << endl;
        };
        for (int i = 0; i < w; i++){
            cout << '#';
        };
        cout << "" << endl;
        cout << "" << endl;
    }  
    return 0;
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,x,gcd=0;cin>>n>>x;
  lvector v(n,0);rep(i,n) cin>>v[i];
  gcd=abs(v[0]-x);
  for(ll i=1;i<n;++i) gcd=__gcd(gcd,abs(v[i]-x));
  print(gcd);
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1)*a%MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1)*a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b,a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size()>n) return kaijo_memo[n];
  if(kaijo_memo.size()==0) kaijo_memo.push_back(1);
  while(kaijo_memo.size()<=n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1]*kaijo_memo.size()%MOD);
  return kaijo_memo[n];
}

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

	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1000000)

n,m=map(int,input().split())
graph=[[] for _ in range(n)]

for _ in range(m):
    a,b=map(int,input().split())
    graph[a].append(b)
    graph[b].append(a)

def dfs(v):
    if reached[v]:
        reached[v]=0
        ll.add(v)
        for i in range(len(graph[v])):
            dfs(graph[v][i])

reached=[1]*n
ans=[[] for _ in range(n)]

for j in range(n):
    ll=set()
    dfs(j)
    if ll:
        for s in ll:
            ans[s]=ll

q=int(input())
ab=[]
for i in range(q):
    a,b=map(int,input().split())
    ab.append([a,b])

for i in range(q):
    a,b=ab[i][0],ab[i][1]
    if b in ans[a]:
        print("yes")
    else:
        print("no")



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

int main() {
	int a, b;
	cin >> a >> b;
	if(b==0)
	{
		cout << a << endl;
		return 0;
	}
	int c[b];
	int i;
	for(i=0; i<b; i++)
	{
		cin >> c[i];
	}
	int n[2*b+3];
	n[0]=a;
	n[1]=a-1;
	n[2]=a+1;
	for(i=1; i<2*b+1; i++)
	{
		if(i%2==1)
		{
			n[i+2]=n[i]-1;
		}
		else
		{
			n[i+2]=n[i]+1;
		}
	}
	for(i=0; i<2*b+3; i++)
	{
		int hola=0;
		int j;
		for(j=0; j<b; j++)
		{
			if(c[j]==n[i])
			{
				hola=hola+1;
			}
		}
		if(hola==0)
		{
			cout << n[i] << endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3620
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	//	"strings"
)

func main() {
	sc := NewScanner()

	n := sc.NextInt()
	max := 0
	sum := 0
	for i := 0; i < n; i++ {
		tmp := sc.NextInt()
		sum += tmp
		if tmp > max {
			max = tmp
		}
	}
	sum -= max
	if sum > max {
		fmt.Printf("Yes\n") // output for debug
	} else {
		fmt.Printf("No\n") // output for debug
	}

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			result = append(result, v)
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	result = append(result, v)

	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;

int main() {
    int x; cin >> x;
    if (x == 3 || x == 5 || x == 7) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

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

int main(){
  int h,w;
  cin >> h >> w;
  
  vector<vector<char>> A(h,vector<char>(w));
  
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin >> A.at(i).at(j);
    }
  }
  
  bool can = true; 
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      if(A.at(i).at(j) == '#'){
        if(j < w-1 && A.at(i).at(j+1) == '#'){
          continue;
        }
        else if(i >= 1 && A.at(i-1).at(j) == '#'){
          continue;
        }
        else if(j >= 1 && A.at(i).at(j-1) == '#'){
          continue;
        }
        else if(i <= h-2 && A.at(i+1).at(j) == '#'){
          continue;
        }
        else{
          can = false;
          break;
        }
      }
    }
    if(can == false){
      break;
    }
  }
  
  if(can == true){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
               
}


Measured memory_bytes: 256
/**
 * @author Video Vocabulary
 * @date 2020-06-21 18:15:00
 */
#include <bits/stdc++.h>

using namespace std;

void solve() {
    
}

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

    int n, k;
    cin >> n >> k;
    int a[n];
    for (int i=0; i<n; i++) {
        cin >> a[i];
    }
    sort(a, a+n);
    long long sum = 0;
    for (int i=0; i<k; i++) {
        sum += a[i];
    }
    cout << sum << endl;
}


Measured memory_bytes: 3648