akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

class Main{
    private void compute(){
        int i, j, k, r, c;
        int cnt = 0;
        int ans = 0;
        int tmp = 0;
        String inStr, tmpStr;
        char tmpChar;

        Scanner sc = new Scanner(System.in);
        int C = sc.nextInt();
        int N = sc.nextInt();
        int[][] p = new int[N+1][N+1];

        for (i = 1; i <= N; i++){
            inStr = sc.next();
            for (j = 1; j <= N; j++){
                tmpChar = inStr.charAt(j - 1);
                p[i][j] = Character.getNumericValue(tmpChar);
            }
        }


        cnt = 1;
        out_of_loop:
        for (i = 1; i <= (N / 2); i++){
            for (j = 1; j <= (N / 2); j++){
                if ((p[i][j] != p[i][N+1-j]) || (p[i][j] != p[N+1-i][j]) || (p[i][j] != p[N+1-i][N+1-j])){
                    cnt--;
                    break out_of_loop;
                }
            }
        }

        for (i = 2; i <= C; i++){
            int D = sc.nextInt();
            for (j = 1; j <= D; j++){
                r = sc.nextInt();
                c = sc.nextInt();
                switch (p[r][c]){
                case 0:
                    p[r][c] = 1;
                    break;
                case 1:
                    p[r][c] = 0;
                    break;
                }
            }

            cnt++;
            out_of_loop:
            for (j = 1; j <= (N / 2); j++){
                for (k = 1; k <= (N / 2); k++){
                    if ((p[j][k] != p[j][N+1-k]) || (p[j][k] != p[N+1-j][k]) || (p[j][k] != p[N+1-j][N+1-k])){
                        cnt--;
                        break out_of_loop;
                    }
                }
            }
        }

        System.out.println(cnt);
    }
    public static void main(String[] arg){
        new Main().compute();
    }
}


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

#define int long long int
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define lb lower_bound
#define ub upper_bound
#define srt(a) sort(a.begin(),a.end())
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
#define mxe(a) *max_element(a.begin(),a.end())
#define mne(a) *min_element(a.begin(),a.end())
#define endl '\n'
#define mod 1000000007
#define INF64 1e18
const int N=100005;
vi g[N];
vi black(N,1),white(N,1);
vector<bool> visited(N,0);
void dfs(int u){
  visited[u]=1;
  for(int v:g[u]){
    if(visited[v]==0){
      dfs(v);
      black[u]*=white[v];
      black[u]%=mod;
      white[u]*=(white[v]+black[v]);
      white[u]%=mod;
    }
  }
}
void solve(){
  int n ;cin>>n;
  for(int i=1;i<n;i++){
    int x,y;cin>>x>>y;
    g[x].pb(y);
    g[y].pb(x);
  }
  dfs(1);
  cout<<(white[1]+black[1])%mod;
}

int32_t main(){
  #ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
  #endif
  
  ios_base::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);

  int T=1;
  //cin>>T;
  for(int TT=1;TT<=T;TT++){
    solve();
  }
}

Measured memory_bytes: 14552
/*    ####################  */
/*   # I_LOVE_THUY_LINH #  */
/*  ####################  */
#include <bits/stdc++.h>
#define ll long long
#define db double
#define ld long double
#define ii pair<int,int>
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define matrix vector<vector<ll>>
#define fir first
#define sec second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define sz(a) int((a).size())
#define ms(s,val) memset(s,val,sizeof(s))
#define bitcount(n) __builtin_popcountll(n)
#define getbit(s,k) ((s >> k)&1)
#define turnbit(s,k) (s | (1<<k))
#define offbit(s,k) (s & ~(1<<k))
#define flipbit(s,k) (s ^ (1<<k))
#define prec(n) fixed<<setprecision(n)
#define sqr(x) (ll)(x)*(ll)(x)
#define lcm(a,b) ((ll)a/__gcd((ll)a,(ll)b)*(ll)(b))
#define gcd(a,b) __gcd(a,b)
using namespace std;
const int INF = int(1e9);

pair<int,int> split(int x){
    vector<int> d;
    while (x){
        d.pb(x % 10);
        x /= 10;
    }
    return make_pair(d[d.size() - 1],d[0]);
}

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int n;
    cin >> n;
    vector<vector<int>> cnt(10,vector<int> (10));
    for (int x = 1; x <= n; x++){
        ii u = split(x);
        cnt[u.first][u.second]++;
    }

    ll ans = 0;
    for (int x = 1; x <= 9; x++)
        for (int y = 1; y <= 9; y++)
            ans += (ll)cnt[x][y]*(ll)cnt[y][x];
    
    cout << ans;
    

    return 0;
}

