akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

//前提:解は必ず存在する
int main() {
  int N, K;
  cin >> N >> K;

  vector<int> D;

  //配列D、嫌いな数字を入れていく。
  for (int i = 0; i < K; i++) {
    int d;
    cin >> d;
    D.push_back(d);
  }

  // 嫌いな数字が出現した際に立つフラグ
  bool flag;

  for (int ans = N; ans <= 100000; ans++) {
    // ansを文字列に変換
    string str = to_string(ans);
    flag = false;

    for (int i = 0; i < K; i++) {
      // 嫌いな数字を文字に変換
      char judge = '0' + D[i];

      // ans中にD[i]が出現したらフラグを立てる
      if (str.find(judge) != string::npos) {
        flag = true;
        break;
      }
    }

    // 嫌いな数字が出現してなかったら表記して終了
    if (flag == false) {
      cout << ans << endl;
      return 0;
    }
  }
}


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

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(), (x).end()

using namespace std;

template <typename T> T &chmin(T &a, const T &b) {return a = min(a, b);}
template <typename T> T &chmax(T &a, const T &b) {return a = max(a, b);}

using ll = long long;
using ld = long double;

const int INF = 1e9;
const ld eps = 1e-9, pi = acos(-1.0);

struct UnionFind{
  vector<int> parent;
  UnionFind(int N) : parent(N, -1) {};
  int root(int n) { return parent[n] < 0 ? n : parent[n] = root(parent[n]); }
  bool merge(int x, int y){
    x=root(x); y=root(y);
    if(x==y) return false;
    if(parent[x]>parent[y]) swap(x, y);
    if(parent[x]==parent[y]) parent[x]--;
    parent[y] = x;
    return true;
  }
  bool judge(int a, int b){
    return root(a) == root(b);
  }
};

int binarySearch(int* target, int num, int l, int r){
  if(l==r) return l;
  int pivot=(l+r)/2;
  if (*(target+pivot)==num) return pivot;
  return *(target+pivot) > num ? binarySearch(target, num, l, pivot) : binarySearch(target, num, pivot+1, r);
}

