akhauriyash/Code-Regression huggingface dataset:
const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const inputs = input.trim().split('\n');
const n = Number(inputs[0]);
const adj = inputs.slice(1).map((s) => s.split(' ').map(Number));

const G = (new Array(n)).fill(0).map(() => (new Array(n)).fill(0));
for (let i = 0; i < n; i++) {
  const u = adj[i][0];
  const k = adj[i][1];
  const vj = adj[i].slice(2);

  for (let j = 0; j < k; j++) {
    G[u - 1][vj[j] - 1] = 1;
  }
}

for (let i = 0; i < G.length; i++) {
  console.log(G[i].join(' '));
}



Measured memory_bytes: 16484
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, n+1)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define whole(x) (x).begin(),(x).end()
#define rwhole(x) (x).rbegin(), (x).rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define P pair<int, int>
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin >> s;
    string ans = "";
    for (char c: s) {
        if (c=='B') {
            if (ans.size()==0) continue;
            ans.pop_back();
        }
        else {
            ans += c;
        }
    }
    
    cout << ans << endl;
    return 0;
}


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

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

const long long INF = 1LL << 60;

int N;
long long h[100010];

long long dp[100010];

int main(){
    int N; cin >> N;
    for(int i = 0; i < N; ++i) cin >> h[i];

    for(int i = 0; i < 100010; ++i) dp[i] = INF;

    dp[0] = 0;

    for(int i = 0 ; i < N; ++i){
        chmin(dp[i+1],dp[i] + abs(h[i] - h[i+1]));
        chmin(dp[i+2],dp[i] + abs(h[i] - h[i+2]));
    }
    cout << dp[N-1] << endl;

    return 0;
}

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

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

int main()
{
int i;
int j;
int k;
int A;
int B;
int C;
int X;
int iCnt;

	cin >> A;
	cin >> B;
	cin >> C;
	cin >> X;

	iCnt = 0;
	rep( i, A )
	{
		rep( j, B )
		{
			rep( k, C )
			{
				if( 500 * i + 100 * j + 50 * k == X )
					iCnt++;
			}
		}
	}

	cout << iCnt << endl;

	return 0;
}

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

int main(){
  int N;
  float X;
  cin>>N;
  X=ceil(N/1.08);
  if(floor(X*1.08)==N){
    cout<<X<<endl;
    return 0;
  }
  cout<<":("<<endl;
  return 0;
}



    

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

vector<bool> can_use(10, true);
vector<int> candidates;

int get_digit(int n){
  for (int j = n; j < 10; ++j) {
    if(can_use[j]){
      return j;
    }
  }


  for (int j = 0; j < n; ++j) {
    if(can_use[j]){
      return j;
    }
  }
}

int to_int( vector<int> ans){
  int ret = ans[ans.size()-1];
  for (int i = ans.size()-2; i >= 0; --i) {
    ret = ret * 10 + ans[i];
  }
  return ret;

}

void dfs(int i, int n){
  if(i == 0) {
    candidates.push_back(n);
    return;
  }

  for (int j = 0; j < 10; ++j) {
    if(can_use[j]){
      dfs(i-1, n*10 + j);
    }
  }


}

int main() {

  //
  int N, K, k;
  cin >> N >> K;

  for (int i = 0; i < K; ++i) {
    cin >> k;
    can_use[k] = false;
  }

  string str_n = to_string(N);
  int n = str_n[0] - '0';
  for (int i = 1; i < 10; ++i) {
    if(can_use[i] ){
      dfs(str_n.size()-1, i);
      dfs(str_n.size(), i);
    }
  }

  int diff=pow(10, 7), ans;
  for(int n: candidates){
    if(n >= N && (n-N) < diff){
      ans = n;
      diff = (n-N);
    }
  }
  cout << ans << endl;


  return 0;
}



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

int main(void) {
	int N, M, X;
	scanf("%d %d %d", &N, &M, &X);
	int A[100];
	for (int i = 0; i < M; i++) {
		scanf("%d", &A[i]);
	}
	int right = 0, left = 0;
	for (int i = 0; i < M; i++) {
		if (A[i] > X) right++;
		else left++;
	}
	printf("%d\n", min(right, left));

	return 0;
}


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

int main(void){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int H, A;
    cin >> H >> A;

    int cnt = 0;
    while(1){
        if(H <= 0){
            cout << cnt;
            break;
        }
        H -= A;
        cnt ++;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fst first
#define snd second
#define rep(n) for(lint I = 0; (I) < (lint)(n); ++(I))
#define repeat(i, n) for(lint i = 0; (i) < (lint)(n); ++(i))
#define repeat_to(i, n) for(lint i = 0; (i) <= (lint)(n); ++(i))
#define repeat_from(i, m, n) for(lint i = (m); (i) < (lint)(n); ++(i))
#define repeat_from_to(i, m, n) for(lint i = (m); (i) <= (lint)(n); ++(i))
#define repeat_reverse_from_to(i, m, n) for(lint i = (m); (i) >= (lint)(n); --(i))
#define el cout<<endl
#define es cout<<" "
#define dump(x) cout<<" "<<#x<<"="<<x
#define pdump(p) cout<<" "<<#p<<"=("<<p.fst<<","<<p.snd<<")"
#define vdump(v) for(size_t I=0; I<v.size(); ++I){cout<<" "<<#v<<"["<<I<<"]="<<v[I];} cout<<endl
using namespace std; using lint = long long; using ld = long double;
using pii = pair<int, int>; using pll = pair<lint, lint>;
template<class T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<class T, class... Ts> 
auto make_vec(size_t a, Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));}

