akhauriyash/Code-Regression huggingface dataset:
// 2020-09-19 18:05:00
// clang-format off
#include <bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }
// #include <atcoder/convolution>
// #include <atcoder/dsu>
// #include <atcoder/fenwicktree>
// #include <atcoder/lazysegtree>
// #include <atcoder/math>
// #include <atcoder/maxflow>
// #include <atcoder/mincostflow>
// #include <atcoder/modint>
// #include <atcoder/scc>
// #include <atcoder/segtree>
// #include <atcoder/string>
// #include <atcoder/twosat>
// #include <atcoder/all>
// using namespace atcoder;

// clang-format on
const ll inf = 1e18;
void answer() {
  int n;
  cin >> n;
  vector<ll> a(n);
  int mini = -1, maxi = -1;
  ll mina = inf, maxa = -inf;
  rep(i, n) {
    cin >> a[i];
    if (chmin(mina, a[i])) mini = i;
    if (chmax(maxa, a[i])) maxi = i;
  }
  vector<P> q;
  if (mina >= 0 && maxa >= 0) {
    rep(i, n - 1) q.emplace_back(i, i + 1);
  } else if (mina <= 0 && maxa <= 0) {
    REPCM(i, n - 1, 1) q.emplace_back(i, i - 1);
  } else if (abs(mina) <= abs(maxa)) {
    rep(i, n) if (a[i] < 0) {
      a[i] += maxa;
      q.emplace_back(maxi, i);
    }
    rep(i, n - 1) q.emplace_back(i, i + 1);
  } else {
    rep(i, n) if (a[i] > 0) {
      a[i] += mina;
      q.emplace_back(mini, i);
    }
    REPCM(i, n - 1, 1) q.emplace_back(i, i - 1);
  }
  cout << q.size() << '\n';
  for (auto [i, j] : q) cout << i + 1 << ' ' << j + 1 << '\n';
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

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

struct Node {
  int parent;
  int left, right;
  int depth;
  int sibling;
};

void preorder(vector<Node>& tree, int v) {
  cout << " " << v;  
  if ( tree[v].left >= 0 ) preorder(tree, tree[v].left);
  if ( tree[v].right >= 0 ) preorder(tree, tree[v].right);
}

void inorder(vector<Node>& tree, int v) {
  if ( tree[v].left >= 0 ) inorder(tree, tree[v].left);
  cout << " " << v;  
  if ( tree[v].right >= 0 ) inorder(tree, tree[v].right);
}

void postorder(vector<Node>& tree, int v) {
  if ( tree[v].left >= 0 ) postorder(tree, tree[v].left);
  if ( tree[v].right >= 0 ) postorder(tree, tree[v].right);
  cout << " " << v;  
}

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

  vector<Node> tree(n);
  bool used[n] = {0};
  for ( int i = 0; i < n; i++ )
    tree[i].left = tree[i].right = -1;
  
  for ( int i = 0; i < n; i++ ) {
    int id;
    cin >> id;
    int c1, c2;
    cin >> c1 >> c2;
    tree[id].left = c1;
    if ( c1 >= 0 ) {
      used[c1] = true;
      tree[c1].sibling = c2;
    }
    tree[id].right = c2;
    if ( c2 >= 0 ) {
      used[c2] = true;
      tree[c2].sibling = c1;
    }
  }

  int root;
  for ( int i = 0; i < n; i++ ) {
    if ( !used[i] ) {
      root = i;
      break;
    }
  }

  //cout << tree[root].left << " " << tree[root].right << endl;
  
  cout << "Preorder" << endl;
  preorder(tree, root);
  cout << endl;

  cout << "Inorder" << endl;
  inorder(tree, root);
  cout << endl;

  cout << "Postorder" << endl;
  postorder(tree, root);
  cout << endl;
  
  return 0;
}



Measured memory_bytes: 3076
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var one = nextIntArray();
	var N = one[0];
	var K = one[1];
	var output = 0;
	if(K == 1){
		myout(Math.pow(N, 3));
		return;
	}
	var count = 1;
	var even = [];
	var odd = [];
	if(K % 2 == 0){
		while(K * count <= N){
			even.push(K * count);
			count++;
		}
		var count = 0;
		while((K / 2) + K * count <= N){
			odd.push((K / 2) + K * count);
			count++;
		}
	}else{
		while(K * count <= N){
			odd.push(K * count);
			count++;
		}
	}
	for(var i = 1; i <= N; i++){
		if(K % 2 == 0){
			if(i % K == 0){
				output += even.length * even.length;
			}else if(i % (K / 2) == 0){
				output += odd.length * odd.length;
			}
		}else{
			if(i % K == 0){
				output += odd.length * odd.length;
			}
		}
		
	}
	myout(output);
}


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

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
int main() {
    int x;
    cin >> x;

    while (true) {
        if (IsPrime(x)) {
            break;
        }
        x++;
    }

    cout << x << endl;

}



Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
    n, w = map(int, input().split())

    dp = [0] * (w + 1)

    for _ in range(n):
        wi, vi = map(int, input().split())

        for wj in range(w, wi - 1, -1):
            nv = dp[wj - wi] + vi
            if dp[wj] < nv:
                dp[wj] = nv

    print(max(dp))

main()


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

/*******  All Required define Pre-Processors and typedef Constants *******/
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep1(i,n) for(int i=1; i<=(n); ++i)
#define Dcout(a) cout << setprecision(20) << a << endl
#define MP make_pair
#define PB push_back
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
using ll = long long;
using PAIR = pair<int, int>;
using Graph = vector<vector<int>>;
//const ll INF = (1LL << 60);
//const double pi=acos(-1.0);
#define debug cout << "line : " << __LINE__ << " debug" << endl
/****** Template of some basic operations *****/
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/**************************************/