int main(){
  int n;
  cin >> n;
  int a[n], org[n];
  int res = 0;
  UnionFind grp = UnionFind(n);
  REP(i, n) { cin >> a[i]; org[i] = a[i]; }
  sort(a, a+n);
  REP(i, n){
    int place = binarySearch(a, org[i], 0, n-1);
    grp.merge(i, place);
  }
  REP(i, n){
    if(grp.parent[i]==-1) continue;
    if(grp.parent[i]<0) {
      vector<int> target;
      REP(j, n) if(grp.judge(i,j)) target.push_back(a[j]);
      sort(target.begin(), target.end());
      if((target[0]-a[0]) * (target.size()-1) > 2 * (target[0]+a[0])){
        res += accumulate(target.begin(), target.end(), a[0] * (target.size()+1) + target[0]);
      } else {
        res += accumulate(target.begin(), target.end(), target[0] * (target.size()-2));
      }
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;
int main() {
    int n;
    while (cin >> n, n) {
        vector <int> r, w;
        r = w = vector <int> (n);
        int sumR = 0, sumW = 0;
        rep (i, n) {
            cin >> r[i] >> w[i];
            sumR += r[i];
            sumW += w[i];
        }
        vector <int> copyR = r;
        sort(r.begin(), r.end());
        if (sumR >= 2*r.back()) {
            cout << sumR + sumW << endl;
            continue;
        }
        int gap = 2*r.back()-sumR;
        vector <vector <int>> dp(n + 1, vector <int> (gap + 1, 0));
        dp[0][0] = true;
        range (i, 1, n + 1) {
            dp[i]=dp[i-1];
            if (r.back() == copyR[i - 1]) {
                continue;
            }
            for(int j=gap;j>=0;j--){
                if (j - w[i - 1] < 0) continue;
                dp[i][j] |= dp[i - 1][j - w[i - 1]];
            }
        }
        int maxJ = 0;
        rep (j, gap + 1) if (dp[n][j]) maxJ = max(maxJ, j);
        cout << sumR + sumW + (gap - maxJ) << endl;
    }
    return 0;
}


Measured memory_bytes: 3256
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)

int main(){
    
    // 1. 入力情報.
    int N;
    scanf("%d", &N);
    
    // 2. 勝者は？
    // 奇数がある場合
    // -> 奇数部分を first が 食べてから, 後は, second と 同じ内容のりんごを
    // first が 食べることで, first が 勝者.
    // 
    // すべて偶数の場合
    // -> first と 同じ内容のりんごを second が 食べることで, second が 勝者.
    bool ans = false;
    rep(i, N){
        int a;
        scanf("%d", &a);
        if(a & 1) ans = true;
    }
    
    // 3. 出力.
    printf("%s\n", ans ? "first" : "second");
    return 0;
    
}

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

int main() {

while(true){
    int n,m;
    float p;
    cin >> n >> m >> p;
    if(n == 0 && m == 0 && p == 0)break;
    p = (100-p)*0.01;
    
    int x[n+1];
    int sum = 0;
    for(int i = 1;i <= n;i++){
        cin >> x[i];
        sum += x[i];
    }
    int ans = 0;
    ans = sum * 100 * p;
    if(x[m] == 0) ans = 0;
    else ans /= x[m];
    
    cout << ans << "\n";
}
    
return 0;
}

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

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

static void shell_sort(int* array,size_t size);
static void print_array(const int* array,size_t size);

int main(){
    int n;
    int array[1000000];
    cin>>n;
    for(int i=0;i<n;i++)cin>>array[i];
    
    shell_sort(array, n);
    print_array(array, n);
    
    return 0;
}

void shell_sort(int* array,size_t size){
    size_t i,j;
    size_t h,h_tmp;
    int tmp;
    int x=0;
    int cnt=0;
    h=1;
    for (h_tmp=1; h_tmp<=size; h_tmp=h_tmp*3+1) {
        h=h_tmp;
        x++;
    }
    cout<<x<<endl;
    for(size_t k=h;k>0;k=(k-1)/3)cout<<k<<" ";
    cout<<endl;
    
    while (h>0) {
        for (i=h; i<size; i++) {
            tmp=array[i];
            for (j=i; j>=h&&array[j-h]>tmp; j-=h) {
                array[j]=array[j-h];
                cnt++;
            }
            array[j]=tmp;
        }
        h/=3;
    }
    cout<<cnt<<endl;
}

void print_array(const int* array,size_t size){
    size_t i;
    for (i=0; i<size; i++) {
        cout<<array[i]<<endl;
    }
}

Measured memory_bytes: 6968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define se second
const int N = 2e5+5;
bool isp(int x){
    for(int i=2;i*i<=x;i++){
        if(x%i==0)return false;
    }
    return true;
}
void solve(){
    int n;
    cin>>n;
    for(int i=n;i<n+1000;i++){
        if(isp(i)){
            cout<<i<<endl;
            return ;
        }
    }
    assert(false);
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
   // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 3644
// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools

#include <bits/stdc++.h>

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


void solve(std::vector<long long> x){
    for(int i = 0; i < 5; ++i)
        if(x[i] == 0)
            cout << i + 1 << endl;
}


signed main(){
    std::vector<long long> x(5);
    for(int i = 0 ; i < 5 ; i++){
        scanf("%lld",&x[i]);
    }
    solve(std::move(x));
    return 0;
}


Measured memory_bytes: 3696
import java.util.*;

public class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	int n = scan.nextInt();
      	double[] v = new double[n];
      	for (int i = 0; i < n; i ++){
         	v[i] = scan.nextDouble(); 
        }
      	Arrays.sort(v);
      	for(int j = 0; j < n-1; j++){
        	v[j + 1] = (v[j] + v[j + 1]) / 2;
        }
      	System.out.print(v[n-1]);
    }
}

Measured memory_bytes: 24532
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long long gcd(long long a, long long b) {
  long long t;
  while (a != 0) {
    t = a;
    a = b % a;
    b = t;
  }
  return b;
}
int main(){
  int N;cin>>N;
  vector<long long> t(N);
  for(int i=0;i<N;i++)
    cin>>t[i];
  sort(t.begin(),t.end(),greater<int>());
  for(int i=0;i<N-1;i++){
    long long a=gcd(t[i],t[i+1]);
    t[i+1]=(t[i]/a*t[i+1]);
  }
  cout<<t[t.size()-1]<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
// debug
#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl;
#define ddd(x, y, z) cerr << "(" #x "," #y "," #z "):(" << x << "," << y << "," << z << ")" << endl;
#define dump(v)              \
  cerr << #v ":[ ";          \
  for (auto macro_vi : v)    \
  {                          \
    cerr << macro_vi << " "; \
  }                          \
  cerr << "]" << endl;
#define ddump(v)                     \
  cerr << #v ":" << endl;            \
  for (auto macro_row : v)           \
  {                                  \
    cerr << "[";                     \
    for (auto macro__vi : macro_row) \
    {                                \
      cerr << macro__vi << " ";      \
    }                                \
    cerr << "]" << endl;             \
  }
#define damp(m)                                                   \
  for (auto macro_pair : m)                                       \
  {                                                               \
    cerr << macro_pair.first << ":" << macro_pair.second << endl; \
  }
#define dpair(p) cerr << #p ":" \
                      << "(" << p.first << "," << p.second << ")" << endl;
// iterate
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define itr(macro_v, i) macro_v.begin() + i
// etc
#define chmin(mi, val) mi = min(mi, val);
#define chmax(ma, val) ma = max(ma, val);
using ll = long long;

using namespace std;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> v(n, 0ll);
  ll sum = 0ll;
  rep(i, n)
  {
    cin >> v[i];
    sum += v[i];
  }
  vector<ll> L(n + 1, 0ll);
  for (int i = 0; i < n; i++)
  {
    L[i + 1] = L[i] + v[i];
  }
  ll mi = 1e18;
  for (int i = 0; i <= n; i++)
  {
    mi = min(mi, abs(L[i] - (sum - L[i])));
  }
  cout << mi << endl;
  return 0;
}

Measured memory_bytes: 3456
#include <algorithm>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <map>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
const int inf = 1 << 30;
const int INF = INT_MAX;

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  char b, ans;
  cin >> b;
  switch (b) {
  case 'A':
    ans = 'T';
    break;
  case 'T':
    ans = 'A';
    break;
  case 'G':
    ans = 'C';
    break;
  default:
    ans = 'G';
    break;
  }
  cout << ans << endl;
  return 0;
}

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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

bool comp(int a, int b){
    return (a<b);
}

int main(){
    int a, b; cin >> a >> b;
    cout << (a*b)-a-b+1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long signed long;
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; i++)
using namespace std;
constexpr ll INF = ~0ULL >> 4;

int main() {

    ll n; cin >> n;
    vector<ll> r(n);
    REP(i, n) cin >> r[i];
    vector<vector<ll>> spc(3, vector<ll>(n, 0));
    REP(i, n) cin >> spc[0][i] >> spc[1][i] >> spc[2][i];

    ll ans = INF;
    REP(i, 3) {
        ll xok = INF;
        ll xng = -1;
        while (xok - xng > 1) {
            ll xmd = (xok + xng) / 2;
            vector<pair<ll, ll>> v(n);
            vector<ll> pts(n, 0);
            REP(ii, 3) {
                REP(j, n) v[j] = make_pair((j == 0 && ii == i ? xmd : 0) + spc[ii][j], j);
                sort(v.begin(), v.end(), greater<pair<ll, ll>>());
                for (ll k = 0, l = 0; k < n; k++) {
                    if (k && v[k-1].first != v[k].first) {
                        l = k;
                    }
                    pts[v[k].second] += r[l];
                }
            }
            vector<ll> ranking(n);
            iota(ranking.begin(), ranking.end(), 0LL);
            sort(ranking.begin(), ranking.end(), [&](ll i, ll j) {
                return pts[i] > pts[j];
            });
            const bool okay = [&](){
                for (ll k = 0, l = 0; k < n; k++) {
                    if (k && pts[ranking[k]] != pts[ranking[k-1]]) {
                        l = k;
                    }
                    if (ranking[k] == 0) {
                        return l < 8;
                    }
                }
                return false;
            }();
            (okay ? xok : xng) = xmd;
        }
        ans = min(ans, xok);
    }
    if (ans == INF) {
        cout << "Saiko" << endl;
    } else {
        cout << ans << endl;
    }

}


