akhauriyash/Code-Regression huggingface dataset:
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main(int argc, char* argv[]) {
    ll L, R;
    cin >> L >> R;
    if (R - L >= 2018) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = numeric_limits<ll>::max();
    for (ll x = L; x <= R; x++) {
        for (ll y = x + 1; y <= R; y++) {
            ans = min(ans, (x * y) % 2019);
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 888
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int N, A;
	std::cin >> N >> A;
	std::cout << (N*N-A) << "\n";
}


Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
//#include <tuple>

//#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main() {
  int N, b;
  bool flag = false;
  cin >> N;

  for (int i = 9 ; i > 0; i--) {
    if (N % i == 0) {
      b = N / i;
      if (b <= 9) {
        flag = true;
      }
    }
  }

  if (flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
const Int MAX = 305;
const Int MAX2 = MAX*2;
signed ex[MAX2][MAX2];
signed dp[MAX2+2][MAX2+2];
signed main(){
  Int h,w;
  cin>>h>>w;
  vector<string> s(h);
  for(Int i=0;i<h;i++) cin>>s[i];

  using P = pair<Int, Int>;
  vector<P> vp;
  memset(ex,0,sizeof(ex));
  for(Int i=0;i<h;i++){
    for(Int j=0;j<w;j++){
      if(s[i][j]!='#') continue;
      vp.emplace_back(1+i+j,1+i-j+w);
      ex[1+i+j][1+i-j+w]=1;      
    }
  }
  
  auto ch=
    [&](Int i,Int j)->Int{
      if(i<0||i>=MAX2) return 0;
      if(j<0||j>=MAX2) return 0;
      return ex[i][j];
    };
  
  const Int LIM = h+w;
  Int ans=0;
  for(Int k=1;k<=LIM;k++){
    for(Int i=0;i<MAX2;i++)
      for(Int j=1;j<MAX2;j++)
        dp[i][j+1]=dp[i][j]+(ch(i,j)&&ch(i,j-k));

    for(P p:vp){
      Int i,j;
      tie(i,j)=p;
      if(i-k>=0)  ans+=dp[i-k][min(MAX2-1,j+k+1)]-dp[i-k][j];
      if(i+k<MAX2) ans+=dp[i+k][min(MAX2-1,j+k+1)]-dp[i+k][j];
    }

    for(Int j=0;j<MAX2;j++)
      for(Int i=0;i<MAX2;i++)
        dp[j][i+1]=dp[j][i]+(ch(i,j)&&ch(i-k,j));
    
    for(P p:vp){
      Int i,j;
      tie(i,j)=p;
      if(j-k>=0)  ans+=dp[j-k][min(MAX2-1,i+k+1)]-dp[j-k][i];
      if(j+k<MAX2) ans+=dp[j+k][min(MAX2-1,i+k+1)]-dp[j+k][i];   
    }            
  }

  //cout<<ans<<endl;
  for(P p:vp){
    Int i,j;
    tie(i,j)=p;
    for(Int k=1;k<=LIM;k++){
      if(ch(i+k,j)&&ch(i,j+k)) ans--;
      if(ch(i+k,j)&&ch(i,j-k)) ans--;
      if(ch(i-k,j)&&ch(i,j+k)) ans--;
      if(ch(i-k,j)&&ch(i,j-k)) ans--;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4852
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/04/04.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//  ABC163
//
//

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

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

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

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;
//#define __DBG__


void solve(void){
  
  int N;
  
  cin >> N;
  
  vector<int> A(N+1,0);
  
  A[0]=-1;
  A[1]=0;
  
  REP2(i,2,N+1){
    int tmp;
    cin >> tmp;
    A[tmp]++;
  }
  
  REP2(i,1,N+1){
    cout << A[i] << endl;
  }

  
  return;
   
}



#define TESTCASES 1

int main() {


    cin.tie(0);
    ios::sync_with_stdio(false);

    REP(i,TESTCASES){
      solve();
    }
 
    return 0;
}



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

int main() {
    int N; cin >> N;
    set<char> st;
    rep(i, N) {
        char a; cin >> a;
        st.insert(a);
    }
    cout << (st.size() == 4 ? "Four" : "Three") << '\n';
    return 0;
}


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

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

  map<int, int> p;
  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j < n + 1; j++)
      p[min(j - i, abs(i - x) + 1 + abs(j - y))]++;
  }

  for (int k = 1; k < n; k++) cout << p[k] << endl;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<iostream>
using namespace std;


int main()
{	
	int x,y,z;

	while (cin >> x >>y)
	{
		if (x==0 && y==0)
		{
			break;
		}
			if (x > y)
		{
			z = x;
			x = y;
			y = z;
		}
		
		cout <<x << " " <<y <<endl;
	
	}
	return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std ;
int main () {
  int N ;
  cin >> N ;
  int a = 0 , b = 0 ;
  for(int i = 0 ; i < N ; i++ ) {
    string A , B ;
    cin >> A >> B ;
    if( A > B ) a += 3 ;
    else if ( A < B ) b += 3 ;
    else {
      a++ ; b++ ;
    }
  }
  cout << a << ' ' << b << endl ;
}


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

int main(){
int set,i,j,p,q,n,k,input[100100],st,en,sa[100100],cont;

scanf("%d",&set);
for(q=0;q<set;q++){
scanf("%d%d",&n,&k);
for(i=0;i<n;i++){
scanf("%d",&input[i]);
}
st=input[0];
en=input[n-1];
cont=en-st;
for(i=1;i<n;i++){
sa[i-1]=input[i]-input[i-1];
}
sort(sa,sa+n-1,greater<int>());
for(i=0;i<k-1;i++){
cont-=sa[i];
}
if(cont<0){
cont=0;
}
printf("%d\n",cont);
}
}

Measured memory_bytes: 1664
import java.util.*;
import java.text.*;

public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        String s = sc.next();
        Map<String, String> map = new HashMap<>();
        map.put("A", "X");
        map.put("B", "Y");
        map.put("C", "Z");
        map.put("D", "A");
        map.put("E", "B");
        map.put("F", "C");
        map.put("G", "D");
        map.put("H", "E");
        map.put("I", "F");
        map.put("J", "G");
        map.put("K", "H");
        map.put("L", "I");
        map.put("M", "J");
        map.put("N", "K");
        map.put("O", "L");
        map.put("P", "M");
        map.put("Q", "N");
        map.put("R", "O");
        map.put("S", "P");
        map.put("T", "Q");
        map.put("U", "R");
        map.put("V", "S");
        map.put("W", "T");
        map.put("X", "U");
        map.put("Y", "V");
        map.put("Z", "W");
        
        String res = "";
        for (int i = 0; i < s.length(); i++) {
            String c = s.substring(i, i+1);
            res += map.get(c);
        }
        
        System.out.println(res);
    }
}

Measured memory_bytes: 29984
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define mod 1000000007
#define FT() int t; scanf("%d",&t); while(t--)
#define pb push_back
#define nl printf("\n")
#define fi(i,start,end) for(int i=start; i < (int)end ; ++i)
#define ip(n)   scanf("%d",&n)
#define mz(a)   memset(a,0,sizeof(a))
#define inpArr(A,n) fi(i,0,n)   ip(A[i]);
#define print(a)  for(auto i : a)   cout<<i<<" "; nl;
#define Fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
ll max(ll a,ll b) { return a>b?a:b;}
ll min(ll a,ll b) { return a<b?a:b;}
const int N = 1e4+1;
int dp[N];
int main() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif
    mz(dp);
    int n;
    cin>>n;
    for(int i=1;i<=10000;i++)
    {
      for(int j=1;j<=10000;j++)
      {
        for(int k=1;k<=1000;k++)
        {
          ll f = i*i + j*j + k*k + i*j + j*k + i*k;
          if(f>n)
            break;
          dp[f]++;
        }
      }
    }
    fi(i,0,n)
      cout<<dp[i+1]<<"\n";

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s";
    #endif
    
    return 0;
}


Measured memory_bytes: 3624
#include"bits/stdc++.h"

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7


int N;
vector<vector<int>> edges;

pair<ll, ll> solve(int now, int par)
{
	if(par != -1 && edges[now].size() == 1)
	{
		return {1,1};
	}
	vector<pair<ll, ll>> dp;
	for(auto child : edges[now])if(child != par)
		dp.push_back(solve(child, now));
	pair<ll, ll> res = {1,1};
	for(auto p : dp)
	{
		// first: black,  second: white
		res.first = (res.first*p.second) % MOD;
		res.second = (res.second*(p.first + p.second)) % MOD;
	}
	return res;
}

//メイン関数
int main()
{
	cin >> N;
	edges.resize(N);
	REP(i, N - 1)
	{
		int a, b;
		cin >> a >> b;
		a--; b--;
		edges[a].push_back(b);
		edges[b].push_back(a);
	}

	if(N == 1)
	{
		cout << 2 << endl;
		return 0;
	}
	auto res = solve(0, -1);
	cout << (res.first + res.second) % MOD << endl;
	cin >> N;

	return 0;
}


Measured memory_bytes: 14080
n=int(input())
it=list(map(int,input().split()))
dp=[0]*n
dp[1]=abs(it[1]-it[0])
for i in range(2,n):
    dp[i]=min(dp[i-1]+abs(it[i-1]-it[i]),dp[i-2]+abs(it[i-2]-it[i]))
print(dp[-1])


Measured memory_bytes: 52208
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;


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

  string ans = "No";
  if (n % 2 == 0 and s.substr(0, n / 2) == s.substr(n/2, n/2)) ans = "Yes";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author champon
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define ceill(a, b) (a+b-1)/b
#define ok cout << "ok" << endl;
#define sp << " " <<
ll mod = 1e9+7;
void ans(bool b, ostream& out=cout){ out << (b ? "Yes" : "No") << endl; }
void ans2(bool b, ostream& out=cout){ out << (b ? "YES" : "NO") << endl; }
template<typename T> inline bool chmax(T &a, T b){ if(a<b) a=b; return a<b; }
template<typename T> inline bool chmin(T &a, T b){ if(b<a) a=b; return b<a; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill((T*)array, (T*)(array+N), val);}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, -1, -1, 1};

#ifndef INCLUDE_DEBUG_HPP
#define INCLUDE_DEBUG_HPP

class debug
{
public:
    template<typename T> void vdeb(T vec);
    template<typename T1, typename T2> void adeb(T1 *arr, T2 n);
    template<typename T> void mdeb(T mp);
};

#endif //INCLUDE_DEBUG_HPP

template<typename T> void debug::vdeb(T vec)
{
    cout << "#vector set debug" << endl;
    for(auto vv : vec) cout << vv << " ";
    cout << endl;
}

template<typename T1, typename T2> void debug::adeb(T1 *arr, T2 n)
{
    cout << "#adebug" << endl;
    for(int i=0; i<=n; i++) cout << arr[i] << " ";
    cout << endl;
}

template<typename T> void debug::mdeb(T mp)
{
    cout << "#map pair debug" << endl;
    for(auto const& m : mp) cout << m.first sp m.second << endl;
}
debug dbg;

class BShiftOnly {
public:
	void solve(std::istream& in, std::ostream& out)
	{
	    int n;
	    in >> n;
	    ll res = inf;
	    int a;
	    for(int i=0; i<n; i++){
	        in >> a;
	        ll cnt = 0;
	        while(a % 2 == 0){
	            cnt++;
	            a /= 2;
	        }
	        chmin(res, cnt);
	    }

	    out << res << endl;
	}
};


int main() {
	BShiftOnly solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef complex<double> P;


int main() {
	int n; cin >> n;
	while (n--) {
		string s; cin >> s;
		sort(all(s));
		int ma = 0, mi = 1000000000;
		do {
			int a = atoi(s.c_str());
			ma = max(ma, a);
			mi = min(mi, a);
		} while(next_permutation(all(s)));
		cout << ma - mi << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

def solve():
    n = II()
    D = [[0]*10 for _ in range(10)]

    for i in range(1, n+1):
        s = list(str(i))
        l = int(s[0])
        r = int(s[-1])
        # print(s, l, r)
        D[l][r] += 1
    # print(D)

    ans = 0
    for i in range(10):
        for j in range(10):
            ans += D[i][j] * D[j][i]
    print(int(ans))

if __name__ == '__main__':
    solve()


Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AOJ_ITP_1_1_C
{
    class Program
    {
        static void Main(string[] args)
        {
            //長方形の縦と横の長さが入力される
            string[] str = Console.ReadLine().Split(' ');
            int a = int.Parse(str[0]);
            int b = int.Parse(str[1]);
            //長方形の面積と外周
            Console.WriteLine(a*b + " " + 2*(a+b));
        }
    }
}



Measured memory_bytes: 13832
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();

		char c = s.charAt(0);

		s = s.replace("" + c, "");

		String ans = "No";

		if (s.length() == 2 && s.charAt(0) == s.charAt(1))
			ans = "Yes";

		System.out.println(ans);

		sc.close();
	}

}


Measured memory_bytes: 23764
#include <stdio.h>
#include <stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x)
{
    while (x->left != NIL) x = x->left;
    return x;
}

Node treeMaximum(Node x)
{
    while (x->right != NIL) x = x->right;
    return x;
}

Node treeSearch(Node x, int k)
{
    if (x == NIL || k == x->key) return x;
    if (k < x->key) return treeSearch(x->left, k);
    else return treeSearch(x->right, k);
}

Node treeSuccessor(Node x)
{
    if (x->right != NIL) return treeMinimum(x->right);
    Node y = x->parent;
    while (y != NIL && x == y->right)
    {
        x = y;
        y = y->parent;
    }
    return y;
}

//void treeDelete(Node z){
//  Node y; // node to be deleted
//  Node x; // child of y
//
//
//
//}

void insert(int k){
    Node y = NIL;
    Node x = root;
    Node z;

    z = malloc(sizeof(struct node));
    z->key = k;
    z->left = NIL;
    z->right = NIL;
  
    while (x != NIL)
    {
        y = x;
        if (z->key < x->key) x = x->left;
        else x = x->right;
    }
    
    z->parent = y;
    
    if (y == NIL) root = z;
    else if (z->key < y->key) y->left = z;
    else y->right = z;
}

void inorder(Node u)
{
    if (u != NIL)
    {
        inorder(u->left);
        printf(" %d", u->key);
        inorder(u->right);
    }
}
void preorder(Node u)
{
    if (u != NIL) 
    {
        printf(" %d", u->key);
        preorder(u->left);
        preorder(u->right);
    }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");}
//    } else if ( com[0] == 'd' ){
//      scanf("%d", &x);
//      treeDelete(treeSearch(root, x));
//    }
  }

  return EXIT_SUCCESS;
}



Measured memory_bytes: 20468
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	iv, _ := strconv.Atoi(scanString())
	return iv
}

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

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 100001), 100001*100)
}

