akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cstring>
#include <cassert>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif


#ifdef L_JUDGE
#pragma warning(disable:4996)
#endif

using namespace std;

template <typename T>
inline bool read(T& ret) {
    T x = 0, f = 1; char ch = getchar();
    while(ch!=EOF && (ch > '9' || ch < '0')) { if(ch == '-') f = -1; ch = getchar();  }
    if(EOF==ch)return false;
    do x = x * 10 + ch - 48, ch = getchar(); while(ch >= '0' && ch <= '9');
    ret = x * f;
    return true;
}


inline char nc() {
    static char buf[100000], *p1 = buf, *p2 = buf;
    return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++;
}
template <typename T>
bool rn(T& v) {
    static char ch;
    while (ch != EOF && !isdigit(ch)) ch = nc();
    if (ch == EOF) return false;
    for (v = 0; isdigit(ch); ch = nc())
        v = v * 10 + ch - '0';
    return true;
}

template <typename T>
void o(T p) {
    static int stk[70], tp;
    if (p == 0) { putchar('0'); return; }
    if (p < 0) { p = -p; putchar('-'); }
    while (p) stk[++tp] = p % 10, p /= 10;
    while (tp) putchar(stk[tp--] + '0');
}


LL bin(LL x, LL n, LL MOD) {
    LL ret = MOD != 1;
    for (x %= MOD; n; n >>= 1, x = x * x % MOD)
        if (n & 1) ret = ret * x % MOD;
    return ret;
}
inline LL get_inv(LL x, LL p) { return bin(x, p - 2, p); }



void Solve(){
}

int A[200010];

int main(){
#ifdef L_JUDGE
    freopen("in1.txt","r",stdin);
    //		freopen("out.txt","w",stdout);
#endif
    //std::ios::sync_with_stdio(false);
    //std::cin.tie(0);
    int N;
    while(cin>>N){
        long long ans=0;
        for(int i=0;i<N;i++){
            cin>>A[i];
        }
        int pre=A[0];
        for(int i=1;i<N;i++){
            if(A[i]>=pre){
                pre=A[i];
            }else{
                ans+=(pre-A[i]);
            }
        }
        cout<<ans<<endl;

    }
    return 0;

#ifdef L_JUDGE
    fclose(stdin);
    fclose(stdout);
    //		system("out.txt");
#endif

	return 0;
}


Measured memory_bytes: 3936
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		
		String ans ="No";
		for (int i = 0; i < s.length(); i++) {
			String a = "";
			for (int j = 0; j < s.length(); j++) {
				if (j == s.length() - 1) {
					a = s.substring(j, j + 1) + a;
				} else {
					a += s.substring(j, j + 1);
				}
			}
			if (a.equals(t)) {
				ans = "Yes";
				break;
			}
			s = a;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 27860
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
	int h,w,h1,w1,s;
	scanf("%d %d",&h,&w);
	scanf("%d %d",&h1,&w1);
	s=(h-h1)*(w-w1);
	printf("%d\n",s);
	return 0;
}

Measured memory_bytes: 128
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FAST            ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll              long long
#define ld              long double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define all(a)          (a).begin(),(a).end()
#define clz(a)          __builtin_clz(a) // count leading zeroes
#define ctz(a)          __builtin_ctz(a) // count trailing zeroes
#define popc(a)         __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define lul             1000000007
#define rep(i,a,b)      for(int i=a;i<b;i++)
#define rfor(i,a,b)     for(int i=a; i>=b; i--)
#define debug(x)        cerr << #x << " = " << x << endl;
#define F               first
#define S               second
#define lul2            998244353 
#define pll             pair<ll,ll>
#define endl            '\n'
#define SIZE            1000005
#define deci(n)         cout<<fixed<<setprecision(n)
#define ordered_set     tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k)
// find_by_order(k)
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;

void mod(ll &x)
{
    if(x>=lul) x-=lul;
    if(x<0) x+=lul;
}

int n;
void compstr(string s, char chck)
{
    if(s.size() == n)
    {
        cout<<s<<endl;
        s.pop_back();
        return;
    }
    else{
        rep(i,0,chck-'a'+2)
        {
            char x = i+'a';
            s+=x;
            compstr(s, max(chck,x));
            s.pop_back();
        }
    } 
}
void solve()
{
    cin>>n;
    compstr("a",'a');
}
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; /*cin>>t;*/ t=1;
    rep(i,1,t+1){
        solve();
    }
    return 0;
}

Measured memory_bytes: 1536
import sys
input = sys.stdin.readline
k, a, b = map(int, input().split())

# ずっと叩いたほうがいい場合
# bの方がaより小さかったら交換する意味がない
# aがb-1の場合、2回で1枚増えるより叩いて2回で2枚増えた方がお得
# a - 1回叩いてaになった時点で2回残ってないと交換できない
# 2回ないと交換できない
if a >= b or a == b - 1 or k < (a - 1) + 2 or k == 1:
    print(1 + k)
    exit(0)
