akhauriyash/Code-Regression huggingface dataset:
n, m, q = map(int, input().split())   
a = []
for i in range(10):
  a.append(1)
max = 0
inp = []
for i in range(q):
  ta,tb,tc,td = map(int,input().split())
  inp.append((ta,tb,tc,td))
for i1 in range(1,m+1):
  a[0] = i1
  for i2 in range(i1,m+1):
    a[1] = i2
    for i3 in range(i2,m+1):
      a[2] = i3
      for i4 in range(i3,m+1):
        a[3] = i4
        for i5 in range(i4,m+1):
          a[4] = i5
          for i6 in range(i5,m+1):
            a[5] = i6
            for i7 in range(i6,m+1):
              a[6] = i7
              for i8 in range(i7,m+1):
                a[7] = i8
                for i9 in range(i8,m+1):
                  a[8] = i9
                  for i10 in range(i9,m+1):
                    a[9] = i10
                    sum = 0
                    if q != 1:
                      for i in range(q):
                        if a[inp[i][1]-1] - a[inp[i][0]-1] == inp[i][2]:
                          sum = sum + inp[i][3]
                        if sum > max:
                          max = sum
                    else:
                      if a[inp[0][1]-1] - a[inp[0][0]-1] == inp[0][2]:
                          sum = sum + inp[0][3]
                      if sum > max:
                          max = sum

print(max)

Measured memory_bytes: 9336
#include<bits/stdc++.h>
#define N 100005
#define P 1000000007
using namespace std;
int n,m,f[N],dep[N];
vector<int>a[N];
void dfs(int x,int fa){
	dep[x]=dep[fa]+1;
	int t=0;
	for(int i=0;i<(int)a[x].size();i++){
		int y=a[x][i],res=m;
		if(y==fa)continue;
		t++;
		if(dep[x]>=2)res-=2;
		else res--;
		res-=t-1;
		f[y]=res;
		dfs(y,x);
	}
	
}
signed main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		a[x].push_back(y);
		a[y].push_back(x);
	}
	f[1]=m;
	dfs(1,0);
	long long ans=1ll;
	for(int i=1;i<=n;i++)ans=ans*f[i]%P;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 12288
# -*- coding: utf-8 -*-
import sys
from collections import defaultdict

N,K=map(int, sys.stdin.readline().split())
A=map(int, sys.stdin.readline().split())
A=map(lambda a: (a-1)%K, A)

S=[0]
for a in A:
    S.append( (S[-1]+a)%K )   #累積和

d=dict()    #要素：要素の数を持つ

ans=0
for i in range(N+1):
    x=S[i]%K
    if i==0:
        d[x]=1
    else:
        if x in d:
            if 2<=K:    #K=1の時は自分の値も見てはいけない
                ans+=d[x]   #自分より前に同じ出現した、自分と同じ要素の数を答えに追加
            d[x]+=1
        else:
            d[x]=1      
        if 0<=i-K+1:
            x_head=S[i-K+1]%K  #長さK-1の範囲で配列Sを見るため、１つ進んだら一番先頭の要素を辞書から削除する
            d[x_head]-=1

print ans


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

using namespace std;

typedef long long ll;

const int MAXN = 2e5 + 10;

int n, p[MAXN], sec[MAXN];
set<int>	st;

