akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

#define N_MAX 100
#define W_MAX 100
#define H_MAX 100

int main()
{
    int w, h, n;
    int points[N_MAX][2];
    int commands[N_MAX];

    scanf("%d %d %d", &w, &h, &n);
    for (int i = 0; i < n; i++)
    {
	scanf("%d", &points[i][0]);
	scanf("%d", &points[i][1]);
	scanf("%d", &commands[i]);
    }

    int area[W_MAX][H_MAX] = {};
    for (int i = 0; i < n; i++)
    {
	switch (commands[i])
	{
	    case 1:
		for (int x = 0; x < points[i][0]; x++)
		{
		    for (int y = 0; y < h; y++)
		    {
			area[x][y] = 1;
		    }
		}
		break;
	    case 2:
		for (int x = points[i][0]; x < w; x++)
		
		{
		    for (int y = 0; y < h; y++)
		    {
			area[x][y] = 1;
		    }
		}
		break;
	    case 3:
		for (int x = 0; x < w; x++)
		{
		    for (int y = 0; y < points[i][1]; y++)
		    {
			area[x][y] = 1;
		    }
		}
		break;
	    case 4:
		for (int x = 0; x < w; x++)
		{
		    for (int y = points[i][1]; y < h; y++)
		    {
			area[x][y] = 1;
		    }
		}
		break;
	}
    }

    int count = 0;
    for (int x = 0; x < w; x++)
    {
	for (int y = 0; y < h; y++)
	{
	    if (area[x][y] == 0)
	    {
		count++;
	    }
	}
    }
    printf("%d\n", count);
    
    return 0;
}


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

int matrix[31][51][51];
int s[51];

void init(){
  for(int i=0;i<51;i++){
    for(int j=0;j<51;j++){
      for(int k=0;k<30;k++)matrix[k][i][j]=0;
    }
  }
}

int main()
{
  int n,m,a,b,c,t;

  while(1){
    cin>>n>>m>>a>>b>>c>>t;
    init();
    if((n+m+a+b+c+t)==0)break;
    for(int i=0;i<n;i++)cin>>s[i];

    for(int i=0;i<n;i++)matrix[0][i][i]=b;
    for(int i=0;i<n-1;i++)matrix[0][i+1][i]=a;
    for(int i=0;i<n-1;i++)matrix[0][i][i+1]=c;

    for(int bit=1;bit<30;bit++){
      for(int i=0;i<n;i++){
	for(int j=0;j<n;j++){
	  for(int k=0;k<n;k++){
	    matrix[bit][i][j]+=matrix[bit-1][i][k]*matrix[bit-1][k][j];
	    matrix[bit][i][j]%=m;
	  }
	}
      }
    }

    int ans[51]={},tmp[51]={};

    for(int bit=0;(1<<bit)<=t;bit++){
      if((t>>bit)%2){
	for(int i=0;i<n;i++){
	  tmp[i]=s[i];
	  s[i]=0;
	}

	for(int i=0;i<n;i++){
	  for(int j=0;j<n;j++){
 	    s[i]+=matrix[bit][i][j]*tmp[j];
	    s[i]%=m;
	  }
	}
      }
    }
    
    for(int i=0;i<n;i++){
      cout<<s[i];
      if(i!=n-1)cout<<" ";
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 1472
#include  <iostream>
#include <algorithm>

int main() {

	int n; std::cin >> n;
	long long int max = 0;
	long long int ans = 0;

	for (int i = 0; i < n; ++i) {

		long long int a; scanf("%lld", &a);
		max = std::max(a, max);
		ans += max - a;

	}

	std::cout << ans<< std::endl;

	return 0;
}

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

#define ll long long
#define INF 99999999
#define INF_LL 1LL << 60
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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

    if( X == 7 || X == 5 || X == 3 ) cout << "YES" << endl;
    else cout << "NO" << endl;

}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();

    long[] a = new long[n];
    for(int i=0; i<n; i++){
      a[i] = sc.nextLong();

      if(a[i] == 0){
        System.out.println(0);
        return;
      }
    }

    long result = a[0];
    long preResult = a[0];
    long upper = 1000000000000000000L;

    for(int i=1; i<n; i++){
      result = result * a[i];
      if(result < preResult || result > upper){
        System.out.println(-1);
        return;
      }
      preResult = result;
    }

    System.out.println(result);
  }
}

Measured memory_bytes: 58816
/* � Ashiq Uddin Pranto
   Department of Computer Science and Engineering
   BATCH 27
   University Of Rajshahi,Bangladesh
*/
#include<bits/stdc++.h>

#define ll long long
#define ld long double
#define FOR(x,y) for(ll i=x;i<=y;i++)
#define pb(x) push_back(x)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define matrix(x) vector<vector<x>>
#define vss vector<string>
#define PI (2*acos(0.0))
#define sqr(x) ((x)*(x))
#define sf(a)   scanf("%d",&a)
#define sfl(a)  scanf("%lld",&a)
#define sff(a,b)    scanf("%d %d",&a,&b)
#define sffl(a,b)   scanf("%lld %lld",&a,&b)
#define sfff(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)    scanf("%lld %lld %lld",&a,&b,&c)
#define ms(a,b) memset(a, b, sizeof(a))
#define ff  first
#define ss  second
#define lcm(a, b)   ((a)*((b)/__gcd(a,b)))
#define all(a)  a.begin(),a.end()
#define readfile freopen("input.txt","r",stdin);
#define writefile freopen("output.txt","w",stdout);
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define gap " "
#define mx 104
#define inf (ll)1e9
#define WHITE 1
#define GRAY 2
#define BLACK 3
#define EMPTY_VALUE -1
#define mod 1000000007
#define MOD(a,b) (a%b + b)%b