Measured memory_bytes: 256
///Have faith in god.
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
///-------------------Typedefine---------------------///
typedef long long ll;
typedef vector<ll> v;
typedef map<ll,ll> mm;
typedef map<string,ll> mp;
typedef pair<ll,ll> pii;
const ll MOD = 1000000007;
const ll N   = 200000;
///-------------------functions----------------------///
bool is_vowel_up(char c){return c=='A'|c=='E'||c=='I'||c=='U'||c=='O'||c=='Y';}
bool is_vowel_low(char c){return c=='a'||c =='e'||c=='i'||c=='u'||c=='o'||c=='y';}
int fx[]={1,1,1,0,-1,-1,-1,0},fy[]={-1,0,1,1,1,0,-1,-1};
ll Strtoll(string str){stringstream ss(str);ll x = 0;ss >> x ;return x ;}
string llostr(ll x){stringstream ss; ss << x; string str = ss.str(); return str;}
template <typename T> T add(T a,T b) { return a + b >= MOD ? a + b - MOD : a + b; }
template <typename T> T sub(T a,T b) { return a - b < 0 ? a - b + MOD : a - b; }
template <typename T> T mul(T a,T b) { return (a * 1LL * b) % MOD; }
template <typename T> T gcd(T a,T b) { return b ? gcd (b,a%b): a; }
template <typename T> T lcm(T a,T b) { return a / gcd (a,b) * b; }
#define     nn           "\n"
#define     ss           " "
#define     pb           push_back
#define     SS(v)        v.size()
#define     pi           acos(-1.0)
#define     CLR(a)       memset(a,0,sizeof(a))
#define     SET(a)       memset(a,-1,sizeof(a))
#define     all(x)       (x).begin(), (x).end()
#define     haha         cout<< "YES" <<endl;
#define     oono         cout<< "NO" <<endl;
#define     INF9         2147483647
#define     INF18        9223372036854775807
#define     deb(x)       cout << #x << " " << x << endl;
#define     _0_          ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int main()
{
   _0_;
      //freopen("input.txt","r" ,stdin);
      string s;
      cin>>s;
      int c=0;
      for(auto i:s)
      {
          if(i=='7')
            c++;
      }
      if(c)
        cout<<"Yes";
      else

        cout<<"No";
    return 0;
}




Measured memory_bytes: 3656
#include<iostream>
using namespace std;
 
int main(){
 
int a,b;
 
cin >> a>>b;
 
if(a>b) cout<<"a > b"<<endl;
else if(a<b) cout<<"a < b"<<endl;
else cout<<"a == b"<<endl;
 
 
return 0;
 
}

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

signed main() {
	int a, b;
	cin >> a >> b;
	int ans = max({a+b, a-b, a*b});
	cout << ans << endl;
}


Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace test1
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = int.Parse(Console.ReadLine());

            var span = TimeSpan.FromSeconds(input);
            Console.WriteLine("{0}:{1}:{2}",
                span.Hours,
                span.Minutes,
                span.Seconds);
        }
    }
}

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

int main(){
	//freopen("in.txt","r",stdin);
	string s,sc;
	cin >> s;
	sc = s;
	int l = s.length();
	int cnt1 = 0,cnt2 = 1;
	for(int i = 1;i <l;i ++){
		if(s[i] == s[i-1]){
			cnt1 ++;
			if(s[i] == '1') s[i] = '0';
			else s[i] = '1';
		}
	//	cout << s<<endl<<cnt1<<endl;
	}
	if(sc[0] == '0') sc[0] = '1'; else sc[0] = '0';
	s = sc;
	
	for(int i = 1;i <l;i ++){
		if(s[i] == s[i-1]){
			cnt2 ++;
			if(s[i] == '1') s[i] = '0';
			else s[i] = '1';
		}
	//	cout << s <<endl << cnt2<<endl;
	}
	if(cnt2 > cnt1) cnt2 = cnt1;
	printf("%d",cnt2);
	//fclose(stdin);
    return 0;
}


Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;
long long p[200000];
long long p_sums[200000];
int main(void){
  int N;
  int K;
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    cin >> p[i];
  }
  for(int i = 0; i < K; i++){
    p_sums[0] += p[i];
  }
  for(int i = 1; i < N - K + 1; i++){
    p_sums[i] = p_sums[i - 1] - p[i - 1] + p[i + K - 1];
  }
  long long max_p_sums = 0;
  for(int i = 0; i < N - K + 1; i++){
    max_p_sums = max(max_p_sums, p_sums[i]);
  }
  cout << setprecision(15) << (double) (max_p_sums + K) / 2.0  << endl;
  return 0;
}

Measured memory_bytes: 3328
def solution(s):
    n = len(s)
    k = s[0]
    for i in xrange(1, n):
        if s[i] > k:
            return chr(ord(k) + 1) * n
    return k * n

def main():
    d = int(raw_input().strip())
    print solution(str(d))

if __name__ == '__main__':
    main()

Measured memory_bytes: 2568
#include <stdio.h>
#define INF 100000000

int m[101][101];
int p[101];

int matrixChainOrder(int n) {
  int i, j, l, k, q;

  for (i = 1; i <= n; i++) {
    m[i][i] = 0;
  }
  for(l = 2; l <= n; l++) {
    for(i = 1; i <= n-l+1; i++) {
      j = i+l-1;
      m[i][j] = INF;
      for(k = i; k < j; k++) {
        q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
        if(m[i][j] > q) m[i][j] = q;
      }
    }
  }
  return m[1][n];
}

int main() {
  int n, i, x, k;

  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    scanf("%d", &p[i]);
    if(i < n-1)scanf("%d", &k);
  }
  scanf("%d", &p[n]);
  x = matrixChainOrder(n);
  printf("%d\n", x);

  return 0;
}