# 叩いてa枚にする
k -= (a - 1)
ans = a
# ひたすら交換する
ans += (b - a) * (k // 2)
ans += k % 2
print(ans)


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 100;
ll f[maxn], inv[maxn];

ll powmod(ll a, ll b) {
    ll ret = 1;
    while (b) {
        if (b & 1) ret = ret * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return ret;
}

void init() {
    f[0] = 1;
    for (int i = 1; i < maxn; i++) {
        f[i] = f[i - 1] * i % mod;
    }
    inv[maxn - 1] = powmod(f[maxn - 1], mod - 2);
    for (int i = maxn - 2; i >= 1; i--) {
        inv[i] = inv[i + 1] * (i + 1) % mod;
    }
}

ll C(int n, int m) {
    if (n == m) return 1;
    return f[n] * inv[m] % mod * inv[n - m] % mod;
}

ll cnt[maxn];
int tot;

int main() {

    init();
    ll n, m;
    scanf("%lld %lld", &n, &m);

    int sum = 0;
    for (int i = 2; i * i <= m; i++) {
        if (m % i) continue;
        sum = 0;
        while (m % i == 0) {
            sum++;
            m /= i;
        }
        cnt[++tot] = sum;
    }
    if (m != 1) cnt[++tot] = 1;
    ll ans = 1;
    for (int i = 1; i <= tot; i++) {
        ans = ans * C(n - 1 + cnt[i], cnt[i]) % mod;
    }
    ans = (ans % mod + mod) % mod;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 3328
from math import sqrt
a, b = (int(i) for i in input().split())

GCD = lambda x, y: (GCD(y, x % y) if x % y else y)
ab_gcd = GCD(a, b)

def factoring(gcb,n=2):
    for i in range(n,int(gcb**0.5)+1):
        if gcb%i==0:
            ret = factoring(gcb//i,i)
            ret[i] = ret.get(i,0)+1
            return ret
    return {gcb:1}

result = set(factoring(ab_gcd).keys())
result.add(1)
print(len(result))


Measured memory_bytes: 3064
def prime_fac(x):
    pfs = {1}
    for i in range(2, x):
        if i * i > x:
            break
        while x % i == 0:
            pfs.add(i)
            x //= i
    pfs.add(x)
    return pfs


n = int(input())
xs = prime_fac(n)
xs.remove(1)
ans = 0
for v in xs:
    t = v
    while n % t == 0:
        n //= t
        t *= v
        ans += 1
print(ans)


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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i = 0; i<N-1;i++){
    int a = 0;
    cin >> a;
    vec.at(a-1)++;
  }
  for(int i = 0; i<N;i++){
    cout << vec.at(i) << endl;
  }
}

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

typedef long long LL;
typedef vector<int> VI;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define EACH(i,c) for(__typeof((c).begin()) i=(c).begin(),i##_end=(c).end();i!=i##_end;++i)
#define eprintf(...) fprintf(stderr, __VA_ARGS__)

template<class T> inline void amin(T &x, const T &y) { if (y<x) x=y; }
template<class T> inline void amax(T &x, const T &y) { if (x<y) x=y; }
template<class Iter> void rprintf(const char *fmt, Iter begin, Iter end) {
    for (bool sp=0; begin!=end; ++begin) { if (sp) putchar(' '); else sp = true; printf(fmt, *begin); }
    putchar('\n');
}

int N, M, S, T;

struct Edge {
    int to;
    LL cst;
    Edge(){}
    Edge(int to_, LL cst_) {
	to = to_;
	cst = cst_;
    }

    bool operator<(const Edge &y) const {
	return cst > y.cst;
    }
};

const int MAXN = 100011;
void dijk(vector<Edge> G[], int s, LL D[]) {
    memset(D, 0x3f, sizeof (LL) * N);
    D[s] = 0;
    priority_queue<Edge> Q;
    Q.emplace(s, 0);
    while (!Q.empty()) {
	int v = Q.top().to;
	LL cst = Q.top().cst;
	Q.pop();
	if (cst > D[v]) continue;
	EACH (e, G[v]) if (D[e->to] > cst + e->cst) {
	    D[e->to] = cst + e->cst;
	    Q.emplace(e->to, D[e->to]);
	}
    }
}
vector<Edge> Gy[MAXN];
vector<Edge> Gs[MAXN];

LL Dy[MAXN];
LL Ds[MAXN];


void MAIN() {
    scanf("%d%d%d%d", &N, &M, &S, &T);
    S--;
    T--;
    REP (i, M) {
	int x, y, a, b;
	scanf("%d%d%d%d", &x, &y, &a, &b);
	x--; y--;
	Gy[x].emplace_back(y, a);
	Gy[y].emplace_back(x, a);
	Gs[x].emplace_back(y, b);
	Gs[y].emplace_back(x, b);
    }

    dijk(Gy, S, Dy);
    dijk(Gs, T, Ds);

    priority_queue<pair<LL, int> > pq;
    REP (i, N) pq.emplace((LL)(1e15) - Dy[i] - Ds[i], i);

    REP (i, N) {
	while (pq.top().second < i) pq.pop();
	LL ans = pq.top().first;
	printf("%lld\n", ans);
    }
}

int main() {
    int TC = 1;
//    scanf("%d", &TC);
    REP (tc, TC) MAIN();
    return 0;
}



Measured memory_bytes: 19900
n, a, b = map(int, input().split())
V = list(map(int, input().split()))
V.sort(reverse=True)

N = 50
C = [[0]*(N+1) for i in range(N+1)] #C[n][k] > nCk

for i in range(N+1):
    for j in range(i+1):
        if j == 0 or j == i:
            C[i][j] = 1
        else:
            C[i][j] = C[i-1][j-1]+C[i-1][j]

def comb3(n, k):
    return C[n][k]

ans = 0
x = 0
y = 0
for i in range(n):
    if i <= a-1:
        ans += V[i]
        if V[i] == V[a-1]:
            x += 1
            y += 1
    else:
        if V[i] == V[a-1]:
            x += 1

if V[0] != V[a-1]:
    cnt = comb3(x, y)
    print(ans/a)
    print(cnt)
else:
    cnt = 0
    for i in range(a, b+1):
        if i <= x:
            cnt += comb3(x, i)
    print(ans/a)
    print(cnt)


Measured memory_bytes: 38768
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define    clr(v,d)      memset( v, d ,sizeof(v))
#define     PI                       acos(-1)
typedef  long long     ll ;
typedef  unsigned long long ull;
const double eps= (1e-9);
using namespace std;
int dcmp(long double a,long double b){   return fabsl(a-b)<=eps ? 0: (a>b)? 1:-1  ;}
int getBit(ll num, int idx) {return ((num >> idx) & 1ll) == 1;}
int setBit1(int num, int idx) {return num | (1<<idx);}
ll setBit0(ll num, int idx) {return num & ~(1ll<<idx);}
ll flipBit(ll num, int idx) {return num ^ (1ll<<idx);}
void GO(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
int countNumBit1(int mask) {int ret=0; while (mask) 	{mask &= (mask-1);++ret;	}return ret;}
const int N=3000+5,mod=1e9+7;

int main(){
    GO();

    int T;
    T=1;
    while(T--){
        int n,x,t;
        cin>>n>>x>>t;
        cout<<(n/x+(n%x!=0))*t<<"\n";

    }

}





























































































































































































Measured memory_bytes: 3624
k = int(input())
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(a[k-1])


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

using namespace std;

#define pb push_back
#define F first
#define S second
#define fast_cin() ios_base::sync_with_stdio(false)
#define ALL(v) v.begin(), v.end()
#define smid ((i + j) >> 1)
#define lc (sidx * 2)
#define rc (lc + 1)


#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::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


typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;


const int mod = 1e9 + 7;
const ll inf = 4e18;
const ll ninf = -inf;
const int imax = 2e9;

bool cp(pll a, pll b) {
	return a.F < b.F;
}

ll solve(pll a[], ll n, ll c) {
	sort(a + 1, a + n + 1, cp);
	ll energy = 0, dist = 0;
	ll maxEnergy = 0, maxEnergyPoint = -1;
	ll maxTill[n + 1];
	maxTill[0] = 0;
	for(int i = 1; i <= n; i++) {
		energy += (a[i].S - (a[i].F - dist));
		dist = a[i].F;
		if(energy > maxEnergy) {
			maxEnergy = energy;
			maxEnergyPoint = i;
		}
		maxTill[i] = maxEnergy;
	}
	energy = 0, dist = 0;
	dist = c;
	ll maxEnergyAns = maxEnergy;
	for(int i = n; i >= 1; i--) {
		energy += (a[i].S - (dist - a[i].F) * 2);
		dist = a[i].F;
		if(energy + maxTill[i - 1] > maxEnergyAns) {
			maxEnergyAns = energy + maxTill[i - 1];
		}
	}
	return maxEnergyAns;
}

int main()
{
	fast_cin();
	ll n, c;
	cin >> n >> c;
	pll a[n + 1];
	for(int i = 1; i <= n; i++) {
		cin >> a[i].F >> a[i].S;
	}
	ll ans = solve(a, n, c);
	for(int i = 1; i <= n; i++) {
		a[i].F = c - a[i].F;
	}
	ans = max(ans, solve(a, n, c));
	cout << ans << endl;
}

Measured memory_bytes: 2560
#!/usr/bin/env python3
import sys
from collections import Counter
input = lambda: sys.stdin.readline()[:-1]
sys.setrecursionlimit(10**8)

ans=0
n,m=map(int,input().split())
A=list(map(int,input().split()))
bc=[]
for i in range(m):
    b,c=map(int,input().split())
    bc.append((c,b))
C=Counter(A)
bc+=list(C.items())
bc.sort(key=lambda tup:-tup[0])
# print(bc)
for c,b in bc:
    if n>=b:
        n-=b
        ans+=c*b
    else:
        ans+=c*n
        break
print(ans)



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

int main()
{
    char a, b;
    cin >> a >> b;
    int a_flag, b_flag;
    if (a == 'H') a_flag = 1;
    else a_flag = 0;
    if (b == 'D') b_flag = 0;
    else b_flag = 1;
    if (a_flag^b_flag == 0) cout << 'H';
    else cout << 'D';
    cout << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = (a); i < (b); i++)
#define REPR(i, a, b) for (int i = (a); i >= (b); i--)
#define ALL(container) container.begin(), container.end()
using namespace std;
const int INF = 1e9;

const int city_num = 4;
const int road_num = 3;
bool judge(array<int, city_num> city_count) {
  REP(i, 0, city_num) {
    if (city_count[i] == 0 || city_count[i] > 2) {
      return false;
    }
  }
  return true;
}

int main() {
  array<int, road_num> a, b;
  array<int, city_num> city_count = {0};
  bool ans;

  REP(i, 0, road_num) {
    cin >> a[i] >> b[i];
    city_count[a[i]-1]++;
    city_count[b[i]-1]++;
  }
  ans = judge(city_count);

  if (ans) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}


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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){
    int N;cin>>N;
    vec_int A(N);
    rep(i,N)cin>>A.at(i);

    sort(A.begin(),A.end());
    reverse(A.begin(),A.end());

    // rep(i,N)cout<<A.at(i)<<endl;

    priority_queue<int>  pq;
    pq.push(A.at(0));

    int tot_score=0;
    for(int i=1;i<N;i++){
        int max_score = pq.top();pq.pop();
        pq.push(A.at(i));
        pq.push(A.at(i));
        tot_score += max_score;
    }
    cout<<tot_score<<endl;



    return 0;
}

Measured memory_bytes: 6924
#include <stdio.h>
#include <string.h>

int main(void) {
  char s[300000];
  char t[300000];
  int count = 0;

  int ret = scanf("%s %s", s, t);
  if (!ret)
    return 0;
  for (int i = 0; s[i]; i++)
  {
    if (s[i] != t[i])
      count++;
  }
  printf("%d\n", count);
  return 0;
}


Measured memory_bytes: 2128
from itertools import permutations


def submit():
    n, c = map(int, input().split())
    d = [list(map(int, input().split())) for _ in range(c)]    
    color = [list(map(lambda x: int(x) - 1, input().split())) for _ in range(n)]
    color_cnt = {i: {cl: 0 for cl in range(c)} for i in range(3)}

    for i in range(n):
        for j in range(n):
            color_cnt[(i + j) % 3][color[i][j]] += 1

    ans = float('inf')
    for c0, c1, c2 in permutations(range(c), 3):
        t = 0
        for cl in range(c):
            t += color_cnt[0][cl] * d[cl][c0]
            t += color_cnt[1][cl] * d[cl][c1]
            t += color_cnt[2][cl] * d[cl][c2]
        if t < ans:
            ans = t
    print(ans)


submit()

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

bool okay[100005];
string s;
string wrds[] = {"dream", "dreamer", "erase", "eraser"};

bool check(int ind, int w) {
	string wrd = wrds[w];
	if (ind < wrd.size()) return false;
	if (!okay[ind - wrd.size()]) return false;
	for (int i = 0; i < wrd.size(); i++) {
		if (s[ind - i - 1] != wrd[wrd.size() - 1 - i]) return false;
	}
	return true;
}

int main() {
	cin >> s;
	okay[0] = true;
	int n = s.size();

	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < 4; j++) {
			if (check(i, j)) okay[i] = true;
		}

	}

	if (okay[n]) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

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

int a[3000];
long long dp[3000][3000];

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

    int n;
    cin >> n;
    for (int i=0; i<n; i++)
        cin >> a[i];

    for (int i=0; i<n; i++)
        dp[i][i] = (n % 2 == 0 ? -a[i] : a[i]);
    for (int diff=1; diff<n; diff++)
        for (int i=0; i+diff<n; i++) {
            int j = i + diff;
            if (n % 2 != diff % 2)
                dp[i][j] = max(dp[i+1][j] + a[i], dp[i][j-1] + a[j]);
            else
                dp[i][j] = min(dp[i+1][j] - a[i], dp[i][j-1] - a[j]);
        }

    cout << dp[0][n-1] << "\n";

    return 0;
}


Measured memory_bytes: 70016
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 1050;
const long long INF = 1e18;

int n, m;
long long x[MAXN], y[MAXN], z[MAXN];
long long dp[MAXN][MAXN];
long long ans = -INF;

int getBit(long long x, int pos) {
  return (x & (1ll << pos)) > 0 ? 1 : 0;
}

int main() { 

  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%lld %lld %lld", &x[i], &y[i], &z[i]);
  }

  if (m == 0) {
    cout << 0 << endl;
    return 0;
  }

  for (int mask = 0; mask < (1 << 3); mask++) {
    memset(dp, 0, sizeof(dp));

    for (int i = 0; i < n; i++) {
      if (getBit(mask, 0)) {
        x[i] = -x[i];
      }
      if (getBit(mask, 1)) {
        y[i] = -y[i];
      }
      if (getBit(mask, 2)) {
        z[i] = -z[i];
      }
    }

    for (int i = 0; i <= n; i++) {
      for (int j = 0; j <= m; j++) {
        dp[i][j] = -INF;
      }
    }

    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= min(i, m); j++) {
        dp[i][j] = dp[i - 1][j];
        if (j == 1) {
          dp[i][j] = max(dp[i][j], x[i - 1] + y[i - 1] + z[i - 1]);
        }
        dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + x[i - 1] + y[i - 1] + z[i - 1]);
      }
    }

    for (int i = 0; i < n; i++) {
      if (getBit(mask, 0)) {
        x[i] = -x[i];
      }
      if (getBit(mask, 1)) {
        y[i] = -y[i];
      }
      if (getBit(mask, 2)) {
        z[i] = -z[i];
      }
    }

    ans = max(ans, dp[n][m]);
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