using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


int main()
{
    //fastio
    ll x;
    sfl(x);
    cout<<x+x*x+x*x*x<<endl;

    return 0;
}

Measured memory_bytes: 3688
#include <stdio.h>
int t, n, x, f;
unsigned long long a[200];
unsigned long long b[64];
unsigned long long q[200];
int y[64];
char s[201];
int main() {
	scanf("%d", &t);
	b[0] = 1;
	for (int i = 1; i < 64; i++)b[i] = b[i - 1] * 2;
	for (int v = 0; v < t; v++) {
		scanf("%d", &n);
		for (int i = 0; i < n; i++) {
			scanf("%llu", a + i);
		}
		scanf(" %s", s);
		for (int i = 0; i < 64; i++)y[i] = -1;
		f = 0;
		for (int i = n - 1; i >= 0; i--) {
			if (s[i] == '1') {
				for (int j = 0; j < 64; j++) {
					if (a[i] & b[j]) {
						if (y[j] == -1) {
							f = 1;
							goto X;
						}
						else {
							a[i] ^= q[y[j]];
						}
					}
				}
				if (a[i]) {
					f = 1;
					goto X;
				}
			}
			else {
				q[x] = a[i];
				for (int j = 0; j < 64; j++) {
					if (q[x] & b[j]) {
						if (y[j] != -1) {
							q[x] ^= q[y[j]];
						}
					}
				}
				for (int j = 0; j < 64; j++) {
					if (q[x] & b[j]) {
						if (y[j] == -1) {
							y[j] = x;
							break;
						}
					}
				}
				x++;
			}
		}
		x = 0;
	X:
		x = 0;
		printf("%d\n", f);
	}
}

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

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

  int n;
  cin >> n;
  int ans = 0;

  rep(i, 1, n + 1) ans += sowa(n / i) * i;

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

Measured memory_bytes: 3660
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>

using namespace std;

int main(){
	int h, w, ans = 0;
	cin >> h >> w;
	int inf = h * w + 100;
	vector<vector<char>> s(h + 2, vector<char>(w + 2, '#'));
	vector<vector<int>> c(h + 2, vector<int>(w + 2, inf));
	for(int i = 1; i <= h; i++){
		for(int j = 1; j <= w; j++){
			cin >> s[i][j];
			if(s[i][j] == '.') ans++;
		}
	}
	c[1][1] = 0;
	queue<pair<int, int>> q;
	q.push({1, 1});
	int dx[] = {0, 1, 0, -1}, dy[] = {-1, 0, 1, 0};
	while(!q.empty()){
		auto pa = q.front();
		int x = pa.second, y = pa.first;
		q.pop();
		for(int i = 0; i < 4; i++){
			int nx = x + dx[i], ny = y + dy[i], nc = c[y][x] + 1;
			if(s[ny][nx] != '#' && nc < c[ny][nx]){
				c[ny][nx] = nc;
				q.push({ny, nx});
			}
		}
	}
	ans -= c[h][w] + 1;
	cout << ((c[h][w] == inf)? -1 : ans) << endl;
	return 0;
}

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

bool checkSame(string* a, string* b, int i, int j, int m){
    for(int k = 0; k<m; k++){
        auto sa = a[i+k];
        sa = sa.substr(j, m);
        if(sa != b[k]) return false;
    }
    return true;
}

