akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
using P = pair<int, int>; 
using ll = long long;

int main()
{
  int a, b;
  cin >> a >> b;
  if(a > b){
    cout << "safe" << endl;
  }
else {
  cout << "unsafe" << endl;
}
  return 0;
}


Measured memory_bytes: 3620
#include <cstdio>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <iterator>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long;
using ULL = unsigned long long;

int main() {
    string s; cin >> s;

    int ans = 0;
    if (s == "SUN") {
        ans = 7;
    } else if (s == "MON") {
        ans = 6;
    } else if (s == "TUE") {
        ans = 5;
    } else if (s == "WED") {
        ans = 4;
    } else if (s == "THU") {
        ans = 3;
    } else if (s == "FRI") {
        ans = 2;
    } else if (s == "SAT") {
        ans = 1;
    }
    cout << ans << endl;
}


Measured memory_bytes: 760
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct Chien{
  int n;
  vector<int> dat,laz;
  const int def=0;
  Chien(){}
  Chien(int n_){init(n_);}
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.clear();
    dat.resize(2*n-1,def);
    laz.clear();
    laz.resize(2*n-1,0);
  }
  inline void eval(int len,int k){
    if(k*2+1<n*2-1){
      laz[k*2+1]+=laz[k];
      laz[k*2+2]+=laz[k];
    }
    dat[k]+=laz[k]*len;
    laz[k]=0;
  }
  int update(int a,int b,int x,int k,int l,int r){
    eval(r-l,k);
    if(r<=a||b<=l) return dat[k]+laz[k]*(r-l);
    if(a<=l&&r<=b) return dat[k]+(laz[k]+=x)*(r-l);
    eval(r-l,k);
    return dat[k]=update(a,b,x,k*2+1,l,(l+r)/2)+update(a,b,x,k*2+2,(l+r)/2,r);
  }
  int query(int a,int b,int k,int l,int r){
    eval(r-l,k);
    if(r<=a||b<=l) return def;
    if(a<=l&&r<=b) return dat[k];
    int vl=query(a,b,k*2+1,l,(l+r)/2);
    int vr=query(a,b,k*2+2,(l+r)/2,r);
    return vl+vr;
  }
  int update(int a,int b,int x){
    return update(a,b,x,0,0,n);
  }
  int query(int a,int b){
    return query(a,b,0,0,n);
  }
};
signed main(){
  int n,q;
  cin>>n>>q;
  Chien ch(n);
  for(int i=0;i<q;i++){
    int c,s,t,x;
    cin>>c;
    if(c){
      cin>>s>>t;
      cout<<ch.query(s-1,t)<<endl;
    }else{
      cin>>s>>t>>x;
      ch.update(s-1,t,x);
    }
  }
}

/*
verified on 2017/02/24
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_G
*/

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

int main(){
    	int N;
    	cin >> N;
    	vector<long int> vec (N);
    	for(int i = 0;i<N;i++){
    		cin >> vec.at(i);
    	}
    	for(int a = 0;true;a++){
    		for(int i = 0;i < N;i++){
    			if(vec.at(i) % 2 != 0){
    				cout << a << endl;;
    				return 0;
    			}
    		}
    		for(int i = 0;i < N;i++){
    			vec.at(i) /= 2;
    		}
    	}
    	
}

Measured memory_bytes: 256
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,M;
    cin >> N >> M;
    ll A[10010];
    rep(i,0,M) cin >> A[i];
    ll res = N;
    rep(i,0,M) res -= A[i];
    if(res < 0){
        print(-1);
    }else{
        print(res);
    }
    

}

Measured memory_bytes: 3692
#include <stdio.h>