/******** User-defined Function *******/

/**************************************/

/********** Main()  function **********/
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int h,w,k; cin >> h >> w >> k;
    char table[h][w];
    rep(i,h)rep(j,w) cin >> table[i][j];
    char c[h][w];
    rep(i,h)rep(j,w) c[i][j] = table[i][j];

    ll ans = 0;

    for(int bit = 0; bit < (1<<h); ++bit){
      vector<int> S;
      for (int i = 0; i < h; ++i) {
        if (bit & (1<<i)) S.push_back(i);
      }
      for(int bit2 = 0; bit2 < (1<<w); ++bit2){
        vector<int> a;
        for(int i=0; i<w; ++i){
          if(bit2 & (1<<i)) a.push_back(i);
        }
        
        for(int i=0; i<(int)S.size(); ++i){
          rep(j,w){
            c[S[i]][j] = '!';
          }
        }

        for(int i=0; i<(int)a.size(); ++i){
          rep(j,h){
            c[j][a[i]] = '!';
          }
        }
        
        int cnt = 0;
        rep(i,h)rep(j,w){
          if(c[i][j]=='#') cnt++;
        }
        if(cnt==k) ans++;
        rep(i,h)rep(j,w) c[i][j] = table[i][j];
      }
    }

    cout << ans << endl;

    return 0;
}
/********  Main() Ends Here *************/


Measured memory_bytes: 3652
def sumNumber(x: str):
    x_list = [x[i] for i in range(len(x))]
    x_list = list(map(int, x_list))
    x_sum = sum(x_list)

    if a <= x_sum and x_sum <= b:
        return int(x)
    else:
        return False


def judge():
    nl = [x for x in range(1, n + 1)]
    nl_str = list(map(str, nl))
    ans = list(map(sumNumber, nl_str))

    ans = [i for i in ans if i is not False]
    print(sum(ans))


n, a, b = list(map(int, input().split(" ")))
judge()


Measured memory_bytes: 4448
#include<stdio.h>
#define NIL NULL


int main()
{
  int i,id,T[251];
  
  scanf("%d",&id);
  
  for(i = 1;i <= id;i++)
    {
      scanf("%d",&T[i]);
    }
  for(i = 1;i <= id;i++)
    {
      printf("node %d: key = %d, ",i,T[i]);
      if(i/2 >= 1)
	{
	  printf("parent key = %d, ",T[i/2]);
	}
      if(2*i <= id)
	{
	  printf("left key = %d, ",T[2*i]);
	}
      if(((2*i)+1) <= id)
	{
	  printf("right key = %d, ",T[(2*i)+1]);
	}
      printf("\n");
    }
  return 0;
}

  
  
  
      



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

int main() {
    int n, x, y;
    cin >> n >> x >> y;
    x--;
    y--;
    vector<int> adj[10000];
    rep(i, n - 1) {
        adj[i].push_back(i + 1);
        adj[i + 1].push_back(i);
    }
    adj[x].push_back(y);
    adj[y].push_back(x);

    vector<int> counter(n, 0);
    for (int start = 0; start < n; start++) {
        queue<int> q;
        q.push(start);
        vector<int> dist(n, 1e9);
        dist[start] = 0;
        while (!q.empty()) {
            int now = q.front();
            q.pop();
            for (int to : adj[now]) {
                if (dist[to] != 1e9) continue;
                if (dist[to] > dist[now] + 1) {
                    dist[to] = dist[now] + 1;
                    q.push(to);
                }
            }
        }
        for (int i = start + 1; i < n; i++) {
            counter[dist[i]]++;
        }
        // cout << "start: " << start << ", counter: ";
        // for (int i = 0; i < n; i++) {
        //     cout << counter[i] << " ";
        // }
        // cout << endl;
    }
    for (int i = 1; i < n; i++) {
        cout << counter[i] << endl;
    }
}

Measured memory_bytes: 512
#include<iostream>
using namespace std;
long gcd(long a,long b){return b?gcd(b,a%b):a;}
int H,h,m,s;
bool check(long H,long h,long m,long s)
{
	for(int r=-1;r<=1;r++)
	{
		long A=r*360*10*H+60*m*(H+1)+3600*h;
		long B=119*H-1;
		long d=gcd(A,B);
		A/=d;
		B/=d;
		if(!(A>=60*B||s*B>A)&&!(h==0&&m==0&&A==0))
		{
			cout<<h<<" "<<m<<" "<<A<<" "<<B<<endl;
			return true;
		}
	}
	return false;
}
main()
{
	while(cin>>H>>h>>m>>s,H)
	{
		while(!check(H,h,m,s))
		{
			s++;
			if(s==60)m++,s=0;
			if(m==60)h++,m=0;
			if(h==H)h=0;
		}
	}
}



Measured memory_bytes: 3084
import java.util.Scanner;
import java.util.TreeSet;