int main()
{
    int n, m;
    cin >> n >> m;
    string a[n], b[m];
    for(int i = 0; i<n; i++){
        cin >> a[i];
    }
    for(int i = 0; i<m; i++){
        cin >> b[i];
    }
    for(int i = 0; i<=n-m; i++){
        for(int j = 0; j<=n-m; j++){
            if(checkSame(a, b, i, j, m)){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
def threeDivCheck(x):
  if x % 3 == 0: return x
  return 0

def threeIncludeCheck(x):
  y = x
  while y!=0:
    if y%10 == 3:
      return x
    y=int(y/10)
  return 0

def main():
  n = int(input())
  p = 0
  for i in range(n+1):
    p = threeDivCheck(i)
    if p:
      print(' {}'.format(p), end='')
    else:
      p=threeIncludeCheck(i)
      if p:
        print(' {}'.format(p), end='')
  print()

main()

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


int main()
{
	int h, w;
	cin >> h >> w;
	vector<string> masu;
	for (int i = 0; i < h; ++i) {
		string s;
		cin >> s;
		masu.push_back(s);
	}
	bool ok = true;
	bool top;
	bool bot;
	bool l;
	bool r;
	string yn = "Yes";
	
	for (int i1 = 0; i1 < masu.size(); ++i1) {
		for (int i2 = 0; i2 < w; ++i2) {
			top = true;
			bot = true;
			l = true;
			r = true;

			if (masu[i1][i2] == '#') {
				if (i1 == 0)
					top = false;
				else if (masu[i1 - 1][i2] == '.')
					top = false;
				if (i2 == 0)
					l = false;
				else if (masu[i1][i2 - 1] == '.')
					l = false;
				if (i1 == masu.size() - 1)
					bot = false;
				else if (masu[i1 + 1][i2] == '.')
					bot = false;
				if (i2 == w - 1)
					r = false;
				else if (masu[i1][i2 + 1] == '.')
					r = false;
				if (top == false && bot == false && l == false && r == false) {
					yn = "No";
				}
			}
		}
	}
	cout << yn;
	
	
}

Measured memory_bytes: 256
module Main where
import Debug.Trace
import Data.List
import Data.Maybe
import Data.Ord
import Control.Monad

solve :: Int -> String
solve n = iter 1 where
    iter i
        | n < i = [] 
        | mod i  3 == 0 || mod i 10 == 3 = ' ': show i ++ iter (succ i)
        | i >= 10 = iter2 (div i 10)
        | otherwise = iter (succ i) where
            iter2 j
                | mod j 10 == 3 = ' ': show i ++ iter (succ i)
                | j > 10 = iter2 (div j 10)
                | otherwise = iter (succ i)

readLine:: IO [Int]
readLine = fmap (map read . words) getLine

main :: IO() 
main = do
    [n] <- readLine
    putStrLn (solve n)



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

def check(x,A,B):
    xp=x
    _sum=0
    while x>0:
        _sum+=x%10
        x=x//10
    return True if A<=_sum<=B else False

n=1
ans=0
while n<=N:
    ans+=n if check(n,A,B) else 0
    n+=1
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	int N,M; cin>>N>>M;
	vector<int> room(N,inf);
	vector<vector<int>> path(N, vector<int>());
	rep(i,M){
		int a,b; cin>>a>>b;
		--a; --b;
		path[a].push_back(b);
		path[b].push_back(a);
	}
	queue<int> Q;
	room[0] = -1;
	Q.push(0);
	while(!Q.empty()){
		int node = Q.front();
		Q.pop();
		for(auto x:path[node]){
			if(room[x] != inf)continue;
			room[x] = node;
			Q.push(x);
		}
	}
	bool ok = true;
	rep(i,N)if(room[i] == inf)ok = false;
	if(ok == false){cout<<"No"<<endl; return 0;}
	cout<<"Yes"<<endl;
	for(int i = 1; i<N; ++i)cout<<room[i]+1<<endl;
	return 0;
}

Measured memory_bytes: 10236
#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
import sys
 
 
def assign_color():
    _color = 1
    for m in range(vertices_num):
        if vertices_status_list[m] == -1:
            graph_dfs(m, _color)
            _color += 1
    return None
 
 
def graph_dfs(vertex, color):
    vertices_stack = list()
    vertices_stack.append(vertex)
    vertices_status_list[vertex] = color
 
    while vertices_stack:
        current_vertex = vertices_stack[-1]
        vertices_stack.pop()
        for v in adj_list[current_vertex]:
            if vertices_status_list[v] == -1:
                vertices_status_list[v] = color
                vertices_stack.append(v)
    return None
 
 
def solve():
    for relation in relation_info:
        key, value = map(int, relation.split())
        adj_list[key].append(value)
        adj_list[value].append(key)
 
    assign_color()
 
    # print(adj_list)
    for question in question_list:
        start, target = map(int, question.split())
        if vertices_status_list[start] == vertices_status_list[target]:
            print("yes")
        else:
            print("no")
    return vertices_status_list
 
 
if __name__ == '__main__':
    _input = sys.stdin.readlines()
    vertices_num, relation_num = map(int, _input[0].split())
 
    relation_info = _input[1:relation_num + 1]
 
    question_num = int(_input[relation_num + 1])
    question_list = _input[relation_num + 2:]
 
    adj_list = tuple([[] for _ in range(vertices_num)])
    vertices_status_list = [-1] * vertices_num
    ans = solve()

Measured memory_bytes: 35620
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0); 
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
  }
  int s, t;
  cin >> s >> t;
  s--;
  t--;
  vector<vector<int>> dist(n, vector<int>(3, -3));
  deque<pair<int, int>> que;
  dist[s][0] = 0;
  que.emplace_back(s, 0);
  while (que.size()) {
    int cur = que.front().first;
    int mod = que.front().second;
    que.pop_front();
    int modd = (mod + 1) % 3;
    for (int nxt : g[cur]) {
      if (dist[nxt][modd] < 0) {
        dist[nxt][modd] = dist[cur][mod] + 1;
        que.emplace_back(nxt, modd);
      }
    }
  }
  cout << dist[t][0] / 3 << endl;
  return 0;
}

Measured memory_bytes: 11264
#include <stdio.h>

int
main(int argc,char *argv[])
{
  int n; int h[110] = {};
  scanf("%d", &n);
  for(int i = 1; i <= n; i++){
    scanf("%d", &h[i]);
  }
  
  int l = 0;
  
  for(int i = 0; i < 100; i++){
    for(int j = 0; j <= n ; j++){
      if(h[j] <= 0 && h[j + 1] > 0){
        l++;
      }
      h[j] -= 1;
    }
  }
  
  printf("%d\n", l);
  
  return 0;
}
  
  