Measured memory_bytes: 632
#include<iostream>
#include<vector>
#include<map>
using namespace std;
main(){
  //mlÛ¶vÛ¶
  long long a,b,c,n,f;
  //aÔbP¿cÊ
  while(cin>>n,n){
		map<int,long long> m;
		vector<int> v;
		f=1;
    for(;n;n--){
			cin>>a>>b>>c;
      if(!m[a])v.push_back(a);
      m[a] += b*c;
    }
    
    for(int i=0;i<v.size();i++)
			if(m[v[i]]>999999)f=0,cout<<v[i]<<endl;
    if(f)cout<<"NA"<<endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main(){
    int R,C,sy,sx,gy,gx,ny,nx;
    int INF=100000000;
    queue<int> que;
    char c[55][55];
    cin >> R >> C;
    sx = 0; sy = 0;
    gx = C-1; gy = R-1;
    int black = 0,white = 0;
    for(int i=0;i<R;i++){
        for(int j=0;j<C;j++){
            cin >> c[i][j];
            if(c[i][j]=='.')white++;
            if(c[i][j]=='#')black++;
        }
    }
    int d[55][55];
    for(int i=0;i<55;i++){
        for(int j=0;j<55;j++){
            d[i][j] = INF;
        }
    }

    d[sy][sx]=0;
    que.push(sy);
    que.push(sx);
    while(que.size()!=0){
        int y = que.front();
        que.pop();
        int x = que.front();
        que.pop();

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

        for(int i=0;i<4;i++){
            ny = y + dy[i];
            nx = x + dx[i];
            if( 0<=nx && 0<=ny && nx<C && ny<R && c[ny][nx]!='#' && d[ny][nx]==INF){
                que.push(ny);
                que.push(nx);
                d[ny][nx] = d[y][x] + 1;
            }
        }
    }
    if(d[gy][gx]==INF){
        cout << -1 << endl;
    }else{
        cout << white - d[gy][gx] - 1 << endl;
    }
}


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


int main() {
    unsigned int firstNumber;
    unsigned int lastNumber;
    std::cin >> firstNumber >> lastNumber;
    
    unsigned int numOfPalindrome = 0U;
    for(unsigned int i = firstNumber; i <= lastNumber; ++i) {
        std::string forwardNumber = std::to_string(i);
        std::string reverseNumber = forwardNumber;
        std::reverse(reverseNumber.begin(), reverseNumber.end());
        
        if(forwardNumber == reverseNumber) {
            ++numOfPalindrome;
        }
    }
    std::cout << numOfPalindrome << std::endl;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;
const int mod = 1e9+7;

int main() {
    int k, s; cin >> k >> s;
    int ct = 0;
    for (int x = 0; x <= k; x++) {
        for (int y = 0; y <= k; y++) {
            int z = s-(x+y);
            if (z <= k && 0 <= z) ct++;
        }
    }
    cout << ct << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

constexpr ll MOD = 1000000007;
constexpr int INF = 0x3f3f3f3f;
constexpr ll INFL = 0x3f3f3f3f3f3f3f3fLL;

int main() {
  ll n, x;
  cin >> n >> x;
  vector<ll> a(n);
  for (ll& b : a) cin >> b;

  ll ans = 0;
  rep(i, 0, n - 1) {
    if (a[i] + a[i + 1] > x) {
      ll d = a[i] + a[i + 1] - x;
      ans += d;
      a[i + 1] = max((ll)0, a[i + 1] - d);
    }
  }
  cout << ans << endl;

#ifdef LOCAL
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

Measured memory_bytes: 4028
n = int(input())
# n = 100
m = 0
x = 1
for i in range(1, n+1):
    a = i
    c = 0
    while a % 2 == 0:
        a = a//2
        c += 1
    if c > m:
        x = i
    m = max(m, c)
print(x)


Measured memory_bytes: 2940
import math

def ggcd(p,q,r):
    s = math.gcd(p,q)
    return math.gcd(r,s)

def main():
    n = int(input())
    ans = 0
    for i in range(1,n+1):
        for j in range(1,n+1):
            for k in range(1,n+1):
                ans += ggcd(i,j,k)
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 69852
import java.util.Scanner;
import java.util.HashMap;
import java.util.Map;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int cap = scan.nextInt();
        int[] weights = new int[n];
        int[] values = new int[n];

        int maxValue = 0;
        for(int i = 0 ; i < n ; i++) {
            weights[i] = scan.nextInt();
            values[i] = scan.nextInt();
            maxValue += values[i];
        }

        // approach = bottom-up. but state has value and index.
        // we build the min weights table and find out if we are including the new item or not. 

        long[][] dp = new long[n+1][maxValue+1];
        long optimalValue = 0;
        for(int index = 0 ; index <= n ; index++) {
            for(int value = 1 ; value <= maxValue ; value++) {
                dp[index][value] = 1000000009; // initialize with +INF for the current cell.
            }
        }

        for(int index = 1 ; index <= n ; index++) {
            // Row signifies set of all the elements until this row index. 
            int vi = values[index-1];
            int wi = weights[index-1];
            for(int value = 1 ; value <= maxValue ; value++) {
                if(vi <= value){
                    dp[index][value] = Math.min(dp[index-1][value], wi + dp[index-1][value-vi]);
                } else {
                    dp[index][value] = dp[index-1][value];
                }
            }
        }

        int result = 0;
        for(int col = 0 ; col < maxValue+1;col++){
            if(dp[n][col] <= cap){
                result = col;
            } 
        }
                System.out.println(result);
    }
}


Measured memory_bytes: 127444
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
import sys
input = sys.stdin.readline
#文字列のときはうまく行かないのでコメントアウトすること
sys.setrecursionlimit(2147483647)

def main():
  n, m = map(int, input().split())
  #隣接リストを作る
  path = [[False for i in range(n)] for j in range(n)]
  for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    path[a][b] = True
    path[b][a] = True
  ans = 0
  for i in permutations(range(n), n):
    if i[0] == 0:
      for j in range(n):
        if j == n-1:
          ans += 1
          break
        if not path[i[j]][i[j+1]]:
          break
  print(ans)

if __name__ == '__main__':
  main()

Measured memory_bytes: 39536
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

const int INF = 1e9;
int n, m;
vi s, d;
int dp[111][1 << 15];

int solve(int p, int bit)
{
	if (dp[p][bit] >= 0) return dp[p][bit];
	if (p == m) return 0;
	int res = INF;
	int tmp = 0;
	REP(i, n)
	{
		if ((bit >> i) & 1) tmp += s[i];
	}
	chmin(res, solve(p + 1, bit) + abs(d[p] - tmp));
	REP(i, n)
	{
		if ((bit >> i) & 1) continue;
		chmin(res, solve(p, bit | (1 << i)));
	}
	return dp[p][bit] = res;
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	while (cin >> n >> m, n)
	{
		MS(dp, -1);
		s.resize(n); cin >> s;
		d.resize(m); cin >> d;
		sort(ALL(d));
		cout << solve(0, 0) << endl;
	}
	return 0;
}


Measured memory_bytes: 17396
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int X = sc.nextInt();
    int[] L = new int[N+1];
    int distance = 0, ans = 0;
    for (int i=1; i<=N; i++) {
      L[i] = sc.nextInt();
    }
    for (int i=1; i<=N; i++) {
      if (distance + L[i] > X) {
        ans = i;
        break;
      }
      if ( i == N) {
        ans = i+1;
      }
      distance += L[i];
    }
     System.out.println(ans);
  }
}

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

int main(){
  int x;
  cin >> x;
  long long a,b;
  a=1;
  vector<long long> k;
  k.push_back(0);
  while(a<=120){
    k.push_back(a);
    k.push_back(-a);
    a++;
  }
  a++;
  k.push_back(a);
  k.push_back(-a);
  a=0;
  int n=k.size();
  for(int i=0;i<n;++i){
    for(int j=0;j<n;++j){
      if(pow(k[i],5)-pow(k[j],5)==x){
        a=k[i];
        b=k[j];
        break;
      }
      if(pow(k[j],5)-pow(k[i],5)==x){
        a=k[j];
        b=k[i];
        break;
      }
    }
  }


  cout << a << " " << b << endl;
  return 0;
}


Measured memory_bytes: 4056
N = parse(Int, readline())
S = chomp(readline())

br = 0
pre = ""
suf = ""
for i in 1:N
    if S[i] == '('
        br += 1
    elseif br == 0
        pre *= "("
    else
        br -= 1
    end
end
for i in 1:br
    suf *= ")"
end
println(pre * S * suf)

Measured memory_bytes: 166808
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static long[] h;
	static void Main(){
		Sc sc=new Sc();
		int[] s=sc.Ia;
		int n=s[0],m=s[1];
		h=new long[n];
		var e=new int[m][];
		for(int i=0;i<m;i++){e[i]=sc.Ia;}
		for(int i=0;i<n;i++){h[i]=long.MaxValue;}
		h[s[2]]=0;
		bool bo=true,bn=false;
		for(int i=0;bo&&i<=n;i++){
			bo=false;
			for(int j=0;j<m;j++){
				if(h[e[j][0]]!=long.MaxValue&&h[e[j][1]]>h[e[j][0]]+e[j][2]){
					h[e[j][1]]=h[e[j][0]]+e[j][2];
					bo=true;
					if(i==n){bn=true;break;}
				}
			}
		}
		StringBuilder sb=new StringBuilder();
		if(bn){sb.Append("NEGATIVE CYCLE\n");}
		else{
			for(int i=0;i<n;i++){
				if(h[i]==long.MaxValue){sb.Append("INF\n");}
				else{sb.Append(h[i]+"\n");}
			}
		}
		Console.Write(sb);
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}



Measured memory_bytes: 20080
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
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;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ll ans = 0;
  ll n;
  cin >> n;
  // ll n, m;
  // cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  int arr[] = { 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 };
  cout << arr[n-1]<<endl;
  // cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
/*@author hussein zayed ;
    ___  ___
   |\  \|\  \
   \ \  \_\  \
    \ \   ___ \USSEIN
     \ \  \\ \ \
      \ \__\\ \_\
       \|__| \|__|
****************************************
*/

#include <bits/stdc++.h>
using namespace std;
#define fr for(int i=0;i<n;++i)
#define fr1 for(int i=1;i<=n;++i)
#define cinA for(int i=0;i<n;++i){cin>>arr[i];}
#define cinA1 for(int i=1;i<=n;++i){cin>>arr[i];}
#define coutA for(int i=0;i<n;++i){cout<<arr[i]<<" ";}
#define ll long long
#define lnarray sizeof(arr)/sizeof(*arr)
#define vi vector<int>
#define vs vector<string>
void Fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
inline int RD()
{
    int i ;
    cin>>i;
    return i;
}

inline float RF()
{
    float i ;
    cin>>i;
    return i;
}

inline double RDO()
{
    double i ;
    cin>>i;
    return i;
}

inline string RS()
{
    string i ;
    cin>>i;
    return i;
}

inline ll RLL()
{
    ll i ;
    cin>>i;
    return i;
}

ll sumSet(ll n)
{
    return (1ll*n*(n+1))/2;
}


bool isPrime(int n)
{
    if(n==1)
        return false;
    for(int i=2; i*i<=n; ++i)
    {
        if(n%i==0)
            return false;
    }
    return true;
}
int sumDigit(int n){
int sum =0;
  while (n != 0)
    {
        sum+= + n % 10;
        n = n / 10;
    }
    return sum;
}

ll power2(int n){
  ll ans=(1<<n);
  return ans;
}

ll sumpow2(ll n){
 ll sum=(n*(n+1)*(2*n-1))/6;
 return sum;
}
const int MX=3e5+100;
int n,arr[MX],cm[MX];
int Left,Right,add;
bool can(int x){
 for(int i=1,j=x;j<=n;++i,++j){
  if(cm[j]-cm[i-1]+add>=x){
  Left=i,Right=j;
   return true;}
 }
 return false;
}
bool checkP(int n){
 vector<int>vr;
 while(n!=0){
 int a=n%10;
  n/=10;
 vr.push_back(a);}
 if(vr[0]==vr[4]&&vr[1]==vr[3])
 return true;
 return false;
}
int main(){
    Fast();
//freopen("output.txt" , "w" , stdout);
//freopen("wall.in" , "r" , stdin);

int n=RD(),sum1=0,sum2=0;
bool flag=true;
cinA
sort(arr,arr+n);

 while(n--){
 if(flag==true){
  flag=!flag;
  sum1+=arr[n];
 }
 else{
 flag=!flag;
 sum2+=arr[n];
 }
 }
 int ans=sum1-sum2;
 cout<<ans;
 }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

int main(void){
	int N,A;
	cin >> N >> A;
	int L=A;
	int R=A+N-1;
	int eat;
	if(R<=0)eat=R;
	else if(L>=0)eat=L;
	else if(L<=0&&R>=0)eat = 0;
	int ans=(R+L)*N/2 -eat;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll n, k; cin >> n >> k;

    // a, b, cは整数、ansは条件を満たす組数
    ll a, b, c, ans = 0;

    // k|a+b && k|b+c && k|c+aより、k|2a && k|2b && k|2cである
    if(k%2 == 0){
        // kが偶数の場合、a, b, cは必ずk/2の倍数となる
        ll multi_k = floor(n/k);
        ll multi_kd2 = floor(n/(k/2));
        multi_kd2 -= multi_k;
        ans = pow(multi_k, 3) + pow(multi_kd2, 3);
    }
    else{
        // kが奇数の場合、a, b, cは必ずkの倍数となる
        ll multi = floor(n/k);
        ans = multi * multi * multi;
    }
    
    // 結果の出力
    cout << ans <<endl;
}

Measured memory_bytes: 384
#include <iostream>

int main()
{
  int N, M;
  std::cin >> N >> M;
  int sum = 0;
  int A;
  for (int i=0; i<M; i++) {
    std::cin >> A;
    sum += A;
  }
  if (N-sum>=0) std::cout << N-sum << std::endl;
  else std::cout << -1 << std::endl;
  return 0;
}
  

Measured memory_bytes: 3548
n = input()

S = map(int, raw_input().split())

q = input()

T = map(int, raw_input().split())

S.append(0)
cnt = 0
for i in range(q):
    j = 0
    S[n] = T[i]
    while S[j] != S[n]:
        j = j + 1
    if j != n:
        cnt = cnt + 1


print cnt

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

using namespace std;
using ll = long long;
int main() {
    ll N;
    cin >> N;
    --N;
    ll power = 26LL;
    ll digit = 1;
    while (N >= power) {
        N -= power;
        ++digit;
        power *= 26LL;
    }
    string ans;
    while (digit > 0) {
        ans.push_back('a' + N % 26);
        N /= 26;
        --digit;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f
#define MEM(x,y) memset(x,y,sizeof(x))
#define Maxn 25
using namespace std;
int n,m;
int tmax,tmin;
int a[Maxn];
int ans1[Maxn];
int ans2[Maxn];
int main()
{
    int f;
    cin>>n;
    while(n--)
    {
        f=1;
        MEM(a,0);
        MEM(ans1,0);
        MEM(ans2,0);
        for(int i=1; i<=10; i++)
            cin>>a[i];
        ans1[1]=a[1];
        ans2[0]=0;
        int p1=0,p2=0;
        int i;
        for(i=2; i<=10; i++)
        {
//            if(ans1[p1]>ans[p2])
//            {
//                tmax=ans1[p1];
//                tmin=ans2[p2];
//            }
//            else
//            {
//                tmax=ans2[p2];
//                tmin=ans1[p1];
//            }
            if(a[i]>ans1[p1])
            {
                ans1[++p1]=a[i];
            }
            else if(a[i]>ans2[p2])
            {
                ans2[++p2]=a[i];
            }
            else
            {
                cout<<"NO"<<endl;
                break;
            }
        }
        if(i>10)
            cout<<"YES"<<endl;
    }
}





Measured memory_bytes: 3008
import java.util.Scanner;

class Main
{

    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if (a <= b) {
            System.out.println(b - a);
        } else {
            System.out.println(a - b);
        }
    }
}



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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
#define BIT(bit,a,n) for (int bit = a;bit < (1<<n);bit++) // {0, 1, ..., n-1} の部分集合の全探索 // n番目のフラグが立っている状態は (1<<n)

const int d4x[4] = {1, 0, -1, 0};
const int d4y[4] = {0, 1, 0, -1};
const int d8x[8] = { 1,1,0,-1,-1,-1,0,1 };
const int d8y[8] = { 0,1,1,1,0,-1,-1,-1 };

#define MAX_N (int)2e5+20

typedef long long ll;
using namespace std;

ll l[87] ={0};
int n;
int main() {
    l[0] = 2;
    l[1] = 1;
    scanf("%d",&n);
    rep(i,2,n+1){
        l[i] = l[i-2] + l[i-1];
    }
    printf("%lld\n",l[n]);
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <queue>
const int N = 3e5 + 10;
typedef long long ll;
int n, a[N];
ll ans = -1e18, pre[N], suf[N];
std::priority_queue<int> q;
int main() {
//	freopen("input", "r", stdin);
	scanf("%d", &n);
	for (int i = 1; i <= 3*n; i++) scanf("%d", a + i);
	for (int i = 1; i <= 3*n; i++) {
		pre[i] = pre[i - 1] + a[i];
		q.push(-a[i]);
		if (q.size() > n) {
			int x = -q.top();
			q.pop();
			pre[i] -= x;
		}
	}
	while (!q.empty()) q.pop();
	for (int i = 3*n; i; i--) {
		suf[i] = suf[i + 1] + a[i];
		q.push(a[i]);
		if (q.size() > n) {
			int x = q.top();
			q.pop();
			suf[i] -= x;
		}
	}
	for (int i = n; i <= 2*n; i++) 
		ans = std::max(ans, pre[i] - suf[i + 1]);
	printf("%lld\n", ans);
}

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

#include <cstdio>
#include <cstdlib>
#include <cmath>

#include <iostream>

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long ll;

const ll mod = 1000000007;

class mint{
public:
  ll x;
  mint(ll x=0) : x(x%mod){}
  mint& operator+=(const mint rhs){
    x += rhs.x;
    while(x >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint rhs){
    x -= rhs.x;
    while(x < 0) x += mod;
    return *this;
  }
  mint & operator*=(const mint rhs){
    (x *= rhs.x) %= mod;
    return *this;
  }
  mint operator+(const mint rhs) const {
    mint res(*this);
    return res += rhs;
  }
  mint operator-(const mint rhs) const {
    mint res(*this);
    return res -= rhs;
  }
  mint operator*(const mint rhs) const {
    mint res(*this);
    return res *= rhs;
  }
  bool operator>(const ll rhs) const {
    return x > rhs;
  }
  bool operator<(const ll rhs) const {
    return x < rhs;
  }
  bool operator>=(const ll rhs) const {
    return x >= rhs;
  }
  bool operator<=(const ll rhs) const {
    return x <= rhs;
  }
  bool operator==(const ll rhs) const {
    return x == rhs;
  }
  bool operator!=(const ll rhs) const {
    return x != rhs;
  }
  friend ostream& operator<<(ostream& os,const mint rhs){
    os << rhs.x;
    return os;
  }
};

#define rep(index,num) for(int index=0;index<num;++index)

int main(){
  int K;
  std::string S;
  std::cin >> K >> S;
  if(S.size() <= K) std::cout << S << std::endl;
  else {
    std::string s = S.erase(K);
    std::cout << s << "..." << std::endl;
  }
  return 0;
}


Measured memory_bytes: 3604
string = input()
numbers = string.split()
W = int(numbers[0])
H = int(numbers[1])
x = int(numbers[2])
y = int(numbers[3])
r = int(numbers[4])
if x-r>=0 and y-r>=0 and x+r<=W and y+r<=H:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 5596
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;
const ll LMAX=1000000000000001;


int main(){
int k,x; cin>>k>>x;
if(k*500>=x)
puts("Yes");
else
puts("No");

  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict

def calc(n):
    if memo[n] != float('inf'):
        return memo[n]
    if n == 0:
        return 0
    if n == 1:
        return D
    ans = n * D
    for x, c in [(2, A), (3, B), (5, C)]:
        ans = min(ans, calc(n//x) + c + (n % x) * D)
        if n % x:
            ans = min(ans, calc(n//x + 1) + c + (x - n % x) * D)
    memo[n] = ans
    return memo[n]


t = int(input())
for _ in range(t):
    N, A, B, C, D = map(int, input().split())
    memo = defaultdict(lambda: float('inf'))
    print(calc(N))

Measured memory_bytes: 11240
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input! {
        n:i64,
        mut k:i64,
        mut abn:[(i64,i64);n],
    }
    let mut abn: Vec<(i64, i64)> = abn;
    abn.sort_by_key(|x| x.0);
    let mut ans = 0;
    for &(a, b) in &abn {
        if k <= 0 {
            break;
        }
        k -= b;
        ans = a;
    }
    println!("{}", ans);
}

Measured memory_bytes: 6396
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <iostream>
using namespace std;

int main()
{
	char a[5];
	for (int i= 1; i <= 4; i++){
		scanf("%c", &a[i]);
	}
	if ((a[1] == a[2] && a[2] == a[3]) || (a[2] == a[3] && a[3] == a[4]))
		cout <<"Yes" <<endl;
	else cout <<"No" <<endl;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
p = list(map(int,input().split()))

ls = []
ans = 0

for i in range(k):
    ans += p[i]
    
max_ans = ans
max_index = 0

for i in range(n-k):
    ans -= p[i]
    ans += p[i+k]
    if max_ans < ans:
        max_ans = ans
        max_index = i+1

ans = 0
for i in range(k):
    pp = p[max_index+i]
    for j in range(pp):
        ans += (1/pp*(j+1))
    
print(ans)
        

Measured memory_bytes: 71792
#include <iostream>
#include <string>

using namespace std;
int main() {
  string s, t;
  cin >> s;
  int l = s.size();
  for (int i = 0; i < l; ++i) {
    if (i % 2 == 0) {
      t += s[i];
    }
  }
  cout << t << endl;
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
int A;
  int B;
  int S;
  cin >>A>>B>>S;
  if((A<=S) &&(S<=B+A)) {
cout <<"YES" << endl;
    
  }
else {
cout << "NO" << endl;
}
}


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

using namespace std;

#define ll long long

int n,m,q;
vector<int> a,b,c,d;
int ans = 0;

void dfs(vector<int> A){
  if(A.size() == n+1){
    int now = 0;
    for(int i = 0; i < q; i++){
      if(A[b[i]] - A[a[i]] == c[i]){
        now += d[i];
      }
    }
    ans = max(ans,now);
    return;
  }
  
  A.push_back(A.back());
  while(A.back() <= m){
    dfs(A);
    A.back()++;
  }
}


int main(){
  cin >> n >> m >> q;
  a = b = c = d = vector<int>(q);
  
  for(int i = 0; i < q; i++){
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }

  dfs(vector<int>(1,1));
  cout << ans << endl;
  
  return 0;
  
}


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


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

    vector<string> weather(3);
    weather = {"Sunny", "Cloudy", "Rainy"};

    rep(i, 3) {
        if (S == weather.at(i)) {
            cout << weather.at((i + 1) % 3) << endl;
            return 0;
        }

    }
    return 0;
}

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

typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef pair<ll,ll> lll;

const ll MOD = 1000000007;
const ll INF = 1e9+5;
const double eps = 1e-7;
const double PI = acos(-1.0);

#define FOR(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++)
#define RFOR(i,a,b) for(long long i = (long long)(a); i >= (long long)(b); i--)
#define ull unsigned long long
#define deb(x )     cerr << #x << " = "<< x << endl;
#define endl    "\n"
#define coud(a,d) cout << fixed << showpoint << setprecision(d) << a;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define fill(x, y) memset(x, y, sizeof(y))
#define all(x) (x).begin(), (x).end()
#define bitcount(x) __builtin_popcount(x)
#define cps CLOCKS_PER_SEC
#define verify(x) if(x >= MOD) x -= MOD;

inline void debug_vi(vi a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void debug_vll(vll a) {FOR(i, 0, a.size()) cout<<a[i]<<" ";}
inline void print_case(int tn) {cout<<"Case #"<<tn<<": ";}

template<typename T>
using minpq = priority_queue<T, vector<T>, greater<T>>;

template<typename T>
using maxpq = priority_queue<T>;
/*----------------------------------------------------------------------*/

//return x^y mod p
ll power(ll x,ll y, ll p)
{
    ll res = 1;     
    x = x % p; 
 
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
 
        y = y>>1; // y = y/2
        x = (x*x) % p;  
    }
    return res;
}

int main(){
    std::ios::sync_with_stdio(false);cin.tie(NULL); cout.tie(NULL);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    int n; cin>>n;
    vll arr(n);
    FOR(i, 0, n) cin>>arr[i];
    sort(all(arr));
    ll res = 0;
    FOR(i, 0, n) {
        ll contrib = power(4, i, MOD);
        contrib *= power(2, n - i, MOD); contrib %= MOD;
        contrib *= arr[i]; contrib %= MOD;
        
        if(i < n - 1) {
            ll sm = (power(2, n - i - 1, MOD))%MOD;
            sm += ((n - i - 1) * power(2, n - i - 2, MOD))%MOD; sm %= MOD;
            contrib *= sm; contrib %= MOD;
        }
        
        res += contrib; res %= MOD;
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 4652
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int p,q,r;
	cin>>p>>q>>r;
	
	int sum1 = p + q;
	int sum2 = q + r;
	int sum3 = p + r;
	
	int min_flight = min(sum1,min(sum2,sum3));
	cout<<min_flight<<endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
S = input()

white = [0]*(N+2)
black = [0]*(N+2)

black[0] = 0
white[N] = 0

for i in range(N):
    if S[i] == "#":
        black[i+1] = black[i]+1
    else:
        black[i+1] = black[i]

    if S[N-i-1] == ".":
        white[N-i-1] = white[N-i]+1
    else:
        white[N-i-1] = white[N-i]

count_min = 2 * 10 ** 6
for i in range(N+1):
    if black[i]+white[i] < count_min:
        count_min = black[i]+white[i]

print(count_min)


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

int main(){
  long N,a,b;
  cin >> N;
  cin >> a;
  cin >> b;
  if((N == 1 && a != b) || a > b ){
  cout << 0 << endl;
  }
  else if((N == 1 && a == b) || N == 2 || a == b){
  cout << 1 << endl;
  }
  else {
 cout << (N - 2) * (b - a) + 1 << endl;
 }
 }

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

int main() {
  int a,b,c;
  char d;
  cin >> a >> d >> b >> d >> c;

  if(b <= 4 && c <= 30) cout << "Heisei" << endl;
  else cout << "TBD" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int heap[500000];
int size;

void max_heapify(int heap[], int i) {
    int l = 2 * i + 1;
    int r = 2 * i + 2;
    int largest;

    if (l <= size && heap[l] > heap[i]) {
        largest = l;
    } else {
        largest = i;
    }
    if (r <= size && heap[r] > heap[largest]) {
        largest = r;
    }

    if (largest != i) {
        int tmp = heap[i];
        heap[i] = heap[largest];
        heap[largest] = tmp;
        max_heapify(heap, largest);
    }
}

void build_max_heap(int heap[]) {
    for (int i = size / 2; i >= 0; i--) {
        max_heapify(heap, i);
    }
}

int main(){
    scanf("%d", &size);
    for(int i=0; i<size; i++) {
        int tmp;
        scanf("%d", &tmp);
        heap[i] = tmp;
    }

    build_max_heap(heap);
    for(int i=0; i<size; i++) {
        printf(" %d", heap[i]);
    }
    printf("\n");
}

Measured memory_bytes: 3800
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <vector>
#include <set>
#include <cassert>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <functional>
#include <iomanip>
//#include <windows.h>  //Should be deleted when using AtCoder&POJ
using namespace std;

#define ll long long
#define pii pair<int,int>
#define qi ios::sync_with_stdio(0)
/**==Info==
*Program:1
*Problem:Bringing Order To Disorder
*Date:2019-7-5
*Algorithm:My Rubbish DP that will TLE 
*Stats:Unknown*/

bool debug=false;

map<ll,ll> dp[15][150][3];

const int LIMITED=1,FREE=0,EXCEED=2;
string s;

int allSum;
ll allPro;

ll dfs(int pos,int sum,ll pro,int limit){
	
//	cout<<pos<<" "<<sum<<" "<<pro<<" "<<limit<<endl;
	
//	cout<<"Compare with "<<allSum<<" "<<allPro<<endl;
	
	
	if(sum>allSum){
		return 0;
	}
	if(sum==allSum && pro>allPro){
		return 0;
	}
	if(sum==allSum && pro==allPro && limit==EXCEED){
		return 0;
	}
	if(dp[pos][sum][limit].count(pro)){
		return dp[pos][sum][limit][pro];
	}
//	cout<<"PTP"<<endl;
	
	if(pos==s.size()){
		
//		cout<<"Note:Good"<<endl;
		if(sum<allSum){
			return 1;
		}
		if(sum==allSum && pro<allPro){
			return 1;
		}
//		cout<<"Answer accept protect failed"<<endl;
		if(sum==allSum && pro==allPro){
			
			return !limit;
		}
		return 0;
	}
	
	ll poss=0;
	for(int i=0;i<=9;i++){
//		cout<<"Choosing "<<i<<endl;
//		cout<<"{"<<endl;
		poss+=dfs(pos+1,sum+i,pro*(i+1),(limit==EXCEED?EXCEED:(limit==LIMITED?(i==s[pos]-'0'?LIMITED:(i>s[pos]-'0'?EXCEED:FREE)):FREE)));
//		cout<<"}"<<endl;
	}
	
	return dp[pos][sum][limit][pro]=poss;
}

int main(int argc,char* argv[]){
	cin>>s;
	
	for(int i=0;i<s.size();i++){
		allSum+=s[i]-'0';
	}
	
	allPro=1;
	for(int i=0;i<s.size();i++){
		allPro*=(s[i]-'0'+1);
	}
	
	cout<<dfs(0,0,1,LIMITED)<<endl;
	return 0;
}




Measured memory_bytes: 41668
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		int count=0;
		
		for(int i=0;i<s.length()-1;i++){
			if(s.charAt(i)!=s.charAt(i+1))count++;
		}
		System.out.println(count);
	}

}


Measured memory_bytes: 13472
pxcount=0
pycount=0
pzcount=0

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

for i in p:
  if i<=a:
    pxcount=pxcount+1
for i in p:
  if a+1<=i and i<=b:
    pycount=pycount+1
for i in p:
  if b+1<=i:
    pzcount=pzcount+1
  
print(min(pxcount,pycount,pzcount))

Measured memory_bytes: 9136