func main() {
	h, w := scanInt(), scanInt()
	xm := make(map[rune]int)
	for i := 0; i < h; i++ {
		a := scanString()
		for _, v := range a {
			xm[v]++
		}
	}

	var g1, g2, g4 int
	if h%2 == 1 && w%2 == 1 {
		g1 = 1
	}
	if h%2 == 1 {
		g2 += w / 2
	}
	if w%2 == 1 {
		g2 += h / 2
	}
	g4 = (h / 2) * (w / 2)

	for i := 0; i < g4; i++ {
		found := false
		for j := range xm {
			if xm[j] >= 4 {
				xm[j] -= 4
				found = true
				break
			}
		}
		if !found {
			fmt.Println("No")
			return
		}
	}
	for i := 0; i < g2; i++ {
		found := false
		for j := range xm {
			if xm[j] >= 2 {
				xm[j] -= 2
				found = true
				break
			}
		}
		if !found {
			fmt.Println("No")
			return
		}
	}
	if g1 == 1 {
		found := false
		for j := range xm {
			if xm[j] >= 1 {
				xm[j]--
				found = true
				break
			}
		}
		if !found {
			fmt.Println("No")
			return
		}
	}
	fmt.Println("Yes")
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
typedef pair<int,int>P;
typedef pair<P,int>P1;
vector<P>v[100009];
int n,m,a1,a2,a3,a4;
int d[100009],pre[100009];
int xx[100009];
map<P,int>M;
int main(){
  while(cin>>n>>m,n){
    fill(d,d+n,(int)1e9);
    fill(xx,xx+n,(int)1e9);
    r(i,n)v[i].clear();
    r(i,m){
      cin>>a1>>a2>>a3>>a4;
      a1--,a2--;
      v[a1].push_back(P(a2,a3));
      v[a2].push_back(P(a1,a3));
      M[P(a1,a2)]=a4;
      M[P(a2,a1)]=a4;
    }
    priority_queue<P1,vector<P1>,greater<P1> >q;
    d[0]=0;
    int ans=0;
    q.push(P1(P(0,0),0));
    while(!q.empty()){
      P1 p=q.top();q.pop();
      int cost=p.first.first;
      int now=p.second;
      if(d[now]<cost)continue;
      xx[now]=min(xx[now],p.first.second);
      r(i,v[now].size()){
        P p=v[now][i];
        int next=p.first;
        int cost2=cost+p.second;
        if(d[next]>=cost2){
          d[next]=cost2;
          q.push(P1(P(cost2,M[P(now,next)]),next));
        }
      }
    }
    r(i,n-1)ans+=xx[i+1];
    cout<<ans<<endl;
  }
}

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

int main()
  {
  int N;
  cin >> N;
  vector <int> H(N); 
  for(int num=0; num<N; ++num){
    cin >> H[num];
      }
  
  int k=0;
  
  for(int num=0; num<N; ++num){
    bool s = true;
      for (int t = 0; num>t; ++t){
        if (H[t]>H[num]){
          s = false;
          break;
          }}
        if (s){
          ++k;}}
    
  cout << k <<endl;
  
  return 0;
  }
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define speed                   \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define oprecision    \
  cout.precision(30); \
  cerr.precision(7);
#define ll long long
#define ld long double
#define ss string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define forn(n) for (int i = 1; i <= n; i++)
#define forlr(l, r) \
  for (int i = l; (l > r ? i >= r : i <= r); (l > r ? i-- : i++))
#define pb push_back
#define pc __builtin_popcount
#define pcll __builtin_popcountll
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
using namespace std;
int n;
ss s;
int main() {
  speed;
  oprecision;
  // code
  cin >> n >> s;
  if (s.size() <= n) {
    cout << s;
    return 0;
  }
  for (int i = 0; i < n; i++) cout << s[i];
  cout << "...";
  // endl
#ifndef ONLINE_JUDGE
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

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

int main(){
    vector<char> c1(3), c2(3);
    bool f = true;
    for (int i = 0; i < 3; i++) {
        cin >> c1[i];
    }
    for (int i = 2; i >= 0; i--) {
        cin >> c2[i];
    }
    for (int i = 0; i < 3; i++) {
        if(c1[i] != c2[i]) f = false;
    }
    if(f) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
// AOJ Volume 5 Problem 0505 Questionnaire

#include <stdio.h>

typedef struct {
    int place;
    int count;
} QUEST;

int main(void)
{
    int n, m;
    QUEST data[100], tmp;
    int i, j;
    int wish;

    
    while (1){
        scanf("%d%d", &n, &m);
        
        if (n == 0 && m == 0){
            break;
        }
        
        for (i = 0; i < m; i++){
            data[i].place = i + 1;
            data[i].count = 0;
        }
        
        for (i = 0; i < n; i++){
            for (j = 0; j < m; j++){
                scanf("%d", &wish);
                data[j].count += wish;
            }
        }
        
        for (i = 0; i < m - 1; i++){
            for (j = 0; j < m - i - 1; j++){
                if (data[j].count < data[j + 1].count){
                    tmp = data[j];
                    data[j] = data[j + 1];
                    data[j + 1] = tmp;
                }
            }
        }
        
        printf("%d", data[0].place);
        for (i = 1; i < m; i++){
            printf(" %d", data[i].place);
        }
        printf("\n");
    }
    
    return (0);
}

Measured memory_bytes: 604
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();    
    int c = sc.nextInt();    
    int d = sc.nextInt();
    if (Math.abs(a-c) <= d || Math.abs(a-b) <= d && Math.abs(b-c) <= d) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

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

string code(char c){
  if(c == ' ')return "101";
  if(c == '\'')return "000000";
  if(c == ',')return "000011";
  if(c == '-')return "10010001";
  if(c == '.')return "010001";
  if(c == '?')return "000001";
  if(c == 'A')return "100101";
  if(c == 'B')return "10011010";
  if(c == 'C')return "0101";
  if(c == 'D')return "0001";
  if(c == 'E')return "110";
  if(c == 'F')return "01001";
  if(c == 'G')return "10011011";
  if(c == 'H')return "010000";
  if(c == 'I')return "0111";
  if(c == 'J')return "10011000";
  if(c == 'K')return "0110";
  if(c == 'L')return "00100";
  if(c == 'M')return "10011001";
  if(c == 'N')return "10011110";
  if(c == 'O')return "00101";
  if(c == 'P')return "111";
  if(c == 'Q')return "10011111";
  if(c == 'R')return "1000";
  if(c == 'S')return "00110";
  if(c == 'T')return "00111";
  if(c == 'U')return "10011100";
  if(c == 'V')return "10011101";
  if(c == 'W')return "000010";
  if(c == 'X')return "10010010";
  if(c == 'Y')return "10010011";
  return "10010000";
}

string decode(string s){
  string res;
  for(int i=0;i<(int)s.size();i+=5){
    int tmp=0,k=1;
    for(int j=4;j>=0;j--){
      tmp += (s[i+j] - '0') * k;
      k *= 2;
    }

    if(tmp <26)res.push_back('A'+tmp);
    if(tmp == 26)res.push_back(' ');
    if(tmp == 27)res.push_back('.');
    if(tmp == 28)res.push_back(',');
    if(tmp == 29)res.push_back('-');
    if(tmp == 30)res.push_back('\'');
    if(tmp == 31)res.push_back('?');
  }
  return res;
}

int main(){
  char str[10000];

  while(fgets(str,10000,stdin)!=NULL){
    int pos = 0;
    string c;
    while(str[pos]!='\n')c += code(str[pos++]);

    while((int)c.size()%5)c.push_back('0');

    cout << decode(c) << endl;
  }
}

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

#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#define fo(i, a, b, k) for(int i = a; i <= b; i += k)
#define _fo(i, a, b, k) for(int i = a; i >= b; i -= k)
#define foa(i, a) for (auto &i : a)
#define fod(i, a) for(int i = 1; i*i <= a; i++)
#define sz(a) ((int) a.size())
#define all(a) begin(a), end(a)
#define fi first
#define se second
#define pb(x) push_back(x)
#define mk(x, y) make_pair(x, y)  
#define log2i(x) (31-__builtin_clz(x))
#define log2ll(x) (63-__builtin_clzll(x)) 
#define msz(x) __builtin_popcount(x) 
#define mszll(x) __builtin_popcountll(x) 
#define fom(i, a, b) for(int i = a; i < (1<<b); i++)
#define ifon(i, mask) if(mask&(1<<i))
#define ss(i, mask) while(i=(i-mask)&mask)
#define ifss(i, mask) if(i > (mask^i)) 

int n, mn, mx, cnt;

bool solve() {
	if(mx-mn > 1) return false;
	if(mx-mn == 1) {
		int k = mx;
		if(cnt >= k) return false;
		return ((n-cnt) >= (k-cnt)*2);	
	}
	if(mx == mn) {
		if(mn == n-1) return true;
		return (n >= (mn)*2);
	}
}

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	cin >> n;
	mn = n;
	mx = 0;
	fo(i, 1, n, 1) {
		int val;
		cin >> val;
		
		if(val < mn) {
			cnt = 1;
			mn = val;
		}
		else if(val == mn) cnt++;
		
		mx = max(mx, val);
	}
	
	if(solve())	cout << "Yes";
	else cout << "No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO ios::sync_with_stdio(0), cin.tie(0)
using namespace std;
typedef long long ll;
const int maxn = 1e9;
const ll p = 1e9 + 7;

ll Pow(ll a, ll b)
{
    ll ans = 1;
    while (b)
    {
        if (b & 1)
            ans = (ans * a) % p;
        a = (a * a) % p;
        b >>= 1;
    }
    return ans;
}

ll C(ll n, ll m)
{
    if (m == 0)
        return 1;
    if (m > n - m)
        m = n - m;
    ll up = 1, down = 1;
    for (ll i = 1; i <= m; i++)
    {
        up = (up * (n - i + 1)) % p;
        down = (down * i) % p;
    }
    return up * Pow(down, p - 2) % p;
}
int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    //cout << Pow(2, n) - 1 << ' ' << C(n, a) << ' ' << C(n, b) << endl;
    cout << (Pow(2, n) - 1 - (C(n, a) + C(n, b)) % p+p) % p << endl;
    return 0;
}


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

int main(){
	long long int n,k;
	cin>>n>>k;
	vector<vector<long long int> > wg(1001,vector<long long int>(1001,0));
	vector<vector<long long int> > bg(1001,vector<long long int>(1001,0));
	
	for(long long int i=0;i<n;i++){
		long long int a,b;
		char c;
		cin>>a>>b>>c;
		if((c=='B'&&((a/k)+(b/k))%2==0)||(c=='W'&&((a/k)+(b/k))%2==1)){
			bg[a%k][b%k]++;
		}else{
			wg[a%k][b%k]++;
		}
	}
	
	long long int ans=0;
	
	vector<vector<long long int> > brui(1002,vector<long long int>(1002,0));
	for(int i=0;i<k;i++){
		for(int j=0;j<k;j++){
			brui[i+1][j+1]=bg[i][j];
		}
	}
	for(int i=0;i<k+1;i++){
		for(int j=0;j<k;j++){
			brui[i][j+1]+=brui[i][j];
		}
	}
	for(int i=0;i<k;i++){
		for(int j=0;j<k+1;j++){
			brui[i+1][j]+=brui[i][j];
		}
	}
	
	vector<vector<long long int> > wrui(1002,vector<long long int>(1002,0));
	for(int i=0;i<k;i++){
		for(int j=0;j<k;j++){
			wrui[i+1][j+1]=wg[i][j];
		}
	}
	for(int i=0;i<k+1;i++){
		for(int j=0;j<k;j++){
			wrui[i][j+1]+=wrui[i][j];
		}
	}
	for(int i=0;i<k;i++){
		for(int j=0;j<k+1;j++){
			wrui[i+1][j]+=wrui[i][j];
		}
	}
	
	for(int i=0;i<k+1;i++){
		for(int j=0;j<k+1;j++){
			ans=max(ans,brui[i][j]+
				brui[k][k]-brui[i][k]-brui[k][j]+brui[i][j]+
				wrui[i][k]+wrui[k][j]-wrui[i][j]-wrui[i][j]);
			ans=max(ans,wrui[i][j]+
				wrui[k][k]-wrui[i][k]-wrui[k][j]+wrui[i][j]+
				brui[i][k]+brui[k][j]-brui[i][j]-brui[i][j]);
		}
	}
	
	cout<<ans<<endl;
	
}

Measured memory_bytes: 31744
using System;

namespace ABC056B
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] bufs = Console.ReadLine().Split(' ');
            int W = Int32.Parse(bufs[0]);
            int a = Int32.Parse(bufs[1]);
            int b = Int32.Parse(bufs[2]);

            int res = 0;

            if (b > (a + W))
            {
                res = b - (a + W);
            }
            else if (a > (b + W))
            {
                res = a - (b + W);
            }

            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
int n=100005;
vector<pair<int,int>>adj[100005];
long long dist[100005];
bool processed[100005];
long long inf = 10000000000000009;
void dijkstra(int s)
{
	priority_queue<pair<long long,int>> q;
	q.push({0,s});
	while(!q.empty())
	{
		int a = q.top().second; q.pop();
		if(processed[a])
			continue;
		processed[a]=true;
		for(auto u : adj[a])
		{
			int b = u.first; long long w=u.second;
			if(dist[a]+w < dist[b]){
			dist[b]=dist[a]+w;
			q.push({-dist[b],b});
			}
		}
	}

}

int main()
{
	cin>>n;
	for(int i=0;i<n-1;i++)
	{
		int a,b;long long c;
		cin>>a>>b>>c;
		a--;b--;
		adj[a].push_back({b,c});
		adj[b].push_back({a,c});
	}
	int q,k;
	cin>>q>>k;
	k--;
	for(int i=0;i<n;i++){
		dist[i]=inf;
		processed[i]=false;
	}
	dist[k]=0;
	dijkstra(k);

	while(q-->0)
	{
		int x,y;
		cin>>x>>y;
		x--;y--;
		cout<<dist[x]+dist[y]<<"\n";
	}

}

Measured memory_bytes: 12476
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,s=0;
	cin>>n;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= n; j++)
			for(int k = 1; k<= n; k++)
				s+=__gcd(k,__gcd(i, j));
	cout<<s;
	return 0;
}

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