Measured memory_bytes: 128
#include <iostream>

using namespace std;

const int M = 1e9+7;
int n, k;
long long kaijo[2200];

int mpow(long long a, int n)
{
  if (n == 0) return 1;
  if (n % 2) return mpow(a, n-1) * a % M;
  return mpow(a * a % M, n / 2);
}

long long cmb(int n, int r)
{
  return kaijo[n] * mpow(kaijo[r], M-2) % M * mpow(kaijo[n-r], M-2) % M;
}

int main()
{
  cin >> n >> k;
  
  kaijo[0] = 1;
  for (int i = 1; i <= 2100; i++) {
    kaijo[i] = kaijo[i-1] * i % M;
  }
  
  for (int r = 1; r <= k; r++) {
    int ans = 0;
    if (n-k+1 >= r) {
      ans = cmb(k-1, r-1) * cmb(n-k+1, r) % M;
    }
    cout << ans << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!
 
#include <bits/stdc++.h>
using namespace std;
 
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define cout_precision cout.setf(ios::fixed); cout.precision(32);
 
using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;
 
// ------------------------------------------------------------------------------------------------
 
ll w, h, x, y;
 
void func() {
    cin >> w >> h >> x >> y;
    cout << double(w * h) / 2 << ' ';
    x = min(x, w - x); y = min(y, h - y);
    cout << (((2 * x == w) && (2 * y == h))? 1 : 0) << endl;
}

int main() {
    fast_io; cout_precision;
    ll t = 1; // cin >> t;
    for (ll i = 1; i <= t; i++) {
        func();
    }
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int n, num, right, left;
  bool flag;

  cin >> n;

  for(int i = 0; i < n; i++){
    right = 0;
    left = 0;
    flag = true;

    for(int j = 0; j < 10; j++){
      cin >> num;

      if(right < num){
        right = num;
      }else if(left < num){
        left = num;
      }else{
        flag = false;
      }
    }

    if(flag){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1152
N = int(input())
A = list(map(int,input().split()))
cnt = 0
flag = 0
for i in range(N-1):
    if A[i]==A[i+1]:
        continue
    elif A[i]<A[i+1]:
        if flag==0 or flag==1:
            flag = 1
            continue
        else:
            cnt += 1
            flag = 0
    elif A[i]>A[i+1]:
        if flag==0 or flag==-1:
            flag = -1
            continue
        else:
            cnt += 1
            flag = 0
print(cnt+1)

Measured memory_bytes: 62704
#include <iostream>
#include <algorithm>
#include <climits>
#include <numeric>
#include <iomanip>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <cstring>
#include <map>
#include <unordered_map>
#include <tuple>
 
using namespace std;
 
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define umap unordered_map
#define uset unordered_set
#define cina(s, n, a) for(int i = s; i < n; i++) cin >> a[i]
#define couta(s, n, a) for(int i = s; i < n; i++) cout << a[i] << ' '
#define copy(s, n, a, b) for(int i = s; i < n; i++) b[i] = a[i]
#define yesno(ok) cout << (ok ? "YES\n" : "NO\n")
#define mod(a, b) (b + (a % b)) % b
typedef long long ll;
typedef unsigned long long ull;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll MOD = 1e9 + 7;
void add_self (int& a, int b){ a += b; if (a >= MOD) a -= MOD; }
void mul(ll &x, ll y){
    x *= y;
    if(x >= MOD) x %= MOD;
}

ll bp(ll a, ll n){
  ll r = 1;
  while(n){
    if(n & 1) r = r % MOD * a % MOD;
    a = a % MOD * a % MOD;
    n >>= 1;
  }
  return r % MOD;
}
//-------------------------------------------------------------------------------------------------------//
void solve(){
    ll n;
    cin >> n;
    ll a, b;
    cin >> a >> b;
    ll x = 1, y = 1;
    for(ll i = n - a + 1; i <= n; i++){
        x *= i;
        x %= MOD;
    }
    for(ll i = n - b + 1; i <= n; i++){
        y *= i;
        y %= MOD;
    }
    ll f1 = 1, f2 = 1;
    for(ll i = 1; i <= a; i++){
        f1 *= i;
        f1 %= MOD;
    }
    for(ll i = 1; i <= b; i++){
        f2 *= i;
        f2 %= MOD;
    }
    x *= bp(f1,MOD - 2);
    y *= bp(f2,MOD - 2);
    x %= MOD;
    y %= MOD;
    cout << (bp(2ll, n) - 1 - x - y + 4 * MOD)%MOD;
}

int main(){
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int q = 1;
    //cin >> q;
    for(int i = 1; i <= q; i++){
        solve();
    }
}


Measured memory_bytes: 256
import sys
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7
import math
n = I()

# N円払った
# 8パーセントの消費税がかかる
# 税抜き価格xを忘れたので、求めたい。
# xは整数とする。
# あり得る価格のうち一つを出力せよ。ただし考えられるものが存在しない場合はその旨を報告せよ。

# 普通に考えたら、n / 1.08が原価
# ただし、消費税は切り捨てとなる点に注意が必要。

x = n / 1.08
c_x = math.ceil(x)

f_n = math.floor(c_x * 1.08)

if f_n == n:
    print(c_x)
else:
    print(":(")

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

using namespace std;


#define PI 3.14159265
#define int long long


int sqr(int x){
	return x * x;
}


main(){

	int n; cin >> n;

	vector <int> x(n);

	for(int i = 0; i < n; i++){
		cin >> x[i];
	}

	int record = 1e9;

	for(int i = 0; i <= 100; i++){
		int res = 0;
		for(int j = 0; j < n; j++){
			res += sqr(i - x[j]);
		}

		record = min(res, record);
	}
	

	cout << record << endl;
	
	
	
	return 0;
}

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

void print_arr(int* arr, int len) {
    for (int i = 0; i < len; i++) {
        if (i > 0) cout << ' ';
        cout << arr[i];
    }
    cout << endl;
}

void insertionSort(int* arr, int len) {
    int val;
    int j;
    print_arr(arr, len);

    for (int i = 1; i < len; i++) {
        val = arr[i];

        // j番目が大きい場合は1つずつずらす
        j = i - 1;
        while (j >= 0 && arr[j] > val) {
            arr[j + 1] = arr[j];
            j--;
        }
        arr[j + 1] = val;

        print_arr(arr, len);
    }
}

int main() {
    int N;
    int arr[100];

    cin >> N;
    for (int i = 0; i < N; i++) cin >> arr[i];

    insertionSort(arr, N);
}


Measured memory_bytes: 3088
N,L = map(int,input().split())
min_abs = float('inf')
Taste = []
for i in range(N):
  taste = L+(i+1)-1
  if(min_abs > taste):
     min_abs = abs(taste)
     min_abs_index = i
  Taste.append(taste)

Taste.pop(min_abs_index)
ans = sum(Taste)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<ll,ll> P;
typedef pair<ll,ll> Pll;
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]

int main(){
    string s; int k;
    cin >> s >> k;
    int n=s.size();
    int dp[n+1][k+1][2];
    memset(dp,0,sizeof(dp));
    dp[0][0][0]=1;
    //dp[i][j][0]=nを下回ってない、iまで見て０でないものがj個
    rep(i,n){
        rep(j,k+1){
            int x=s[i]-'0';
            if(x==0){
                dp[i+1][j][0]+=dp[i][j][0];
            }else{
                if(j>0){
                    dp[i+1][j][0]+=dp[i][j-1][0];
                    dp[i+1][j][1]+=(x-1)*dp[i][j-1][0];
                }
                dp[i+1][j][1]+=dp[i][j][0];
            }
            dp[i+1][j][1]+=dp[i][j][1];
            if(j>0)dp[i+1][j][1]+=dp[i][j-1][1]*9;
        }
    }
    cout << dp[n][k][0]+dp[n][k][1] << endl;
}


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

int main() {
    int A, B;
    cin >> A >> B;

    int ans = 0;

    for (int i = A; i < B+1; i++) {

        int a = i % 10, b = i / 10000;
        int c = i / 10 % 10, d = i / 1000 % 10;
        if ((a == b) && (c == d))
            ans++;
        /* code */
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn gcd(a: usize, b: usize) -> usize {
    if a % b == 0 {
        b
    } else {
        gcd(b, a % b)
    }
}
fn lcm(a: usize, b:usize) -> usize {
    a / gcd(a, b) * b
}



fn main() {
    let input = read_vec::<usize>();
    let (a,b,c,d) = (input[0], input[1], input[2], input[3]);

    let mut count = b - a + 1;

    let c_div = b / c - (a-1) / c;
    let d_div = b / d - (a-1) / d;
    let lcm = lcm(c, d);
    let lcm_div = b / lcm - (a-1) / lcm;

    count -= c_div;
    count -= d_div;
    count += lcm_div;

    println!("{}", count);
}

Measured memory_bytes: 4352
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <deque>

int main(){
  int n;
  scanf("%d", &n);
  std::vector<long long > a(n);
  long long maxa = 0;
  int maxindex = -1;
  for (int i=0; i<n; i++){
    scanf("%lld", &a[i]);
    if (a[i]>maxa){
      maxa = a[i];
      maxindex = i;
    }
  }
  long long close;
  for (int i=0; i<2; i++){
    if (i!=maxindex){
      close = a[i];
    }
  }

  for (int i=0; i<n; i++){
    if (abs(maxa/2.0-close)>abs(a[i]-maxa/2.0)){
      close = a[i];
    }
  }
  printf("%lld %lld\n", maxa, close);
  return 0;
}


Measured memory_bytes: 1656
/* ****mittal**** */
#include<bits/stdc++.h>
#define ll          long long int 
#define pb          push_back
#define endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define jell        998244353
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repr(i,a,b)   for(ll int i=a;i>=b;i--)
#define lbnd    lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define DEC(N)  cout << std::fixed; cout << setprecision(N);
using namespace std;
ll add(ll x,ll y)
{
return (x%hell+y%hell)%hell;
}
ll mul(ll x,ll y)
{
return ((x%hell)*(y%hell))%hell;
}
ll sub(ll x,ll y)
{
return (x-y+hell)%hell;
}
#define N  100005
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll t=1;
   //cin>>t;
    for(int ok=1;ok<=t;ok++)
    {
        ll a,b,c;
        cin>>a>>b>>c;
        ll ans=0;
        ll k;
        cin>>k;
        if(k>=a)
        {
        	ans=a;
        	k-=a;
        }
        else
        {
        	ans+=k;
        	k=0;
        }
        if(k==0)
        {
        	cout<<ans;
        	return 0;
        }
        if(k>=b)
        {
        	k-=b;
        }
        else
        {
        	k=0;
        }
        if(k==0)
        {
        	cout<<ans;
        	return 0;
        }
        if(k>=c)
        {
        	ans-=c;
        	k-=c;
        }
        else
        {
        	ans-=k;
        	k=0;
        }
        if(k==0)
        {
        	cout<<ans;
        	return 0;
        }

     
    }
    return 0;
}

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

using namespace std;

const int N = 20;
const int md = (int) 1e9 + 9;
const int pr[] = {37, 1999};

inline pair<int, int> get(string s) {
  int res[2] = {0, 0};
  for (char c : s) {
    for (int it : {0, 1}) {
      res[it] = 1LL * res[it] * pr[it] % md;
      res[it] += c - 'a';
      if (res[it] >= md) res[it] -= md;
    }
  }
  return {res[0], res[1]};
}

map<pair<int, int>, int> cnt[N];

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int m = (int) s.size();
  for (int mask = 0; mask < (1 << n); mask++) {
    string sc, tc;
    for (int i = 0; i < n; i++) {
      if ((mask >> i) & 1) {
        tc = s[i] + tc;
      } else {
        sc += s[i];
      }
    }
    ++cnt[(int) sc.size()][get(sc + tc)];
  }
  long long res = 0;
  for (int mask = 0; mask < (1 << n); mask++) {
    string sc, tc;
    for (int i = 0; i < n; i++) {
      if ((mask >> i) & 1) {
        tc = s[i + n] + tc;
      } else {
        sc += s[i + n];
      }
    }
    res += cnt[(int) tc.size()][get(tc + sc)];
  }
  cout << res << '\n';
  return 0;
}


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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define forn(i,o,n) for(int i=o;i<n;i++)
#define int long long
#define endl "\n"
#define mod 1000000007
#define mod2 998244353
#define double long double
#define pb push_back
#define mk make_pair
#define swap(x,y) (x^=y^=x^=y)
#define TT int ttt;cin>>ttt;while(ttt--)
#define oo 2000000000000000000


using namespace std;

int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b); 
}
bool isPrime(int n){
    if(n < 2)
        return 0;
    if(n < 4)
        return 1;
    if(n % 2 == 0 or n % 3 == 0)
        return 0;
    for(int i = 5; i*i <= n; i += 6)
        if(n % i == 0 or n % (i+2) == 0)
            return 0;
    return 1;
}
int modexpo(int x,int p){
    int res = 1;
    x = x%mod;
    while(p){
        if(p%2)
            res = res * x;
        p >>= 1;
        x = x*x % mod;
        res %= mod;
    }
    return res;
}

int max(int a,int b){
    if(a>b){
        return a;
    }
    return b;
}

int min(int a,int b){
    if(a<b){
        return a;
    }
    return b;
}


int32_t main(){
    IOS
    int n;
    cin>>n;
    int arr[n+1][4];
    memset(arr,0,sizeof(arr));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=3;j++){
            cin>>arr[i][j];
        }
    }
    int dp[n+1][3];
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=n;i++){
        dp[i][1]=max(dp[i-1][2],dp[i-1][3])+arr[i][1];
        dp[i][2]=max(dp[i-1][1],dp[i-1][3])+arr[i][2];
        dp[i][3]=max(dp[i-1][2],dp[i-1][1])+arr[i][3];
    }
    /*for(int i=1;i<=n;i++){
        for(int j=1;j<=3;j++){
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }*/
    cout<<max(max(dp[n][3],dp[n][1]),dp[n][2])<<endl;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
