akhauriyash/Code-Regression huggingface dataset:
use proconio::input;
use proconio::marker::{Chars, Usize1};
use std::iter::Iterator;
use std::collections::HashSet;
use std::cmp::*;
use itertools::Itertools;

#[allow(unused_macros)]
macro_rules! max {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      max($x,max!($($xs)+))
    };
  }
  
  #[allow(unused_macros)]
  macro_rules! min {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      min($x,min!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

//最大公約数
pub fn gcd(a: u64, b: u64) -> u64 {
  if b == 0 {
    a
  } else {
    gcd(b, a % b)
  }
}

//最小公倍数
pub fn lcm(a: u64, b: u64) -> u64 {
  a * b / gcd(a, b)
}

fn main() {
    input! {
    a: u64,
    b: u64,
    c: u64,
    d: u64,
    }

    let cnt_a = cnt_multi(c, d, a -1);
    let cnt_b = cnt_multi(c, d, b);

     println!("{}", cnt_b - cnt_a);
}

fn cnt_multi(a:u64, b:u64, target:u64) -> u64{

  let mut cnt = 0;
  cnt = target / a + target / b;
  let lc = lcm(a, b);
  cnt -= target / lc;
  return target - cnt;

}


Measured memory_bytes: 2132
from math import sqrt
n = int(input())

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

# def solve1(n):
#     ans = []
#     for k in range(2, n+1):
#         tmp = n
#         while tmp % k == 0:
#             tmp = tmp // k
#             if tmp < k:
#                 break
#         tmp = tmp % k
#         if tmp == 1:
#             ans.append(k)
#     return ans, len(ans)

def solve2(n):
    div1 = make_divisors(n-1)
    div2 = make_divisors(n)
    div = list(set(filter(lambda x: x > 1, div1 + div2)))
    ans = []
    for k in div:
        tmp = n
        while tmp % k == 0:
            tmp = tmp // k
            if tmp < k or tmp == 1:
                break
        tmp = tmp % k
        if tmp == 1:
            ans.append(k)
    return len(ans)

print(solve2(n))

Measured memory_bytes: 41180
S = int(input())
i = 1
ans = [S]
while True:
    if S%2 == 0:
        S = S//2
        i += 1
        ans.append(S)
    else:
        S = 3*S+1
        i += 1
        ans.append(S)
    if len(set(ans[:-2]) & set([S]))!=0:
        break
print(i)

Measured memory_bytes: 3060
//                _                                      
//  ___ _ __ ___ (_) __ ___      ___   _ _ __ ___  _ __  
// / __| '_ ` _ \| |/ _` \ \ /\ / / | | | '_ ` _ \| '_ \ 
// \__ \ | | | | | | (_| |\ V  V /| |_| | | | | | | |_) |
// |___/_| |_| |_|_|\__, | \_/\_/  \__,_|_| |_| |_| .__/ 
//                  |___/                         |_|  
//code by smigwump
//https://codeforces.com/blog/entry/62393 hashing hack protection
//https://codeforces.com/blog/entry/61587 rand() alternatives
//https://codeforces.com/blog/entry/61675 randomized hack protection
#include <bits/stdc++.h>
typedef long long ll;
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define REP(i,a,b) for(ll i = a; i <= b; i++)
#define PER(i,a,b) for(ll i = a; i >= b; i--)

using namespace std;

int main() {
	// #ifndef ONLINE_JUDGE
	//     freopen("input.txt", "r", stdin);
	//     freopen("output.txt", "w", stdout);
	// #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    vector<ll> a(n,0);
    REP(i,0,n-1) {
    	cin>>a[i];
    }
    ll sum = 0;
    REP(i,1,n-1) {
    	if(a[i]<a[i-1]) {
    		sum += (a[i-1]-a[i]);
    		a[i] = a[i-1];
    	}
    }
    cout<<sum;
	return 0;
}

Measured memory_bytes: 4724
n,k,q = map(int,input().split())

a = []
for i in range(q):
  a.append(int(input()))

p = [k for _ in range(n)]
p = list(map(lambda x: x -q, p))
for s in a:
  
  p[s-1] = p[s-1] + 1

for i in p:
  if i > 0:
    print('Yes')
  else:
    print('No')

Measured memory_bytes: 11828
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cmath>
#include <functional>
#include <queue>
//#include <stack>
#include <climits>
#include <map>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define put(a) cout<<a<<endl;
#define all(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
using namespace std;
typedef long long ll;
//typedef unsigned long long ull;
typedef pair<int, int> P;

int n;
int s[400][400];

int jdg(int n){
    int k1 = floor(sqrt(n));
    return k1*(k1+1)==n;
}

int main() {
    cin >> n;
    n*=2;
    if(!jdg(n)){
        put("No");
        return 0;
    }else{
        put("Yes");
        int k = floor(sqrt(n))+1;
        vector<int> b(k);
        b[0] = k-1;
        REP(i,k-1){
            b[i+1] = b[i]+i-2;
        }
        vector<vector<int>> sc(k);
        int cnt = 1;
        REP(i,k-1){
            REP(j,k-1-i){
                sc[i].push_back(cnt);
                sc[i+j+1].push_back(cnt);
                cnt++;
            }
        }
        /*REP(i,n){
            auto itr = lower_bound(all(b),i+1);
            int  d = itr - b.begin();
            s[d][cnt++] =
            
        }*/
        //vector<vector<int>> s(k);
        put(k);
        REP(i,k){
            cout << k-1 << " ";
            REP(j,k-2){
                cout << sc[i][j] << " ";
        }
        put(sc[i][k-2]);
    }
    
        
    }
    return 0;
}



Measured memory_bytes: 2304
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int N;
  cin >> N;
  int a,b;
  vector<int> c(1e6+2,0);
  vector<int> d(1e6+2,0);
  for(int i = 0; i< N ;i++){
    cin >> a >> b;
      c[a]++;
      c[b+1]--;
  }
  for(int i = 0; i < c.size() ;i++){
    c[i+1] += c[i];
  }
  int maxnum = 0;
  for(int i = 1; i < c.size() ; i++){
    if(i <= c[i]+1) maxnum = i-1;
  }
  cout << maxnum << endl;
  return 0;
}

Measured memory_bytes: 8860
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#if __cplusplus >= 201103L
#include <chrono>
using namespace std::chrono;
#endif
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fi first
#define se second
#ifdef LOCAL
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
#else
#define prln(x) 
#define pr(x)
#define prv(x)
#endif
#define clr(x) memset((x), 0, sizeof((x)))
#define clr1(x) memset((x), -1, sizeof((x)))
#define endl "\n"
#define pi acos(-1)
#define rep(i, st, ed) for (int i = (st); i <= (ed); ++i)
#define rep0(i, st, ed) for (int i = (st); i < (ed); ++i)
#define per(i, st, ed) for (int i = (st); i >= ed; --i)
template<class T> void _sf(T &x) {cin >> x;}
void _sf(int &x) {scanf("%d", &x);}
void _sf(ll &x) {scanf("%lld", &x);}
void _sf(double &x) {scanf("%lf", &x);}
void _sf(char &x) {scanf(" %c", &x);}
void _sf(char *x) {scanf("%s", x);}
void sf() {}
template <class T, class...U> void sf(T & head, U&... tail) { _sf(head); sf(tail...);}
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

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

map<char, int> mm;

int main(){
	#ifdef LOCAL
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
		#if __cplusplus >= 201103L
		auto start = steady_clock::now();
		#endif
	#endif
	string s;
	cin >> s;
	for (auto ele : s) {
		mm[ele]++;
	}
	bool flag = true;
	for (auto ele : mm) {
		if (ele.second != 2) {
			flag = false;
		}
	}
	if (!flag) puts("No");
	else puts("Yes");
	#ifdef LOCAL
		#if __cplusplus >= 201103L
		auto end = steady_clock::now();
		duration<double> time_span = duration_cast<duration<double>>(end - start);;
		printf("Total time: %.6fs\n", time_span.count());
		#endif
	#endif
	return 0;
}

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

using namespace std;

using LL = long long;
template<class T> using min_heap = priority_queue<T, std::vector<T>, std::greater<T>>;
using LD = long double;

#define ALL(v) v.begin(), v.end()
#define en(v) *(--v.end())
#define endl '\n'
#define SYNC ios_base::sync_with_stdio(false); cin.tie(NULL); cerr.tie(NULL);
#define her     cerr << "here\n" 
#define un(x) x.erase(unique(ALL(x)), x.end())

template<class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=','){cerr<<*sdbg++;} cerr<<"="<<h<<","; _dbg(sdbg+1, a...);
}