int main() {
    int N;
    int V = 100; // bucket volume
    int tmp;
    int cnt = 0;
    cin >> N;
    int a[105];
    for(int i = 0; i < N ; i++) cin >> a[i];
    
    int num[105] = {0}; // bucket

    for(int i = 0; i < N ; i++) {
        ++num[a[i]];
    }
    for(int i = 1; i <= V ; i++) {
        if(num[i] > 0) ++cnt;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

//nまでの素数表を返す
vector<ll> prime(ll n){
	ll visited[300010]={};
	vector<ll> p;
	reg(i,2,n){
		if(visited[i]==0){
			p.push_back(i);
			reg(j,2,n){
				if(j*i>n)break;
				visited[i*j]=1;
			}
		}
	}
	return p;
}

int main(void){
	ll n;
	vector<ll> prime_list=prime(100010);
	cin>>n;
	printf("%lld:",n);
	rep(i,prime_list.size()){
		while(n%prime_list[i]==0){
			n/=prime_list[i];
			printf(" %lld",prime_list[i]);
		}
	}
	if(n!=1)printf(" %lld",n);
	printf("\n");
	return 0;
}


Measured memory_bytes: 5772
#from functools import lru_cache
import sys
from itertools import product,combinations
from functools import reduce,lru_cache
import heapq

def vfunc(f): return lambda *lst, **kwargs: list(map(lambda *x:f(*x,**kwargs),*lst))

def list_t(l): return vfunc(lambda *args:args)(*l)

def rvfunc(f): return lambda *lst, **kwargs: list(map(lambda *x:rvfunc(f)(*x,**kwargs) if all(vfunc(lambda y:isinstance(y,list))(x)) else f(*x,**kwargs),*lst))

def reader():return vfunc(lambda l:l.split())(sys.stdin.readlines())

n,a = rvfunc(int)(reader())
tmax=0
f=0
for i in range(n[0]):
    ai=a[i]
    if a[i]>tmax:tmax=a[i]
    f+=tmax-a[i]
print(f)

Measured memory_bytes: 94508
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,tune=native")
 
using namespace __gnu_pbds;
using namespace std;
     
#define mp make_pair
#define sz(x) (int)((x).size())
#define all(x) (x).begin(),(x).end()
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define eb emplace_back
 
typedef pair< int, int > pii;
typedef pair< long long, long long > pll;
typedef long long ll;
typedef unsigned long long ull;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vll;
typedef vector< vll > vvll;
typedef vector< pii > vpii;
typedef vector< vpii > vvpii;
typedef vector< pll > vpll;
typedef long double ld;
typedef vector< ld > vld;
typedef unsigned int uint;
 
const ll MOD2 = 1e9 + 7;
const int MOD = 1e9 + 7;
 
const ull infull = numeric_limits<unsigned long long>::max();
 
void fix(int &x, ll MOD) {
    x = (x % MOD);
    if(x < 0) x += MOD;
    return;
}
 
ll lgput(ll a, ll b, ll MOD) {
    ll ret = 1;
    a %= MOD;
    while(b) {
        if(b&1) ret = ret*a % MOD;
        a = a*a % MOD;
        b >>= 1;
    }
 
    return ret;
}
 
ll inv(ll a, ll MOD) {
    return lgput(a, MOD-2, MOD);
}
 
template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    const bool operator<(const M& o) const {return v < o.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
 
using Mint = ModInt<998244353>;

int main() { 
    #ifdef BLAT
        freopen("stdin", "r", stdin);
        freopen("stderr", "w", stderr);
    #endif
 
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(12);
    srand(time(NULL));

    int k, n;
    cin >> k >> n;

    vi v(n);
    for(auto &x : v) cin >> x;

    int maxx = 0;

    for(int i = 0; i < n - 1; ++i) {
        maxx = max(maxx, v[i+1] - v[i]);
    }

    maxx = max(maxx, v[0] + k - v.back());

    cout << k - maxx << '\n';
    return 0; 
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define ALL(v) v.begin(),v.end()
typedef long long ll;
int main() {
  long double a,b,x;
  cin >> a >> b >> x;
  long double v=a*a*b;
  long double arg;
  if(v==2*x) arg = atan(b/a)*180.0/PI;
  if(v>2*x) arg = atan(a*b*b/(2*x))*180.0/PI;
  if(v<2*x) arg = atan(2*(a*a*b-x)/(a*a*a))*180.0/PI;
  cout <<  fixed << setprecision(10) <<  arg << endl;
  
}




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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int N=in();
	auto R=vecin(N);
	int num=0;
	REP(i,N){
		for(int j=0;j<N-1-i;j++){
			if(R[j]>R[j+1]){
				swap(R[j],R[j+1]);
				num++;
			}
		}
	}
	REP(i,N-1){
		cout << R[i] << ' ';
	}
	out(R[N-1]);
	out(num);

	return 0;
}



Measured memory_bytes: 3192
#include<stdio.h>
#include<string.h>
#define LEN 1001
void nativeStringSearch(char*,char*);
int main(void)
{
  char str1[LEN],str2[LEN];
  scanf("%s%s",str1,str2);
  nativeStringSearch(str1,str2);
  return 0;
}
void nativeStringSearch(char *str1,char *str2)
{
  int i;//counter
  for(i=0;strlen(str1)>=strlen(str2);i++,str1++)
    {
      if(strncmp(str1,str2,strlen(str2))==0) printf("%d\n",i);
    }
}


Measured memory_bytes: 2104
import sys

n, k = map(int, sys.stdin.read().split())

def main():
    m = str(n)
    l = len(str(n))
    dp1 = [[0] * (k + 1) for _ in range(l+1)]
    dp2 = [[0] * (k + 1) for _ in range(l+1)]
    dp2[0][0] = 1
    for i in range(l):
        d = int(m[i])
        for j in range(k+1):
            dp1[i+1][j] += dp1[i][j]
            if d > 0:
                dp1[i+1][j] += dp2[i][j]
            if j >= 1:
                dp1[i+1][j] += dp1[i][j-1] * 9 + dp2[i][j-1] * max(d - 1, 0)
            
            if d == 0:
                dp2[i+1][j] += dp2[i][j]
            elif j >= 1:
                dp2[i+1][j] += dp2[i][j-1]

    return dp1[l][k] + dp2[l][k]

if __name__ == '__main__':
    ans = main()
    print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
using namespace std;
typedef long long ll;
const int N = 2 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
int main(){/*
    freopen("in","r",stdin);
    freopen("out","w",stdout);*/
    int n;
    ll t;
    cin >> n >> t;
    vector<ll> v(n + 1);
    ll ans = 0;
    fore(i,0,n)cin >> v[i];
    v[n] = 1LL << 60;
    ans = 0;
    ll aux = 0;
    fore(i,0,n - 1){
        ans += min(t,v[i + 1] - v[i]);
    }
    ans += t;
    cout << ans << endl;
    return 0;
}   

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

int main() {
  int a, b, number = 0;
  cin >> a >> b;
  
  for (int i = a; i <= b; i++) {
    if (i / 10000 == i % 10 && i / 1000 % 10 == i % 100 / 10) number++;
  }
  
  cout << number << endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define int long long
#define N 300005
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
int cnt[N];
int sum[N],ans[N];
signed main()
{
#ifdef __LOCAL__
	freopen("in.txt","r",stdin);
#endif
	int n=read();
	for(int i=1;i<=n;i++)
	{
		int x=read();
		cnt[x]++;
		sum[cnt[x]]++;
	}
	for(int i=1;i<=n;i++)
	{
		sum[i]+=sum[i-1];
	}
	int cur=0;
	for(int i=n;i>=1;i--)
	{
		while(cur<n&&sum[cur+1]>=i*(cur+1)) cur++;
		ans[i]=cur;
	}
	for(int i=1;i<=n;i++) printf("%lld\n",ans[i]);
#ifdef __LOCAL__
	printf("Time Used : %d\n",clock());
#endif
	return 0;
}



Measured memory_bytes: 7936
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = Integer.parseInt(sc.next());
        }
        
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < n; i++){
            sb.append(a[i]).append(" ");
        }
        sb.delete(sb.length()-1, sb.length());
        sb.append(System.lineSeparator());
        
        for(int i = 1; i < n; i++){
            int v = a[i];
            int j = i-1;
            while(j >= 0 && a[j] > v){
                a[j+1] = a[j];
                j--;
                a[j+1] = v;
            }
            
            for(int k = 0; k < n; k++){
                sb.append(a[k]).append(" ");
            }
            sb.delete(sb.length()-1, sb.length());
            sb.append(System.lineSeparator());
        }
        
        System.out.print(sb);
    }
}