Measured memory_bytes: 3164
#include <iostream>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <float.h>
#include <queue>
#include <cstdio>
#include <iomanip>

using namespace std;
typedef long long ll;
#define loop(i, N) for(int i=0; i<N; ++i)

int n;
int a[110];
int sum = 0;


int main(void) {
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < n; i++)
	{
		for (int j = i+1; j < n; j++)
		{
			sum += a[i] * a[j];
		}
	}

	cout << sum << endl;
	
	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define ll long long
#define M 1000000007
#define all(a) a.begin(), a.end()

char s[100100];
bool tag[30];

int main(){
	scanf("%s", s);
	for(int i = 0; s[i]; ++i)
		tag[s[i] - 'a'] = 1;
	for(int i = 0; i < 26; ++i)
		if(!tag[i]){
			putchar('a' + i);
			return 0;
		}
	puts("None");
	
	return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

using P = std::pair<int, int>;

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

  vector<P> X(4);
  rep(i, 2) cin >> X[i].first >> X[i].second;

  int dx = X[1].first  - X[0].first;
  int dy = X[1].second - X[0].second;

  X[2].first  = X[1].first  - dy;
  X[2].second = X[1].second + dx;
  X[3].first  = X[2].first  - dx; 
  X[3].second = X[2].second - dy;

  cout << X[2].first << ' ' << X[2].second << ' ';
  cout << X[3].first << ' ' << X[3].second << '\n';
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<stdio.h>
using namespace std;
 
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<25
 
int main()
{
	int n ,k;
	int i;
	int c;
	int t;
	cin >> n >> k;
	if (n == k) {
		cout << 1 << endl;
	} else {
		c = 1;
		n -= k;
		c += int(n / (k - 1));
		if (n % (k - 1) != 0) {
			c += 1;
		}
		cout << c << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define vv vector< vector< int > >
#define ll long long
#define ALL(a) (a).begin(), (a).end()
const long long mod = 1000000000 + 7;
const long long INF = 9e18;
const double PI = 3.14159265358979323846;

ll gcd(ll a, ll b){if (b == 0) return a;return gcd(b, a % b);}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }


int main(){
    int N, D, X, ans=0;
    cin >> N >> D >> X;
    vector<int> A(N);
    for(int i = 0; i < N; ++i) cin >> A[i];
    for(int i = 0; i < N; ++i){
        int j = 1;
        while(j <= D){
            ans++;
            j += A[i]; 
        }
    }
    ans += X;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
s=list(input())

if len(s)==2:
    if s[0]==s[1]:
        print(1,2)
    else:
        print(-1,-1)
    exit()
    
for i in range(len(s)-2):
    if s[i]==s[i+2] or s[i]==s[i+1] or s[i+1]==s[i+2]:
        print(i+1,i+3)
        exit()
print(-1,-1)

Measured memory_bytes: 49520
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)

using namespace std;
typedef pair<int, int> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

int N;
string S;

int E_cnt[300001];
int main(int argc, char **argv) {
    cin >> N;
    cin >> S;

    E_cnt[0] = 0;
    for(int i = 0; i < N; ++i)
        E_cnt[i + 1] = E_cnt[i] + (S[i] == 'E');
    
    int res = INF;
    for(int i = 0; i < N; ++i) {
        res = min(res, i - E_cnt[i] + (E_cnt[N] - E_cnt[i + 1]) );
    }

    cout << res << endl;
}

Measured memory_bytes: 1796
def nC2(n)
  n * (n - 1) / 2
end

n = gets.to_i
as = gets.split.map(&:to_i)

cs = Hash.new(0)
as.each do |a|
  cs[a] += 1
end

sum = cs.values.inject(0) do |r, v|
  r + nC2(v)
end

as.each do |a|
  c = cs[a]

  puts sum - (nC2(c) - nC2(c - 1))
end


Measured memory_bytes: 29700
def main():
    from collections import defaultdict
    import sys
    sys.setrecursionlimit(10 ** 9)
    
    H, W = list(map(int, raw_input().split()))
    G = [list(raw_input()) for i in range(H)]
    
    Visited = [[0] * W for i in range(H)]
    direction = [[0, 1], [0, -1], [1, 0], [-1, 0]]
    
    
    def dfs(ny, nx, color):
        for dy, dx in direction:
            if not ((0 <= ny + dy < H) and (0 <= nx + dx < W)):
                continue
    
            if G[ny + dy][nx + dx] == G[ny][nx]:
                continue
    
            if Visited[ny + dy][nx + dx] != 0:
                continue
    
            if G[ny + dy][nx + dx] == '#':
                Visited[ny + dy][nx + dx] = color
            else:
                Visited[ny + dy][nx + dx] = -color
    
            dfs(ny + dy, nx + dx, color)
    
    
    Color = 1
    for y in range(H):
        for x in range(W):
            if Visited[y][x] == 0:
                if G[y][x] == '#':
                    Visited[y][x] = Color
                else:
                    Visited[y][x] = -Color
                dfs(y, x, Color)
                Color += 1
    
    D = defaultdict(int)
    for i in range(1, Color + 1):
        D[i] = 0
        D[-i] = 0
    
    for row in Visited:
        for data in row:
            D[data] += 1
    
    ans = 0
    for key in D.keys():
        ans += D[key] * D[-key]
    
    print(ans // 2)
    
main()


Measured memory_bytes: 205212
use proconio::input;
use std::cmp::max;
fn main(){
    input! {
        a:i64,
        b:i64,
        c:i64,
        d:i64,
    }
    let ans1 = a * c;
    let ans2 = a * d;
    let mx1 = max(ans1,ans2);
    let ans3 = b * c;
    let ans4 = b * d;
    let mx2 = max(ans3, ans4);
    let ans = max(mx1,mx2);
    println!("{}", ans);
}


Measured memory_bytes: 2172
n = gets.chomp.to_i
vs = gets.chomp.split(' ').map(&:to_i)

vs.map!(&:to_f)

loop do
  vs.sort!

  v0 = vs.shift
  v1 = vs.shift

  v = ((v0 + v1) / 2.0)

  if vs.empty?
    puts v
    break
  end

  vs.unshift(v)
end


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

int main() {
	int n, k, h, cou = 0;

	cin >> n >> k;

	for (int i = 0; i < n; ++i) {
		cin >> h;
		if (h >= k) cou++;
	}
	cout << cou << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<eps)
int L,res;
int main()
{
	while(1)
	{
		res=0;
		cin >> L;
		if(L==0)break;
		int ans=-1;
		for(int i=0;i<12;i++)
		{
			int n,m;
			cin >> m >> n;
			res+=m-n;
			if(ans==-1&&res>=L)ans=i+1;
		}
		if(ans==-1)cout << "NA" << endl;
		else cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
// by DenyTianly
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long LL;

const int inf = 1 << 26;

int main(){
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if(c >= a && c <= b) puts("Yes");
	else puts("No");

	return 0;
}


Measured memory_bytes: 256
str = input()
S= list(str)
P=len(S)
i=0
for x in range(0,P):
    if x%2==1:
        if S[x]=="R":
            i=1
    if x%2==0:
        if S[x]=="L":
            i=1
if i==0:
    print("Yes")
if i==1:
    print("No")



Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main(){
  int R[MAX], n;
  cin >> n;
  for(int i =0; i < n;i++) cin >> R[i];
  
  int maxv = -2000000000;
  int minv = R[0];
  
  for(int i=1; i<n; i++){
    maxv = max(maxv, R[i] - minv); 
    minv = min(minv, R[i]);
  }
  cout << maxv << endl;
  
  return 0;
}



Measured memory_bytes: 3864
#include<bits/stdc++.h>
#define ll long long
#define pa pair<int,int>
using namespace std;
int n,m;
int cu[200004];
int dir[200004],dep[200004];
vector<int>G[200004];
vector<pa>ans;
void dfs(int x,int fa){
    for(int i=0;i<G[x].size();i++){
        if(G[x][i]==fa)continue;
        if(!dep[G[x][i]]){
            dep[G[x][i]]=dep[x]+1;
            dfs(G[x][i],x);
        }
        else if(dep[G[x][i]]<dep[x]){
            cu[x]^=1;
            ans.push_back(make_pair(x,G[x][i]));
        }
    }
    if(cu[x]&1){
        cu[x]^=1;
        ans.push_back(make_pair(x,fa));
    }
    else if(fa){
        cu[fa]^=1;
        ans.push_back(make_pair(fa,x));
    }
}
int main(){
    ans.clear();
    memset(dep,0,sizeof(dep));
    memset(dir,0,sizeof(dir));
    memset(cu,0,sizeof(cu));
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        int u,v;scanf("%d%d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    if(m&1)return puts("-1"),0;
    dep[1]=1;
    dfs(1,0);
    for(int i=0;i<ans.size();i++){
        printf("%d %d\n",ans[i].first,ans[i].second);
    }
    return 0;
}


Measured memory_bytes: 20212
from collections import deque
k = int(input())
q = deque(range(1,10))
while k:
    k-=1
    t=q.popleft()
    if t%10 !=0 : q.append(10*t+t%10-1)
    q.append(10*t+t%10)
    if t%10 !=9 : q.append(10*t+t%10+1)

print(t)

Measured memory_bytes: 11900
import heapq
class HeapDict:
    def __init__(self):
        self.h = []
        self.d = {}

    def insert(self,x):
        if x not in self.d or self.d[x] == 0:
            heapq.heappush(self.h, x)
        self.d.setdefault(x,0)
        self.d[x] += 1


    def erase(self,x):
        if x not in self.d or self.d[x] == 0:
            return
        else:
            self.d[x] -= 1

        while self.h:
            if self.d[self.h[0]] == 0:
                heapq.heappop(self.h)
            else:
                break


    def get_min(self):
        if not self.h:
            return None
        else:
            return self.h[0]


    def pop(self):
        poped_val = self.h[0]
        self.erase(poped_val)
        return poped_val


    def exist(self, x):
        return (x in self.d and self.d[x] > 0)


    def show_h(self):
        elems = [v for v in self.h if self.d[v] > 0]
        print(elems)


    def show_d(self):
        print(self.d)



# def main():
n,q = map(int, input().split())
eventl = []

for _ in range(n):
    s,t,x = map(int, input().split())
    eventl.append((s-x, 'a-stop', x)) 
    eventl.append((t-x, 'b-start', x))

for i in range(q):
    d = int(input())
    eventl.append((d,'c-go', i))

eventl.sort()

ans = [0]*q
hd = HeapDict()
for e in eventl:
    if e[1] == 'a-stop':
        hd.insert(e[2])
    elif e[1] == 'b-start':
        hd.erase(e[2])
    else:
        min_x = hd.get_min()
        if min_x is not None:
            ans[e[2]] = min_x
        else:
            ans[e[2]] = -1

for a in ans:
    print(a)


# if __name__ == "__main__":
#     main()

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C;
    cin >> A >> B >> C;
    if ((A <= C && C <= B) || (B <= C && C <= A)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

#define FOR(i,a,n) for(int i = (a); i < (n); ++i)
#define REP(i,n) FOR(i,0,n)
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

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

using ll = long long;

int main() {
  int n, h; cin >> n >> h;
  int a, amax = 0;
  vector<int> b(n);
  REP(i,n) {
    cin >> a >> b[i];
    chmax(amax, a); 
  }
  whole(sort, b, greater<int>()); 
  ll ans = 0, hp = h;
  while (hp > 0 && ans < n && b[ans] >= amax) {
    hp -= b[ans];
    ans++;
  }
  if (hp > 0) {
    ans += (ll)(hp+amax-1)/amax;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int k = scan.nextInt();
        String s = scan.next();
        if(s.length() <= k){
            System.out.println(s);
        }else{
            System.out.println(s.substring(0, k) + "...");
        }
        scan.close();
    }
}

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

int main() {
	string S, T;
	cin >> S >> T;

	int ans = 0;
	for (int i = 0; i < 3; i++) {
		if (S.at(i) == T.at(i)) {
			ans++;
		}
	}
	cout << ans << endl;
}


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

int main() {
  string N;
  cin >> N;
  bool good = false;
  for (int i=0; i+2<N.size(); i++) {
    if (N.at(i)==N.at(i+1)&&N.at(i+1)==N.at(i+2)) {
      good = true;
      break;
    }
  }
  if (good) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner; 
class Main{
  public static void main (String[] args){
    Scanner scanner =new Scanner(System.in);
    int a = scanner.nextInt();
    int b = scanner.nextInt();
    int c = scanner.nextInt();
    int d = scanner.nextInt();
    if(a+b>c+d)
      System.out.println("Left");
    else if(a+b<c+d)
      System.out.println("Right");
    else
      System.out.println("Balanced");
    scanner.close();
  }
}

Measured memory_bytes: 22612
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct RMQ{
  int n;
  vector<int> dat;
  const int def=INT_MAX;
  RMQ(){}
  RMQ(int n_){init(n_);}
  RMQ(int n_,int *a){init(n_);construct(n_,a);}
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    dat.clear();
    dat.resize(2*n-1,def);
  }
  void construct(int n_,int *a){
    for(int i=0;i<n_;i++) dat[n-1+i]=a[i];
    for(int i=n-2;i>=0;i--) 
      dat[i]=min(dat[i*2+1],dat[i*2+2]);
  }
  void update(int k,int a){
    k+=n-1;
    dat[k]=a;
    while(k>0){
      k=(k-1)/2;
      dat[k]=min(dat[k*2+1],dat[k*2+2]);
    }
  }
  int query(int a,int b,int k,int l,int r){
    if(r<=a||b<=l) return def;
    if(a<=l&&r<=b) return dat[k];
    int vl=query(a,b,k*2+1,l,(l+r)/2);
    int vr=query(a,b,k*2+2,(l+r)/2,r);
    return min(vl,vr);
  }
  int query(int a,int b){
    return query(a,b,0,0,n);
  }
};
#define MAX 114514
int n,l;
int a[MAX],b[MAX],c[MAX],d[MAX];
int sum[MAX],rev[MAX];
typedef pair<int,int> P;
vector<P> v;
signed main(){
  cin>>n>>l;
  for(int i=0;i<n;i++) cin>>a[i]>>b[i];
  for(int i=0;i<n;i++) cin>>c[i];
  for(int i=0;i<n;i++){
    if(a[i]>=l){
      cout<<1<<endl;
      return 0;
    }
  }
  for(int i=0;i<n;i++)
    v.push_back(P(a[i]-b[i],i));
  sort(v.begin(),v.end(),greater<P>());
  for(int i=0;i<n;i++)
    rev[v[i].second]=i;
  int ans=n+1;
  memset(sum,0,sizeof(sum));
  int cur=0,tmp=0,z=n,lim=n;
  bool dbg=0;
  for(int i=0;i<n;i++){
    if(v[i].first<0){
      z=i;
      break;
    }
    cur+=v[i].first;
    if(i) d[i-1]=cur-tmp;
    tmp+=c[i];
    sum[i]=cur;
    if(cur<=tmp) lim=min(lim,i);
    if(dbg) cout<<i<<" "<<cur<<" "<<tmp<<endl;
  }
  if(dbg) for(int i=0;i<z-1;i++) cout<<i<<" "<<d[i]<<endl;
  if(dbg) for(int i=0;i<z;i++) cout<<i<<":"<<sum[i]<<endl;
  //cout<<ans<<endl;
  RMQ rmq(z-1,d);
  for(int i=0;i<n;i++){
    {
      int x=l-a[i];
      int pos=lower_bound(sum,sum+z,x)-sum;
      if(pos==z) continue;
      if(pos>=lim) continue;
      if(dbg) cout<<i<<";"<<a[i]<<" "<<b[i]<<" "<<rev[i]<<endl;
      if(dbg) cout<<i<<";"<<x<<" "<<pos<<" "<<endl;
      if(rev[i]<=pos) continue;
      ans=min(ans,pos+2);
    }
  }
  for(int i=0;i<n;i++){
    {
      int x=l-b[i],y=a[i]-b[i];
      int pos=lower_bound(sum,sum+z,x)-sum;
      //cout<<pos<<endl;
      if(pos==z) continue;
      if(rmq.query(rev[i],pos)<=y) continue;
      if(dbg) cout<<i<<":"<<a[i]<<" "<<b[i]<<" "<<rev[i]<<endl;
      if(dbg) cout<<i<<":"<<x<<" "<<y<<" "<<pos<<" "<<rmq.query(rev[i],pos)<<endl;
      if(pos<=rev[i]) continue;
      ans=min(ans,pos+1);
    }
  }
  if(ans>n) ans=-1;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 11432
n,t=map(int,input().split())
arr=list(map(int,input().split()))
start=arr[0]
ans=0
for i in range(1,n):
  tmp=arr[i]
  if tmp-start<t:
    ans+=tmp-start
  else:
    ans+=t
  start=tmp
print(ans+t)


Measured memory_bytes: 26836
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
#define INF 999999999
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;

int main(){
  int n,m;cin >> n >> m;
  vector<pair<Int,Int>> data(n);
  rep(i,n){
    Int a,b;cin >> a >> b;
    data[i] = make_pair(a,b);
  }
  sort(data.begin(),data.end());
  Int ans = 0;
  rep(i,n){
    m-=data[i].second;
    ans+=data[i].first*data[i].second;
    if(m<=0){
      ans-=abs(m)*data[i].first;
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			long mod = 1000000000 + 7;

			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			int n = vs[0];  // 総数
			int b = vs[1];  // 青
			int r = n - b;  // 赤

			// 順列
			// nPr = n! / (n-r)!
			// 組み合わせ
			// nCr = nPr / r! = n! / r!(n-r)!
			// 公式
			// nCr = nCn-r
			// nCr = n-1Cr + n-1Cr-1
			// nC0 = 1
			// nC1 = n
			long[,] dp = new long[n + 2, n + 2];
			for (int i = 0; i <= n; i++) {
				dp[i, 0] = 1;
			}
			for (int j = 1; j <= b; j++) {
				for (int i = j; i <= n; i++) {
					dp[i, j] = (dp[i - 1, j] + dp[i - 1, j - 1]) % mod;
				}
				// r+1Cj * b-1Cj-1
				long ans = dp[r + 1, j] * dp[b - 1, j - 1] % mod;
				Console.WriteLine(ans);
			}


			Console.Out.Flush();
		}
	}
}


Measured memory_bytes: 42080
#pragma GCC optimize("Ofast,fast-math,unroll-loops")
 
#include <bits/stdc++.h>
 
#define int ll
//#define double long double
#define endl '\n'
#define all(C) (C).begin(), (C).end()
#define rall(C) (C).rbegin(), (C).rend()
#define mp make_pair 
#define pb emplace_back
#define dbg(x) cerr << #x << " : " << x << endl
//#define PI 3.141592653589
 
using namespace std;
        
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair <int, int>;
using pld = pair <ld, ld>;
        
/* 
const ll MAX_MEM = 25e7;
char MEM[MAX_MEM];
ll MEM_POS = 0;
void* operator new(size_t x)
{
    auto ret = MEM + MEM_POS;
    MEM_POS += x;
    assert(MEM_POS < MAX_MEM);
    return ret;
}
void operator delete(void*)
{}
*/
        
template <class T>
istream& operator>> (istream &in, vector <T> &a)
{
    for (auto &i : a)
        in >> i;
    return in;
}
        
template <class T> 
ostream& operator<< (ostream &out, vector <T> a)
{
    for (auto &i : a)
        out << i << ' ';
    return out;
}
        
template <class T, class U>
istream& operator>> (istream &in, pair <T, U> &p)
{
    in >> p.first >> p.second;
    return in;
}
        
template <class T, class U>
ostream& operator<< (ostream &out, pair <T, U> p)
{
    out << p.first << " " << p.second << " ";
    return out;
}
        
inline void Start()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //freopen("lol.in", "r", stdin);
    //freopen("lol.out", "w", stdout);
}

const int P = 1e9 + 7;
int add(int a, int b)
{
    return a + b >= P ? a + b - P : a + b;
}
int mul(int a, int b)
{
    return a * b % P;
}
int bpow(int a, int n)
{
    int res = 1;
    while (n)
    {
        if (n & 1)
            res = mul(res, a);
        a = mul(a, a);
        n >>= 1;
    }
    return res;
}
int rev(int x)
{
    return bpow(x, P - 2);
}
int sub(int a, int b)
{
    return add(a, P - b);
}
int divi(int a, int b)
{
    return mul(a, rev(b));
}
struct combinations
{
    vector <int> fact, revfact;
    combinations() {}
    combinations(int n)
    {
        fact.assign(n, 1);
        revfact.assign(n, 1);
        for (int i = 1; i < n; ++i)
            fact[i] = mul(fact[i - 1], i), revfact[i] = divi(revfact[i - 1], i);
    }
    int operator() (int n, int k)
    {
        return mul(fact[n], mul(revfact[k], revfact[n - k]));
    }
};

signed main()
{
    Start();
    int n, k;
    cin >> n >> k;
    combinations c(2001 * 2001);
    if (k == 1)
        return cout << 1, 0;
    vector <vector <int>> dp(n + 1, vector <int> (n + 1));
    dp[0][0] = 1;
    for (int i = 0; i <= n; ++i)
    {
        for (int j = (i ? 0 : 1); j <= n; ++j)
        {
            if (j < i)
                continue;
            if (i)
                dp[i][j] = add(dp[i][j], dp[i - 1][j]);
            if (j)
                dp[i][j] = add(dp[i][j], mul(dp[i][j - 1], c(i + j * (k - 1) - 1, k - 2)));

        }
    }
    cout << mul(dp[n][n], c.fact[n]);
    return 0;
}
 


Measured memory_bytes: 94208
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		  Scanner sc = new Scanner(System.in);
		  
		  int N = sc.nextInt();
		  int array [] = new int [N];

		  List<Integer> listA = new ArrayList<Integer>();
		  for(int i = 0; i<N;i++) {
			listA.add(sc.nextInt());
		  }
		  
		  List<Integer> listB = new ArrayList<Integer>(new HashSet<>(listA));
		  
		  
		  //Arrays.sort(array);
		  //System.out.println(Arrays.toString(array));
		   	   
		  System.out.println(listB.size());

	}

}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define long long long
using namespace std;
const int N=1e6;
long aa[N+2];
map<int,long>dp[N+2];
int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  int n;cin>>n;
  for(int i=1;i<=n;i++)
  {
    cin>>aa[i];
    //aa[i]=rand();
  }

  dp[0][0]=0;dp[1][0]=0;dp[1][1]=aa[1];
  for(int i=2;i<=n;i++)
  {
    for(int j=i/2-4;j<=i/2+4;j++)
    {
      if(j<0)continue;if(j==0)dp[i][j]=0;
      dp[i][j]=-1e18;
      if(dp[i-1].count(j))dp[i][j]=dp[i-1][j];
      if(dp[i-2].count(j-1))dp[i][j]=max(dp[i][j],aa[i]+dp[i-2][j-1]);
    }
  }
  cout<<dp[n][n/2]<<endl;
  return 0;
}

Measured memory_bytes: 164576
#define _USE_MATH_DEFINES
#define INF 100000000
 
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
 
static const double EPS = 1e-8;
 
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};
 
int main(){
	int N,T,E;
	while(~scanf("%d %d %d",&N,&T,&E)){
		int clock[101];
		for(int i=0;i<N;i++){		
			scanf("%d",clock+i);		
		}
 
		bool isok = false;
		for(int i=0;i<N;i++){
			for(int j=clock[i];j<=T+E;j+=clock[i]){
				if(T-E<=j && j<=T+E){
					printf("%d\n",i+1);
					isok = true;
					goto next;
				}
			}
		}
 
		if(!isok) printf("%d\n",-1);
next:;
	}
	return 0;
}

Measured memory_bytes: 1188
import java.util.*;

class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
while(sc.hasNextLong()){
long a=sc.nextLong();
long b=sc.nextLong();
long c=gcd(a,b);
long d=(a*b)/c;
System.out.println(c+" "+d);
}
}
public static long gcd(long x,long y){
long max=Math.max(x,y);
long min=Math.min(x,y);
long amari=max%min;
if(amari==0){return min;}
else{return gcd(min,amari);}
}
}

Measured memory_bytes: 17216
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

class Main {
    public static void main(final String[] args) throws Exception {

        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
            int N = Integer.parseInt(br.readLine());

            int ans = 1;
            while (ans < N) {
                ans *= 2;
            }

            if (ans > N) {
                ans /= 2;
            }

            System.out.println(ans);
        } catch (IOException | NumberFormatException e) {
            e.printStackTrace();
            System.exit(0);
        } catch (final Exception e) {
            e.printStackTrace();
            System.exit(0);
        }
    }
}

