akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
 
#include <bits/stdc++.h>
 
#define len(x) (int)((x).size())
#define endl '\n'
#define x first
#define y second
#define int long long
#define double long double
#define all(a) (a).begin(), (a).end()
 
#ifdef LOCAL
	#define dbg(x) cout << #x << " = " << x << endl;
#else 
	#define dbg(x)
#endif 
 
using namespace std;
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("file1.txt", "r", stdin);                                       
    freopen("file2.txt", "w", stdout);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(15);
    solve();  	
}

void solve() {
	string s;
	cin >> s;

	bool ok = true;
	set<char> one = {'R', 'U', 'D'};
	set<char> two = {'L', 'U', 'D'};

	for (int i = 0; i < len(s); ++i) {
		if (i % 2 == 0) {
			if (!one.count(s[i])) {
				ok = false;
			}
		}
		else {
			if (!two.count(s[i])) {
				ok = false;
			}
		}
	}

	cout << (ok ? "Yes" : "No") << endl;
}

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

int cnt[26];

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

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            char ch;
            cin>>ch;
            cnt[ch-'a']++;
        }
    }

    int cnt4=0,cnt1=0,cnt2=0;
    for(int i=0;i<26;i++)
    {
        cnt4+=cnt[i]/4;
        cnt2+=(cnt[i]%4)/2;
        cnt1+=cnt[i]%2;
    }

    int r4= (n/2)*(m/2);
    int r2=0,r1=0;
    if(m%2==1)
        r2+=n/2;
    if(n%2==1)
        r2+=m/2;
    if(n%2==1&&m%2==1)
        r1=1;

    int flag=0;
    if(cnt1==r1)
    {
        if(cnt2<r2&&(r2-cnt2)%2==0)
        {
            cnt4-=(r2-cnt2)/2;
            cnt2=r2;
        }

        if(cnt2==r2&&cnt4==r4)
        {
            flag=1;
        }
    }

    if(flag) cout<<"Yes";
    else cout<<"No";
    return 0;
}


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

int S(string s) {
  int ans = 0;
  for(int i = 0; i < s.size(); i++) {
    ans += stoi(s.substr(i, 1));
  }
  return ans;
}

int main() {
  string s;
  cin >> s;
  int N = stoi(s);
  if(N % S(s) == 0) {
    puts("Yes");
  } else {
    puts("No");
  }
  return 0;
}

Measured memory_bytes: 256
void main() {
	auto N = ri;
	auto a = readAs!(int[]);
	a.map!(b => b-1).sum.writeln;
}

// ===================================

import std.stdio;
import std.string;
import std.functional;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

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

int main() {
  int R,G,B,n;
  cin >> R >> G >> B;
  n = 10 * G + B;
  
  if (n % 4 == 0) {
    cout << "YES" << endl;
  }
  else cout << "NO" << endl; 
}

Measured memory_bytes: 256
/* ***********************************************
Author        :dasinlsb
Created Time  :2018/6/3 19:58:39
File Name     :C:\dasin\duipai.cpp
************************************************ */

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second


int main(){
 // freopen("C:/dasin/aa.in","r",stdin);
  //freopen("C:/dasin/mine.out","w",stdout);
  int i,j;
  int n;
  scanf("%d",&n);
  if(n%10==0)return puts("10"),0;
  int x=0;
  for(;n;n/=10)x+=n%10;
  printf("%d\n",x);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define pb push_back
#define fi first
#define se second
const int maxn=2e5+10;
const int mod=1e9+7;
const int inf=0x3f3f3f3f;
pair<int,int> book[maxn];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=0;i<n;i++) cin>>book[i].se>>book[i].fi;
	sort(book,book+n);
	int now=inf;
	for(int i=n-1;i>=0;i--)
	{
		if(now>book[i].fi) now=book[i].fi;
		now-=book[i].se;
	}
	if(now<0) cout<<"No"<<'\n';
	else cout<<"Yes"<<'\n';
    return 0;
}



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

using ll=long long; 

void solve(){
	int n;
	cin>>n;
	vector<int>a(n), b(n), c(n);
	for(int i=0; i<n; i++){
		cin>>a[i];
		a[i]--;
	}	
	for(int i=0; i<n; i++){
		cin>>b[i];
	}
	for(int i=0; i<n-1; i++){
		cin>>c[i];
	}
	int manzoku=0;
	manzoku+=b[a[0]];
	for(int i=1; i<n; i++){
		manzoku+=b[a[i]];
		if(a[i-1]==a[i]-1){
			manzoku+=c[a[i-1]];
		}
	}
	cout<<manzoku<<endl;
}

signed main(){
	//while(1)
	solve();
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)

def main():
    s = [int(c) for c in S()]
    if s[0] != 1 or s[-1] == 1:
        return -1
    n = len(s)
    for i in range(1,n):
        if s[i-1] != s[n-i-1]:
            return -1

    q = collections.deque()
    for i in range(1,n):
        if s[i] == 1:
            q.append(i+1)
    q.append(n)
    c = 1
    r = []
    for i in range(1,n):
        if c == i:
            c = q.popleft()
        r.append('{} {}'.format(i,c))

    return '\n'.join(r)


print(main())


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

using namespace std;

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;

constexpr int MAXN = 100000, MOD = 1000000007;

vector<int> adj[MAXN + 2];

int cw, cb;
void dfs(int u, int w) {
	int cumw = 1, cumb = 1;
	for(int v : adj[u]) {
		if(v != w) {
			dfs(v, u);
			cumw = (ll)cumw * (cw + cb) % MOD;
			cumb = (ll)cumb * cw % MOD;
		}
	}
	cw = cumw; cb = cumb;
}