int main(void) {
    lint n; cin >> n;
    vector<lint> v(5);
    repeat (i, 5) cin >> v[i];
    
    lint bottle = 1e18;
    repeat (i, 5) bottle = min(bottle, v[i]);
    
    lint k;
    if (n % bottle != 0) k = (n / bottle) + 1;
    else k = (n / bottle);
    
    cout << 5LL + (k - 1) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)  {
  int a, b, c, temp;
  scanf("%d %d %d", &a, &b, &c);
  
  if (a > c)  {
    temp = a;
    a = c;
    c = temp;
  }

  if (a > b)  {
    temp = a;
    a = b;
    b = temp;
  }
  
  if (b > c)  {
    temp = b;
    b = c;
    c = temp;
  }
    
  printf("%d %d %d\n", a, b, c);

  return 0; 
}

Measured memory_bytes: 1848
n, q = list(map(int, input().split()))
works = []
for i in range(n):
    works.append(list(input().split()))
 
count = 0
while len(works) != 0:
    work = works.pop(0)
    time = int(work[1])
    if time > q:
        count += q
        work[1] = time - q
        works.append(work)
    else:
        count += time
        print(work[0] , count)


Measured memory_bytes: 14288
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

#define nnm(x, y) (((y) + (x) % (y)) % (y))
template<typename T> inline T gcd(T x, T y) { if(x < y) swap(x, y); T mod = x % y; if(mod == 0) return y; return gcd(y, mod); }
template<typename T> inline T lmc(T x, T y) { return x / gcd(x, y) * y; }

int N, Q;

int root(int c)
{
	return (c - 2) / N + 1;
}

int main(int argc, char* argv[])
{
	scanf("%d%d", &N, &Q);

	for (int i = 0; i < Q; i++) {
		if (N == 1) {
			int a, b;
			scanf("%d%d", &a, &b);
			printf("%d\n", min(a, b));
		} else {
			stack<int> v;
			stack<int> w;
			int a, b;
			scanf("%d%d", &a, &b);
			v.push(a);
			w.push(b);
			while (v.top() != 1) {
				v.push(root(v.top()));
			}
			while (w.top() != 1) {
				w.push(root(w.top()));
			}
			int ans = 1;
			while (!v.empty() && !w.empty() && v.top() == w.top()) {
				ans = v.top();
				v.pop(); w.pop();
			}
			printf("%d\n", ans);
		}
	}

	return 0;
}


Measured memory_bytes: 1280
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
    ll N, K;
    cin >> N >> K;
    ll a[N];
    ll s[N + 1];
    s[0] = 0;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        s[i + 1] = s[i] + a[i];
    }

    for(int i = 0; i <= N; i++){
        s[i] -= i;
        s[i] %= K;
    }

    ll ans = 0;
    int sz = 0;
    map<ll, int> mp;
    for(int i = 0; i <= N; i++){
        if(sz >= K){
            mp[s[i - K]]--;
            //cout << "erase " << s[i - K] << endl;
        }

        ans += mp[s[i]];

        sz++;
        mp[s[i]]++;

        //cout << "insert " << s[i] << endl;
    }

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


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

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<typename T> void view(T cont) {std::cout << cont << std::endl;}
template<typename T> void view(T* cont, ll sz) {rep(i, sz) std::cout << cont[i] << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<T>& v) {for (const auto& f: v) std::cout << f << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v: vv) {view(v);}}

#define MAX_N 86
vector<ll> lucas(MAX_N+1, -1);

ll lucas_seq(int n) {
    if (n == 0) {
        lucas[n] = 2;
        return 2;
    }
    if (n == 1) {
        lucas[n] = 1;
        return 1;
    }
    ll l_1, l_2;
    if (lucas[n - 1] != -1) {
        l_1 = lucas[n - 1];
    } else {
        lucas[n - 1] = lucas_seq(n - 1);
        l_1 = lucas[n - 1];
    }
    if (lucas[n - 2] != -1) {
        l_2 = lucas[n - 2];
    } else {
        lucas[n - 2] = lucas_seq(n - 2);
        l_2 = lucas[n - 2];
    }
    return l_1 + l_2;
}

int main(){
    int N; cin >> N;
    cout << lucas_seq(N) << endl;
    // view(lucas);
}

Measured memory_bytes: 256
#include <stdio.h>
#define STACK_SIZE 500
#define MAX_LEN 500

int stack[STACK_SIZE];
int stack_size = 0;

int pop()
{
  if (stack_size <= 0) return 0;
  return stack[--stack_size];
}

int push(int a)
{
  stack[stack_size++] = a;
}

int is_digit(char *s)
{
  
  if (*s == '+' || *s =='-') {
    s++;
    if (*s >= '0' && *s <= '9') return 1;
    return 0;
  }
  if (*s >= '0' && *s <= '9') return 1;
  return 0;
}

int get_number(char *s)
{
  int sign = 0, n = 0;
  if (*s == '+') {
    s++;
  } else if (*s == '-') {
    sign = 1;
    s++;
  }
  
  while (*s >= '0' && *s <= '9') {
    n = n * 10 + (*s - '0');
    s++;
  }
  
  if (sign) return -n;
  return n;
}

int calc_rpn(char *s)
{
  int a, b, n;
  while (*s) {
    
    if (is_digit(s)) {
      n = get_number(s);
      push(n);
      while (*s == '-' || *s == '+') {
	s++;
      }
      while (n) {
	n /= 10;
	s++;
      }
      
    } else {
      switch (*s) {
      case '+':
	a = pop();
	b = pop();
	push(b+a);
	break;
      case '-':
	a = pop();
	b = pop();
	push(b-a);
	break;
      case '*':
	a = pop();
	b = pop();
	push(b*a);
	break;
      case '/':
	a = pop();
	b = pop();
	if (a == 0) break;
	push(b/a);
	break;
      case '%':
	a = pop();
	b = pop();
	if (a == 0) break;
	push(b%a);
      }
      s++;
    }
  }
  return pop();
}