Measured memory_bytes: 22612
f=lambda:[*map(int,input().split())]
h,w=f()
g=[f() for _ in range(h)]
a=[]
for x in range(h):
  for y in range(w):
    if g[x][y]%2 and (x+1)*(y+1)<h*w:
      if (t:=y+1)<w: s=x
      elif (s:=x+1)<h: t=y
      g[x][y]-=1
      g[s][t]+=1
      a+=[(x+1,y+1,s+1,t+1)]
print(len(a))
for l in a: print(*l)

Measured memory_bytes: 30464
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val a = (1..n).map { sc.nextInt() }

  val color = Array(8) { false }
  var over = 0
  for (ai in a) {
    if (ai >= 3200) {
      over++
    } else if (ai >= 2800) {
      color[7] = true
    } else if (ai >= 2400) {
      color[6] = true
    } else if (ai >= 2000) {
      color[5] = true
    } else if (ai >= 1600) {
      color[4] = true
    } else if (ai >= 1200) {
      color[3] = true
    } else if (ai >= 800) {
      color[2] = true
    } else if (ai >= 400) {
      color[1] = true
    } else {
      color[0] = true
    }
  }

  val size = color.filter { it }.size
  if (over > 0) {
    if (size == 0) {
      print(1)
    } else {
      print(size)
    }
    print(" ")
    println(size + over)
  } else {
    print(size)
    print(" ")
    println(size)
  }
}