int main() {
	int N;
	cin >> N;
	for(int i = 0; i < N - 1; i++) {
		int x, y;
		cin >> x >> y;
		adj[x].push_back(y);
		adj[y].push_back(x);
	}
	dfs(1, 0);
	cout << ((cw + cb) % MOD) << endl;
}


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

int N, Q;
string S;
char T[200000], D[200000];

bool solve1(int c){
    for(int i=0; i<Q; i++){
        if(S[c] == T[i]){
            c += (D[i] == 'R' ? 1 : -1);
            if(c == N) return false;
            if(c == -1) return true;
        }
    }
    return false;
}

bool solve2(int c){
    for(int i=0; i<Q; i++){
        if(S[c] == T[i]){
            c += (D[i] == 'R' ? 1 : -1);
            if(c == -1) return false;
            if(c == N) return true;
        }
    }
    return false;
}

int main(){
    cin >> N >> Q >> S;
    for(int i=0; i<Q; i++) cin >> T[i] >> D[i];

    int ng = N, ok = -1;
    while(ng-ok>1){
        int mid = (ng+ok)/2;
        (solve1(mid) ? ok : ng) = mid;
    }
    int L = ng;

    ng = -1;
    ok = N;
    while(ok-ng>1){
        int mid = (ng+ok)/2;
        (solve2(mid) ? ok : ng) = mid;
    }
    int R = ng;

    int ans = min(N, R-L+1);
    cout << ans << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define SETMAX(x, y) x = max(x, (y));

ll width(const pair<ll, ll>& p){
    return p.second - p.first + 1;
}

ll width(ll left, ll right){
    return max(0LL, right - left + 1);
}

int main(){
    ll n;
    cin >> n;
    vector<pair<ll, ll>> p(n);
    REP(i, n){
        cin >> p.at(i).first >> p.at(i).second;
    }

    if(n == 2){
        cout << width(p.at(0)) + width(p.at(1)) << endl;
        return 0;
    }

    ll maxl = 0, maxl_idx = -1;
    ll minr = 1000000001, minr_idx = -1;
    REP(i, n){
        if(maxl < p.at(i).first){
            maxl = p.at(i).first;
            maxl_idx = i;
        }
        if(minr > p.at(i).second){
            minr = p.at(i).second;
            minr_idx = i;
        }
    }

    vector<pair<ll, ll>> p2;
    REP(i, n){
        if(i == maxl_idx || i == minr_idx){
            continue;
        }
        p2.push_back(p.at(i));
    }
    sort(p2.begin(), p2.end());

    ll ans = 0;
    for(auto q : p2){
        SETMAX(ans, width(maxl, minr) + width(q));
    }

    vector<ll> cminr(p2.size());
    cminr.at(p2.size() - 1) = p2.back().second;
    for(ll i = p2.size() - 2; i >= 0; --i){
        cminr.at(i) = min(p2.at(i).second, cminr.at(i + 1));
    }

    for(ll i = -1; i < (ll)p2.size(); ++i){
        if(i == -1){
            SETMAX(
                ans,
                width(p.at(minr_idx)) + 
                width(maxl, min(cminr.at(i + 1), p.at(maxl_idx).second))
            );
        }else if(i < cminr.size() - 1){
            SETMAX(
                ans,
                width(max(p2.at(i).first, p.at(minr_idx).first), minr) + 
                width(maxl, min(cminr.at(i + 1), p.at(maxl_idx).second))
            );
        }else{
            SETMAX(
                ans,
                width(max(p2.at(i).first, p.at(minr_idx).first), minr) +
                width(p.at(maxl_idx))
            );
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4980
#include <algorithm>
#include <climits>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
using ll = long long int;

const ll MOD = 1e9 + 7;

ll pow_fast(ll n, ll k) {
  if (k == 0) {
    return 1LL;
  }
  if (k == 1) {
    return n;
  }

  if (k % 2 == 0) {
    ll tmp = pow_fast(n, k / 2);
    return tmp * tmp % MOD;
  } else {
    ll tmp = pow_fast(n, (k - 1) / 2);
    tmp *= tmp;
    tmp %= MOD;
    return tmp * n % MOD;
  }
}

template <typename T>
class stack {
 private:
  vector<T> _vec;

 public:
  stack(){};

  void push(T n) {
    _vec.push_back(n);
    return;
  }

  void pop() {
    if (this->empty()) {
      return;
    }
    _vec.erase(_vec.end() - 1);
    _vec.shrink_to_fit();
    return;
  }

  size_t size() { return _vec.size(); }

  T top() { return _vec[this->size() - 1]; }
  bool empty() { return _vec.empty(); }
};

int main() {
  ll N, M;
  cin >> N >> M;

  vector<vector<char>> A(N, vector<char>(N));
  vector<vector<char>> B(M, vector<char>(M));

  for (ll i = 0; i < N; i++) {
    string s;
    cin >> s;
    for (ll j = 0; j < N; j++) {
      A[i][j] = s[j];
    }
  }

  for (ll i = 0; i < M; i++) {
    string s;
    cin >> s;
    for (ll j = 0; j < M; j++) {
      B[i][j] = s[j];
    }
  }

  bool ans = false;
  for (ll i = 0; i <= N - M; i++) {
    for (ll j = 0; j <= N - M; j++) {
      bool ok = true;
      for (ll ni = 0; ni < M; ni++) {
        for (ll nj = 0; nj < M; nj++) {
          if (A[ni + i][nj + j] != B[ni][nj]) {
            ok = false;
          }
        }
      }
      ans |= ok;
    }
  }

  cout << (ans ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3576
n = int(input())
s = input()

ans = s.count("R") * s.count("G") * s.count("B")

for i in range(n):
    for j in range(i+1, n):
        k = 2 * j - i
        if k >= n:
            break
        ans -= s[k] != s[i] != s[j] != s[k]

print(ans)

Measured memory_bytes: 9092
import scala.io.StdIn

object Main extends App {
  val s = StdIn.readLine.split(" ")

  val res = s.filter(_.charAt(0) == 'A')
    .filter(l => l.count(_.isUpper) == 2)
    .map(_.toCharArray)
    .map(_.drop(2).init)
    .exists(l => l.count(ch => ch == 'C') == 1)

  println(if (res) "AC" else "WA")
}

Measured memory_bytes: 25552
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 100010;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vector<ll> a(n+1),b(n);
    cins(all(a));
    cins(all(b));
    ll cnt = 0;
    rep(i,n){
        if (b[i] <= a[i]){
            cnt += b[i];
        }
        else if (b[i] <= a[i]+a[i+1]){
            cnt += b[i];
            a[i+1] -= (b[i]-a[i]);
        }
        else{
            cnt += a[i]+a[i+1];
            a[i+1] = 0;
        }
    }
    PRINT(cnt);
}    


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
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 long long INF = 1LL << 60;

int main(){
  int n, m; cin >> n >> m;
  vector<int> x(m);
  if(n >= m){
    cout << 0 << endl;
    return 0;
  }

  rep(i, m) cin >> x[i];
  sort(all(x));

  vector<int> l(m-1);
  rep(i, m-1) l[i] = x[i+1] - x[i];
  sort(l.rbegin(), l.rend());

  int ans = x[m-1] - x[0];
  rep(i, n-1) ans -= l[i];

  cout << ans << endl;

  return 0;
}


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

string test(string s, string t){
	int **dp = new int*[s.size()+1], temp; 
	for(int i = 0; i < s.size()+1; i++){
		dp[i] = new int[t.size()+1];
	}
	for(int i = 0; i < s.size()+1; i++){
		dp[i][0] = 0;
	}
	for(int j = 0; j < t.size() + 1; j++){
		dp[0][j] = 0;
	}
	for(int i = 1; i <= s.size(); i++){
		for(int j = 1; j <= t.size(); j++){
			if(t[j-1]==s[i-1]){
				dp[i][j] = 1 + dp[i-1][j-1];
			}
			else{
				dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			}
		}
	}
	string answer;
	int i = s.size(), j = t.size();
	while(i!=0 && j!=0){
		if(s[i-1]==t[j-1]){
			answer.push_back(t[j-1]);
			i--;j--;
		}
		else{
			if(dp[i-1][j] > dp[i][j-1]){
				i--;
			}
			else{
				j--;
			}
		}
	}
	for(int i = 0; i < answer.size()/2; i++){
		char temp = answer[i];
		answer[i] = answer[answer.size()-1-i];
		answer[answer.size()-1-i] = temp;
	}
	return answer;
}

int main(){
	#ifndef ONLINE_JUDGE
	freopen("/home/afzalrao/Desktop/Academics/2nd Year/3rd Sem/ESO207/CP/Text Files/input.txt", "r", stdin);
	freopen("/home/afzalrao/Desktop/Academics/2nd Year/3rd Sem/ESO207/CP/Text Files/output.txt", "w", stdout);
	#endif
	string s, t;
	cin >> s >> t;
	cout << test(s, t);
	return 0;
}

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

using namespace std;

#define INF 100000000
#define YJ 1145141919
#define INF_INT_MAX 2147483647
#define INF_LL 9223372036854775
#define INF_LL_MAX 9223372036854775807
#define EPS 1e-10
#define MOD 1000000007
#define MOD9 998244353
#define Pi acos(-1)
#define LL long long
#define ULL unsigned long long
#define LD long double

#define int long long

using II = pair<int, int>;

int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
int extgcd(int a, int b, int &x, int &y) { int g = a; x = 1; y = 0; if (b != 0) g = extgcd(b, a % b, y, x), y -= (a / b) * x; return g; }

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a)  begin((a)), end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())

const int MAX_N = 2505;
const int MAX_M = 5005;

int N, M, P;
vector<II> Edge[MAX_N];
vector<II> rEdge[MAX_N];

int dist[MAX_N];

int used[MAX_N];
bool used2[MAX_N];

void check()
{
  {
    memset(used2, 0, sizeof(used2));
    queue<int> que;
    que.push(0);
    used[0]++;
    used2[0] = true;

    while(que.size()) {
      int pos = que.front(); que.pop();
      for(II edge : Edge[pos]) {
        if(used2[edge.first]) continue;
        used[edge.first]++;
        used2[edge.first] = true;
        que.push(edge.first);
      }
    }
  }
  
{
  memset(used2, 0, sizeof(used2));
  queue<int> que;
  que.push(N-1);
  used[N-1]++;
  used2[N-1] = true;

  while(que.size()) {
    int pos = que.front(); que.pop();
    for(II edge : rEdge[pos]) {
      if(used2[edge.first]) continue;
      used[edge.first]++;
      used2[edge.first] = true;
      que.push(edge.first);
    }
  }
}
  
}

signed main()
{
  cin >> N >> M >> P; 
  REP(n,N) {
    dist[n] = INF_LL;
    used[n] = false;
  }
  dist[0] = 0;
  REP(m,M) {
    int a, b, c; cin >> a >> b >> c; a--; b--;
    Edge[a].emplace_back(II(b,-1*(c-P)));
    rEdge[b].emplace_back(II(a, -1*(c-P)));
  }

  check();

  int r = 0;
  bool whileFlag = true;
  while(whileFlag) {
    whileFlag = false;
    REP(n,N) {
      if(used[n] != 2) continue;
      if(dist[n] == INF_LL) {
        continue;
      }
      for(const II& edge : Edge[n]) {
        if(used[edge.first] != 2 ) continue;
        if(dist[edge.first] > dist[n] + edge.second) {
          whileFlag = true;
          dist[edge.first] = dist[n] + edge.second;
        }
      }
    }
    r++;
    if(r >= N+1) {
      cout << -1 << endl;
      return 0;
    }
  }

  if(dist[N-1] != INF_LL) {
    cout << max((LL)0, -1*dist[N-1]) << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}


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

int main(){
    string s;
    cin >> s;
    long long ans = 1LL;
    auto tmp1 = string() + s[0];
    auto tmp2 = string()+ s[1];
    bool flag = false;
    int i = 1;
    for(i; i < s.size() -1;i++){
    tmp2 = string() +s[i];
    if(tmp1 == tmp2){
        ++i;
        tmp2 += s[i];
        ans++;
    } else {
        ans++;
    }
    tmp1 = tmp2;
    }
      if(i == s.size() -1 && tmp1 != string()+ s[s.size()-1]){
          ans++;
      }
    if(s.size()==1){
        ans = 1;
    }

    cout << ans << endl;
}

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


int main(){
    ll x,y,z,k;cin>>x>>y>>z>>k;
    ll a[1010],b[1010],c[1010];
    rep(i,0,x)cin>>a[i];
    rep(i,0,y)cin>>b[i];
    rep(i,0,z)cin>>c[i];
    vector<ll> vc,vec;
    rep(i,0,x){
        rep(j,0,y){
            vc.push_back(a[i]+b[j]);
        }
    }
    sort(vc.begin(),vc.end(),greater<>());
    rep(i,0,z){
        rep(j,0,min(x*y,k)){
            vec.push_back(vc[j]+c[i]);
        }
    }
    sort(vec.begin(),vec.end(),greater<>());
    rep(i,0,k){
        cout<<vec[i]<<endl;
    }
}

    









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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n){cin >> a[i];}
  sort(a.begin(),a.end());
  int before = a[0];
  bool isUnique = true;
  for(int i = 1; i < n; i++){
    if(a[i] == before){
      isUnique = false;
      break;
    }
    before = a[i];
  }
  if(isUnique){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		Integer[] array = new Integer[3];

		array[0] = sc.nextInt();
		array[1] = sc.nextInt();
		array[2] = sc.nextInt();

		Arrays.sort(array);

		System.out.println(array[0] + " " + array[1] + " " + array[2]);

	}

}



Measured memory_bytes: 26300
times = [int(input()) for _ in range(5)]
times1 = []
total = 0
for t in times:
  t1 = t % 10
  if t1 == 0:
    total += t
  else:
    times1.append(t1)
    total += (t//10 + 1) * 10
if len(times1) >= 1:
    total = total + min(times1) - 10
print(total)

Measured memory_bytes: 3060
s = input()
for i in range(len(s)):
    if s[i] == s[i-1] and i-1>=0:
        print(i-1+1, i+1)
        exit()
    elif (i+1)<=len(s)-1 and s[i+1] == s[i]:
        print(i+1, i+1+1)
        exit()
    elif (i-1)>=0 and (i+1)<= len(s)-1 and s[i-1]==s[i+1]:
        print(i-1+1,i+1+1)
        exit()
print(-1, -1)

Measured memory_bytes: 3188
N,M = map(int,input().split())
correct = [0]*N
penalty = [0]*N
ans_c,ans_p = 0,0
for i in range(M):
    p,s = input().split()
    p = int(p)
    if s=="AC":
        if correct[p-1]==0:
            correct[p-1]+=1
    if s=="WA":
        if correct[p-1]==0:
            penalty[p-1]+=1

ans_penalty = 0
for i in range(N):
    if correct[i]>=1:
        ans_penalty+=penalty[i]
print(sum(correct),ans_penalty)

Measured memory_bytes: 10416
/////////////////////////////////TEST CASES////////////////////////////////////
/*
*/
/////////////////////////////////////CODE//////////////////////////////////////		
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a ; i > b ; i--)
#define fastio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define PI 3.14159265
typedef long long ll;
#define vl vector<ll> 
#define IN(inp) ll inp;cin>>inp;
#define pb push_back
#define all(a) a.begin(),a.end()
#define FR(i,a) for(auto &i:a)
#define rvl(a,n) vl a;FOR(i,0,n){IN(in); a.pb(in);}
#define what(A) cout<<#A<<" is "<<A<<endl;
ll MAX = 100000000000;
ll MOD = 1000000007;
void solve()
{
	IN(n);
	ll ans = 1, less_1 = 1, less_2 = 1;
	FOR(i, 0, n)
	{
		ans = (ans * 10)%MOD;
		less_1 = (less_1 * 9) % MOD;
		less_2 = (less_2 * 8) % MOD;
	}
	cout << ((ans - 2 * less_1 + MOD) % MOD + less_2 + MOD) % MOD;
}
int main()
{
	fastio
		//freopen("input.txt", "rt", stdin);
		//freopen("output.txt", "wt", stdout);
		ll test = 1;
	//cin >> test;
	while (test--)
	{
		solve();
	}
}

Measured memory_bytes: 3588
// テ・ツ淞コテヲツ慊ャテ」ツδ?」ツδウテ」ツδ療」ツδャテ」ツδシテ」ツδ?

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long int

template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}

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

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int M, N;
bool prime[7400000];

signed main() {
    while(cin >> M >> N, M || N) {
        memset(prime, false, sizeof(prime));
        int p = M;
        rep(i,0,N) {
            while(prime[p]) p++;
            for(int q=p; q<7400000; q+=p) {
                prime[q] = true;
            }
        }
        while(prime[p]) p++;
        cout << p << endl;
    }
    return 0;
}

Measured memory_bytes: 10240
# Binary Indexed Tree (Fenwick Tree)
class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
        self.el = [0]*(n+1)
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s
    def add(self, i, x):
        # assert i > 0
        self.el[i] += x
        while i <= self.n:
            self.data[i] += x
            i += i & -i
    def get(self, i, j=None):
        if j is None:
            return self.el[i]
        return self.sum(j) - self.sum(i)

def solve():
  N, Q = map(int, input().split())
  ans = []
  bit = BIT(N)
  for i in range(Q):
    com,x,y = map(int, input().split())
    if com==0:
      bit.add(x,y)
    else:
      ans.append(bit.get(x-1,y))
  return ans
print(*solve(),sep='\n')


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

int main(){
    int N;
    cin >> N;
    string s;
    cin >> s;
    vector<int> r,g,b;
    map<int, int> bhash;
    for(int i =0; i < N; i++){
        if(s.at(i) == 'R') {
            r.push_back(i);
        }
        else if(s.at(i) == 'G'){
            g.push_back(i);
        }
        else{
            b.push_back(i);
            bhash[i] = 1;   //i 番目にいるのかどうかを記録.
        }
    }
    long long ans = 0;
    for(int i =0; i < r.size(); i++){
        for(int j =0; j < g.size(); j++){
            int u = r[i];  //r g ここでの添え字。
            int v = g[j];
            ans += b.size();
            ans -= (bhash[2*u - v] + bhash[2*v - u]);
            if((u + v)%2 == 0) ans -= bhash[(u + v)/2];
        }
    }
    cout << ans << endl;
}

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

using namespace std;
const int N = 1e5 + 5;
int arr[N];
map<int, int> mp[2];

int main() {
    //  freopen("in.txt", "rt", stdin);
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", arr + i);
        mp[i % 2][arr[i]]++;
    }
    vector<pair<int, int>> v0, v1;
    for (auto x:mp[0]) {
        v0.push_back(x);
        swap(v0.back().first, v0.back().second);
    }
    for (auto x:mp[1]) {
        v1.push_back(x);
        swap(v1.back().first, v1.back().second);
    }
    sort(v1.rbegin(), v1.rend());
    sort(v0.rbegin(), v0.rend());
    int ans = n;
    for (int i = 0; i < n; i += 2) {
        int v = (n / 2) - mp[0][arr[i]];
        for (auto P:v1) {
            if (P.second != arr[i]) {
                ans = min(v + (n / 2 - P.first), ans);
                break;
            }
        }
        ans = min(ans, v + n / 2);
    }
    for (int i = 1; i < n; i += 2) {
        int v = (n / 2) - mp[1][arr[i]];
        for (auto P:v0) {
            if (P.second != arr[i]) {
                ans = min(v + (n / 2 - P.first), ans);
                break;
            }
        }
        ans = min(ans, v + n / 2);
    }
    printf("%d", ans);
}