using P = pair<int, int>;

int main() {
  int H, W, K;
  cin >> H >> W >> K;
  char c[6][6];
  char cc[6][6];
  rep(i, H) {
    rep(j, W) {
      cin >> c[i][j];
    }
  }
  int ans = 0;
  for(int bit = 0; bit < (1<<(H+W)); bit++) {
    int count = 0;
    rep(i, H) {
      rep(j, W) {
        cc[i][j] = c[i][j];
      }
    }
    for(int i = 0; i < H + W; i++) {
      if(bit & (1 << i)) {
        if(i <= H - 1) {
          rep(j, W) {
            cc[i][j] = '.';
          }
        } else {
          rep(j, H) {
            cc[j][i-H] = '.';
          }
        }
      }
    }
    rep(i, H) {
      rep(j, W) {
        if(cc[i][j] == '#') {
          count++;
        }
      }
    }
    if(count == K) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

int main(){
    ll n;
    cin >> n;
    vector<ll> c(n - 1), s(n - 1), f(n - 1);
    for(int i = 0; i < n - 1; ++i){
        cin >> c.at(i) >> s.at(i) >> f.at(i);
    }
    for(int i = 0; i < n - 1; ++i){
        ll t = 0;
        for(int j = i; j < n - 1; ++j){
            t = max(t, s.at(j));
            t = f.at(j) * ((t + f.at(j) - 1) / f.at(j));
            t += c.at(j);
        }
        cout << t << endl;
    }
    cout << 0 << endl;
    return 0;
}


Measured memory_bytes: 888
gets
puts gets.split(" ").map(&:to_i).reduce(1, :lcm)

# n = gets.to_i
# c = gets.split(" ").map(&:to_i)
#
# def gcd_t(m,n)
#   if n == 0
#     return m
#   else
#     return gcd_t(n, m%n)
#   end
# end
#
# d = 1
# for i in 0..n-1
#   # d = d * c[i] / gcd_t(d, c[i])
#   # d = d * c[i] / d.gcd(c[i])
#   d = d.lcm(c[i])
# end



Measured memory_bytes: 6872
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<int,int> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};

bool vis[51][51];
int r,c;
vector<string> s(51);
vector<vector<vector<int>>> d(51,vector<vector<int>> (51));

int dfs(int y,int x,int gy,int gx,int tt){
    if(y==gy&&x==gx) return tt;
    if(vis[y][x]) return -1;
    vis[y][x] = true;
    for (int k = 0; k < 4; k++) {
        int ny = y + dy[k], nx = x + dx[k];
        if(0<=ny&&ny<r&&0<=nx&&nx<c&&s[ny][nx]=='.'){
            auto ret = dfs(ny,nx,gy,gx,tt+1);
            if(ret>=0){
                d[ny][nx].pb(tt+1);
                return ret;
            }
        }
    }
    return -1;
};



int main(){
    int m;cin >> r >> c >> m;
    for (int i = 0; i < r; i++) {
        cin >> s[i];
    }
    vector<vector<int>> a(r,vector<int> (c,0));
    auto oc = a, fc = a;
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            cin >> oc[i][j];
        }
    }
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            cin >> fc[i][j];
        }
    }
    vector<P> v(m,mp(0,0));
    for (int i = 0; i < m; i++) {
        cin >> v[i].fs >> v[i].sc;
    }
    int t = 0;
    d[v[0].fs][v[0].sc].pb(0);
    for (int i = 1; i < v.size(); i++) {
        memset(vis,false,sizeof(vis));
        auto q = dfs(v[i-1].fs,v[i-1].sc,v[i].fs,v[i].sc,t);
        t = q;
    }
    int ans = 0;
    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            if(d[i][j].size()){
                int p = oc[i][j] + fc[i][j];
                ans += p;
                for (int k = 1; k < d[i][j].size(); k++) {
                    ans += min(p,a[i][j] * (d[i][j][k] - d[i][j][k-1]));
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 8468
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define ERROR 0
ll func(ll n, ll x);
ll a[51], p[51];

int main() {
  ll n, x;
  cin >> n >> x;

  a[0] = p[0] = 1;
  for (int i = 1; i <= n; i++) {
    a[i] = 2*a[i-1]+3;
    p[i] = 2*p[i-1]+1;
  }

  cout << func(n,x) << endl;
  return 0;
}

ll func(ll n, ll x) {
if(n != 0) {
  if(x == 1) return 0;
  else if(1 < x && x <= 1+a[n-1]) return func(n-1, x-1);
  else if(x == 2+a[n-1]) return p[n-1]+1;
  else if(2+a[n-1] < x && x <= 2+2*a[n-1]) return (p[n-1]+1)+func(n-1, x-a[n-1]-2);
  else if(x == a[n]) return p[n];
  else if(n == 0) return 1;
  else if(x == 0) return 0;
  else return ERROR;
}
else return 1;
}


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

using namespace std;
using LL = long long;
using P = pair<int, int>;

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

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

    int n;
    cin >> n;
    if(n == 1){
        cout << "Hello World" << endl;
    }else{
        int a, b;
        cin >> a >> b;
        cout << a + b << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <map>
#include <utility>
#include <set>
#include <climits>

using namespace std;

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

int main() {
    int A, B;
    scanf ("%d %d", &A, &B);
    int total = 1;
    int need = 0;
    while (total < B) {
        total = total - 1 + A;
        ++need;
    }
    printf("%d\n", need);
    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#define mo 1000000007
using namespace std;
int n,i,a[100010],x,p=1;
int main()
{
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&x);
		a[x]++;
	}
	if(n&1)
	{
		if(a[0]!=1)
		{
			putchar('0');
			return 0;
		}
		for(i=2;i<n;i+=2)
			if(a[i]!=2)
			{
				putchar('0');
				return 0;
			}else p=p*2%mo;
	}else
		for(i=1;i<n;i+=2)
			if(a[i]!=2)
			{
				putchar('0');
				return 0;
			}else p=p*2%mo;
	printf("%d",p);
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
    int N, L;
    string S[100];
    cin >> N >> L;
    for (int i = 0; i < N; ++i) cin >> S[i];

    sort(S, S + N);
    string T;
    for (int i = 0; i < N; ++i) T += S[i];

    cout << T << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

struct Edge {
    int to, id;
    Edge(int to, int id) :to(to), id(id) {}
};

vector<Edge> adj[55];

bool dfs(int now, int tar, int from, vector<int> & id) {
    if (now == tar) return true;
    
    for(auto edge: adj[now]) {
        if (edge.to == from) continue;

        if(dfs(edge.to, tar, now, id)) { id.emplace_back(edge.id); return true; }
    }
    return false;
}

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

    int n; cin >> n;
    rep(i, n-1) {
        int a, b; cin >> a >> b; --a; --b;
        adj[a].emplace_back(b, i);
        adj[b].emplace_back(a, i);
    }

    int m; cin >> m;
    vector<ll> edge_bit(m, 0);
    rep(i, m) {
        int a, b; cin >> a >> b; --a; --b;
        vector<int> ids;
        dfs(a, b, -1, ids);
        for(auto id: ids) edge_bit[i] |= 1LL<<id; 
    }

    ll ans = 0;
    rep(bit, 1<<m) {
        ll mask = 0;
        rep(i, m) if (bit>>i&1) mask |= edge_bit[i];
        int white = __builtin_popcountll(mask);

        ll val = 1LL<<(n-1-white);
        if (__builtin_popcount(bit)%2 == 0) ans += val;
        else ans -= val;
    }
    cout << ans << endl;

    return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define all(x) begin(x), end(x)
#define loop(i,n) for(int i=0; i<n; i++)
#define rep(i,a,b,c) for(int i=a; i<b; i+=c)
#define brep(i,a,b,c) for(int i=a; i>b; i-=c)
#define tc(t) int t; cin>>t; while(t--)
#define sz(v) int((v).size())
#define pb push_back


using namespace std;

void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {std::cout << x;}
void __print(unsigned x) {std::cout << x;}
void __print(unsigned long x) {std::cout << x;}
void __print(unsigned long long x) {std::cout << x;}
void __print(float x) {std::cout << x;}
void __print(double x) {std::cout << x;}
void __print(long double x) {std::cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i : x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
template <typename T> inline void inp(T &any) {cin >> any;} template <typename T, typename... U>inline void inp(T &a, U &...b) {cin >> a; inp(b...);}
#define rin(args...) ll args; inp(args);
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#define matdeb(mat,row,col) cout << #mat << "::" << endl; printmat(mat,row,col); printpartition;
#define debugv(v,n) cout << #v << ":" << endl; printv(v,0,n-1); printpartition;
#else
#define debug(x...)
#define matdeb(mat,row,col)
#define debugv(v,n)
#endif

const int maxm = 1000000000 + 7;

double startTime;
double getCurrentTime() {
	return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}


//----------->CODE BEGINS --------------->


int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

   int n;
   cin>>n;

   int ans = (int)log2(n);

   cout<<(pow(2,ans))<<endl;


}


Measured memory_bytes: 4092
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
ll mod = 1000000007;

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

template<class Type>
Type gcd(Type x, Type y)
{
	Type r;
	if (x < y) swap(x, y);

	while (0 < y) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}

template<class Type>
Type lcm(Type x, Type y)
{
	return x * y / gcd(x, y);
}

template<class Type>
bool is_prime(Type x)
{
	if (x == 2) return true;
	if (x < 2 || x % 2 == 0) return false;

	for (Type i = 3; i <= sqrt(x); i += 2) {
		if (x % i == 0) return false;
	}
	return true;
}

template<class Type>
vector<bool> eratos(Type n)
{
	vector<bool> isPrime(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	for (Type i = 2; i <= n; i++) {
		if (isPrime[i]) {
			Type j = i + i;
			while (j <= n) {
				isPrime[j] = false;
				j = j + i;
			}
		}
	}
	return isPrime;
}

bool binary_search_judge(vector<int> a, int index, int key)
{
	if (key <= a[index]) return true;
	else return false;
}

int binary_search(vector<int> a, int key)
{
	int ng = -1;
	int ok = a.size();
	while (1 < abs(ng - ok)) {
		int mid = (ng + ok) / 2;
		if (binary_search_judge(a, mid, key)) ok = mid;
		else ng = mid;
	}
	return a[ok] == key;
}

int main()
{
	int n, m;
	cin >> n >> m;
	if (n == m) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

#define null               ""
#define endl               '\n'
#define all(dat)           dat.begin(), dat.end()
#define over(msg)          cout << msg << endl, exit(0);
#define loop(i, to)        for (int i = 0; i < to; ++i)
#define cont(i, to)        for (int i = 1; i <= to; ++i)
#define circ(i, fr, to)    for (int i = fr; i <= to; ++i)
#define foreach(i, dat)    for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long          num;

using namespace std;

int n, m, w[10] = {-1, 2, 5, 5, 4, 5, 6, 3, 7, 6};
string dp[10005];
vector<int> d;

bool operator < (string a, string b) {
    if (a.size() != b.size())  return a.size() < b.size();
    loop (i, a.size()) {
        if (a[i] != b[i])  return a[i] < b[i];
    }
    return 0;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin >> n >> m;
    cont (i, m) {
        int a;
        cin >> a;
        d.push_back(a);
    }
    dp[0] = "#";
    cont (i, n) {
        for (int j : d) {
            if (i - w[j] >= 0 && dp[i - w[j]] != null) {
                string tmp = dp[i - w[j]];
                tmp += j + '0';
                if (dp[i] < tmp) {
                    dp[i] = tmp;
                }
            }
        }
    }
    dp[n].erase(dp[n].begin());
    cout << dp[n] << endl;
}


Measured memory_bytes: 41728