Measured memory_bytes: 37452
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cstdio>
using namespace std;

static const int INF=100000;
static const int MOD=1000000007;
typedef long long ll;
typedef pair<int,int> P;

ll dp[100005][13];

int main(){
    string s;
    cin >> s;
    dp[0][0]=1;
    int N=s.size();
    for(int i=0;i<N;i++){
        if(s[i]=='?'){
            for(int j=0;j<10;j++){ //はてなとしてあり得る値
                for(int k=0;k<13;k++){
                    dp[i+1][(k*10+j)%13]+=dp[i][k];
                    dp[i+1][(k*10+j)%13]%=MOD;
                }
            }
        }else{
            int j=s[i]-'0';
            for(int k=0;k<13;k++){
                dp[i+1][(k*10+j)%13]+=dp[i][k];
                dp[i+1][(k*10+j)%13]%=MOD;
            }
        }
    }
    cout << dp[N][5] << endl;
}


Measured memory_bytes: 10624
s = input().split()  # s[0]は体力, s[1]は攻撃の種類
s2 = list(map(int, input().split()))  # 必殺技のリスト

# print(sum(s2))


if sum(s2) >= int(s[0]):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 13964
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>

#define max 50

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int count_digit(int a){int i=0;while (a!=0) {a=a/10;i++;}return i;}