const int MAX = 100001;

long long A[MAX], B[MAX];

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%lld %lld", &A[i], &B[i]);
	long long ans = 0;
	for (int i = n - 1; i >= 0; i--) {
		A[i] += ans;
		if (A[i] % B[i] == 0)
			continue;
		ans += (B[i] - (A[i] % B[i]));
	}
	printf("%lld\n", ans);
	return 0;
}

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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// vector
template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    for (T& x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&& ... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}
#ifdef DEBUG
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif
#endif


signed main(){
    int N, M;
    cin >> N >> M;
    
    if(N==M)
        Yes;
    else No;
        }


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <cstdlib>
#include <cstdio>
using namespace std;

void get_op(double* a, double* b, stack<double>* st)
{
    *a = st->top();
    st->pop();
    *b = st->top();
    st->pop();
}

int main()
{
    string line;

    while (getline(cin, line)){
        istringstream iss(line);
        stack<double> st;
        string s;

        while (iss >> s){
            double a, b;

            if (s == "+"){
                get_op(&a, &b, &st);
                st.push(b + a);
            }
            else if (s == "-"){
                get_op(&a, &b, &st);
                st.push(b - a);
            }
            else if (s == "*"){
                get_op(&a, &b, &st);
                st.push(b * a);
            }
            else if (s == "/"){
                get_op(&a, &b, &st);
                st.push(b / a);
            }
            else {
                st.push(atof(s.c_str()));
            }
        }
        printf("%f\n", st.top());
    }

    return (0);
}