int main(void)
{
	int a,b,c;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	if(a<b&&b<c){
	printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 2140
N,A,B = map(int,input().split())
S = input()

plist = [False for i in range(N)]
p = 0
kp = 0
for i in range(N):
    if p>=A+B: break
    else:
        if S[i]=="a":
            p+=1
            plist[i] = True
        elif S[i]=="b" and kp<B:
            p+=1
            kp+=1
            plist[i] = True
            
for i in range(N):
    if plist[i]:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 4784
# by the authority of GOD     author: manhar singh sachdev #

import os,sys
from io import BytesIO, IOBase
def main():
    k = int(input())
    ans=val=7%k
    fin,n = -1,1
    se = set()
    while ans not in se:
        if not ans:
            fin = n
            break
        se.add(ans)
        val *= 10
        val %= k
        ans += val
        ans %= k
        n += 1
    print(fin)

# Fast IO Region
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()

Measured memory_bytes: 157516
#include<stdio.h>
#include<math.h>

#define PI 3.14159265358979
int main()
{
	double a, b, c, s, l, h, C;

	scanf("%lf %lf %lf", &a, &b, &c);

	C = sqrt(a * a + b * b - 2 * a * b * cos(c * PI / 180));
	s = 0.5 * a * b * sin(c * PI / 180);
	l = a + b + C;
	h = b * sin(c * PI /180);

	printf("%.8lf\n", s);
	printf("%.8lf\n", l); 
	printf("%.8lf\n", h);
	
	
	return(0);
}


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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  if (a * n >= b)
  cout << b << endl;
  else cout << n * a << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <cctype>
#include <cstring>
using namespace std;

int idx, n, ans;
vector<int> pos;
char s[128];

string op = "01+-*()";

int toInt(string tb){
  int j = tb.find("1");
  string binary;

  if(j == string::npos){
    binary = "0";
  }
  else{
    binary = tb.substr(j);
  }

  if(binary.length() > 10){
    return -1;
  }

  int res = 0;

  for(int i = 0; i < binary.length(); i++){
    res <<= 1;

    if(binary[i] == '1'){
      res++;
    }
  }

  return res;
}

int number(){
  string binary = "";

  while(isdigit(s[idx])){
    binary += s[idx];
    idx++;
  }

  return toInt(binary);
}

int solve();

int factor(){
  if(s[idx] == '('){
    idx++;

    int x = solve();
    if(x < 0 || 1024 <= x) return -1;

    if(s[idx] != ')'){
      return -1;
    }
    idx++;
    return x;
  }
  else if(s[idx] == '0' || s[idx] == '1'){
    return number();
  }
  else{
    return -1;
  }
}

int term(){
  int x = factor();
  if(x < 0 || 1024 <= x) return -1;

  while(idx < n){
    if(s[idx] == '*'){
      idx++;

      int y = factor();
      if(y < 0 || 1024 <= y) return -1;

      x *= y;

      if(x < 0 || 1024 <= x) return -1;
    }
    else{
      break;
    }
  }

  return x;
}

int solve(){
  int x = term();

  if(x < 0 || 1024 <= x) return -1;

  while(idx < n){
    if(s[idx] == '+'){
      idx++;

      int y = term();
      if(y < 0 || 1024 <= y) return -1;

      x += y;
      if(x < 0 || 1024 <= x) return -1;
    }
    else if(s[idx] == '-'){
      idx++;

      int y = term();
      if(y < 0 || 1024 <= y) return -1;

      x -= y;
      if(x < 0 || 1024 <= x) return -1;
    }
    else if(s[idx] == '*'){
      idx++;

      int y = term();
      if(y < 0 || 1024 <= y) return -1;

      x *= y;
      if(x < 0 || 1024 <= x) return -1;
    }
    else{
      break;
    }
  }

  return x;
}

int idx2;

bool check(bool first){
  bool flg = false;

  while(idx2 < n){
    if(s[idx2] == ')'){
      return flg;
    }

    if(s[idx2] == '('){
      idx2++;
      if(!check(false)) return false;
    }

    if(s[idx2] == '+' || s[idx2] == '-' || s[idx2] == '*'){
      flg = true;
    }

    idx2++;
  }

  if(first){
    return true;
  }

  return flg;
}

void dfs(int now){
  if(now == pos.size()){
    idx = 0;
    int cal = solve();

    if(idx != n){
      cal = -1;
    }

    idx2 = 0;

    if(cal != -1 && 0 <= cal && cal < (1 << 10) && check(true)){
      ans = max(ans, cal);
    }

    return;
  }

  for(int i = 0; i < op.size(); i++){
    s[pos[now]] = op[i];
    dfs(now + 1);
  }
}

int main(){
  memset(s, '?', sizeof(s));

  while(cin >> s){
    n = strlen(s);
    pos.clear();

    for(int i = 0; i < n; i++){
      if(s[i] == '.'){
        pos.push_back(i);
      }
    }

    ans = INT_MIN;
    dfs(0);

    if(ans == INT_MIN){
      cout << -1 << endl;
    }
    else{
      cout << ans << endl;
    }

    memset(s, '?', sizeof(s));
  }
}

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

bool fib(int n)
{
    if (n <= 1)
        return n;
    return fib(n-1) + fib(n-2);
}
long long int modpow(long long int x,long long int n,long long int m)
{
    if(n==0) return 1%m;
    long long int u=modpow(x,n/2,m);
    u=(u*u)%m;
    if(n%2==1)
    {
        u=(u*x)%m;
    }
    return u;



}




int main()

{
   string s;
   cin>>s;
   if(s[2]==s[3] && s[4]==s[5])
   {
       cout<<"Yes"<<endl;
   }
   else cout<<"No"<<endl;

}


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

public class Main {
    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int n = scanner.nextInt();
        final int ma = scanner.nextInt();
        final int mb = scanner.nextInt();

        final int[] aArray = new int[n];
        final int[] bArray = new int[n];
        final int[] cArray = new int[n];
        for (int i = 0; i < n; i++) {
            aArray[i] = scanner.nextInt();
            bArray[i] = scanner.nextInt();
            cArray[i] = scanner.nextInt();
        }

        final int[][][] cube = new int[n][401][401];
        init(cube);
        cube[0][0][0] = 0;
        cube[0][aArray[0]][bArray[0]] = cArray[0];
        for (int i = 1; i < n; i++) {
            for (int j = 0; j < cube[i].length; j++) {
                System.arraycopy(cube[i - 1][j], 0, cube[i][j], 0, cube[i][j].length);
            }

            for (int j = 0; j < 401; j++) {
                for (int k = 0; k < 401; k++) {
                    if (cube[i - 1][j][k] == Integer.MAX_VALUE) {
                        continue;
                    }
                    cube[i][j + aArray[i]][k + bArray[i]] = Math.min(cube[i - 1][j][k] + cArray[i], cube[i - 1][j + aArray[i]][k + bArray[i]]);
                }
            }
        }

        int answer = Integer.MAX_VALUE;
        for (int i = 1; ma * i < 401 && mb * i < 401; i++) {
            answer = Math.min(answer, cube[n - 1][ma * i][mb * i]);
        }

        System.out.println(answer != Integer.MAX_VALUE ? answer : -1);
    }

    private static void init(final int[][][] cube) {
        for (final int[][] table : cube) {
            for (final int[] array : table) {
                Arrays.fill(array, Integer.MAX_VALUE);
            }
        }
    }
}


Measured memory_bytes: 53816
//BISMILLAH
#include<bits/stdc++.h>
#define ll long long
#define ll long long
using namespace std;



int main()
{
    int n;
    cin>>n;
    vector<ll> v(n);
    ll flag=0,temp=0,res=1;
    for(int i=0;i<n;i++) cin>>v[i];

    for(int i=0;i<v.size();i++)
    {
        if(v[i]==0)
        {
            flag=1;
            break;
        }
    }
    if(flag==1) cout<< "0"<<endl;
    else{
        for(int i=0;i<v.size();i++)
        {
            if(v[i]<=1000000000000000000/res)
            {
                res*=v[i];
            }
            else
            {
                temp=1;
                break;
            }
        }
        if(temp==1) cout<< "-1"<<endl;
        else cout<< res<<endl;
    }

}


Measured memory_bytes: 4028
import math
N,M = (int(T) for T in input().split())
S = input()
T = input()

NMgcd = math.gcd(N,M)
Leng  = N*M//NMgcd
Flag  = True
SList = [S[Nk] for Nk in range(0,N) if Nk%(N//NMgcd)==0]

for Mk in range(0,len(SList)):
    if SList[Mk]!=T[Mk*(M//NMgcd)]:
        Flag = False
        break
if Flag:
    print(Leng)
else:
    print(-1)

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

using namespace std;

const int N = 5005;
const int M = 205;

int n, m;
int LG[N];
int b[M][N];
pair<int, int> f[14][N];
long long a[N];
long long g[N][N];

int get(int l, int r) {
	int k = LG[r - l + 1];
	return max(f[k][l], f[k][r - (1 << k) + 1]).second;
}

void cal(int id, int l, int r) {
	if (l > r) return;
	int p = get(l, r);
	g[l][r] += b[id][p];
	// cout << l << ' ' << r << ' ' << b[id][p] << '\n';
	if (l <= p - 1) {
		g[l][p - 1] -= b[id][p];
		cal(id, l, p - 1);
	}
	if (p + 1 <= r) {
		g[p + 1][r] -= b[id][p];
	 	cal(id, p + 1, r);
	}
}

int main() {
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for (int i = 2; i <= n; ++i) LG[i] = LG[i >> 1] + 1;
	for (int i = 1; i < n; ++i) cin >> a[i], a[i] += a[i - 1];
	for (int i = 1; i <= n; ++i) for (int j = 1; j <= m; ++j) cin >> b[j][i];
	for (int i = 1; i <= m; ++i) {
		for (int j = 1; j <= n; ++j) {
			f[0][j] = make_pair(b[i][j], j);
		}
		for (int j = 1; j <= 13; ++j) {
			for (int k = 1; k + (1 << j) - 1 <= n; ++k) {
				f[j][k] = max(f[j - 1][k], f[j - 1][k + (1 << (j - 1))]);
			}
		}
		cal(i, 1, n);
	}
	for (int i = n; i >= 1; --i) {
		for (int j = 1; j + i - 1 <= n; ++j) {
			int k = i + j - 1;
			g[j][k] += g[j - 1][k];
		}
	}
	for (int i = n; i >= 1; --i) {
		for (int j = 1; j + i - 1 <= n; ++j) {
			int k = i + j - 1;
			g[j][k] += g[j][k + 1];
		}
	}
	long long res = 0;
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= i; ++j) {
			// cout << j << ' ' << i << ' ' << -a[i - 1] + a[j - 1] + g[j][i] << '\n';
			res = max(res, -a[i - 1] + a[j - 1] + g[j][i]);
		}
	}
	cout << res;
}

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

int main(){
    ll n; cin >> n;
    ll ac = 0;
    ll wa = 0;
    ll tle = 0;
    ll re = 0;

    rep(i,n){
        string s; cin >> s;
        if(s == "AC") ac++;
        if(s == "WA") wa++;
        if(s == "RE") re++;
        if(s == "TLE") tle++;
    }

    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl; 
    cout << "RE x " << re << endl;  


}

Measured memory_bytes: 3628
#include <stdio.h>
int main(void){
	int a;
	scanf("%d",&a);
	if(a==100000) printf("%d",9+900+90000);
	else if(a>9999) printf("%d",9+900+a-9999);
	else if(a>999) printf("%d",9+900);
	else if(a>99) printf("%d",9+a-99);
	else if(a>9) printf("%d",9);
	else printf("%d",a);
	return 0;
}

Measured memory_bytes: 128
import sys
MOD=10**9+7
N,M=map(int,input().split())

if N==1:
    print(1)
    sys.exit()

a=[0]*(N+1)
for i in range(M):
  a[int(input())]=-1

pat=[0 for i in range(N+1)]
pat[0]=1
if a[1]==0: pat[1]=1

for i in range(2,N+1):
    if a[i]==0: pat[i]=pat[i-1]+pat[i-2]
    pat[i]%=MOD
print(pat[N])

Measured memory_bytes: 7832
import math
A,B,H,M = list(map(int,input().split(" ")))

#時針の角度
Ha = (H * 360 / 12) + (30 * M/60)
#分針の角度
Ma = M * 360 / 60
#時針と分針のなす角度
a = abs(Ha-Ma)
#aのコサイン
cosa = math.cos(math.radians(a))

ans = math.sqrt(A**2 + B**2 - 2*A*B*cosa)

print(ans)


Measured memory_bytes: 9472
#include<iostream>

using namespace std;

int main() {
	int A, B;
	cin >> A >> B;
	if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0)cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	return 0;
}

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


int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<setprecision(10)<<fixed;
	
	int n,k;
	cin>>n>>k;
	int t=log(n)/log(k);
	cout<<t+1<<endl;
	return 0;
}



Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<sstream>
using namespace std;
int inf = 1e9;
int main(){
  string s;
  cin >> s;
  sort(s.begin(), s.end());
  if( s == "abc" ) cout << "Yes" << endl;
  else cout << "No" << endl;


  return 0;
}


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


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

  if (400 <= X &&  X <= 599){
    cout << 8 << endl;
  }else if(600<= X &&  X <=799){
    cout << 7 << endl;
  }else if(800 <= X &&  X <= 999){
    cout << 6 << endl;
  }else if(1000 <= X &&  X <= 1199){
    cout << 5 << endl;
  }else if(1200 <= X &&  X <= 1399){
    cout << 4 << endl;
  }else if(1400 <= X &&  X <= 1599){
    cout << 3 << endl;
  }else if(1600 <= X &&  X <= 1799){
    cout << 2 << endl;
  }else if(1800 <= X &&  X <=1999){
    cout << 1 << endl;
  }
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#include<iostream>
using namespace std;
long long int lcm(long long int a,long long int b){
  long long int n;
  n=a*b/__gcd(a,b);
  return n;
}
using ll =long long int;
#define ci(a) cin>>a
#define co(a) cout<<a<<endl
#define gcd(a,b) __gcd(a,b)
#define vec vector<ll>
#define For(i,a,b) for(ll i=a;i<b;i++)
#define rFor(i,a,b) for(ll i=a;i>b;i--)
#define wFor(i,a,b) for(ll i=a;i<b;i+=2)
#define wrFor(i,a,b) for(ll i=a;i>b;i-=2)
#define sort(a,b) sort(a.begin(),b.end())
#define reverse(a,b) reverse(a.begin(),b.end())
//gcd 最大公約数
//lcm 最小公倍数
//double 少数（変数）
//string 文字列（変数）
//sqrt 平方根
//ceil 天井関数
//floor 床関数
//abs 絶対値
//pow 累乗
//cbrt  立方根
//hypot 平方和の平方根
//(string-'0') 文字列を数字に変換
//(char-'0') 数字に変換
//vector<vector<int>> data(a,vector<int>(b)) a×b行列
//for(int i=0;i<a;i++)
//for(int j=0;j<b;j++)
//cin>>data.at(i).at(j)  a×b行列の入力
//floor(log10(a)+1) aの10進法での桁数
//ceil(log10(a)) aの10進法での桁数

int main() {
  int a,b;
  ci(a>>b);
  co(max(a-2*b,0));
}


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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int h, w;
	cin >>h >>w;
	vector<string> s(h);
	rep(i, h) cin >>s[i];
	
	int ans = 0;
	const int dr[]={0,1,0,-1,0};
	const int INF= 1<<28;
	rep(sy, h) rep(sx,w){
		if(s[sy][sx]=='#') continue;
		vector<VI> dd(h, VI(w, INF));
		queue< pair<int, int> > que;
		que.emplace(sy, sx); dd[sy][sx]=0;
		while(!que.empty()){
			int cy,cx; tie(cy,cx) = que.front();
			que.pop();
			rep(i,4){
				int ny=cy+dr[i], nx=cx+dr[i+1];
				if(ny<0 || ny>=h || nx<0 || nx>=w) continue;
				if(dd[ny][nx] == INF && s[ny][nx] =='.'){
					que.emplace(ny, nx);
					dd[ny][nx] = dd[cy][cx] + 1;
				}
			}
		}
		rep(i,h)rep(j,w) if(dd[i][j]<INF) ans=max(ans, dd[i][j]);
		//for(auto xl: dd){for(auto x :xl) cerr<<x<<" ";dbg("",sy,sx);}

	}
	cout <<ans <<"\n";
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}

