akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a);i<(b);++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
#define INF 1000000000000000
#define MOD 1000000007
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
template<typename T> void invec(vector<T> &A){for(T& a : A) cin >> a;} 


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

int N; cin >> N;
VVI T(N+1);
VI edgecnt(N+1, 0);
rep(i, 0, N-1){
    int a, b; cin >> a >> b;
    T[a].push_back(b);
    T[b].push_back(a);
    ++edgecnt[a];
    ++edgecnt[b];
}
int maxpos = max_element(ALL(edgecnt)) - edgecnt.begin();
VI c(N); invec(c); 
sort(ALL(c), greater<i64>());
VI d(N+1, 0);

d[maxpos] = c[0]; 
int cpos = 1;
queue<int> que;
que.push(maxpos); 
while (!que.empty()) {
    int v = que.front(); 
    que.pop();
    for (int nv : T[v]) {
        if (d[nv] != 0) continue;
        d[nv] = c[cpos];
        ++cpos;
        que.push(nv);
    }
}
cout << accumulate(RANGE(c, 1, N), (i64)0) << "\n";
rep(i, 1, N+1) cout << d[i] << " ";
cout << "\n";

return 0;
}
// コンテスト前はtemplate振り返り。
// 書いて考える．場合分け．情報整理．
// 単純に分かる量から．愚直解を実装して研究．
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，分割，次にDP(小さい問題から大きな問題)
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性→二分探索
// 存在判定：構成方法，入力の特徴
// 構築問題。極端解を試す。
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// コーナーケース。境界値。数表出力プログラム作る
// 実行エラー：vector添え字超え．0割り．



Measured memory_bytes: 1280
#include<cstring>
#include<string>
#include<vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<complex>
#include<sstream>
#include<climits>
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

const int MAX_N = 40, MOD = 1e9+7;
int N, X, Y, Z;
ll dp[MAX_N+1][1 << 16];

//x^nをmodのもとで計算する
ll mod_pow(ll x, ll n, ll mod) {
  if (n == 0) return 1;
  ll res = mod_pow((x*x) % mod, n/2, mod);
  if (n & 1) res = (res*x) % mod;
  return res;
}


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

  dp[0][0] = 1;

  int ng = (1 << (X+Y+Z-1)) | (1 << (Y+Z-1)) | (1 << (Z-1));

  for (int i = 0; i < N; ++i) {
    for (int state = 0; state < 1 << (X+Y+Z-1); ++state) {
      for (int j = 1; j <= 10; ++j) {
       int next_state = (state << j) + (1 << (j-1));
       int judge = next_state & ng;
       if ((judge & 1 << (X+Y+Z-1)) && (judge & 1 << (Y+Z-1)) && (judge & 1 << (Z-1))) continue; 
       next_state %= (1 << (X+Y+Z-1));
       (dp[i+1][next_state] += dp[i][state]) %= MOD;
      }
    }
  }

  /*
  for (int i = 0; i <= N; ++i) {
    printf("%d ", i);
    for (int state = 0; state < 1 << (X+Y+Z-1); ++state) {
      printf("%lld ", dp[i][state]);
    }
    puts("\n");
  }
  */

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

  cout << (mod_pow(10, N, MOD) - ans + MOD) % MOD << endl;

  return 0;
}


Measured memory_bytes: 20736
using System;
class Program
{
    public static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');
        int a, b, c;
        a = int.Parse(str[0]);
        b = int.Parse(str[1]);
        c = int.Parse(str[2]);
        bool f = a + b == c || b + c == a || a + c == b;
        Console.WriteLine(f ? "Yes" : "No");
    }
}

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

int main(){

  char x,y;
  cin >> x >> y;

  if(x>y){
    cout << ">" << endl;
  }else if(x==y){
    cout <<"=" << endl;
  }else{
    cout <<"<" << endl;
  }


}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n,k;cin>>n>>k;
  vector<long long> A(n);for(int i = 0; n > i; i++)cin>>A[i];
  long long ans = 1000000000000000LL;
  for(int bit = 0; (1<<(n-1)) > bit; bit++){
    if(__builtin_popcount(bit)+1 != k)continue;
    long long he = A[0];
    long long tmp = 0;
    for(int i = 0; n > i; i++){
      if(bit & (1<<i)){
        if(he < A[i+1]){
          he = A[i+1];
        }else{
          he++;
          tmp +=he-A[i+1];
        }
      }else{
        he = max(he,A[i+1]);
      }
    }
    ans = min(ans,tmp);
  }
  cout << ans << endl;
}
    


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>

using namespace std;
//DP用
template<class T> inline bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