#ifdef aishwarya_tandon_is_the_best
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

const int N = (int)1e5 + 10;

int n, m;
vector<vector<int>> g;
vector<int> p;
bool vis[N];
vector<int> nodes;
vector<int> vals;

void dfs(int u) {
  vis[u] = true;
  for(auto & i : g[u]) {
    if(!vis[i]) {
      dfs(i);
    }
  }
  nodes.push_back(u);
  vals.push_back(p[u]);
}

int calculate() {
  int ans = 0;
  sort(ALL(nodes));
  for(auto & i : vals) {
    if(binary_search(ALL(nodes), i))
      ans++;
  }
  return ans;
}

int32_t main() { SYNC
  cin >> n >> m;
  g.resize(n);
  p.resize(n);

  for(int i = 0; i < n; i ++) {
    cin >> p[i];
    p[i]--;
  }
  //debug("reached_here");

  for(int i = 0; i < m; i ++) {
    int x, y;
    cin >> x >> y;
    x--; y--;
    //debug(x, y);
    g[x].push_back(y);
    g[y].push_back(x);
  }

  //debug("reached_here");
  int ans = 0;
  for(int i = 0; i < n; i ++) {
    if(!vis[i]) {
      nodes.clear(); vals.clear();
      dfs(i);
      ans += calculate();
    }
  }

  cout << ans << endl;
  cerr << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
  return 0;
}


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

//#define Fast ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
typedef vector<int>Vl;
typedef pair<int,int>PII;
typedef vector<PII>Vll;
typedef vector<pair<int,pair<int,int> > >Vlll;
typedef priority_queue<int>PQL;
typedef map<int,int>MP;
#define S second
#define F first
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define sl(n) scanf("%lld",&n)
#define pl(n) printf("%lld",n)
const int mod=1e9+7;
const int sze=1e5+2;
#define ld long double
signed main(){
  int nt,na,n,t,a,p;
  nt=1;
  na=1;
  cin>>n;
  for(int i=0;i<n;i++){
	  cin>>t>>a;
	  int p=max(ceil(nt/ (ld)t),ceil(na/ (ld)a));
	  //cout<<p<<" ";
	  nt=t*p;
	  na=a*p;
  }
  cout<<(nt + na)<<endl;
  return 0;
}


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

