akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int n,a[100500];

long long dp[100500];

int main(){
     cin >> n;
     for(int i = 1; i <= n; i++){
     	cin >> a[i];
     	dp[i] = 1e18;
     }
     dp[1] = 0;
     dp[2] = abs(a[2] - a[1]);
     for(int i = 3; i <= n; i++){
     	dp[i] = min(dp[i],min(dp[i - 1] + abs(a[i] - a[i - 1]),dp[i - 2] + abs(a[i] - a[i - 2])));
     }
     cout << dp[n];
	return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define make_unique(vec) vec.resize(distance(vec.begin(),unique(vec.begin(),vec.end())))
#define Sort(vec) sort(vec.begin(),vec.end())
#define RSort(vec) sort(vec.rbegin(),vec.rend())
#define endl "\n"
#define tr1(i) cout<<i<<endl;
#define tr2(i,j) cout<<i<<" "<<j<<endl;
#define tr3(i,j,k) cout<<i<<" "<<j<<" "<<k<<endl;
#define vvi vector<vector<int> > 
#define vvl vector<vector<ll> >
#define all(st) st.begin(),st.end()
#define vpl vector<pair<ll,ll> >
#define vpi vector<pair<int,int> >
#define pi pair<int,int>
#define pl pair<ll,ll>
#define al vector<list<int> >
#define vs vector<string>
#define vi vector<int>
#define vb vector<bool>
#define vl vector<ll>
#define vc vector<char>
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repit(st) for(auto it=st.begin();it!=st.end();it++)
#define ull unsigned long long int
#define eb emplace_back
#define pb push_back
#define ll long long int
#define minf -(1e18)
#define inf 1e18
#define f first
#define se second
#define mod 1000000007
#define mx 500001
using namespace std;
ll mi(ll n,ll m){ll pw=n;ll ex=m-2;ll ans=1;while(ex){if(ex&1) ans = ans*pw%m;pw = pw*pw%m;ex>>=1;}return ans;}
ll pw(ll a,ll n){ll pw=a;ll ex=n;ll ans=1;while(ex){if(ex&1) ans = ans*pw;pw = pw*pw;ex>>=1;}return ans;}
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
void show(ll x){cout<<x<<" ";}
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;}
ll max(ll a,ll b){return a>b?a:b;}
ll min(ll a,ll b){return a<b?a:b;}
ll Abs(ll x){return x>0?x:(-x);}
ll Ceil(ll a,ll b){return a/b+(a%b!=0);}
#define bs binary_search
#define lb lower_bound
#define mkp make_pair
//#define d double
void solve(){
ll n,k;
cin>>n>>k;
vb rk(10);
ll x;
rep(i,0,k) cin>>x,rk[x]=true;
while(true){
	ll tk=n;
	bool ok=true;
	while(tk){
		int r=tk%10;
		if(rk[r]){
			ok=false;
			break;
		}
		tk/=10;
	}
	if(ok) break;
	n++;
}
cout<<n;
}
int32_t main(){
FIO;
int t=1;
//cin>>t;
while(t--){
	solve();
}
}



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

int main()
{
    int n,p=0,q=0;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    reverse(a,a+n);
    for(int i=0;i<n;i++)
    {
        if(i%2==0)
          p+=a[i];
        else
          q+=a[i];
    }
    cout<<p-q;

    return 0;
}



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

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
#define LINF 1e18
//const int mod = 1e9+7;
const int mod = 998244353;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef long long i64;

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

  int n, a;
  cin >> n >> a;
  vi x(n);
  int sum = 0;
  rep(i, 0, n) {
    cin >> x[i];
    sum += x[i];
  }

  vector<vector<vector<i64>>> dp(n + 1, vector<vector<i64>>(n + 1, vector<i64>(2501, 0)));
  dp[0][0][0] = 1;
  rep(i, 1, n + 1) {
    rep(k, 0, n + 1) {
      rep(s, 0, sum + 1) {
        if(s < x[i - 1]) dp[i][k][s] = dp[i - 1][k][s];
        else if(k >= 1 && s >= x[i - 1]) dp[i][k][s] = dp[i - 1][k][s] + dp[i - 1][k - 1][s - x[i - 1]];
        else dp[i][k][s] = 0;
      }
    }
  }

  i64 ans = 0;
  rep(k, 1, n + 1) {
    ans += dp[n][k][k * a];
  }
  cout << ans << endl;
}