string a,b;

int main(){
	cin >> a >> b;
	ll n = 0;
	rep(i,a.size()){
		n += a[i] - '0';
		n *= 10;
	}
	rep(i,b.size()){
		n += b[i] - '0';
		if(i != b.size()-1)n *= 10;
	}
	// cout << "!" << n << endl;
	bool f = false;
	ll i = 1;
	while(i * i <= n){
		if(i * i == n)f = 1;
		i++;
	}
	if(f)cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.Stack;

class Main {

    public static void main(String[] args) {
        new Main().compute();
    }

    void compute() {
        Scanner sc = new Scanner(System.in);
        sc.useDelimiter("[\\s]+");
        int n = sc.nextInt();
        long f = 1;
        for (; n > 1; n--) {
            f *= n;
        }
        System.out.println(f);
    }
}


Measured memory_bytes: 26016
#include <vector>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())

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

  int n, m;
  cin >> n >> m;

  cout << (((n-m) * 100) + (m * 1900)) * pow(2, m) << endl;
  return 0;
}


Measured memory_bytes: 512
# -*- coding: utf-8 -*-
# 整数の入力
lst = list(map(int, input().split()))

if lst[0] == 5:
    if (lst[1] == 7 and lst[2] == 5) or (lst[1] == 5 and lst[2] == 7):
        print("YES")
        exit()