Measured memory_bytes: 6520
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

// -------------------------------------------------------------------------------------

int n, k;
int ans = INF<int>;

void dfs(int x, int i) {
  if(i == 0) {
    ans = min(ans, x);
    return;
  }

  // 2倍
  dfs(2 * x, i - 1);

  // +K
  dfs(x + k, i - 1);
}

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

  dfs(1, n);

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize "trapv" 
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define rep(i,a,n)     for(int i=a;i<n;i++)
#define rep3(n)        for(int i=0;i<n;i++)
#define inarr(arr,n)   rep(i,a,n)cin>>arr[i]
#define ll             long long int
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define endl           "\n"
#define eb             emplace_back
#define x              first
#define y              second
#define gcd(a,b)       __gcd(a,b)
#define mem1(a)        memset(a,-1,sizeof(a))
#define pres(a,x)      a.find(x)!=a.end()
#define sz(a)          (int)a.size()
#define pii            pair<int,int>
#define IOS            ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ret            return 0
#define pi             3.1415926536
#define hell           1000000007
#define narak          998244353
#define elasped_time 1.0 * clock() / CLOCKS_PER_SEC
const int inf1=1e9;
const ll inf2=1e18;
const int N=100000;
using namespace std;
using namespace __gnu_pbds;
#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update>
int dirs[4][2] ={{1,0},{-1,0},{0,1},{0,-1}};
int solve(){
 int h,w;cin>>h>>w;           
 int dp[h+1][w+1]={0};
 for(int i=0;i<=h;i++){
     for(int j=0;j<=w;j++)dp[i][j]=0;
 }
 dp[1][0]=1;
 for(int i=1;i<=h;i++){
     for(int j=1;j<=w;j++){
         char c;cin>>c;
         if(c=='#')dp[i][j]=0;
         else dp[i][j]=(dp[i-1][j]+dp[i][j-1])%hell;
     }
 } 
 cout<<dp[h][w]<<endl;          
 ret;
}
int main(){
    IOS;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef cat
    cat();
    #endif
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    ret;
}
 

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