int main(){
	int i;
	int a[3];
	rep(i, 3) cin >> a[i];
	sort(a, a+3);
	cout << a[0] + a[1] << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
const ll MOD = (ll)998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using vvvvector = vector<vvector<vector<t>>>;
template<class t>
using vvvvvector = vector<vvvvector<t>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

ll modpow(ll x, ll b){
	ll res = 1;
	while(b){
		if(b&1)res = res * x % MOD;
		x = x * x % MOD;
		b>>=1;
	}
	return res;
}

ll modinv(ll x){
	return modpow(x, MOD-2);
}

ll factorial(ll x){
	static vector<ll> memo;
	if(memo.empty()){
		int n = 1e7;
		memo.resize(n+1);
		memo[1]=1;
		repa(i, n){
			memo[i+1] = (i+1) * memo[i] % MOD;
		}
	}
	if(x<=1)return 1;
	return memo[x];
}

ll C(ll a, ll b){
	return factorial(a) * modinv(factorial(b)) % MOD * modinv(factorial(a-b)) % MOD;
}

int main(){
	ll n;
	cin >> n;
	ll ans = modpow(3, n);
	for(int i=n/2-1;i>=0;--i){
		ans -= 2 * C(n, i) * modpow(2, i) % MOD;
		ans = (ans % MOD + MOD) % MOD;
	}
	cout << ans << endl;
	return 0;
}




Measured memory_bytes: 78336
n,k = map(int, input().split())
mod = 1000000007
ans = 0
for i in range(k, (n+2)):
    min= (0+(i-1))/2*i
    max= (n+(n-i+1))/2*i
    count = max -min +1
    ans += count
ans %=mod
print(int(ans))


Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define sec second
#define fir first
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
typedef vector<int> Vec;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



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

    int n;
    cin >> n;
    Vec a(n);
    rep(i, n) cin >> a[i];

    int res = 0;
    rep(i, 60) {
        int count = 0;
        rep(j, n) {
            if(a[j] & (1LL << i)) count++;
        }
        int now = (1LL << i) % MOD;
        now *= count, now %= MOD;
        now *= n - count, now %= MOD;
        res += now, res %= MOD;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 2688
n=int(input())
s=input()
from collections import defaultdict
l,r=s[:n],s[-1:-n-1:-1]
d=defaultdict(int)
for i in range(2**n):
    a={j for j in range(n)if (i>>j)%2}
    d[("".join(l[p] for p in sorted(list(a))),"".join(l[o] for o in range(n)if o not in a))]+=1
ans=0
for i in range(2**n):
    a={j for j in range(n)if (i>>j)%2}
    ans+=d[("".join(r[p] for p in sorted(list(a))),"".join(r[o] for o in range(n)if o not in a))]

print(ans)

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

typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;

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

    int n;    
    cin >> n;
    vi a(n);
    vector<vll> dp(n, vll(n));
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    for (int i = 0; i < n; ++i) {
        if (n & 1)
            dp[i][i] = a[i];
        else
            dp[i][i] = -a[i];
    }
    for (int len = 2; len <= n; ++len) {
        for (int i = 0; i + len <= n; ++i) {
            int j = i + len - 1;
            if ((n - len) & 1) {
                dp[i][j] = min(dp[i + 1][j] - a[i], dp[i][j - 1] - a[j]);
            }
            else {
                dp[i][j] = max(dp[i + 1][j] + a[i], dp[i][j - 1] + a[j]);
            }
        }
    }
    cout << dp[0][n - 1] << '\n';

    return 0;
}

Measured memory_bytes: 70784
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
struct node
{
    char ming[15];
    int fen;
    int flag;
}a[15];

int cmp(node a,node b)
{
    if(strcmp(a.ming,b.ming)==0)return a.fen>b.fen;
   if(strcmp(a.ming,b.ming)<0)return 1;
   return 0;
}

int main()
{
   int n;
   cin>>n;
   for(int i=1;i<=n;i++)
   {
       scanf("%s%d",&a[i].ming,&a[i].fen);
       a[i].flag=i;
   }
   sort(a+1,a+n+1,cmp);
   for(int i=1;i<=n;i++)printf("%d\n",a[i].flag);
    return 0;
}


Measured memory_bytes: 256
N,K = list(map(int, input().split(" ")))
H = sorted(list(map(int, input().split(" "))), reverse=True)
Z = 0
R = 0
for n,e in enumerate(H):
  if (n == K):
    Z = n
    break
  elif (K >= len(H)):
    Z = len(H)
    break
for i in H[Z:]:
  R += i
print(R)


Measured memory_bytes: 31404
import bisect

n = int(input())
As = list(map(int, input().split()))

As.sort()
maxA = As[-1]

i = bisect.bisect_right(As, maxA / 2)
if i == n - 1:
    i = i - 1
elif i > 0:
    if maxA / 2 - As[i - 1] < As[i] - maxA / 2:
        i = i - 1

print(maxA, As[i])


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

def main():
    Q, H, S, D = map(int, input().split())
    N = int(input())
    c1 = min(Q*4, H*2, S)
    c2 = min(c1*2, D)
    ans = 0
    ans += c2 * (N//2)
    rest = int(N%2)
    ans += c1 * rest
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int d = sc.nextInt();
        int[][] x = new int[n][d];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < d; j++) {
                x[i][j] = sc.nextInt();
            }
        }

        int resCnt = 0;
        for (int i = 0; i < n-1; i++) {
            for (int in = i+1; in < n; in++) {
                int sq = 0;
                for (int di = 0; di < d; di++) {
                    sq += Math.pow(x[i][di] - x[in][di], 2);
                }
                if (Math.pow((int)Math.sqrt(sq), 2) == sq) {
                    resCnt++;
                }
            }
        }
        System.out.println(resCnt);
    }
}

