akhauriyash/Code-Regression huggingface dataset:
o = input()
e = input()
ans = ''
for i in range(min(len(o), len(e))):
    ans += o[i]
    ans += e[i]
if len(o) > len(e):
    ans += o[len(o) - 1]
if len(o) < len(e):
    ans += o[len(e) - 1]
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007ll)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			(3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
template<class T> void chmax(T &a, const T &b){if(a<b)a=b;}
template<class T> void chmin(T &a, const T &b){if(a>b)a=b;}
void YN(bool b){cout<<(b?"YES":"NO")<<endl;}
void Yn(bool b){cout<<(b?"Yes":"No")<<endl;}
void yn(bool b){cout<<(b?"yes":"no")<<endl;}

int clz(ll x) { return 63 - __builtin_clzll(x); }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,k;
	int t;
	cin>>k;
	n=(k+3)/4*2;
	if(k==1)n--;
	cout<<n<<endl;
	rep(i,n){
		rep(j,n){
			t=(i+j)%n;
			if(i%2==1&&t+n<k)t+=n; 
			cout<<t+1<<((j==n-1)?"\n":" ");
		}
	}

}

 

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

template<class T>inline bool chmax(T &a, const T &b) { if (b > a) { a = b; return true; } return false; }
template<class T>inline bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

bool need(int n, int N, int K, const vector<int> &a) {
    bitset<5000> bits(1);
    for (int i=0; i<N; ++i) {
        if (i != n && a[i] < 5000) bits |= (bits << a[i]);
    }
    for (int i=max(0, K-a[n]); i<K; ++i) {
        if (bits.test(i)) return true;
    }
    return false;
}

void solve() {
    int N, K;
    cin >> N >> K;
    vector<int> a(N);
    for (int i=0; i<N; ++i) cin >> a[i];

    sort(a.begin(), a.end());
    int ok = -1, ng = N;
    while (abs(ok - ng) > 1) {
        int mid = (ok + ng) / 2;
        if (!need(mid, N, K, a)) ok = mid;
        else ng = mid;
    }
    cout << ok + 1 << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 3656
n = int(input())
a = list(map(int, input().split()))
rate = [0 for i in range(9)]
ans = 0

for i in range(n):
    if 1<=a[i] and a[i]<=399:
        rate[0] = 1
    elif 400<=a[i] and a[i]<=799:
        rate[1] = 1
    elif 800<=a[i] and a[i]<=1199:
        rate[2] = 1
    elif 1200<=a[i] and a[i]<=1599:
        rate[3] = 1
    elif 1600<=a[i] and a[i]<=1999:
        rate[4] = 1
    elif 2000<=a[i] and a[i]<=2399:
        rate[5] = 1
    elif 2400<=a[i] and a[i]<=2799:
        rate[6] = 1
    elif 2800<=a[i] and a[i]<=3199:
        rate[7] = 1
    else:
        rate[8] += 1

for i in range(len(rate)-1):
    if rate[i] == 1:
        ans += 1
if ans == 0:
    ans = 1
    rate[8] -= 1
print(ans,ans+rate[8])


Measured memory_bytes: 38384
class Problem
  attr_accessor *(?a..?z).to_a.map(&:to_sym)
  def initialize
    @s = gets.chomp
    @k = gets.to_s.to_i
  end

  def solve
    if k <= ones_length
      return 1
    else
      return not_one_head
    end
  end

  def ones_length
    ans = 0
    ans += 1 while s[ans] == "1"
    ans
  end

  def not_one_head
    s.chars.each do |c|
      return c if c != "1"
    end
    return nil
  end

  def show(ans)
    puts ans
  end
end

Problem.new.instance_eval do
  show(solve)
end

Measured memory_bytes: 14260
import sys,math

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]


def main():
	n,a,b = MI()
	mod = 10 ** 9 + 7

	def f(n,r,mod):
		r = min(r,n-r)
		x = y = 1
		for i in range(r):
			x = (x*(n-i)) % mod
			y = (y*(i+1)) % mod
		return (x * pow(y, mod-2, mod)) % mod

	ans = pow(2,n,mod) - f(n,a,mod) - f(n,b,mod) - 1
	ans += mod if ans < 0 else 0
	ans += mod if ans < 0 else 0
	print(ans)

if __name__ == '__main__':
	main()

Measured memory_bytes: 3064
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int d = sc.nextInt();
        int t = sc.nextInt();
		int s = sc.nextInt();
       if(t*s>=d){System.out.println("Yes");}
		else{System.out.println("No");}
	}
}


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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  int p1 = n*a;
  int p2 = b;

  if (p1 < p2) {
      cout << p1 << endl;
  }
  else {
      cout << p2 << endl;
  }
}

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

