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

using Graph = vector<vector<int>>;
/*
*/


int main() {
   string X;
   cin >> X;
   stack<char> st;
   //st.push(X[0]);

   for(int i = 0;i<X.size();i++){
       if(X[i] == 'S'){
           st.push(X[i]);
       }
       else if(X[i] == 'T'){
           if(st.size() == 0) st.push(X[i]);
           else if(st.top() == 'S') st.pop();
           else if(st.top() == 'T') st.push(X[i]);
       }
       
   }
   cout << st.size() << endl;

}

Measured memory_bytes: 644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false


int main(void){
    ll N,K,a;
    vector<ll> A;
    
    cin >> N >> K;
    REP(i,N){
        cin >> a;A.push_back(a);
    }
    
    REP(i,N-K){
        if(A[i+K]>A[i]){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    
    return 0;
}



Measured memory_bytes: 5364
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
#define Max 1000001
#define inf INT_MAX
#define llinf LONG_LONG_MAX
#define rep(i,a,b) for(i=a;i<=b;i++)
#define rrep(i,a,b) for(i=a;i>=b;i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define pb push_back
#define pf push_front
#define F first
#define S second
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define PI 3.14159265358979311599796346854418516159057617187500
#define endl '\n'
const ll N=51,mod=1000000007;
signed main()
{
    fast;
    ll pro=1,temp,t,m,n,k,i,j,l,r,mid,x,y,z,rem,carry=0,ind,ans=0,mx=-llinf,mn=llinf,cnt=0,curr=0,prev,sum=0,flag=1,i1=-1,i2=-1;
  cin>>x>>y;
  cout<<max({x+y,x*y,x-y});
	return 0;
} 

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

int main()
{
  int N, L;
  cin >> N >> L;
  string s[N];
  for(int i = 0; i < N; i++)
    cin >> s[i];
  sort(s,s+N);
  for(int i = 0; i < N; i++)
    cout << s[i];
  cout << endl;
}

Measured memory_bytes: 256
/*
 * a.cpp
 *
 *  Created on: 2017/08/22
 *      Author: pinebooks
 */

#include <iostream>
#include <cmath>

using namespace std;

int main(void) {
  int x, a, b;
  cin >> x >> a >> b;
  if (abs(x - a) < abs(x - b))
    cout << "A" << endl;
  else
    cout << "B" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
    int n;
    cin >> n;
    int a[100500];
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    int ans = 0;
    
    int cnt = 0;
    for(int i = n - 2; i >= 0; i--){
        if(a[i] >= a[i + 1]){
            cnt++;
        }
        else cnt = 0;
        ans = max(cnt, ans);
    }
    cout << ans;
}


Measured memory_bytes: 640
#include <iostream>
#include <set>
#include <iomanip>
#include <math.h>
#include <algorithm>
#include <functional>
#include <stdio.h>
#include <vector>
#include <string>
#include <map>
#define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
//#define rep(i, n) for(int (i) = 0, TmP = (n); (i) < (int)TmP ; ++(i))
#define asort(v, n) sort((v), (v + n)) //Using array
#define vsort(v) sort((v).begin(), (v).end()) // Using vector
#define vint vector<int>
typedef long long ll;

using namespace std;

signed main(){
  int n; cin >> n;
  vector<string> list(n);
  rep(i, n) cin >> list[i];

  set<string> st;
  rep(i, n) st.insert(list[i]);
  if(st.size() != n){
    cout << "No" << endl;
    return 0;
  }

  rep(i, n - 1){
    if(list[i].back() != list[i + 1][0]){
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

}


Measured memory_bytes: 256
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

int32_t distances[20][20][20][20];

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

  int32_t H, W;
  cin >> H >> W;
  vector<vector<bool>> is_open(H, vector<bool>(W, false));
  for (int32_t row = 0; row < H; ++row) {
    string s;
    cin >> s;
    for (int32_t column = 0; column < W; ++column) {
      if (s.c_str()[column] == '.') {
        is_open[row][column] = true;
      }
    }
  }

  for (int32_t from_row = 0; from_row < H; ++from_row)
    for (int32_t from_column = 0; from_column < W; ++from_column)
      for (int32_t to_row = 0; to_row < H; ++to_row)
        for (int32_t to_column = 0; to_column < W; ++to_column) {
          if (!is_open[from_row][from_column]) {
            distances[from_row][from_column][to_row][to_column] = INT32_MAX;
          } else if (!is_open[to_row][to_column]) {
            distances[from_row][from_column][to_row][to_column] = INT32_MAX;
          } else if (from_row == to_row && from_column == to_column) {
            distances[from_row][from_column][to_row][to_column] = 0;
          } else if (abs(from_row - to_row) == 1 && from_column == to_column) {
            distances[from_row][from_column][to_row][to_column] = 1;
          } else if (from_row == to_row && abs(from_column - to_column) == 1) {
            distances[from_row][from_column][to_row][to_column] = 1;
          } else {
            distances[from_row][from_column][to_row][to_column] = INT32_MAX;
          }
        }

  for (int32_t via_row = 0; via_row < H; ++via_row)
    for (int32_t via_column = 0; via_column < W; ++via_column)
      for (int32_t from_row = 0; from_row < H; ++from_row)
        for (int32_t from_column = 0; from_column < W; ++from_column)
          for (int32_t to_row = 0; to_row < H; ++to_row)
            for (int32_t to_column = 0; to_column < W; ++to_column)
              if (distances[from_row][from_column][via_row][via_column] != INT32_MAX &&
                  distances[via_row][via_column][to_row][to_column] != INT32_MAX)
                distances[from_row][from_column][to_row][to_column] =
                    min(distances[from_row][from_column][to_row][to_column],
                        distances[from_row][from_column][via_row][via_column] +
                            distances[via_row][via_column][to_row][to_column]);
  int32_t result = INT32_MIN;
  for (int32_t from_row = 0; from_row < H; ++from_row)
    for (int32_t from_column = 0; from_column < W; ++from_column)
      for (int32_t to_row = 0; to_row < H; ++to_row)
        for (int32_t to_column = 0; to_column < W; ++to_column)
          if (distances[from_row][from_column][to_row][to_column] != INT32_MAX) {
            result = max(result, distances[from_row][from_column][to_row][to_column]);
          }

  cout << result << endl;
  return 0;
}


Measured memory_bytes: 896
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
using ll = long long;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define rep(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288

int main(){
    string s1,s2;
    cin>>s1>>s2;
    map<string,int>mp;
    cin>>mp[s1]>>mp[s2];
    string t;
    cin>>t;
    mp[t]--;
    cout<<mp[s1]<<" "<<mp[s2]<<endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env ruby
DEBUG = false
def money(index)
  [500, 100, 50][index]
end
def how_many_exact(coins, price, index)
  puts "how_many_exact #{coins}, price: #{price}, index: #{index}" if DEBUG
  results = 0
  for i in 0..coins[index] do
    selected_money = money(index) * i
    puts "  index: #{index}, i: #{i}, selected_money: #{selected_money}" if DEBUG
    next if selected_money > price
    if index == coins.length() - 1 
      puts "  HIT!" if selected_money == price if DEBUG
      results += 1 if selected_money == price
    else
      results += how_many_exact(coins, price - selected_money, index + 1)
    end
  end
  results
end
def update_coins(coins, index)
  updated_coins = coins.dup()
  updated_coins[index] = 0
  updated_coins
end

read_i = lambda { STDIN.readline().to_i() }
a, b, c = read_i[], read_i[], read_i[]
price = read_i[]
puts how_many_exact([a, b, c], price, 0)

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define per(i, n) for(int i = (n)-1; i >= 0; --i)
#define eee(a) (cerr << (#a) << ": " << (a) << endl);
#define ppp(a) (cout << (a) << endl); 
#define cop(a) for(auto x:(a)){cout << x << endl;}

using ll = long long;

constexpr int dx[4] = {1, 0, -1, 0};
constexpr int dy[4] = {0, 1, 0, -1};

constexpr char sp = ' ';
constexpr char cmm = ',';
constexpr ll MOD = 1e9+7;
constexpr ll Mod = 998244353;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;

inline ll mod(ll a, ll m=MOD){return (a%m+m)%m;}
inline ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
inline ll inv(ll n, ll m=MOD){
    ll a = n, b = m, x = 1, y = 0;
    while(b){
        ll t = a/b;
        a -= t*b;
        swap(a, b);
        x -= t*y;
        swap(x, y);
    }
    return mod(a, m); 
}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e, ll m=MOD){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
    s<<'[';for(size_t i=0;i<v.size();++i){s << v[i];if(i < v.size()-1) s << ", ";}s<<']';return s;
}
struct __{ __(){ /* cin.tie(0); ios::sync_with_stdio(0); */ cout<<fixed<<setprecision(15); } };

int main(){

    int n;
    scanf("%d", &n);
    string s;
    cin >> s;

    int cnt = 0;

    rep(i, n-2){
        if(s.substr(i, 3) == "ABC"){
            ++cnt;
            i += 2;
        }
    }
    ppp(cnt);

    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String A = "CODEFESTIVAL2016";
		int count = 0;

		for (int i=0; i<S.length() ; i++) {
			if(S.charAt(i) != A.charAt(i)){
				count++;
			}
		}

		System.out.println(count);

		sc.close();
	}

}

Measured memory_bytes: 10064
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
using namespace std;


typedef long long ll;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)

const int mod = 1000000007;

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

  vector<int> h(n);
  rep(i, n) cin >> h[i];
  int pre = -999;
  for(int i = 0; i < n; ++i){
    if(pre <= h[i] - 1){
      pre = h[i] - 1;

    } else if(pre <= h[i]){
      pre = h[i];
    } else {
      puts("No");
      return 0;
    }
  }

  puts("Yes");

}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <utility>
#include <map>
int needleX[4] = { -1,0,1,0 };
int needleY[4] = { 0,1,0,-1 };
bool dfs(int start,int goal,int x, int y, int goalx, int goaly, std::vector<std::vector<bool>>&canGo) {
    if (x == goalx && y == goaly) { return true; }
    if (start == -1 || goal == -1) { return false; }
    if (start != goal) { return false; }
    canGo[y][x] = false;
    for (int i = 0; i < 4; i++) {
        int next_x = x + needleX[i];
        int next_y = y + needleY[i];

        if (canGo[next_y][next_x]) {
            bool flag = dfs(start, goal,next_x, next_y, goalx, goaly, canGo);
            if (flag)
                return true;
        }
    }
    return false;
}
int main(void) {
    int h, w, n;
    std::cin >> w >> h;
    std::vector<std::string> ans;
    while(h!=0|| w!=0){
        int color=-1, orient, leftX, leftY;
        int sx, sy, gx, gy;
        std::cin >> sx >> sy >> gx >> gy;
        std::vector<std::vector<int>> board(h + 2, std::vector<int>(w+ 2, 0));
        std::vector<std::vector<bool>> canGo(h + 2, std::vector<bool>(w + 2, false));
        std::cin >> n;
        int start = -1, goal = -1;
        for (int i = 0; i < n; i++) {
            std::cin >> color >> orient >> leftX >> leftY;


            if (orient == 0) {
                for (int j = 0; j <= 3; j++) {
                    for (int k = 0; k <= 1; k++) {
                        board[leftY + k][leftX + j] = color;
                        if (leftX + j == sx && leftY + k == sy) {
                            start = color;
                        }
                        else if (leftX + j == gx && leftY + k == gy) {
                            goal = color;
                        }
                    }
                }

            }
            else {
                for (int j = 0; j <= 1; j++) {
                    for (int k = 0; k <= 3; k++) {
                        board[leftY + k][leftX + j] = color;
                        if (leftX + j == sx && leftY + k == sy) {
                            start = color;
                        }
                        else if (leftX + j == gx && leftY + k == gy) {
                            goal = color;
                        }
                    }
                }
            }
        }
        /*for (int i = 0; i <= w; i++) {
            for (int j = 0; j <= h; j++) {
                std::cout << board[i][j] << " ";
            }
            std::cout << std::endl;
        }*/
        if (start != -1) {
            for (int i = 0; i <= h+1; i++) {
                for (int j = 0; j <= w+1; j++) {
                    if (board[i][j] == start) {
                        canGo[i][j] = true;
                    }
                }
            }
        }
        bool result = dfs(start,goal,sx, sy, gx, gy, canGo);
        if (result) { ans.push_back("OK"); }
        else { ans.push_back("NG"); }
        std::cin >> w >> h;
    }
    for (std::string i : ans) {
        std::cout << i << std::endl;
    }
    return 0;
}


Measured memory_bytes: 3124
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<stack>
#define MAXN 50
#define MAXM 100
#define MO 1000000007
using namespace std;
struct edge
{
	int u,v,id;
	edge(){};
	edge(int _u,int _v,int _id):u(_u),v(_v),id(_id){};
};
int N,M,K;
vector<edge> G[MAXN+5];
stack<edge> st;
vector<int> need;
int dfn[MAXN+5],low[MAXN+5],cnt=0;
bool vis[MAXN+5],vispoi[MAXN+5];
int blocnt,bloes[MAXN+5],blopoi[MAXN+5];
int fact[MAXM*100+5],inv[MAXM*100+5];
int PowMod(int a,int b)
{
	int ret=1;
	while(b)
	{
		if(b&1)
			ret=1LL*ret*a%MO;
		a=1LL*a*a%MO;
		b>>=1;
	}
	return ret;
}
void prepare()
{
	fact[0]=1;
	for(int i=1;i<=MAXM*100;i++)
		fact[i]=1LL*fact[i-1]*i%MO;
	inv[MAXM*100]=PowMod(fact[MAXM*100],MO-2);
	for(int i=MAXM*100-1;i>=0;i--)
		inv[i]=1LL*inv[i+1]*(1LL*i+1LL)%MO;
}
int gcd(int a,int b)
{
	if(b==0)
		return a;
	return gcd(b,a%b);
}
int C(int n,int m)
{
	if(n<m)
		return 0;
	return 1LL*fact[n]*inv[m]%MO*inv[n-m]%MO;
}
void DFS(int u,int fa)
{
	vispoi[u]=true;
	dfn[u]=low[u]=++cnt;
	for(int i=0;i<G[u].size();i++)
	{
		int v=G[u][i].v;
		if(dfn[v]==0)
		{
			st.push(G[u][i]);
			DFS(v,u);
			low[u]=min(low[u],low[v]);
			if(low[v]>=dfn[u])
			{
				edge fro;
				need.clear();
				blocnt++;
				do
				{
					fro=st.top();st.pop();
					if(vis[fro.u]==0)	blopoi[blocnt]++,need.push_back(fro.u);
					if(vis[fro.v]==0)	blopoi[blocnt]++,need.push_back(fro.v);
					vis[fro.u]=vis[fro.v]=true;
					bloes[blocnt]++;
				}while(fro.u!=u||fro.v!=v);
				for(int j=0;j<need.size();j++)
					vis[need[j]]=false;
			}
		}
		else if(v!=fa)
		{
			if(dfn[u]>dfn[v])
				st.push(edge(G[u][i]));
			low[u]=min(low[u],dfn[v]);
		}
	}
}
int main()
{
	prepare();
	scanf("%d %d %d",&N,&M,&K);
	int a,b;
	for(int i=1;i<=M;i++)
	{
		scanf("%d %d",&a,&b);
		G[a].push_back(edge(a,b,i));
		G[b].push_back(edge(b,a,i));
	}
	for(int i=1;i<=N;i++)
		if(vispoi[i]==false)
			DFS(i,-1);
	int ans=1;
	for(int i=1;i<=blocnt;i++)
	{
		int tot=0;
		if(blopoi[i]==bloes[i]+1)
		{
			tot=PowMod(K,bloes[i]);
		}
		else if(blopoi[i]==bloes[i])
		{
			for(int j=1;j<=bloes[i];j++)
				tot=(1LL*tot+1LL*PowMod(K,gcd(j,bloes[i])))%MO;
			tot=1LL*tot*PowMod(bloes[i],MO-2)%MO;
		}
		else
			tot=C(bloes[i]+K-1,K-1);
		ans=1LL*ans*tot%MO;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines
#rstrip().decode('utf-8')

#import numpy as np
#import operator
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10**7)

#map(int,input().split())

def prime(n):
    if n >= 2:
        prime_nums = [2]
        for i in range(3, n + 1):
            for p in prime_nums:
                if i % p == 0:
                    break
            else:
                prime_nums.append(i)
    return prime_nums

def main():
    n=int(input())
    p=prime(5555)
    li=[]
    i=0
    while len(li)<56:
        if p[i]%5==1:
            li.append(p[i])
        i+=1

    print(*li[:n])






if __name__ == '__main__':
    main()

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

void solve() {
    int N, M, Q;
    cin >> N >> M >> Q;
    vector<int> L(M+1), R(M+1);
    vector<vector<int>> lr(N+1,vector<int>(N+1));
    rep(i,M) {
        cin >> L[i+1] >> R[i+1];
        lr[L[i+1]][R[i+1]]++;
    }
    rep(i,N) rep(j,N+1) lr[i+1][j] += lr[i][j];
    rep(i,N+1) rep(j,N) lr[i][j+1] += lr[i][j];
    int p, q;
    rep(i,Q) {
        cin >> p >> q;
        cout << lr[N][q] - lr[p - 1][q] << endl;
    }
    return;
}

int main() {
    solve();
}


Measured memory_bytes: 3456
#include<iostream>
using namespace std;
#include<math.h>

#define MAX 1000000
int min(int a, int b);

int min(int a, int b) {
    if (a > b)
        return b;
    else
        return a;
}
int main()
{
    while (1)
    {
        int y, z, e, ans = MAX;
        cin >> e;
        if (!e)
            break;
        for (z=0; z*z*z <= e; z++) {
            y = (int)sqrt((double)e - z*z*z);
            ans = min(ans, e - y*y - z*z*z + y + z);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
class LazySegmentTree
	def initialize(n, l = 0, r = n-1)
		@range_min = l
		@range_max = r
		@start = 0
		@between = 0
		@end = 0
		if l == r
		else
			c = (l + r) / 2
			@left_child = self.class.new(n, l, c)
			@right_child = self.class.new(n, c+1, r)
		end
	end

	attr_reader :range_min, :range_max

	def add_start(x, bits)
		if @range_min == @range_max
			@start |= bits
		else
			if x <= @left_child.range_max
				@left_child.add_start(x, bits)
			else
				@right_child.add_start(x, bits)
			end
		end
	end

	def add_end(x, bits)
		if @range_min == @range_max
			@end |= bits
		else
			if x <= @left_child.range_max
				@left_child.add_end(x, bits)
			else
				@right_child.add_end(x, bits)
			end
		end
	end

	def add_between(x, y, bits)
		return if x > y

		if x == @range_min && y == @range_max
			@between |= bits
		else
			lr = @left_child.range_max
			@left_child.add_between(x, lr < y ? lr : y, bits)
			rl = @right_child.range_min
			@right_child.add_between(rl > x ? rl : x, y, bits)
		end
	end

	def force
		if @range_min != @range_max
			@left_child.take(@start, @between, @end)
			@right_child.take(@start, @between, @end)
		end
		@star = @between = @end = 0
	end

	def take(start, between, finish)
		@start |= start
		@between |= between
		@end |= finish
	end

	def net_start_count(x)
		if @range_min == @range_max
			bits = @start
			bits -= bits & @end
			bits -= bits & @between
			bits.to_s(2).count("1")
		else
			force
			if x <= @left_child.range_max
				@left_child.net_start_count(x)
			else
				@right_child.net_start_count(x)
			end
		end
	end

	def net_end_count(x)
		if @range_min == @range_max
			bits = @end
			bits -= bits & @start
			bits -= bits & @between
			bits.to_s(2).count("1")
		else force
			if x <= @left_child.range_max
				@left_child.net_end_count(x)
			else
				@right_child.net_end_count(x)
			end
		end
	end
end


ones = [0]
10000.times{
	ones << ((ones[-1] << 1) | 1)
}

t = Time.new

loop {
	n, r = gets.split.map(&:to_i)
	break if n == 0


	a = (1..n).map{ gets.split.map(&:to_i) }
	max_x = a.map{|_,_,x2,_| x2}.max
	max_y = a.map{|_,_,_,y2| y2}.max
	v_st = LazySegmentTree.new(max_x+1)
	h_st = LazySegmentTree.new(max_y+1)

	a.each {|x1, y1, x2, y2|
		bits = ones[y2-y1] << y1
		v_st.add_start(x1, bits)
		v_st.add_between(x1+1, x2-1, bits) if x1+1 < x2
		v_st.add_end(x2, bits)
		bits = ones[x2-x1] << x1
		h_st.add_start(y1, bits)
		h_st.add_between(y1+1, y2-1, bits) if y1+1 < y2
		h_st.add_end(y2, bits)
	}

	area = 0
	for x in 0..max_x
		area += v_st.net_start_count(x) * (10000-x)
		area -= v_st.net_end_count(x) * (10000-x)
	end
	p area

	if r == 2
		len = 0
		for x in 0..max_x
			len += v_st.net_start_count(x)
			len += v_st.net_end_count(x)
		end
		for y in 0..max_y
			len += h_st.net_start_count(y)
			len += h_st.net_end_count(y)
		end
		p len
	end
}

Measured memory_bytes: 87176
n, m = map(int, input().split())
A = set({i for i in range(1,m+1)})
for i in range(n):
    row = list(map(int, input().split()))
    k = row[0]
    A_i = row[1:]
    A = A & set(A_i)
print(len(list(A)))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int prime[100100];


int main()
{

    int n=700;
    int cnt = 0;
    string s;
    cin >> s;
    for(int i=0; i<3; i++)
    {
        if(s[i]=='o')cnt++;
    }

    cout << n+cnt*100 << endl;
}


Measured memory_bytes: 3560
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class B { public static void Main() => (new Solver()).Solve(); }

public class Solver
{
	public void Solve()
	{
		long X = GetLong();
		long Y = GetLong();

		for(long i = 0; i <= X; i++)
		{
			if(2 * i + 4 * (X - i) == Y)
			{
				WriteLine("Yes");
				return;
			}
		}
		WriteLine("No");
	}
}

public static class MyIO
{
	private static string[] args = new string[0];
	private static int cnt = 0;
	private static IEnumerable<string> getArgs(long N) => Range(0, N).Select(_ => getArg());
	private static string getArg()
	{
		if(cnt == args.Length) { args = Console.ReadLine().Split(); cnt = 0; }
		return args[cnt++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => getArgs(N).Select(int.Parse).ToArray();
	public static long[] GetLongs(long N) => getArgs(N).Select(long.Parse).ToArray();
	public static double[] GetDoubles(long N) => getArgs(N).Select(double.Parse).ToArray();
	public static decimal[] GetDecimals(long N) => getArgs(N).Select(decimal.Parse).ToArray();
	public static string[] GetStrings(long N) => getArgs(N).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) < 0) x = y; }
	public static void chmin<T>(ref T x, T y) where T : IComparable<T> { if(x.CompareTo(y) > 0)	x = y; }
	public static void swap<T>(ref T x, ref T y) { T tmp = x; x = y; y = tmp; }
	public static long rightShift(long x, long y) => (x >> (int)y);
	public static long leftShift(long x, long y) => (x << (int)y);
	public static bool contains(long s, long x) => (rightShift(s, x) & 1L) == 1L;
	public static long gcd(long x, long y) => (y == 0) ? x : gcd(y, x % y);
	public static long lcm(long x, long y) => (x / gcd(x,y)) * y;	
	public static IEnumerable<int> Range(long start, long count) => Enumerable.Range((int)start, (int)count);
	public static void Sort(this List<string> source) => source.Sort(StringComparer.Ordinal);
}


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

string a[] = {"+++=", "++-=", "+-+=", "+--=", "-++=", "-+-=", "--+=", "---="};
string n;

bool flag(int i) {
	if (i == 0) {
		return ((n[0] - '0') + (n[1] - '0') + (n[2] - '0') + (n[3] - '0')) == 7;
	}
	else if (i == 1) {
		return ((n[0] - '0') + (n[1] - '0') + (n[2] - '0') - (n[3] - '0')) == 7;
	}
	else if (i == 2) {
		return ((n[0] - '0') + (n[1] - '0') - (n[2] - '0') + (n[3] - '0')) == 7;
	}
	else if (i == 3) {
		return ((n[0] - '0') + (n[1] - '0') - (n[2] - '0') - (n[3] - '0')) == 7;
	}
	else if (i == 4) {
		return ((n[0] - '0') - (n[1] - '0') + (n[2] - '0') + (n[3] - '0')) == 7;
	}
	else if (i == 5) {
		return ((n[0] - '0') - (n[1] - '0') + (n[2] - '0') - (n[3] - '0')) == 7;
	}
	else if (i == 6) {
		return ((n[0] - '0') - (n[1] - '0') - (n[2] - '0') + (n[3] - '0')) == 7;
	}
	else {
		return ((n[0] - '0') - (n[1] - '0') - (n[2] - '0') - (n[3] - '0')) == 7;
	}
}

int main() {
	cin >> n;

	int i;
	for (i = 0; i < 8; i++) {
		if (flag(i))break;
	}

	for (int j = 0; j < 4; j++) {
		cout << n[j] << a[i][j];
	}
	cout << "7" << endl;
}

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

ll calc(vector<ll> A) {
  int side = 0;
  int N = A.size();
  ll ans = 1;
  for (int i = 1; i < N; i++) {
    if (side == 0 && A[i] > A[i - 1]) {
      side = 1;
    } else if (side == 0 && A[i] < A[i - 1]) {
      side = -1;
    } else if ((A[i] < A[i - 1] && side == 1) || (A[i] > A[i - 1] && side == -1)) {
      side = 0;
      ans++;
    }
  }
  return ans;
}

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

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

  ll ans = calc(A);
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;
using vp = vector<P>;
using vpp = vector<pair<P, P>>;
using vvp = vector<vp>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion

int main()
{
    int n, k;
    cin >> n >> k;
    vint a(n + 1);
    rep(i, n) cin >> a[i];

    vint b(n);
    rep(i, k)
    {
        bool maxed = true;
        b = vint(n);
        rep(j, n)
        {
            int l = a[j];
            int low = max(0, j - l);
            int hig = min(n - 1, j + l);

            b[low]++;
            if (hig < n - 1)
                b[hig + 1]--;
        }

        a = vint(n + 1);
        rep(j, n)
        {
            if (j > 0)
                a[j] += a[j - 1];
            a[j] += b[j];
            maxed = maxed && a[j] >= n;
        }

        if (maxed)
        {
            break;
        }
    }

    rep(i, n)
    {
        cout << a[i] << " ";
    }

    cout << endl;
    return 0;
}

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

int main() {
    size_t n, m;
    cin >> n;
    vector<string> b( n );
    for ( size_t i = 0; i < n; ++i )
        cin >> b.at( i );
    cin >> m;

    vector<string> r( m );
    for ( size_t i = 0; i < m; ++i )
        cin >> r.at( i );
    int a = 0;
    for ( size_t i = 0; i < n; ++i ) {
        int t = 0;
        for ( size_t k = 0; k < n; ++k )
            if ( b.at( i ) == b.at( k ) )
                ++t;
        for ( size_t k = 0; k < m; ++k )
            if ( b.at( i ) == r.at( k ) )
                --t;
        if ( t > a )
            a = t;
    }
    cout << a;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main()
{
  ll H;
  cin >> H;
  if(H == 1){
    cout << "1" << endl;
    return 0;
  }
  if(H%2==1){
    H-=1;
  }
  ll tmp=0;
  while(H!=0){
    H/=2;
    tmp++;
    // cout << H << endl;
  }
  tmp--;
  ll ans=2;
  for(ll i=0;i<tmp;i++ ){
    ans*=2;
  }
  cout << ans-1 << endl;
  return 0;
}


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

int main( void )
{
    string a,b,c;
    cin >> a >> b >> c;
    
    int la = a.length(),lb = b.length();
    if ( a[la-1] == b[0] && b[lb-1] == c[0] )
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define llp 1000000007
#define mod 1000000007

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;
int n;
vi N;
int ct=0;
int eval(){
    // deb(N);
    int ans=0;
    for(int i=0;i<N.size();i++){
        ans=ans*10+N[i];
    }
    return ans;
}
bool check(){
    int f=0;
    for(int i=0;i<N.size();i++){
        if(N[i]==3){
            f=1;
        }
    }
    if(!f)return false;
    f=0;
    for(int i=0;i<N.size();i++){
        if(N[i]==5){
            f=1;
        }
    }
    if(!f)return false;
    f=0;
    for(int i=0;i<N.size();i++){
        if(N[i]==7){
            f=1;
        }
    }
    if(!f)return false;
    return true;
}
void fun(){
    if(eval()>n){
        return;
    }
    else{
        N.PB(3);
        if(eval()<=n && check())ct++;
        fun();
        N.pop_back();
        N.PB(5);
       if(eval()<=n && check())ct++;
        fun();
        N.pop_back();
        N.PB(7);
       if(eval()<=n && check())ct++;
        fun();
        N.pop_back();
    }

}
int32_t main(){
	ios::sync_with_stdio(false);
    cin>>n;
    fun();
    cout<<ct<<"\n";

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define for0(n) for(i=0; i<(n); i++)
#define for1(n) for(i=1; i<=(n); i++)


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll _,i,j,n,a,b,e,k,u,t,x=1,m,y,q,f=1,c=0,d=0,l,p,z,o,r,g;
    string ss,s;
    cin>>n;
    ll aa[n];
    for0(n)
    {
        cin>>aa[i];
    }
    x=1000;
    for0(n-1)
    {
        if(aa[i]<aa[i+1])
        {
            if(aa[i]<=x)
            {
                c=x/aa[i];
                x%=aa[i];
                x+=c*aa[i+1];
                c=0;
            }
        }
    }
    if(c>0)
    {
        x+=c*aa[n-1];
    }
    cout<<x<<endl;
}



Measured memory_bytes: 3608
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n;
  string array[105];
  string pre;
  cin>>n;
  cin>>pre;
  array[0]=pre;
  for(int i=1;i<n;i++){
    string str;
    cin>>str;
    if(str[0]==pre[pre.size()-1]){
      bool success=true;
      for(int j=0;j<i&&success;j++){
	if(array[j]==str){
	  success=false;
	}
      }
      if(success){
	array[i]=str;
	pre=str;
      }else{
	cout<<"No"<<endl;
	return(0);
      }
    }else{
      cout<<"No"<<endl;
      return(0);
    }
  }
  cout<<"Yes"<<endl;
  return(0);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <math.h>

int main() {

    int n, a;

    scanf("%d", &n);

    int arr[n];

    for (int i = 0; i < n; i++) {
        scanf("%d", &a);
        arr[i] = a;
    }

    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            //printf("%d %d\n", arr[i], arr[j]);
            if (arr[i] < arr[j]) {
                int temp = arr[i];
                arr[i] = arr[j];
                arr[j] = temp;
            }
        }
    }

    int sum01 = 0;
    int sum02 = 0;
    for (int i = 0; i < n; i++) {
        if (i % 2 == 0) {
            sum01 += arr[i];
        } else {
            sum02 += arr[i];
        }
    }

    printf("%d\n",sum01-sum02);


    return 0;
} 

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

arr = [[] for i in range(n)]

for i in range(m):
	a, b = list(map(int, input().split()))
	arr[a-1].append(b)	

cnt = 0	
sting = n+1
for i,isl in enumerate(arr):
	isl.sort()
	if sting == i+1:
		cnt += 1
		sting = n+1

	if len(isl) == 0:
		continue
		
	if isl[0] < sting:
		sting = isl[0]
print(cnt)

Measured memory_bytes: 24216
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()

using ll = long long;
using ull = unsigned long long;
using vb = vector<bool>;
using vi = vector<int>;
using vll = vector<ll>;
using vs = vector<string>;
using vvb = vector<vb>;
using vvi = vector<vi>;
using vvll = vector<vll>;

template<typename A, typename T>void assign2d(A&arr, ll H, ll W, T t) { arr.resize(H); REP(i, H) arr[i].assign(W, t); }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { int n = v.size(); REP(i, n)os << v[i] << (i == n - 1 ? "" : " "); return os; }
template <class T = int> inline T IN() { T x; cin >> x; return x; }
template<class T> inline void OUT(const T &x) { cout << x << "\n"; }
void YESNO(bool c) { OUT(c ? "YES" : "NO"); };
void YesNo(bool c) { OUT(c ? "Yes" : "No"); };
void yesno(bool c) { OUT(c ? "yes" : "no"); };
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); /*cout << fixed << setprecision(6);*/ } } pre__;

int main() {
	int N;
	string S;
	cin >> N >> S;
	int x = 0;
	int ans = 0;
	REP(i, N) {
		if (S[i] == 'I')x++;
		else x--;
		ans = max(ans, x);
	}
	OUT(ans);
	return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define itn long long

typedef long long ll;
typedef pair<ll,ll> p;


int main()
{
  string s;
  cin >> s;
  for(int i = 0; i < int(s.size()); i++)
  {
    if(s[i] == 'B')
    {
      if(i == 0){
        s = s.substr(1, int(s.size())-1);
      }
      else
      {
        s = s.substr(0, i-1) + s.substr(i+1);
      }
      i = -1;
    }
  }
  cout << s << endl;
}

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

int main(void) {
   
   int N;
   
   scanf("%d",&N);
  
   int digit = log10(N) + 1;
   int d;
   int ans = 0;

   for (d = digit - 1; d >= 1; d--) {
      if (d%2 == 1) {
         ans = ans + 9*pow(10, d - 1);
      }
   }
   
   if (digit%2 == 1) {
      ans = ans + N - pow(10, digit - 1) + 1;
   }
   
   printf("%d\n", ans);
   
   
   return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 105
#define INF 100000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 100005;
const int MOD = 1000000007;
int main(){
    int n,m;
    cin>>n>>m;
    vector<int>a(m);
    REP(i,m)IN(a[i]);
    sort(ALL(a));
    vector<int>b(m-1);
    REP(i,m-1){
        b[i]=a[i+1]-a[i];    
    }
    sort(ALL(b));
    ll ans=0;
    if(m>n){
        REP(i,m-n){
            ans+=b[i];
        }
    }

    OUT(ans);
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main()
{
    int n, days, x, y;
    cin >> n >> days >> x >> y;
    if(n >= days){
      cout << y * (n - days) + x * days;
    }else{
      cout << n * x;
    }
    cout << '\n';
    return 0;
}


Measured memory_bytes: 256
n,k = map(int,input().split())
r,s,p = map(int,input().split())
hands = {'r':r,'s':s,'p':p}
win = {'r':p,'s':r,'p':s}
t = input()

score =[]
for i in range(n):
    enemy = t[i]
    if i - k >= 0 and t[i - k] == enemy and score[i-k]:
        score.append(0)
    else:
        score.append(win[enemy])
print(sum(score))

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

#define int long long
#define ll long long
#define vll vector<int>
#define mset(a) memset(a,0,sizeof(a))
#define pb push_back
#define range(c) c.begin() , c.end()
#define forn(i,n) for(ll i=0; i<(int)n; ++i)
#define for1(i,n) for(ll i=1; i<(int)n; ++i)
#define endl '\n'
#define MOD 1000000007
#define pii pair<int,int>
#define test ll t;cin>>t;while(t--)
using namespace std;

vector<bool> sieve(ll n){
    vector<bool>prime(n+1,true);
    prime[0]=prime[1]=false;
    for(ll i=2; i<=n; ++i){
        if(prime[i]&&(i*i)<=n)
        for(ll j=i*i; j<=n; j+=i)prime[j]=false;
    }
    return prime;
}

ll power(ll a, ll b, ll m = MOD) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

//////////////////////////////////////////////////////////////

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    

    int n;cin>>n;
    vector<double>p(n);
    forn(i,n) cin>>p[i];

    long double dp[n+1][n+1];
    memset(dp, (long double)0.0, sizeof(dp));

    dp[0][0] = 1.0;

    for1(i,n+1) {
        forn(j, n+1) {
            // if(i==0 && j==0)
            // continue;

            if(j==0) {
                dp[i][j] = (1.0-p[i-1]) * dp[i-1][j];
            } else {
                dp[i][j] = p[i-1]*dp[i-1][j-1] + (1.0-p[i-1])*dp[i-1][j];
            }
        }
    }    

    long double res = 0.0;
    for(int i=n/2+1; i<n+1; ++i)
    res+=dp[n][i];

    cout<<fixed<<setprecision(10)<<res;

    return 0;
}


Measured memory_bytes: 140928
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    S = lines.pop(0)
    c = 0
    res = 0
    for i in S:
        if i in 'AGCT':
            c += 1
        else:
            c = 0
        res = max(res, c)
    print(res)

lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)


Measured memory_bytes: 2940
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

typedef long long ll;

using namespace std;


bool kaku[90][90],kouri[90][90];

int dfs(int a,int b){
    int re=0,me;
    if(a>=90 || a<0 || b>=90 || b<0) return 0;
    if(kaku[a][b] || !kouri[a][b]) return 0;
    kaku[a][b]=true;
    
    
    me=dfs(a-1,b);
    re=max(re,me);
    me=dfs(a,b-1);
    re=max(re,me);
    me=dfs(a,b+1);
    re=max(re,me);
    me=dfs(a+1,b);
    re=max(re,me);
    
    kaku[a][b]=false;
    return re+1;
}

int main(){
    int m,n,a,ans,me;

    while(1){
        ans=0;
        
        scanf("%d%d",&m,&n);
        if(m+n==0)break;
        
        for(int i=0;i<n;i++)
            for(int j=0;j<m;j++){
                scanf("%d",&a);
                kouri[i][j]=(a==1);
            }
        
        for(int i=0;i<n;i++)
            for(int j=0;j<m;j++){
                me=dfs(i,j);
                ans=max(ans,me);
            }
        
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <vector>
#include <sstream>
//#include <fstream>

using namespace std;

int main()
{
//	cut here before submit 
//	freopen("testcase.di", "r", stdin);
	const int small[][3] = { 
					{ 0, 1 ,0 },
					{ 1, 1, 1 },
					{ 0, 1, 0 } 
				};
	const int medium[][3] = {
					{ 1, 1, 1 },
					{ 1, 1, 1 },
					{ 1, 1, 1 }
				};
	const int large[][5] = {
					{ 0, 0, 1, 0, 0 },
					{ 0, 1, 1, 1, 0 },
					{ 1, 1, 1, 1, 1 },
					{ 0, 1, 1, 1, 0 },
					{ 0, 0, 1, 0, 0 }
				};
										
	string str = "";
	vector <vector <int> > paper (14, vector <int> (14, 0 ) );
	vector <int> px, py, size;

	while (getline (cin, str ) ){
		int x, y, s;
		while (str.find(',') != string::npos ){
			str = str.replace (str.find(','), 1, " " );
		} // end while
		stringstream ss (str );
		ss >> x >> y >> s;
		px.push_back(x); py.push_back(y); size.push_back(s);		
	} // end for
	
	int n = px.size();
	int i,j,k;

	for (k = 0; k < n; ++k ){
		if (size[k] == 1 ){
			for (i = -1; i <= 1; ++i ){
				for (j = -1; j <= 1; ++j ){
					paper[ py[k] + 2 + i][ px[k] + 2 + j] += small[i+1][j+1];
				} // end for
			} // end for
		}else if (size[k] == 2 ){
			for (i = -1; i <= 1; ++i ){
				for (j = -1; j <= 1; ++j ){
					paper[ py[k] + 2 + i][ px[k] + 2 + j] += medium[i+1][j+1];
				} // end for
			} // end for
		}else if (size[k] == 3 ){
			for (i = -2; i <= 2; ++i ){
				for (j = -2; j <= 2; ++j ){
					paper[ py[k] + 2 + i][ px[k] + 2 + j] += large[i+2][j+2];
				} // end for
			} // end for
		} // end if
	} // end for

	int res = 0;
	int maxd = 0;
	for (i = 2; i < 12; ++i ){
		for (j = 2; j < 12; ++j ){
			if (paper[i][j] == 0){
				++res;
			}else{
				maxd = max (maxd, paper[i][j]);
			} // end if
		} // end for
	} // end for

	cout << res << endl;
	cout << maxd << endl;
		
	return 0;
}

Measured memory_bytes: 0
import sys
input = sys.stdin.readline
from operator import itemgetter
import itertools

def main():
    n, m = map(int, input().strip().split())
    lis = [[] for _ in range(n)]
    visited = [-1] * n
    for _ in range(m):
        a, b = list(map(lambda x: x-1, map(int, input().strip().split())))
        lis[a].append(b)
        lis[b].append(a)
    
    ans = 0
    for path in itertools.permutations(range(n), n):
        if path[0] != 0:
            continue
        c = True
        for i in range(n-1):
            pi1 = path[i+1]
            pi = path[i]
            # print(path)
            if pi1 not in lis[pi]:
                c = False
                break
        if c:
            ans += 1
    print(ans)

if __name__ == '__main__':
    main()


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


int main() {
  string s,t;
  cin >> s >> t;
  int count = 0;
  rep(i,s.size()) {
    if (s.at(i) != t.at(i)) {
      count++;
    }
  }
  cout << count;
}

Measured memory_bytes: 3916
#include <bits/stdc++.h>
        #include<iostream>
        #include<cstdio>
        #include<vector>
        #include<queue>
        #include<map>
        #include<cstring>
        #include<string>
        #include <math.h>
        #include<algorithm>
        #include<functional>
   //    #define int long long
        #define inf  1000000007
        #define pa pair<int,int>
#define ll long long
        #define pal pair<ll,ll>
        #define ppa pair<int,pa>
        #define EPS (1e-10)
        #define equals(a,b) (fabs((a)-(b))<EPS)

        using namespace std;

 
        int dx[4] = {1, 0, -1, 0};
        int dy[4] = {0, 1, 0, -1};
        //----------------kokomade temple------------
int dis[10005];
vector<ppa> G;
int V,E,r;
int main(){
	
cin>>V>>E>>r;
	for(int i=0;i<V;i++) dis[i]=inf;
	for(int i=0;i<E;i++){
		int z,zz,zzz;
		cin>>z>>zz>>zzz;
		G.push_back(make_pair(zzz,make_pair(z,zz)));
	}
	dis[r]=0;
	
	for(int i=0;i<V-1;i++){
		for(int j=0;j<E;j++){
			if(dis[G[j].second.first]==inf) continue;
			dis[(G[j].second).second]=min(dis[G[j].second.first]+G[j].first,dis[G[j].second.second]);
		}
	}
	
	
	for(int j=0;j<E;j++){
		if(dis[G[j].second.first]==inf) continue;
		if(dis[G[j].second.second]>dis[G[j].second.first]+G[j].first ){
			cout<<"NEGATIVE CYCLE"<<endl;
			return 0;
		}
		
	}
	
	
	for(int i=0;i<V;i++){
		if(dis[i]==inf) cout<<"INF"<<endl;
		else cout<<dis[i]<<endl;
	}
	
	
	return 0;
	
        }

Measured memory_bytes: 1252
#include<iostream>
#include<map>
#include<list>
#include<vector>
#include<set>
#include<algorithm>

using namespace std;

int vec_find(vector<pair<int,char>> &v,char c){
	int i = 0;
	for(auto &key:v){
		if(key.second == c){
			return i;
		}
		i++;
	}
	return 0;
}

int main(){
	vector<pair<int,char>> point;
	set<char> person;
	int n;
	char p;
	while(cin >> n,n){
		int count = 0;
		bool triger = true;
		point.push_back(make_pair(0,'@'));
		for(int i=0;i<n;i++){
			count++;
			cin >> p;
			decltype(person)::iterator it =	person.find(p);
			if(it == person.end()){
				point.push_back(pair<int,char>(1,p));
				person.insert(p);
			}else{
				point[vec_find(point,p)].first++;	
			}
			sort(point.begin(), point.end(),greater<pair<int,char>>());
			//cout << count << ":" << point[0].first << "," << point[1].first << endl;
			if(triger){
				if(n == 1){
					cout << p << " " << 1 << endl;
					triger = false;
				}else if(point[0].first > (point[1].first+n-count)){
					cout << point[0].second << " " << count << endl;
					triger = false;
				}else if(n == count){
					cout << "TIE" << endl;
					triger = false;
				}
			}
		}
		point.clear();
		person.clear();
	}
	return 0;
}

Measured memory_bytes: 3124