akhauriyash/Code-Regression huggingface dataset:
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return int(i)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	n := nextInt()

	var ans, active int
	nn := make([]int, 0, n)
	for i := 0; i < n; i++ {
		nn = append(nn, nextInt())
	}

	for i := 0; i < n; i++ {
		if active < nn[i] {
			ans += nn[i] - active
		}
		active = nn[i]
	}

	fmt.Printf("%#v\n", ans)
}


Measured memory_bytes: 640
NT = list(map(int, input().split()))
N = NT[0]
T = NT[1]
S = E = ans = 0
t = list(map(int, input().split()))
for i in range(N):
    if t[i] < E:
        E = t[i] + T
    else:
        ans += E - S
        S, E = t[i], t[i] + T
ans += E - S
print(ans)

Measured memory_bytes: 25712
#include<bits/stdc++.h>
using namespace std;
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string s;
	cin >> s;
	
	int ans = 0;
	for (int i = 0; i < s.size() / 2; ++i){
		ans += s[i] != s[s.size() - i - 1];
	}
	cout << ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <climits>
using namespace std;

bool comp(pair<int, string> a, pair<int, string> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}

int main(){
    string s,a = "dream",b = "dreamer",c="erase",d="eraser";
    cin >> s;

    long int i = s.size() - 1;
    while(i >= 0){
        if(s[i] == a[4] && s[i-1]==a[3]&&s[i-2]==a[2]&&s[i-3]==a[1]&&s[i-4]==a[0]){
            i -= 5;
        }else if(s[i]==b[6]&&s[i-1]==b[5]&&s[i-2] == b[4] && s[i-3]==b[3]&&s[i-4]==b[2]&&s[i-5]==b[1]&&s[i-6]==b[0]){
            i -= 7;
        }else if(s[i] == c[4] && s[i-1]==c[3]&&s[i-2]==c[2]&&s[i-3]==c[1]&&s[i-4]==c[0]){
            i -= 5;
        }else if(s[i]==d[5]&&s[i-1]==d[4]&&s[i-2]==d[3] && s[i-3]==d[2]&&s[i-4]==d[1]&&s[i-5]==d[0]){
            i -= 6;
        }else{
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
#include <random>
#include <queue>
#include <deque>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;

const int INF = (1 << 30) - 1;
const ll INFLL= (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()

vector<bool> IsPrime;

void sieve(int max){
  if(max+1 > IsPrime.size()){
    IsPrime.resize(max+1,true);
  }
  IsPrime[0] = false;
  IsPrime[1] = false;

  for(int i=2; i*i<=max; ++i){
    if(IsPrime[i]){
      for(int j=2; i*j<=max; ++j){
        IsPrime[i*j] = false;
      }
    }
  }
}


int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N,cnt=0;
  cin>>N;
  sieve(55555);
  for(int i=0;i<IsPrime.size();i++){
    if(IsPrime[i]&&i%5==1){
      cout<<i;
      if(cnt<N-1)cout<<" ";
      cnt++;
    }
    if(cnt==N)break;
  }
  cout<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, z, w;
    cin >> n >> z >> w;
    vector<int> a(n);
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int c1 = 0;
    if(n >= 2)
    {
        c1 = abs(a[n-2]-a[n-1]);
    }
    else
    {
        c1 = abs(a[n-1]-w);
    }
    int c2 = abs(a[n-1]-w);

    cout << max(c1, c2) << endl;
}


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

public class MainClass
{
	public const long Giri = 1000000007;

	public static void Main(string[] args)
	{
		var p = Console.ReadLine();
		
		var c = new string[]{"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
		
		Console.WriteLine( 7 - Array.IndexOf(c, p));
	}

	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}

public class UnionFind
{
	private int[] par;
	public UnionFind(int n)
	{
		par = new int[n];
		for(int i = 0; i < n; i++)
			par[i] = i;
	}
	public int Root(int x)
	{
		if(par[x] == x) return x;
		par[x] = Root(par[x]);
		return par[x];
	}
	public void Unite(int x, int y)
	{
		int rx = Root(x);
		int ry = Root(y);
		if(rx == ry) return;
		par[rx] = ry;
	}
	public bool InSameTree(int x, int y)
	{
		return Root(x) == Root(y);
	}
}

Measured memory_bytes: 11104
// G++ MACRO.CPP -STD=C++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) if(1){for(auto tt=x.begin();tt!=x.end();tt++){if(tt!=x.begin())cout<<" ";cout<<(*tt);}cout<<endl;}

#define ALL(obj) (obj).begin(),(obj).end()

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define EN(x) if(1){cout<<#x<<endl;return 0;}
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template <class T = ll>
T IN(){T x;cin>>x;return (x);}

template <class Head>
void VT(Head head){}
template <class Head,class Seco,class... Tail>
void VT(Head&& head,Seco&& seco,Tail&&... tail){
    seco.resize(head);
    VT(head,move(tail)...);
}
void VT2(){}
template <class Head,class... Tail>
void VT2(Head&& head,Tail&&... tail){
  VECCIN(head);
  VT2(move(tail)...);
}

template <class Head>
void VT3(Head&& head){}
template <class Head,class Seco,class... Tail>
void VT3(Head&& head,Seco&& seco,Tail&&... tail){
  seco[head]=IN();
  VT3(head,move(tail)...);
}

#define VC1(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);VT2(__VA_ARGS__); //aaabbbccc
#define VC2(n,...) V __VA_ARGS__;VT(n,__VA_ARGS__);REP(i,n)VT3(i,__VA_ARGS__); //abcabcabc

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision; // cpp_int

#define P pair<int,int>
#define V vector<ll>
#define M map<ll,ll>
#define S set<ll>

#define pb(a) push_back(a)
#define mp make_pair

int main(){
  SCIN(s);
  CIN(w);
  for(int i = 0; i < s.size(); i += w)
  cout<<s[i];
  ENDL;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
ab = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    ab[a-1].append(b-1)
    ab[b-1].append(a-1)

rb = [-1]*n
rb[0] = 1
count1 = 1
count2 = 0
rb_m = [[0]]
for i in rb_m:
    n_rb = []
    for j in i:
        x = rb[j]
        for k in ab[j]:
            if(rb[k] != -1):
                continue
            if(x == 1):
                rb[k] = 2
                count2 += 1
            elif(x == 2):
                rb[k] = 1
                count1 += 1
            n_rb.append(k)
    set(n_rb)
    if(n_rb == []):
        break
    else:
        rb_m.append(n_rb)

ans = [0 for i in range(n)]
if(count1 > n//3 and count2 > n//3):
    ne1 = 1
    ne2 = 2
    ne3 = 3
    for i in range(n):
        if(rb[i] == 1 and ne1 <= n):
            ans[i] = ne1
            ne1 += 3
        elif(rb[i] == 2 and ne2 <= n):
            ans[i] = ne2
            ne2 += 3
        else:
            ans[i] = ne3
            ne3 += 3
elif(count2 >= 2*n//3):
    ne1 = 1
    ne2 = 2
    ne3 = 3
    for i in range(n):
        if(rb[i] == 1):
            ans[i] = ne3
            ne3 += 3
        elif(ne1 <= n):
            ans[i] = ne1
            ne1 += 3
        elif(ne2 <= n):
            ans[i] = ne2
            ne2 += 3
        else:
            ans[i] = ne3
            ne3 += 3
elif(count1 >= 2*n//3):
    ne1 = 1
    ne2 = 2
    ne3 = 3
    for i in range(n):
        if(rb[i] == 2):
            ans[i] = ne3
            ne3 += 3
        elif(ne1 <= n):
            ans[i] = ne1
            ne1 += 3
        elif(ne2 <= n):
            ans[i] = ne2
            ne2 += 3
        else:
            ans[i] = ne3
            ne3 += 3
print(*ans)

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

using namespace std;

using ll = long long;


void solve(istream &cin = std::cin, ostream &cout = std::cout)
{
	int n;

	cin >> n;

	vector<string> arr(n);

	for (auto &it : arr)
		cin >> it;

	int ans = 0;

	for (const auto &it : arr)
		for (size_t j = 0; j < it.size(); j++)
			if (it.substr(j, 2) == "AB")
				ans++;

	int a = 0, b = 0, ab = 0;

	for (const auto &it : arr)
	{
		if (it.front() == 'B')
			b++;
		if (it.back() == 'A')
			a++;

		if (it.front() == 'B' && it.back() == 'A')
			ab++;
	}

	if (a != b || ab != a)
		ans += min (a, b);
	else
		ans += max (min (a, b) - 1, 0);

	cout << ans << endl;
}


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

	cout << fixed;

#ifdef LOCAL
	ifstream fin("../input.txt");

	solve(fin);

	cout << setprecision(4) << "clock: " << clock() / (double) CLOCKS_PER_SEC << endl;
#else
	cout << setprecision(20);

	solve();
#endif

	return 0;
}


Measured memory_bytes: 768
package main

import "fmt"

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func main() {
	var a, b, c, d int
	fmt.Scan(&a, &b, &c, &d)
	if abs(c-a) <= d || (abs(b-a) <= d && abs(c-b) <= d) {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include <iostream>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
using ll = long long;

using namespace std;



int main() {
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;
    if(a1 + a2 + a3 >= 22) puts("bust");
    else puts("win");

    return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>
int main(){
    int i,t,a;
    scanf("%d",&a);
    t = a / 100;
    if(t == 0){
        printf("ai1333\n");
    } else printf("ai1333");
    for(i=0;i < t;i++){
        if(i == t - 1){
            printf("%d\n",3);
        } else {
            printf("%d",3);
        }
    }
    return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <cstdlib>
#include <string>
#include <typeinfo>
#include <cstring>
#include <iostream>
using namespace std;
#define MAX 100000
struct Node{int key;
Node *right, *left, *parent;};
Node *root, *NIL;

int parent(int i){return i/2;}
int left(int i){return 2*i;}
int right(int i){return 2*i+1;}


int main(){
    int n,i,A[MAX+1];
    
    cin >> n;
    
    for(i = 1; i <= n; i++)cin >> A[i];
    for(i = 1;i <= n; i++){
        cout << "node " << i << ": key = " << A[i] << ", ";
        if(parent(i) >= 1)cout << "parent key = " << A[parent(i)] << ", ";
        if(left(i) <= n)cout << "left key = " << A[left(i)] << ", ";
        if(right(i) <= n)cout <<"right key = "<< A[right(i)] <<", ";
        cout << endl;
    }
    return 0;
}






Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
int main()
{
	std::vector<int> a(3);
	cin >>a[0]>>a[1]>>a[2];
	sort(a.begin(),a.end());
	cout<<abs(a[1]-a[0])+abs(a[2]-a[1])<<endl;
	
	
    
    return 0;
}


Measured memory_bytes: 256
#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 rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const ll INF = 1e18;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N, M;
    cin >> N >> M;
    string yes = "Yes", no = "No";
    vector<int> edge[N+1];
    rep(i, M){
        int a, b;
        cin >> a >> b;
        edge[a].push_back(b), edge[b].push_back(a);
    }
    vector<int> node;
    bool eng = false;
    rep2(i, 1, N){
        if(edge[i].size()%2 == 1){cout << no << endl; exit(0);}
        elif(edge[i].size() == 4) node.push_back(i);
        elif(edge[i].size() >= 6) eng = true;
    }
    if(eng){cout << yes << endl; exit(0);}
    int n = node.size();
    if(n >= 3) cout << yes << endl;
    elif(n <= 1) cout << no << endl;
    else{
        int cnt = 0;
        int p = node[0], q = node[1];
        rep(i, 4){
            int pre = p, pos = edge[p][i];
            while(edge[pos].size() == 2){
                rep(j, 2){
                    if(edge[pos][j] != pre){
                        pre = pos, pos = edge[pos][j];
                        break;
                    }
                }
            }
            if(pos == q) cnt++;
        }
        if(cnt == 2) cout << yes << endl;
        else cout << no << endl;
    } 
}

Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
const int maxn=210;
int n,a[maxn][maxn];
vector<int> ver[maxn];
int flag[maxn];
inline void dfs(int x,int v)
{
	if(v==1) v=2;else v=1;
	if(flag[x]){if(flag[x]!=v){puts("-1");exit(0);}return;}
	flag[x]=v;
	for(int i=0;i<(int)ver[x].size();i++) dfs(ver[x][i],v);
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) a[i][j]=i==j?0:(n+1);
	for(int i=1;i<=n;i++) for(int j=1;j<=n;j++)
	{
		char c;cin>>c;if(i==j) continue;
		if(c=='1') a[i][j]=1,ver[i].push_back(j),ver[j].push_back(i);
	}
	dfs(1,0);
	for(int k=1;k<=n;k++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) a[i][j]=min(a[i][j],a[i][k]+a[k][j]);
	int ans=0;
	for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) ans=max(ans,a[i][j]+1);
	cout<<ans<<endl;
}

Measured memory_bytes: 4140
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>

using namespace std;

int main() {
  int x, n,p[200];
  cin >> x >> n;  
  for(int i = 0; i < n; i++)
    cin >> p[i];
  
  if(n == 0) {
    cout << x << endl;
    return 0;
  }

  bool flags = 0, flagt = 0;
  for(int i = 0; ; i++) {
    int s = x - i;
    int t = x + i;
    for(int j = 0; j < n; j++) {
      if(s == p[j]) {
        flags = 0; break;
      } else flags = 1;
    }
    for(int j = 0; j < n; j++) {
      if(t == p[j]) {
        flagt = 0; break;
      } else flagt = 1;
    }
    if(flags == 1) {
      cout << s << endl; return 0;
    }
    else if(flagt == 1) {
      cout << t << endl; return 0;
    }
  }
}

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

main(){
 	int k,n;
  	cin >> k >> n;
 	int a[n+1];
  	
  	for(int i=0;i<n;i++)
      	cin >> a[i];
  		
  	a[n] = k+a[0];
  	int tot_d = 0, max_dist = 0; 
  	for(int i = 1;i<n+1;i++){
      tot_d += a[i]-a[i-1];
      if( a[i]-a[i-1] > max_dist)
        	max_dist = a[i]-a[i-1];
     }
  
  	cout << tot_d-max_dist << endl;
  	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int A[32] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
int K;

int main() {
	cin >> K;
	cout << A[K - 1] << endl;
	return 0;
}

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

int main(){
    int a, b;
    string op;
    while(true){
        cin >> a;
        cin >> op;
        if(op != "?"){
            cin >> b;
        if(op == "+"){
            cout << a + b << endl;
        }else if(op == "-"){
            cout << a - b << endl;
        }else if(op == "*"){
            cout << a * b << endl;
        }else if(op == "/"){
            cout << a / b << endl;
        }
        }else{
            break;
        }
    }
return 0;
}
    

Measured memory_bytes: 3164
def main():
  import sys
  input = sys.stdin.readline
  
  X, Y, Z, K = map(int,input().split())
  A = list(map(int,input().split()))
  B = list(map(int,input().split()))
  C = list(map(int,input().split()))
  A.sort(reverse = True)
  B.sort(reverse = True)
  C.sort(reverse = True)
  res = []
  for i in range(X):
    for j in range(Y):
      for k in range(Z):
        if (i+1)*(j+1)*(k+1) <= K:
          res.append(A[i]+B[j]+C[k])
        else:
          break
  res.sort(reverse = True)
  for r in res[:K]:
    print(r)

if __name__ == "__main__":
  main()

Measured memory_bytes: 8708
#include <cstdio>

using namespace std;

const char* arr[20];

int n;

char ans[1005][1005];
int curpos = 1;

void place(int siz)
{
    for (int row = 0; row < siz; row++) {
        for (int col = 0; col < siz; col++){
            ans[curpos+row][curpos+col] = arr[siz][row*siz+col];
        }
    }
    curpos += siz;
}

int main()
{
    arr[3] = ".aa"
             "b.."
             "b..";
    arr[4] = "aabc"
             "ddbc"
             "efgg"
             "efhh";
    arr[5] = "aabbc"
             "dde.c"
             "f.egg"
             "fh..i"
             ".hjji";
    arr[6] = "aabc.."
             "..bcdd"
             "eefg.."
             "..fghh"
             "iijk.."
             "..jkll";
    arr[7] = ".aabbcc"
             "d.ee.ff"
             "dg..h.."
             "ig..h.."
             "i.jj.kk"
             "lm..n.."
             "lm..n..";
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) ans[i][j] = '.';
    }
    if (n == 2) {
        printf("-1"); return 0;
    }
    if (n <= 7) {
        place(n);
    } else if (n == 8) {
        place(4); place(4);
    } else if (n == 9) {
        place(3); place(3); place(3);
    } else if (n == 10) {
        place(5); place(5);
    } else if (n == 11) {
        place(4); place(7);
    } else {
        for (int fcnt = 0; fcnt <= n / 4; fcnt++) {
            if ((n - fcnt * 4) % 5) continue;
            for (int i = 1; i <= fcnt; i++) place(4);
            for (int i = 1; i <= (n - fcnt * 4) / 5; i++) place(5);
            break;
        }
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            printf("%c", ans[i][j]);
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 2176
#include <stdio.h>
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DPL_1_D
//LIS
//got TLE with O(n*n)
/*int findNumberOfLIS(int nums[],int n) {
        int l = n;
        int lis[l];
        for(int i= 0; i<l; i++){//as the last one
            lis[i] = 1;//for 1
            for(int j = 0; j<i; j++){
                if(nums[i]>nums[j]&&lis[j]>=lis[i]){
                    lis[i] = lis[j]+1; 
                }
            }   
        }
        int res = 0;
        for(int i =0; i<l; i++){
            if(lis[i]>res)
                res = lis[i];
            
        }
        return res;  
    }*/
    
//search longest increasing sequence (geek for geek)
//binary search to find the first ele bigger than key
//return index of the ele    
int ceilindex(int sec_array[],int l,int r,int key){
	while(r-l>1){
		int m = l+(r-l)/2;
		if(sec_array[m]>=key)
			r = m;
		else l = m;
	}
	return r;
}
int findNumberOfLIS(int nums[],int n){
	int sec_array[n];
	int len;
	sec_array[0] = nums[0];
	len = 1;
	for(int i  =1; i<n; i++){
		if(nums[i]<sec_array[0])
			sec_array[0] = nums[i];
		else if(nums[i]>sec_array[len-1])
			sec_array[len++] = nums[i];
		else {
			sec_array[ceilindex(sec_array,-1,len-1,nums[i])] = nums[i];
		}
	}
	//the sec_array is not LIS: smallest elements
	/*for(int i = 0; i<len; i++){
		printf("%d ",sec_array[i]);
	}
	printf("\n");*/
	return len;
} 

int main(){
	int n;
	scanf("%d",&n);
	int nums[n];
	for(int i = 0; i<n; i++){
		scanf("%d",&nums[i]);
	}
	printf("%d\n",findNumberOfLIS(nums,n));
	return 0;
}


Measured memory_bytes: 3348
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
string a,b;
int main(){
    cin>>a;
    b=a;
    reverse(a.begin(),a.end());
    for(int i=0;i<a.size();++i)
    {
        if(a[i]=='b'){
        	a[i]='d';
		} 
        else if(a[i]=='d'){
        	a[i]='b';
		} 
        else if(a[i]=='p'){
        	a[i]='q';
		} 
        else if(a[i]=='q'){
        	a[i]='p';
		}
    }
    if(a==b){
    	cout<<"Yes";
    	return 0;
	}
    cout<<"No";
}

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

int main(){
	int x, y;
	cin >> x >> y;
	vector<int> a(12);
	a.at(0) = 0;
	a.at(2) = 0;
	a.at(4) = 0;
	a.at(6) = 0;
	a.at(7) = 0;
	a.at(9) = 0;
	a.at(11) = 0;
	a.at(3) = 1;
	a.at(5) = 1;
	a.at(8) = 1;
	a.at(10) = 1;
	a.at(1) = 2;
	if(a.at(x-1) == a.at(y-1)){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 998244353;
ll dp[3005][3005][3];
int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	int n, k;
	cin >> n >> k;
	int a[n];
	for(int i = 0; i < n; i ++) cin >> a[i];
	dp[0][0][0] = 1;
	for(int i = 0; i < n; i ++) {
		for(int j = 0; j <= k; j ++) {
			dp[i + 1][j][0] = (dp[i + 1][j][0] + dp[i][j][0]) % MOD;
			dp[i + 1][j][1] = (dp[i + 1][j][1] + dp[i][j][0] + dp[i][j][1]) % MOD;
			dp[i + 1][j][2] = (dp[i + 1][j][2] + dp[i][j][0] + dp[i][j][1] + dp[i][j][2]) % MOD;
			if(j + a[i] <= k) {
				dp[i + 1][j + a[i]][1] = (dp[i + 1][j + a[i]][1] + dp[i][j][0] + dp[i][j][1]) % MOD;
				dp[i + 1][j + a[i]][2] = (dp[i + 1][j + a[i]][2] + dp[i][j][0] + dp[i][j][1]) % MOD;
			}
		}
	}
	cout << dp[n][k][2];
	return 0;
}


Measured memory_bytes: 211712
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
    int N;
    string S;
    cin >> N >> S;
    vector<int> num(N);
    for(int i=0; i<N; i++) {
        num.at(i) = S.at(i) - '0';
    }

    vector<int> first(10);
    for(int i=0; i<10; i++) {
        first.at(i) = distance(num.begin(),find(num.begin(), num.end(), i));
    }
    reverse(num.begin(), num.end());
    vector<int> last(10);
    for(int i=0; i<10; i++) {
        last.at(i) = N-1 - distance(num.begin(),find(num.begin(), num.end(), i));
    }
    reverse(num.begin(), num.end());

    int ans = 0;
    for(int i=0; i<10; i++) {
        for(int j=0; j<10; j++) {
            if(first.at(i) < last.at(j)) {
                int tmp = distance(num.begin(), find(num.begin() + first.at(i) + 1, num.end(), j));
                if(last.at(0) > tmp) ans++;
                if(last.at(1) > tmp) ans++;
                if(last.at(2) > tmp) ans++;
                if(last.at(3) > tmp) ans++;
                if(last.at(4) > tmp) ans++;
                if(last.at(5) > tmp) ans++;
                if(last.at(6) > tmp) ans++;
                if(last.at(7) > tmp) ans++;
                if(last.at(8) > tmp) ans++;
                if(last.at(9) > tmp) ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
using namespace std;
string a,b,c;
int main(){
    cin>>a>>b>>c;
    cout<<a[0]<<b[0]<<c[0]<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define all(x) begin((x)), end((x))
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}


int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,q;cin>>n>>m>>q;
    vector<ll> a(q),b(q),c(q),d(q);
    rep(i,q) {
        cin>>a[i]>>b[i]>>c[i]>>d[i];
        a[i]--;b[i]--;
    }
    ll res = 0;
    function<void(string)> solve = [&] (string s) {
        if (s.size()==n) {
            ll sum = 0;
            rep(i,q) {
                if (s[b[i]] - s[a[i]] == c[i]) {
                    sum += d[i];
                }
            }
            chmax(res, sum);
            return;
        }
        ll num;
        if (s.size()==0) {
            num = 1;
        } else {
            num = s[s.size()-1] - '0';
        }
        repr(i,num,m+1) {
            string tmp = s;
            tmp += (i+'0');
            solve(tmp);
        }
    };
    solve("");
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,n) for(int i=(a); i<(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
void print() { cout << endl; }
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) { cout << head; if (sizeof...(tail) != 0) cout << " "; print(forward<Tail>(tail)...); }
template <class T> void print(vector<T> &vec) { for (auto& a : vec) { cout << a; if (&a != &vec.back()) cout << " "; } cout << endl; }
template <class T> void print(vector<vector<T>> &df) { for (auto& vec : df) { print(vec); } }
const int INF = 1e9;
const int MOD = 1e9+7;

// dp[i番目の魔法][与えた総ダメージ] = (min) 消費MP
// dp[i+1][j] = min(dp[i+1][j], dp[i][j]) ★
// i番目の魔法を使う場合、dp[i+1][j] = dp[i+1][j], dp[i+1][j-Ai]+Bi
// ※ dp[i][j-Ai]+Bi からの遷移は、★の遷移で拾われているので見なくて良い

int dp[1010][20010];
int damage[10010];
int mp[10010];

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

	int H, N; cin >> H >> N;
	rep(i, N) cin >> damage[i] >> mp[i];

	rep(i, 1010) rep(j, 20010) dp[i][j] = INF;
	dp[0][0] = 0;

	int max_damage = *max_element(damage, damage+N);
	// rep(i, N) if (damage[i]>max_damage) max_damage = damage[i];

	rep(i, N) rep(j, H+max_damage+1) {
		int a = damage[i];
		int b = mp[i];
		dp[i+1][j] = min(dp[i][j], dp[i+1][j]);
		if (j>=a) dp[i+1][j] = min(dp[i+1][j-a]+b, dp[i+1][j]);
	}

	int ans = INF;
	FOR(i, H, H+max_damage+1) ans = min(ans, dp[N][i]);

	cout << ans << endl;

	// FOR(i, 9990, 10010) print(i, dp[N][i]);
}

Measured memory_bytes: 79232
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;
int main(){
  int a,p; cin >> a >> p;
  cout << (a*3 + p)/2 << endl;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
using namespace std;
typedef long long ll;

const int MAXN = 100055;

ll dp[MAXN], du[MAXN], dl[MAXN], dr[MAXN];
int prt[MAXN];

vector<int> G[MAXN];

int N, MOD;

void f(int i) {
	if(prt[i]) G[i].erase(find(allv(G[i]), prt[i]));
	dp[i] = 1;
	for(int j = 0, n = sz(G[i]), v; j < n; j++) {
		v = G[i][j];
		prt[v] = i;
		f(v);
		dl[v] = (dp[v] + 1) % MOD;
		if(j) dl[v] = dl[v] * dl[G[i][j-1]] % MOD;
	}
	for(int n = sz(G[i]), j = n, v; j--;) {
		v = G[i][j];
		dr[v] = (dp[v] + 1) % MOD;
		if(j+1 < n) dr[v] = dr[v] * dr[G[i][j+1]] % MOD;
	}
	if(!G[i].empty()) dp[i] = dl[G[i].back()];
}

void g(int i) {
	for(int j = 0, n = sz(G[i]), v; j < n; j++) {
		v = G[i][j];
		du[v] = du[i];
		if(j) du[v] = du[v] * dl[G[i][j-1]] % MOD;
		if(j+1 < n) du[v] = du[v] * dr[G[i][j+1]] % MOD;
		du[v] = (du[v] + 1) % MOD;
		g(v);
	}
}

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

	cin >> N >> MOD;
	for(int i = 1, a, b; i < N; i++) {
		cin >> a >> b;
		G[a].eb(b);
		G[b].eb(a);
	}

	du[1] = 1;
	f(1); g(1);

	for(int i = 1; i <= N; i++)
		printf("%lld\n", dp[i] * du[i] % MOD);
	return 0;
}

Measured memory_bytes: 15744
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
set<string> c;
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
int main(){
    int n;
    cin>>n;
    vector<ll> a(n,0),sum(n+1,0);
    for(int i=0;i<n;i++)cin>>a.at(i);
    sort(all(a));
    for(int i=0;i<n;i++)sum.at(i+1)=sum.at(i)+a.at(i);
    ll ans=1;
   for(int i=n-1;i>=1;i--){
       if(a.at(i)<=sum.at(i)*2)ans++;
       else break;
   }
   cout<<ans<<endl;
}


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

int main(){
    int n,m,q;
    std::cin >> n >> m >> q;
    std::vector<int> a(q),b(q),c(q),d(q);
    for(int i = 0;i < q;i++){
        std::cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
        a.at(i)--;
        b.at(i)--;
    }
    std::vector<int> vec(n+m-1,1);
    for(int i= 0;i < m-1;i++)vec.at(i) = 0;
    int ans = 0;
    do{
        std::vector<int> A(10);
        int i = 0;
        int val = 1;
        for(const auto& flag:vec){
            if(flag == 1){
                A.at(i) = val;
                i++;
            }
            else val++;
        }
        int cnt = 0;
        for(int j = 0;j < q;j++){
            if(A.at(b.at(j)) - A.at(a.at(j)) == c.at(j))cnt += d.at(j);
        }
        ans = std::max(ans,cnt);
    } while (std::next_permutation(vec.begin(),vec.end()));
    std::cout << ans << std::endl;
}


Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<unordered_map>
#define mod 1000000007
using namespace std;
typedef long long ll;
bool chmax(ll &a,ll b){
    if(a>b)return 0;
    a=b; return 1;
}
bool chmin(ll &a,ll b){
    if(a<b)return 0;
    a=b; return 1;
}
#define mad(a,b) a=(a+b)%mod
#define mul(a,b) a=a*b%mod

ll po(ll x,ll y){
    ll res=1;
    for(;y;y>>=1){
	if(y&1)res*=x;
	x*=x;
    }
    return res;
}
ll pomod(ll x,ll y){
    ll res=1;
    for(;y;y>>=1){
	if(y&1)mul(res,x);
	mul(x,x);
    }
    return res;
}
unordered_map<ll,ll> mas[66];
ll f(ll n,ll k){
    if(mas[k].find(n)!=mas[k].end())return mas[k][n];
    if(n<0)return 0;
    if(k==0)return min(n,2LL)+1;
    if(po(2,k+2)<=n)return pomod(3,k+1);
    ll res=0;
    mad(res,f(n,k-1));
    mad(res,f(n-po(2,k),k-1));
    mad(res,f(n-po(2,k+1),k-1));
    mas[k][n]=res;
    return res;
}
int main(){
    ll n;
    cin>>n;
    cout<<f(n,60)<<endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  int no_of_input,minimum;
  int ans = 0;
  int input;
  cin >> no_of_input >> minimum;
  for(int i=0;i<no_of_input;i++){
    cin >> input;
    ans += (input>=minimum);
  }
  cout << ans;
}

Measured memory_bytes: 256
import sys
import itertools

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, K = lr()
XY = [lr() for _ in range(N)]
XY.sort()
answer = float('inf')
# 端の4点、まずはx軸の2点を選ぶ
for i, j in itertools.combinations(range(N), 2):
    xleft = XY[i][0]
    xright = XY[j][0]
    candidate = sorted(XY[i:j+1], key=lambda xy: xy[1])
    if len(candidate) < K:
        continue
    for s in range(len(candidate) - K + 1):
        yup = candidate[s+K-1][1]
        ylow = candidate[s][1]
        area = (xright - xleft) * (yup - ylow)
        if area < answer:
            answer = area

print(answer)
# 31


Measured memory_bytes: 3064
import java.io.*;
import java.util.*;
import java.text.NumberFormat;

class Main{
	public static void main(String[] args) throws IOException{
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
		String s=" ";
		StringTokenizer st;
		NumberFormat formatter = NumberFormat.getNumberInstance();
		formatter.setMaximumFractionDigits(3);
		formatter.setMinimumFractionDigits(3);
		double a,b,c,d,e,f,x,y;
		try {
			for(;s!=null;){
				s = r.readLine();
				st = new StringTokenizer(s," ");
				a = Double.parseDouble(st.nextToken().toString());
				b = Double.parseDouble(st.nextToken().toString());
				c = Double.parseDouble(st.nextToken().toString());
				d = Double.parseDouble(st.nextToken().toString());
				e = Double.parseDouble(st.nextToken().toString());
				f = Double.parseDouble(st.nextToken().toString());
				x = (double)(b*f-c*e)/(b*d-a*e);
				y = (double)(a*f-c*d)/(a*e-b*d);
				if(x<=0.0&&x>-0.0009)x=(double)0;
				if(y<=0.0&&y>-0.0009)y=(double)0;
				System.out.println(formatter.format(x)+" "+formatter.format(y));
			}
		} catch (NoSuchElementException err) {
			System.exit(0);
		}
	}
}

Measured memory_bytes: 11000
/*
Atcoder ABC177E
*/
#include <bits/stdc++.h>
using namespace std;

#define int long long

int n,a[1000005];
bool apr[1000005];

signed main()
{
	cin>>n;
	for(int i=1;i<=n;cin>>a[i++]);
	int gcd=a[1];
	for(int i=2;i<=n;i++)
		gcd = __gcd(gcd,a[i]);
	for(int i=1;i<=n;i++)
	{
		int tmp=a[i];
		for(int j=2;j*j<=a[i];j++)
			if(tmp%j==0)
			{
				if(apr[j])
					return cout<<(gcd==1 ? "setwise coprime\n" : "not coprime\n"), 0;
				while(tmp%j==0)
					tmp /= j;
				apr[j] = 1;
			}
		if(tmp>1)
		{
			if(apr[tmp])
				return cout<<(gcd==1 ? "setwise coprime\n" : "not coprime\n"), 0;
			apr[tmp] = 1;
		}
	}
	puts("pairwise coprime");
	
	return 0;
}

Measured memory_bytes: 11412
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e3 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int n;
	cin >> n;
	if (n & 1) n <<= 1;
	cout << n << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <math.h>
using namespace std;

int main() {

	int N;
	cin >> N;

	string S, T;
	cin >> S;
	cin >> T;

	string ans;

	for (int i = 0; i < N; i++) {
		ans += S[i];
		ans += T[i];
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()

lim = 55555
prime = [1]*(lim+1)
prime[0] = 0
prime[1] = 0

for i in range(lim+1):
	if prime[i] == 1:
		for j in range(2, lim//i + 1):
			prime[i*j] = 0

p = [i for i in range(lim+1) if prime[i]]

ans = [x for x in p if x%5 == 2]
print(*ans[:N])

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

int main()
{
  double W , H , x , y  ;
  cin >> W >> H >> x >> y  ;

  cout << W*H/2 << " " ;

  if( H/2 == y && W/2 == x){cout << 1;}
  else{cout << 0;}
  return 0 ;
}

Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int coin[] = {1, 5, 10, 50, 100, 500};
    int INF = INT_MAX / 2;

    for(;;){
        int p;
        cin >> p;
        if(p == 0)
            return 0;

        vector<int> n(6);
        for(int i=0; i<6; ++i)
            cin >> n[i];

        int ret = 0;
        for(int i=5; i>=0; --i){
            while(p >= 500 && n[i] > 0){
                p -= coin[i];
                -- n[i];
                ++ ret;
            }
        }

        vector<int> dp(601, INF);
        dp[0] = 0;
        for(int i=0; i<6; ++i){
            for(int j=600; j>=1; --j){
                for(int k=1; k<=n[i]; ++k){
                    if(j-k*coin[i] < 0)
                        break;
                    dp[j] = min(dp[j], dp[j-k*coin[i]] + k);
                }
            }
        }

        int ret2 = INF;
        for(int i=p; i<=600; ++i){
            if(dp[i] == INF)
                continue;
            int a = i - p;
            int b = 0;
            for(int i=5; i>=0; --i){
                b += a / coin[i];
                a %= coin[i];
            }
            ret2 = min(ret2, dp[i] + b);
        }

        ret += ret2;
        cout << ret << endl;
    }
}

Measured memory_bytes: 908
a = readline.to_i
b = readline.to_i
c = readline.to_i
x = readline.to_i

r = 0

0.upto(a).each do |i|
  0.upto(b).each do |j|
    0.upto(c).each do |k|
      r += 1 if i * 500 + j * 100 + k * 50 == x
    end
  end
end

puts r


Measured memory_bytes: 1916
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include<iomanip>
using namespace std;
using P = pair<int, int>;

int N, D, A;
map<int, int> xh;
int X[200010], H[200010];
int rightX[200010];
int bomb[200010];

int main()
{
	cin >> N >> D >> A;
	for (int i = 0; i < N; i++) {
		int x, h;
		cin >> x >> h;
		xh[x] = h;
	}
	int count = 0;
	for (auto itr = xh.begin(); itr != xh.end(); itr++) {
		X[count] = itr->first;
		H[count] = itr->second;
		count++;
	}
	int rightx = 0;
	for (int i = 0; i < N; i++) {
		for (rightx; rightx <= N; rightx++) {
			if (X[rightx] - X[i] > 2 * D || rightx == N) {
				rightX[i] = rightx-1;
				break;
			}
		}
	}
	long long int ans = 0;
	int bombcount = 0;
	for (int i = 0; i < N; i++) {
		bombcount += bomb[i];
		if (bombcount * A < H[i]) {
			int count = (int)(H[i] - bombcount * A) / A + 1;
			if ((H[i] - bombcount * A) % A == 0) count--;
			ans += count;
			bombcount += count;
			bomb[rightX[i]+1] -= count;
		}
	}
	cout << ans << endl;\
}

Measured memory_bytes: 12800
h, w = map(int, input().split())
s = []
for i in range(h):
    si = list(input())
    s.append(si)

ans = True
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            u_r_d_l = [(-1, 0), (0, 1), (1, 0), (0, -1)]
            if i == 0:
                u_r_d_l[0] = (0, 0)
            if i == h - 1:
                u_r_d_l[2] = (0, 0)
            if j == 0:
                u_r_d_l[3] = (0, 0)
            if j == w - 1:
                u_r_d_l[1] = (0, 0)
            for k in u_r_d_l:
                if k != (0, 0):
                    if s[i + k[0]][j + k[1]] == "#":
                        # ans = True
                        break
            else:
                ans = False


if ans:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 9228
#include<bits/stdc++.h>
#define sz 100002
#define pb push_back
#define ff first
#define ss second
#define ll long long
#define VEC(n)  int x; vector<ll int>v;for(int i=0;i<n;i++){cin>>x;v.pb(x);}
#define TEST() int test;cin>>test; while(test--)
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;

//ll int LCM(ll int a,ll int b) { ll int gcd=__gcd(a,b);ll int lcm=a*b/gcd;return lcm;}
//ll int bigmod(ll int b, ll int p, ll int m){if(p==0)return 1;if(p%2!=0) return b%m*fun(b,p-1,m)%m;if(p%2==0){ ll int res=fun(b,p/2,m);return (res%m*res%m)%m;}}
//void seive() { prime[np++]=2;for(i=3; i<=sz; i+=2){if(mark[i]==0){ prime[np++]=i;for(j=i*i; j<=sz; j+=i) mark[j]=1; } }}
//string add(string s1,string s2) {string s;int j=s1.size()-1,c=0,m; for(int i=s2.size()-1; i>=0; i--) {if(j>=0)m=s2[i]-'0'+s1[j]-'0'+c;else m=s2[i]-'0'+c; if(m>9) { s+=m%10+'0';c=m/10; } else {  c=0;s+=m+'0'; }j--; } if(c!=0) {s+=c+'0'; }reverse(s.begin(),s.end());return s;}
//int pos;string mul(int n) {string s;for(int i=0; i<pos; i++) { s+="0"; }pos++;int c=0,m; for(int i=s1.size()-1; i>=0; i--) { m=(s1[i]-'0')*n+c;if(m>9) { s+=m%10+'0';c=m/10;} else { c=0; s+=m+'0';} }while(c!=0) { s+=c%10+'0';c=c/10;}    reverse(s.begin(),s.end());return s;}

int main()
{
    FAST();
    ll int n;
    cin>>n;
    vector<ll int>v;
    int x,a=0;
   for(int i=0;i<n;i++)
   {
       cin>>x;
       a=a^x;
       v.pb(x);
   }
   for(int i=0;i<n;i++)
   {
       cout<<(a^v[i])<<" ";
   }
}
//LayCurse




Measured memory_bytes: 5312
#include <iostream>

using namespace std;

int main() {
  double a = 0, b = 0;
  int n, m; cin >> n >> m;
  double t = 1;
  for (int i = 0; i < m; ++i) {
    t /= 2;
  }
  double f = 1 - t;
  int cnt = 1;
  do {
    b = a;
    double x = t;
    for (int i = 1; i < cnt; ++i) {
      x *= f;
    }
    a += (1900 * m + (n - m) * 100) * cnt * x;
    cnt ++;
  } while (a - b > 0.001);
  cout << a << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;
#define MAXN 101010
using namespace std;
 
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(0); 
 
	int n , k;
	cin >> n >> k;
	
	vector<pii> v(n);
	ll ans = 0;
	ll ans1 = 0;
	rep(i , n){
		cin >> v[i].fi >> v[i].se;
	/*	repn(j , 32){
			if((k & (1 << j)) && (v[i].fi & (1 << j))){
				break;
			}else if(k & (1 << j)){
				ans1 += v[i].se;
			}else if(v[i].fi & (1 << j)){
				break;
			}
		}*/
	}
	
	int p = -1;
	repn(i , 32){
		if(k & (1 << i)){
			p = i;
			break;
		}
	}
	
	if(p == -1){
		ll ans = 0;
		rep(i , n){
			if(v[i].fi == 0)ans += v[i].se;
		}
		dier(ans);
	}
	//cout << "p=" << p << nl;
	repn(i , 32){
		if(k & (1 << i)){
			ll cur = 0;
			int lim = 0;
			rep(j , 32){
				if(j > i){
					if(k & (1 << j)){
						lim |= 1 << j;
					}
				}else if(j < i){
					lim |= 1 << j;
				}
			}
			rep(j , n){
				int x = v[j].fi;
				if((lim | x) == lim)
					cur += v[j].se;
			}
		//	cout << nl;
			ans = max(ans , cur);
		}
	}
	
	ll ans2 = 0;
	rep(i , n){
		if((k | v[i].fi) == k)ans2 += v[i].se;
	}
	ans = max(ans , ans2);
		
 
	cout << max(ans , ans1) << nl;
 
	return 0;
}

Measured memory_bytes: 1024
n=int(input())
A=list(map(int,input().split()))

from bisect import bisect
cums=[0]
for a in A:
    cums.append(cums[-1]+a)

lmn=[]
lmx=[]
for i in range(2,n-1):
    j=bisect(cums,cums[i]//2)
    a1,b1=cums[j],cums[i]-cums[j]
    a2,b2=cums[j-1],cums[i]-cums[j-1]
    if abs(a1-b1)<abs(a2-b2):
        lmn.append(min(a1,b1))
        lmx.append(max(a1,b1))
    else:
        lmn.append(min(a2,b2))
        lmx.append(max(a2,b2))
A.reverse()
cums=[0]
for a in A:
    cums.append(cums[-1]+a)

rmn=[]
rmx=[]
for i in range(2,n-1):
    j=bisect(cums,cums[i]//2)
    a1,b1=cums[j],cums[i]-cums[j]
    a2,b2=cums[j-1],cums[i]-cums[j-1]
    if abs(a1-b1)<abs(a2-b2):
        rmn.append(min(a1,b1))
        rmx.append(max(a1,b1))
    else:
        rmn.append(min(a2,b2))
        rmx.append(max(a2,b2))
rmn.reverse()
rmx.reverse()
ans=float('inf')
for ln,lx,rn,rx in zip(lmn,lmx,rmn,rmx):
    d=max(lx,rx)-min(ln,rn)
    ans=min(ans,d)
print(ans)




Measured memory_bytes: 42932
from itertools import takewhile

H, W = map(int, input().split())
S = [input() for _ in range(H)]

x = [[0 for _ in range(W)] for _ in range(H)]
y = [[0 for _ in range(W)] for _ in range(H)]

for i, j in ((i, j) for i in range(H) for j in range(W) if S[i][j] == '.'):
    if x[i][j] == 0:
        w = len(list(takewhile(lambda k: S[i][k] == '.', range(j, W))))
        for k in range(j, j + w):
            x[i][k] = w
    if y[i][j] == 0:
        h = len(list(takewhile(lambda k: S[k][j] == '.', range(i, H))))
        for l in range(i, i + h):
            y[l][j] = h

ans = max(
    x[i][j] + y[i][j] - 1
    for i in range(H)
    for j in range(W)
)
# 出力
print(ans)

Measured memory_bytes: 128472
#include <iostream>

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

int main(void){
    int n, m, l; scanf("%d%d%d", &n, &m, &l);
    long long int A[n][m], B[m][l], C[n][l];
    rep(i, n) rep(j, m) scanf("%lld", &A[i][j]);
    rep(i, m) rep(j, l) scanf("%lld", &B[i][j]);
    rep(i, n) rep(j, l) C[i][j] = 0;
    rep(i, n) rep(k, m) rep(j, l){
        C[i][j] += A[i][k] * B[k][j];
    }
    rep(i, n) rep(j, l){printf("%lld", C[i][j]); putchar(j == l-1 ? '\n' : ' ');}
    return 0;
}


Measured memory_bytes: 3408
function Main(input){
	var S = input.trim();
  	var W_MAX = 3;
  	var b = true;
  	if(S[0] === S[1] && S[0] === S[2])b=false;
  	var result = b?"Yes":"No";
  	console.log(result);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define mp make_pair
#define pb emplace_back
#define x first
#define y second
#define sz(a) ((int)(a).size())
#define rep(i,begin,end) for(__typeof(end) i = (begin)-((begin)>(end)); i != (end)-((begin)>(end)); i += 1-2*((begin)>(end)))
#define clr(a,v) memset(a, v, sizeof(a))
#define all(a) (a).begin(),(a).end()
#define EPS 1e-8
#define fcin ios_base::sync_with_stdio(false)
#define db(x) cerr << #x << " == " << x << endl
#define _ << " " <<
#define MAXN 101010
#define LOGN 20
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;

bitset<16160> pos;

bool solve(vi & vet, int v){
	if(v >= 8080) return 0;
	pos.reset();
	pos[8080] = 1;
	rep(i,0,sz(vet))
		pos = (pos<<vet[i])|(pos>>vet[i]);
	return pos[v+8080];
}

int x, y, ini, n;
vi vet[2];
char s[8080];

int main(){
	scanf("%s%d%d", s, &x, &y);
	n = strlen(s);
	while(ini < n && s[ini] == 'F')
		x--, ini++;
	int d = 0, t = 0;
	rep(i,ini,n){
		if(s[i] == 'F') t++;
		else{
			if(t) vet[d].pb(t);
			t=0, d^=1;
		}
	}
	if(t) vet[d].pb(t);
	if(solve(vet[0],abs(x)) && solve(vet[1],abs(y))) puts("Yes");
	else puts("No");
}



Measured memory_bytes: 256