Measured memory_bytes: 22996
#include <iostream>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
template<class T = ll> constexpr T TEN(int n) {return (n==0)?1:10*TEN<T>(n-1);}

int main() {
    int h, w;
    cin >> h >> w;

    bool g[h][w];
    for (int y = 0; y < h; y++) {
        string s;
        cin >> s;
        for (int x = 0; x < w; x++) {
            g[y][x] = (s[x] == '#');
        }
    }

    bool r[h][w], b[h][w];
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            bool rf = false;
            if (x == 0) rf = true;
            if (x < w-1 and y % 3 == 0) rf = true;
            bool bf = false;
            if (x == w-1) bf = true;
            if (0 < x and y % 3 == 1) bf = true;
            if (g[y][x]) {
                rf = bf = true;
            }
            r[y][x] = rf; b[y][x] = bf;
        }
    }

    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            if (r[y][x]) {
                cout << "#";
            } else {
                cout << ".";
            }
        }
        cout << endl;
    }
    cout << endl;
    for (int y = 0; y < h; y++) {
        for (int x = 0; x < w; x++) {
            if (b[y][x]) {
                cout << "#";
            } else {
                cout << ".";
            }
        }
        cout << endl;
    }
    return 0;
}

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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	string s, t;
	cin >> s >> t;
	int ans=0;
	for(int i=0; i<3; i++){
		if(s[i]==t[i]) ans++;
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll,ll> P;
typedef vector<P> vp;

const ll mod = 1e9+7;
const ll inf = 1e16;

#define loop(i,m,n) for(ll i=m;i<n;i++)
#define vloop(it,x) for(auto it=x.begin(); it!=x.begin(); it++)
#define all(x) x.begin(),x.end()
#define debug(x) cout << #x <<":"<< x <<endl	
#define showll(x) printf("%lld\n",x)
#define test(t) ll t;cin >> t;while(t--)
#define showc(x) printf("%c\n",x)
#define show(x) cout << x << endl
#define read(x) cin >> x
#define yes printf("YES\n")
#define no printf("NO\n")
#define pb push_back
#define mp make_pair

void fast()
{
ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
}

//////////////////////////////// - _ - \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

#define MAXN 60000001
int spf[MAXN]; 
  
// Calculating SPF (Smallest Prime Factor) for every 
// number till MAXN. 
// Time Complexity : O(nloglogn) 
void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++) 
  
        // marking smallest prime factor for every 
        // number to be itself. 
        spf[i] = i; 
  
    // separately marking spf for every even 
    // number as 2 
    for (int i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for (int i=3; i*i<MAXN; i++) 
    { 
        // checking if i is prime 
        if (spf[i] == i) 
        { 
            // marking SPF for all numbers divisible by i 
            for (int j=i*i; j<MAXN; j+=i) 
  
                // marking spf[j] if it is not  
                // previously marked 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 
  
#define  maxi 100005
ll indegree[maxi];
ll dist[maxi];
bool visited[maxi];
vector <ll> edges[maxi];

void dfs(ll a)
{
	if(visited[a]==true)
	{
		return;
	}

	visited[a]= true;
	for(ll b: edges[a])
	{
		dist[b] = max(dist[b],dist[a]+1);
		indegree[b]--;
		if(indegree[b]==0)
		{
			dfs(b);
		}
	}
}

int main()
{
	ll n,m,i,a,b;
	ll ans = 0;
	read(n);read(m);
	loop(i,0,m)
	{
		scanf("%lld %lld",&a,&b);
		edges[a].pb(b);
		indegree[b]++;
	}
	loop(i,1,n+1)
	{
		if(visited[i]==false && indegree[i]==0)
		{
			dfs(i);
		}
	}
	loop(i,1,n+1)
	{
		ans = max(ans,dist[i]);
	}
	printf("%lld\n",ans);

}

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

struct node {
	
	long long seg_st, seg_en, seg_mid;
	long long val;
	node *left, *right;
	
	node(long long st, long long en) {
		
		seg_st = st;
		seg_en = en;
		seg_mid = (st + en) / 2;
		val = 0;
		if (st == en) return;
		left = new node(st, seg_mid);
		right = new node(seg_mid+1, en);
		
	}
	
	void update(long long pos, long long to) {
		if (pos < seg_st || pos > seg_en) return;
		if (seg_st == seg_en) {
			val = to;
			return;
		}
		left->update(pos, to);
		right->update(pos, to);
		val = max(left->val, right->val);
	}
	
	long long query(long long le, long long ri) {
		if (le > seg_en) return INT_MIN;
		if (ri < seg_st) return INT_MIN;
		if (le <= seg_st && seg_en <= ri) return val;
		return max(left->query(le, ri), right->query(le, ri));
	}
	
} *root;

void init(long long x) {
	root = new node(0, x-1);
}

void update(long long pos, long long to) {
	root->update(pos, to);
}

long long query(long long a, long long b) {
	return root->query(a, b);
}

int main() {
	
	long long n;
	cin >> n;
	long long he[n];
	long long va[n];
	
	for (int i=0; i<n; i++) cin >> he[i];
	for (int i=0; i<n; i++) cin >> va[i];
	
	init(n+1);
	
	long long ans = 0;
	
	for (int i=0; i<n; i++) {
		long long at = he[i];
		long long mx = query(0, at-1);
		long long v = va[i] + mx;
		ans = max(ans, v);
		update(at, v);
		// cout << at << ' ' << mx << ' ' << v << ' ' << ans << endl;
	}
	
	cout << ans << endl;
	
}




Measured memory_bytes: 28416
#include <stdio.h>  /*入出力*/
#include <stdlib.h> /*標準ライブラリ*/
#include <string.h> /*文字列*/
#include <math.h>   /*計算*/
#include <assert.h> /*確認*/
#include <ctype.h>  /*文字操作*/
#include <stdbool.h>/*bool型*/
#include <limits.h>/*限界*/
//---------------------------------------------------
#define rep(i, n) for(int  i = 0; i < (n); i++)
#define ABS(a) (((a)>(0))?a:-(a))
#define LL long long
#define MOD 1000000007//10^9+7(素数)
//---------------------------------------------------
LL max(LL a, LL b){
  if (a > b) {
    return a;
  }else return b;
}

void swap(LL *a, LL *b)
{
  LL temp;
  temp = *a;*a = *b;*b = temp;
}



int main(void)
{
  LL n;
  LL m;
  LL a;
  LL b;
  LL *c;
  LL *h;
  LL *ans;
  LL sum = 0;

  scanf("%lld %lld", &n, &m);
  h = (LL *)malloc(sizeof(LL) * (n+2));
  if (h == NULL) {
    exit(0);
  }
  ans = (LL *)malloc(sizeof(LL) * (n+2));
  if (ans == NULL) {
    exit(0);
  }
  c = (LL *)malloc(sizeof(LL) * (n+2));
  if (c == NULL) {
    exit(0);
  }

  for (LL i = 0; i < n; i++) {
    scanf("%lld", &h[i]);
    ans[i] = 0;
    c[i]= 0;
  }

  for (LL i = 0; i < m; i++) {
    scanf("%lld %lld", &a, &b);
    if (h[a-1] == h[b-1]) {
      c[a-1]++;
      c[b-1]++;
    //  printf("%lld %lld ++\n",c[a], c[b] );
    }
    else if (h[a-1] > h[b-1]) {
      if (ans[a-1] < h[a-1]) {
        ans[a-1] = h[a-1];
      }
      ans[b-1] = h[a-1];
    }else{
      if (ans[b-1] < h[b-1]) {
        ans[b-1] = h[b-1];
      }
      ans[a-1] = h[b-1];
    }
  }

  for (LL i = 0; i < n; i++) {
  //  printf("ans[i] = %lld\n",ans[i] );
    if (ans[i] == h[i] || ans[i] == 0) {
      if (c[i] == 0) {
      //  printf("hit %d\n",i-1 );
        sum++;
      }
    }
  }
  printf("%lld\n", sum);


  free(h);
  free(ans);
  free(c);
  return 0;
}


Measured memory_bytes: 3832
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)

using namespace std;

const int mod=1e9+7;

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}

void run(){
    int n;
    cin>>n;
    vi r(n),c(n);
    rep(i,n){
        cin>>r[i]>>c[i];
    }
    int dp[n+1][n+1];
    MEMSET(dp);
    REP(a,2,n){
        rep(i,n-a+1){
            int j=i+a-1;
            dp[i][j]=inf;
            REP(k,i,j-1){
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+r[i]*c[k]*c[j]);
            }
        }
    }
    cout<<dp[0][n-1]<<endl;
}


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