Measured memory_bytes: 52224
let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d\n" @@ fun a -> a in
  let as' = Array.copy as_ in
  Array.sort (fun a a' -> compare a' a) as';
  Array.iter (fun a ->
    Printf.printf "%d\n" @@ if a = as'.(0) then as'.(1) else as'.(0)) as_



Measured memory_bytes: 7552
from itertools import combinations
s = input()
d = {0: 1}
tmp = 0
i = 0
for char in s[::-1]:
    tmp += int(char) * pow(10, i, 2019)
    tmp %= 2019
    if tmp not in d:
        d[tmp] = 1
    else:
        d[tmp] += 1
    i += 1

result = 0
for num, v in d.items():
    result += v * (v - 1) // 2

print(result)


Measured memory_bytes: 68944
/*
 * ID: adityaa
 * LANG: C++
 */
#include <bits/stdc++.h>
using namespace std;

#define fio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mem(x, y) memset(x, y, sizeof x);
#define fi first
#define se second
#define pb push_back
#define pii pair<int , int>
#define asdfg y1
#define int long long
#define double long double
#define endl '\n'
#define PI 3.14159265359

/*-----------------------------------------------------------------------*/

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

/*-----------------------------------------------------------------------*/

// check base cases n = 0 , n = 1
// max / min questions - check for binary search
const int maxn = (int) 110;
const double EPS = 1e-9;
const int INF = (int)1e18 + 18;
const int mod = (int) 998244353;
int n , max_weight , weight[maxn] , value[maxn];

const int max_value = 100000;
int dp[maxn][max_value + 1];

signed main() {
    
    fio;
    cin >> n >> max_weight;
    for(int i = 1; i <= n; i++){
        cin >> weight[i] >> value[i];
        for(int j = 0; j <= max_value; j++){
            dp[i][j] = INF;
        }
    }
    
    dp[1][value[1]] = weight[1];
    dp[1][0] = 0;
    for(int i = 2; i <= n; i++){
        for(int j = 0; j <= max_value; j++){
            dp[i][j] = min(dp[i][j] , dp[i - 1][j]);
            if(value[i] > j) continue;
            dp[i][j] = min(dp[i][j] , dp[i - 1][j - value[i]] + weight[i]);
        }
    }
    
    for(int i = max_value; i >= 0; i--){
        if(dp[n][i] <= max_weight){
            cout << i << endl;
            return 0;
        }
    }
    
    
    return 0;
    
}


Measured memory_bytes: 79488
#include<iostream>
using namespace std;
int main(void){
	
	int n,t,a[4][13]={0};
	char m;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>m>>t;
		switch(m){
			case 'S':
			a[0][t-1]=1;
			break;
			
			case 'H':
			a[1][t-1]=1;
			break;
			
			case 'C':
			a[2][t-1]=1;
			break;
			
			case 'D':
			a[3][t-1]=1;
			break;
			}
}		
		for(int i=0;i<4;i++){
			for(int j=0;j<13;j++){
				if(a[i][j]!=1){
					switch(i){
						case 0:
						cout<<"S"<<" "<<j+1<<endl;
						break;
			
						case 1:
						cout<<"H"<<" "<<j+1<<endl;
						break;
			
						case 2:
						cout<<"C"<<" "<<j+1<<endl;
						break;
			
						case 3:
						cout<<"D"<<" "<<j+1<<endl;
						break;
					}
				}
			}
		}
	return 0;	
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007

int main(){
  int h,w,k;
  cin >> h >> w >> k;
  vector<vector<int>> data(h);
  int last;
  rep(i,h){
    rep(j,w){
      char c;
      cin >> c;
      if(c == '#'){
        data.at(i).push_back(j);
        //cout << i << " " << j << endl;
        last = i;
      }
    }
  }
  int cake = 1;
  queue<int> que;
  vector<vector<int>> ans(h,vector<int>(w));
  rep(i,h){
    if(data.at(i).size() == 0){
      que.push(i);
    }else{
      int m = data.at(i).size();
      int id = 0;
      rep(j,w){
        ans.at(i).at(j) = cake;
        if(j == data.at(i).at(id)){
          if(j == data.at(i).at(m-1)) continue;
          id++;
          cake++;
        }
      }
      cake++;
      while(que.size()){
        int x = que.front();
        //cout << x << endl;
        que.pop();
        rep(j,w){
          ans.at(x).at(j) = ans.at(i).at(j);
        }
      }
    }
  }
  for(int i=last+1;i<h;i++){
    rep(j,w) ans.at(i).at(j) = ans.at(last).at(j);
  }
  rep(i,h){
    rep(j,w){
      cout << ans.at(i).at(j) << " ";
    }
    cout << endl;
  }
}


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

int main() {
int n,k;
cin >> n >> k;
long long cost[200000];
long long dp[200000];

for(int i=0;i<n;i++){
    cin >> cost[i];
    dp[i]=100000000000000;}
dp[0]=0;
for(int i=0;i<n;i++){
    for(int j=1;j<=k;j++){
        dp[i+j]=min(dp[i]+abs(cost[i+j]-cost[i]),dp[i+j]);
    }
}
cout << dp[n-1];
}


Measured memory_bytes: 3072
n = int(input())
k, *b = map(int, input().split())

m = 0
for i in b:
    m |= 1 << i
    
for i in range(2**n):
    if i & m != m:
        continue
    
    if i == 0:
        print("0:")
        continue
    else:
        print("{}: ".format(i), end="")
    l = []
    for j in range(n):
        if i & (1 << j) != 0:
            l.append(j)
    print(*l)
    


Measured memory_bytes: 6172
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;

int N;
char A[2005], B[2005];
int right[2005], left[2005];

int min(int a, int b){ return a < b ? a : b; }

int res = 1e9;

void perform(){
    
    for(int i=0; i<N; i++) left[i] = 0, right[i] = 0;
    
    int last = 1e9;
    for(int i=N-1; i>=0; i--){
        if(B[i] == '1') last = i;
        right[i] = last-i;
    }
    for(int i=N-1; i>=0; i--){
        if(B[i] == '1') break;
        right[i] = N+last-i;
    }
    
    last = -1e9;
    for(int i=0; i<N; i++){
        if(B[i] == '1') last = i;
        left[i] = i-last;
    }
    for(int i=0; i<N; i++){
        if(B[i] == '1') break;
        left[i] = N+i-last;
    }
    
    // shift to the left, right <= st is free
    for(int st=0; st<N; st++){
        priority_queue<pair<int, int>> pq;
        int mismatched = 0;
        for(int ind=0; ind<N; ind++){
            int loc = (st+ind)%N;
            if(A[loc] != B[ind]) mismatched++;
            else continue;
            if(right[ind] <= st) continue;
            pq.push({left[ind], right[ind]});
        }
        for(int sh=0; sh<N; sh++){
            while(!pq.empty()){
                int rr = pq.top().second;
                if(sh >= rr-st) pq.pop();
                else break;
            }
            int need = 0;
            if(!pq.empty()) need = pq.top().first;
            res = min(res, mismatched + st + 2*(need+sh));
        }
    }
    
}

int main(){
    scanf("%s%s", A, B);
    for(N=0; A[N]; N++);
    perform();
    reverse(A, A+N);
    reverse(B, B+N);
    perform();
    if(res > 1e6) printf("-1");
    else printf("%d", res);
    return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

inline void gc(int *x) {
    *x = 0;
    while (1) {
        int c = getchar_unlocked();
        if ('0' <= c && c <= '9') {
            *x = *x * 10 + c - '0';
        } else {
            break;
        }
    }
}

#define KMAX (1000)
int s[KMAX + 1][2 * KMAX + 1];
int main(void) {
    char c;
    int n, k, x, y;
    scanf("%d %d\n", &n, &k);
    for (int i = 0; i < n; i++) {
        gc(&x);
        gc(&y);
        c = getchar_unlocked();
        getchar_unlocked();
        y %= 2 * k;
        if (c == 'W') {
            if (y >= k) {
                y -= k;
            } else {
                x += k;
            }
        } else {
            if (y >= k) {
                y -= k;
                x += k;
            }
        }
        x %= 2 * k;
        s[y + 1][x + 1]++;
    }
    for (int y = 0; y < k; y++) {
        for (int x = 0; x < 2 * k; x++) {
            s[y + 1][x + 1] += s[y][x + 1] + s[y + 1][x] - s[y][x];
        }
    }
    int max = 0;
    int v = s[0][0] - s[0][2 * k];
    for (int y = 0; y < k; y++) {
        int u = v - s[y][0] + s[y][2 * k];
        for (int x = 0; x < k; x++) {
            int t = u - s[0][x] - s[k][x] + s[0][x + k] + s[k][x + k] +
                    2 * s[y][x] - 2 * s[y][x + k];
            t = t < n / 2 ? n - t : t;
            max = t > max ? t : max;
        }
    }
    printf("%d", max);
    return 0;
}


Measured memory_bytes: 7936
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;

using ll=long long;

template <typename T>
T in(){
    T x;
    cin >> x;
    return x;
}

template <typename T,typename U>
void forin(T* x,U n){
    for (U i=0;i<n;i++) cin >> x[i];
}

template <typename T>
int div1(T x) {
    return x%1000000007;
}

main(){
    int x=in<int>();
    bool so=false;
    int i;
    for (i=x;!so;i++){
        so=true;
        for (int i2=2;i2<sqrt(i);i2++){
            if (i%i2==0) {
                so=false;
                break;
            }
        }
        if (so) break;
    }
    cout << i << endl;
}

Measured memory_bytes: 256
while 1:
    a, b = map(int, input().split())
    if a == 0:
        break
    r = [[1 for i in range(a+b-1)] for j in range(a+b-1)]
    n = int(input())
    for i in range(n):
        x, y = map(int, input().split())
        r[x-1][y-1] = 0
    for i in range(1, a+b-1):
        for j in range(i+1):
            if r[j][i-j] == 0:
                continue
            elif j == 0:
                if r[0][i-j-1] == 0:
                    r[j][i - j] = 0
            elif i-j == 0:
                if r[j-1][0] == 0:
                    r[j][i - j] = 0
            else:
                r[j][i-j] = r[j-1][i-j] + r[j][i-j-1]
    print(r[a-1][b-1])


Measured memory_bytes: 5608
n = int(input())
s = input()
migi = s.count(".")
hidari = 0
ans = migi
for i in range(n):
    if s[i] == "#":
        hidari += 1
    elif s[i] == ".":
        migi -= 1
    ans = min(ans,hidari+migi)
print(ans)

Measured memory_bytes: 3500
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <iostream>
#include <queue>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
#define INFTY 1 << 21

int main() {
  int A, B;
  cin >> A >> B;
  if ((A + B) % 2 == 0) cout << (A + B) / 2 << endl;
  else
    cout << "IMPOSSIBLE" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <queue>
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#define debug(x) cerr<<#x<<'='<<x<<endl
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
template<typename T> void read(T &x){
	x = 0;char ch = getchar();int f = 1;
	while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
	while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}

char x[20];
int main() {
	cin>>x;
	int cnt = 0;
	for(int i=0;i<20;i++){
		if(x[i] == 'x')cnt++;
	}
	if(cnt>7){
		cout<<"NO"<<endl;
	}else{
		cout<<"YES"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;

int h, w;
char mp[111][111];
 
int main(){
  ios_base::sync_with_stdio(false);

  cin >> h >> w;
  for(int i=0;i<h;i++){
    cin >> mp[i];
  }

  for(int i=0;i<h;i++){
    cout << mp[i] << endl;
    cout << mp[i] << endl;
  }
 
  return 0;
}



Measured memory_bytes: 256
import java.util.*;

import static java.lang.System.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long K = sc.nextLong();

        Map<Integer, Long> map = new TreeMap<>();
        for (int i = 0; i < N; i++) {
            int a = sc.nextInt();
            long b = sc.nextInt();

            if (map.containsKey(a)) {
                b += map.get(a);
            }

            map.put(a, b);
        }

        for (Map.Entry entry : map.entrySet()) {
            K -= (long) entry.getValue();
            if (K <= 0) {
                out.print(entry.getKey());
                return;
            }
        }
    }
}

Measured memory_bytes: 89244
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 

vector<pair<char, int>> ans;
  
int32_t main()
{
    fast;
    string a, b; cin >> a >> b;
    if(a.size() > b.size()) {
        cout << "GREATER";
        return 0;
    }
    else if(a.size() < b.size()) {
        cout << "LESS";
        return 0;
    }
    else {
        For(i, 0, a.size()) {
            if(a[i] > b[i]) {
                cout << "GREATER";
                return 0;
            }
            else if(a[i] < b[i]) {
                cout << "LESS";
                return 0;
            }
        }
    }
    cout << "EQUAL";
    
    return 0;
}

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

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

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

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        p: u8,
        q: u8,
        r: u8,
    }
    // 3! = 6通り計算して最小の値を出すのも正しいが、
    // 条件から3つの経路のうち最小値と2番目の値の和が最小値になる。
    let mut v = vec![p, q, r];
    v.sort();
    let s: u8 = v.iter().take(2).sum();
    println!("{}", s);
}


Measured memory_bytes: 4352
#include<stdio.h>
main()
{
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	while(1)
	{
		c=c-b;
		if(c<=0)
		{
			printf("Yes");
			break;
		}
		a=a-d;
		if(a<=0)
		{
			printf("No");
			break;
		}
	}
}

Measured memory_bytes: 2136
#include <stdio.h>

int main() {
  int number, i, max_value = 0;
  scanf("%d", &number);
  int jewelry_cost[number+1];
  int jewelry_value[number+1];
  int jewelry_true_value[number+1];
  for(i = 0; i < number; i++) {
    scanf("%d", &jewelry_value[i]);
  }
  for(i = 0; i < number; i++) {
    scanf("%d", &jewelry_cost[i]);
  }
  for(i = 0; i < number; i++) {
    jewelry_true_value[i] = jewelry_value[i] - jewelry_cost[i];
    if(jewelry_true_value[i] > 0) {
      max_value += jewelry_true_value[i];
    }
  }
  printf("%d\n", max_value);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

template<class T>
struct Vec2
{
	Vec2(){}
	Vec2(T _x, T _y) : x(_x), y(_y) {}

	Vec2 operator+(const Vec2& rhs) const { return Vec2(x + rhs.x, y + rhs.y); }
	Vec2 operator-(const Vec2& rhs) const { return Vec2(x - rhs.x, y - rhs.y); }
	Vec2 operator*(T s) const { return Vec2(x*s, y*s); }
	Vec2 operator/(T s) const { return Vec2(x/s, y/s); }
	T dot(const Vec2& rhs) const { return x*rhs.x + y*rhs.y; }
	T cross(const Vec2& rhs) const { return x*rhs.y - y*rhs.x; }
	T sqlength() const { return x*x + y*y; }
	double length() const { return sqrt(sqlength()); }
	bool operator<(const Vec2& rhs) const
	{
		if (x != rhs.x) return x < rhs.x;
		return y < rhs.y;
	}

	T x;
	T y;
};

template<class T>
T cross(const Vec2<T> &O, const Vec2<T> &A, const Vec2<T> &B)
{
	return (A - O).cross(B - O);
}

template<class T>
bool IsIntSegments(const Vec2<T>& A1, const Vec2<T>& A2, const Vec2<T>& B1, const Vec2<T>& B2)
{
	return (cross(A1, A2, B1)*cross(A1, A2, B2) <= 0 && cross(B1, B2, A1)*cross(B1, B2, A2) <= 0);
}

template<class T>
bool IsPointOnSegment(const Vec2<T>& P, const Vec2<T>& S, const Vec2<T>& E)
{
	Vec2<T> dir = E - S;
	if ((P - S).cross(dir) != 0) {
		return false;
	}
	T prd = (P - S).dot(dir);
	if (prd < 0) {
		return false;
	}
	return prd <= dir.dot(dir);
}

static unsigned int Rand()
{
	static unsigned int r = 123456789;
	r = r ^ (r << 13);
	r = r ^ (r >> 17);
	r = r ^ (r << 5);
	return r;
}

template<class T>
int CheckPolyInclude(const vector<Vec2<T> >& poly, Vec2<T> P)
{
	for (size_t i = 0; i < poly.size() - 1; i++) {
		if (IsPointOnSegment(P, poly[i], poly[i+1]) ) {
			return 1;
		}
	}

	Vec2<T> O;
	while (1) {
		bool ok = true;
		O = Vec2<T>(10000 + Rand() % 10000, Rand() % 10000);
		for (size_t i = 0; i < poly.size() - 1; i++) {
			if (IsPointOnSegment(poly[i], P, O)) {
				ok = false;
				break;
			}
		}
		if (ok) {
			size_t num = 0;
			for (size_t i = 0; i < poly.size() - 1; i++) {
				if (IsIntSegments(P, O, poly[i], poly[i + 1])) {
					num++;
				}
			}
			return num % 2 * 2;
		}
	}
}

int main()
{
	typedef Vec2<long long> Vec;

	int n, q;
	cin >> n;
	vector<Vec> poly(n + 1);
	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		poly[i] = Vec(x, y);
	}
	poly.back() = poly.front();

	cin >> q;
	for (int i = 0; i < q; i++) {
		int x, y;
		cin >> x >> y;
		cout << CheckPolyInclude(poly, Vec(x, y)) << endl;
	}
	return 0;
}


Measured memory_bytes: 3116
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXH=100;
const int MAXW=100;
const int MAXDIM=100;
const int MAXVAL=100;

int h,w,mxval,mod;
void inc(int &a,int b) { if((a+=b)>=mod) a-=mod; }

// dp[nrow][ncol] = # ways of:
// * choosing nrow rows and ncol cols in the grid
// * fixing the values of the intersection of those columns and rows, such that each column has at least one cell < curvalue
// * fixing the contribution for each cell in the union of those columns, such that each of those cells has a valid contribution < curvalue
// tdp[nrow][ncol] = similar to dp[nrow][ncol], but now the contribution can be <= curvalue
int dp[MAXH+1][MAXW+1]; 
int tdp[MAXH+1][MAXW+1];

int pw[MAXVAL+1][MAXW+1];
int choose[MAXDIM+1][MAXDIM+1];

int solve() {
	REPE(val,mxval) { pw[val][0]=1; FORE(y,1,max(h,w)) pw[val][y]=(ll)pw[val][y-1]*val%mod; }
	REPE(i,MAXDIM) { choose[i][0]=choose[i][i]=1; FOR(j,1,i) choose[i][j]=(choose[i-1][j-1]+choose[i-1][j])%mod; }

	REPE(x,h) REPE(y,w) dp[x][y]=x==0&&y==0?1:0;
	FORE(val,1,mxval) {
		REPE(x,h) REPE(y,w) tdp[x][y]=0;
		REPE(x,h) REPE(y,w) {
			int eachrowcontrib=pw[val][w-y]-pw[val-1][w-y]; if(eachrowcontrib<0) eachrowcontrib+=mod;
			int eachrowvalue=pw[mxval-val+1][y];
			int cur=dp[x][y],mlt=(ll)eachrowcontrib*eachrowvalue%mod;
			REPE(dx,h-x) {
				int now=(ll)choose[h-x][dx]*cur%mod;
				inc(tdp[x+dx][y],now);
				cur=(ll)cur*mlt%mod;
			}
		}
		//printf("tdp after %d:\n",val); REPE(x,h) { REPE(y,w) { if(y!=0) printf(" "); printf("%d",tdp[x][y]); } puts(""); }
		REPE(x,h) REPE(y,w) dp[x][y]=0;
		REPE(x,h) REPE(y,w) {
			int eachcolcontrib=pw[val][h-x];
			int eachcolvalue=pw[mxval-val+1][x]-pw[mxval-val][x]; if(eachcolvalue<0) eachcolvalue+=mod;
			int cur=tdp[x][y],mlt=(ll)eachcolcontrib*eachcolvalue%mod;
			REPE(dy,w-y) {
				int now=(ll)choose[w-y][dy]*cur%mod;
				inc(dp[x][y+dy],now);
				cur=(ll)cur*mlt%mod;
			}
		}
		//printf("dp after %d:\n",val); REPE(x,h) { REPE(y,w) { if(y!=0) printf(" "); printf("%d",dp[x][y]); } puts(""); }
	}
	return dp[h][w];
}

void run() {
	scanf("%d%d%d%d",&h,&w,&mxval,&mod);
	printf("%d\n",solve());
}

int main() {
	run();
	return 0;
}


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

using namespace std;

const int NMAX = 100005;

int v[NMAX], sorted[NMAX], s[NMAX], n;
ll aint[8 * NMAX];

void update(int toadd, int pos, int node, int le, int ri) {
    if(le == ri)
        aint[node] += toadd;
    else {
        int mid = (le + ri) / 2;
        if(pos <= mid)
            update(toadd, pos, node * 2, le, mid);
        else
            update(toadd, pos, node * 2 + 1, mid + 1, ri);
        aint[node] = aint[node * 2] + aint[node * 2 + 1];
    }
}

ll query(int from, int to, int node, int le, int ri) {
    if(from <= le && ri <= to)
        return aint[node];
    int mid = (le + ri) / 2;
    ll ans = 0;
    if(from <= mid)
        ans += query(from, to, node * 2, le, mid);
    if(mid < to)
        ans += query(from, to, node * 2 + 1, mid + 1, ri);
    return ans;
}

ll check(int val) {
    for(int i = 1; i <= n; i ++) {
        if(v[i] <= val)
            s[i] = -1;
        else
            s[i] = 1;
        s[i] += s[i - 1];
    }
    ll ans = 0;

    for(int i = 1; i <= n; i ++) {
        update(1, s[i] + n, 1, 0, 2 * n);
        ans += query(s[i] + n + 1, 2 * n, 1, 0,  2 * n);
        if(s[i] < 0)
            ans ++;
    }
    for(int i = 1; i <= n; i ++)
        update(-1, s[i] + n, 1, 0, 2 * n);

    return ans;
}

int main() {
   // freopen("a.in", "r", stdin);
 //  freopen("a.out", "w", stdout);

    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> n;
    for(int i = 1; i <= n; i ++) {
        cin >> v[i];
        sorted[i] = v[i];
    }
    sort(sorted + 1, sorted + n + 1);
    int ans = 0;
    ll m = 1LL * n * (n + 1) / 2;
    for(int step = (1 << 17); step; step >>= 1)
        if(ans + step <=  n && check(sorted[ans + step]) < (m / 2 + 1))
            ans += step;
    cout << sorted[ans + 1];

    return 0;
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2 //1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) fixed<<setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) max(x,y)-min(x,y)
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int, int>;
typedef vector<int> vit;

//最大公約数
lol gcd(lol x, lol y){
  if(x < y) swap(x, y);
  lol r = x % y;
  while(r != 0){
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}

//最小公倍数
lol lcm(lol x, lol y){
  lol a = x * y;
  return (a / gcd(x, y));
}

signed main(void){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  map<lol, lol> ans;
  int a[n + 5];
  lol sum = 0;
  rep(i, n){
    cin >> a[i];
    ans[a[i]] ++;
    sum += a[i];
  }
  int q, b, c;
  //  cout << sum << '\n';
  cin >> q;
  rep(i, q){
    cin >> b >> c;
    sum -= (lol)(b * ans[b]);
    sum += (lol)(ans[b] * c);
    ans[c] += ans[b];
    ans[b] = 0;
    cout << sum << '\n';
  }
  return 0;
}


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

// clang-format off
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
// clang-format on

// vector<vector<int>> r;
int r[2001][2001];
int n, k, ans;

inline int sum(int y, int x, int Y, int X) {
  return (r[Y][X] - r[Y][x] - r[y][X] + r[y][x]);
}

inline int query(int y, int x) {
  return sum(0, 0, y, x) + sum(y, x, y + k, x + k) + sum(y + k, x + k, 2 * k, 2 * k) + sum(0, x + k, y, 2 * k) +
         sum(y + k, 0, 2 * k, x);
}

int main() {
  cin >> n >> k;
  // r.assign(2 * k + 1, vector<int>(2 * k + 1, 0));
  for (int i = 0; i < n; ++i) {
    int x, y;
    char c;
    cin >> x >> y >> c;
    if (c == 'W') x += k;
    x %= 2 * k;
    y %= 2 * k;
    r[y + 1][x + 1]++;
  }

  rep(i, 2 * k) rep(j, 2 * k) r[i + 1][j + 1] += r[i + 1][j] + r[i][j + 1] - r[i][j];
  rep(i, k) rep(j, k) chmax(ans, max(query(i, j), n - query(i, j)));

  cout << ans << endl;
}


Measured memory_bytes: 15872
from fractions import gcd

N,M = map(int, input().split())
S = input()
T = input()
L = N*M//gcd(N,M)
n = L//N
m = L//M
f = True
for i in range(N):
  if (i*n)%m == 0:
    if S[i] != T[(i*n)//m]:
      f = False
      break
print(L if f else -1)


Measured memory_bytes: 5564
# include <iostream>
# include <sstream>
# include <cstdio>
# include <cstdlib>
# include <algorithm>
# include <string>
# include <cstring>
# include <cmath>
# include <stack>
# include <queue>
# include <vector>
# include <list>
# include <map>
# include <set>
# include <deque>
# include <iterator>
# include <functional>
# include <bitset>
# include <climits>
# include <ctime>
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define odd(x) (x&1)
typedef long long ll;
typedef long double ld;
const ll oo = 2 * 1000 * 1000 * 1000;
const int _cnt = 1000 * 1000;
const int _p = 1000 * 1000 * 1000 + 7;
ll o(ll x) { return x%_p; }
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; }
using namespace std;

void file_put() {
	freopen("filename.in", "r", stdin);
	freopen("filename.out", "w", stdout);
}

struct point {
	int x, y;
};

ll dist(point p, point q) {
	return (ll)abs(p.x - q.x)+(ll)abs(p.y - q.y);
}

int n, m, ans[100005];
point p[55], q[55];
ll minnum = oo*oo;

int main() {
	//file_put();

	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++) scanf("%d%d", &p[i].x, &p[i].y);
	for (int i = 1; i <= m; i++) scanf("%d%d", &q[i].x, &q[i].y);
	for (int i = 1; i <= n; i++) {
		minnum = oo*oo;
		for (int j = 1; j <= m; j++) {
			if (dist(p[i], q[j]) >= minnum) continue;
			minnum = dist(p[i], q[j]);
			ans[i] = j;
		}
	}
	for (int i = 1; i <= n; i++) printf("%d\n", ans[i]);

	return 0;
}


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

int N, W;

// dp[i][v] := i番目まで見て、価値vを達成できる最小の重さ
long long dp[101][110000];

int main(){
    cin >> N >> W;

    for(int j = 1; j <= 100000; j++){
        dp[0][j] = 1e15;
    }
    for(int i = 1; i <= N; i++){
        int w, v;
        cin >> w >> v;

        for(int j = 0; j <= 100000; j++){
            dp[i][j] = 1e15;
        }
        for(int j = 100000; j >= 0; j--){
            dp[i][j] = dp[i - 1][j];
            if(j < 100000){
                dp[i][j] = min(dp[i][j], dp[i][j + 1]);
            }
            if(j - v >= 0){
                dp[i][j] = min(dp[i][j], dp[i - 1][j - v] + w);
            }
        }
    }

    int ans = 0;
    for(int j = 0; j <= 100000; j++){
        if(dp[N][j] <= W){
            ans = j;
        }
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 86784
// AOJ 2870 The Diversity of Prime Factorization
// 2018.3.29 bal4u

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

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0, c = getchar_unlocked();
	do n = 10*n + (c & 0xf), c = getchar_unlocked(); while (c >= '0');
	return n;
}

#define MAX  1000005
#define SQRT 1000	     // sqrt(MAX)
char prime[MAX+3];       // prime table

int tbl[168] = {
     2,      3,      5,      7,     11,     13,     17,     19,     23,     29, 
    31,     37,     41,     43,     47,     53,     59,     61,     67,     71, 
    73,     79,     83,     89,     97,    101,    103,    107,    109,    113, 
   127,    131,    137,    139,    149,    151,    157,    163,    167,    173, 
   179,    181,    191,    193,    197,    199,    211,    223,    227,    229, 
   233,    239,    241,    251,    257,    263,    269,    271,    277,    281, 
   283,    293,    307,    311,    313,    317,    331,    337,    347,    349, 
   353,    359,    367,    373,    379,    383,    389,    397,    401,    409, 
   419,    421,    431,    433,    439,    443,    449,    457,    461,    463, 
   467,    479,    487,    491,    499,    503,    509,    521,    523,    541, 
   547,    557,    563,    569,    571,    577,    587,    593,    599,    601, 
   607,    613,    617,    619,    631,    641,    643,    647,    653,    659, 
   661,    673,    677,    683,    691,    701,    709,    719,    727,    733, 
   739,    743,    751,    757,    761,    769,    773,    787,    797,    809, 
   811,    821,    823,    827,    829,    839,    853,    857,    859,    863, 
   877,    881,    883,    887,    907,    911,    919,    929,    937,    941, 
   947,    953,    967,    971,    977,    983,    991,    997 };

void primetbl()
{
	int i, j, k;
	memset(prime+2, 1, 1000003);
	for (i = 4; i < MAX; i += 2) prime[i] = 0;
	for (k = 1; k < 168; k++) {
		i = tbl[k];
		for (j = i*i; j <= MAX; j += i) prime[j] = 0;  // j = i*i !!!!!
	}
}

#define M 1000000007
int  q[100005];
int dp[100005];

int main()
{
	int N, i;

	primetbl();

	N = in();
	for (i = 0; i < N; i++) q[i] = in();
	q[N] = 1000003;

	dp[0] = 1;
	for (i = 0; i < N; i++) if (prime[q[i]]) {
		if (prime[q[i+1]] && q[i] < q[i+1]) {
			dp[i+1] += dp[i]; if (dp[i+1] >= M) dp[i+1] -= M;
		}
		if (prime[q[i+2]] && q[i] < q[i+2]) {
			dp[i+2] += dp[i]; if (dp[i+2] >= M) dp[i+1] -= M;
		}
	}
	printf("%d\n", dp[N]);
	return 0;
}


Measured memory_bytes: 3556
package main

import (
	"fmt"
	"regexp"
)

func main() {
	var S, T string
	fmt.Scan(&S, &T)
	S = replaceAll(S, "?", ".")
	for i := len(S) - 1; i >= len(T) - 1; i-- {
		start, end := i + 1 - len(T), i + 1
		h, s, t := S[:start], S[start:end], S[end:]
		b, _ := regexp.Match(s, []byte(T))
		if b {
			tmp := h + T + t
			fmt.Println(replaceAll(tmp, ".", "a"))
			return
		}
	}
	fmt.Println("UNRESTORABLE")
}

func replaceAll(target, old, new string) string {
	result := ""
	for _, i := range target {
		s := string(i)
		if s == old {
			result += new
		} else {
			result += s
		}
	}
	return result
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define all(x) (x).begin(),(x).end()
int INF = 100000000;

int main() {
  string divide[4] = {"dream", "dreamer", "erase", "eraser"};
  string S; cin >> S;
  queue<int> BFS;
  bool flag = false;
  
  BFS.push(0);
  while(!BFS.empty()) {
    int t = BFS.front();
    BFS.pop();
    if (t == S.size()) {
      flag = true;
      break;
    }
    for (string s : divide) {
      if (S.substr(t, s.size()) == s) {
        BFS.push(t + s.size());
      }
    }
  }
  if (flag) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
    using namespace std;
  #define int long long int
    #define endl "\n"
    #define MOD 1000000007
    #define mod 1000000007
    #define M 1000000007
    
    #define pb push_back
    #define take(a,b,c) for(int b=0;b<c;b++) cin>>a[b]
  //  #define mp make_pair
  #define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);  
  #define mx 400005
  #define fiint(a,b) memset(a,b,sizeof(a))  
  #define bitcount __builtin_popcount
  #define fori(i,a,b) for(int i=a;i<b;i++)
  #define ford(i,a,b) for(int i=a;i>=b;i--)
  #define debug(x) cout<<x<<endl;
  #define cases(t) int t; cin>>t; while(t--)
  #define inf1 INT_MAX
  #define all(a) a.begin(),a.end()
  #define vec vector<int>
  #define pii pair<int,int>
  #define plii pair<int,int>
  #define pint pair<int,int>
  #define ff first
  #define ss second
  #define lb lower_bound
  #define ub upper_bound
  #define bs binary_search
  #define sz(x) (int)x.size()
#define PI                    3.14159265359

bool prime[10000001];

void sieveFunction(int maxLimit){
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1]=false;
    for(int i=2; maxLimit >= i ; i++){
        if(prime[i]){
            for(int j=2*i ; maxLimit >= j ; j+=i)
                prime[j]=false;
        }
    }
}

vec adj[mx];
int n,m;
vec in_de(mx + 1);
int vis[mx];
vec dis( mx + 1);
void  dfs(int v)
{
	vis[ v ] = 1;
	for(auto it : adj[v])
	{
		dis[it] = max( dis[it] , dis[v]+1);
		--in_de[it]; 
		if (  in_de[it] == 0  && vis [it] != 1)
			dfs(it);
	}

}

signed  main() 
{ 
	cin>>n>>m;
	fori(i,0,m)
	{int u,v;cin>>u>>v; adj[u].pb(v); in_de[v]++; }
			

		fori(i,1,n+1)
			if(vis[i]==0 && in_de[i] == 0)
				dfs(i);
		int ans=0;		
		fori(i,1,n+1)
		ans = max( ans , dis[i]   );
		cout<<ans<<endl;
		//fori(j,0,n)

	
	
		
	
}




 


Measured memory_bytes: 25856
#include <iostream>

using namespace std;

int main ()
{
        char w[101];
        int c[26] = { 0 };
        cin >> w;
        int b = (int)'a';
        int e = (int)'z';
        for (int i = 0; w[i] != '\0'; i++) {
                c[e - (int)w[i]]++;
        }
        for (int i = 0; i < 26; i++) {
                if (c[i] % 2 != 0) {
                        cout << "No" << endl;
                        return 0;
                }
        }
        cout << "Yes" << endl;
        return 0;
}


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

signed main(){
    // cout << fixed << setprecision(10) << flush;

    int n;
    cin >> n;
    vector<int> a(n), b(n);
    vector<int> numa(n+1, 0), numb(n+1, 0);
    for(int i=0; i<n; i++){
        cin >> a[i];
        numa[a[i]]++;
    }
    for(int i=0; i<n; i++){
        cin >> b[i];
        numb[b[i]]++;
    }
    reverse(b.begin(), b.end());

    int l = 0;
    for(int i=0; i<n; i++){
        if(a[i] == b[i]){
            if(numa[a[i]] + numb[b[i]] > n){
                cout << "No" << endl;
                return 0;
            }
            while(a[i] == a[l] || a[i] == b[l]) l++;
            swap(b[i], b[l]);
            l++;
        }
    }
    cout << "Yes" << endl;
    for(int i=0; i<n-1; i++){
        cout << b[i] << " ";
    }
    cout << b[n-1] << endl;

    return 0;
}

Measured memory_bytes: 9576
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll int64_t
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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; }


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

struct Point{double x,y;};

void koch(int n, Point a, Point b){
    if(n==0) return;
    Point s, t, u;
    double th = M_PI * 60.0 / 180.0;

    s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
    s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
    t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
    t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
    u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

    koch(n-1, a, s);
    printf("%.8f %.8f\n",s.x, s.y);
    koch(n-1, s, u);
    printf("%.8f %.8f\n",u.x, u.y);
    koch(n-1, u, t);
    printf("%.8f %.8f\n",t.x, t.y);
    koch(n-1, t, b);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    Point a,b;
    int n;
    cin>>n;

    a.x=0;
    a.y=0;
    b.x=100;
    b.y=0;
    printf("%.8f %.8f\n",a.x, a.y);
    koch(n, a, b);
    printf("%.8f %.8f\n",b.x, b.y);
}


Measured memory_bytes: 3152
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	//予備
	n := iScan()
	l := make([]int, n)
	for i := 0; i < n; i++ {
		l[i] = iScan()
	}
	if n < 3 {
		fmt.Println(0)
		return
	}
	sort.Slice(l, func(i int, j int) bool {
		return l[i] < l[j]
	})
	//fmt.Println(l)
	ans := 0
	for i := 0; i < n-2; i++ {
		for j := i + 1; j < n-1; j++ {
			for r := j + 1; r < n; r++ {
				if l[i] == l[r] || l[i] == l[j] || l[j] == l[r] {
					continue
				}
				if l[i]+l[j] > l[r] {
					ans++
					//fmt.Println(l[i], l[j], l[r])
				}
			}
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 1776
import math

n, m = map(int, input().split())
if abs(n - m) == 0:
    ans = math.factorial(n) ** 2 * 2
elif abs(n - m) == 1:
    ans = math.factorial(n) * math.factorial(m)
else:
    ans = 0
print(ans % (10 ** 9 + 7))

Measured memory_bytes: 5172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(var, begin, end) for (int var = (begin); var <= (end); var++)
#define RFOR(var, begin, end) for (int var = (begin); var >= (end); var--)
#define REP(var, length) FOR(var, 0, length - 1)
#define RREP(var, length) RFOR(var, length - 1, 0)
#define EACH(value, var) for (auto value : var)
#define SORT(var) sort(var.begin(), var.end())
#define REVERSE(var) reverse(var.begin(), var.end())
#define RSORT(var) SORT(var); REVERSE(var)
#define OPTIMIZE_STDIO ios::sync_with_stdio(false);cin.tie(0);cout.precision(10);cout << fixed
#define endl '\n'

const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
struct mint {
    ll x;
    mint() : x(0) {}
    mint(ll x) : x((x % MOD + MOD) % MOD) {}
    mint& operator+=(const mint& r) { if ((x += r.x) >= MOD) { x -= MOD; } return *this; }
    mint& operator-=(const mint& r) { if ((x -= r.x) < 0) { x += MOD; } return *this; }
    mint& operator*=(const mint& r) { if ((x *= r.x) > MOD) { x %= MOD; } return *this; }
    mint& operator++() { if ((++x) >= MOD) { x -= MOD; } return *this; }
    mint operator++(int) { mint ret = x; if ((++x) >= MOD) { x-= MOD; } return ret; }
    mint& operator--() { if ((--x) < 0) { x += MOD; } return *this; }
    mint operator--(int) { mint ret = x; if ((--x) < 0) { x += MOD; } return ret; }
    mint operator+(const mint& r) { mint ret; return ret = x + r.x; }
    mint operator-(const mint& r) { mint ret; return ret = x - r.x; }
    mint operator*(const mint& r) { mint ret; return ret = x * r.x; }
    mint operator-() { return mint() - *this; }
    bool operator<(const mint& a) { return x < a.x; }
    bool operator>(const mint& a) { return x > a.x; }
    bool operator<=(const mint& a) { return x <= a.x; }
    bool operator>=(const mint& a) { return x >= a.x; }
    bool operator==(const mint& a) { return x == a.x; }
    bool operator!=(const mint& a) { return x != a.x; }
};
ostream& operator<<(ostream& os, const mint& r) { os << r.x; return os; }
ostream& operator>>(ostream& os, const mint& r) { os >> r.x; return os; }

void solve(istream& cin, ostream& cout) {
  int N;
  cin >> N;
  int ans = pow(N, 3);
  cout << ans << endl;
}

#ifndef TEST
int main() {
  OPTIMIZE_STDIO;
  solve(cin, cout);
}
#endif


Measured memory_bytes: 384
#editorial参照
#再帰

m,y = map(int, input().split( ))
a = [1]
p = [1]
#あらかじめ作っておく
for i in range(m):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)
#場合分け、境界値

#入力と変数を一致させたが問題なかった
def f(m,y):#n,xにしないだけでバグる
    if m==0:
        return 0 if y<=0 else 1
    elif y <= 1+a[m-1]:
        return f(m-1,y-1)
    else:
        return p[m-1] + 1 + f(m-1, y-2 -a[m-1])

print(f(m,y))

Measured memory_bytes: 38384
n = int(input())

a_l = []
b_l = []
for _ in range(n):
    _a, _b = map(int, input().split())
    a_l.append(_a)
    b_l.append(_b)

#%%
cnt = 0
for a, b in zip(a_l[::-1], b_l[::-1]):
    m = (a + cnt) % b
    if m == 0:
        continue
    else:
        cnt += b - m

print(cnt)


Measured memory_bytes: 58200