//a^n mod を計算する関数
long long modpow(long long a,long long n,long long mod) {
    long long res = 1;
    while(n > 0) {
        if(n % 2 == 1) {
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//a^(-1) mod すなわちaの逆元を返す関数
long long modinv(long long a,long long mod) {
    return modpow(a,mod-2,mod);
}

//最大公約数をを返す関数
long long gcd (long long a,long long b) {
    if(a % b == 0) {
        return b;
    }else {
        return (gcd(b,a%b));
    }
}

const long long INF = 1LL << 60;
const long long P = 1000000007;

//nCkを求める関数
long long conbi (long long n,long long k) {
    long long res = 1;
    long long inv;
    for(long long i = n-k+1; i <= n; i++) {
        res *= i;
        res %= P;
    }
    for(long long i = 1; i <= k; i++) {
        inv = modinv(i,P);
        res *= inv;
        res %= P;
    }
    return res;
}

int main() {
    int n;
    cin >> n;
    int a[n+1];
    a[0] = 0;
    bool flag = 0;
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        if(a[i] == 2) {
            flag = 1;
        }
    }
    if(flag == 0) {
        cout << -1;
        return 0;
    }
    int num = 1;
    int count = 0;
    while(num != 2) {
        num = a[num];
        count++;
        if(count > n) {
            cout << -1;
            return 0;
        }
    }
    cout << count;
    return 0;
}



Measured memory_bytes: 640
/*
String[]の初期化、整数の型がlongになっているか
関数（splitとかcontainsとか）内では"+"とかは正規表現となされるので"\\+"とする
配列のコピーはarr1=arr.clone()
HashSet<>[]はおのおの初期化した？？？？？
負の数の割り算は絶対値が小さいほうに切り捨てられるex.-1/2=0ので、ある値>kみたいな式だとバグらせやすいので注意
ある値>=kとして、切り上げた値をとるべき
toLowerCase()はアルファベット以外に対して行ってもエラーにはならない
ArrayDequeではpopとpushはStackと同じ操作になる
//import static java.lang.System.*; はしばらく使わなそう(使うとしてもexit(0)のためだけ)←return;でよさそう
最後にout.flush()またはout.close()をするのを忘れずに！
*/
//入力終了→Ctrl+D
import java.util.*;
import java.io.*;
import java.awt.*;
import java.awt.geom.Point2D;
import static java.lang.Math.*;
public class Main {
    public static void main(String[] $) {
        long n=sc.nextLong();
        long[] t=new long[5];
        long m=Long.MAX_VALUE;
        for (int i = 0; i < 5; i++) {
            t[i]=sc.nextLong();
            m=min(t[i],m);
        }
        long temp=n/m;
        if(n%m==0)temp--;
        out.println(temp+(long) 5);
        out.close();
    }

    static PrintWriter out = new PrintWriter(System.out);

    static class sc {
        static Scanner s = new Scanner(System.in);

        static String next() {
            return s.next();
        }

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

        static long nextLong() {
            return Long.parseLong(s.next());
        }

        static double nextDouble() {
            return Double.parseDouble(s.next());
        }
    }
}

Measured memory_bytes: 23892
# 入力
N, M = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))


MOD = 10**9 + 7