int main()
{
  char s[MAX_LEN];
  scanf("%[^\n]*s", s);
  printf("%d\n",calc_rpn(s));
}



Measured memory_bytes: 2108
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, m, R;
int r[10];
int a[20010], b[20010], c[20010];

int d[210][210];

void warshall_floyd() {
    for (int k = 0; k < n; k++)
	for (int i = 0; i < n; i++)
	    for (int j = 0; j < n; j++)
		d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}

int solve() {
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            d[i][j] = inf;
    for (int i = 0; i < m; i++) {
        d[a[i]][b[i]] = d[b[i]][a[i]] = c[i];
    }

    warshall_floyd();

    int idx[R];
    for (int i = 0; i < R; i++) idx[i] = i;
    int res = inf;
    do {
        int dist = 0;
        for (int i = 0; i < R-1; i++) {
            dist += d[r[idx[i]]][r[idx[i+1]]];
        }
        res = min(res, dist);
    } while (next_permutation(idx, idx+R));
    return res;
}

void input() {
    cin >> n >> m >> R;
    for (int i = 0; i < R; i++) {
        cin >> r[i];
        r[i]--;
    }
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;
        b[i]--;
    }
}

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

    input();
    cout << solve() << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int a,b,c,x,ans=0;
	scanf("%d%d%d%d",&a,&b,&c,&x);
	x/=50;
	for (int i = 0;i <= a;++i){
		for (int j = 0;j <= b;++j){
			for (int k = 0;k <= c;++k){
				if (10*i+2*j+k == x) ++ans;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

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

int main(){
    
    int n;
    const int hei = -2;
    cin >> n;
    if(n == 0){
        cout << 0 << endl;
        return 0;
    }
    vector<string> hai;
    while((n != 1)){
        if(abs(n)%2 == 1){
            hai.push_back("1");
            if(n<0){
                n = n/hei + 1;
            }
            else{
                n = n/hei;
            }
        }
        else{
            hai.push_back("0");
            n = n/hei;
        }
    }
    hai.push_back("1");
    for(int i=hai.size()-1; i>=0; i--){
        cout << hai.at(i);
    }
}


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

void solve(long long N, vector<long long> A){
	long long sum = 0;
  long long p = 0;
  for (long long i = 1; i <= N; i++) {
    p += i;
  }
  for (long long i = 0; i < A.size(); i++) {
    A[i] %= p;
    sum += A[i];
  }
  if (sum % p != 0) {
    cout << "NO" << endl;
    return;
  }

  vector<long long> d;
  for (long long i = 0; i < A.size() - 1; i++) {
    long long j = A[i+1] - A[i] - sum / p;
    if (j <= 0 && (j * -1) % N == 0) {
    } else {
      cout << "NO" << endl;
      return;
    }
  }
  cout << "YES" << endl;
}

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> A(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&A[i]);
	}
	solve(N, A);
	return 0;
}



Measured memory_bytes: 1792
#!/usr/bin/env python3


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main(n, k, a):
    ck=[-1]*n
    tak=0
    c=0
    ck[0]=c
    for i in range(n):
        c+=1
        tak=a[tak]-1
        if ck[tak]!=-1:
            loop=c-ck[tak]
            lps=ck[tak]
            break
        ck[tak]=c

    tak=0
    for i in range(min(k, (k-lps)%(loop)+lps)):
        tak=a[tak]-1

    print(tak+1)


if __name__ == '__main__':
    n,k=map(int, input().split())
    a=list(map(int, input().split()))
    main(n, k, a)


Measured memory_bytes: 32312
N, Q = map(int,input().split())
S = str(input())
count = 0
li = [0]
for i in range(N-1):
    if S[i:i+2] == "AC":
        count += 1
    li.append(count)
for i in range(Q):
    l,r = map(int,input().split())
    print(li[r-1]-li[l-1])

Measured memory_bytes: 6100
import java.util.Arrays;
import java.util.Random;

//The Closest Circle
public class Main{

	class Scanner {
		int nextInt() {
			try {
				int c = System.in.read();
				while (c != '-' && (c < '0' || '9' < c))
					c = System.in.read();
				if (c == '-') return -nextInt();
				int res = 0;
				do {
					res *= 10;
					res += c - '0';
					c = System.in.read();
				} while ('0' <= c && c <= '9');
				return res;
			} catch (Exception e) {
				return -1;
			}
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
		String next() {
			try {
				StringBuilder res = new StringBuilder("");
				int c = System.in.read();
				while (Character.isWhitespace(c))
					c = System.in.read();
				do {
					res.append((char) c);
				} while (!Character.isWhitespace(c = System.in.read()));
				return res.toString();
			} catch (Exception e) {
				return null;
			}
		}
	}
	
	class R implements Comparable<R>{
		double x, y, r;
		public R(double x, double y, double r) {
			this.x = x;
			this.y = y;
			this.r = r;
		}
		public int compareTo(R o) {
			if(Math.abs(x-o.x)<EPS)return (int)Math.signum(y-o.y);
			return (int)Math.signum(x-o.x);
		}
	}
	
	double EPS = 1e-8;
	
	void run(){
		Scanner sc = new Scanner();
		Random rand = new Random(System.currentTimeMillis());
		for(;;){
			int n = sc.nextInt();
			if(n==0)break;
			int rot = rand.nextInt(44)+1;
			double sin = Math.sin(rot*Math.PI/180), cos = Math.cos(rot*Math.PI/180);
			R[] rs = new R[n];
			for(int i=0;i<n;i++){
				double r = sc.nextDouble(), x = sc.nextDouble(), y = sc.nextDouble();
				rs[i] = new R(cos*x-sin*y, sin*x+cos*y, r);
			}
			Arrays.sort(rs);
			double res = 1L<<60;
			for(int i=0;i<n;i++){
				int t = Math.min(n, i+5);
				for(int j=i+1;j<t;j++){
					res = Math.min(res, Math.sqrt((rs[i].x-rs[j].x)*(rs[i].x-rs[j].x) + (rs[i].y-rs[j].y)*(rs[i].y-rs[j].y))-rs[i].r-rs[j].r);
				}
			}
			System.out.printf("%.9f\n", res);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

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

using namespace std;

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

const ll maxn =2e6+100;
const ll mod = 1e9+7;
const ld PI = 4 * atan((ld) 1);

#define pb(x) push_back(x);
#define endl '\n'
#define dominance true
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define ms(x , y) memset(x , y , sizeof x);
ll pw(ll a, ll b) {
    return (!b ? 1 : (b & 1 ? a * pw(a * a % mod, b / 2) % mod : pw(a * a % mod, b / 2) % mod));
}

int a , b , m;
int r[maxn] , mc[maxn] , c[maxn];
int x[maxn] , y[maxn];
int mn = 1e9 , mnr = 1e9 , mnm = 1e9;

int main(){
    migmig
    cin >> a >> b >> m;
    for (int i = 0 ; i < a ; i ++){
        cin >> r[i];
        mnr = min(mnr , r[i]);
    }
    for (int i = 0 ; i < b ; i ++){
        cin >> mc[i];
        mnm = min(mnm , mc[i]);
    }
    mn = min(mn , mnm + mnr);
    for (int i = 0 ; i < m ; i ++){
        cin >> x[i] >> y[i] >> c[i];
        mn = min(mn , r[x[i] - 1] + mc[y[i]  - 1] - c[i]);
    }
    cout << mn;
    return(0);
}

//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, life is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you will come to a better place.
//It is important to draw wisdom from diffrent places. If you take it from only one place it becomes rigid and stale.
//kuxtal jach uts chuchul u u páajtal máak jach táaj meyajilo'ob le castigadas tumen ch'aik descansos.


Measured memory_bytes: 10880
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    int n;
    int dp[199999]={};
    int tmp=1;
    
    cin >> n;
    
    for(int i=0; i<=199999; i++){
        
        dp[i]=199999;
        
    }
    
    dp[0] = 0;
    
    for(int i=0; i<=n; i++){
        
        dp[i+1] = min(dp[i+1], dp[i]+1);
        
        for(int k=1; k<=6; k++){
            
            tmp = pow(6, k);
            dp[i+tmp] = min(dp[i+tmp], dp[i]+1);
            
        }
        
        for(int k=1; k<=5; k++){
            
            tmp = pow(9, k);
            dp[i+tmp] = min(dp[i+tmp], dp[i]+1);
            
        }
        
    }
    
    cout << dp[n] << endl;
    
    return 0;
    
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main() {
  int n, t;
  cin >> n >> t;
  int ans = INF;

  rep (i, n) {
    int c, tt;
    cin >> c >> tt;
    if (tt <= t) {
      ans = min(c, ans);
    }
  }
  if (ans == INF) {
    P("TLE");
  } else {
    P(ans);
  }


  return 0;
}



Measured memory_bytes: 256
n,k = map(int, raw_input().split())
aa = map(int, raw_input().split())

max_a = aa[0]

if n == 1:
  if aa[0] == k:
    print 'POSSIBLE'
  else:
    print 'IMPOSSIBLE'
  exit()

b = aa[0]
for i in range(1,n):
  a = aa[i]
  max_a = max(a, max_a)

  a,b = max(a,b), min(a,b)
  while a % b != 0:
    if a > b:
      a %= b
    else:
      b %= a
    a,b = max(a,b), min(a,b)

if k > max_a:
  print 'IMPOSSIBLE'
elif k % b == 0:
  print 'POSSIBLE'
else:
  print 'IMPOSSIBLE'
  

Measured memory_bytes: 11296
#![allow(non_snake_case, unused_macros, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} };}
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,BTreeMap,VecDeque};

// Main
fn main(){
    input!{
        H: usize,
        W: usize,
        K: usize,
    }
    

    // 左隣(あるいは右隣)にn本の縦棒があり、真横と繋がっている時の場合の数
    let j = vec![0,1,1,2,3,5,8,13];
    // 左隣(あるいは右隣)にn本の縦棒があり、真横と繋がっていない時の場合の数
    let m = vec![1,1,2,3,5,8,13,21];

    // dp[h][w] : h行目を終えた時点でwにいる場合の数
    let mut dp = vec![vec![0 as u64; W]; H+1];
    // 初期化 : 最初は左端固定
    dp[0][0] = 1;

    // dpを更新
    for h in 1..H+1{
        for w in 0..W{
            // 右に移動
            if w != 0{
                dp[h][w] += dp[h-1][w-1] * j[w] * m[W-1-w];
            }
            // 左に移動
            if w != W-1{
                dp[h][w] += dp[h-1][w+1] * m[w] * j[W-1-w];
            }
            // 真下に移動
            dp[h][w] += dp[h-1][w] * m[w] * m[W-1-w];
            // 割った余り
            dp[h][w] %= 1_000_000_007;
        }
    }
    
    println!("{}", dp[H][K-1]);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define ll long long
#define str string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define inf 1000000000
#define mod 1000000007
#define pi atan(1) * 4
using namespace std;
int num[200005];
pii oseg[262200], eseg[262200];
pii lazy[524400];
set<int> taken;
int x, y;
pii z;
void rgeupd (int l, int r, int i) {
	if (l > y || r < x) return;
	else if (x <= l && r <= y) {
		lazy[i] = z; return;
	}
	int m = (l + r) >> 1;
	rgeupd(l, m, i << 1); rgeupd(m + 1, r, (i << 1) + 1);
	if (lazy[i << 1].fi < lazy[(i << 1) + 1].fi) lazy[i] = lazy[i << 1];
	else lazy[i] = lazy[(i << 1) + 1];
	return;
}
pii query (pii *seg, int l, int r, int i) {
	if (l > y || r < x) return {inf, -1};
	else if (x <= l && r <= y) return seg[i];
	int m = (l + r) >> 1;
	pii lc = query(seg, l, m, i << 1);
	pii rc = query(seg, m + 1, r, (i << 1) + 1);
	if (lc.fi < rc.fi) return lc;
	else return rc;
}
void updatelazy (int e, int f) {
	if (e & 1) {
		x = (e >> 1) + 1; y = ((f - 1) >> 1) + 1; z = query(oseg, 1, 131072, 1);
	} else {
		x = e >> 1; y = (f - 1) >> 1; z = query(eseg, 1, 131072, 1);
	}
	x = e; y = f; rgeupd(1, 262144, 1);
	return;
}
int main () {
	int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q;
	scanf("%d", &a);
	for (i = 0; i < 262200; i++) {
		oseg[i] = eseg[i] = {inf, -1};
	}
	for (i = 0; i < 524400; i++) {
		lazy[i] = {inf, -1};
	}
	for (i = 1; i <= a; i++) {
		scanf("%d", &b); num[i] = b;
		if (i & 1) oseg[131072 + (i >> 1)] = {b, i};
		else eseg[131071 + (i >> 1)] = {b, i};
	}
	for (i = 131071; i >= 1; i--) {
		if (oseg[i << 1].fi < oseg[(i << 1) + 1].fi) oseg[i] = oseg[i << 1];
		else oseg[i] = oseg[(i << 1) + 1];
		if (eseg[i << 1].fi < eseg[(i << 1) + 1].fi) eseg[i] = eseg[i << 1];
		else eseg[i] = eseg[(i << 1) + 1];
	}
	x = 1; y = a; z = oseg[1];
	rgeupd(1, 131072, 1);
	pii r, s, t; taken.insert(0); taken.insert(a + 1);
	for (i = 1; i <= a; i += 2) {
		r = lazy[1];
		c = r.se + 1; d = *(taken.upper_bound(r.se)) - 1;
		if (c & 1) {
			x = (c >> 1) + 1; y = (d >> 1) + 1;
			s = query(oseg, 1, 131072, 1);
		} else {
			x = c >> 1; y = d >> 1;
			s = query(eseg, 1, 131072, 1);
		}
		printf("%d %d%c", num[r.se], num[s.se], (i == a - 1) ? '\n' : ' '); 
		x = y = r.se; z = {inf, -1}; rgeupd(1, 262144, 1);
		x = y = s.se; z = {inf, -1}; rgeupd(1, 262144, 1);
		updatelazy((*(--taken.upper_bound(r.se))) + 1, r.se - 1);
		updatelazy(r.se + 1, s.se - 1);
		updatelazy(s.se + 1, (*taken.upper_bound(s.se)) - 1);
		taken.insert(r.se); taken.insert(s.se);
	}
	return 0;
}

Measured memory_bytes: 19840
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main() {
  string s,t;
  cin >> s >> t;
  cout << t << s << endl;
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main() {
    int N, A, ans = 1, ng = 1;
    cin >> N;
    rep(i, N) {
        ans *= 3;
        cin >> A;
        if (A % 2 == 0) {
            ng *= 2;
        }
    }
    cout << ans - ng << "\n";
}

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

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

int main()
{
    string S;
    char c;
    int Q, T, F, N, direct = 1;
    cin >> S;
    N = S.length();
    cin >> Q;
    deque<char> res;
    REP(i, N)
    {
        res.push_back(S[i]);
    }

    REP(i, Q)
    {
        cin >> T;
        if (T == 1)
        {
            direct ^= 1;
        }
        else
        {
            cin >> F;
            cin >> c;
            if ((F - 1) ^ direct)
            {
                res.push_front(c);
            }
            else
            {
                res.push_back(c);
            }
        }
    }

    if (direct)
    {
        while (res.size())
        {
            cout << res.front();
            res.pop_front();
        }
    }
    else
    {
        while (res.size())
        {
            cout << res.back();
            res.pop_back();
        }
    }
    cout << endl;
}

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

#define rep1(i, a, n) for (int i = a; i < n; i++)
#define rep2(i, a, n) for (int i = n; i >= a; i--)
#define asc(v) sort(v.begin(), v.end())
#define desc(v) sort(v.begin(), v.end(), greater<int>())

using namespace std;

int main() {
  string s;
  cin >> s;
  int ans = 0;
  rep1(i, 0, s.size()) { ans += s[i] == '+' ? 1 : -1; }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

const (
	initialBufSize = 10000
	maxBufSize     = 1000000
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
	mod int = 1e9 + 7
)

func genAs(subS string) (as []int) {
	index := strings.Index(subS, "<>")
	if index == -1 {
		if subS[0] == '<' {
			for i := 0; i < len(subS); i++ {
				as = append(as, i + 1)
			}
		} else {
			for i := 0; i < len(subS); i++ {
				as = append(as, len(subS) - (i + 1))
			}
		}
	} else {
		for i := 0; i < index; i++ {
			as = append(as, i + 1)
		}
		for i := 0; i < len(subS) - index; i++ {
			if index != 0 && i == 0 {
				if as[len(as) - 1] >= len(subS) - index - (i + 1) {
					as = append(as, as[len(as) - 1] + 1)
					continue
				}
			}
			as = append(as, len(subS) - index - (i + 1))
		}
	}

	return
}

func main() {
	S := getString()
	var as []int

	tmpS := S
	for ; ; {
		index := strings.Index(tmpS, "><")
		if index == -1 {
			as = append(as, genAs(tmpS)...)
			break
		}

		as = append(as, genAs(tmpS[:index + 1])...)
		tmpS = tmpS[index + 1:]
	}

	if S[0] == '<' {
		as = append([]int{0}, as...)
	} else {
		as = append([]int{as[0] + 1}, as...)
	}

	sum := 0
	for _, a := range as {
		sum += a
	}
	fmt.Println(sum)
}

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray) - 1])
}

func calcMod(x int) int {
	return x % mod
}


Measured memory_bytes: 23296
N = int(input())
A = list(map(int,input().split()))
C1 = 0
C2 = 0
for i in range(N):
    if A[i] % 2 == 0 :
        C1 += 1
        if A[i] % 3 == 0 or A[i] % 5 == 0:
            C2 += 1
if C1 == C2:
    print('APPROVED')
else:
    print('DENIED')

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

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


Measured memory_bytes: 3944
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    unordered_map<string,int>m;
    long long ans=0;
    string s;
    for(int i=0;i<n;i++){
        cin >> s;
        sort(s.begin(),s.end());
        ans+=m[s];
        m[s]++;
    }
    cout << ans;
}

Measured memory_bytes: 10660
#include<cstdio>
#define min(a,b) (a<b?a:b)
#define max(a,b) (a<b?a:b)
int n,c;
const long long mod=1e9+7;
int A[405],B[405];
long long matmod(long long val,long long k){
	long long ret=1;
	for(;k;k>>=1){
		if(k&1) ret=(val*ret)%mod;
		val=(val*val)%mod;
	}
	return ret;
}
void add(long long &des,long long sor){des+=sor;des%=mod;return ;}
long long sum[405][405],f[405][405];
int main(){
	//freopen("candies.in","r",stdin);
	//freopen("candies.out","w",stdout);
	scanf("%d%d",&n,&c);
	for(int i=1;i<=n;i++) scanf("%d",&A[i]);
	for(int i=1;i<=n;i++) scanf("%d",&B[i]);
	for(int i=0;i<=c;i++){
		for(int j=1;j<=400;j++)
			add(sum[i][j],sum[i][j-1]+matmod(j*1ll,i*1ll));
	}
	f[0][0]=1;
	for(int i=1;i<=n;i++){
		for(int j=0;j<=c;j++)
			for(int k=j;k>=0;k--)
				add(f[i][j],f[i-1][j-k]*(sum[k][B[i]]-sum[k][A[i]-1]+mod)%mod);
	}
	printf("%lld\n",f[n][c]);
	return 0;
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
using namespace std;
int GCDserch(long long int a,long long int b)
{
    if(a%b==0)return b;
    return GCDserch(b,a%b);
}
int main()
{
    long long int a,b,ch,GCD,LCM;
    while(cin>>a>>b){
            if(b>a){
                ch=a;
                a=b;
                b=ch;
            }
        GCD=GCDserch(a,b);
        LCM=a*b/GCD;
        cout<<GCD<<" "<<LCM<<endl;
    }
}

Measured memory_bytes: 1152
#include <iostream>

using namespace std;


int main() {
    int N;
    cin >> N;
    long long a[N];
    long long sum[N];
    long long c = 0;
    for(int i=0;i<N;i++){
        cin >> a[i];
        c += a[i];
        //cout << c <<"\n";
        sum[i] = c;
    }
    long long x;
    long long min = 1000000000000000000LL;;
    for(int i=0;i<N-1;i++){
        long long p = sum[i];
        long long q = sum[N-1] - sum[i];
        if(p < q) x = q - p;
        else x = p - q;
        if(x<=min){
            min = x;
        }
        //cout << mini << " " << min <<"\n";
    }
    cout << min << "\n";
    return 0;
}




Measured memory_bytes: 3328
a = input()
s = (int(a) % 60)
m1 = ((int(a) - s) / 60)
m2 = (int(m1) % 60)
m = m2
h1 = ((m1 - m) / 60)
h = int(h1)
print(str(h) + ":" + str(m)  + ":" + str(s))


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

#define ll long long int
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define all(A) A.begin(), A.end()
#define sz(A) (int)A.size()
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <int, int> pii;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const int inf = 1e9;
//const ll inf = 1e18;
const int N = 2e5;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	long double pi = 3.14159265358979323846;
	ll r;
	cin >> r;
	cout << 2 * pi * r << "\n";
 	return 0;
}

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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> s(m), c(m);
	rep(i, m) cin >> s[i] >> c[i];
	int i = pow(10, n-1);
	if(n == 1) i = 0;
	for( ; i < pow(10, n); i++) {
		bool ok = true;
		rep(j, m) {
			if((i/(int)pow(10, n-s[j]))%10 != c[j]) {
				ok = false;
				break;
			}
		}
		if(ok) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long LL;
typedef pair<int, int> pii;
 
#define fst first
#define snd second
#define pb push_back
#define REP(i, a, b)  for(int i = (a), i##end = (b); i < i##end; ++i)
#define DREP(i, a, b) for(int i=(a-1), i##end = (b); i >=i##end; --i)
 
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
 
const int oo = 0x3f3f3f3f;
const int maxn = 100000 + 5;
 
template<typename T> T read() {
    T n(0), f(1);
    char ch = getchar();
    for( ;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for( ; isdigit(ch); ch = getchar()) n = n * 10 + ch - 48; 
    return n * f;
}

char s[maxn];
int main() {
#ifdef Wearry
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif

    scanf("%s", s);

    int len = strlen(s);
    if(len < 4 || s[0] != 'Y' || s[1] != 'A' || s[2] != 'K' || s[3] != 'I') {
        puts("No");
        return 0;
    }
    puts("Yes");
    
    return 0;
}


Measured memory_bytes: 256
//#include "pch.h"
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <math.h>
#define OO INT_MAX
#define mp(x,y) make_pair(x,y)
#define x first
#define y second
#define ll unsigned long long int
#define pp pair<int,int>
#define heap priority_queue<pp, vector<pp>, greater<pp>>
using namespace std;

int ans;
string  s;
string s1;
void check(string str, int i) {
	if (i == s.size()) {
		if (str == "ABC")
			ans++;
		return;
	}
	s1 = str;
	check(s1, i + 1);
	s1 = str + s[i];
	check(s1, i + 1);
}

int main()
{
//	freopen("test.txt", "r", stdin);

	map<string, int> fre;
	string s;
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s;
		fre[s]++;
	}
	int maxfre = -1;
	for (auto p : fre) {
		maxfre = max(maxfre, p.second);
	}
	for (auto p : fre) {
		if (p.second == maxfre) {
			cout << p.first << "\n";
		}
	}
}


Measured memory_bytes: 25216
#include <iostream>

using namespace std;

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


Measured memory_bytes: 3104
n = int(input())
score = []
for i in range(n):
  a,b = map(int,input().split())
  score.append([a,b])
sorted_score = sorted(score, key=lambda x: x[0]+x[1], reverse=True)
i=0
t_score = 0
a_score = 0
for i,scores in enumerate(sorted_score):
  if i%2==0:
    t_score+=scores[0]
  else:
    a_score+=scores[1]
print(t_score-a_score)
    
  


Measured memory_bytes: 29424
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
#define mp make_pair
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf=vector<vector<int>>;
#define MAX 1000000007

class Calc_Mod{//calculate mod
    public:
        unsigned int mod=1000000007;
        ll plus_mod(ll a,ll b){
            return (a+b)%mod;
        }
        ll minus_mod(ll a,ll b){
            return (a-b)%mod;
        }
        ll multi_mod(ll a,ll b){
            return a*b%mod;
        }
        ll LSM(ll a,int b){//a^b%mod
            queue<int> q;
            while(b>=1){
                q.push(b%2);
                b/=2;
            }
            ll ans=1;
            while(!q.empty()){
                if(q.front()==1){
                    ans=multi_mod(ans,a);
                }
                a=multi_mod(a,a);
                q.pop();
            }
            return ans;
        }
        ll div_mod(ll a,ll b){// a/b
            return multi_mod(a,LSM(b,mod-2));
        }
        ll combi(ll a,ll b){//aCb
            ll ans=1;
            ll kaijo=1;
            rep(i,b){
                ans=multi_mod(ans,a-i);
                kaijo=multi_mod(kaijo,b-i);
            }
            ans=div_mod(ans,kaijo);
            return ans;
        }
        
};

int main()
{
    int s;
    cin >> s;
    ll ans=0;
    Calc_Mod cal;
    if(s<3){
        cout << 0 << endl;
    }

    else{
        s-=3;
        int i=0;
        while(s>=0){
            ans=cal.plus_mod(ans,cal.combi(s+i,i));
            ++i;s-=3;
        }
        cout << ans << endl;
    }


    
}

Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>

using namespace std;

#define INF 1000000007
#define LINF 1000000000000000007

typedef long long i64;
typedef pair<i64,i64> P;


int a,b;

int main(){
	cin >> a >> b;
	
	if((a + b) % 2) cout << "IMPOSSIBLE" << endl;
	else cout << (a + b) / 2 << endl;
	
	return 0;
}

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

using namespace std;

int main(){
  int Q;
  cin >> Q;
  
  priority_queue<long long> pre;
  priority_queue<long long, vector<long long>, greater<long long>> suf;
  long long sum_a = 0, sum_pre = 0;
  long long sum_b = 0;
  for(int q = 0; q < Q; q++){
    char query_type;
    cin >> query_type;
    
    if(query_type == '1'){
      long long a, b;
      cin >> a >> b;
      
      sum_b += b;
      sum_a += a;
      
      if(pre.empty()){
        pre.push(a);
        sum_pre += a;
      }else if(pre.size() == suf.size()){
        if(a <= suf.top()){
          pre.push(a);
          sum_pre += a;
        }else{
          suf.push(a);
          pre.push(suf.top());
          sum_pre += suf.top();
          suf.pop();
        }
      }else{
        if(a < pre.top()){
          pre.push(a);
          sum_pre += a;
          suf.push(pre.top());
          sum_pre -= pre.top();
          pre.pop();
        }else{
          suf.push(a);
        }
      }
    }else{
      if(pre.size() == suf.size()) cout << pre.top() << ' ' << sum_a - 2 * sum_pre + sum_b << endl;
      else cout << pre.top() << ' ' << sum_a - 2 * sum_pre + sum_b + pre.top() << endl;
    }
  }
  
  return 0;
}

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

#define all(x)        (x).begin(),(x).end()
#define eb            emplace_back
#define mp            make_pair
#define pb            push_back
#define fi            first
#define se            second
#define sz(x)         ((int)(x).size())
#define rep(x,y,z)    for(int x=y;x<z;x++)
#define per(x,z,y)    for(int x=z-1;x>=y;x--)
#define trav(y,x)     for(auto& y:x)
#define pii           pair<int, int>
#define pll           pair<ll, ll>
#define vi            vector<int>
#define vpi           vector<pii>

int dbg = 0;
#define cri           if(0)
#define shame         cri cerr<<(++dbg)<<"\n\n";

const ll MOD = 1e9 + 7;
ll add(ll x, ll y) {
  ll sm = x + y;
  ((sm %= MOD) += MOD) %= MOD;
  return sm;
}

// aaaaaaaaaaaaaaaa
void solve() {
  int N, K;
  scanf("%d%d", &N, &K);

  ll lo = 0, hi = 0;
  rep(i, 0, K) lo = add(lo, i);
  rep(i, 0, K) hi = add(hi, N - i);
  ll ans = (hi - lo + 1) % MOD;
  rep(i, K, N + 1) {
    lo = add(lo, i);
    hi = add(hi, N - i);
    ans = add(ans, hi - lo + 1);
  }
  printf("%lld\n", ans);
}

int main() {
  // int _; scanf("%d", &_); while (_--)
  solve();
	return 0;
}



Measured memory_bytes: 3832
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(),v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 20;
vector<int> g[N];
vector<int> vis(N);
int dfs(int v){
    vis[v] = 1; 
    for(int u : g[v]){
        if(!vis[u]){
            dfs(u);
        }
    }
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        int n, m;
        cin >> n >> m;
        for(int i = 1; i <= n; i++){
            int k;
            cin >> k;
            for(int j = 1; j <= k; j++){
                int l;
                cin >> l;
                int u = i;
                int v = l + 1e5 + 1;
                g[u].pb(v);
                g[v].pb(u);
            }
        }
        int ans = 0;
        for(int i = 1; i <= n; i++){
            if(!vis[i]){
                ans++;
                dfs(i);
            }
        }
        if(ans > 1){
            cout << "NO\n";
        }else{
            cout << "YES\n";
        }
    }
}

Measured memory_bytes: 35712
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define MOD 1000000007LL
#define REP(i, n) for(int i=0;i<(n);++i)
// typedef long long ll;
#define int long long

#define INF 5e18
int V;
typedef pair<int, int> P;
struct edge {int to, cost;};
vector<edge> graph[100010];
int d[100010];

void dijkstra(int s){
	fill(d, d+V, INF); d[s] = 0;
	priority_queue<P, vector<P>, greater<P> > que;
	que.push(P(0, s));
	while(!que.empty()){
		P a = que.top(); que.pop();
		if(d[a.second] < a.first) continue;
		REP(i, graph[a.second].size()){
			edge e = graph[a.second][i];
			if(d[e.to] > d[a.second]+e.cost){
				d[e.to] = d[a.second]+e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

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

	int Q, K; cin >> V;
	REP(i, V-1){
		int a, b, c; cin >> a >> b >> c;
		graph[a-1].push_back({b-1, c});
		graph[b-1].push_back({a-1, c});
	}
	cin >> Q >> K;
	dijkstra(K-1);
	REP(i, Q){
		int x, y; cin >> x >> y;
		cout << d[x-1]+d[y-1] << endl;
	}
	return 0;
}


Measured memory_bytes: 11120
def check1(s):
    if len(s) % 2 == 1:
        return True
    else:
        return False


def helper(s):
    if len(s) % 2 == 0:
        return _helper_even(s)
    else:
        return _helper_odd(s)


def _helper_odd(s):
    center = int(len(s) / 2)
    s1 = s[:center]
    s2 = s[center + 1:]
    s2 = s2[::-1]

    for c1, c2 in zip(s1, s2):
        if c1 != c2:
            return False
    else:
        return True


def _helper_even(s):
    center = int(len(s) / 2)
    s1 = s[:center]
    s2 = s[center:]
    s2 = s2[::-1]

    for c1, c2 in zip(s1, s2):
        if c1 != c2:
            return False
    else:
        return True


def check2(s):
    if not helper(s):
        return False

    s1 = s[:int((len(s) - 1) / 2)]
    s2 = s[int((len(s) + 3) / 2) - 1:]

    if not helper(s1):
        return False
    if not helper(s2):
        return False

    return True


def main():
    s = input().strip()

    if check1(s) and check2(s):
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <string>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) (a)=max(a, b)
#define chmin(a, b) (a)=min(a, b)
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;


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


int main(void) {
  ll i, j, k;
  
  ll N, K, C;
  cin >> N >> K >> C; C++;
  string s;
  cin >> s;
  s="z"+s;
  
  ll dp[MAX*2][2]={}, ep[MAX*2][2]={};
  
  
  //初期化
  for(i=1; i<=C; i++) {
    dp[i][1]=(s[i]=='o');
    dp[i][0]=dp[i-1][1];
  }
  
  for(i=N; i>=N-C+1; i--) {
    ep[i][1]=(s[i]=='o');
    ep[i][0]=ep[i+1][1];
  }
  
  //DP
  for(i=1; i<=N; i++) {
    if(i-C>=1) chmax(dp[i][1], max(dp[i-C][1], dp[i-C][0])+(s[i]=='o'));
    chmax(dp[i][0], max(dp[i-1][1], dp[i-1][0]));
  }
  
  for(i=N; i>=1; i--) {
    if(i+C<=N) chmax(ep[i][1], max(ep[i+C][1], ep[i+C][0])+(s[i]=='o'));
    chmax(ep[i][0], max(ep[i+1][1], ep[i+1][0]));
  }
  
  for(i=1; i<=N; i++) if(s[i]=='o') if(dp[i][0]+ep[i][0]<K) pt(i);
  
}

Measured memory_bytes: 8128