elif lst[0] == 7:
    if lst[1] == 5 and lst[2] == 5:
        print("YES")
        exit()

print("NO")

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

typedef complex<double> Point;

#define EPS (1e-10)
#define EQ(a,b) (abs((a)-(b)) < EPS)
#define EQV(a,b) ( EQ( (a).real() , (b).real() ) && EQ( (a).imag(), (b).imag() ) )

// àÏ : aEb
double dot(Point a,Point b) {
  return (a.real()*b.real() + a.imag()*b.imag());
}

//OÏ a~b
double cross(Point a,Point b) {
  return (a.real()*b.imag() - a.imag()*b.real());
}


// a1,a2ð[_Æ·éüªÆb1,b2ð[_Æ·éüªÌð·»è
int is_intersected_ls(Point a1, Point a2, Point b1, Point b2) {
  return ( cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS ) &&
         ( cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS );
}

int main(){
  double x,y;

  while(cin>>x>>y){
  Point p1(x,y);

  cin>>x>>y;
  Point p2(x,y);

  cin>>x>>y;
  Point p3(x,y);

  cin>>x>>y;
  Point p(x,y);

  Point s(200,252.3);

  bool flag1,flag2,flag3;

  flag1= is_intersected_ls(p,s,p1,p2);
  flag2 = is_intersected_ls(p,s,p2,p3);
  flag3 = is_intersected_ls(p,s,p3,p1);

  if((flag1^flag2)^flag3) {
    cout<<"YES"<<endl;
    continue;
  }

  cout<<"NO"<<endl;

  }
}