bool cmp(int u, int v){return p[u] < p[v];}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> p[i], p[i]--;
	iota(sec, sec + n, 0);
	sort(sec, sec + n, cmp);
	ll ans = 0;
	for (int i = 0; i < n; i++){
		int prv = -1, nxt = n;
		auto it = st.lower_bound(sec[i]);
		if (it != st.end())	nxt = *it;
		if (it != st.begin())
			it--, prv = *it;
		ans += 1ll * (i + 1) * (sec[i] - prv) * (nxt - sec[i]);
		st.insert(sec[i]);
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 11136
/* ex6_2 melo */
#include <stdio.h>
#include<string.h> //文字列関数
#define SIZE 101 //文字列の大きさを定義
int main(void){
    char sente[SIZE];
    int length;
    fgets(sente,SIZE,stdin);
    length=(int)strlen(sente);
    if (sente[length-1]=='\n') {
        sente[length-1]='\0';
    }
    printf("%c%d%c\n",sente[0],(int)strlen(sente)-2,sente[(int)strlen(sente)-1]);
    return 0;
}


Measured memory_bytes: 128
N = int(input())
A = map(int, input().split())
MOD = 1000000007
ans = 1
cnt = [3 if i == 0 else 0 for i in range(N + 1)]

for a in A:
    ans = ans * cnt[a] % MOD
    if ans == 0:
        break
    cnt[a] -= 1
    if cnt[a] < 0:
        cnt[N + 10] = 0
    cnt[a + 1] += 1

print(ans)

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

ll solve() {
    ll N;
    vector<string> S(3);
    cin >> N >> S[0] >> S[1] >> S[2];
    ll ans = 0;
    for ( int i = 0; i < N; i++ ) {
        set<char> c;
        for ( int j = 0; j < 3; j++ ) {
            c.insert(S[j][i]);
        }
        ans += c.size() - 1;
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n);
    cout<<arr[n-1]-arr[0]<<endl;
}


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

using namespace std;

const int mod = 1e9 + 7, P = 1e9 + 7;
int n, a[323456];
int x[10], y[10], p[10];

 
int main() {

	cin >> n;
	double fact = 1;
	for(int i = 1; i <= n; i++) {
		cin >> x[i] >> y[i];
		p[i] = i;
		fact *= i;
	}

	double res = 0;
	do {
		double cur = 0;
		for(int i = 2; i <= n; i++) {
			cur += sqrt((x[p[i]] - x[p[i - 1]]) * (x[p[i]] - x[p[i - 1]]) + (y[p[i]] - y[p[i - 1]]) * (y[p[i]] - y[p[i - 1]]));
		}
		res += cur;
	} while(next_permutation(p + 1, p + n + 1));

	printf("%.9f", res / fact);
}


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

int main() {
    long long A,B;
    cin >> A >> B;
    for(long long i=0;i< max(A,B);i++){
        long long diffA = abs(A-i);
        long long diffB = abs(B-i);
        if(diffA == diffB) {
            cout << i << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
}

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

    divisors.sort()
    return divisors

n = int(input())
n_ = n
div = make_divisors(n)
ans = []
for d in div[1:]:
    while n_ % d == 0 and n_ > 0:
        n_ //= d
        ans.append(d)
print("{}:".format(n), *ans)



Measured memory_bytes: 5636
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
    
        while(true){
            int x = sc.nextInt();
            String a = sc.next();
            int y = sc.nextInt();
            int z = 0;

            if(a.equals("+")) z = x + y;
            if(a.equals("-")) z = x - y;
            if(a.equals("*")) z = x * y;
            if(a.equals("/")) z = x / y;
            if(a.equals("?")) break;

            System.out.printf("%d\n",z);
        }    
    } 
}


Measured memory_bytes: 26424
#include <vector>
#include <iostream>
using namespace std;
typedef long long ll;

#ifdef MUTABLE
int mod;
#else
template<int mod>
#endif
struct ModInt {
  int val;
  ModInt inv() const{
    int tmp,a=val,b=mod,x=1,y=0;
    while(b)tmp=a/b,a-=tmp*b,swap(a,b),x-=tmp*y,swap(x,y);
    return ModInt(x);
  }
  ModInt():val(0){}
  ModInt(ll x){if((val=x%mod)<0)val+=mod;}
  ModInt pow(ll t){ModInt res=1,b=*this; while(t){if(t&1)res*=b;b*=b;t>>=1;}return res;}
  ModInt& operator+=(const ModInt& x){if((val+=x.val)>=mod)val-=mod;return *this;}
  ModInt& operator-=(const ModInt& x){if((val+=mod-x.val)>=mod)val-=mod; return *this;}
  ModInt& operator*=(const ModInt& x){val=(ll)val*x.val%mod; return *this;}
  ModInt& operator/=(const ModInt& x){return *this*=x.inv();}
  bool operator==(const ModInt& x) const{return val==x.val;}
  bool operator!=(const ModInt& x) const{return val!=x.val;}
  bool operator<(const ModInt& x) const{return val<x.val;}
  bool operator<=(const ModInt& x) const{return val<=x.val;}
  bool operator>(const ModInt& x) const{return val>x.val;}
  bool operator>=(const ModInt& x) const{return val>=x.val;}
  ModInt operator+(const ModInt& x) const{return ModInt(*this)+=x;}
  ModInt operator-(const ModInt& x) const{return ModInt(*this)-=x;}
  ModInt operator*(const ModInt& x) const{return ModInt(*this)*=x;}
  ModInt operator/(const ModInt& x) const{return ModInt(*this)/=x;}
  static int get_mod() { return mod; }
};

#ifndef MUTABLE
using modint = ModInt<1000000007>;
#endif

template <int mod>
struct Factorial {
  using mint = ModInt<mod>;
  vector<modint> Fact, Finv;
public:
  Factorial(int _n): Fact(_n+1), Finv(_n+1) {
      Fact[0]=mint(1); for (int i = 0; i < _n; ++i) Fact[i+1]=Fact[i]*(i+1);
      Finv[_n]=mint(1)/Fact[_n]; for (int i = _n; i > 0; --i) Finv[i-1]=Finv[i]*i;
  }
  mint fact(int n,bool inv=0) { if (inv) return Finv[n]; else return Fact[n]; }
  mint nPr(int n,int r){ if (n<0||n<r||r<0) return mint(0); else return Fact[n]*Finv[n-r]; }
  mint nCr(int n,int r){ if (n<0||n<r||r<0) return mint(0); else return Fact[n]*Finv[r]*Finv[n-r]; }
};

using factorial = Factorial<1000000007>;

int main() {
  int h, w, a, b;
  cin >> h >> w >> a >> b;
  factorial fact(300000);
  modint ans(0);
  for (int i = b; i < w; ++i) {
    modint c1 = fact.nCr(h-a-1+i, i);
    modint c2 = fact.nCr(w-i-1+a-1, a-1);
    ans += c1*c2;
  }
  cout << ans.val << endl;
}



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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    char s[100003];
    Scs(s);

    int len = strlen(s);
    bool ans = true;
    ans = s[0] == '1';
    ans = ans && s[len-1] == '0';
    for (int i = 1; i < len-1; i++){
        if( s[i] != s[len-i-2] ){
            ans = false;
            break;
        }
    }
    if( ans ){
        int hit = len;
        for(int i = len-2; i >= 0; i--){
            printf ("%d %d\n", hit, i+1);
            if( s[i] == '1' ) hit = i+1;
        }
    }else printf ("%d\n", -1);


    return 0;
}



Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define FINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;
/* ---------------------------------------------------------------------------------------------------- */