int N;
int ans[200010]= {0};
int main(){
	cin >> N;
	vector<pair<int,int>> v(N+1);
	for(int i=1;i<=N;i++){
		int a;
		cin >> a;
		v[i] = make_pair(a,i);
	}
	sort(v.begin()+1,v.end());
	for(int i=1;i<=N;i++){
		pair<int,int> t;
		if(i<=N/2){
			t = v[(N/2)+1];
			ans[v[i].second] = t.first;
		}else{
			t = v[N/2];
			ans[v[i].second] = t.first;
		}
	}
	for(int i=1;i<=N;i++){
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 4480
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>PP;
const ll MOD = 1000000007;
int main(){
  int n;cin>>n;
  cout<<(n-1)/2<<endl;


}

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

typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/
const int MAXN = 220000;
int n;
int was[MAXN];
int h[MAXN];
int p[MAXN];
vector<int> eds0[MAXN];
vector<int> eds1[MAXN];
int dd[MAXN];
queue<int> qu;

void dfs1(int v) {
	was[v] = 1;
	for (int u: eds1[v]) {
		if (was[u])
			continue;
		p[u] = v;
		h[u] = h[v] + 1;
		dfs1(u);
	}
}

int dst(int a, int b) {
	if (a == b)
		return 0;
	if (p[a] == b || p[b] == a)
		return 1;
	if (p[a] == p[b] || (p[a] != -1 && p[p[a]] == b) || (p[b] != -1 && p[p[b]] == a))
		return 2;
	return 3;
}

int main() {
	int x, y;
	int ans = 0;
	scanf("%d%d%d", &n, &x, &y);
	--x, --y;
	for (int i = 0; i < n - 1; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		--a, --b;
		eds0[a].push_back(b);
		eds0[b].push_back(a);
	}
	for (int i = 0; i < n - 1; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		--a, --b;
		eds1[a].push_back(b);
		eds1[b].push_back(a);
	}
	dfs1(y);
	p[y] = -1;
	
	qu.push(x);
	for (int i = 0; i < n; ++i)
		dd[i] = -1;
	dd[x] = 0;
	while (!qu.empty()) {
		int x = qu.front();
		qu.pop();
		ans = max(ans, h[x] * 2);
		if (dd[x] < h[x]) {
			for (int u: eds0[x]) {
				if (dst(x, u) > 2) {
					cout << -1 << "\n";
					return 0;
				}
				if (dd[u] == -1)
					dd[u] = dd[x] + 1, qu.push(u);
			}
		}
	}
	cout << ans << "\n";
	return 0;
}




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


int main() {
  string s;
  cin >> s;
  int count = 0;
  if (s[0] == 'o') ++count;
  if (s[1] == 'o') ++count;
  if (s[2] == 'o') ++count;
  cout << 700+100*count << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  n %= 10;
  if (n == 3) {
    puts("bon");
  } else
  if (n == 0 || n == 1 || n == 6 || n == 8) {
    puts("pon");
  } else {
    puts("hon");
  }
}


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

int main() {
  int a,b,c;
  cin >> a >> b >> c;
  cout << (b-a == c-b ? "YES" : "NO") << endl;
  return 0;
}

Measured memory_bytes: 256
a,b,c=map(int,input().split())
d={"a":a,"b":b,"c":c}
for i in range(int(input())+1):
    if d["a"]<d["b"]<d["c"]:
        print("Yes")
        exit()
    elif d["a"]>=d["c"]: d["c"]*=2
    elif d["a"]>=d["b"]: d["b"]*=2
    elif d["b"]>=d["c"]: d["c"]*=2
print("No")


Measured memory_bytes: 62000
#include <bits/stdc++.h> 
using namespace std;
 
int main() {
  int ans=0;
  string i;
  cin>>i;
  if((i.at(0)==i.at(1)&&i.at(1)==i.at(2))||(i.at(1)==i.at(2)&&i.at(2)==i.at(3))) {
    cout<<"Yes"<<endl;
  }
  else {
    cout<<"No"<<endl;
  }
}

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

long long int area1;
long long int area2;
long long int area3;
long long int max_area;
long long int min_area;

int main() {

    int h,w;

    cin >> h >> w;

    long long int ans = 1LL << 60;

    if(h%3 == 0 || w%3 == 0){
        ans = 0;
    }
    else{

        for(long long int i=1; i<w; i++){

            if(h >= 2) {
                area1 = i*h;
                area2 = (h / 2) * (w - i);
                area3 = (h - (h / 2)) * (w - i);
                max_area = max(area1, max(area2, area3));
                min_area = min(area1, min(area2, area3));
                ans = min(ans, max_area - min_area);
            }

            if((w-i) >= 2) {
                area1 = i * h;
                area2 = (w - i) / 2 * h;
                area3 = ((w-i) - (w-i) / 2) * h;
                max_area = max(area1, max(area2, area3));
                min_area = min(area1, min(area2, area3));
                ans = min(ans, max_area - min_area);
            }
        }

        for(long long int i=1; i<h; i++){

            if(w >= 2) {
                area1 = i * w;
                area2 = (w / 2) * (h - i);
                area3 = (w - (w / 2)) * (h - i);
                max_area = max(area1, max(area2, area3));
                min_area = min(area1, min(area2, area3));
                ans = min(ans, max_area - min_area);
            }

            if((h-i) >= 2) {
                area1 = i * w;
                area2 = (h - i) / 2 * w;
                area3 = ((h-i) - (h - i) / 2) * w;
                max_area = max(area1, max(area2, area3));
                min_area = min(area1, min(area2, area3));
                ans = min(ans, max_area - min_area);
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;



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

	int N;
	cin >> N;
	VI A(N),B(N);
	REP(i, N) {
		cin >> A[i];
		B[i] = A[i];
	}
	rSORT(B);
	REP(i, N) {
		if (A[i] == B[0]) {
			cout << B[1] << endl;
		}
		else {
			cout << B[0] << endl;
		}
	}
	return 0;
}



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

int main() {
    string s;
    cin >> s;
    int n, res;
    n = res = s.size();
    for(int i = 0; i < n - 1; ++i) {
        if(s[i] == s[i + 1]) continue;
        int x = max(i + 1, n - 1 - i);
        res = min(res, x);
    }
    printf("%d\n", res);
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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;
}
int main()
{
    ll N, M;
    cin >> N >> M;
    vint div;
    for (int i = 1; i * i <= M; i++)
    {
        if (M % i == 0)
        {
            if (i <= M / N)
                div.push_back(i);
            if ((M / i) <= M / N)
                div.push_back(M / i);
        }
    }
    cout << *max_element(all(div));

    return 0;
}

Measured memory_bytes: 256
<?php
  declare(strict_types=1);

  fscanf(STDIN, "%i", $n);
  $s = trim(fgets(STDIN));

  $correct = FALSE;
  for ($assumption = 3; !$correct && $assumption >= 0; --$assumption)
  {
      unset($t);
      $t[0] = (bool)($assumption & 1); // TRUE means sheep
      $t[1] = (bool)(($assumption >> 1) & 1);
      for ($i = 1; $i < $n; ++$i)
      {
          if ($t[$i])
          {
              if ($s[$i] === 'o')
              {
                  $t[$i + 1] = $t[$i - 1];
              }
              else
              {
                  $t[$i + 1] = !$t[$i - 1];
              }
          }
          else
          {
              if ($s[$i] === 'o')
              {
                  $t[$i + 1] = !$t[$i - 1];
              }
              else
              {
                  $t[$i + 1] = $t[$i - 1];
              }
          }
      }
      
      if ($t[0])
      {
          if ($s[0] === 'o')
          {
              $correct = $t[1] === $t[$n - 1];
          }
          else
          {
              $correct = $t[1] !== $t[$n - 1];
          }
      }
      else
      {
          if ($s[0] === 'o')
          {
              $correct = $t[1] !== $t[$n - 1];
          }
          else
          {
              $correct = $t[1] === $t[$n - 1];
          }
      }
      $correct = $correct && $t[0] === $t[$n];
  }

  if ($correct)
  {
      for ($i = 0; $i < $n; ++$i)
      {
          $t[$i] = $t[$i] ? 'S' : 'W';
      }

      echo substr(join($t), 0, $n),PHP_EOL;
  }
  else
  {
      echo -1,PHP_EOL;
  }


Measured memory_bytes: 10868
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <map>
#include <iomanip>
#include <limits.h>

using namespace std;    
typedef long long ll;
typedef pair<ll, ll> pll;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const bool DEBAG = false;


int N;

struct Node{
    ll cost;
    int parent;  // index of parent node
    int index;   // index in node list
    vector< ll > connect;
};
    
int reach[100001];
ll cnt = 0;    

bool ret = false;
vector<int> r;

void dfs(vector<Node> &node, int index, vector<int> &route){

    cnt ++;
    reach[index] = 1;
    route.push_back(index);

    if(index == N - 1){
        r = route;
        ret = true;
        return ;
    }

    for(int i = 0; i < node[index].connect.size(); i++){
        int next_index = node[index].connect[i];
        if(reach[next_index] == 0){
            dfs(node, next_index, route);
        }
    }
    if(!ret && route.back() == index){
        route.pop_back();
    }
}
    

int main(){

    cin >> N;
    
    vector<Node> node(N);
    for(int i = 0; i < N; i++){
        node[i].cost = 0;
        node[i].parent = -1;
        node[i].index = i;
    }
    for(int i = 0; i < N-1; i++){
        ll a, b;
        cin >> a >> b ;
        a --;
        b --;
        node[a].connect.push_back(b);
        node[b].connect.push_back(a);
    }

    vector<int> route;
    dfs(node, 0, route);

    /*
    for(int i = 0; i < route.size(); i++){
        cout << route[i] + 1<< " ";
    }
        cout << endl;
    */
    // reset
    cnt = 0;
    for(int i = 0; i < N; i++){
        reach[i] = 0;
    }

    //int id = (route.size() + 1) / 2;
    //reach[ route[id] ] = 1;
    int id = (r.size() + 1) / 2;
    reach[ r[id] ] = 1;

    //cout << route[id] + 1 << " ";

    dfs(node, 0, route);
    //cout << cnt << endl;

    if(cnt > N - cnt){
        cout << "Fennec" << endl;
    }
    else{
        cout << "Snuke" << endl;
    }

}

Measured memory_bytes: 13944
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n, k;
  string s;
  
  cin >> n >> k;
  cin >> s;
  k = k-1;
  if(s[k] == 'A')s[k] = 'a';
  if(s[k] == 'B')s[k] = 'b';
  if(s[k] == 'C')s[k] = 'c';

  cout<<s<<endl;
 
  
}

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

int main() {
  int n, cnt, tmp;
  bool flag = true;
  string s;
  vector<int> v;
  cin >> n;
  cin.ignore();
  getline(cin, s);
  stringstream ss(s);
  while (ss >> tmp)
    v.push_back(tmp);

  cnt = 0;

  while (flag) {
    flag = false;
    for (int i = n - 1; i > 0; i--) {
      if (v[i] < v[i - 1]) {
        tmp = v[i];
        v[i] = v[i - 1];
        v[i - 1] = tmp;
        cnt++;
        flag = true;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    if (i == n - 1)
      cout << v[i] << endl;
    else
      cout << v[i] << ' ';
  }

  cout << cnt << endl;

  return 0;
}



Measured memory_bytes: 3208
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


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

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N, x[111], y[111], h[111];

  bool valid[111];

  memset(valid, 1, sizeof(valid));

  std::cin >> N;

  for (int i = 0; i < N; i ++)
    std::cin >> x[i] >> y[i] >> h[i];

  for (int i = 0; i < N; i ++)
    for (int j = 0; j < N; j ++)
      if (i != j)
        if (h[i] == 0 && h[j]) {
          int dx = std::abs(x[j] - x[i]), dy = std::abs(y[j] - y[i]);

          if (h[i] + dx + dy != h[j]) {
            valid[i] = false;

            break;
          }
        }

  for (int i = 0; i <= 100; i ++)
    for (int j = 0; j <= 100; j ++) {
      std::set<int> set;

      for (int k = 0; k < N; k ++)
        if (valid[k]) {
          int dx = std::abs(j - x[k]), dy = std::abs(i - y[k]);

          set.insert(h[k] + dx + dy);
        }

      if (set.size() == 1) {
        std::cout << j << ' ' << i << ' ' << *set.begin() << std::endl;

        return 0;
      }
    }

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;
//cout << fixed << setprecision(0)
int main() { 
  string s;cin >> s;
  int ans = 0;
  rep(i,s.length()){
    if(s[i]=='+'){
      ans++;
    }else{
      ans--;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct frep {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr frep(int l_, int r_): l(std::min(l_, r_)), r(r_) {}
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct brep {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr r, l;
  constexpr brep(int r_, int l_): r(std::max(l_, r_) - 1), l(l_ - 1) {}
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

template <class T>
inline T scan() {
  T res;
  std::cin >> res;
  return res;
}

int main() {
  int N;
  std::cin >> N;
  int min = (1 << 30) - 1, ans = 0;
  for (const int i: frep(0, N)) {
    int P;
    std::cin >> P;
    if (P <= min) {
      ++ans;
    }
    chmin(min, P);
  }
  std::cout << ans << '\n';
  return 0;
}


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

#define rep_0(i, end) for(int i = 0; i < (end); ++i)
#define rep_1(i, fr, ba) for(int i = (fr); i <= (ba); ++i)
#define rep(...) overload_rep(__VA_ARGS__, rep_1, rep_0)(__VA_ARGS__)
#define overload_rep(arg_0, arg_1, arg_2, name, ...) name
#define all(box) box.begin(), box.end()

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template <const int MODULUS = 1000000007>
struct ModInt {
private: 
    using lint = long long;
    lint value;
public: 
    friend istream& operator >> (istream& stream, ModInt& lhs) { 
        stream >> lhs.value; lhs.normalize();  return stream;
    }
    friend ostream& operator << (ostream& stream, const ModInt& rhs) { 
        return stream << rhs.value; 
    }
    constexpr ModInt(const lint& value_ = 0) : value(value_) { normalize(); }
    constexpr const lint operator () () const  { return value; }
    constexpr lint& operator () () { return value; }
    constexpr ModInt operator + (const ModInt& rhs) { return ModInt(*this) += rhs; }
    constexpr ModInt& operator += (const ModInt& rhs) {
        if((value += rhs.value) >= MODULUS)value -= MODULUS; 
        return *this;
    }
    constexpr ModInt operator - (const ModInt& rhs) { return ModInt(*this) -= rhs; }
    constexpr ModInt& operator -= (const ModInt& rhs) {
        if((value += MODULUS - rhs.value) >= MODULUS)value -= MODULUS; 
        return *this;
    }
    constexpr ModInt operator * (const ModInt& rhs) { return ModInt(*this) *= rhs; }
    constexpr ModInt& operator *= (const ModInt& rhs) {
        value = value * rhs.value % MODULUS;  
        return *this;
    }
    constexpr ModInt operator / (const ModInt& rhs) { return ModInt(*this) /= rhs; }
    constexpr ModInt& operator /= (const ModInt& rhs) { return *this *= ~rhs; }
    constexpr ModInt operator - () const { return ModInt(MODULUS - value); }
    constexpr ModInt operator ~ () const { return pow(MODULUS - 2); }
    constexpr ModInt pow(lint p) const {
        ModInt res(1), mult(*this);
        for(; p; p >>= 1){ if(p & 1)res *= mult; mult *= mult; }
        return res;
    }
    constexpr void normalize() {
        if(value >= 0 && value < MODULUS)return;
        value %= MODULUS;
        if(value < 0)value += MODULUS;
    }
};

using mint = ModInt<>;
typedef long long lint;

int main() {

    int N;
    cin >> N;
    vector<lint> a(N);
    rep(i, N) cin >> a[i];

    vector<int> bitcnt(60, 0);
    rep(i, N) {
        rep(j, 60) {
            if(a[i] & (1ll << j))bitcnt[j]++;
        }
    }

    mint ans;
    rep(i, 60) {
        int t = bitcnt[i];
        ans += mint(t) * mint(N - t) * mint(1ll << i);
    }

    cout << ans << '\n';
    return 0;

}


Measured memory_bytes: 2560
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    long n = 0;
    long m = 0;
    std::cin >> n;
    std::cin >> m;
    long l = (long) m / n;
    bool b = !(l == 1);
    long r = 1;
    while(b){
        if((m % l == 0) && ((m / l) >= n)){
            m = m / l;
            r = r * l;
        }
        l--;
        b = !((m <= n) || (l == 1));
    }
    std::cout << r << std::endl;
}


Measured memory_bytes: 256
#include <stdio.h>          // printf(), scanf()
#define MAX_N 100

int
main(int argc, char** argv)
{
	int a[MAX_N];
	int x;
	int n;
	int i, j;

	scanf("%d", &n);
	for (i = 0; i < n; ++i)
	{
		scanf("%d", &a[i]);
		printf("%d%c", a[i], (i != n - 1) ? ' ' : '\n');
	}

	for (i = 1; i < n; ++i)
	{
		x = a[i];
		for (j = i - 1; j >= 0 && x < a[j]; --j)
			a[j + 1] = a[j];

		a[j + 1] = x;

		for (j = 0; j < n; ++j)
			printf("%d%c", a[j], (j != n - 1) ? ' ' : '\n');
	}

	return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<math.h>
using namespace std;
int main() {
	int N,count = 0;
	static double X[200000], Y[200000];
	double D,x;
	cin >> N;
	cin >> D;
	for (int i = 0; i < N; i++)
	{
		cin >> X[i];
		cin >> Y[i];
		x = X[i] * X[i] + Y[i] * Y[i];
		x = sqrt(x);

		if (D >= x)count++;
		
	}
	cout << count;
	return 0;

}

Measured memory_bytes: 6964
n, m = map(int, input().split())

ans = [0] * (n + 2)

for i in range(m):

    l, r = map(int, input().split())

    ans[l] += 1

    ans[r + 1] -= 1

count = 0

for i in range(n + 1):

    ans[i + 1] += ans[i]

    if ans[i] == m:
        count += 1

print(count)

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

#define int long long
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define yn(x) ((x) ? "Yes" : "No")

typedef pair <int, int> ii;
typedef pair <int, ii> iii;

const int siz = 2e5 + 10;
const int SIZ = 1e6 + 10;
const int mod = 1e9 + 7;
const int maxx = 2e9;
const int MAXX = 1e18;
const string file = "1";

int quickPow(int x, int n) {
    if (n == 0) {
        return 1;
    }

    int t = quickPow(x, n / 2);
    (t *= t) %= mod;

    if (n % 2 == 0) {
        return t;
    }
    return (t * x) % mod;
}

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

//    freopen ((file + ".inp").c_str(), "r", stdin);
//    freopen ((file + ".out").c_str(), "w", stdout);

    int n;
    cin >> n;
    map <ii, int> cnt;
    int cnt0 = 0;
    for (int i = 1; i <= n; i++) {
        int x, y;
        cin >> x >> y;

        if (x == 0 && y == 0) {
            cnt0++;
            continue;
        }

        int g = __gcd(abs(x), abs(y));
        x /= g;
        y /= g;

        if (y < 0) {
            x *= (-1);
            y *= (-1);
        }

        if (y == 0) {
            if (x < 0) {
                x *= (-1);
            }
        }

        cnt[ii(x, y)]++;
    }

//    for (auto &a : cnt) {
//        cout << a.fi.fi << " " << a.fi.se << " " << a.se << "\n";
//    }

    int ans = 1;
    for (auto &a : cnt) {
        int x, y;
        tie(x, y) = a.fi;

        if (cnt[ii(x, y)] == -1) {
            continue;
        }

        int x2 = -y, y2 = x;
        if (y2 < 0) {
            x2 *= (-1);
            y2 *= (-1);
        }

        if (y2 == 0) {
            if (x2 < 0) {
                x2 *= (-1);
            }
        }

        if (cnt.find(ii(x2, y2)) != cnt.end()) {
            if (cnt[ii(x2, y2)] != -1) {
                (ans *= ((quickPow(2, cnt[ii(x, y)]) + quickPow(2, cnt[ii(x2, y2)])) % mod - 1)) %= mod;
                cnt[ii(x, y)] = -1;
                cnt[ii(x2, y2)] = -1;
            }
        }
        else {
            (ans *= quickPow(2, cnt[ii(x, y)])) %= mod;
        }
    }

    cout << ((ans - 1 + mod) % mod + cnt0) % mod << "\n";

//    cerr << "Time: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

    return 0;
}


Measured memory_bytes: 15908
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  string A,B,C;
  cin >> A;
  cin >> B;
  cin >> C;
  char pl='a';
  
  while(true){
    
    if(pl=='a'){
      if(A.size()==0){
        pl='A';
        break;
      }else{
        pl=A.at(0);
        A.erase(0,1);
        continue;
      }
    }else if(pl=='b'){
      if(B.size()==0){
        pl='B';
        break;
      }else{
        pl=B.at(0);
        B.erase(0,1);
        continue;
      }
    }else if(pl=='c'){
      if(C.size()==0){
        pl='C';
        break;
      }else{
        pl=C.at(0);
        C.erase(0,1);
        continue;
      }
    }
    
  }
  
  cout << pl << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
 
class Main{
 public static void main(String[] args) {
  int a, b, c;
  Scanner scan = new Scanner(System.in);
 
  a = scan.nextInt();
  b = scan.nextInt();
  c = scan.nextInt();
 
  if (a < b && b < c) {
   System.out.println("Yes");
  } else {
   System.out.println("No");
  }
 }
}

Measured memory_bytes: 26112
#include <iostream>
#include <cstdio>
#include<cstring>
#include <algorithm>
using namespace std;

int main()
{
    int a[10];
    for(int i = 0; i < 3; i ++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a + 3);
    bool flag = false;
    if(a[0] != 5)flag = true;
    if(a[1] != 5)flag = true;
    if(a[2] != 7)flag = true;
    if(flag == true)
    {
        printf("NO\n");
    }
    else
    {
        printf("YES\n");
    }
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

read=sys.stdin.read
class Unionfind():
    def __init__(self,n):
        self.parents=[-1]*n
        self.dist=[0]*n 
    
    def find(self,x):
        if self.parents[x]<0:
            return x,self.dist[x]
        else:
            tmp=self.find(self.parents[x])
            self.parents[x]=tmp[0]
            self.dist[x]+=tmp[1]
            return self.parents[x],self.dist[x]
    
    def union(self,x,y,d):
        rx=self.find(x)[0]
        ry=self.find(y)[0]
        diff=self.dist[y]-self.dist[x]-d
        if rx==ry:
            if diff!=0:
                return True
            return False
        if diff<0:
            rx,ry=ry,rx
            diff=-diff
        self.parents[ry]=min(self.parents[ry],self.parents[rx]-diff)
        self.parents[rx]=ry
        self.dist[rx]=diff
        return False
    
def main():
    n,m,*lrd=map(int,read().split())
    v=Unionfind(n)
    for l,r,d in zip(*[iter(lrd)]*3):
        if v.union(l-1,r-1,d):
            print('No')
            break
    else:
        print('Yes')
if __name__=='__main__':
    main()


Measured memory_bytes: 74380
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int main(){
  int N, P; cin >> N >> P;
  string S; cin >> S;

  if (P == 2 || P == 5){
    ll ans = 0;
    for (ll i = 0; i < N; i++){
      int now = S[i] - '0';
      if (now % P == 0){
        ans += i + 1;
      }
    }
    cout << ans << endl;
    return 0;
  }

  ll DP[N + 1] = {}, digit = 1;
  ll cnt[P] = {};
  for (int i = N - 1; i >= 0; i--){
    ll now = S[i] - '0';
    now = now * digit % P;
    DP[i] = DP[i + 1] + now; DP[i] %= P;
    digit *= 10; digit %= P;
    cnt[DP[i]]++;
  }
  
  ll ans = 0;
  for (int i = 0; i < P; i++){
    ans += cnt[i] * (cnt[i] - 1) / 2;
  }
  ans += cnt[0];
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 2180
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstdlib>
#include<algorithm>
using namespace std;
string st1,st2;
int main()
{
cin>>st1;
for(int i=0; i<st1.size(); i++)
{
	if(st1[i]!='B')st2+=st1[i];
	else 
	{
	if(st2.size()>=1)
		st2.erase(st2.size()-1,1);
	}
	
}
cout<<st2<<endl;
return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int p[5];
	int n=5;
	int i,j,temp;
	for(i=0;i<5;i++){
	scanf("%d",&p[i]);
	}
	for(i=0;i<n-1;i++){
		for(j=n-1;j>i;j--){
			if(p[j-1]<p[j]){
				temp=p[j];
				p[j]=p[j-1];
				p[j-1]=temp;
			}
		}
	}
	for(i=0;i<5;i++){
	printf("%d",p[i]);
		if(i<4){
			printf(" ");
		}
		else{
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 600
package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, h, m float64
	fmt.Scan(&a, &b, &h, &m)
	rec := float64(30*h + m/2 - 6*m)

	cosC := math.Cos(rec * math.Pi / 180)
	//fmt.Println(rec, cosC)
	result := a*a + b*b - float64(2*a*b*cosC)
	fmt.Println(math.Sqrt(result))
}


Measured memory_bytes: 1820
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    vector<ll> a(N + 1);
    for (int i = 0; i < N; i++) cin >> a[i];
    vector<vector<ll> > dp(2, vector<ll>(N + 2));
    dp[0][0] = 0;
    dp[1][0] = -LINF;
    for (int i = 0; i <= N; i++) {
        dp[0][i + 1] = max(dp[0][i] + a[i], dp[1][i] - a[i]);
        dp[1][i + 1] = max(dp[0][i] - a[i], dp[1][i] + a[i]);
    }
    cout << dp[0][N] << '\n';
}


Measured memory_bytes: 3328
N = int(input())
a = []
not_ten = []
for i in range(N):
    k = int(input())
    a.append(k)
    if k%10 != 0:
        not_ten.append(k)

a = sorted(a)
not_ten = sorted(not_ten)
res = sum(a)
if res%10 != 0:
    print(res)
elif len(not_ten) > 0:
    print(res-not_ten[0])
else:
    print(0)

Measured memory_bytes: 38416
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 998244353;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    string s;
    cin >> s;
    string ans;
    for (char c : s) {
        if (c == 'B') {
            if (sz(ans)) ans.pop_back();
        } else {
            ans += c;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=998244353;
int n,s,a[3010],f[3010];
ll ans;
int main(){
	scanf("%d%d",&n,&s);
	for(int i=1;i<=n;i++)scanf("%d",a+i);
	for(int i=1;i<=n;i++){
		for(int j=s;j>a[i];j--)
			j==s && ((ans+=1ll*f[j-a[i]]*(n-i+1))%=mod),
			(f[j]+=f[j-a[i]])%=mod;
		(f[a[i]]+=i)%=mod;
		if(a[i]==s)(ans+=1ll*i*(n-i+1))%=mod;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265358979323
#define ll long long int
#define vi vector <int>
#define vl vector <ll>
#define all(v) (v).begin(),(v).end()
#define pb push_back
 
ll power(ll a, ll b){//a^b
    ll res=1;
    while(b>0){
        if(b&1){res=(res*a);b--;}
        a=(a*a);
        b>>=1;
    }
    return res;
}
 
ll gcd(ll a, ll b){return (b==0)?a:gcd(b,a%b);}
 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n;
	cin>>n;
	map <string,ll> mp;
	ll ma=0;
	for(ll i=0;i<n;i++){
		string s;
		cin>>s;
		mp[s]++;
		if(mp[s]>ma)
			ma=mp[s];
	}
	map <string,ll> :: iterator it=mp.begin();
	while(it!=mp.end()){
		if(it->second==ma)
			cout<<it->first<<"\n";
		it++;
	}
}

Measured memory_bytes: 19248
x,y=(int(x) for x in input().split())
prize=0
if x==1:
  prize+=300000
if x==2:
  prize+=200000
if x==3:
  prize+=100000
if y==1:
  prize+=300000
if y==2:
  prize+=200000
if y==3:
  prize+=100000
if x==1 and y==1:
  prize+=400000
print(prize)
  

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
void f(string s,char m,int n){
  if(!n)cout<<s<<"\n";
  else{
    for(char c='a';c<m;++c) f(s+c,m,n-1);
    f(s+m,m+1,n-1);
  }
}
main(){
  int n;
  cin>>n;
  f("a",'b',n-1);
}

Measured memory_bytes: 1536
#include <iostream>
#include<climits>
using namespace std;
int solve(int a[],int n,int k)
{
    int dp[n+1];
    dp[1] = 0;
    for(int i = 2;i <= n;i++)
    {
        dp[i] = INT_MAX;
        for(int j = i -1 ;j >= 1 && (i-j) <= k;j--)
        {
            dp[i] = min(dp[i],abs(a[i] - a[j]) + dp[j]);
        }
    }
    return dp[n];
}
int main() {
    int n,k;
    cin>>n>>k;
    int a[n+1];
    for(int i = 1;i <=n;i++)
        cin>>a[i];
    cout<<solve(a,n,k);
}

Measured memory_bytes: 4332
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def S(): return input()


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = {False: 'No', True: 'Yes'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']


# show_flg = True
show_flg = False


def main():
    N, K = MI()
    s = S()
    a = [0]
    first_zero = s[0] == '0'
    cur = s[0]

    for i in range(len(s)):
        if cur == s[i]:
            a[-1] += 1
        else:
            cur = s[i]
            a.append(1)

    # print(a)
    # print(first_zero, limit)
    ans = 0
    cur = 0
    right = 0
    for left in range(len(a)):
        if first_zero:
            if left % 2 == 0:
                limit = 2 * K
            else:
                limit = 2 * K + 1
        else:
            if left % 2 == 0:
                limit = 2 * K + 1
            else:
                limit = 2 * K
        # limit = 2 * K if first_zero else 2 * K + 1

        while right < len(a) and right - left < limit:
            cur += a[right]
            right += 1

        ans = max(cur, ans)
        cur -= a[left]
        # print(ans, cur, cur + a[left], left, right)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 45932
#include <bits/stdc++.h>
using namespace std;
typedef int64_t i64;

int main()
{
  long long X;
  cin >> X ;
  long long Y = 0;
  long long C = 100;
	while(true){
	 Y++;
     C = C * 1.01;
       if(C >= X){
       break;
       }
    }
  cout << Y << endl;
}


Measured memory_bytes: 3596
#include <stdio.h>

//0 -> # start //1 -> . start
void drawline(int width, int mode)
{
	int i;

	i = 0;
	while(i < width)
	{
		if(mode == 0)
		{
			printf("#");
			mode = 1;
		}
		else if(mode == 1)
		{
			printf(".");
			mode = 0;
		}
		i++;
	}
	printf("\n");
}

int main(void)
{
	int height, width;		//Value H, W.
	int i, mode;

	while(1)
	{
		mode = 0;			//# start reset.

		scanf("%d %d", &height, &width);
		if(height == 0 && width == 0)
			return (0);

		i = 0;
		while(i < height)
		{
			drawline(width, mode);
			if(mode == 0)
				mode = 1;
			else if(mode == 1)
				mode = 0;
			i++;
		}
		
		printf("\n");
	}

	return (0);
}



Measured memory_bytes: 2072
n,m,q=map(int,input().split())
A=[]
for i  in range(q):
    A.append(list(map(int,input().split())))
ans=0
def judge(Q):
    now=0
    for l in A:
        a,b,c,d=l
        if Q[b-1]-Q[a-1]==c:
            now+=d
    global ans
    ans=max(ans,now)
    return


def dfs(L):
    if len(L)==n:
        judge(L)
        return
    jj=L[-1] if len(L)>0 else 1
    for i in range(jj,m+1):
        L.append(i)
        dfs(L)
        L.pop()

dfs([])
print(ans)


Measured memory_bytes: 9156
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
const int INF = 2147483647;
const ll MOD = 1000000007;

using namespace std;

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

ll modinv(ll a, ll mod) { return modpow(a, mod - 2, mod); }

ll modnCr(ll n, ll r, ll mod) {
  ll ans = 1;
  FOR(i, 1, n + 1) { ans = (ans * i) % mod; }
  ll inv = 1;
  FOR(i, 1, r + 1) { inv = (inv * i) % mod; }
  FOR(i, 1, n - r + 1) { inv = (inv * i) % mod; }
  ans = (ans * modinv(inv, mod)) % mod;
  return ans;
}

int main() {
  ll n, k;
  cin >> n >> k;
  vl a(n);
  REP(i, n) { cin >> a[i]; }

  vl ex(n + 1), exinv(n + 1);
  ex[0] = 1LL;
  exinv[0] = 1LL;

  FOR(i, 1, n + 1) {
    ex[i] = (ex[i - 1] * i) % MOD;
    exinv[i] = modinv(ex[i], MOD);
  }

  ll ans = 0;
  sort(a.rbegin(), a.rend());

  REP(i, n) {
    if (n - i - 1 >= k - 1) {
      ll tmp = (ex[n - i - 1] * exinv[k - 1]) % MOD;
      ll tmp2 = (tmp * exinv[n - i - k]) % MOD;
      ans = (ans + (a[i] * tmp2) % MOD) % MOD;
    }
    if (i >= k - 1) {
      ll tmp = (ex[i] * exinv[k - 1]) % MOD;
      ll tmp2 = (tmp * exinv[i - k + 1]) % MOD;

      ans = (ans - ((a[i] * tmp2) % MOD) + MOD) % MOD;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 2560
// https://atcoder.jp/contests/agc022/tasks/agc022_a
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <stack>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main()
{
    string S;
    cin >> S;
    if (26 == S.size())
    {
        int idx = 25;
        for (int i = 0; i < 25; ++i)
        {
            bool ok = true;
            for (int j = i; j < 25; ++j)
            {
                if (S[j] < S[j + 1]) 
                {
                    ok = false;
                    break;
                }
            }
            if (ok)
            {
                idx = i;
                break;
            }
        }
        if (idx == 0)
        {
            cout << -1 << endl;
            return 0;
        }
        char c = 'z' + 1;
        for (int i = idx; i < 26; ++i)
        {
            if (c > S[i] && S[i] > S[idx - 1]) c = S[i];
        }
        for (int i = 0; i < idx - 1; ++i)
        {
            cout << S[i];
        }
        cout << c << endl;
        return 0;
    }
    vector<int> cnts(26, 0);
    for (int i = 0; i < S.size(); ++i)
    {
        ++cnts[S[i] - 'a'];
    }
    
    int idx = 0;
    for (int i = 0; i < 26; ++i)
    {
        if (cnts[i] == 0)
        {
            idx = i;
            break;
        }
    }
    S.push_back('a' + idx);
    cout << S << endl;
    return 0;
}


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

using namespace std;
using ll = long long;
const int mod = 1e9 + 7;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}

    mint operator-() const { return mint(-x); }

    mint &operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }

    mint &operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }

    mint operator+(const mint a) const { return mint(*this) += a; }

    mint operator-(const mint a) const { return mint(*this) -= a; }

    mint operator*(const mint a) const { return mint(*this) *= a; }

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }

    mint &operator/=(const mint a) { return *this *= a.inv(); }

    mint operator/(const mint a) const { return mint(*this) /= a; }
};

istream &operator>>(istream &is, const mint &a) { return is >> a.x; }

ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

struct combination {
    vector<mint> fact, ifact;

    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }

    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
};

struct UnionFind {
    vector<int> d;

    UnionFind(int n = 0) : d(n, -1) {}

    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }

    bool unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }

    bool same(int x, int y) { return find(x) == find(y); }

    int size(int x) { return -d[find(x)]; }
};

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

int main() {
    int n;
    cin >> n;
    vector<int> A(n + 1, -1);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    vector<int> ans(n);
    int N = n;
    for (int i = 0; i < n; ++i) {
        int k = -1;
        for (int j = 0; j < n; ++j) {
            if (N >= A[j] && j + 1 == A[j])k = j;
        }
        if (k == -1) {
            cout << -1 << endl;
            return 0;
        }
        N--;
        ans[N] = A[k];
        for (int j = k; j < n; ++j) {
            A[j] = A[j + 1];
        }
    }
    for (int i = 0; i < n; ++i) {
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 3644