int main()
{
    int n, i, sum, v[max];
    double ava;
    
    scanf("%d", &n);
    for (i=0; i<n; i++) {
        scanf("%d", &v[i]);
    }
    
    qsort(v, n, sizeof(int), up_comp);
    
    ava=v[0];
    for (i=1; i<n; i++) {
        ava=((double)v[i]+ava)/2;
    }
    
    printf("%lf", ava);
    
    return 0;
}



Measured memory_bytes: 128
from functools import reduce
n = int(input())
s = list(input())
def count_combination(x):
    if sum(x) != n:
        return(0)
    total_count = 1
    false_count = 0
    for i in range(2*n):
        if x[i]:
            total_count = total_count*false_count%(10**9+7)
            false_count -= 1
        else:
            false_count += 1
        if false_count == -1:
            return(0)
    return(total_count)
sb = list(map(lambda x: False if x == 'W' else True, s))
sb[::2] = list(map(lambda x: not x, sb[::2]))

total_count = count_combination(sb)

permutation = reduce(lambda x, y: x*y%(10**9+7), range(1,n+1))

print(total_count * permutation % (10**9+7))

Measured memory_bytes: 8596
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }


int main(int argc, char const *argv[])
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int N, Q;
	ll K;
	std::vector<int> A;
	std::vector<ll> P;
	cin >> N;
	cin >> K;
	cin >> Q;
	A.reserve(Q);
	P.reserve(N);

	int a;

	for (size_t i = 0; i < Q; i++)
	{
		cin >> a;
		A.push_back(a - 1);
	}

	for (size_t i = 0; i < N; i++)
	{
		P.push_back(0);
	}
	
	int winner;
	for (size_t i = 0; i < Q; i++)
	{
		P[A[i]]++;
	}
	
	for (size_t i = 0; i < N; i++)
	{
		if (K - (Q - P[i]) > 0)
		{
			cout << "Yes" << endl;
		} else {
			cout << "No" << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <cstring>
#include <utility>
#include <vector>
#include <climits>
#include <cstdio>
#include <cmath>
#include <unordered_map>
using namespace std;
void solve()
{
	int n;
	cin>>n;n++;
	double ans=0,p[n],dp[n][n];
	for(int i=1;i<n;i++) {cin>>p[i];}
	

	dp[1][1]=p[1];dp[1][0]=1-p[1];
	for(int i=2;i<n;i++)
	{
		dp[i][0]=dp[i-1][0]*(1-p[i]);
		for(int j=1;j<i;j++)
		{
			dp[i][j]=dp[i-1][j]*(1-p[i])+dp[i-1][j-1]*p[i];
		}
		dp[i][i]=dp[i-1][i-1]*p[i];
	}
	// cout<<'\n';
	// for(int i=1;i<n;i++)
	// {
	// 	for(int j=1;j<=i;j++)
	// 	{
	// 		cout<<dp[i][j]<<' ';
	// 	}
	// 	cout<<'\n';
	// }
	n--;
	for(int i=n/2+1;i<=n;i++)
	{
		ans+=dp[n][i];
	}
	cout<<ans<<'\n';
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(12);

	// int t;
	// cin>>t;
	// while(t--)
    solve();
    return 0;
}

Measured memory_bytes: 70400
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(true){
			int n = cin.nextInt();
			if(n==0){
				break;
			}
			int a[] = new int[n];
			int b[] = new int[n];
			int suma=0, sumb=0;
			for(int i = 0; i < n;i++){
				a[i]=cin.nextInt();
				b[i]=cin.nextInt();
				if(a[i] > b[i]){
					suma += a[i]+b[i];
				}
				else if(a[i] < b[i]){
					sumb += a[i]+b[i];
				}
				else{
					suma += a[i];
					sumb += b[i];
				}
			}
			System.out.println(suma + " " + sumb);
		}
			
	}

}