using namespace std;




int main(void) {
  int N=0;
  string Suraimu;

  cin >> N;
  cin >> Suraimu;


  string Ans;
  int i=0;
  while(1) {
    if(Suraimu[i] == Suraimu[i+1]) {
      Suraimu.erase(i, 1);
    } else {
      i++;
    }
    if (i == Suraimu.size()) break;
  }
  cout << Suraimu.size() << endl;

  
  return 0;
}


Measured memory_bytes: 512
import sys
import copy
import math
import bisect
import pprint
import bisect
from functools import reduce
from copy import deepcopy
from collections import deque

if __name__ == '__main__':
    b, c = map(int, input().split())

    if b <10 and c <10:
        print(b*c)
    else:
        print(-1)

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

signed main() {
  int A, B;
  cin >> A >> B;
  
  vector<int> high(999);
  high.at(0) = 1;
  for( int i = 1; i < 999; i++ ){
    high.at(i) = high.at(i-1) + i + 1;
  }
  for( int i = 1; i < 999; i++ ){
    if( B-A == high.at(i) - high.at(i-1) ){
      cout << high.at(i) - B << endl;
      return 0;
    }
  }
    
}


Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    n %= 10;

    string res = "bon";
    if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9) {
        res = "hon";
    } else if (n == 0 || n == 1 || n == 6 || n == 8) {
        res = "pon";
    } else {
        res = "bon";
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 3636
import sys
from itertools import combinations
input = lambda: sys.stdin.readline().rstrip()
mod = 10**9 + 7
n = int(input())
a = list(map(int, input().split()))
dp = [0 for _ in range(n)]
dp[0] = a[0]

# 累積和の計算
for i in range(1, n):
    dp[i] = (a[i] + dp[i - 1]) % mod

ans = 0
for i in range(n):
    ans += a[i] * (dp[n - 1] - dp[i])
    ans %= mod

print(ans)


Measured memory_bytes: 31712
from collections import deque
def main():
    n = int(input())
    s = list(input())

    stack = []
    ans = deque([])
    for c in s:
        if c == '(':
            ans.append('(')
            stack.append('(')
        
        if c == ')':
            if stack==[]:
                ans.appendleft('(')
                ans.append(')')
            else:
                stack.pop()
                ans.append(')')
    for c in stack:
        ans.append(')')

    for c in ans:
        print(c,end="")
    print()

if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
#https://atcoder.jp/contests/abc128
# -*- coding: utf-8 -*-

n,k = map(int,input().split())
v = list(map(int,input().split()))

ans = []
for left in range(k+1):
    for right in range(k-left+1):
        if left+right > n : continue
        for trash in range (k-left-right+1):
            x = sorted(v[0:left]+v[::-1][0:right])[trash:]
            ans.append(sum(x))

print(max(ans))

Measured memory_bytes: 5144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

struct edge{
    int to;
    int cost;
};

vector<int> dijkstra(vector<vector<edge>> g, int start_v, int num_v) {
    vector<int> dist(num_v, INF);
    dist[start_v] = 0;
    priority_queue<pair<int, int>> pq;
    pq.push(make_pair(0, start_v));
    while (!pq.empty()) {
        auto tmp = pq.top();
        pq.pop();
        int v = tmp.second;
        if (dist[v] < -tmp.first) continue;
        for (auto e : g[v]) {
            int next_v = e.to;
            int next_cost = e.cost;
            if (dist[v] + next_cost < dist[next_v]) {
                dist[next_v] = dist[v] + next_cost;
                pq.push(make_pair(-dist[next_v], next_v));
            }
        }
    }
    return dist;
}

int main() {
    int n, m, r;
    cin >> n >> m >> r;
    vector<vector<edge>> g(n);
    rep(i, 0, m) {
        int s, t, d;
        cin >> s >> t >> d;
        g[s].push_back(edge{t, d});
    }
    vector<int> dist = dijkstra(g, r, n);
    rep(i, 0, n) {
        if (dist[i] == INF) cout << "INF" << endl;
        else cout << dist[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 20288
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
int n,a[1000000];
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }
for(int i=n;i>=0;i--){
  if(a[i]<a[i-1]){
      a[i-1]--;
  }
}
for(int i=1;i<=n-2;i++){
   if(a[i]>a[i+1]){
   cout<<"No\n";
     return(0);
   }
}
cout<<"Yes\n";
  return(0);
}


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

using namespace std;

#define debug(x) '[' << #x << " is: " << x << "] "
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;
	#ifndef ONLINE_JUDGE
//		freopen("input.txt","r",stdin);
	#endif
	ll n,k;
	cin>>n>>k;
	if(!k){
		cout << n*n << endl;
		return 0;
	}
	ll ans = 0;
	for(ll i=k+1;i<=n;i++){
		ll fr=k,to=i-1;
		while(fr <= n){
			to = min(to, n);
			ans += to - fr + 1;
			fr+=i;to+=i;
		}
		// cout << i << ' ' << ans << endl;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
def c():
    n, m = map(int, input().split())
    ship_loot = []
    for _ in range(m):
        a, b = map(int, input().split())
        ship_loot.append( (a, b) )

    loot = { x:set() for x in range(1, n+1)}
    for l in ship_loot:
        a, b = l
        loot[a].add(b)
        loot[b].add(a)

    print('POSSIBLE' if loot[1] & loot[n] else 'IMPOSSIBLE')
    # print(ship_loot)
    # print(loot)
    # print(loot[1] & loot[n])

c()

Measured memory_bytes: 103504
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;

const int INF = 1e9 + 5;

int main() {
    int n;
    scanf("%d", &n);
    vector<int> h(n);
    for(int& x : h) {
        scanf("%d", &x);
    }
    vector<int> dp(n, INF);
    dp[0] = 0;
    for(int i = 0; i < n; ++i) {
        for(int j : {i + 1, i + 2}) {
            if(j < n) {
                dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
            }
        }
    }
    printf("%d\n", dp[n-1]);
}

Measured memory_bytes: 4036
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
#define MAX 1000005
#define NTL -1

struct Node {int p, l, r; };
Node T[MAX];
int n, D[MAX];

void print(int u) {
    int i, c;
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";

    if( T[u].p == NTL)  cout << "root, ";
    else if ( T[u].l == NTL ) cout << "leaf, ";
    else cout << "internal node, ";

    cout << "[";
    for(i = 0, c = T[u].l; c != NTL; i++, c = T[c].r) {
        if(i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

void rec(int u, int p) {
    D[u] = p;
    if (T[u].r != NTL) rec(T[u].r, p);
    if (T[u].l != NTL) rec(T[u].l, p + 1);
}

int main() {
    int i, j, d, v, c, l, r;
    cin >> n;
    for(int i = 0; i < n; i++) {
        T[i].p = T[i].l = T[i].r = NTL;
    }
    for(int i = 0; i < n; i++) {
        cin >> v >> d;
        for (j = 0; j < d; j++) {
            cin >> c;
            if( j == 0) T[v].l = c;
            else T[l].r = c;
            l = c;
            T[c].p = v;
        }
    }
    for ( i = 0; i < n; i++) {
        if(T[i].p == NTL) r = i;
    }
    rec(r, 0);
    for( i = 0; i < n; i++) print(i);
    return 0;
}


Measured memory_bytes: 7704
#include "bits/stdc++.h"
using namespace std;

//

#define RESIDUE(u,v) (capacity[u][v] - flow[u][v])
#define RCOST(u,v) (cost[u][v] + h[u] - h[v])
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long

int h,w,a[500][500],b[500][500];
int r=0;

int main(){
  cin>>h>>w;
  REP(i,h){
    REP(j,w){
      cin>>a[i][j];
      b[i][j]=a[i][j];
    }
  } 

  REP(i,h){
    REP(j,w){
      if(a[i][j]%2!=0 && j!=w-1){
	a[i][j]--;
	a[i][j+1]++;
	//cout<<i+1<<" "<<j+1<<" "<<i+1<<" "<<j+2<<endl;
	r++;
      }else if(a[i][j]%2!=0 && j==w-1 && i!=h-1){
	a[i][j]--;
	a[i+1][j]++;
	//cout<<i+1<<" "<<j+1<<" "<<i+2<<" "<<j+1<<endl;
	r++;
      }
    }
  }

  cout<<r<<endl;

  REP(i,h){
    REP(j,w){
      if(b[i][j]%2!=0 && j!=w-1){
	b[i][j]--;
	b[i][j+1]++;
	cout<<i+1<<" "<<j+1<<" "<<i+1<<" "<<j+2<<endl;
      }else if(b[i][j]%2!=0 && j==w-1 && i!=h-1){
	b[i][j]--;
	b[i+1][j]++;
	cout<<i+1<<" "<<j+1<<" "<<i+2<<" "<<j+1<<endl;
      }
    }
  }
  
  
  return 0;
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
    ll n;
    cin >>n;
    int x=0;
    while(n>>x&1) ++x;
    cout << (1LL<<x) << endl;
    return 0;
}



Measured memory_bytes: 3104
#include<algorithm>
#include<iostream>
#include<cstring>
#include<iomanip>
#include<sstream>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#define rep(i,x,n) for(int i=x;i<=n;i++)
#define per(i,n,x) for(int i=n;i>=x;i--)
#define sz(a) int(a.size())
#define rson mid+1,r,p<<1|1
#define pii pair<int,int>
#define lson l,mid,p<<1
#define ll long long
#define pb push_back
#define mp make_pair
#define se second
#define fi first
using namespace std;
const double eps=1e-8;
const int mod=1e9+7;
const int N=1e5+10;
const int inf=1e9;
string s;
int cnt[2050];
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>s;
	int n=s.size();
	int p=2019,sta=1,now=0;
	cnt[0]=1;
	ll ans=0;
	per(i,n-1,0){
		s[i]-='0';
		now=(now+1ll*s[i]*sta%p)%p;
		ans+=cnt[now]++;
		sta=sta*10%p;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3752
INF = 10**9
H, W = map(int, input().split())
A = [list(input()) for h in range(H)]
# (0, 0), (0, W-1), (H-1, 0), (H-1, W-1)
ans = [[INF for w in range(W)] for h in range(H)]
for h in range(H):
    for w in range(W):
        if A[h][w] == '#':
            ans[h][w] = 0
        tmp = ans[h][w]+1
        if h < H-1:
            ans[h+1][w] = min(tmp, ans[h+1][w])
        if w < W-1:
            ans[h][w+1] = min(tmp, ans[h][w+1])
for h in range(H-1, -1, -1):
    for w in range(W-1, -1, -1):
        tmp = ans[h][w]+1
        if h > 0:
            ans[h-1][w] = min(tmp, ans[h-1][w])
        if w > 0:
            ans[h][w-1] = min(tmp, ans[h][w-1])
# print(ans)
print(max([w for h in ans for w in h]))


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

int main(){
    int n; cin>>n;
    map<int,int> map;
    for(int i=0;i<n;i++){
        int a; cin>>a;
        if(map.find(a)==map.end()){
            map[a]=1;
        }else{
            map[a]++;
        }
    }
    int ans=0;
    for(auto it=map.begin();it!=map.end();it++){
        if((*it).first<=(*it).second){
            ans+=(*it).second-(*it).first;
        }else{
            ans+=(*it).second;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4736
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
using namespace std;
typedef long long LL;
LL MOD;
struct qq{LL s[3][3];};
qq operator * (qq a,qq b)
{
    qq c;
    for (LL u=0;u<=2;u++)
        for (LL i=0;i<=2;i++)
        {
            c.s[u][i]=0;
            for (LL j=0;j<=2;j++)
                c.s[u][i]=(c.s[u][i]+a.s[u][j]*b.s[j][i]%MOD)%MOD;
        }
    return c;
};
LL L,A,B;
qq Pow (qq x,LL y)
{
	if (y==1) return x;
	qq lalal=Pow(x,y>>1);
	lalal=lalal*lalal;
	if (y&1) lalal=lalal*x;
	return lalal;
}
int main()
{
	scanf("%lld%lld%lld%lld",&L,&A,&B,&MOD);L--;
	LL op=10,ans=0;
	LL o=0;
	for (LL u=1;u<=19;u++)
	{
		LL l=o,r=L,p=-1;
		while (l<=r)
		{
			LL mid=(l+r)>>1;
			if (mid*B+A<op) {p=mid;l=mid+1;}
			else r=mid-1;
		}
		if (p!=-1)
		{
			qq a;
			a.s[0][0]=op%MOD;a.s[0][1]=1;a.s[0][2]=0;
			a.s[1][0]=0;a.s[1][1]=1;a.s[1][2]=B%MOD;
			a.s[2][0]=0;a.s[2][1]=0;a.s[2][2]=1;
			a=Pow(a,p-o+1);
			LL t=(o%MOD*B%MOD+A)%MOD;	
			//printf("%lld %lld %lld\n",op,t,p-o+1);
			ans=(ans*a.s[0][0]%MOD+t*a.s[0][1]%MOD+a.s[0][2])%MOD;
			o=p+1;
		}
		if (o>L) break;
		op*=10;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll INF=1e18+5;
int main(){
    cin.tie(0);cout.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vl a(n);
    rep (i, n) cin >> a[i];
 
    int m;
    if (n % 2 == 0) m = 1;
    else m = 2;
 
    vvl dp(n + 10, vl(m + 1, -INF));
    for (int i = 0; i <= m; i++) {
        dp[i][i] = 0;
    }
 
    rep (i, n) {
        rep (j, m + 1) {
            if (dp[i][j] == -INF) continue;
            dp[i + 2][j]=max(dp[i+2][j],dp[i][j] + a[i]);
            if (j + 1 <= m) {
                dp[i + 3][j + 1]=max(dp[i+3][j+1],dp[i][j] + a[i]);
            }
            if (j + 2 <= m) {
                dp[i + 4][j + 2]=max(dp[i+4][j],dp[i][j] + a[i]);
            }
        }
    }
 
    ll ans = -INF;
    int mi;
    if (n % 2 == 0) mi = 0;
    else mi = 1;
    for (int i = n; i <= n + 5; i++) {
        for (int j = mi; j <= m; j++) {
            ans=max(ans,dp[i][j]);
        }
    }
    cout << ans << endl;
}

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

using namespace std;

const int INF = 1e9;
const int N = 1e5;
const int MOD = 998244353;

const double PI = acos(-1);



int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    map<string, int> cnt;
    int mx = 1;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        cnt[s]++;
        mx = max(mx, cnt[s]);
    }
    vector<string> res;
    for (auto x : cnt) {
        if (x.second == mx)
            res.push_back(x.first);
    }
    sort(res.begin(), res.end());
    for (string s : res)
        cout << s << endl;
}

Measured memory_bytes: 25584
import java.util.*;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int n = sc.nextInt();
        Set<Integer> set = new HashSet<>();
        for(int i=0; i<n; i++) {
            set.add(sc.nextInt());
        }
        for(int i=0; i<=200; i++) {
            if(!set.contains(x-i)) {
                System.out.println(x-i);
                return;
            }
            if(!set.contains(x+i)) {
                System.out.println(x+i);
                return;
            }
        }


    }


}

Measured memory_bytes: 35952
def g;gets.split.map &:to_i;end
def f a,b,c,e,m;[a,b]==e||[[a,b+1],[a,b-1],[a+1,b],[a-1,b]].any?{|i,j|m[j][i]==c&&(m[j][i]=7;f i,j,c,e,m)}end
while(w,h=g)[0]>0
s,t=g
e=g
m=[v=[6]*(w+2)]+(1..h).map{[6]+[0]*w<<6}<<v
g[0].times{c,d,x,y=g;o=d<1?4:2;m[y,6-o].map{|i|i[x,o]=[c]*o}}
puts f(s,t,m[t][s],e,m)?:OK:"NG"end

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

int main()
{
    string s;
    cin >> s;
    int sum_0, sum_1;
    sum_0 = sum_1 = 0;
    rep(i, 0, s.size()){
        if(s[i] == '0') sum_0++;
        else sum_1++;
    }
    cout << min(sum_0, sum_1)*2 << endl;
    return 0;
}


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

const int MAXL = 300010;
int str[MAXL],slen;
int k,n;
void goback() {
	static int i = slen-1;
	for ( ; i>=0; i--)
		if (str[i] != 0) {
			str[i]--;
			if (str[i]!=0) {
				for (int j=i+1; j<slen; j++)
					str[j]=k;
				i = slen-1;
			}
			return ;
		}
}
int main() {
	cin>>k>>n;
	if (k%2 == 0) {
		cout<<k/2<<" ";
		for (int i=1;i<n;i++)
			cout<<k<<" ";
		cout<<endl;
	}else {
		cout<<(k+1)/2<<" ";
		int move = (n)/2;
		for (int i=1;i<n;i++)
			str[i-1]=(k+1)/2;
		slen = n-1;
		//cout<<"DEBUG move="<<move<<endl;
		for (int i=0;i<move; i++)
			goback();
		for (int i=0;i<slen && str[i];i++)
			cout<<str[i]<<" ";
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3456