Measured memory_bytes: 0
#include <iostream>
#include <cstring>
#include <cmath>
using namespace std;
int y[101],r,n;

double mk_dis(int x1,int h,double cy){
  return sqrt(x1*x1+(h-cy)*(h-cy));
}

bool check(double cy){
  cy=(int)(cy*100000)/100000.0;
  double x=fabs(sqrt(r*r-cy*cy));
  if(cy>=0)x=r;
  int L=(-x-0.999999),R=(x+0.999999),hb[101]={};
  for(int i=L+50;i<R+50;i++)
    if(i>=50){
      if(mk_dis(i-50,y[i],cy)>=r)hb[i]++;
    }
    else {
      if(mk_dis(i-49,y[i],cy)>=r)hb[i]++;
    }
  
  for(int i=L+50;i<R+50;i++)if(!hb[i])return false;
  return true;
}

int main(){
  while(1){
    cin>>r>>n;
    if(!r&&!n)break;
    memset(y,0,sizeof(y));
    for(int i=0;i<n;i++){
      int x1,x2,h;
      cin>>x1>>x2>>h;
      for(int j=x1;j<x2;j++) y[j+50]=max(y[j+50],h);
    }
    double ans;
    for(ans=0;check(ans-r);ans+=0.0001);
    cout << ans<<endl;
  }
  return 0;
}

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

#define endl '\n'
#define pb push_back
#define mod 1000000007
typedef int integer;
#define int long long
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 0
#endif
using namespace std;

template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
    cerr << name << ": " << arg1 << endl;
}

template<typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
    const char *comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << ": " << arg1 << " |";
    __f(comma + 1, args...);
}

int powmod(int a, int b) {
    int res = 1;
    a %= mod;
    assert(b >= 0);
    for (; b; b >>= 1) {
        if (b & 1)res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}

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

const integer NN = (int) 5e5 + 2;
int n, m, k;

int ar[3001][3001];
int dp[3001][3001][4];

int solve(int x, int y, int cnt){
    assert(cnt <= 3);
    if (x == n-1 && y == m-1){
        return cnt == 3 ? 0 : ar[x][y];
    }
    if (dp[x][y][cnt] != -1) return dp[x][y][cnt];
    if (y == m-1){
        return dp[x][y][cnt] = (cnt == 3 ? 0 : ar[x][y]) + solve(x+1, y, 0);
    }
    if (x == n-1){
        if (cnt == 3) return dp[x][y][cnt] = solve(x, y+1, cnt);
        return dp[x][y][cnt] = max(solve(x, y+1, cnt+1) + ar[x][y], solve(x, y+1, cnt));
    }
    int ans = max(solve(x, y+1, cnt), solve(x+1, y, 0));
    if (cnt < 3)
        ans =  max(ans, ar[x][y] + max(solve(x, y+1, cnt+1), solve(x+1, y, 0)));
    return dp[x][y][cnt] = ans;
}

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


    cin >> n >> m >> k;
    for (int i = 0; i < k; i++){
        int a, b, c;
        cin >> a >> b >> c;
        ar[a-1][b-1] = c;
    }
    memset(dp, -1, sizeof dp);
    cout << solve(0, 0, 0) << endl;

}


Measured memory_bytes: 355728
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
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; }



int main(int argc, char const *argv[]) {
  int n, k;
  cin >> n >> k;
  if ((n - 2) * (n - 1) / 2 < k) {
    puts("-1");
    return 0;
  }

  vector<pii> G;
  // create star graph
  for (int i = 1; i < n; i++){
    G.pb({1, i + 1});
  }
  int cnt = (n - 2) * (n - 1) / 2 - k;
  vector<pii> rec;
  for (int i = 2; i < n; i++){
    for (int j = i ; j < n; j++){
      rec.pb({i, j + 1});
    }
  }
  rep(i, cnt) G.pb(rec[i]);

  cout << sz(G) << endl;
  rep(i,sz(G)){
    cout << G[i].fi << " " << G[i].se << endl;
  }
  return 0;
}

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

vector<int> par(10000);
vector<long long> item(10000);

int root(int i) {
	if (par[i] == i) return i;
	return par[i] = root(par[i]);
}

bool same(int i, int j) {
	return root(i) == root(j);
}