Measured memory_bytes: 1264
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <limits>
#include <bitset>
#include <functional>
#include <type_traits>
#include <queue>
#include <stack>
#include <array>
#include <random>
#include <utility>
#include <cstdlib>
#include <ctime>

using namespace std;

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

int main()
{
    int N,A,B,dist;
    cin>>N>>A>>B;
        dist=(A>B)?(A-B-1):(B-A-1);
        if(dist%2)
        cout<<"Alice"<<endl;
        else
        cout<<"Borys"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N,K,X,Y;
  cin >> N >> K >> X >> Y;
  if (N <= K){
    cout << N*X << endl;
  }
  else {
    cout << K*X + (N-K)*Y << endl;
  }
}

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

using namespace std;
int D1[111], D2[111], N;

int main(){
    cin>>N;
    for (int i=0; i<N; i++){
        cin>>D1[i]>>D2[i];
        if (i>=2){
            if (D1[i]-D2[i]==0&&D1[i-1]-D2[i-1]==0&&D1[i-2]-D2[i-2]==0){
                cout<<"Yes";
                return 0;
            }
        }
    }
    cout<<"No";
}


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

int main() {
  int a,b;
  string op,ans;
  cin >> a >> b;

  int ct = 0;
  int a1,a2,a3;
  int al = a / 10000;
  int au = b / 10000 + 1;
  
  for(a1 = al;a1<au;a1++)
    for(a2 = 0;a2<10;a2++)
      for(a3 = 0;a3<10;a3++){
        int tg = a1*10001+a2*1010+a3*100;
  		if (a <= tg && tg <= b)
          ct++;
      }
  cout << ct << endl;
}


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

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

	string A,B;
	A = to_string(a);
	B = to_string(b);
	string A2 = A;
	string B2 = B;

	rep(i,b-1){
		A += A2;
	}
	rep(i,a-1){
		B += B2;
	}

	cout <<((A<B)?A:B) <<endl;
}

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