int n;
int a[200010];
int b[200010];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  cin >> n;
  REP(i,n) cin >> a[i];
  reverse(a,a+n);
  int l = 0, r = n-1;
  REP(i,n) {
    if (i % 2 == 0) {
      b[l] = a[i];
      l++;
    } else {
      b[r] = a[i];
      r--;
    }
  }
  REP(i,n) {
    cout << b[i] << " \n"[i+1==n];
  }

  return 0;
}

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

using namespace std;

void chmin(int &a, int b) {if(a > b) a=b; }

int N, A, B, C;
vector<int> L;
int INF = 1 << 29;

int cost(int i, int a, int b, int c){
    /*ベースケース */
    if(i == N){
        if(a ==0 || b == 0 || c==0) return INF;
        return abs(A-a) + abs(B-b) + abs (C-c);
    }
    /*i本目(今)の竹を使わないケース */
    int ncost = cost(i+1, a, b, c);

    chmin(ncost, cost(i+1, a + L[i], b, c) + (a ? 10:0)); 
    chmin(ncost, cost(i+1, a, b + L[i], c) + (b ? 10:0)); 
    chmin(ncost, cost(i+1, a, b, c + L[i]) + (c ? 10:0)); 

    return ncost;
}

int main() {
    cin >> N >> A >> B >> C;
    L.resize(N);
    for(int i = 0; i < N; i++) {
        int l;
        cin >> l;
        L[i] = l;
    }


    cout << cost(0,0,0,0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define ROF(i, a, b) for (int i = a; i >= b; i--)
using namespace std;

using pii = pair<int, int>; using vpii = vector<pii>;
using vi = vector<int>; using vvi = vector<vi>;
using ll = long long;
using pll = pair<ll, ll>; using vpll = vector<pll>;
using vll = vector<ll>; using vvll = vector<vll>;

int main() {
    int n; cin >> n;
    vi f(n + 1);
    FOR(i, 1, 100) FOR(j, 1, 100) FOR(k, 1, 100) {
        int sum = i * i + j * j + k * k + i * j + j * k + k * i;
        if (sum <= n) f[sum]++;
    }
    FOR(i, 1, n)
        cout << f[i] << endl;
}

Measured memory_bytes: 3576
import Control.Monad
import Data.List

main = do
  [n, m] <- map read . words <$> getLine
  xs <- replicateM n (map read . words <$> getLine)
  let a = func $ group $ sort $ concat $ map tail xs
  print $ length $ filter (==n) a
  
func :: [[Int]] -> [Int]
func [] = []
func (x: xs) = length x : func xs

Measured memory_bytes: 1276
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath> // sqrt
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif


int main(void) {
    int a, b;
    int h, m;
    cin >> a >> b;
    cin >> h >> m;
    int mm = h * 60 + m;
    double argh = (double)mm / (60*12) * 360;
    double argm = 6 * m;
    double diff = argh - argm;
    // to rad
    diff = min(diff, 360-diff) * (M_PI/180);
    debug("theta: %lf\n", diff);
    // Law of cosines
    double ans = (a*a) + (b*b) - 2*a*b*cos(diff);
    printf("%.10lf\n", sqrt(ans));
    return 0;
}

Measured memory_bytes: 4184
S = input()
num = []
ans = 0
length = 0


def calc(x, i, j):
    if i == length-1:
        x += j
        global ans
        ans += x
    else:
        calc(x+j, i+1, num[i+1])
        calc(x, i+1, 10*j+num[i+1])


def solve():
    for s in S:
        num.append(int(s))
    global length
    length = len(num)
    calc(0, 0, num[0])
    print(ans)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 3064
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())


ar = [t % 10 for t in [a, b, c, d, e] if t % 10 != 0]
if len(ar) == 0:
    ar.append(0)
mi = min(ar)


# print(mi)

# print([wt + (10 - (wt % 10)) if wt % 10 != 0 else wt for wt in [a, b, c, d, e]])
w = sum([wt + (10 - (wt % 10)) if wt % 10 != 0 else wt for wt in [a, b, c, d, e]])

if mi > 0:
    w = w - 10 + mi
print(w)

Measured memory_bytes: 3064
import numpy as np
import sys
h,w = map(int,input().split())
if h == 1:
    print(1)
    sys.exit()
if w == 1:
    print(1)
    sys.exit()
if w%2 == 0:
    if h%2 == 0:
        print((w//2)*h)
    else:
        print((w//2)*h)
else:
    if h%2 == 0:
        print(((w//2)+1)*(h//2) + (w//2)*(h//2))
    else:
        print(((w//2)+1)*((h//2)+1) + (w//2)*(h//2))


Measured memory_bytes: 12388
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	ll a, b, c, k;
	cin >> a >> b >> c >> k;
	ll ans = 0;
	if(a >= k) ans = k, k -= k;
	else ans = a, k -= a;
	if(k){
		if(b < k) k -= b;
		else k = 0;
	}
	if(k){
		if(c >= k) ans -= k;
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i <= n; i++)
#define FORR(i, m, n) for(ll i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n)
#define MAX 100000
#define inf 1000000007
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;
using graph = vector<vector<int>>;

int main() {
    //cin高速化
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, c, ans;
    cin >> a >> b >> c;
    ans = b/c - (a-1)/c;

    cout << ans <<"\n";
	return 0;
}

Measured memory_bytes: 3644
#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;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

#define v(type) vector<type>
#define p(type1, type2) pair<type1 , type2>
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[MAX];

void solve() {
    int n ;
    cin>>n;
    v(vi) adj(n);
    for(int i = 1 ; i< n ; i++){
        int p;
        cin>>p;
        p--;
        adj[i].push_back(p);
        adj[p].push_back(i);
    }
    cout<<adj[0].size()<<endl;
    for(int i = 1 ; i< n ; i++){
        cout<<adj[i].size() -1 <<endl;
    }
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;

vll G[200100];


signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,m; cin>>n>>m;
  rep(i,m){
    ll a,b; cin>>a>>b; a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  
  vb visited(n);
  visited[0]=true;
  queue<pll> q;
  q.emplace(0,0);
  while(!q.empty()){
    auto p=q.front(); q.pop();
    ll v=p.first, cnt=p.second;
    // if(cnt>=2) continue;
    for(auto nv: G[v]){
      if(!visited[nv] && cnt<2){
        visited[nv]=true;
        q.emplace(nv,cnt+1);
      }
    }
  }
  if(visited[n-1]) cout<<"POSSIBLE"<<endl;
  else cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 14440
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
//#include <atcoder/all>
using namespace std;
//using namespace atcoder;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;

//typedef modint998244353 mint;

const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
//const ll MOD = 1e9 + 7;
const ll MOD = 998244353;

const ll MAX = 1e9 + 5;

int main() {
	int n;
	cin >> n;

	vector<ll> a(n);
	vector<ll> b(n);

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

	for (int i = 0; i < n; i++) {
		cin >> b[i];
	}


	vector<ll> c(n);
	for (int i = 0; i < n; i++) {
		c[i] = a[i] - b[i];
	}

	sort(c.begin(), c.end());

	ll cnt = 0;
	for (int i = 0; i < n; i++) {
		if (c[i] > 0) {
			break;
		}
		ll tmp = abs(c[i]) / 2;
		cnt += tmp;
		c[i] += tmp * 2;
		if (c[i] < 0) {
			c[i] += 2;
			cnt++;
		}
	}

	sort(c.begin(), c.end());
	for (int i = 0; i < n; i++) {
		cnt -= c[i];
	}
	//cout << cnt << endl;
	if (cnt >= 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	
}

Measured memory_bytes: 3844
import sys
from collections import deque
import bisect
import copy
import heapq
import itertools
import math
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]


def main():
    N, K = read_values()
    A = read_list()
    S = [] # min
    T = [] # max
    D = deque()
    C = 0 # swap count

    for k in range(K):
        a = A[k]
        heapq.heappush(S, (a, k))
        heapq.heappush(T, (-a, k))
        if k > 0:
            c = 1 if A[k - 1] > A[k] else 0
            D.append(c)
            C += c

    r = 0
    F = True if C == 0 else False
    res = 0 if F else 1

    # print(f"A: {A[0:K]}")
    # print(f"S: {S[0][0]}, T: {-T[0][0]}, C: {C}")
    # print(f"res: {res}, F: {F}")
    for i in range(N - K):
        # update swap
        C -= D.popleft()
        c = 1 if A[K + i - 1] > A[K + i] else 0
        D.append(c)
        C += c

        out_a = A[i]
        in_a = A[K + i]
        
        # update T
        heapq.heappush(T, (-in_a, K + i))
        while T[0][1] <= i:
            heapq.heappop(T)

        if C == 0:
            F = True
        else:
            if not (T[0][0] == -in_a and S[0][0] == out_a):
                res += 1

        # print(f"in: {in_a}, out: {out_a}")
        # update S
        heapq.heappush(S, (in_a, K + i))
        while S[0][1] <= i:
            heapq.heappop(S)
        # print(f"S: {S[0][0]}, T: {-T[0][0]}, C: {C}")
        # if K + i + 1 < N:
       #      print(f"A: {A[i + 1:i+K+1]}")
        # print(f"res: {res}, F: {F}")
    if F:
        res += 1
    print(res)


if __name__ == "__main__":
    main()


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

#include <algorithm>
struct Product {long w, v;};

int main(){
  int N, K;
  
  cin >> N;
  K = 2;
  vector<int> H(N);
  int dp[N];
  for (int i=0;i<N;i++) dp[i] = 1000000000;
  for (int i=0;i<N;i++){
    int h;
    cin >> h;
    H[i] = h;
  }

  dp[0] = 0;
  for (int i=1; i<N; i++){
    for(int j=1; j<=K; j++){
      if (i-j>=0) {
	dp[i] = min(dp[i], dp[i-j]+ abs(H[i]-H[i-j]));
      }
    }
  }
  
  cout << dp[N-1] << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;


int main() {
  int k, n;
  cin >> k >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  int mx = k - a[n-1] + a[0];
  rep(i, n){
    mx = max(a[i+1]-a[i], mx);
  }
  cout << k - mx << endl;
  return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
// max 1000 numbers + cr + null = 1002 chars
#define MAX_NUMBERS 1002

int main(void){
    int i,sum;
    char num[MAX_NUMBERS];
    while ( 1 ){
        fgets(num, MAX_NUMBERS, stdin);
        if ( num[0] == '0' ) break;
        i = 0;sum = 0;
        while ( num[i] != '\0' ){
            if ( isdigit(num[i]) ) {
                sum += num[i] - '0';
            }
            i++;
        }
        printf("%d\n", sum);
    }
    return 0;
}


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

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

const char sp = ' ';
const int MOD = 1000000007;

using ll = long long;

ll mod(ll a, ll b){return (a%b+b)%b;}
ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll b, ll e, ll m){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2));}

template<typename T>
void ppp(T n){cout << n << endl;}

vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin >> s;

    vector<string> tmp = split(s, '/');

    string d = tmp[0]+tmp[1]+tmp[2];
    ll aiu = stoi(d);

    if(aiu <= 20190430){
        ppp("Heisei");
    }
    else{
        ppp("TBD");
    }



    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    ll n,d;
    cin >> n >> d;
    cout << (n%(2*d+1)?n/(2*d+1)+1:n/(2*d+1)) << endl;
    return 0;
}

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

using namespace std;

int main() {
    char c11, c12, c13, c21, c22, c23;
    cin >> c11 >> c12 >> c13 >> c21 >> c22 >> c23;
    if (c11 != c23 || c12 != c22 || c13 != c21) puts("NO");
    else puts("YES");
    return 0;
}

Measured memory_bytes: 256
N = int(input())
total = 0
for i in range(N):
    xu = input()
    x_u = xu.split(" ")
    x_u[0] = float(x_u[0])
    
    if x_u[1] == "JPY":
        total += x_u[0]
    else:
        total += x_u[0] * 380000.0
print(total)

Measured memory_bytes: 3060
#include <iostream>
#include <cctype>
#include <cstdio>
#include <cstdlib>
using namespace std;

int main(){
char a[101];
int i,f=0;
cin>>a;
for(i=0; i<101; i++){
if (f==0 && a[i]=='C') f=1;
if (f==1 && a[i]=='F') {
f=2;
break;
}
if(a[i]=='/0') break;
}

if(f==2) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repe(i, n) for(int (i) = 0; i <= (n); (i)++)
#define repr(i, n) for(int (i) = (n); (i) > 0; --(i))
#define repre(i, n) for(int (i) = (n); (i) >= 0; --(i))
#define elm1(pair) (pair).first
#define elm2(pair) (pair)).second
typedef long long ll;
typedef unsigned long long ull;
const ull MOD = 1000000007;
ull mpow(ull a, ull n);
ull inv_mod(ull a){return mpow(a, MOD-2);}

ull mpow(ull a, ull n)
{
    ull ans = 1;
    while(n>>=1){
        if(n & 1)(ans *= a)%= MOD;
        (a*=a)%=MOD;
    }
    return ans;
}

ull nCr(ull n, ull r)
{
    vector<ull> factorial(n+1);
    factorial[0]=1;
    rep(i, n)factorial[i+1] = factorial[i]*(i+1)%MOD;
    return factorial[n]*(inv_mod(factorial[n-r])%MOD*inv_mod(factorial[r])%MOD) % MOD;
}

int main()
{
    string s; cin >> s;
    int ans;
    if(s == "SUN")ans = 7;
    else if(s == "MON") ans = 6;
    else if(s == "TUE") ans = 5;
    else if(s == "WED") ans = 4;
    else if(s == "THU") ans = 3;
    else if(s == "FRI") ans = 2;
    else ans = 1;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	long long h[n];
	int max=0;
	int count=0;
	for(int i=0;i<n;i++)
	{
		cin>>h[i];
	}
	
	long long k=h[0];
	for(int i=1;i<n;i++)
	{
		//k=h[i-1];
		
		if(k>=h[i])
		{
			count++;
			if(max<count)
			{
			max=count;
			}
			k=h[i];
		}
		else
		{
			count=0;
			k=h[i];
		}
	}

	cout<<max;	
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const int INF = 0x3f3f3f3f;
const int N = 100005;
#define ll long long
int cmp(int a,int b){
	return a>b;
}	
int gcd(int x, int y)
{
    while(y^=x^=y^=x%=y);
    return x;
}
int main(){
	int n,m;
	int a[10005];
	cin >> n>>m;
	
	for(int i=0;i<m;i++){
		cin >> a[i] ;
		n-=a[i];
	}
	if(n<0)	 cout << "-1";
	else cout << n;
	
	
	
	return 0;
}



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

int main() {
  int N,K;
  cin >> N >> K;
  
  vector<double> dice(N);
    for(int i=0; i<N;i++) cin >> dice.at(i);//oN
  
  double kmax=0;
  
  for(int o=0;o<K;o++){
    kmax+=dice.at(o);
  }
  double ksum=kmax;
    for(int h=0; h < N-K ; h++){ //h;最大ゾーンを求める回数
      ksum= ksum + dice.at(h+K) - dice.at(h);
      kmax=max(kmax,ksum);
    }
               
  double ans = kmax/2+0.5*K;
  //cout << kmax << endl;
  cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
    int n, cnt=0;
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        if(1==to_string(i).size()){
            cnt++;
        }else if(3==to_string(i).size()){
            cnt++;
        }else if(5==to_string(i).size()){
            cnt++;
        }
    }
    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!int).array;
    auto st = new SegmentTree!(Tuple!(long, long), max, tuple(0L, 0L))(10^^5+1);

    foreach (i; 0..N) {
        auto v = st.query(0, A[i]-1);
        v[0] += 1;
        v[1] += A[i];
        if (v > st.query(A[i], A[i])) {
            st.assign(A[i], v);
        }
    }

    st.query(0, 10^^5)[1].writeln;
}


class SegmentTree(T, alias op, T e) {
    T[] table;
    int size;
    int offset;

    this(int n) {
        size = 1;
        while (size <= n) size <<= 1;
        size <<= 1;
        table = new T[](size);
        fill(table, e);
        offset = size / 2;
    }

    void assign(int pos, T val) {
        pos += offset;
        table[pos] = val;
        while (pos > 1) {
            pos /= 2;
            table[pos] = op(table[pos*2], table[pos*2+1]);
        }
    }

    T query(int l, int r) {
        if (r < l) return e;
        return query(l, r, 1, 0, offset-1);
    }

    T query(int l, int r, int i, int a, int b) {
        if (b < l || r < a) {
            return e;
        } else if (l <= a && b <= r) {
            return table[i];
        } else {
            return op(query(l, r, i*2, a, (a+b)/2), query(l, r, i*2+1, (a+b)/2+1, b));
        }
    }
}



Measured memory_bytes: 9112
#include<iostream>
#include<string>
using namespace std;
int main(){
    int a[10];
    for(int i=0;i<10;i++)
        cin>>a[i];
    for(int i=0;i<9;i++){
      for(int j=9;j>i;j--){
        if(a[j]>a[j-1]){
        int t=a[j];
        a[j]=a[j-1];
        a[j-1]=t;
       }
      }
    }
    cout<<a[0]<<endl;
    cout<<a[1]<<endl;
    cout<<a[2]<<endl;
    return 0;
}
 

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

using ll = long long;
using uint = unsigned int;
template<uint MOD> struct ModInt {
  using M = ModInt;
  uint v;
  ModInt() : v(0) {}
  ModInt(ll _v) { norm(_v % MOD + MOD); }
  M& norm(uint _v) {
    v = (_v < MOD) ? _v : _v - MOD;
    return *this;
  }
  bool operator==(const M x) const { return v == x.v; }
  bool operator!=(const M x) const { return v != x.v; }
  M operator+(const M x) const { return M().norm(v + x.v); }
  M operator-(const M x) const { return M().norm(v + MOD - x.v); }
  M operator*(const M x) const { return M().norm(ll(v) * x.v % MOD); }
  M operator/(const M x) const { return *this * x.inv(); }
  M operator%(const M x) const { return M().norm(v % x.v); }
  M& operator+=(const M x) { return *this = *this + x; }
  M& operator-=(const M x) { return *this = *this - x; }
  M& operator*=(const M x) { return *this = *this * x; }
  M& operator/=(const M x) { return *this = *this / x; }
  friend istream& operator>>(istream& input, M& x) {
    input >> x.v, x.norm(x.v); return input;
  }
  friend ostream& operator<<(ostream& output, const M& x) {
    return output << x.v;
  }
  M pow(ll n) const {
    M x(v), res(1);
    while (n) {
      if (n & 1) res *= x;
      x *= x;
      n >>= 1;
    }
    return res;
  }
  M inv() const { return (*this).pow(MOD - 2); }

  static vector<M> fact, finv;
  static void build(int n) {
    fact.assign(n + 1, 1);
    finv.assign(n + 1, 1);
    for (int i = 1; i < n + 1; i++) fact[i] = fact[i - 1] * M(i);
    for (int i = 0; i < n + 1; i++) finv[i] = fact[i].inv();
  }
  static M comb(int n, int k) {
    if (n < k || k < 0) return M(0);
    return fact[n] * finv[n - k] * finv[k];
  }
};
template<uint MOD> vector<ModInt<MOD>> ModInt<MOD>::fact = vector<ModInt<MOD>>(); 
template<uint MOD> vector<ModInt<MOD>> ModInt<MOD>::finv = vector<ModInt<MOD>>(); 
using mint = ModInt<uint(1e9 + 7)>;

int main() {
  int n, m;
  cin >> n >> m;
  
  mint::build(200000);
  mint rem(m);
  mint ans(1);
  for (int i = 2; i * i < m; i++) {
    int cnt = 0;
    while (rem % i == 0) cnt++, rem /= i;
    ans *= mint::comb(cnt + n - 1, cnt);
  }
  if (rem != 1) ans *= mint::comb(n, 1);

  cout << ans << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<vector>

using namespace std;

typedef long long ll;

int N, X, Y, Z;

const ll MOD = 1000000007;

ll dp[41][1 << 17];

ll modpow(ll a, ll b) {
	ll base = 1, kakeru = a;
	while (b > 0) {
		if (b & 1) {
			base *= kakeru, base %= MOD;
		}
		kakeru *= kakeru, kakeru %= MOD;
		b >>= 1;
	}
	return base;
}

int main() {
	cin >> N >> X >> Y >> Z;

	ll ans = modpow(10, N);

	int forbidden = (1 << (Z - 1)) + (1 << (Z + Y - 1)) + (1 << (Z + Y + X - 1));
	int mask = (1 << (X + Y + Z - 1)) - 1;

	dp[0][0] = 1;
	
	for (int i = 0; i < N; i++) {
		for (int bit = 0; bit < (1 << (X + Y + Z - 1)); bit++) {
			if ((bit & forbidden) == forbidden) continue;

			//cout << i << " " << bit <<

			for (int cur = 1; cur <= 10; cur++) {

				int nxt = (bit << cur) + (1 << (cur - 1));

				if ((nxt & forbidden) == forbidden)continue;
				
				dp[i + 1][nxt & mask] += dp[i][bit];
				dp[i + 1][nxt & mask] %= MOD;
			}
		}
	}

	for (int bit = 0; bit < (1 << (X + Y + Z - 1)); bit++) {
		ans = ans + MOD - dp[N][bit];
		ans %= MOD;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 40192
#include <iostream>
#include <string>
using namespace std;
int main(){
  string s;
  cin >> s;
  int cnt=0;
  int max=0;
  for (int i=0; i <s.size(); i++){
    if (s.at(i) == 'A' || s.at(i) == 'C' || s.at(i) == 'G' || s.at(i) == 'T' )cnt++; 
    else {
      if ( max < cnt) max=cnt;
      cnt=0;
    }
  }
  if ( max < cnt) max=cnt;
  cout << max << endl;
  return 0;
}
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;a++)
#define rl(a,b,c) for(int a=b;a>=c;a--)
#define niv vector<int>
#define LL long long
#define IT iterator
#define PB(a) push_back(a)
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
using namespace std;
const LL INF=100000000000000;
typedef pair<LL,LL> mp;
typedef pair<mp,mp> superpair;
int n,m;
pair<mp,LL> a[1001];
LL dp[1001][1001];
LL res=0;
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m;
	rb(i,1,n) cin>>a[i].FIR.FIR>>a[i].FIR.SEC>>a[i].SEC;
	rb(i,0,1){
		rb(j,0,1){
			rb(k,0,1){	
				memset(dp,0,sizeof(dp));
				rb(i,0,n){
					rb(j,0,m) dp[i][j]=-INF;
					dp[i][0]=0;
				}
				dp[0][0]=0;
				rb(l,1,n){
					LL tmp1=a[l].FIR.FIR,tmp2=a[l].FIR.SEC,tmp3=a[l].SEC;
					if(!i) tmp1*=-1;
					if(!j) tmp2*=-1;
					if(!k) tmp3*=-1;
					rb(p,1,m){
						dp[l][p]=max(dp[l-1][p],dp[l-1][p-1]+tmp1+tmp2+tmp3);
					}
				}
				res=max(res,dp[n][m]);
			}
		}
	}
	cout<<res<<endl;
	return 0;
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  
  if(a == b){
    cout << c << endl;
  }
  else if(b == c){
    cout << a << endl;
  }
  else{
    cout << b << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int countLeapYear(int year1, int year2){
	int count = 0, y;
	for(y = year1; y <= year2; y++){
		if(y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)){
			printf("%d\n", y);
			count++;
		}
	}
	return count;
}

int main(void){
	int startYear, stopYear, d = 0, c;

	while(1){
		scanf("%d %d", &startYear, &stopYear);
		c = 0;
		if(startYear == 0 && stopYear == 0){
			break;
		}
		if(d != 0){
			printf("\n");
		}
		c = countLeapYear(startYear, stopYear);
		if(c == 0){
			printf("NA\n");
		}
		d++;
	}
	return 0;
}

Measured memory_bytes: 616
#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
int main()
{
    long long int x,y,i,j,k,c=0,n,z;
    vector<long long int>v,u,w;
    //string s;
    //map<string,long long int>m;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>x;
        c+=x;
        v.push_back(c);
    }
    c=0;
    for(i=0;i<n;i++)
    {
         cin>>x;
        c+=x;
        u.push_back(c);
    }
    c=0;
    k=0;
    for(i=0;i<n;i++)
    {

        //x=v[v.size()-1];
        y=u[u.size()-1];
        z=y+v[i]-k;
        w.push_back(z);
        k=u[i];
    }
    sort(w.begin(),w.end());
    cout<<w[w.size()-1]<<endl;
    return 0;

}


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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int P, Q, R; cin >> P >> Q >> R;
    cout << min(min(P+Q, Q+R), R+P) << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

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

highest = int(math.sqrt(n))
l = [0]*n
cal = 0

for x in range(1, highest+1):
  for y in range(1, highest+1):
    for z in range(1, highest+1):
      cal = x**2 + y**2 + z**2 + x*y + y*z + z*x
      if cal > n:
        continue
      else:
        l[cal-1] += 1
        
for i in range(len(l)):
  print(l[i])


Measured memory_bytes: 9140
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = INF+7;
const ll LINF = 1e18;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>0;--i)
#define FOR(i,j,N) for(int (i)=(j);(i)<(N);++(i))
#define put(n) cout<<(n)<<endl;
#define all(v) v.begin(),v.end()
#define MP make_pair
#define pb(n) push_back(n)
#define int long long 

signed main(){
   int N,K;
   cin >> N >> K;
   if(K <= (N+1)/2) cout << "YES" << endl;
   else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int f(int a,int k){
	if(a%k==0){
		return a/k; 
	}
	if(a<k){
		return 0;
	}
	int x=max(1,(a-a/k*k)/(a/k+1));
	return f(a-x*(a/k+1),k);
}
int main() {
	int N;
	cin >> N;
	LL r=0;
	for(int i=0;i<N;i++){
		int a,k;
		cin >> a >> k;
		r^=f(a,k);
	}

	if(r==0){
		cout << "Aoki" << endl;
	}
	else{
		cout << "Takahashi" << endl;
	}
	return 0;
}



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

//~ #pragma GCC optimize("O3")

using namespace std;

#define all(x) (x).begin(), (x).end()

typedef long long ll;

bool is_palindrome(string s) {
	string t(s.rbegin(), s.rend());
	return s == t;
}

void solve(){
	string s;
	cin >> s;
	bool is;
	int n = s.size();
	is = is_palindrome(s) && is_palindrome(s.substr(0, (n-1)/2)) && is_palindrome(s.substr((n+1/2)));
	
	cout << (is ? "Yes" : "No");
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    solve();
    
    return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long LL;
template <typename F, typename S> std::ostream& operator<<(ostream& os, const pair<F,S>& p) {
    os << "(" << p.first << "," << p.second << ")"; return os; }
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "["; for(const T& a: v){ os << a << ", "; } os << "]"; return os; }
template <typename K, typename V> ostream& operator<<(ostream& os, const map<K,V>& m) {
    os << "{"; for(const auto& p: m){ os << p.first <<":"<< p.second << ", "; } os << "}"; return os; }


bool check(vector<LL>& a, vector<LL>& rest, LL d, LL k){
    LL n = a.size();
    for(LL i = 0; i < n; ++i){
        rest[i] = a[i] % d;
    }
    sort(rest.begin(), rest.end());
    LL cur = 0;
    LL sub_total1 = 0;
    while(cur < n){
        if(sub_total1 + rest[cur] > k) break;
        sub_total1 += rest[cur];
        ++cur;
    }
    LL sub_total2 = (n-cur) * d - accumulate(rest.begin() + cur, rest.end(), 0);
    return sub_total2 <= k;
}

int main(){
    LL n, k;
    cin >> n >> k;
    vector<LL> a(n);
    for(LL i = 0; i < n; ++i){
        cin >> a[i];
    }
    LL total = accumulate(a.begin(), a.end(), 0);
    cerr << "total=" << total << endl;
    LL ans = 1;
    vector<LL> rest(n);
    for(LL d = 1; d <= 1000000; ++d){
        if(total % d != 0) continue;
        if(check(a, rest, d, k)) ans = max(ans, d);
        if(check(a, rest, total / d, k)) ans = max(ans, total / d);
    }

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



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

signed main()
{
  bool prime[1000005];

  fill_n(prime, 1000005, true);
  prime[1] = false;
  for(int i = 2; i * i <= 1000005; i++) {
    if(prime[i]) {
      for(int j = i * i; j <= 1000005; j += i) prime[j] = false;
    }
  }

  int A, D, N;
  
  while(cin >> A >> D >> N, A || D || N) {
    int cnt = 0;
    while(cnt < N) {
      cnt += prime[A];
      A += D;
    }
    cout << A - D << endl;
  }

  return 0;
}

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

H,W,h,w = map(int,input().split())

if H%h == 0 and W%w == 0:
    print('No')
    exit()

x,y = H//h, W//w
s = x*y + 1
t = (h*w-1) * s + 1

import numpy as np
grid = np.full((H+1, W+1), s, dtype=np.int32)
grid[::h,::w] = -t
grid = grid[1:,1:]

print('Yes')
for row in grid:
    print(' '.join(row.astype(str)))

Measured memory_bytes: 15204
# -*- coding: utf-8 -*-
n = int(input())
a = [int(i) for i in input().split()] 

a.sort(reverse = True)
tmp = []
i = 0
while i < n - 1:
    if a[i] == a[i + 1]:
        tmp.append(a[i])
        i += 2
    else:
        i += 1
if len(tmp) >= 2:
    print(tmp[0] * tmp[1])
else:
    print(0)

Measured memory_bytes: 14252
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<iomanip>
#include<sstream>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cout << '\n';}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << '[' << *it << " = " << a << "]  ";
    err(++it, args...);
}

#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<lli, lli> tii;
typedef tuple<lli, lli, lli> tiii;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;


void solve(){
	int n,k; cin>>n>>k;
	int di,h;
	vi a(n+1,0);
	rep(i,k){
		cin>>di;
		rep(j,di){
			cin>>h;
			a[h]++;
		}	
	}
	int ans=0;
	repp(i,1,n+1){
		if(a[i]==0) ans++;
	}
	cout<<ans;
}

int main(){
	fast_io
	int tc=1;
	//cin>>tc;
	while(tc--){solve();}
	return 0;
}

Measured memory_bytes: 3140