public class Main {
	Scanner sc;
	TreeSet< String > set;
	void run(){
		sc = new Scanner( System.in );
		int n = sc.nextInt();
		for( int i = 0; i < n; i++ ){
			set = new TreeSet< String >();
			String str = sc.next();
			for( int sp = 1; sp < str.length(); sp++ ){
				StringBuffer strb = new StringBuffer( str.substring( sp ) );
				StringBuffer stra = new StringBuffer( str.substring( 0, sp ) );
				set.add( stra.toString() + strb.toString() );
				set.add( strb.toString() + stra.toString() );
				stra.reverse();
				set.add( stra.toString() + strb.toString() );
				set.add( strb.toString() + stra.toString() );
				stra.reverse();
				strb.reverse();
				set.add( stra.toString() + strb.toString() );
				set.add( strb.toString() + stra.toString() );
				stra.reverse();
				set.add( stra.toString() + strb.toString() );
				set.add( strb.toString() + stra.toString() );
			}
			System.out.println( set.size() );
		}
	}
	public static void main( String[] args ){
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include <iostream>
#include <map>
#include <algorithm>

using namespace std;

long find(long n){
    long tmp = 1;
    int len = 0;
    while(tmp <= n){
        tmp *= 2;
        len++;
        //cout << tmp;
    }
    return tmp - n;
}

int main(){
    int N;
    long A[200000];
    cin >> N;
    map<long, int> m;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        m[A[i]]++;
    }

    sort(A, A+N);
    /*
    for(int i = 0; i < N; i++){
        cout << A[i] << ':' << m[A[i]] << ':' << find(A[i])  << endl;
    }
    */
    int ans = 0;
    for(int i = 0; i < N; i++){
        if(m[A[N-i-1]] >= 1){
            m[A[N-i-1]]--;
            long p = find(A[N-i-1]);
            //cout << p << endl;
            if(m[p] >= 1){
                m[p]--;
                ans++;
            }
        }
    }
    cout << ans << endl;
}

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

using namespace std;

typedef vector<int> vec;

struct node
{
	int fa,ls,rs;
	node()
	{
		fa=ls=rs=-1;
	}
}T[25];

vec Pre,In,Post;

void Preorder(int t)
{
	if(t==-1) return;
	Pre.push_back(t);
	Preorder(T[t].ls);
	Preorder(T[t].rs);
}

void Inorder(int t)
{
	if(t==-1) return;
	Inorder(T[t].ls);
	In.push_back(t);
	Inorder(T[t].rs);
}

void Postorder(int t)
{
	if(t==-1) return;
	Postorder(T[t].ls);
	Postorder(T[t].rs);
	Post.push_back(t);
}

void print(const vec& V)
{
	for(int i=0;i<V.size();i++)
		printf(" %d",V[i]);
	printf("\n");
}

int main()
{ 
	//freopen("out.txt","w",stdout);
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		int id,ls,rs;
		scanf("%d%d%d",&id,&ls,&rs);
		T[id].ls=ls;
		T[id].rs=rs;
		if(ls!=-1) T[ls].fa=id;
		if(rs!=-1) T[rs].fa=id;
	}
	int root;
	for(root=0;T[root].fa!=-1;root++);
	Preorder(root);
	Inorder(root);
	Postorder(root);
	printf("Preorder\n");
	print(Pre);
	printf("Inorder\n");
	print(In);
	printf("Postorder\n");
	print(Post);
	return 0;
}

Measured memory_bytes: 3220
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define sort(a)         sort((a).begin(), (a).end())
#define uniq(a)         sort(a);(a).erase(unique((a).begin(), (a).end()), (a).end())
#define reverse(a)      reverse((a).begin(), (a).end())
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#define debug(x)        cerr << #x << ": " << (x) << '\n'
#define debug2(x, y)    cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << '\n'
#define debug3(x, y, z) cerr << #x << ": " << (x) << ", " << #y << ": " << (y) << ", " << #z << ": " << (z) << '\n'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;

const ll MOD = 1000000007; // 10^9 + 7