Measured memory_bytes: 13000
/* Bismillahirrahmanirrahim */
/* Author : Jehian Norman Saviero (@Reiva5) */
#include <bits/stdc++.h>
 
// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std
 
Jehian Norman Saviero;
 
// MACROS TYPE
typedef long l;
typedef unsigned long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;
 
// MACROS FOR PRINT
#define nl printf("\n")
#define sp printf(" ")
 
// MACROS FOR ATTRIBUTE
#define fi first
#define se second
 
// MACROS FOR FUNCTION AND METHOD
#define eb emplace_back
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ALL(x) (x).begin(), (x).end()
#define ALLN(x,n) (x), (x)+(n)
#define CUBE(x) (SQR(x)*(x))
#define SET(x,y) for (int _qwe = sizeof(x)/sizeof(x[0]); _qwe; ) x[--_qwe] = (y)
#define SQR(x) ((x)*(x))
#define SSORT(x,sz) sort(ALLN(x,sz))
#define RESET(x) memset((x), 0, sizeof(x))
#define VSORT(x) sort(ALL(x))
 
// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)

int main() {
	ll N, K;
	scll(N), scll(K);
	vll dat(N);
	for (int i = 0; i < N; ++i) {
		scll(dat[i]);
	}
	VSORT(dat);
	while (!dat.empty() && K--) {
		dat.ppb();
	}
	ll tot = 0;
	for (auto &it : dat) {
		tot += it;
	}
	printf("%lld\n", tot);
	return 0;
}

Measured memory_bytes: 1792
from collections import deque
n = int(input())
u = []
k = []
v = []

for i in range(n):
    tmp = list(map(int, input().split()))
    u.append(tmp[0])
    k.append(tmp[1])
    if tmp[1] != 0:
        v.append(tmp[2:])
    else:
        v.append([])
        
check = [0]*n
intime = [0]*n
outtime = [0]*n
time = 1

def dfs(v, start):
    d = deque()
    d.append(start)
    global check
    global intime
    global outtime
    global time
    check[start-1] = 1
    intime[start-1] = time
    time += 1
    while len(d) > 0:
        visit = d[-1]
        tf = True
        for dtn in v[visit-1]:
            if check[dtn-1] == 0:
                d.append(dtn)
                check[dtn-1] = 1
                intime[dtn-1] = time
                time += 1
                tf = False
                break
        if tf:
            outtime[visit-1] = time
            d.pop()
            time += 1

dfs(v, 1)
for i in range(n):
    if check[i] == 0:
        dfs(v, i+1)
for i in range(n):
    print(i+1, intime[i], outtime[i])


Measured memory_bytes: 6044