akhauriyash/Code-Regression huggingface dataset:
from bisect import bisect

a, b, q = map(int, input().split())
s = [int(input()) for i in range(a)]
t = [int(input()) for i in range(b)]
x = [int(input()) for i in range(q)]

sentinel = lambda x: [-9e20] + x + [9e20]
s = sentinel(s)
t = sentinel(t)

for i in x:
    ss = bisect(s, i)
    tt = bisect(t, i)

    ll = max(s[ss], t[tt]) - i
    rr = i - min(s[ss-1], t[tt-1])
    rl = min((s[ss]- i) + s[ss] - t[tt-1], (t[tt]- i) + t[tt] - s[ss-1])
    lr = min((i - s[ss-1]) + t[tt] - s[ss-1], (i - t[tt-1]) + s[ss] - t[tt-1])

    print(min(ll, rr, rl, lr))


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

int main() {
  int n, k; cin >> n >> k;
  vector<bool> check(n);
  rep(i,k) {
    int d; cin >> d;
    rep(j,d) {
      int a; cin >> a;
      check[a-1] = true;
    }
  }
  int ans = 0;
  rep(i,n) ans += !check[i];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3636
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int x = Integer.parseInt(sc.next());
    int[] l = new int[n];
    for(int i=0; i<n; i++){
      l[i] = Integer.parseInt(sc.next());
    } 
    int ans = 1;
    int dictance = 0;

    for(int j=0; j<n; j++){
      dictance += l[j];
      if(dictance>x){
        break;
      }

      ans++;
    }

    System.out.println(ans);
  }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

int main(){
    int D;
    cin >> D;
    vector<int> c(26);
    for (int i = 0; i < 26; i++) cin >> c.at(i);
    vector<vector<int>> s(D, vector<int>(26));
    for (int i = 0; i < D; i++) {
        for (int j = 0; j < 26; j++) cin >> s.at(i).at(j);
    }
    vector<int> t(D, 0);
    //for (int i = 0; i < D; i++) cin >> t.at(i);
    vector<int> dp(26, 0);
    int ans = 0, ans_c = 0;

    for (int i = 0; i < D; i++) {
        int ans_pre = ans;
        for (int j = 0; j < 26; j++) {
            int satisfy = s.at(i).at(j);
            int tmp = ans_pre;
            tmp += satisfy;
            for (int k = 0; k < 26; k++) {
                if (k == j) continue;
                else tmp -= c.at(k) * (i + 1 - dp.at(k));
            }
            if (tmp > ans) {
                ans = tmp;
                ans_c = j;
            }
        }
        dp.at(ans_c) = i + 1;
        t.at(i) = ans_c + 1;
    }

    for (int i = 0; i < D; i++) {
        cout << t.at(i);
        if (i < D - 1) cout << endl;
    }
    
    return 0;
}


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