int main()
{
  int N, M;
  while (cin >> N >> M && N != 0) {
    vector<int> ps(N);
    for (int i = 0; i < N; i++) {
      cin >> ps[i];
    }

    vector<int> v(1, 0);
    for (int i = 0; i < N; i++) {
      v.push_back(ps[i]);
      for (int j = i; j < N; j++) {
        if (ps[i] + ps[j] <= M) {
          v.push_back(ps[i] + ps[j]);
        }
      }
    }
    sort(v.begin(), v.end());

    int ans = 0;
    for (vector<int>::const_iterator it(v.begin()); it != v.end(); ++it) {
      vector<int>::const_iterator jt = lower_bound(v.begin(), v.end(), M - *it);
      if (jt != v.begin()) {
        --jt;
        ans = max(ans, *it + *jt);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 3000
#include <bits/stdc++.h>
#define PI acos(-1)
#define eq(x,y) (fabs((x)-(y)) < eps)
#define debug(x) cerr<<x<<endl;
#define endl "\n"
#define pb push_back
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
const int nmax=1e5+10;
const int eps=1e-8;

vector<int>adj[2*nmax];
int sum[2*nmax];
bool vis[2*nmax];

void dfs(int now, int from)
{
    if(vis[now])
        return;
    vis[now]=true;
    sum[now]+=sum[from];

    for(auto to: adj[now])
        dfs(to,now);
}

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout<<fixed;
    //cout.tie(NULL);
    int n,q;
    cin>>n>>q;
    for(int i=0;i<n-1;i++)
    {
        int u,v;
        cin>>u>>v;
        adj[u].pb(v);
        adj[v].pb(u);
    }

    while(q--)
    {
        int v,x;
        cin>>v>>x;

        sum[v]+=x;
    }

    dfs(1,0);

    for(int i=1;i<=n;i++)
        cout<<sum[i]<<" ";

    cout<<endl;

    return 0;
}


Measured memory_bytes: 20608
#include <bits/stdc++.h>
using namespace std;
int main(){
  
 int N,A,X;
 cin >> N >> A;
 X = N % 500; 
   
 if(X <= A){
   cout << "Yes" << endl;
   
 
 }
 else{
   cout << "No" << endl;
  
  }
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back

void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}


string s;
int k;

signed main(){
  cin>>s>>k;

  rep(i,s.size()){
    if(s[i]+k<='z'||s[i]=='a') continue;
    k-='z'-s[i]+1;
    s[i]='a';
  }

  k%=26;
  int n = s.size()-1;
  s[n]+=k;

  cout<<s<<endl;
}


Measured memory_bytes: 512
#include "bits/stdc++.h"
using namespace std;
 
typedef long long ll;
 
 
int main() {
	int n;
	cin >> n;
	vector<ll> v(n);
	ll a = 0;
	for (int i = 0; i < n; ++i) {
		cin >> v[i];
		a ^= v[i];
	}
	for (int i = 0; i < n; ++i) {
		cout << (v[i] ^ a) << " ";
	}
}


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin >> a[i];
  n--;
  
  long long  money=1000;
  long long kabu=0;
  
  for(int i=0;i<n;i++){
    if(a[i]<a[i+1]){
      kabu+=money/a[i];
      money%=a[i];
    }
    else if(a[i]>a[i+1]){
      money+=kabu*a[i];
      kabu=0;
    }
  }
  
  cout << money+kabu*a[n] << endl;
}

Measured memory_bytes: 3564
#include <cassert>
#include <cctype>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <sstream>
#include <iomanip>
#include <limits>
#include <string>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
using namespace std;
unsigned long long rdtsc(){unsigned long long ret=0;asm volatile("rdtsc" : "=A" (ret) : :);return ret;}
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define reunique(v) v.erase(unique(all(v)),v.end())
#define RET(p,x) return p<<x<<endl,0;
#define Debug(x) cerr<<#x<<" = "<<x<<endl
#define int long long
const int inf=1e9;
const int mod=1e9+7;
const int Maxn=1005;
int n,k;
int sum1,sum2,res;
int t[Maxn][Maxn];
int sp[Maxn][Maxn];
signed main()
{
	rdtsc();
	cout<<setprecision(10);
	cin>>n>>k;
	for (int i=0;i<n;++i)
	{
		int x,y;
		char c;
		cin>>x>>y>>c;
		int cur=(x/k+y/k+(c=='B'))%2;
		if (!cur)
		{
			cur=-1;
		}
		t[x%k][y%k]+=cur;
		if (cur==1)
		{
			sum1++;
		}
		else
		{
			sum2++;
		}
	}
	for (int i=0;i<k;++i)
	{
		for (int j=0;j<k;++j)
		{
			sp[i+1][j+1]=sp[i+1][j]+sp[i][j+1]+t[i][j]-sp[i][j];
		}
	}
	for (int i=0;i<k;++i)
	{
		for (int j=0;j<k;++j)
		{
			int cur=sp[i][k]+sp[k][j]-2*sp[i][j];
			initializer_list<int> il={res,sum1-cur,sum2+cur};
			res=*max_element(il.begin(),il.end());
		}
	}
	RET(cout,res);
}

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

int main()
{
  int n;
  cin >> n;
  ll mn = 10000000;
  int ans = 0;
  rep(i, n)
  {
    ll p;
    cin >> p;
    if (p <= mn)
    {
      mn = p;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>

using namespace std;

typedef long long ll;

ll n;
ll a[15][15];
ll ans;

int main()
{
    cin>>n;
    for(ll i = 1; i <= n; i++)
    {
        ll x = i % 10;
        ll y = i;
        while(y > 9) y /= 10;
        a[x][y]++;
    }
    for(ll i = 0; i <= 9; i++)
    {
        for(ll j = 1; j <= 9; j++)
        {
            ans += a[i][j] * a[j][i];
        }
    }
    cout<<ans;
    return 0;
}


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

def swap(a,b):
    c=[i for i in a]
    c[b],c[b+1]=c[b+1],c[b]
    return "".join(c)

def ok(a):
    if "AGC" in swap(a,0) or "AGC" in swap(a,1) or "AGC" in swap(a,2) or "AGC" in a:
        return False
    return True

if n==1:
    print(4)
elif n==2:
    print(16)
else:
    a={}
    for i in "ACGT":
        for j in "ACGT":
            for k in "ACGT":
                if not i+j+k in ["AGC","ACG","GAC"]:
                    a[i+j+k]=1
    for q in range(n-3):
        b={}
        for i in a:
            for j in "ACGT":
                if ok(i+j):
                    w=i[1:]+j
                    if w in b:
                        b[w]+=a[i]
                    else:
                        b[w]=a[i]
        a=dict(b)
    al=0
    for i in a:
        al+=a[i]
    print(al%(10**9+7))


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

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;i++)
#define rep2(i, m, n) for(int i=m;i<n;i++)
#define rrep(i, n, m) for(int i=n;i>=m;i--)
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll MOD = 1000000007;
#ifdef __DEBUG

#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    int N, D;
    cin >> N >> D;
    cout << (N + 2*D) / (2*D+1) << endl;

}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}


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

int main(){
  string s;
  cin>>s;
  if(s=="AKIHABARA"||s=="AKIHABAR"||s=="AKIHABRA"||s=="AKIHBARA"||s=="KIHABARA"||s=="AKIHABR"||s=="AKIHBAR"||s=="KIHABAR"||s=="AKIHBRA"||s=="KIHABRA"||s=="KIHBARA"||s=="AKIHBR"||s=="KIHABR"||s=="KIHBAR"||s=="KIHBRA"||s=="KIHBR") cout<<"YES";
  else cout<<"NO";
  cout<<endl;
}

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

int main(){
    int n,k;
    string s;
    cin >> n >> s >> k;
    char t;
    t = s.at(k-1);
    for(int i=0;i<s.size();i++){
        if (s.at(i)!=t){
            s.at(i)='*';
        }
    }
    cout << s << endl;
}


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

#define REP(i, n) for(int (i)=0;(i)<(n);++(i))
#define MOD 1000000007
#define DAYNUM 5
#define TIMENUM 2

using namespace std;

typedef long long ll;

int main()
{
    int N;
    cin >> N;
    int F[N][TIMENUM * DAYNUM];
    REP(i, N)
    {
        REP(j, TIMENUM * DAYNUM)
        {
            cin >> F[i][j];
        }
    }
    int P[N][TIMENUM * DAYNUM + 1];
    REP(i, N)
    {
        REP(j, TIMENUM * DAYNUM + 1)
        {
            cin >> P[i][j];
        }
    }

    // 1023 = 2^10 - 1
    int ans = INT_MIN;
    for (int i = 1; i <= 1023; ++i)
    {
        int sumOpened[N] = {0};
        int pattern = 1;
        REP(j, TIMENUM * DAYNUM)
        {
            int bit = (i & pattern) >> j;
            pattern <<= 1;
            REP(k, N)
            {
                if (F[k][j] * bit)
                {
                    sumOpened[k]++;
                }
            }
        }

        ll sumNow = 0;
        REP(j, N)
        {
            sumNow += P[j][sumOpened[j]];
        }
        if (ans < sumNow)
        {
            ans = sumNow;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
# 2019/09/12

s=list(input())
n=len(s)
res=[1]*n


def rle():

    RLE=[]
    l=0
    r=1
    while l<n:
        while r<n:
            if s[l]==s[r]:
                r+=1
            else:
                break
        RLE.append((s[l],r-l))
        l=r
        r+=1
    return RLE

RLE=rle()

ans=[]

for i in range(0,len(RLE),2):
    r=RLE[i][1]
    l=RLE[i+1][1]
    ans+=[0]*(r-1)

    a=r//2+(-(-l//2))   
    b=l//2+(-(-r//2))
    if (r+l)%2:
        a,b=b,a


    ans.append(a)
    ans.append(b)
    ans+=[0]*(l-1)
    

print(*ans)

Measured memory_bytes: 14884
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;


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



ll P[2000000];
ll C[2000000];
int main() {
	int N;
	cin >> N;
	REP(i, N) {
		cin >> P[i];
		C[P[i]-1] = i;
	}
	ll res = 1, cnt = 1;
	REP(i, N) {
		if (C[i + 1] > C[i]) {
			cnt++;
		}
		else {
			res = max(res, cnt);
			cnt = 1;
		}
	}
	cout << N - res << endl;
	return 0;
}

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

typedef long long ll;
typedef long double ld;
const ll mod = 1e9 + 7;
#define eps 1e-9
ll pos1[(int)1e7 + 5];
ll pos2[(int)1e7 + 5];
bool move1[(int)1e7 + 5], stop1[(int)1e7 + 5];
bool move2[(int)1e7 + 5], stop2[(int)1e7 + 5];
using namespace std;
int main() {
    ll x, y;
    cin >> x >> y;
    if (abs(x - y) > 1)
        return cout << 0, 0;
    ll fact[(int)1e5 + 5];
    fact[0] = fact[1] = 1;
    for (int i = 2; i <= 1e5; i++) {
        fact[i] = (fact[i - 1] % mod) * i;
        fact[i] %= mod;
    }
    ll res = ((fact[x] % mod) * (fact[y] % mod)) % mod;
    if (x == y) {
    res *= 2;
    res %= mod;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 1024
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;

const int MAX_N = 200005;

inline void chmax(int &x, int y) {
  if (x < y) x = y;
}

inline void chmin(int &x, int y) {
  if (x > y) x = y;
}

int prefix[1 << 18], suffix[1 << 18], f[MAX_N];
int L[25][MAX_N], R[25][MAX_N], N, V, val[25], tot, X[MAX_N];

void work(int *l, int *r, int v) {
  int last = 1;
  
  l[1] = l[0] = 1;
  for (int i = 2; i <= N; ++i) {
    if (X[i] - X[i - 1] > v) last = i;
    l[i] = last;
  }
  
  last = N, r[N] = r[N + 1] = N;
  for (int i = N - 1; i >= 1; --i) {
    if (X[i + 1] - X[i] > v) last = i;
    r[i] = last;
  }
}

int main() {
  scanf("%d%d", &N, &V);
  
  for (int i = 1; i <= N; ++i)
    scanf("%d", &X[i]);
  
  int temp = V;
  
  while (temp) {
    val[tot++] = temp;
    temp = temp >> 1;
  }
  val[tot++] = 0;
  for (int i = 0; i < tot; ++i) 
    work(L[i], R[i], val[i]);
  
  int S = (1 << tot - 1) - 1;
  for (int i = 1; i <= S; ++i) suffix[i] = N + 1;
  
  prefix[0] = 0, suffix[0] = N + 1;


  for (int mask = 0; mask <= S; ++mask) {
    for (int j = 1; j < tot; ++j)
      if (!(mask & (1 << j - 1))) {
	chmax(prefix[mask | (1 << j - 1)], R[j][prefix[mask] + 1]);
	chmin(suffix[mask | (1 << j - 1)], L[j][suffix[mask] - 1]);
      }
  }

  memset(f, -1, sizeof f);
  for (int mask = 0; mask <= S; ++mask) 
    chmax(f[suffix[mask]], prefix[S ^ mask]);

  for (int i = 1, mx = -1, pos = 1; i <= N; ++i) {
    int l = L[0][i], r = R[0][i];
    while (pos <= r + 1) chmax(mx, f[pos++]);
    if (mx + 1 >= l) puts("Possible");
    else puts("Impossible");
  }
  
  return 0;
}

Measured memory_bytes: 40832
import java.io.*;

class Main{
    public static void main(String args[]){
        Qq q = new Qq(9);
        q.outputQQ();
    }
}

class Qq{
    int wide;

    Qq(int w){
        wide = w;
    }
    
    void outputQQ(){
        for (int i = 1; i <= wide; i ++){
            for(int j = 1; j <= wide;j ++) {
                System.out.printf("%dx%d=%d\n", i, j, i*j);
            }
        }
    }
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    int k;
    string s;
    cin>>k;
    cin>>s;
    if(s.size()<=k)
    {
        cout<<s;
    }
    else
    {
        cout<<s.substr(0,k)<<"...";
    }
    return 0;
}

Measured memory_bytes: 3684
//writer：Sakura
//problem：Digits Sum
//id：
//from：

#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
//#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

//快读（可去）
/*
inline int read(){
	int S=0,W=1;
	char CH=getchar();
	while(CH<='0' || CH>'9'){
		if(CH=='-')W=-1;
		CH=getchar();
	}
	while(CH>='0' && CH<='9')S=S*10+CH-'0',CH=getchar();
	return S*W;
}*/

int work(int x){
	int sum=0;
	while(x>0){
		sum+=x%10;
		x/=10;
	}
	return sum;
}

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n;
	int ans=0;
	scanf("%d",&n);
	if(n%10!=0){
		ans=work(n);
	}
	else{
		ans=10;
	}
	printf("%d\n",ans);
	return 0;
}



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

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

	ll N, M;
	cin >> N >> M;
	ll c = 0;
	for (int i = 0; i < M; i++) {
		ll a;
		cin >> a;
		c += a;
	}
	if (c > N) {
		cout << -1 << endl;
	}
	else {
		cout << N - c << endl;
	}

}


Measured memory_bytes: 3652
n = int(input())
t = [0]
x = [0]
y = [0]
for _ in range(n):
    t_, x_, y_ = map(int, input().split())
    t.append(t_)
    x.append(x_)
    y.append(y_)

flag = True
for i in range(n):
    t_diff = t[i+1] - t[i]
    x_diff = x[i+1] - x[i]
    y_diff = y[i+1] - y[i]

    if abs(x_diff) + abs(y_diff) > t_diff:
        flag = False
        break

    if (x_diff % 2 == 0 and y_diff % 2 == 0) or (x_diff % 2 != 0 and y_diff % 2 != 0):
        match = True
    else:
        match = False

    if t_diff % 2 == 0 and not match:
        flag = False
        break
    elif t_diff % 2 != 0 and match:
        flag = False
        break

if flag:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 11732
T = input()
L = len(T)
if T[0] is "?" and L > 1 :
    if T[1] is "D":
        T = 'P' + T[1:]
    else:
        T = 'D' + T[1:]
if T[L-1] is "?":
    T = T[:L-1] + 'D'
T = T.replace("P?", "PD")
T = T.replace("?P", "DP") 
T = T.replace("?","D")

print(T)

Measured memory_bytes: 65128
/**
* Copyright(c)
* All rights reserved.
* Author : zzy
* Date : 2020-03-07-19.52.47
*/
#include <bits/stdc++.h>

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, a, b) for (int i = (int)(a); i >= (int)b; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
#define SZ(x) ((int)(x).size())

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

string s;
int a =0 , b = 0;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    cin >> s;
    for (char ch : s) {
        if (ch == 'A') ++a;
        else ++b;
    }
    if (a == 3 || b == 3) cout << "No" << '\n';
    else cout << "Yes" << '\n';

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


Measured memory_bytes: 256
import itertools

N = int(input())
P = list(map(int, input().split()))
Q = list(map(int, input().split()))

a = 0
b = 0
i = 1

for x in itertools.permutations(list(range(1,N+1))):
    l = list(x)
    if P == l:
        a = i
    if Q == l:
        b = i
    i += 1

print(abs(a - b))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define ld long double
#define mod ((ll)1e9+7)
#define maxx ((ll)1e6+5)
#define pb push_back
#define ins insert
#define usefile freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll expo(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x%mod)%mod; x=(x*x)%mod; y/=2; } return res;}
using namespace std;

string lcs(string s, string t)
{
	int n = s.size();
    int m = t.size();
    int i,j,k;
    int d[n+1][m+1];
    for(i=0 ; i<=n ; i++)
    	for(j=0 ; j<=m ; j++)
    		d[i][j] = 0;
    for(i=1 ; i<=n ; i++)
    {
    	for(j=1 ; j<=m ; j++)
		{
			d[i][j] = max(d[i-1][j] , d[i][j-1]);
			if(s[i-1] == t[j-1])
				d[i][j] = max(d[i][j] , d[i-1][j-1]+1);
		}
    }
    int x=n, y=m;
    string ans;
    while(x>0 && y>0)//idk watmidoin
    {
    	if(x==0 || y==0) break;
    	while(d[x][y-1] == d[x][y] && y>0)//go left till end
    		y = y-1;
    	while(d[x-1][y] == d[x][y] && x>0)//go up
    		x = x-1;
    	if(x<=0 || y<=0) break;
    	if(d[x][y] == 0) break;
    	ans.pb(s[x-1]);
    	x = x-1;
    	y = y-1;
    }
    reverse(ans.begin() , ans.end());
    return ans;
}

signed main()
{
    string s,t;
    cin >> s >> t;
    string ans = lcs(s, t);
    cout << ans <<"\n";
    return 0;
}

Measured memory_bytes: 70656