void unite(int i, int j) {
	int ri = root(i);
	int rj = root(j);
	par[rj] = ri;
}

int main() {
	int N,M;
	cin >> N >> M;
	par.resize(N);
	item.resize(N);
	for (int i = 0; i < N; i++) {
		par[i] = i;
		item[i] = 1L;
	}
	vector<int> A(M);
	vector<int> B(M);
	for (int i = 0; i < M; i++) {
		cin >> A[i] >> B[i];
		A[i]--; B[i]--;
	}
	reverse(A.begin(), A.end());
	reverse(B.begin(), B.end());
	vector<long long> conf(M);
	for (int i = 0; i < M; i++) {
		int a = A[i], b = B[i];
		if (same(a, b)) {
			conf[i] = 0;
			continue;
		}
		int ra = root(a), rb = root(b);
		unite(a, b);
		conf[i] = item[ra]*item[rb];
		item[ra] = item[rb] = item[ra] + item[rb];
	}
	long long sum = 0;
	for (int i = M-1; i >= 0; i--) {
		sum += conf[i];
		cout << sum << endl;
	}
	return 0;
}


Measured memory_bytes: 4224
import java.util.Scanner;

public class Main {
	
	public static int count(int[] nums) {
		
		int total = 0;
		for (int i = 0; i < nums.length; i++) {
			
			int temp = nums[i];
			
			if (temp == 2 | temp == 3) {
				total++;
			}
			
			for (int j = 2; j < Math.sqrt(temp); j++) {
				
				if (temp%j == 0) {
					break;
				}
				else if(j == Math.floor(Math.sqrt(temp))) {
					total++;
				}
				
			}
		}
		
		return total;
	}
	
	
	public static void main(String[] args) {
		
		Scanner in = new Scanner(System.in);
		
		int elements = in.nextInt();
		int[] nums = new int[elements];
		
		for (int i = 0; i < elements; i++) {
			nums[i] = in.nextInt();
		}
		
		int result = count(nums);
		System.out.println(result);
		
		in.close();

	}

}



Measured memory_bytes: 41300
#include<stdio.h>
int main()
{
  int  n, i;
  long int l0, l1, l2;
  scanf("%d", &n);
  if(n == 1){
     printf("1\n");
  }else{
  l0 = 2;
  l1 = 1;
  for(i = 2; i <= n; i++){
    l2 = l1 + l0;
    l0 = l1;
    l1 = l2; 
  }
  printf("%ld\n", l2);
  }
 
  return 0;
}
  

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> ii;
typedef map<int, int> MPII;
typedef set<int> SETI;

const int mxN = 2e5;
const ld pi = 4.0 * atanl(1.0);
const int iinf = 1e9 + 10;
const int inf = 1e18 + iinf + 10;
const int mod = 1000000007;
const ld prec = .000001;

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define all(c) c.begin(), c.end()
#define rall(c) c.end(), c.begin()

int n, m, t, a[mxN];
vi v;

void fast() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); }

int main() {
  fast();
  string s;
  cin >> s;
  ll ans = 0, t = 0;
  for (int i = 0; i < s.length(); ++i) {
    if (s[i] == 'B')
      ++t;
    else
      ans += t;
  }
  cout << ans;
  return 0;
}


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

int dfs(int n,int k){
    if(n==1)
        return 0;
    return (k+dfs(n-1,k))%n;
}
int main(){
    int n,k,m;
    while(cin>>n>>k>>m,n){
        cout<<(m+dfs(n-1,k))%n+1<<endl;


    }

    return 0;
}

Measured memory_bytes: 3312
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#ifdef __GXX_EXPERIMENTAL_CXX0X__
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
//#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;


int main(){
    ll N;
    cin >> N;
    int i = 1;
    ll M = 0;
    while(N > M){
        M += pow(26, i);
        i++;
    }
    i--;
    ll k = N;
    rep(j, 1, i){
        k -= pow(26, j);
    }
    ll K = k - 1;
    stack<ll> S;
    rep(j, 1, i + 1){
        ll q = K / 26;
        ll r = K % 26;
        K = q;
        S.push(r);
    }
    
    while(!S.empty()){
        int x = S.top();
        S.pop();
        cout << char('a' + x);
    }
    cout << endl;
}

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

using namespace std;

int n;
int tb[11][11];

int main() {
	while (1) {
		cin >> n; if (n == 0) break;
		
		int allsum = 0;
		for (int i = 0; i < n; i++) {
			int rsum = 0;
			for (int j = 0; j < n; j++) {
				cin >> tb[i][j];
				rsum += tb[i][j];
			}
			tb[i][n] = rsum;
			allsum += rsum;
		}
		tb[n][n] = allsum;
		
		for (int j = 0; j < n; j++) {
			int csum = 0;
			for (int i = 0; i < n; i++) {
				csum += tb[i][j];
			}
			tb[n][j] = csum;
		}
		
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j <= n; j++) {
				cout << setw(5) << tb[i][j];
			}
			cout << endl;
		}
	}	
	
	return 0;
}