int main() {long H, W;
cin >> H >> W;
vector<string> c(H);
rep(i, H) cin >> c.at(i);
rep(i, H){
  rep(j, 2){
    cout << c.at(i) << endl;
  }
}



// cout << ans << endl;
  return 0;
 
}



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

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

  if ((a + b + c) > 21) {
    cout << "bust" << endl;
  }
  else {
    cout << "win" <<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define pii pair<int, int>
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
typedef long long ll;
typedef long double ld;
using namespace std;
template<class T> using minheap = priority_queue<T, vector<T>, greater<T>>;



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

  int a, b;
  cin >> a >> b;
  if (a < 10 && b < 10) {
    cout << a * b << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
package main

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

// input scanner
var sc = bufio.NewScanner(os.Stdin)

const (
	initialBufSize = 10e4
	maxBufSize     = 10e6
)

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// util
func max(l []int) int {
	ans := l[0]
	for _, n := range l {
		if n > ans {
			ans = n
		}
	}
	return ans
}

func min(l []int) int {
	ans := l[0]
	for _, n := range l {
		if n < ans {
			ans = n
		}
	}
	return ans
}

type Xl struct {
	X int
	L int
}

type Xls []Xl

func (f Xls) Len() int {
	return len(f)
}

func (f Xls) Less(i, j int) bool {
	return f[i].X < f[j].X
}

func (f Xls) Swap(i, j int) {
	f[i], f[j] = f[j], f[i]
}

// main
func main() {
	buf := make([]byte, initialBufSize)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords)
	n := nextInt()
	xls := make([]Xl, n, n)
	ans := 0
	for i := 0; i < n; i++ {
		xls[i].X = nextInt()
		xls[i].L = nextInt()
	}
	sort.Sort(Xls(xls))

	current := 1
	for i := 0; i < n; i++ {
		nextx := xls[i].X
		nextl := xls[i].L
		current = nextx + nextl
		find := false
		var findIdx int
		for j := i + 1; j < n && xls[j].X-xls[j].L < current; j++ {
			xj := xls[j].X
			lj := xls[j].L
			if xj+lj < nextx+nextl {
				nextx, nextl = xj, lj
				find = true
				findIdx = j
			}
			i++
		}
		if find {
			i = findIdx - 1
		} else {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 4608
#include<bits/stdc++.h>
using namespace std;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) c.begin(),c.end()
#define tr(c,i) for(i = c.begin(); i != c.end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e;++i)
#define forsn(i,s,e) for(int i = s; i < e;++i)
#define rforn(i,s) for(int i = s; i >= 0;--i)
#define rforsn(i,s,e) for(int i = s; i >= e;--i)
# define INF 0x3f3f3f3f 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll,ll> p64;
typedef pair<int,int> p32;
typedef pair<int,p32> p96;
typedef vector<ll> v64;
typedef vector<int> v32; 
typedef vector<v32> vv32;
typedef vector<v64> vv64;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int,int> m32;
const int LIM=1e5+5,MOD=1e9+7;
ll n,m;
v64 adj[100005];
ll vis[100005];
v64 topo;
void dfs(ll s)
{
    vis[s]=1;
    for(int i=0;i<adj[s].size();i++)
    {
        if(vis[adj[s][i]]==1)
            continue;
        dfs(adj[s][i]);
    }
    topo.pb(s);
}
int main()
{
    ll i,j,k,x,y;
    cin>>n>>m;
    forn(i,n)
        vis[i]=0;
    forn(i,m)
    {
        cin>>x>>y;
        x--;
        y--;
        adj[x].pb(y);
    }
    for(i=0;i<n;i++)
    {
        if(vis[i]==0)
            dfs(i);
    }
    //reverse(top.begin(),top.end());
    ll dp[n+5],res=0;
    for(i=0;i<topo.size();i++)
    {
        x=topo[i];
        dp[x]=0;
        for(j=0;j<adj[x].size();j++)
        {
            dp[x]=max(dp[x],dp[adj[x][j]]+1);
        }
        res=max(res,dp[x]);
    }
    cout<<res<<"\n";
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    int tmp=0;
    for(int i=1;i<n;i++){
        if(s[i]=='E'){
            tmp++;
        }
    }

    int ans=1e9,cmp=tmp;

    for(int j=1;j<n;j++){
        if(s[j]=='E'){
            cmp--;
        }

        if(s[j-1]=='W'){
            cmp++;
        }

        ans=min(ans,cmp);
    }
    ans=min(ans,tmp);
    cout << ans << endl;

	return 0;
}

Measured memory_bytes: 720
#include<stdio.h>
int main(void){
	int i;
	double a,b,c,d,e,f,x,y;
	while(scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f)!=EOF){
	    x=(c*e-b*f)/(a*e-b*d);
	    y=(a*f-c*d)/(a*e-d*b);
		if(x==-0)x=0;
		if(y==-0)y=0;
		printf("%.3f %.3f\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ll long long
#define fr(i,a,n) for(ll i=a;i<n;i++)
#define ina for(ll i=0;i<n;i++)cin>>a[i];
#define YES printf("YES\n")
#define all(v) v.begin(),v.end()
#define NO printf("NO\n")
#define fastio std::ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;


int main()
{
    fastio;


          ll n,k;
          cin>>n>>k;

          ll mn=n%k;
          ll mx=abs(n%k-k);
          mx=min(mx,mn);
          cout<<mx<<endl;



}




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

/* -------------------------------- Template -------------------------------- */

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

using namespace std;

using ll = long long;
using ld = long double;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

template<typename T> T inf() { assert(false); }
template<> constexpr int inf<int>() { return 1e9; }
template<> constexpr ll inf<ll>() { return 1e18; }
template<> constexpr ld inf<ld>() { return 1e30; }

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

/* -------------------------------- Library -------------------------------- */

/* ---------------------------------- Main ---------------------------------- */

int H, W;
string s[512];
int memo1[320][320][320];
int memo2[320][320][320];

int dp1(int l, int i, int j) {
  if (i <= 0 || j <= 0) return 0;
  if (memo1[l][i][j] != -1) return memo1[l][i][j];
  int res = dp1(l, i - 1, j - 1) + (s[i-1][l] == s[j-1][l+1]);
  return memo1[l][i][j] = res;
}

int dp2(int l, int i, int j) {
  if (i <= 0 || j <= 0) return 0;
  if (memo2[l][i][j] != -1) return memo2[l][i][j];
  int res = min(dp2(l, i-1, j), dp2(l, i, j-1));
  return memo2[l][i][j] = res + dp1(l, i, j);
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha;
  cout.imbue(loc);
  memset(memo1, -1, sizeof(memo1));
  memset(memo2, -1, sizeof(memo2));

  cin >> H >> W;
  REP(i,H) cin >> s[i];
  int res = 0;
  REP(i,W-1) {
    int val = dp2(i, H, H);
    res += val;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256384
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int ans;
int main(){
        int a,b;
        string s;
        cin >> a >> b;
        for(int i=a; i<=b; i++) {
                s=to_string(i);
                string t;
                t=s;
                reverse(begin(s),end(s));
                if(s==t) ans++;
        }
        cout << ans << endl;
}


Measured memory_bytes: 384
/*
   THE DARK NIGHT RISES
I LOVE YOU 72 AND WILL FOREVER DO SO
Patience, Persistence, Perseverance, Passion, Purpose
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
const int N = 2e5 + 20 ;
#define F first
#define S second
# define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define mk make_pair
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i,a,b) for(ll i=a;i<b;i++)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define sz(x)       (int)x.size()
const long long int mod=1e9 + 7;
const long double EPS=1e-12;
#define mem( a, val ) memset(a, val, sizeof( a ) )
#define deci( x ) cout<<fixed<<setprecision( x );
#define bitcount( x ) __builtin_popcountll( x )
 
const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
 

 
int solve()
{
 	ll n ;
 	cin >> n ;
 	cout << n*n ;
	
}
int main()
{
	fast;
	ll t;
	t=1;
	//cin>>t;
	while(t--)
	{
		solve();
	}
 
	return 0;
}
// Patience, Persistence, Perseverance, Passion, Purpose
// I LOVE YOU 72 AND WILL FOREVER DO SO.

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

int main() {
  int X; cin >> X;
  vector<bool> expo(X+1);
  
  expo[1] = 1;
  repi(b,2,X) {
    int v = b*b;
    while(v<=X) {
      expo[v] = 1;
      v *= b;
    }
  }
    
  repr(i,X,1) {
    if(expo[i]) {
      cout << i << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
using namespace std;
int n, k;

int main() {
    ios::sync_with_stdio(false);
    
    cin >> n >> k;
    int ans = k;
    
    for (int i = 1; i <=n-1; i++)
        ans *= (k-1);
    
    cout << ans << endl;
    return 0;
}

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

int cnt = 0;

void scanArray(int n, int* A){
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }
}

void printArray(int n, int* A){
    for(int i = 0; i < n; i++){
        cout << A[i] << endl;
    }
}

void printGArray(int m, int* G){
    for(int i = m - 1; i > 0; i--){
        cout << G[i] << " ";
    }
    cout << G[0] << endl;
}

int gArray(int n, int* G){
    G[0] = 1;
    int g = 4;
    int i = 0;
    int m = 1;
    while(g < n){
        m++;
        i++;
        G[i] = g;
        g = 3 * g + 1;
    }
    return m;
}

void insertionSort(int n, int* A, int g){
    for(int i = g; i < n; i++){
        int v = A[i];
        int j = i - g;
        while(j >= 0 && A[j] > v){
            A[j + g] = A[j];
            j = j - g;
            cnt++;
        }
        A[ j + g ] = v;
    }
}

void shellSort(int n, int* A, int m, int* G){
    cnt = 0;
    for(int i = m - 1; i >= 0; i--){
        insertionSort(n, A, G[i]);
    }
}

int main(){
    int n;
    cin >> n;
    int* A = new int[n];
    scanArray(n, A);
    
    int* G = new int[n];
    int m = gArray(n, G);
    cout << m << endl;
    printGArray(m, G);

    shellSort(n, A, m, G);
    cout << cnt << endl;

    printArray(n, A);
    return 0;
}


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

ll GCD(ll a, ll b) { return (b == 0)? a: GCD(b, a % b); }
ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }

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

  ll N; cin >> N;
  ll M; cin >> M;
  vector<ll> A(N); for (ll i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) {
    A[i] /= 2;
  }

  ll l = A[0];
  for (int i = 1; i < N; i++) {
    l = LCM(l, A[i]);
  }

  bool check = false;
  for (int i = 0; i < N; i++) {
    if ((l / A[i]) % 2 == 0) check = true;
  }
  if (check) {
    cout << 0 << "\n";
    return 0;
  }
  cout << (M / l + 1) / 2 << '\n';
  return 0;
}

Measured memory_bytes: 1024
import collections, itertools
H, W, ch, cw, dh, dw, *S = open(0).read().split()
H, W, ch, cw, dh, dw = [int(_) + 1 for _ in [H, W, ch, cw, dh, dw]]
H += 3
W += 3
S = ['#' * W] + ['#' * W] + ['##' + s + '##'
                             for s in S] + ['#' * W] + ['#' * W]
Dist = [[None] * W for _ in range(H)]
Q = collections.deque([(0, ch, cw)])
while Q:
    d, ox, oy = Q.popleft()
    if Dist[ox][oy] is not None:
        continue
    stack = [[ox, oy]]
    warp = set()
    while stack:
        x, y = stack.pop()
        if (x, y) == (dh, dw):
            print(d)
            exit()
        Dist[x][y] = d
        for dx, dy in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
            nx, ny = x + dx, y + dy
            if Dist[nx][ny] is None:
                if S[nx][ny] == '.':
                    stack += [[nx, ny]]
                else:
                    warp.add((x, y))
    for x, y in warp:
        for dx, dy in itertools.product(range(-2, 3), repeat=2):
            nx, ny = x + dx, y + dy
            if Dist[nx][ny] is None and S[nx][ny] == '.':
                Q += [(d + 1, nx, ny)]
print(-1)


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

using namespace std;

int main()
{
  uint64_t N, M;

  cin >> N >> M;
  vector<vector<int64_t> > uv;
  uv.resize(N + 1);

  for(int64_t i = 0;
      i < M;
      ++i)
    {
      int64_t a, b;
      cin >> a >> b;
      uv[a].push_back(b);
    }

  vector<vector<bool> > v_trv;
  v_trv.resize(N + 1);

  for(int64_t i = 0;
      i <= N;
      ++i)
    {
      v_trv[i].resize(3);
      for(int64_t j = 0;
          j < 3;
          ++j)
        {
          v_trv[i][j] = false;
        }
    }


  int64_t S, T;

  cin >> S >> T;

  deque<int64_t> dep;

  dep.push_back(S);
  v_trv[S][0] = true;

  for(int64_t i = 1;
      !dep.empty();
      ++i)
    {
      int64_t dep_size = dep.size();
      for(int64_t j = 0;
          j < dep_size;
          ++j)
        {
          vector<int64_t> &vec1 = uv[dep.front()];
          for(int64_t k = 0;
              k < vec1.size();
              ++k)
            {
              if(v_trv[vec1[k]][i % 3] == false)
                {
                  v_trv[vec1[k]][i % 3] = true;
                  dep.push_back(vec1[k]);
                  if(i % 3 == 0 && vec1[k] == T)
                    {
                      cout << i/3 << endl;
                      return 0;
                    }
                }
            }
          dep.pop_front();
        }
    }

  cout << -1 << endl;
  return 0;
}


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

const long long BASE = 1e9 + 7 ;

long long POW[110], hA[110], hB[110] ;
int n, m ;
char a[110], b[110] ;

long long get_A(int i, int j) { return (hA[j] - hA[i - 1] * POW[j - i + 1] + BASE * BASE) % BASE ; }
long long get_B(int i, int j) { return (hB[j] - hB[i - 1] * POW[j - i + 1] + BASE * BASE) % BASE ; }

main()
{
  //freopen("A.inp", "r", stdin) ;
  //freopen("A.out", "w", stdout) ;
  scanf("%d", &n) ; m = n ;
  scanf("%s%s", a + 1, b + 1) ;
  int t = m + n ;
  POW[0] = 1 ;
  for(int i = 1; i <= 105; ++i) POW[i] = (POW[i - 1] * 26) % BASE ;
  for(int i = 1; i <= m; ++i) hA[i] = (hA[i - 1] * 26 + a[i] - 'a') % BASE ;
  for(int i = 1; i <= n; ++i) hB[i] = (hB[i - 1] * 26 + b[i] - 'a') % BASE ;
  for(int i = max(m, n); i <= t; ++i)
  {
    int c = m + n - i ;
    if(get_A(m - c + 1, m) == get_B(1, c)) return printf("%d", 2 * n - c), 0 ;
  }
  printf("%d", 2 * n) ;
}


Measured memory_bytes: 256
#include <stdio.h>

#define N 44

int fib[N];

int main(){
  int i,n;

  scanf("%d",&n);

  fib[0] = 1;
  fib[1] = 1;

  for(i=2; i<=n; i++){
    fib[i]=fib[i-2]+fib[i-1];
    }

  printf("%d\n",fib[n]);
  return 0;
}

Measured memory_bytes: 596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

int main() {
    int n;
    string s;
    cin >> n >> s;
    vector<vector<int>> v(10);
    for (int i = 0; i < n; i++) v[s[i] - '0'].push_back(i);

    int ret = 0;
    for (int i = 0; i < 1000; i++) {
        int nowindex = -1;
        int tmp = i;
        for (int j = 0; j < 3; j++) {
            int x = tmp % 10;
            int idx = upper_bound(v[x].begin(), v[x].end(), nowindex) - v[x].begin();
            nowindex = idx >= v[x].size() ? 1145141919 : v[x][idx];
            tmp /= 10;
        }
        if (nowindex < n)ret++;
    }

    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 512
import java.util.*;
public class Main {
	public static void main (String[] args) {
      Scanner sc = new Scanner(System.in);
      int D = sc.nextInt();
      String eve = String.join("", Collections.nCopies(25-D, " Eve"));
      String ans = "Christmas" + eve;
      System.out.println(ans);
      
    }
}

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

int main(){
	int n,a,b;
	int mi=0,mib=0;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a>>b;
		if(a>mi){
			mi=a;
			mib=b;
		}
	}
	cout<<mi+mib<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class C
{
	public static void Main()
	{
		int N = GetInt();
		long[] A = Enumerable.Range(0, N + 1).Select(_ => GetLong()).ToArray();
		long[] B = Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();

		long ans = 0;
		for(int i = 0; i < N; i++)
		{
			for(int j = 0; j < 2; j++)
			{
				long num = Math.Min(A[i + j], B[i]);
				A[i + j] -= num;
				B[i] -= num;
				ans += num;
			}
		}

		Console.WriteLine(ans);
	}
}


public class SegmentTree<T>
{
	private int N;
	private T INI;
	private Func<T, T, T> Func;
	private T[] dat;

	public SegmentTree(int n, T ini, Func<T, T, T> func)
	{
		N = 1;		
		while(N < n)
			N <<= 1;

		INI = ini;
		Func = func;
			
		dat = new T[2 * N - 1];
		for(int i = 0; i < 2 * N - 1; i++)
			dat[i] = INI;
	}

	public void Update(int k, T a)
	{
		k += N - 1;
		dat[k] = a;
		while(k > 0)
		{
			k = (k - 1) / 2;
			dat[k] = Func(dat[k * 2 + 1], dat[k * 2 + 2]);
		}
	}

	public T Query(int a, int b, int k = 0, int l = 0, int r = -1)
	{
		if(r == -1)
			r = N;

		if(r <= a || b <= l)
			return INI;

		if(a <= l && r <= b)
			return dat[k];
		else
		{
			T vl = Query(a, b, k * 2 + 1, l, (l + r) / 2);
			T vr = Query(a, b, k * 2 + 2, (l + r) / 2, r);
			return Func(vl, vr);
		}
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


Measured memory_bytes: 36300
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

int N;
vector<pair<long long,long long>> v;

int main(){
    cin >> N;
    long long a,b;
    for(int i=0;i<N;i++){
        cin >> a >> b;
        v.push_back(make_pair(b,a));
    }
    sort(v.begin(),v.end());
    long long t = 0;
    for(int i=0;i<N;i++){
        t += v[i].second;
        if(t > v[i].first){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 6512
#include<stdio.h>
int main(void)
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a+b==c||b+c==a||c+a==b){
			printf("Yes\n");
	}
	else{
			printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var N = F;
		var A = G;
		var d = new Dictionary<int, int>();
		foreach (var a in A)
		{
			if (!d.ContainsKey(a)) d[a] = 0;
			d[a]++;
		}
		var ans = 0;
		var ks = d.Keys.ToList();
		ks.Sort((x, y) => y.CompareTo(x));
		var pow = new List<int>();
		var q = 1L;
		while (q < int.MaxValue)
		{
			pow.Add((int)q);
			q *= 2;
		}
		foreach (var k in ks)
		{
			if (!d.ContainsKey(k)) continue;
			foreach (var p in pow)
			{
				if (d.ContainsKey(p - k))
				{
					if (p - k != k)
					{
						var pair = Min(d[k], d[p - k]);
						if (d[p - k] <= pair) d.Remove(p - k);
						else d[p - k] -= pair;
						ans += pair;
					}
					else ans += d[k] / 2;
					d.Remove(k);
					break;
				}
			}
		}
		WriteLine(ans);
	}
}


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

using namespace std;
using ll = long long;

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

int main() {
  int h, a;
  cin >> h >> a;
  cout << (h + a - 1) / a << endl;
  return 0;
}


Measured memory_bytes: 3604
<?php
fscanf(STDIN,"%d %d",$N,$D);
//全ての点を表す配列作成
for($i=0;$i<$N;$i++){
  $X = fgets(STDIN);
  ${"array".$i} = explode(" ",$X);
}
//答え、整数だったら+1
$counter = 0;
//2点の総当り
for($i=0;$i<$N-1;$i++){
  for($j=$i+1;$j<$N;$j++){
    $result = calcDistance(${"array".$i},${"array".$j});
    if(is_decimal($result)){
      $counter++;
    }
  }
}
echo $counter;

//2点の距離を求める関数
function calcDistance($arrayA,$arrayB){
  $result = 0;
  for($i=0;$i<count($arrayA);$i++){
    $result += ($arrayA[$i]-$arrayB[$i])**2;
  }
  return sqrt($result);
}

//整数かチェックする関数（数値型文字列含む）
function is_decimal($value) {
    return filter_var($value, FILTER_VALIDATE_INT) !== false;
}


Measured memory_bytes: 3576
S=input()
S1=int(S[:2])
S2=int(S[2:])

if ((0<=S1 and S1<=99) and (1<=S2 and S2<=12)):
    if (1<=S1 and S1<=12) and (0<=S2 and S2<=99):
        print("AMBIGUOUS")
    else:
        print("YYMM")
elif (1<=S1 and S1<=12) and (0<=S2 and S2<=99):
    print("MMYY")

else:
    print("NA")

Measured memory_bytes: 3064
/*input
14
1 2 2 3 3 3 4 4 4 4 1 2 3 4
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie(0) , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define MAX 1000
#define INF 0x3f3f3f3f

int n , x[MAX];
int32_t main(){
	IOS;
	cin >> n;
	REP(i , 1 , n + 1) cin >> x[i];
	int ans = 0;
	REP(i , 2 , n + 1){
		if(x[i] == x[i - 1]) x[i] = -1 , ans ++;
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    s,w = LI()
    if s > w:
        return "safe"

    return "unsafe"


print(main())





Measured memory_bytes: 11012
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int N, M, p, K, t, ans;
  while (cin >> N, N) {
    vector< vector<int> > V(N);
    vector<int> A(N, 0);
    for (int i = 0; i < N; ++i) {
      cin >> M;
      for (int j = 0; j < M; ++j) {
	cin >> p;
	V[p-1].push_back(i);
      }
    }
    cin >> K;
    for (int i = 0; i < K; ++i) {
      cin >> p;
      for (int j = 0; j < V[p-1].size(); ++j) {
	++A[V[p-1][j]];
      }
    }
    t = 0;
    ans = -1;
    for (int i = 0; i < N; ++i) {
      if (A[i] == K) {
	++t;
	ans = i+1;
      }
    }
    if (t == 1) cout << ans << endl;
    else cout << -1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3148
n = int(input())
c = []
bs = 0
for i in range(n):
  a,b = map(int,input().split())
  bs += b
  c.append(a+b)

c.sort()

ans = -bs
for i in range(n-1,-1,-1):
  if (n-1-i)%2==0: ans += c[i]
    
print(ans)


Measured memory_bytes: 7388
#include<iostream>
#include<cmath>
#include<queue>
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<cstring>
#include<climits>
#include<sstream>
#include<deque>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<bitset>

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

using namespace std;

typedef long long ll;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;

#define MAX 100010
int V,E,s,t;
vector<int> G[MAX];
vector<ll> d;


class RMQ{
private:
  int limit,N;
  vector<ll> dat;
public:
  void init(int n_){
    N = n_;
    limit = 1;
    while(limit<n_)limit*=2;
    dat.clear();
    dat.resize(2*limit,LLONG_MAX);
  }
  
  ll _build(int cur,int L,int R,const vector<ll> &buf){
    if( !( 0 <= cur && cur < 2*limit ) ) return LLONG_MAX;
    if( L == R-1 ) {
      if( L >= N ) return LLONG_MAX;
      dat[cur] = buf[L];
    } else {
      ll vl = _build(cur*2+1,L,(L+R)/2,buf);
      ll vr = _build(cur*2+2,(L+R)/2,R,buf);
      dat[cur] = min(vl,vr);
    }
    return dat[cur];
  }

  void build(const vector<ll> &buf){ _build(0,0,limit,buf); };

  void update(int k,ll a){
    k += limit-1;
    dat[k] = a;
    while(k > 0){
      k = (k-1)/2;
      dat[k] = min(dat[k*2+1],dat[k*2+2]);
    }
  }
 
  ll _query(int a,int b,int k,int l,int r){
    if(r<=a || b<=l)return LLONG_MAX;
    else if(a<=l && r<=b)return dat[k];
    ll vl = _query(a,b,k*2+1,l,(l+r)/2);
    ll vr = _query(a,b,k*2+2,(l+r)/2,r);
    return min(vl,vr);
  }

  ll query(int a,int b){ return _query(a,b,0,0,limit); }
};



int main(){
  /*
  RMQ rmq2;
  rmq2.init(10);
  rmq2.build(vector<ll>(10,LLONG_MAX));
  while(1) {
    int t;
    int a,b;
    cout << "t = ";
    cin >> t;
    if( t == 0 ) {
      cin >> a >> b;
      cout << rmq2.query(a,b) << endl;
    } else {
      cin >> a >> b;
      rmq2.update(a,(ll)b);
    }
  }
  puts("--");
  */

  
  cin >> V >> E >> s >> t;
  --s, --t;
  d = vector<ll>(V,0);
  rep(i,V) cin >> d[i];
  rep(i,E) {
    int a,b;
    cin >> a >> b;
    --a, --b;
    if( a < s ) a = s;
    G[a].push_back(b);
  }
  if( t <= s ) {
    puts("0");
    return 0;
  }

  RMQ rmq;
  rmq.init(V+1);
  rmq.build(vector<ll>(V+1,LLONG_MAX));
  rmq.update(s,0LL);
  REP(i,s,V) {
    ll mini = rmq.query(i,V+1);
    rmq.update(i,mini);
    rep(j,(int)G[i].size()) {
      int nex = G[i][j];
      if( nex == i ) continue;
      ll v = rmq.query(nex,nex+1);
      if( v > mini + d[nex]) {
	//cout << mini << " + " << d[nex] << endl;
	rmq.update(nex,mini+d[nex]);
      }
    }
  }
  cout << rmq.query(t,t+1) << endl;
  return 0;
}

Measured memory_bytes: 11932
import sys

input = sys.stdin.buffer.readline
n, m = map(int, input().split())


# union-findを導入したい。
par = [-1] * (n + 10)


def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]


def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        False
    else:
        if par[x] > par[y]:
            x, y = y, x
        par[x] += par[y]
        par[y] = x
        return True


def same(x, y):
    return find(x) == find(y)


def size(x):
    return -par[find(x)]


for _ in range(m):
    a, b = map(int, input().split())
    unite(a, b)

num = 0
for i in range(n):
    num = max(num, size(i))
print(num)


Measured memory_bytes: 73780
/*
by.YXH_XianYu
   2018.9.15
 */
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LLI long long
#define DBL double
#define CHR char
#define BOL bool
#define REG register
#define rep(i, j, k) for(int i = j, lim = k; i <= lim; i++)
#define req(i, j, k) for(int i = j, lim = k; i >= lim; i--)
#define MXN 1010

int n, x,
	a[MXN];

int main() {
	//freopen("TEMPLATE.in", "r", stdin);
	//freopen("TEMPLATE.out", "w", stdout);
	REG int i, ans = 0;

	scanf("%d %d", &n, &x);
	for(i = 1; i <= n; i ++)
		scanf("%d", &a[i]);
	std::sort(a+1, a+n+1);
	for(i = 1; i < n; i ++)
		if(x >= a[i]) x -= a[i], ans ++;
		else break;
	if(x == a[n]) ans ++;
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 256
S = input()
N = len(S)
S1 = S[:N//2]
S2 = S[N//2 + 1:]
N1 = len(S1)
if S1 != S2:
    print('No')
    exit()

for i in range(N//4):
    if S1[i] != S1[-i - 1]:
        print('No')
        exit()
print('Yes')

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


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

    long long n,m;
    cin>>n>>m;
    long long mod=1e9+7;
    long long x,y;
    long long ans=0;
    for(int i=0;i<n;i++){
        cin>>x;
        ans += x*(2*i-n+1)%mod;
        ans %= mod;
    }
    long long t=0;
    for (int i = 0; i < m; i++)
    {
        cin>>y;
        t += y*(2*i - m+1)%mod;
        t %= mod;
    }
    ans *= t;
    ans %= mod;
    cout << ans << endl;

    
}

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

int main()
{
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> a(q);
  vector<int> hito(n);
  for (int i = 0; i < n; i++)
  {
    hito[i] = k - q;
  }
  for (int i = 0; i < q; i++)
  {
    cin >> a[i];
    hito[a[i] - 1]++;
  }
  for (int i = 0; i < n; i++)
  {
    if (hito[i] > 0)
    {
      cout << "Yes" <<endl;
      continue;
    }
    else
      cout << "No" << endl;
  }
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
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;}
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

//for(i=0; i<N; i++) cin >> a[i];


int main(void) {
  ll i, j, k;
  
  ll N;
  ll a[MAX*2];
  
  cin >> N;
  ll X=0;
  for(i=0; i<N; i++) {
    cin >> a[i];
    X^=a[i];
  }
  
  for(i=0; i<N; i++) pt((X^a[i]));
  
  
  
  
  
  
  
  
  
}
 
 




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

int mod = 1000000007;
int n, m;
int a[1000];
int b[1000];
int high[1000][1000];
vector<int> vals;
vector<int> nums;

signed main() {
	int i, j;
	
	cin >> n >> m;
	rep(i, n) cin >> a[i];
	rep(i, m) cin >> b[i];
	sort(a, a + n);
	sort(b, b + m);
	
	rep(i, n - 1) {
		if (a[i] == a[i + 1]) {
			cout << 0 << endl;
			return 0;
		}
	}
	
	rep(i, m - 1) {
		if (b[i] == b[i + 1]) {
			cout << 0 << endl;
			return 0;
		}
	}
	
	rep(i, n) {
		rep(j, m) {
			high[i][j] = min(a[i], b[j]);
		}
	}
	
	int ans = 1;
	rep(i, n) {
		j = lower_bound(b, b + m, a[i]) - b;
		if (j < m && b[j] == a[i]) continue;
		
		int cnt = 0;
		rep(j, m) {
			if (high[i][j] == a[i]) {
				cnt++;
			}
		}
		ans *= cnt;
		ans %= mod;
	}
	
	rep(j, m) {
		i = lower_bound(a, a + n, b[j]) - a;
		if (i < n && a[i] == b[j]) continue;
		
		int cnt = 0;
		rep(i, n) {
			if (high[i][j] == b[j]) {
				cnt++;
			}
		}
		ans *= cnt;
		ans %= mod;
	}
	
	static int cnt[1000001] = {0};
	rep(i, n) rep(j, m) cnt[high[i][j]]++;
	for (i = 1; i <= n * m; i++) {
		rep(j, cnt[i] - 1) vals.push_back(i);
	}
	
	static bool exist[1000001] = {false};
	rep(i, n) exist[a[i]] = true;
	rep(i, m) exist[b[i]] = true;
	
	for (i = 1; i <= n * m; i++) {
		if (!exist[i]) {
			nums.push_back(i);
		}
	}
	
	//cout << ans << endl;
	//rep(i, vals.size()) cout << vals[i] << " "; cout << endl;
	//rep(i, nums.size()) cout << nums[i] << " "; cout << endl;
	
	for (i = 0; i < vals.size(); i++) {
		int kosuu = upper_bound(nums.begin(), nums.end(), vals[i]) - nums.begin();
		int mul = max(0LL, kosuu - i);
		ans *= mul;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> p(n);

    for(int i=0; i<n; i++){
        cin >> p.at(i);
    } 

    int c=0;
    for(int i=1; i<n-1; i++){
        if((p.at(i-1)<p.at(i)) 
        && (p.at(i+1)>p.at(i))){
            c++;
        }else if((p.at(i-1)>p.at(i)) 
        && (p.at(i+1)<p.at(i))){
            c++;
        }
    }

    cout << c << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int a,b,c,d,e,f;
	f=0;
	scanf("%d %d %d",&a,&b,&c);
	for(d=a;d<=b;d++){
		e=c%d;
		if(e==0){
			f=f+1;
		}
	}
	printf("%d\n",f);
	return 0;
} 

Measured memory_bytes: 596
import itertools

N, M = map(int, input().split())
V = [[] for _ in range(N)]
bag = set()
for _ in range(M):
    a, b = map(int, input().split())
    bag.add(a)
    bag.add(b)
    V[a-1].append(b)
    V[b-1].append(a)

count = 0
for c in itertools.permutations(bag):
    if not c[0] == 1:
        continue
    flag = False
    for i in range(N-1):
        if not c[i+1] in V[c[i]-1]:
            flag = True
            break
    if not flag:
        count += 1
print(count)


Measured memory_bytes: 9004
#include<iostream>
#include<cstdio>
#include<vector>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#define  endl '\n'
#define all(s) s.begin(),s.end()
#define lowbit(x) (x&-x)
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mem(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define pb push_back
#define PI acos(-1.0)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1e9+7;
const double eps=1e-8;
const int inf=0x3f3f3f3f;
const int N=2e5+10;
int main()
{
	int n,m,q,k;
	cin>>k>>n>>m;
	for(int i=n;i<=m;i++){
		if(i%k==0){
			cout<<"OK";
			return 0;
		}
	} 
	cout<<"NG";
}


Measured memory_bytes: 3096
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int R = sc.nextInt();
        int C = sc.nextInt();
        int K = sc.nextInt();
        int[][] V = new int[R][C];
        for (int i = 0; i < K; i++) {
            int r = sc.nextInt();
            int c = sc.nextInt();
            int v = sc.nextInt();
            V[--r][--c] = v;
        }

        long[][][] dp = new long[R][C][4];
        for (int i = 0; i < R; i++) {
            for (int j = 0; j < C; j++) {
                for (int k = 0; k <= 3; k++) {
                    dp[i][j][k] = -1;
                }
            }
        }
        dp[0][0][3] = 0;
        if (V[0][0] > 0) dp[0][0][2] = V[0][0];
        for (int i = 0; i < R; i++) {
            for (int j = 0; j < C; j++) {
                long max = 0;
                for (int k = 0; k <= 3; k++) {
                    max = Math.max(max,dp[i][j][k]);
                }
                for (int k = 0; k <= 3; k++) {
                    if (dp[i][j][k] == -1) continue;
                    if (i+1 < R) {
                        // i+1
                        if (V[i+1][j] > 0) {
                            dp[i+1][j][2] = Math.max(dp[i+1][j][2],max+V[i+1][j]);
                        }
                        dp[i+1][j][3] = Math.max(dp[i+1][j][3],max);
                    }
                    if (j+1 < C) {
                        // j+1
                        if (V[i][j+1] > 0 && k > 0) {
                            dp[i][j+1][k-1] = Math.max(dp[i][j+1][k-1],dp[i][j][k]+V[i][j+1]);
                        }
                        dp[i][j+1][k] = Math.max(dp[i][j+1][k],dp[i][j][k]);
                    }
                }
            }
        }

        long ans = 0;
        for (int k = 0; k <= 3; k++) {
            ans = Math.max(ans,dp[R-1][C-1][k]);
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 702468
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<algorithm>

#define ll long long
#define sz 105

using namespace std;

int main()
{
    ll a,b,c,frq[sz],i=1;

    scanf("%lld %lld %lld",&a,&b,&c);

    memset(frq,0,sizeof(frq));

    ll flag=0;

    while(1)
    {
        ll m=a*i;

        if(m%b==c)
        {
            flag=1;
            break;
        }

        frq[m%b]++;

        if(frq[m%b]==2)
            break;

        i++;
    }

    if(flag)
        printf("YES\n");

    else
        printf("NO\n");

    return (0);
}


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

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

const int N = 2e5+10 , mod = 1e9+7 , M = 5;

bool dp[N][M][M][M];
pair <pii , pii> par[N][M][M][M];

int32_t main(){
   ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
   int n , a , b , c;
   cin >> n >> a >> b >> c;
   a = min(a , 2);
   b = min(b , 2);
   c = min(c , 2);
   dp[0][a][b][c] = true;
   for(int i = 1 ; i <= n ; i++){
      string s;
      cin >> s;
      vector <int> d1(3) , d2(3);
      if(s == "AB")
         d1 = {-1 , 1 , 0} , d2 = {1 , -1 , 0};
      else if(s == "AC")
         d1 = {-1 , 0 , 1} , d2 = {1 , 0 , -1};
      else
         d1 = {0 , -1 , 1} , d2 = {0 , 1 , -1};
      for(int j = 0 ; j < M - 1 ; j++)
         for(int k = 0 ; k < M - 1 ; k++)
            for(int p = 0 ; p < M - 1 ; p++){
               int x = j , y = k , z = p;
               if(x - d1[0] >= 0 && y - d1[1] >= 0 && z - d1[2] >= 0 && dp[i - 1][x - d1[0]][y - d1[1]][z - d1[2]]){
                  dp[i][x][y][z] = true;
                  par[i][x][y][z] = {{i - 1 , x - d1[0]} , {y - d1[1] , z - d1[2]}};
               }
               if(x - d2[0] >= 0 && y - d2[1] >= 0 && z - d2[2] >= 0 && dp[i - 1][x - d2[0]][y - d2[1]][z - d2[2]]){
                  dp[i][x][y][z] = true;
                  par[i][x][y][z] = {{i - 1 , x - d2[0]} , {y - d2[1] , z - d2[2]}};
               }
            }
   }
   bool fnd = false;
   int x , y , z;
   for(int i = 0 ; i < M - 1 ; i++)
      for(int j = 0 ; j < M - 1 ; j++)
         for(int k = 0 ; k < M - 1 ; k++){
            if(dp[n][i][j][k])
               x = i , y = j , z = k , fnd = true;
         }
   if(!fnd)
      cout << "No";
   else{
      cout << "Yes\n";
      vector <string> ans;
      int cur = n;
      while(cur){
         auto xx = par[cur][x][y][z];
         if(x - xx.first.second == 1)
            ans.push_back("A");
         else if(y - xx.second.first == 1)
            ans.push_back("B");
         else
            ans.push_back("C");
         x = xx.first.second;
         y = xx.second.first;
         z = xx.second.second;
         cur--;
      }
      reverse(ans.begin() , ans.end());
      for(auto x : ans)
         cout << x << "\n";
   }
   return 0;
}


Measured memory_bytes: 215024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
const ll mod = 1000000007;
ll dp[305][305][305];
vector<i_i> rule[305];
int N, M;
vector<int> in(3);
int counter[305];

void f(int R, int G, int B) {
    //cout << "f " << R << " " <<G << " " << B<< endl;
    dp[R][G][B] %= mod;
    //vector<int> in;
    //in.push_back(R);
    //in.push_back(G);
    //in.push_back(B);
    in[0] = R;
    in[1] = B;
    in[2] = G;
    sort(in.begin(), in.end());
    int maxi = in[2];
    for(int i = 0; i < rule[maxi].size(); i++) {
        //counter[maxi]++;
        //counter++;
        int l = rule[maxi][i].first;
        int x = rule[maxi][i].second;
        int now = 1;
        if(l <= in[0]) now++;
        if(l <= in[1]) now++;
        if(now != x) {
            dp[R][G][B] = 0;
            return;
        }
    }
    //cout << R << " " << G << " " << B << " " << dp[R][G][B] << endl;
    dp[maxi + 1][G][B] = (dp[maxi + 1][G][B] + dp[R][G][B]);
    dp[R][maxi + 1][B] = (dp[R][maxi + 1][B] + dp[R][G][B]);
    dp[R][G][maxi + 1] = (dp[R][G][maxi + 1] + dp[R][G][B]);
    return;
}

int main() {
    //cout.precision(10);
    cin >> N >> M;
    //cout << N << " " << M << endl;
    for(int i = 1; i <= M; i++) {
        int l, r, x;
        cin >> l >> r >> x;
        rule[r].push_back({l, x});
    }
    dp[0][0][0]++;
    f(0, 0, 0);
    //cout << N << endl;
    for(int maxi = 1; maxi <= N; maxi++) {
        //cout << maxi << endl;
        f(maxi, 0, 0);
        f(0, maxi, 0);
        f(0, 0, maxi);
        for(int maxi2 = 1; maxi2 < maxi; maxi2++) {
            for(int i = 0; i < maxi2; i++) {
                f(maxi, maxi2, i);
                f(maxi, i, maxi2);
                f(maxi2, maxi, i);
                f(maxi2, i, maxi);
                f(i, maxi, maxi2);
                f(i, maxi2, maxi);
            }
        }
    }
    ll ans = 0;
    ans = (ans + dp[N][0][0] + dp[0][N][0] + dp[0][0][N]) % mod;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < i; j++) {
            ans = (ans + dp[N][i][j] + dp[N][j][i] + dp[i][N][j] + dp[i][j][N] + dp[j][N][i] + dp[j][i][N]) % mod;
        }
    }
    cout << ans << endl;
    for(int i = 1; i <= 8; i++) {
        //cout << i << " " << counter[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 221440
#include <bits/stdc++.h>
using namespace std;
int main()
  {int N, M, C, c{}; cin >> N >> M >> C;
  int B[M]; for (int &b: B) cin >> b;
  while (N--)
    {int s{C}; for (int i{}, a; i < M; ++i) cin >> a, s += a * B[i];
    c += s > 0;}
  cout << c;}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
long long n,i,b,a,c,d,e;
int hhh(int x,int y)
{
	if(x%y==0)
	    return y;
	else
	    return hhh(y,x%y);
	
}
int main()
{
	cin>>a>>b;
	if(a<b)
		c=a,a=b,b=c;
	d=hhh(a,b);
	e=a*b/d;
	printf("%lld",e);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int x[10000],y[10000],i=0,n=0;

	while(1){
	scanf("%d %d",&x[i],&y[i]);
	if(x[i]==0 && y[i]==0)
		break;
	i++;
	}
	for(n;n<i;n++){
	if(x[n]>y[n])
		printf("%d %d\n",y[n],x[n]);
	else
		printf("%d %d\n",x[n],y[n]);
	}
}

Measured memory_bytes: 1716
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #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 VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
    #define pb push_back
    #define sz size()
     
    using namespace std;
    using ll = long long int;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
    using Vl = vector<ll>;
     
const int MOD = 1e9 + 7;
const ll ZER = 0;

ll dp1[3010][2], dp2[3010][2];
int main(){
    ll s;
    cin >> s;
    ll a = pow(s, 0.5);
  	if(a < 1e9)a++;
    ll b = (s + a - 1) / a;
    ll c = a * b - s;
    cout << 0 << " " << 0 << " " << a << " " << c << " " << 1 << " " << b << endl;
}



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

int main() 
{
    const int MOD = 1000000007;
    
    long long N, K;
    cin >> N >> K;
    
    long long sum = 0;
    for (long long i = K; i <= N+1; i++) {
        sum = (sum + (N + 1 - i) * i + 1) % MOD;
    }
    
    cout << sum << endl;
}

Measured memory_bytes: 3612