using namespace std;

#define debug(x) cout << '[' << #x << " is: " << x << "] " << '\n';
#define imod(a , n) (a % n + n ) % n

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
#define inF freopen("lineup.in","r",stdin );
#define outF freopen("lineup.out" , "w" , stdout ) ;
#define sor(v) sort(v.begin() , v.end());
#define print(v) for(auto f : v ) cout << f << " " ;
#define ll long long
#define int ll
const double eps = 1e-6 , PI = acos(-1) ;
const long long OO = 1e18 ;
const ll N = 200 , oo = 1e7 , M = 6, mod = 1e9 + 7 , K = 12;

int32_t main(){
    // inF;outF;

    fastio;
    // Dont Forget memset

    //calculate constraints please!!!
    char a ;
    cin >> a;
    if(a > 96)cout << 'a';
    else cout << 'A';

}


Measured memory_bytes: 3628
#include <stdio.h>

int main(void) {
  char s[50], t[50];
  int S, T, i;
  
  scanf("%s %s", s, t);
  
  S = strlen (s);
  T = strlen (t);
  
  if (S > T) {
    for (i = 0; i < T; i++) {
      printf("%c%c", s[i], t[i]);
    }
    printf("%c\n", s[i]);
  } else {
    for (i = 0; i < T; i++) {
      printf("%c%c", s[i], t[i]);
    }
    printf("\n");
  }
  
  return 0;
}


Measured memory_bytes: 128
import sys

A = [[0] * 3 for i in range(3)]

A1 = list(map(int, input().split()))
A2 = list(map(int, input().split()))
A3 = list(map(int, input().split()))

N = int(input())
for _ in range(N):
    b = int(input())
    if b in A1:
        for a in [i for i, x in enumerate(A1) if x == b]:
            A[0][a] = 1
    if b in A2:
        for a in [i for i, x in enumerate(A2) if x == b]:
            A[1][a] = 1
    if b in A3:
        for a in [i for i, x in enumerate(A3) if x == b]:
            A[2][a] = 1

for i in range(3):
    if sum(A[i][:]) == 3:
        print('Yes')
        sys.exit()