class ModInt:
    def __init__(self, x):
        self.x = x % MOD

    def __str__(self):
        return str(self.x)

    __repr__ = __str__

    def __add__(self, other):
        return (
            ModInt(self.x + other.x) if isinstance(other, ModInt) else
            ModInt(self.x + other)
        )

    def __sub__(self, other):
        return (
            ModInt(self.x - other.x) if isinstance(other, ModInt) else
            ModInt(self.x - other)
        )

    def __mul__(self, other):
        return (
            ModInt(self.x * other.x) if isinstance(other, ModInt) else
            ModInt(self.x * other)
        )

    def __truediv__(self, other):
        return (
            ModInt(
                self.x * pow(other.x, MOD - 2, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(self.x * pow(other, MOD - 2, MOD))
        )

    def __pow__(self, other):
        return (
            ModInt(
                pow(self.x, other.x, MOD)
            ) if isinstance(other, ModInt) else
            ModInt(pow(self.x, other, MOD))
        )

    def __radd__(self, other):
        return ModInt(other + self.x)

    def __rsub__(self, other):
        return ModInt(other - self.x)

    def __rmul__(self, other):
        return ModInt(other * self.x)

    def __rtruediv__(self, other):
        return ModInt(other * pow(self.x, MOD - 2, MOD))

    def __rpow__(self, other):
        return ModInt(pow(other, self.x, MOD))


# LCSと同様にDPで解を求める
dp = [[ModInt(1) for _ in range(M + 1)] for _ in range(N + 1)]
for i in range(1, N + 1):
    for j in range(1, M + 1):
        dp[i][j] = (
            dp[i - 1][j] + dp[i][j - 1] if S[i - 1] == T[j - 1] else
            dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1]
        )
ans = dp[N][M]

# 出力
print(ans)


Measured memory_bytes: 575104
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  int nxt = 1, ans = 0;
  rep(i,n) {
    if (nxt == a[i]) {
      ++nxt;
    } else {
      ++ans;
    }
  }
  if (ans == n) ans = -1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define UNVISITED -1
#define _ ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0), cout.precision(15);
using namespace std;

typedef long long int64;
typedef pair<int, int> ii;

int main(){ _
  int n, k; cin >> n >> k;
  vector<int64> vi(n, 0);
  for(int i = 0; i < n; ++i)  cin >> vi[i];

  int64 ans = 1LL << 40;
  for(int i = 0; i + k <= n; ++i) {
    if(vi[i + k - 1] < 0){
      ans = min(ans, -vi[i]);
    } else if(vi[i] < 0) {
      ans = min(ans, min(vi[i+k-1] - vi[i]*2, vi[i+k-1] * 2 - vi[i]));
    } else if(vi[i] >= 0){
       ans = min(ans, vi[i+k-1]);
    }
  }

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


Measured memory_bytes: 1024
#include<cstdio>
#define MAX 100000
#define NIL -1

struct Node { int parent, left, right;};

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d)
{
    if ( u == NIL) return;
    D[u] = d;
    setDepth(T[u].left, d + 1);
    setDepth(T[u].right, d + 1);
}

int setHeight(int u)
{
    int h1 = 0, h2 = 0;
    if ( T[u].left != NIL) h1 = setHeight(T[u].left) + 1;
    if ( T[u].right != NIL) h2 = setHeight(T[u].right) + 1;
    return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u)
{
    if (T[u].parent == NIL) return NIL;
    if (T[T[u].parent].left != u && T[T[u].parent].left != NIL)
    {
        return T[T[u].parent].left;
    }
    if (T[T[u].parent].right != u && T[T[u].parent].right != NIL)
    {
        return T[T[u].parent].right;
    }
    return NIL;
}

void Print(int u)
{
    printf("node %d: ", u);
    printf("parent = %d, ", T[u].parent);
    printf("sibling = %d, ", getSibling(u));
    int deg = 0;
    if (T[u].left != NIL) deg++;
    if (T[u].right != NIL) deg++;
    printf("degree = %d, ", deg);
    printf("depth = %d, ", D[u]);
    printf("height = %d, ", H[u]);

    if (T[u].parent == NIL)
    {
        printf("root\n");
    }
    else if (T[u].left == NIL && T[u].right == NIL)
    {
        printf("leaf\n");
    }
    else
    {
        printf("internal node\n");
    }
}

int main()
{
    int v, l, r, root = 0;
    scanf("%d", &n);

    for (int i = 0; i < n; i++) T[i].parent = NIL;

    for (int i = 0; i < n; i++)
    {
        scanf("%d %d %d", &v, &l, &r);
        T[v].left = l;
        T[v].right = r;
        if (l != NIL) T[l].parent = v;
        if (r != NIL) T[r].parent = v;
    }

    for (int i = 0; i < n; i++)
    {
        if (T[i].parent == NIL) root = i;
    }

    setDepth(root, 0);
    setHeight(root);

    for (int i = 0; i < n; i++) Print(i);

    return 0;
}


Measured memory_bytes: 2720
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	ll a=2,b=1;
	REP(i,n-1) {
		ll buf=b;
		b=a+b;
		a=buf;
	}
	cout<<b<<endl;
}


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

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

    vector<string> s(h);
    rep(i,h) {
        cin >> s.at(i);
    }

    vector<vector<char>> a(h+2, vector<char>(w+2));
    rep(i,h+2) {
        rep(j,w+2) {
            a.at(i).at(j)='#';
        }
    }
    for(int i=1; i<h+1; i++){
        for(int j=1; j<w+1; j++){
            a.at(i).at(j)=s[i-1].at(j-1);
         }
    }

    rep(i,a.size()) {
        rep(j,a.at(0).size()) {
            cout << a.at(i).at(j);
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 3564
import math
n,a,b = map(int,input().split())
hl = []
for _ in range(n):
   h = int(input())
   hl.append(h)

ub = 10**9
lb = 0
while True:
    if ub == lb:
        break
    target = (ub + lb) // 2
    need = 0
    for h in hl:
        rest = h - target * b
        need += max(math.ceil(rest / (a-b)), 0)
    if need <= target:
        ub = target
    else:
        lb = target + 1
print(lb)

Measured memory_bytes: 7068
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vs vector<string>
#define vll vector<ll>
#define ii pair<int, int>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define vii vector<ii>
#define vvi vector<vi>
#define vvii vector<vii>
#define ld long double
#define iii tuple<int, int, int>
#define sc scanf
#define pb push_back
#define FOR(i, x, n) for(int i=x; i<=n; ++i)
#define ROF(i, x, n) for(int i=x; i>=n; --i)
#define MOD 1000000007
#define F first
#define S second

ll n;

int main() {

    sc("%lld", &n);

    ll ans = 0;

    for(ll i=1; i<n; ++i) {
        for(ll j=1; j<n; ++j) {
            if(i*j >= n) break;
            ans++;
        }
    }

    printf("%lld\n", ans);
}



Measured memory_bytes: 3824
# -*- coding: utf-8 -*-


def main():
    from collections import Counter

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

    if len(set(v)) == 1:
        print(n // 2)
        exit()
    else:
        even = Counter(v[::2]).most_common(1)[0][0]
        odd = Counter(v[1::2]).most_common(1)[0][0]
        ans1 = 0

        if even == odd:
            even2 = Counter(v[::2]).most_common(2)[1][0]
            odd2 = Counter(v[1::2]).most_common(2)[1][0]
            ans2 = 0
            ans3 = 0

            for x in range(n):
                if x % 2 == 0:
                    if v[x] != even:
                        ans2 += 1
                else:
                    if v[x] != odd2:
                        ans2 += 1

            for y in range(n):
                if y % 2 == 0:
                    if v[y] != even2:
                        ans3 += 1
                else:
                    if v[y] != odd:
                        ans3 += 1

            print(min(ans2, ans3))
            exit()

        for i in range(n):
            if i % 2 == 0:
                if v[i] != even:
                    ans1 += 1
            else:
                if v[i] != odd:
                    ans1 += 1

        print(ans1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 16228
def dijkstra(adj_matrix, n):
    dist = [float("inf") for _ in range(n)]
    visited = [False for _ in range(n)]
    parent = [-1 for _ in range(n)]

    start = 0
    dist[start] = 0
    visited[start] = True
    while True:
        for end in range(n):
            # startから出ているノードの距離を計算
            if not visited[end] and adj_matrix[start][end] > -1 and dist[start] + adj_matrix[start][end] < dist[end]:
                dist[end] = dist[start] + adj_matrix[start][end]
                parent[end] = start

        # 一番近い距離にあるノードを訪問する
        min_cost = float("inf")
        for nextnode in range(n):

            if not visited[nextnode] and dist[nextnode] < min_cost:
                min_cost = dist[nextnode]
                start = nextnode
        if min_cost == float("inf"):
            return parent, dist
        visited[start] = True


def main():
    n = int(input())
    adj_matrix = []
    for _ in range(n):
        row = [-1 for _ in range(n)]
        line = input().split()
        dim = int(line[1])
        for i in range(dim):
            row[int(line[2 + i * 2])] = int(line[2 + i * 2 + 1])
        adj_matrix.append(row)
    _, dist = dijkstra(adj_matrix, n)
    for i in range(n):
        print("{} {}".format(i, dist[i]))


if __name__ == "__main__":
    main()



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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
constexpr double EPS = 1e-10;
constexpr int INF = 1001001001;
//constexpr ll INF = 1001001001001001001ll;


// a の i ビット目と j ビット目を swap する
void swa(int &a, int i, int j) {
    if ( (a & (1<<i)) && !(a & (1<<j)) ) a += -(1<<i) + (1<<j);
    else if ( !(a & (1<<i)) && (a & (1<<j)) ) a += (1<<i) - (1<<j);
}

// 0, 1, ..., n-1 ビット目を動かして、a を b にする
vector<int> solve(int n, int a, int b) {
    if (n == 1) return {a, b};
    
    // a^b の最高位が 1 でないときは 1 を見つけて swap する
    int exchange = n-1;
    int c = a^b;
    if (!(c & (1<<(n-1)))) {
        for (int d = 0; d < n-1; ++d) if (c & (1<<d)) exchange = d;
    }
    swa(a, n-1, exchange), swa(b, n-1, exchange);

    // 前半戦: テキトーに最後尾のビットを入れ替えておく
    int na = a & ~(1<<(n-1));
    auto zenhan = solve(n-1, na, na^1);

    // 後半戦
    int nb = b & ~(1<<(n-1));
    auto kouhan = solve(n-1, na^1, nb);

    // マージする
    vector<int> res;
    if (a & (1<<(n-1))) {
        for (auto v : zenhan) res.push_back(v ^ (1<<(n-1)));
        for (auto v : kouhan) res.push_back(v);
    }
    else {
        for (auto v : zenhan) res.push_back(v);
        for (auto v : kouhan) res.push_back(v ^ (1<<(n-1)));
    }

    // 最後に swap して戻す
    for (auto &v : res) swa(v, n-1, exchange);
    return res;
}

int main() {
    int N, A, B; cin >> N >> A >> B;
    int C = A ^ B;
    int bitcount = 0;
    for (int i = 0; i < N; ++i) if (C & (1<<i)) ++bitcount;
    if (bitcount % 2 == 0) {
        cout << "NO" << endl;
        return 0;
    }
    auto res = solve(N, A, B);
    cout << "YES" << endl;
    for (auto v : res) cout << v << " ";
    cout << endl;
}

Measured memory_bytes: 1756
import javax.print.DocFlavor;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.function.BiConsumer;

public class Main {

    //グローバル変数を定義

    public static void main(String[] args) throws IOException {
        new Main().run();
    }

    void run() {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        char[][] array = new char[h][w];
        ArrayList<ArrayList<String>> ansList = new ArrayList();
        ArrayList<ArrayList<String>> finalList = new ArrayList<>();

        for(int i=0; i<h; i++){
            char[] input = sc.next().toCharArray();
            for(int j=0; j<w; j++){
                array[i][j] = input[j];
            }
        }

        for(int i=0; i<h; i++){
            boolean isAllWhite = true;
            for(int j=0; j<w; j++){
                if(array[i][j] == '#') {
                    isAllWhite = false;
                    break;
                }
            }
            if(!isAllWhite){
                ArrayList<String> each = new ArrayList();
                for(int j=0; j<w; j++){
                    each.add(String.valueOf(array[i][j]));
                }
                ansList.add(each);
            }
        }

        ArrayList<Integer> no = new ArrayList<>();
        for(int j=0; j<w; j++){
            boolean isWhite = true;
            for(int i=0; i<ansList.size(); i++){
                if(ansList.get(i).get(j).equals("#")){
                    isWhite = false;
                    break;
                }
            }
            if(isWhite){
               no.add(j);
            }
        }

        for(int i=0; i<ansList.size(); i++){
            for(int j=0; j<w; j++){
                if(no.contains(j)){
                    continue;
                } else {
                    System.out.print(ansList.get(i).get(j));
                }
            }
            System.out.println();
        }
    }
}


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

int main(){
 vector<int> s(3);
  for(int i=0 ; i<3 ; i++){
     cin >> s.at(i);
  }
  
  int count5=0, count7=0;
  for(int i=0; i<3; i++){
    if(s.at(i) == 5){
       count5++;
     }else if(s.at(i) == 7){
       count7++;
     }else{
       break;
     }
  
   }
 if(count5 ==2 && count7 ==1){
    cout << "YES" << endl;
 }else{
    cout << "NO" << endl;
 }



return 0;
}

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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

string K;
int D;
int DP[100010][105][2];

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

	cin>>K>>D;

	DP[0][0][1]=1;

	rep(i,0,SZ(K))rep(j,0,D)rep(k,0,2)
	{
		int kd=K[i]-'0';
		rep(d,0,10)
		{
			int ni=i+1,nj=(j+d)%D,nk=k;
			if(nk==1)
			{
				if(d>kd)continue;
				else if(d<kd)nk=0;
			}
			DP[ni][nj][nk]=(DP[ni][nj][nk]+DP[i][j][k])%MOD;
		}
	}

	cout<<(DP[SZ(K)][0][0]+DP[SZ(K)][0][1]-1+MOD)%MOD<<endl;
	
	return 0;
}

Measured memory_bytes: 18688
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

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

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

    int differ = 0;
    for (int i = 0; i < n; ++i) {
        if (p[i] != p_sort[i])
            ++differ;
    }
    if (differ > 2)
        cout << "NO\n";
    else
        cout << "YES\n";
}


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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    string s;
    cin >> s;
    bool res = true;
    REP(i, s.size()) {
        if((i + 1)%2 == 1) {
            res = res && (s[i] == 'R' || s[i] == 'U' || s[i] == 'D');
        }else{
            res = res && (s[i] == 'L' || s[i] == 'U' || s[i] == 'D');
        }
    }
    if(res) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << 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 pair<ll, ll> P;
struct edge { ll to, cost; };

const int MAX_V =300000;
const ll INF = 1LL<<60;

int V;
vector<edge> G[MAX_V];
ll d[MAX_V];

void dijkstra(ll s) {
    // greater<P>を指定することでfirstが小さい順に取り出せるようにする
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d + V, INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top(); que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;
        rep(i,G[v].size()) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

int main() {
    int N, M, S, T;
    cin >> N >> M;
    V = N * 3;
    vector<int> u(M), v(M);
    rep(i, M) {
        cin >> u[i] >> v[i];
        u[i]--;
        v[i]--;
        G[u[i]].push_back({v[i] + N, 1});
        G[u[i] + N].push_back({v[i] + N + N, 1});
        G[u[i] + N + N].push_back({v[i], 1});
    }
    cin >> S >> T;
    S--;
    T--;
    dijkstra(S);
    if (d[T] == INF) cout << "-1\n";
    else cout << d[T] / 3 << endl;
    //rep(i, V) cout << i << " " << d[i] << endl;
}

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

void solve(){
  int a, b, c; cin >> a >> b >> c;
  for(int i = 1; i <= b - 1; i++){
    if(a * i % b == c){
      cout << "YES\n";
      return;
    }
  }
  cout << "NO\n";
  return;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, q; scanf("%d%d", &n, &q);
	char s[n]; scanf("%s", s);
	int ans[n]; ans[0] = 0;
	for(int i = 1; i < n; i++){
		if(s[i - 1] == 'A' && s[i] == 'C') ans[i - 1]++, ans[i] = ans[i - 1] + 1;
		else ans[i] = ans[i - 1];
	}
	for(int i = 0; i < q; i++){
		int l, r; scanf("%d%d", &l, &r);
		int left = ans[l - 1], right = ans[r - 1];
		right -= right % 2;
		if(left % 2) left--;
		// else if (s[l] == 'C' && l > 0 && s[l - 1] == 'A') left++;
		printf("%d\n", (right - left ) / 2);
	}
}

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

using namespace std;

int main () {
    int N, K, Q;

    while (cin >> N >> K >> Q) {
        vector<int> score(N, K-Q);
        int A;
        for (int i = 0;i < Q;i++) {
            cin >> A;
            score[A-1]++;
        }
        for (int i = 0;i < N;i++) {
            if (score[i] > 0) {
                cout << "Yes" << endl;
            }
            else {
                cout << "No" << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#define INF 1000000000
using namespace std;
int dis[5010][5010];
int gedi(int x,int y){
	if(x>y) return dis[y][x];
	else return dis[x][y];
}

void sedi(int x,int y,int v){
	if(x>y) dis[y][x]=v;
	else dis[x][y]=v;
}
int N;
void wf(){
	for(int k=0;k<N;k++){
		for(int i=0;i<N;i++){
			for(int j=i;j<N;j++){
				sedi(i,j,min(gedi(i,j),gedi(i,k)+gedi(k,j)));
			}
		}
	}
}

int main(){
	int K,hog,bak,aho,kso;
	while(1){
		cin>>N>>K;
		if(N==0&&K==0) break;
		for(int i=0;i<N;i++){
			for(int j=0;j<N;j++){
				dis[i][j]=INF;
			}
		}
		for(int i=0;i<K;i++){
			////
			//for(int i=0;i<N;i++){
			//	for(int j=0;j<N;j++){
			//		cout<<"dis["<<i<<"]["<<j<<"]="<<gedi(i,j)<<" ";
			//	}
			//	cout<<endl;
			//}
			////
			cin>>hog;
			if(hog==0){
				cin>>bak>>aho;
				bak--;aho--;
				if(gedi(bak,aho)!=INF){
					cout<<gedi(bak,aho)<<endl;
				}
				else{
					cout<<-1<<endl;
				}
			}
			else{
				cin>>bak>>aho>>kso;
				bak--;aho--;
				if(gedi(bak,aho)>kso){
					sedi(bak,aho,kso);
					wf();
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1592
x = input().split()
n = int(x[0])
d = int(x[1])
d = d**2
s = 0

for i in range(n):
  a = input().split()
  b = int(a[0])
  c = int(a[1])
  if b**2+c**2<=d:
    s+=1
print(s)

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;


int main() {
    cin.sync_with_stdio(0);
    ll t; cin >> t;
    if(t >= 30) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

map<pll, ll> m;

ll gcd(ll a, ll b){
  if(a==1 || b==1)return 1;
  if (a < b)swap(a,b);
  if(m[{a, b}]>0)return m[{a, b}];

  m[{a, b}] = b ? gcd(b, a % b) : a;
  return m[{a, b}];
}

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

ll f(ll x){
  ll res=0;
  while(x%2==0){
    x /= 2;
    res++;
  }
  return res;
}

int main(){
  ll n,m;cin>>n>>m;
  vector<ll>a(n);
  rep(i, n)cin>>a[i];
  rep(i, n)a[i]/=2;

  ll t = f(a[0]);
  rep(i, t)m/=2;

//cout<<m<<' '<<t<<endl;

  rep(i, n){
    if(f(a[i])!=t){ cout<<0<<endl; return 0; }
    rep(k, t)a[i]/=2;
  }

  ll base = 1;
  rep(i, n){
    base = lcm(base, a[i]);
    if(base>m){cout<<0<<endl;return 0;}
  }

  ll result = 0;
  result = ((m/base)+1)/2;
  cout<<result<<endl;

  return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main (void){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if((x-r<0||x+r>W)||(y-r<0||y+r>H)){
        printf("No\n");
    }
    if((y-r>=0&&y+r<=H)&&(x-r>=0&&x+r<=W)){
        printf("Yes\n");
    }
    return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

ll modpow(ll a, ll n, ll mod){
    ll ret=1;
    while(n>0){
        if(n&1) ret=ret*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ret;
}

int main(){
    ll n;
    cin>>n;
    vector<ll> a(n);
    ll sum=0;
    ll sum2=0;
    for(ll i=0;i<n;i++){
        cin>>a[i];
        sum+=a[i];
        sum%=MOD;
        ll nizyou=a[i]*a[i]%MOD;
        sum2+=nizyou;
        sum2%=MOD;
    }
    ll ans=0;
    ans=sum*sum%MOD;
    ans-=sum2;
    ans%=MOD;
    if(ans<0) ans+=MOD;
    ans*=modpow(2,MOD-2,MOD);
    ans%=MOD;
    cout<<ans<<endl;

}

Measured memory_bytes: 4844
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

/*
<url:https://abc073.contest.atcoder.jp/tasks/abc073_d>
問題文============================================================
 Atcoder国には N 個の町があり、M 本の双方向に移動可能な道で結ばれています。
 
 また、 i 本目の道は町 Ai と町 Bi の間を距離 Ci で結んでいます。
 
 joisinoお姉ちゃんは、この国の R 個の町 r1,r2..rR を訪れることとなりました。
 
 最初に訪れる町までの移動と、最後に訪れる町からの移動は空路で行うが、それ以外は道を使わなければなりません。
 
 町を訪れる順番を、道での移動距離が最小となるように決めた時の移動距離を答えてください。
 
=================================================================

解説=============================================================
 
 先にワーシャルフロイドで目的地間の最短距離を調べておけば、
 この問題は実質、頂点数高々８個の全頂点巡回問題となる。
 また、始点、終点は任意でいいので
 
 dp[i][j] := 現在値が i個目の目的地 の時、 j(集合）の目的地に到達済みの時の最小距離
 
 でもとまる。（制約が小さいので、最初の始点を決めての貪欲でも間に合う）
================================================================
*/
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll N,M,R; cin >> N >> M >> R;
    vector<ll> r(R); for(auto &in:r){ cin >> in; in--; }
    vector<vector<ll>> G(N,vector<ll>(N,INF));
    for(int i = 0; i < N;i++) G[i][i] = 0;
    for(int i = 0; i < M;i++){
        ll A,B,C; cin >> A >> B >> C;
        A--; B--;
        G[A][B] = G[B][A] = min(G[A][B],C);
    }
    for(int i = 0; i < N;i++) for(int j = 0; j < N;j++) for(int k = 0; k < N;k++)
        G[j][k] = min(G[j][i] + G[i][k],G[j][k]);
    
    vector<vector<ll>> dp(R,vector<ll>(1<<R,LINF));
    for(int i = 0 ; i < R;i++) dp[i][1<<i] = 0;
    for(int j = 0; j < (1<<R);j++){
        for(int i = 0; i < R;i++){
            if(dp[i][j] == LINF) continue;
            for(int k = 0; k < R; k++){
                if((j>>k)&1) continue;
                dp[k][j|(1<<k)] = min(dp[k][j|(1<<k)],dp[i][j] + G[r[i]][r[k]]);
            }
        }
    }
    ll ans = LINF;
    for(int i = 0; i < R;i++) ans = min(ans,dp[i][(1<<R)-1]);
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 640
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

a = inint()
b = inint()

if a > b:
    print("GREATER")
elif a == b:
    print("EQUAL")
else:
    print("LESS")

Measured memory_bytes: 61840
#include <iostream>
#include <cmath>

using namespace std;

bool Primality(int);

int main(){
	int n, count = 0;
	int ain;
	
	cin >> n;
	for(int i = 0;i < n;++i){
		cin >> ain;
		if(Primality(ain))++count;
	}
	cout << count << endl;
	
	return 0;
}

bool Primality(int x){
	if(x < 2)return false;
	else if(x == 2)return true;
	else if(x % 2 == 0) return false;
	for(int i = 3;i <= sqrt(x);++i)
		if(x % i == 0)return false;
	return true;
}


Measured memory_bytes: 3124
#! usr/bin/env python
# -*- coding: utf-8 -*-

from collections import deque
import heapq
import math
import bisect


def main():
    n = int(input())
    s = [input() for i in range(3)]

    ans = 0
    for i in range(n):
        t = 3
        for j in range(3):
            cur = 0
            for k in range(3):
                if s[j][i] != s[k][i]:
                    cur += 1
            t = min(t, cur)

        ans += t

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
#include <functional>
#include <unordered_map>
#include <map>
#include <iomanip>

using namespace std;



int main() 
{
	vector<int> all;
	for (int i = 0; i < 3; i++)
	{
		int t;
		cin >> t;
		all.push_back(t);
	}
	sort(all.begin(), all.end());
	int start = all[0];
	int ans = 0;
	for (int i = 1; i < 3; i++)
	{
		ans += abs(all[i] - start);
		start = all[i];
	}
	cout << ans;







}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
	int n, total;

	while (cin >> n){
		total = 0;

		for (int a = 0; a <= 9; a++){
			for (int b = 0; b <= 9; b++){
				for (int c = 0; c <= 9; c++){
					for (int d = 0; d <= 9; d++){
						if (a + b + c + d == n){
							total++;
						}
					}
				}
			}
		}
		cout << total << endl;
	}
}

Measured memory_bytes: 2992
package main

import "fmt"

func main() {
	var h, w int
	fmt.Scan(&h, &w)

	a := make([]string, h)
	for i := 0; i < h; i++ {
		fmt.Scan(&a[i])
	}

	row := make([]bool, h)
	col := make([]bool, w)
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if a[i][j] == '#' {
				row[i] = true
				col[j] = true
			}
		}
	}

	for i := 0; i < h; i++ {
		if row[i] {
			for j := 0; j < w; j++ {
				if col[j] {
					fmt.Printf("%c", a[i][j])
				}
			}
			fmt.Println()
		}
	}
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;
public class Main {
	public static void main(String[] args){
		FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<>();
		for (int i=0;i<n;i++) {
			list.add(sc.nextInt());
		}
		Collections.sort(list);
		int a = list.get(n/2-1);
		int b = list.get(n/2);
		if (a == b) {
			System.out.println(0);
		} else {
			System.out.println(b-a);
		}


	}

}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

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

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

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

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

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 39220
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("trapv")
#pragma GCC target("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define deb(x) cout << #x << " is " << x << "\n"
#define int long long
#define mod 1000000007LL
#define PI acosl(-1)

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

void solve()
{
	int n, k;
	cin >> n >> k;
	vector<int> arr(n);
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	vector<int> dp(k + 1, 0);
	// dp[i] -> number of ways such that we used i candies so far
	dp[0] = 1;
	for (int child = 0; child < n; child++)
	{
		int upto = arr[child];
		vector<int> temp(k + 1);
		for (int used = k; used >= 0; used--)
		{
			int L = used + 1;
			int R = used + min(upto, k - used);
			if (L <= R)
			{
				temp[L] = (temp[L] + dp[used]) % mod;
				if (R + 1 <= k)
				{
					temp[R + 1] = ((temp[R + 1] - dp[used]) + mod) % mod;
				}
			}
		}
		int curr = 0;
		for (int i = 0; i <= k; i++)
		{
			curr = (curr + temp[i]) % mod;
			dp[i] = (dp[i] + curr) % mod;
		}
	}
	cout << dp[k];
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}

Measured memory_bytes: 4760
# -*- coding: utf-8 -*-
"""
@author: H_Hoshigi
解説PDFを読んだ。
"""

def main():
    N = int(input())
    S = input()

    hash_counter = 0
    dot_counter = S.count(".")
    answer = dot_counter
    for i in range(N):
        if S[i] == "#":
            hash_counter += 1
        else:
            dot_counter -= 1
        answer = min(answer, hash_counter+dot_counter)
    print(answer)

if __name__ == "__main__":
    main()



Measured memory_bytes: 9372
#include<stdio.h>
int main(){
  int a,n,b,c,sum;
  while(scanf("%d",&a),a!=0){
    scanf("%d",&n);
    sum = 0;
    for(int i=0;i<n;i++){
      scanf("%d %d",&b,&c);
      sum += c-b;
    }
    if(a <= sum) puts("OK");
    else printf("%d\n",a-sum);
  }
  return (0);
}

Measured memory_bytes: 2684
using System;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var values = Console.ReadLine().Split(' ').Select(x => double.Parse(x)).ToArray();
            var h = Console.ReadLine().Split(' ').Select(x => int.Parse(x));

            var index = h
                .Select((x, i) => new {index = i + 1, temp = Math.Abs(values[0] - (double) x * 0.006 - values[1])})
                .OrderBy(x => x.temp).First().index;
            
           Console.WriteLine(index);
            
        }

        
    }
}


Measured memory_bytes: 13524
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
using ll = long long;
using namespace std;

int main(){
	ll n;
	cin>>n;
	ll a[110000];
	rep(i,0,n)cin>>a[i];
	ll ans=0;
	ll k=0;
	sort(a,a+n);
	rep(i,0,n){
		ll x=a[i];
		while(x==a[i]&&i<n) {i++;k++;}
		if(k%2==1) ans++;
		k=0;
		i--;
	}
	cout<<ans;
}

Measured memory_bytes: 1024
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;

	void run() {
		Scanner sc = new Scanner(System.in);
		for(;;) {
			int n = sc.nextInt();
			if( n == 0 ) break;
			int val = Divsum(n);
			if( n == val ) 		System.out.println("perfect number");
			else if( n > val )	System.out.println("deficient number");
			else 				System.out.println("abundant number");
		}
	}
	
	int Divsum(int x) {
		if( x == 1 ) return 0;
		int sum = 1;
		for(int i=2;i*i<=x;i++) if(x%i == 0){
			sum += i;
			if( x/i != i ) sum += x/i;
		}
		return sum;
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

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

using namespace std;

typedef long long LL;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);

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

    int cnt = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == mx) {
            cnt++;
        } else if (a[i] != mx - 1) {
            cout << "No" << endl;
            return 0;
        }
    }

    if (cnt == n && (mx == n - 1 || mx == 1)) {
        cout << "Yes" << endl;
    } else {
        if (mx - 1 - (n - mx - 1) <= n - cnt && n - cnt <= mx - 1) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 640
/*
    Author: Alam Khan
    AUST CSE 40th Batch

*/

#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef deque<ll> dl;
typedef stack<ll> stl;
typedef set<ll> sl;
typedef map<string, ll> msl;
typedef map<ll,ll> mll;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
#define sf(n)     scanf("%lld",&n)
#define sff(n,m)     scanf("%lld %lld",&n,&m)
#define sfff(n,m,r)     scanf("%lld %lld %lld",&n,&m,&r)
#define sfs(n)     scanf("%s",n)
#define pf(n)     printf("%lld\n",n)
#define pff(n,m)     printf("%lld %lld\n",n,m)
#define pfff(n,m,r)     printf("%lld %lld %lld\n",n,m,r)
#define pfs(n)     printf("%s\n",n)
#define pfcs(i,n)     printf("Case %lld: %lld\n",i,n)
#define pb     push_back
#define prf     printf
#define inf     2e18
#define low     -1000000000000
#define PI        acos(-1.0)
#define rep1(i,n) for(i=1;i<n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define rep(i,a,n) for(i=a;i<n;i++)
#define repe1(i,n) for(i=1;i<=n;i++)
#define repe0(i,n) for(i=0;i<=n;i++)
#define repe(i,a,n) for(i=a;i<=n;i++)
#define endl  "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fr freopen("input.txt","r",stdin)
#define fw freopen("output.txt","w",stdout)

int main()
{
    ll i,n,t,k,j,x=0,y=0,m;
    string str;
    cin>>str;
    if(str=="ABC")
        cout<<"ARC"<<endl;
    else if(str=="ARC")
    {
        cout<<"ABC"<<endl;
    }
    return 0;
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  string S;
  cin>>S;
  if(S[0]==S[1]&&S[1]==S[2]) {
cout<<"Yes"<<endl;
  }
  else if(S[1]==S[2]&&S[2]==S[3]) {
cout<<"Yes"<<endl;
  }
  else {
cout<<"No"<<endl;
  }
}

Measured memory_bytes: 3584
MOD = 10**9+7
# dp[i][j] := Sの後ろからi桁を13で割った余りがjとなるようなものの個数
S = input()
l = len(S)
dp = [[0]*13 for _ in range(l+1)]
dp[0][0] = 1
mul = 1

for i in range(l):
    x = S[-(i+1)]
    if x == "?":
        for k in range(10):
            for j in range(13):
                dp[i + 1][(mul * k + j) % 13] += dp[i][j]
                dp[i + 1][(mul * k + j) % 13] %= MOD
    else:
        k = int(x) # これしか選ぶ余地なし
        for j in range(13):
            dp[i + 1][(mul * k + j) % 13] += dp[i][j]
            dp[i + 1][(mul * k + j) % 13] %= MOD
    mul = mul * 10 % 13
print(dp[len(S)][5])


Measured memory_bytes: 62300