void solve() {
  ll n; cin >> n;
  set<P> s;
  ll ans = 0;
  for (int i = 1; i <= n; i++) {
    ll ai; cin >> ai;
    s.insert(make_pair(i, ai));
    if (s.find(make_pair(ai, i)) != s.end()) ans++;
  }
  outl(ans);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 6528
// スタック
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<limits.h>

// スタック関連の定義
const int Max_Stack = 1000;
int stack_count = 0;
int ary_stack[Max_Stack];

void create_stack(void);
int push(int element);
int pop(void);

int main(void)
{
    char str[10];
    int i = 0, ch, operand_1, operand_2;
    int result;

    // スタックを作成
    create_stack();

    while( ( ch = getchar() ) != '\n' )
    {

        if( '0' <= ch && ch <= '9' )
        {
            str[i++] = ch;
        }
        else if( ch == '+' || ch == '-' || ch == '*' )
        {
            operand_1 = pop();
            operand_2 = pop();

            if( ch == '+' )
            {
                result = operand_2 + operand_1;
            }
            else if( ch == '-' )
            {
                result = operand_2 - operand_1;
            }
            if( ch == '*' )
            {
                result = operand_2 * operand_1;
            }

            // 次の計算に備えて、結果をpushしておく
            push(result);
        }
        else if( str[0] != '\0' )
        {
            str[i] = '\0';
            // 数値をプッシュする
            push(atoi(&str[0]));
            // 初期化をする
            i = 0;
            str[0] = '\0';
        }
    }

    printf("%d\n", result);

    return 0;

}

// スタックを作成する関数
void create_stack(void)
{
    int i;

    for(i = 0; i < Max_Stack; i++)
    {
        // スタックの初期化
        ary_stack[i] = 0;
    }

    return;
}

// スタックへプッシュする関数
int push(int element)
{

    if( stack_count > Max_Stack )
    {
        // サイズオーバー
        return -1;
    }

    // スタックに追加する
    ary_stack[++stack_count] = element;

    return 0;
}

// スタックからポップする関数
int pop(void)
{
    int ret = 0;

    if( stack_count < 0 )
    {
        // スタックが空の時
        ret = INT_MIN;
    }
    else
    {
        ret = ary_stack[stack_count--];
    }

    return ret;
}



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

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

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

const int MAX = 1e5;
const int INF = 1e9;
const int MOD = 1e9 + 7;

string S;

int main(){
    cin >> S;

    rep(i, S.size()){
        if (i % 2) {
            if (S[i] == 'R') {
                cout << "No" << endl;
                return 0;
            }
        } else {
            if (S[i] == 'L') {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    std::string s; std::cin >> s;
    int n = s.size();
    long long ans = 0;
    for (int b = 0; b < (1 << (n - 1)); b++) {
        long long cur = s[0] - '0';
        for (int i = 0; i < n - 1; i++) {
            if ((b >> i) & 1) ans += cur, cur = s[i + 1] - '0';
            else cur = 10 * cur + s[i + 1] - '0';
        }
        ans += cur;
    }
    std::cout << ans << std::endl;
    return 0;
}


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

int zalgorithm(string s)
{
    int i = 1;
    int j = 0;
    vector<int> a(s.size(), s.size());
    while (i < s.size())
    {
        while (i + j < s.size() and s[i + j] == s[j])
            j++;

        a[i] = j;
        if (j == 0)
        {
            ++i;
            continue; 
        }

        int k = 1;
        while (i+k < s.size() and k + a[k] < j)
            a[i+k] = a[k], ++k;
        j -= k;
        i += k;
    }
    int res = 0;
    rep(i, 1, a.size())
    {
        res = max(res, min(i, a[i]));
        // cout << i << ": " << a[i] << ' ' << s << endl;
    }
    return res; 
} 

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

    int ans = 0;
    rep(i, 0, s.size())
    {
        int now = zalgorithm(s.substr(i, s.size() - i));
        ans = max(ans, now); 
        // cout << i << ' ' << now << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < (int)(n); i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
using ll = long long;

int main() {
    string S; cin >> S;
    reverse(ALL(S));

    ll dp[S.size() + 1][13] = {}; dp[0][0] = 1;
    ll mul = 1;
    REP(i, 0, S.size()) {
        REP(j, 0, 13) {
            if (S[i] == '?') {
                REP(k, 0, 10) {
                    dp[i + 1][(j + (mul * k) % 13) % 13] += dp[i][j];
                    dp[i + 1][(j + (mul * k) % 13) % 13] %= MOD;
                }
            } else {
                int num = (mul * (S[i] - '0')) % 13;
                dp[i + 1][(j + num) % 13] += dp[i][j];
                dp[i + 1][(j + num) % 13] %= MOD;
            }
        }
        mul = (mul * 10) % 13;
    }

    cout << dp[S.size()][5] << endl;
    return 0;
}

Measured memory_bytes: 10624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
static const int INF = 2000000000;



int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int t = a / d;
  int u = c / b;
  if (a % d) t++;
  if (c % b) u++;
  if (t >= u) cout << "Yes\n";
  else cout << "No\n";
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<vector<int>> vv;
typedef vector<vector<ll>> vvll;
const ll inf = 1e16;
const ll md = 1000000007;
vector<pi> to[300];

int main() {
  int n, m, l, q;
  cin >> n >> m >> l;
  rep(i, m) {
    int a, b, c;
    cin >> a >> b >> c;
    a--;
    b--;
    to[a].emplace_back(b, c);
    to[b].emplace_back(a, c);
  }
  cin >> q;
  vv idx(n, vi(n, -1));
  vi qc(n, 0);
  rep(i, q) {
    int s, t;
    cin >> s >> t;
    s--;
    t--;
    idx[s][t] = i;
    qc[min(s, t)]++;
  }
  vi ans(q, -1);
  rep(s, n) {
    int cnt = qc[s];
    if (cnt == 0) continue;
    priority_queue<vi> hp;
    hp.push({0, l, s});
    vector<bool> fin(n, false);
    while (cnt > 0 && hp.size() > 0) {
      // vi kgu=hp.top;
      int k = -hp.top()[0];
      int g = hp.top()[1];
      int u = hp.top()[2];
      hp.pop();
      if (fin[u]) continue;
      fin[u] = true;
      int i = idx[s][u];
      if (i != -1) {
        ans[i] = k;
        idx[s][u] = -1;
        cnt--;
      }
      i = idx[u][s];
      if (i != -1) {
        ans[i] = k;
        idx[u][s] = -1;
        cnt--;
      }
      for (pi p : to[u]) {
        int ku = p.first;
        int c = p.second;
        if (fin[ku]) continue;
        if (g - c >= 0)
          hp.push({-k, g - c, ku});
        else if (l - c >= 0)
          hp.push({-k - 1, l - c, ku});
      }
    }
  }
  for (int x : ans) cout << x << endl;
  return 0;
}


Measured memory_bytes: 5404
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    intmax_t H, W, N;
    intmax_t ans = 0;

    scanf("%jd", &H);
    scanf("%jd", &W);
    scanf("%jd", &N);

    if (H > W) {
        ans = N / H;
        if (N % H)
            ans++;
    } else {
        ans = N / W;
        if (N % W)
            ans++;
    }

    printf("%jd\n", ans);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using std::cerr;using std::cin;using std::cout;using std::abs;using std::min;using std::max;using std::swap;using std::map;using std::unordered_map;using std::unordered_set;using std::bitset;using std::pair;using std::set;using std::string;using std::vector;using std::sort;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
// #define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);std::iostream::sync_with_stdio(0);cout<<std::fixed<<std::setprecision(10);cerr<<std::fixed<<std::setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}

const int N=5019;
int dp[N][N];
int a[N];
int n,M;
void add(int &x,int y){
    x+=y;
    if(x>=M)x-=M;
}
int32_t main(){
    cin>>n>>M;
    int l=2,r=n,vl=1,vr=2;
    while(l<r){
        a[l++]=vl++;
        a[r--]=vr++;
    }
    if(l==r)a[l++]=vl++;
    dp[1][0]=1;
    for(int i=2;i<=n;++i){
        int c=a[i];
        dbg(i,c);
        for(int s=0;s<=n;++s){
            for(int x=0;x<=s;x+=c)
                add(dp[i][s],dp[i-1][s-x]);
            dbg(i,s,dp[i][s]);
        }
    }
    int ans=0;
    forn(s,n){
        add(ans,((n-s)*1ll*dp[n][s])%M);
    }
    cout<<ans<<'\n';
    return 0;
}


Measured memory_bytes: 98560
#include <stdio.h>
#define NIL -1
#define MAX 100001

int main(){
  int kazu,i,j,id,k,a,temp,depth,parent[MAX],left[MAX],right[MAX],degree[MAX];
  scanf("%d",&kazu);
  for(i=0;i<kazu;i++) parent[i]=left[i]=right[i]=NIL;
  for(i=0;i<kazu;i++){
    scanf("%d %d",&id,&k);
    degree[id]=k;
    for(j=0;j<k;j++){
      if(left[id]==NIL){
	scanf("%d",&a);
	left[id]=a;
	parent[a]=id;
	temp=left[id];
      }else{
	scanf("%d",&a);
	right[temp]=a;
	parent[a]=id;
	temp=a;
      }
    }
  }
  for(i=0;i<kazu;i++){
    printf("node %d: parent = %d,",i,parent[i]);
    depth=0;
    a=i;
    while(parent[a]!=NIL){
      a=parent[a];
      depth++;
    }
    printf(" depth = %d,",depth);
    if(parent[i]==NIL) printf(" root, [");
    else if(left[i]==NIL) printf(" leaf, [");
    else printf(" internal node, [");
    a=left[i];
    for(j=0;j<degree[i];j++){
      if(j) printf(", ");
      printf("%d",a);
      a=right[a];
      }
    printf("]\n");
  }
  return 0;
}



Measured memory_bytes: 3420
def solve(W, sc, chL, chR):
    limLs, limRs = [0]*N, [0]*N
    limL, limR = 0, W+1
    for i in reversed(range(N)):
        if Ts[i] == chL:
            limR += 1
            if limR > W+1: limR = W+1
        elif Ts[i] == chR:
            limL -= 1
            if limL < 0: limL = 0
        if Ss[i] == chL:
            limL += 1
            if limL > W+1: limL = W+1
        elif Ss[i] == chR:
            limR -= 1
            if limR < 0: limR = 0
        limLs[i] = limL
        limRs[i] = limR

    posL, posR = sc, sc
    for i in range(N):
        if posR <= limLs[i] or limRs[i] <= posL:
            return False
        if Ss[i] == chL:
            posR -= 1
            if posR < 1: posR = 1
        elif Ss[i] == chR:
            posL += 1
            if posL > W: posL = W
        if Ts[i] == chL:
            posL -= 1
            if posL < 1: posL = 1
        elif Ts[i] == chR:
            posR += 1
            if posR > W: posR = W

    return True


H, W, N = map(int, input().split())
sr, sc = map(int, input().split())
Ss = input()
Ts = input()

ansLR = solve(W, sc, 'L', 'R')
ansUD = solve(H, sr, 'U', 'D')

print('YES' if ansLR and ansUD else 'NO')


Measured memory_bytes: 11944
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define maxn 55
const int inf=1e9;

int n,k;
int a[maxn];
pair<int,int> mx,mn;

inline int read(){
	int x=0,f=1; char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	n=read(); mx.first=-inf,mn.first=inf;
	for (int i=1;i<=n;i++){
		int x=read();
		mx=max(mx,make_pair(x,i));
		mn=min(mn,make_pair(x,i));
	}
	printf("%d\n",2*n-2);
	if (abs(mx.first)<abs(mn.first)){
		for (int i=1;i<=n;i++)
			if (i!=mn.second) printf("%d %d\n",mn.second,i);
		for (int i=n;i>1;i--) printf("%d %d\n",i,i-1);
	}
	else{
		for (int i=1;i<=n;i++)
			if (i!=mx.second) printf("%d %d\n",mx.second,i);
		for (int i=1;i<n;i++) printf("%d %d\n",i,i+1);
	}
	return 0;
}


Measured memory_bytes: 256
a, b, c = map(int, input().split())
d, e, f = map(int, input().split())
g, h, i = map(int, input().split())
N = int(input())

num_list = []
for _ in range(N):
    num_list.append(int(input()))

for j in num_list:
    if a == j:
        a = 101
    if b == j:
        b = 101
    if c == j:
        c = 101
    if d == j:
        d = 101
    if e == j:
        e = 101
    if f == j:
        f = 101
    if g == j:
        g = 101
    if h == j:
        h = 101
    if i == j:
        i = 101

answer = 'No'
if a + b + c == 303:
    answer = 'Yes'
if d + e + f == 303:
    answer = 'Yes'
if g + h + i == 303:
    answer = 'Yes'
if a + d + g == 303:
    answer = 'Yes'
if b + e + h == 303:
    answer = 'Yes'
if c + f + i == 303:
    answer = 'Yes'
if a + e + i == 303:
    answer = 'Yes'
if c + e + g == 303:
    answer = 'Yes'

print(answer)

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

#include <bits/stdc++.h>
using namespace std;

template<typename T>
struct FenwickTree{
    vector<T> fenwick;
    int  n;

    FenwickTree(int n):
        fenwick(vector<T>(n+1, 0)), n(n) {}

    T sum(int i) {
        if (!i) return 0;
        return fenwick[i] + sum(i-(i&-i));
    }

    T sum(int i, int j){
        // half-open Terval
        return sum(j-1) - sum(i-1);
    }

    void add(int i, T x) {
        if (i > n) return;
        fenwick[i] += x;
        add(i+(i&-i), x);
    }
};

//1-indexed
//  http://na-o-s.hateblo.jp/entry/2014/07/13/031143

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int32 n,d,a;
  cin >> n >> d >> a;
  vector<pii> xh(n);
  REP(i,n){
    cin >> xh[i].first >> xh[i].second;
    xh[i].second = (xh[i].second + a - 1) / a;
  }
  sort(ALL(xh));
  FenwickTree<int32> ft(n);
  int64 ans = 0;
  REP(i,n){
    int32 l = lower_bound(ALL(xh), pii(xh[i].first-2*d,-INF)) - xh.begin();
    xh[i].second = max<int32>(0, xh[i].second - ft.sum(l+1,i+2));
    ans += xh[i].second;
    ft.add(i+1,xh[i].second);
  }
  ANS(ans);
  return 0;
}

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

int n,cnt[99];
char s[200010];
LL Ans;

int main()
{
#ifdef h10
	freopen("B.in","r",stdin);
	freopen("B.out","w",stdout);
#endif
	int i,j;
	scanf("%s",s);
	n=strlen(s);
	for (i=0;i<n;i++)
		cnt[s[i]-'a']++;
	for (i=0;i<26;i++)
	for (j=i+1;j<26;j++)
		Ans+=(LL)cnt[i]*cnt[j];
	Ans++;
	printf("%lld\n",Ans);
}


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

int main() {
    cin.tie(0)->sync_with_stdio(false);

	int n;
	cin >> n;
	int rem = n % 1000;
	if (!rem) cout << 0 << '\n';
	else cout << 1000 - rem << '\n';
    return 0;
}


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

struct Point{
  double x;
  double y;
};

int kock(int,struct Point,struct Point);

int main(){
  int n;
  struct Point p1,p2;

  p1.x=0;
  p1.y=0;
  p2.x=100;
  p2.y=0;

  scanf("%d",&n);
  
  printf("%f %f\n",p1.x,p1.y);
  kock(n,p1,p2);
  printf("%f %f\n",p2.x,p2.y);
  
  return 0;
}

int kock(int n,struct Point p1,struct Point p2){
  struct Point s,t,u;

  if(n==0){
    return 0;
  }

  s.x=(2*p1.x+1*p2.x)/3;
  s.y=(2*p1.y+1*p2.y)/3;
  t.x=(1*p1.x+2*p2.x)/3;
  t.y=(1*p1.y+2*p2.y)/3;
  u.x=(t.x-s.x)*cos(M_PI/3)-(t.y-s.y)*sin(M_PI/3)+s.x;
  u.y=(t.x-s.x)*sin(M_PI/3)+(t.y-s.y)*cos(M_PI/3)+s.y;

  kock(n-1,p1,s);
  printf("%f %f\n",s.x,s.y);
  kock(n-1,s,u);
  printf("%f %f\n",u.x,u.y);
  kock(n-1,u,t);
  printf("%f %f\n",t.x,t.y);
  kock(n-1,t,p2);
}

Measured memory_bytes: 636
import sys
N = int(input())
r3 = N//3
r5 = N//5
r15 = N//15
def sum(N):
    return int(1/2*N*(N+1))
S = sum(N) - 3*sum(r3) - 5*sum(r5) +15*sum(r15)
print(S)

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

int main(){
    long long N, x;
    long long a_list[114514];
    long long candies = 0;
    long long y;
    cin >> N >> x;
    for(int i=0; i<N; i++){
        cin >> a_list[i];
    }
    for(int i=1; i<N; i++){
        y = a_list[i] + a_list[i-1] - x;
        if(y > 0){
            candies += y;
            if(a_list[i] - y >= 0){
                a_list[i] -= y;
            }else{
                a_list[i-1] -= y-a_list[i];
                a_list[i] = 0;
            }
        }
    }
    cout << candies;
    return EXIT_SUCCESS;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
 
int main(void){

  int num[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int K;
  cin >> K;
  cout <<num[K-1];

  

  return 0;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define check system("pause")
#define all(x) (x).begin(),(x).end()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 0x3f3f3f3f
const ll mod = 1e9+7;
const int N = 1e5+20;
#define dep(i,a,b) for(int i=(a);i>=(b);i--)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define mes(p,b) memset(p,b,sizeof(p))
#define sz(x) int(x.size())
int n,m,h[N];vi edge[N];
int main()
{
  	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	rep(i,1,n) cin>>h[i];
	rep(i,1,m){
		int a,b;
		cin>>a>>b;
		edge[a].pb(b);
		edge[b].pb(a);
	}
	int ans=0;
	rep(i,1,n){
		int f=0;
		
		for(auto t:edge[i]){
			if(h[i]<=h[t]){
				f=1;
			}
		}
		if(f==0){
			ans++;
		}
	}
	cout<<ans;
  	return 0;
}



Measured memory_bytes: 9172
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <unordered_map>
#include <queue>
#include <sstream>
#include <cstring>
#include <iomanip>

using namespace std;

typedef long long ll;

const ll INF = 1e13 + 7;

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T, class Y>
T GCD(T a, Y b)
{
    if(a<b){
        int c=a;
        a=b;
        b=c;
    }
    if (a % b == 0)
    {
        return b;
    }
    return GCD(b, a % b);
}

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

int main()
{
    int N,max=0;
    cin >> N;
    int A[N + 2];
    int L[N + 2], R[N + 2];
    for (int i = 0; i < N; i++)
        cin >> A[i];
    L[0] = A[0], R[N] = A[N - 1];
    for (int i = 1; i <= N; i++)
    {
        L[i] = GCD(L[i - 1], A[i-1]);
    }
    for (int i = N - 1; i >= 0; i--)
    {
        R[i] = GCD(R[i + 1], A[i]);
    }
    int M[111111];
    for (int i = 0; i < N; i++)
    {
        if(i==0){
            M[i]=R[i+1];
        }else if(i==N-1){
            M[i]=L[i];
        }else{
            M[i] = GCD(L[i], R[i + 1]);
        }
    }
    for(int i=0;i<N;i++)if(max<M[i])max=M[i];
    cout << max << endl;
    return 0;
}

//a=97,z=122

Measured memory_bytes: 1792
n = int(input())
l = list(map(int,input().split()))

l.sort(reverse = 1)
ans = 0

for i in range(n-2):
    indL = i+1
    indR = len(l)-1
    while 1:
        if indL == indR:
            break
        if l[i] < l[indL] + l[indR]:
            ans += (indR - indL)
            indL += 1
        else:
            indR -= 1
                
print(ans)

Measured memory_bytes: 3188
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#include<cmath>
#include<climits>
#include<ctime>
#include<cstring>
#include<stack>
#include<queue>
#include<sstream>
#include<string>

#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define DUMP(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i);

using namespace std;

const int MAX_V = 101;
const int INF = 1<<28;
const int MONEY = 101;
int n,m,l;

struct edge{
	int to, cost, dist;
	edge(int t_to,int t_cost,int t_dist){
		to=t_to;cost=t_cost;dist=t_dist;
	}
};

struct state{
	int cost,v,money;//?????¨?????????????????????????????????
	state(int t_cost,int t_v,int t_money){
		cost=t_cost;v=t_v;money=t_money;		
	}
	bool operator>(const state& s)const{
		return cost > s.cost;
	}
};

vector< vector<edge> > G(MAX_V);
int d[MAX_V][MONEY];

void dijkstra(int s){
	priority_queue<state,vector<state>,greater<state> > que;
	fill_n((int *)d, sizeof(d)/sizeof(int),INF);
	d[s][l] = 0;
	que.push(state(0,s,l));

	while(!que.empty()){
		state p = que.top(); que.pop();
		int v = p.v;
		int m = p.money;
		if(d[v][m]<p.cost) continue;
		rep(i,G[v].size()){
			edge e = G[v][i];
//			cout << "E:" << e.to << endl;
			if(d[e.to][m] > d[v][m] + e.cost){//??????????????´???
				d[e.to][m] = d[v][m] + e.cost;
				que.push(state(d[e.to][m],e.to,m));
			}
			if(e.dist <= m && d[e.to][m-e.dist] > d[v][m]){//????????´???
				d[e.to][m-e.dist] = d[v][m];	
				que.push(state(d[e.to][m-e.dist],e.to,m-e.dist));
			}
		}
	}
}


int main(){

	while(1){
		cin >> n >> m >> l;

		if(n==0&&m==0&&l==0) break;
		G.clear();
		G.resize(n);

		rep(i,m){
			int a,b,d,e;
			cin >> a >> b >> d >> e;
			a--;b--;
			edge tmp1(b,e,d);
			edge tmp2(a,e,d);
			G[a].push_back(tmp1);
			G[b].push_back(tmp2);	
		}

		dijkstra(0);
		int ans=INF;
		rep(i,MONEY+1){
			ans = min(ans,d[n-1][i]);
		}
		cout << ans << endl;
	}
}

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

string vs[] = {"147", "28", "369"};
const int LFOOT = 0;
const int RFOOT = 1;

int calc(string s, int init) {
    int state = -1, foot = init, ret = 0, temp = 0;
    rep(turn,0,s.length()) {
        rep(i,0,3) if(vs[i].find(s[turn]) != string::npos) temp = i;
        bool changed = false;
        if(state != -1) {
            if(foot == LFOOT && state > temp) ret++, changed = true;
            if(foot == RFOOT && state < temp) ret++, changed = true;
        }
        state = temp;
        if(!changed) foot ^= 1;
    }
    return ret;
}

signed main() {
    string s;
    while(cin >> s, s != "#") {
        int c1 = calc(s, 0), c2 = calc(s, 1);
        cout << min(c1, c2) << endl;
    }
    return 0;
}

Measured memory_bytes: 3312
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (int)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<bool>    vecbool;
typedef vector<int>     vecint;
typedef vector<ll>      vecll;
typedef vector<string>  vecstr;
typedef vector<vecint>  vec2int;
typedef vector<vecbool> vec2bool;
int dx[4] {-1,+1, 0, 0};
int dy[4] { 0, 0,-1,+1};
int main()
{
  int a, b, c; cin >> a >> b >> c;
  if(a + b >= c){
    cout << b + c << endl;
  }else{
    cout << 2*b + a + 1 << endl;
  }
}


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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}

vector<string> a;

int hor_best[2001][2001], ver_best[2001][2001];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, m;

    cin >> n >> m;

    for(int i = 0; i < n; ++i){
        string c;
        cin >> c;
        a.push_back(c);
    }

    // Horizontal

    for(int x = 0; x < n; ++x){
        int cur = 0;
        for(int y = 0; y < m; ++y){
            if(a[x][y] == '#'){
                for(int py = y - cur; py < y; ++py)
                    hor_best[x][py] = cur;
                cur = 0;
            } else {
                ++cur;
            }
        }
        for(int py = m - cur; py < m; ++py)
            hor_best[x][py] = cur;
    }

    // Vertical

    for(int y = 0; y < m; ++y){
        int cur = 0;
        for(int x = 0; x < n; ++x){
            if(a[x][y] == '#'){
                for(int px = x - cur; px < x; ++px)
                    ver_best[px][y] = cur;
                cur = 0;
            } else {
                ++cur;
            }
        }
        for(int px = n - cur; px < n; ++px)
            ver_best[px][y] = cur;
    }

    int best = 0;

    for(int x = 0; x < n; ++x)
        for(int y = 0; y < m; ++y)
            if(a[x][y] != '#')
                best = max(best, hor_best[x][y] + ver_best[x][y] - 1);

    cout << best;

    return 0;
}


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

using namespace std;

#define rep(i,k,n) for(int i = k ; i < n ; i++ )
#define INF 10000000

bool used[101];
int mincost[101];
int cost[101][101];
int V;

int prim(){

  fill(mincost,mincost + 101,INF);
  fill(used,used+101,false);

  int re = 0;
  mincost[0] = 0;
  while(1){

    int v = -1;
    for(int i = 0 ; i < V ; i++ ){
      if(!used[i] && (v == -1 || mincost[i] < mincost[v]))v = i;
    }

    re += mincost[v];
    if(v == -1)break;
    used[v] = true;


    for(int i = 0 ; i < V ; ++i){
      if(!used[i])mincost[i] = min(mincost[i],cost[v][i]);
    }
  }
  return re;
}

int main(){
  int n;
  while(cin >> V >> n , V+n){

    fill(cost[0],cost[101],INF);
    for(int i = 0 ; i < n ; ++i ){
      int a,b,c;
      cin >> a >> b >> c;
      cost[a][b] = cost[b][a] = c;
    }
    int res = prim();
    cout << res << endl;
  }

  return 0;
}

Measured memory_bytes: 1200
arr = [0]
nxt = [0, 0]
while true
    nxt[0] += 1 while arr.include?(arr[nxt[0]] + 4)
    nxt[1] += 1 while arr.include?(arr[nxt[1]] + 7)
    min = [arr[nxt[0]] + 4, arr[nxt[1]] + 7].min
    break if min > 100
    arr << min
end

n = gets.to_i
puts arr.include?(n) ? "Yes" : "No"

Measured memory_bytes: 1788
costs = []
for _ in range(0, 4):
  i, v = map(int, input().split())
  if i == 1:
    costs.append(6000*v)
  elif i == 2:
    costs.append(4000*v)
  elif i == 3:
    costs.append(3000*v)
  elif i == 4:
    costs.append(2000*v)

for cost in costs:
  print(cost)


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


int main()
{
  ll N;
  cin >> N;
  vector<ll> hankei(N);
  rep (i,N)
  {
    cin >> hankei.at(i);
  }
  ll count = 0;
  rep (i,100)
  {
    rep(j,N)
    {
      if (hankei.at(j) == i + 1)
      {
        count++;
        break;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
# 169A
# A ×　B を整数として出力せよ。

# 1. 入力をプログラムを扱えるように受け取ること
a, b = map(int, input().split())
# print(a, b)

# 2. 受け取った入力値を使って、適切に処理（計算）すること
answer = a * b

# 3. 計算した結果を出力すること
print(answer)

Measured memory_bytes: 9060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>
#include <cctype>
#include <climits>
#include <list>
#include <queue>

#define INF 1000000000
#define MOD 1000000007
typedef long long ll;
typedef unsigned long long ull;
using namespace std;


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

  int N, x; cin>>N>>x;
  vector<int> A(N);
  for(int i=0; i<N; i++) {
    int a; cin>>a;
    A[i] = a;
  }

  sort(A.begin(), A.end());
  int count = 0;
  ll sum = 0;
  for(int i=0; i<N; i++) {
    sum += A[i];
    if(sum <= x) {
      count++;
    } else {
      break;
    }
  }

  if(sum == x) {
    
  } else if(sum > x){

  } else {
    count -= 1;
  }
  cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;

vector<ll> FACT;

ll NCR(int n, int r) {
  ll res = FACT[n];
  res *= mod_inv((FACT[r] * FACT[n-r])%DVSR, DVSR);
  res %= DVSR;
  if (res < 0) res += DVSR;
  // cout << "n: " << n << " r: " << r << " res: " << res << endl;
  return res;
}

int main(int argc, char const *argv[])
{
  ll N, D; cin >> N;
  vecll AS(N+1), cnt(N+1);
  cnt.assign(N+1, 0);
  FACT.assign(N+2, 1);
  ll I_l = 0, I_r = 0;


  RNG(i, 1, N+2) FACT[i] = (FACT[i-1]*i)%DVSR;

  REP(i, N+1) {
    cin >> AS[i];
    cnt[AS[i]] += 1;
    if (cnt[AS[i]] == 2) {
      D = AS[i];
      I_r = i;
      I_l = find(AS.begin(), AS.end(), AS[i]) - AS.begin();
    }
  }
  ll Ls = I_l, Rs = N+1 - I_r - 1;
  // cout << "Ls:" << Ls << " Rs:"  << Rs << endl;
  // println(FACT);
  RNG(i, 1, N+2) {
    ll loc_res = 0;
    loc_res += NCR(N+1, i);
    if (Ls + Rs >= i-1) {
      loc_res -= NCR(Ls+Rs, i-1);
    }
    if (loc_res < 0) loc_res += DVSR;
    cout << loc_res << endl;
  }
  return 0;
}


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

int main() {
    int m, f, b;
    cin >> m >> f >> b;
    if (m+f < b) printf("NA\n");
    else if (m < b) printf("%d\n", b-m);
    else printf("0\n");
    return 0;
}


Measured memory_bytes: 3184