if A[0][0] == 1 and A[1][0] == 1 and A[2][0] == 1:
    print('Yes')
    sys.exit()
if A[0][1] == 1 and A[1][1] == 1 and A[2][1] == 1:
    print('Yes')
    sys.exit()
if A[0][2] == 1 and A[1][2] == 1 and A[2][2] == 1:
    print('Yes')
    sys.exit()

if A[0][0] == 1 and A[1][1] == 1 and A[2][2] == 1:
    print('Yes')
    sys.exit()

if A[0][2] == 1 and A[1][1] == 1 and A[2][0] == 1:
    print('Yes')
    sys.exit()

print('No')

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
typedef long long ll;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define FOR(i,n) for(int i=0;i<n;i++)
#define all(s) s.begin(),s.end()
#define lla(s) s.rbegin(),s.rend()
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const ll INF = 1e18;



signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,ans = 0;
    cin>>n;
    vector<int>a(n),b(60,0);
    rep(i,0,n){
        cin>>a[i];
    }
    rep(i,0,n){
        rep(j,0,60){
            if(a[i] & (1LL<<j)){
                b[j]++;
            }
        }
    }
    int s = 1;
    rep(i,0,60){
        ans+=((s<<i)%MOD)*(((n-b[i])*b[i])%MOD)%MOD;
        ans%=MOD;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2560
#!/usr/bin/env python3
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


def main():
    _ = readline()
    Ps = list(map(int, readline().split()))
    ans = 1
    tmp = Ps[0]
    for P in Ps[1:]:
        if tmp > P:
            ans += 1
            tmp = P
        if P == 1:
            break
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 20468
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (int)(n); i++
using namespace std;

int main() {
	int q,a,b;
	set<int> s;
	cin >> q;
	for (int i = 0; i < q; i++) {
		cin>>a>>b;
		if (a == 0) {
			s.insert(b);
			cout << s.size() << endl;
		}
		else if (a == 1) {
			cout << s.count(b) << endl;
		}
		else {
			s.erase(b);
		}
	}
}




Measured memory_bytes: 12444
#include<cstdio>
#include<cstring>
using namespace std;
#define MAXN 100005
char s[MAXN];
int main()
{
	scanf("%s",s);
	int len=strlen(s);
	for(int i=0;i<=len-2;i++)
	{
		if(s[i]==s[i+1])
		{
			printf("%d %d\n",i+1,i+2);
			return 0;
		}
		if(s[i]==s[i+2])
		{
			printf("%d %d\n",i+1,i+3);
			return 0;
		}
	}
	printf("-1 -1\n");
	return 0;
}

Measured memory_bytes: 256
#include  <iostream>
using namespace std;
int main ()
{
	int a,b,c,d,x;
	while(cin >> a>>b>>c>>x)
	{
		d=0;
		for(int i=0;i<=a;i++)
		{
			for(int j=0;j<=b;j++)
			{
				for(int k=0;k<=c;k++)
				{
					if(i*500+j*100+k*50==x)
					d++;
				}
   			}
		}
		cout <<d<<endl;        
	}	
	return 0;
 } 

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int N;
	cin >> N;
	int a[N];
	int i,j,total=0;
	for(i=0;i<N;i++){
		cin >> a[i];
	}

	for(i=1;i<101;++i){
		for(j=0;j<N;++j){
			if(a[j]==i){
				total = total + 1;
				break;
			}
		}
	}
	cout << total << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.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 perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
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 x;cin >> x;
    x^=1;
    cout << x <<endl;
} 

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

int main(){
  int n,h; cin>>n>>h;
  vector<int> a(n),b(n);
  int ma=0,mb=0;
  long long count=0;
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i];
    if(ma<a[i]){
      ma=a[i];
      mb=b[i];
    }
  }sort(b.begin(),b.end());
  reverse(b.begin(),b.end());
  bool flag=true;
  for(int i=0;i<n;i++){
    if(flag && mb==b[i]){
      flag=false;
      continue;
    }if(b[i]>=ma){
      h-=b[i];
      count++;
    }if(h<=0){
      cout<<count<<endl;
      return 0;
    }if(h<=mb){
      cout<<count+1<<endl;
      return 0;
    }
  }while(h>mb){
    count++;
    h-=ma;
  }
  cout<<count+1<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define mod 1000000007
using data=pair<ll,ll>;

long mmid(long a,long b,long c){return a<b?(b<c?b:max(a,c)):(b>c?b:min(a,c));}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

ll modncr(ll n,ll r){
  ll i,plus=1;
  rep(i,r){
    plus=(plus*(n-i))%mod;
    plus=moddevide(plus,i+1);
  }
  return plus;
}

ll euclidean_gcd(ll a, ll b) {
  if(a<b) return euclidean_gcd(b, a);
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

void printmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  For(i,0,H+2){
    For(j,0,W+2){cout<<a[i*(W+2)+j];}
    cout<<endl;
  }
}
void inputmap(vector<ll>& a,ll H,ll W){
  ll i,j;
  string ss;
  For(i,1,H+1){
    cin>>ss;
    For(j,1,W+1){
      if(ss[j-1]=='#'){
        a[i*(W+2)+j]=1;
      }else{
        a[i*(W+2)+j]=0;
      }
    }
  }
}