Measured memory_bytes: 27620
#ifdef DBG1
#define _GLIBCXX_DEBUG
#endif

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <functional>

#ifdef DBG1
#define dbg(...) fprintf(stderr, __VA_ARGS__)
#else
#define dbg(...)
#endif

using namespace std;

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

const int P = 998244353;

int &add(int &a, int b) {
  if ((a += b) >= P) {
    a -= P;
  }
  return a;
}

const int MAXN = 310;
int dp[2][MAXN][MAXN];

bool solve() {
  static char s[400];
  int k;
  if (scanf("%s%d", s, &k) != 2) return false;

  int n = strlen(s);
  reverse(s, s + n);

  vector<int> a;
  a.push_back(0);
  int ones = 0;
  for (int i = 0; i < n; ++i) {
    if (s[i] == '0') {
      a.push_back(0);
    } else {
      ones++;
      a.back()++;
    }
  }

  for (int x : a) {
    dbg("%d ", x);
  }
  dbg("\n");

  k = min(ones, k);
  int m = int(a.size());

  memset(dp, 0, sizeof(dp));

  auto get = [&](int i, int j, int p) -> int&{
    return dp[i&1][j][p];
  };

  for (int j = 0; j <= a[0]; ++j) {
    get(0, j, j) = 1;
  }

  for (int i = 1; i <= m; ++i) {
    for (int j = 0; j <= k; ++j) {
      for (int p = 0; p <= k; ++p) {
        auto &cur = get(i - 1, j, p);
        if (cur == 0) { continue; }
        dbg("dp[%d][%d][%d] = %d\n", i - 1, j, p, cur);
        if (i == m) { continue; }

        for (int q = 0; q <= ones; ++q) {
          int delta = a[i] - q;
          int newJ = j + (delta < 0 ? 0 : delta);
          int newP = p + delta;
          if (newJ > k || newP < 0 || newP > k) { continue; }
          auto &next = get(i, newJ, newP);
          add(next, cur);
        }

        cur = 0;
      }
    }
  }

  int ans = 0;
  for (int j = 0; j <= k; ++j) {
    add(ans, get(m - 1, j, 0));
  }
  printf("%d\n", ans);

  return true;
}

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


Measured memory_bytes: 4540
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn d(x: usize, y: usize) -> i64 {
    (x as i64 - y as i64).abs()
}

fn main() {
    let (N, mut X, mut Y) = read!(usize, usize, usize);
    X -= 1;
    Y -= 1;

    let mut dist = vec![vec![0; N]; N];

    for u in 0..N - 1 {
        dist[u][u + 1] = 1;

        for v in u + 1..N {
            dist[u][v] = min(v - u, (d(u, X) + 1 + d(Y, v)) as usize);
        }
    }

    let mut freq = vec![0; N];
    for u in 0..N {
        for v in u + 1..N {
            freq[dist[u][v]] += 1;
        }
    }

    for k in 1..N {
        println!("{}", freq[k]);
    }
}


Measured memory_bytes: 45308