Measured memory_bytes: 1172
#include<bits/stdc++.h>
#include<tr1/unordered_map>
#define ls l,mid
#define rs mid+1,r
#define lc p<<1
#define rc p<<1|1
#define pb push_back
#define pii pair<int,int>
#define SZ(x) (int)x.size()
#define mem(a,b) memset(a,b,sizeof(a))
#define  For(i,a,b) for(int i=a,i##E=b;i<=i##E;++i)
#define rFor(i,a,b) for(int i=a,i##E=b;i>=i##E;--i)
typedef long long LL;
using namespace std;
const int N=200010;
const int inf=0x3f3f3f3f;
template<typename T>inline bool chkmin(T &a,const T &b){return a>b?a=b,1:0;}
template<typename T>inline bool chkmax(T &a,const T &b){return a<b?a=b,1:0;}
template<typename T>inline void read(T &x)
{
	x=0;int _f(0);char ch=getchar();
	while(!isdigit(ch))_f|=(ch=='-'),ch=getchar();
	while( isdigit(ch))x=x*10+ch-'0',ch=getchar();
	x=_f?-x:x;
}
inline void file()
{
	freopen("hamming.in","r",stdin);
	freopen("hamming.out","w",stdout);
}
int n,m,ans,B0,Min[N<<2];
int B[N],s[N],f[N];
vector<int>G[N];
inline void Add_tree(int l,int r,int p,int x,int y)
{
	if(l==r){Min[p]=y;return;}
	int mid=(l+r)>>1;
	if(x<=mid)Add_tree(ls,lc,x,y);
	else Add_tree(rs,rc,x,y);
}
inline void Min_tree(int l,int r,int p,int x,int y,int z)
{
	if(x<=l&&r<=y){chkmin(Min[p],z);return;}
	int mid=(l+r)>>1;
	if(x<=mid)Min_tree(ls,lc,x,y,z);
	if(y> mid)Min_tree(rs,rc,x,y,z);
}
inline int Query_tree(int l,int r,int p,int x)
{
	if(l==r)return Min[p];
	int mid=(l+r)>>1;
	if(x<=mid)return min(Query_tree(ls,lc,x),Min[p]);
	else return min(Query_tree(rs,rc,x),Min[p]);
}
int main()
{
	int x,y;
	//file();
	read(n);
	For(i,1,n)
	{
		read(B[i]);
		s[i]=s[i-1]+(B[i]==1?1:-1);
		if(B[i]==0)B0++;
	}
	read(m);
	For(i,1,m)read(x),read(y),G[y].pb(x);
	ans=inf;
	mem(Min,inf);
	Add_tree(0,n,1,0,0);
	For(i,1,n)
	{
		x=Query_tree(0,n,1,i-1);
		Add_tree(0,n,1,i,min(s[i],x+(B[i]==1?1:-1)));
		For(j,0,SZ(G[i])-1)
		{
			int x=Query_tree(0,n,1,G[i][j]-1);
			Min_tree(0,n,1,G[i][j],i,x);
		}
		x=Query_tree(0,n,1,i);
		chkmin(ans,B0+x+s[n]-s[i]);
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 15232
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#include <queue>
#include <climits>
#include <set>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ve vector
#define umap unordered_map
#define iter iterator

void solve() {
    int n;cin>>n;
    int res=0;
    for(int i=0;i<n;i++) {
        int l,r;cin>>l>>r;
        res += r-l+1;
    }
    cout<<res<<endl;
}

int main() {
    solve();
    return 0;
}

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

#define int long long
#define double long double

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

const int INF = 1e16;
const int MOD = 1e9+7;

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

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int n; cin >> n;
    vvi G(n, vi(n));
    vi d(n, INF); d[0] = 0;
    REP(i, n)
    {
        int u, k; cin >> u >> k; u--;
        REP(j, k)
        {
            int v; cin >> v; v--;
            G[u][v] = 1;
        }
    }

    REP(k, n)
    {
        REP(i, n)
        {
            REP(j, n)
            {
                if(G[i][j] == 1) chmin(d[j], d[i]+1);
            }
        }
    }
    REP(i, n) cout << i+1 << " " << ((d[i] == INF) ? -1 : d[i]) << endl;
}


Measured memory_bytes: 3200
parseInt(x)=parse(Int,x)
parseMap(x::Array{SubString{String},1})=map(parseInt,x)

function main()
	n,k = readline() |> split |> parseMap
	p = 0.0
	p += max((n-k+1)/n,0)
	z = min(k-1,n)
	for i in 1:z
		x = i
		r = 0
		while x < k
			x *= 2
			r += 1
		end
		p += 1/(n*(2^r))
	end
	println(p)
end
main()


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];

    int ans = 1;
    int flag = -1;
    for (int i = 1; i < N; i++) {
        if (A[i] == A[i - 1]) continue;
        else {
            if (flag == -1) {
                if (A[i] > A[i - 1]) flag = 0;
                else flag = 1;
            }
            else if (flag == 0) {
                if (A[i] > A[i - 1]) continue;
                else {
                    flag = -1;
                    ans++;
                }
            }
            else if (flag == 1) {
                if (A[i] < A[i - 1]) continue;
                else {
                    flag = -1;
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <stdio.h>

int main(void) {
	int N, K;
	int i;
	int Dmask = 0;
	int asumikana;
	if (scanf("%d%d", &N, &K) != 2) return 1;
	for (i = 0; i < K; i++) {
		int D;
		if (scanf("%d", &D) != 1) return 1;
		Dmask |= 1 << D;
	}
	asumikana = N;
	for (;;) {
		int kitamuraeri = asumikana;
		int ng = 0;
		while (kitamuraeri > 0) {
			if (Dmask & (1 << (kitamuraeri % 10))) {
				ng = 1;
				break;
			}
			kitamuraeri /= 10;
		}
		if (!ng) break;
		asumikana++;
	}
	printf("%d\n", asumikana);
	return 0;
}


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

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define pb emplace_back
#define mp make_pair
#define endl '\n'
#define f first
#define s second

#ifdef SEREZHKA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; }

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;
    
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;
    
    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7ll;
const ll LINF = INF * INF;
const int MAXN = static_cast<int>(1e5) + 17;

int n, L, q;
int x[MAXN];
int up[20][MAXN];

bool read() {
    if (!(cin >> n))
        return false;

    forn (i, n)
        cin >> x[i];

    cin >> L >> q;

    return true;
}

void solve() {
    for (int l = n - 1, r = n - 1; l >= 0; --l) {
        for (; r >= l && x[r] - x[l] > L; --r) { }
        up[0][l] = r;
    }

    for (int k = 1; k < 20; ++k)
        for (int i = 0; i < n; ++i)
            up[k][i] = up[k - 1][up[k - 1][i]];

    while (q --> 0) {
        int l, r, res = 0;
        cin >> l >> r;
        --l, --r;

        if (l > r)
            swap(l, r);

        for (int k = 19; k >= 0; --k)
            if (up[k][l] < r) {
                l = up[k][l];
                res += (1 << k);
            }

        cout << res + 1 << endl;
    }
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    
    while (read())
        solve();
    
    return 0;
}



Measured memory_bytes: 9088
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;
const int MAX=100;

struct S{
	ll x1,x2,y1,y2,z1,z2;
	bool isIn(ll x,ll y, ll z){
		if(x1<=x&&x<x2&&y1<=y&&y<y2&&z1<=z&&z<z2) return true;
		return false;
	}
};

int N,K;
vector<S> vec;
vector<ll> X;
vector<ll> Y;
vector<ll> Z;
int grid[MAX][MAX][MAX]={};

void input(){
	cin >> N >> K;
	for(int i=0; i<N; ++i){
		S s;
		cin >> s.x1 >> s.y1 >> s.z1 >> s.x2 >> s.y2 >> s.z2;
		vec.push_back(s);
		X.push_back(s.x1);
		X.push_back(s.x2);
		Y.push_back(s.y1);
		Y.push_back(s.y2);
		Z.push_back(s.z1);
		Z.push_back(s.z2);
	}
}

int main(){
	input();
	sort(X.begin(),X.end());
	sort(Y.begin(),Y.end());
	sort(Z.begin(),Z.end());
	X.erase(unique(X.begin(),X.end()),X.end());
	Y.erase(unique(Y.begin(),Y.end()),Y.end());
	Z.erase(unique(Z.begin(),Z.end()),Z.end());
	for(int i=0; i<vec.size(); ++i){
		for(int xin=0; xin<X.size()-1; ++xin){
			for(int yin=0; yin<Y.size()-1; ++yin){
				for(int zin=0; zin<Z.size()-1; ++zin){
					if(vec[i].isIn(X[xin],Y[yin],Z[zin])) ++grid[xin][yin][zin];
				}
			}
		}
	}
	ll ans=0;
	for(int xin=0; xin<X.size()-1; ++xin){
		for(int yin=0; yin<Y.size()-1; ++yin){
			for(int zin=0; zin<Z.size()-1; ++zin){
				if(grid[xin][yin][zin]>=K) ans+=((X[xin+1]-X[xin])*(Y[yin+1]-Y[yin])*(Z[zin+1]-Z[zin]));
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4888
#include <bits/stdc++.h>
#define ll long long
#define all(x) begin(x), end(x)
#define range(x) begin(x), begin(x)
#define what(x) cout << #x << ": " << x << '\n'
#define print(x) for (auto &el: x) cout << el << ' '; cout << '\n'
using namespace std;
 
template<typename S, typename T>
ostream& operator <<(ostream &os, pair<S, T> &m) { 
    os << '[' << m.first << " " << m.second << ']'; 
    return os; 
}

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

    int r, c, x;
    cin >> r >> c >> x;
    vector<string> grid(r);
    for (auto &el: grid) cin >> el;

    int ans = 0;
    for (int i = 0; i < (1 << (r + c)); ++i) {
        int cnt = 0;    
        for (int j = 0; j < r; ++j) {
            for (int k = 0; k < c; ++k) {
                if ( i & (1 << j) ) continue;
                if ( i & (1 << (k + r)) ) continue;
                if ( grid[j][k] != '#' ) continue;
                cnt++;
            }
        }
        if (cnt == x) ans++;
    }
    
    cout << ans << endl;

    return 0;
}

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

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	string s;
	cin >> s;
	int n = SZ(s);
	vector<int> a(n + 1);
	for (int i = 0; i < n; i++) {
		if (s[i] == '<')
			a[i + 1] = max(a[i + 1], a[i] + 1);
	}
	for (int i = n - 1; i >= 0; i--) {
		if (s[i] == '>')
			a[i] = max(a[i], a[i + 1] + 1);
	}
	ll sum = 0;
	for (int i = 0; i <= n; i++)
		sum += a[i];
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 2844
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
#define repi(i, n, iv) for (int i = iv; i < n; i++)
#define all(v) v.begin(), v.end()

using namespace std;
typedef long long ll;

int count(int s)
{
    return floor(sqrt(2 * s + 0.25) - 0.5);
};

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

    ll N;
    cin >> N;

    auto max = sqrt(N);
    map<int, int> p;
    for (int i = 2; i < max; i++)
    {
        while (N % i == 0)
        {
            N /= i;
            p[i]++;
        }
    }
    if (N != 1)
        p[N]++;

    int res = 0;
    for (auto e : p)
    {
        res += count(e.second);
    }

    cout << res << endl;
}


Measured memory_bytes: 3284