void dijkstra(vector<vector<data>>& tree,vector<ll>& d,ll start){
  ll i,K=tree[start].size(),N=d.size(),cnt=1;
  data x;
  d[start]=0;
  priority_queue<data,vector<data>,greater<data>> que;
  rep(i,K){
    que.push(data(tree[start][i].second,tree[start][i].first));
  }
  while(cnt<N){
    x=que.top();que.pop();
    if(d[x.second]>0)continue;
    d[x.second]=x.first;
    cnt++;
    K=tree[x.second].size();
    rep(i,K){
      if(d[tree[x.second][i].first]<0){
        que.push(data(d[x.second]+tree[x.second][i].second,tree[x.second][i].first));
      }
    }
  }
}


int main(){
  ll i,j,N,M,K;
  char a[4],b[4],c[4],ans[4];
  scanf("%s",a);
  scanf("%s",b);
  scanf("%s",c);
  ans[0]=a[0];
  ans[1]=b[1];
  ans[2]=c[2];
  ans[3]='\0';
  printf("%s\n",ans);
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P>IP;
typedef vector<ll> V;
typedef vector<V> V2;
typedef vector<vector<P> > G;
void g_dir(G &graph, ll a, ll b, ll w = 1){graph[a].push_back(P(b, w));}
void g_undir(G &graph, ll a, ll b, ll w = 1){g_dir(graph, a, b, w);g_dir(graph, b, a, w);}
#define rep(i, n) for(ll (i) = 0; (i) < (n); (i)++)
#define rep1(i, n) for(ll (i) = 1; (i) <= (n); (i)++)
#define rrep(i, n) for(ll (i) = (n) - 1; (i) >= 0; (i)--)
#define rrep1(i, n) for(ll (i) = (n); (i) >= 1; (i)--)
template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}
const ll INF = 1145141919;
const ll MOD = 1000000007;
const ll NUM = 101010;

int main(){

    ll H;
    cin >> H;
    ll num = 1;
    ll sum = 0;
    for(;H;H/=2){
        sum += num;
        num *= 2;
    }
    cout << sum << endl;
    
    return 0;
}

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

int main(){
  string S;
  cin >> S;
  
  int a=0,b=0,c=0;
  for(int i=0; i<S.size(); i++){
    if(S[i]=='a') a++;
    else if(S[i]=='b') b++;
    else c++;
  }
  
  bool is_able = true;
  
  /*
  //xxをつくらずにすむ
  if(b+c<a-1||c+a<b-1||a+b<c-1) is_able = false;
  //下に含まれるので削除
  */
  
  //xyxをつくらずにすむ
  if(b<a-1||c<a-1||a<b-1||c<b-1||a<c-1||b<c-1) is_able = false;
  
  cout << (is_able==true?"YES":"NO") << endl;
}


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

const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
const int MOD=1000000007;

int main(){
	int x;cin>>x;
	cout<<((x/500)*1000+(x%500)/5*5)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define FOR(i,a,b) for(i=a;i<=b;i++)
#define RFOR(i,a,b) for(i=a;i>=b;i--)
#define inf 1000000007
using namespace std;
ll x[100010];
int main()
{
    ll i,j,k,n,t;
    ll a,b;
    cin>>n>>a>>b;
    FOR(i,1,n) cin>>x[i];
    k=0;
    FOR(i,1,n-1)    k= k+min(b, a*(x[i+1]-x[i]));
    cout<<k<<endl;
    return 0;
}


Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author HossamDoma
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {

            int h = in.nextInt();
            int w = in.nextInt();

            int n = in.nextInt();
            int[] a = new int[n];

            for (int i = 0; i < n; ++i) {
                a[i] = in.nextInt();
            }

            int[][] ans = new int[h][w];

            int i = 0;
            int j = 0;

            boolean[][] vis = new boolean[h][w];

            int cur = 0;
            int tot = 0;

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

            for (int idx = 0; tot < h * w; idx = (idx + 1) % 4, i += dx[idx], j += dy[idx]) {

                while (i >= 0 && j >= 0 && i < h && j < w && !vis[i][j]) {
                    vis[i][j] = true;
                    ans[i][j] = cur + 1;
                    a[cur]--;
                    tot++;
                    if (a[cur] == 0) cur++;
                    i += dx[idx];
                    j += dy[idx];
                }

                //roll_back
                i -= dx[idx];
                j -= dy[idx];

            }


            for (int ii = 0; ii < h; ++ii)
                for (int jj = 0; jj < w; ++jj)
                    out.print(ans[ii][jj] + (jj == w - 1 ? "\n" : " "));

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 25300
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<functional>
#include<climits>
#include<utility>
#include <iomanip>
#include<map>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define FORB(i,s,e,st) for (int i = int(s); i < int(e); i+=(int(st)))
#define FOR(i,s,e) FORB(i,s,e,1)
#define REP(i,x) FOR(i,0,x)
#define CLR(a) memset((a), 0 ,sizeof(a))


const int MOD = 1e+9+7;
const double PI  = acos(-1.0);

vi g[100000];

int main(){
	string s;
	cin>>s;
	if(s[0]==s[1]){
		cout<<"1 2\n";
		return 0;
	}
	for(int i=2;i<s.length();i++){
		if(s[i]==s[i-1]||s[i]==s[i-2]){
			cout<<i-1<<" "<<i+1<<"\n";
			return 0;
		}
	}
	cout<<"-1 -1\n";
}


Measured memory_bytes: 2816
n = int(input())
ai = list(map(int,input().split()))

def gcd(a, b):
  while b:
    a, b = b, a%b
  return a

r=[]
l=[]
resr = ai[0]
resl = ai[n-1]
r.append(ai[0])
l.append(ai[n-1])
for i in range(1,n):
	resr=gcd(resr,ai[i])
	r.append(resr)
	resl=gcd(resl,ai[n-1-i])
	l.append(resl)

#print(r)
#print(l)

resmax = 1
for i in range(n):
	if i == 0:
		res = l[n-1-1]
	elif i == n-1:
		res = r[n-1-1]
	else:
		res = gcd(r[i-1], l[n-1-i-1])
	if res > resmax:
		resmax = res

print(int(resmax))

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

using namespace std;

int n, k, w[100000];

bool check(int p){
  int cnt = 1;
  long long total = 0;

  for(int i = 0;i < n;i++){
    if(w[i] > p) return false;
    if(total + w[i] <= p) total += w[i];
    else{
      cnt++;
      total = w[i];
    }
  }

  if(cnt <= k) return true;
  else return false;
}

int main(){
  long long left = 0, right = 100000 * 10000;

  cin >> n >> k;
  for(int i = 0;i < n;i++){
    cin >> w[i];
    left = max(left, (long long)w[i]);
  }

  while(left < right){
    int mid = (left + right) / 2;

    if(check(mid)) right = mid;
    else left = mid + 1;
  }

  cout << left << endl;

  return 0;
}



Measured memory_bytes: 3488
#include <stdio.h>
int main()
{
    int a, b, c, d, i, f;
    scanf("%d %d %d %d", &a, &b, &c, &d);

    i = a*b;
    f = c*d;
    if(i>f)
    {
        printf("%d", i);
    }
    else
    {
        printf("%d", f);
    }
    return 0;
}

Measured memory_bytes: 1704
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,cnt=0; cin>>n;
    set<int> s;
    rep(i,n){
        int a; cin>>a;
        a/=400;
        if(a>=8) cnt++;
        else s.insert(a);
    }
    if(s.size()){
        cout<<s.size()<<" "<<s.size()+cnt<<endl;
    }
    else{
        cout<<1<<" "<<cnt<<endl;
    }
}

Measured memory_bytes: 256
def StrToAddress(s)
	return if s.length < 1

	bas = ""
	s.chars { |c|
		case c
		when 'A'
			bas += "0"
		when 'C'
			bas += "1"
		when 'G'
			bas += "2"
		when 'T'
			bas += "3"
		end
	}
	bas.to_i(4) + (1...s.length).inject(0) { |total, n| total + 4**n }
end

dic = Array.new(4**12, false)
gets.to_i.times {
	str = gets.chomp.split(" ")
	add = StrToAddress(str[1])

	case str[0]
	when "insert"
		dic[add] = true
	when "find"
		if dic[add]
			puts "yes"
		else
			puts "no"
		end
	end
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

typedef long long ll;
typedef long double ld;

const ll Inf = 1e18;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    string s;
    cin >> s;
    char tmp = s[0];
    int res = 0;
    rep (i, s.size()) {
        if (tmp == s[i]) continue;
        tmp = s[i];
        res++;
    }
    cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 512
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int a[][] = new int[n][2];
		int c[][] = new int[m][2];
		int ans[] = new int[n];

		for (int i = 0; i < n; i++) {
			a[i][0] = sc.nextInt();
			a[i][1] = sc.nextInt();
		}

		for (int i = 0; i < m; i++) {
			c[i][0] = sc.nextInt();
			c[i][1] = sc.nextInt();
		}

		for (int i = 0; i < n; i++) {
			int min = Integer.MAX_VALUE;
			int no = 0;
			for (int j = 0; j < m; j++) {
				int tmp = min;
				min = Math.min(min, Math.abs(c[j][0] - a[i][0]) + Math.abs(c[j][1] - a[i][1]));
				if (tmp != min) no = j;
			}
			System.out.println(no + 1);
		}

		sc.close();

	}

}

Measured memory_bytes: 35732
#pragma warning(disable:4996)
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int top, S[1000];//栈顶，数组栈

void push(int x) {
	S[++top] =  x; //先将栈顶加一，再将x入栈
}
int pop() {
	top--;
	//将原先栈顶元素，即pop走的元素返回
	return S[top + 1];
}
int main(){
	int a, b;
	top = 0;
	char s[100];//每次输入的操作符或者数字

	while (scanf("%s", &s) != EOF) {//不停接受操作数，直到文件结尾
		if (s[0] == '+') {
			a = pop();
			b = pop();
			push(a + b);
		}else if (s[0] == '-') {
			a = pop();
			b = pop();
			push(b - a);
		}
		else if (s[0] == '*') {
			a = pop();
			b = pop();
			push(a * b);
		}
		else {
			push(atoi(s));
			//将字符串转化数字为整型
		}
	}
	printf("%d\n", pop());

}


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

typedef long long ll;

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

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

int main() {
    int A,B;
    cin >> A >> B;
    
    char c[100][100];
    REP(i,100) REP(j,100){
        if ( i < 50 ) c[i][j] = '#';
        else c[i][j] = '.';
    }
    
    int x = 0, y = 0;
    REP(a,A-1){
        c[x][y] = '.';
        y += 2;
        if ( y >= 100 ) {
            y = 0;
            x += 2;
        }
    }
    
    x = 60; y = 0;
    REP(b,B-1){
        c[x][y] = '#';
        y += 2;
        if ( y >= 100 ){
            y = 0;
            x += 2;
        }
    }
    
    cout << 100 << " " << 100 << endl;
    REP(i,100) REP(j,100){
        cout << c[i][j];
        if ( j == 99 ) cout << endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 3644