akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int m;
vector<int> v;
int num[10] = {0,2,5,5,4,5,6,3,7,6};
int dp[10010][10];
int pre[10010][10];
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a;
    cin >> a;
    v.push_back(a);
  }
  for (int i = 0; i < 10010; i++) {
    for (int j = 0; j < 10; j++) {
      dp[i][j] = -1;
      pre[i][j] = -1;
    }
  }
  sort(v.begin(), v.end());
  for (int i = 0; i < m; i++) {
    dp[0][i] = 0;
  }
  int mx = -1;
  int pos = -1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      for (int k = j; k < m; k++) {
        int use = num[v[j]];
        if (dp[i+use][k] < dp[i][j]+1) {
          dp[i+use][k] = dp[i][j]+1;
          pre[i+use][k] = j;
        }
        else if (dp[i+use][k] == dp[i][j]+1) {
          pre[i+use][k] = max(pre[i+use][k],j);
        }
        if (dp[i+use][k] > mx && i+use == n) {
          mx = dp[i+use][k];
          pos = k;
        }
        else if (i+use == n && dp[i+use][k] == mx) {
          pos = max(pos,k);
        }
      }
    }
  }
  int y = n;
  int x = pos;
  // for (int i = 0; i <= n; i++) {
  //   for (int j = 0; j < m; j++) {
  //     cout << pre[i][j] << " ";
  //   }
  //   cout << endl;
  // }
  while (1) {
    // cout << x << " " << y << endl;
    cout << v[pre[y][x]];
    int kk = v[pre[y][x]];
    x = pre[y][x];
    y -= num[kk];
    if (y == 0) break;
  }
  cout << endl;
}

/*　【提出前に確認すること】
・コンパイルできるか
・テストケース試したか
・オーバーフローあるか
*/


Measured memory_bytes: 1024
/*
 * @Author: your name
 * @Date: 2019-12-19 20:34:04
 * @LastEditTime: 2019-12-19 20:35:50
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \code\AT2391.cpp
 */
#include <bits/stdc++.h>
using namespace std;
int a,b,c;
int main() {
   //freopen(".in", "r", stdin);
  //freopen(".out", "w", stdout);
  scanf("%d %d %d",&a,&b,&c);
  if(b-a==c-b) puts("YES");
  else
  {
       puts("NO");
  }
  
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int r, g, b;
  cin >> r >> g >> b;
  int a = 100*r+10*g+b;
  if(a%4 == 0){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
}

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

using namespace std;

int main(){
	int n;
	cin>>n;
	vector<int> in(n);
	for(int i = 0 ; i < n ; i++) cin>>in[i];
	int dp[100005] = {0};
	dp[0] = 0 , dp[1] = abs(in[1] - in[0]);
	for(int i = 1 ; i < n ; i++){
		dp[i] = min(dp[i - 1] + abs(in[i] - in[i - 1]) , dp[i - 2] + abs(in[i] - in[i - 2]));
	}
	cout<<dp[n - 1]<<endl;
}

Measured memory_bytes: 4028
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

template<class U, class V>
ostream& operator <<(ostream& out, pair<U, V>& p) {
    return out << p.first << " " << p.second;
}

template<class T>
ostream& operator <<(ostream& out, vector<T> vec) {
    for (T& e : vec)
        out << e << " ";
    return out << endl;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;
    cin >> N;
    cout << ++N / 2 << endl;
    return 0;
};

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    string s;
    cin>>s;
    int ans=1e9+5;
    int n=s.length();
    rep(i,n-2){
        string t=s.substr(i,3);
        int a=(t[0]-'0')*100+(t[1]-'0')*10+(t[2]-'0');
        ans=min(ans,abs(a-753));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<cstdlib>
#include<iostream>
#include<string>

using namespace std;

struct Node {
  int key;
  Node* right;
  Node* left;
  Node* parent;
};

Node* root;
Node* NIL;

Node* 
treeMinimum(Node* x) {
  while (x->left != NIL) {
    x = x->left;
  }
  return x;
}

Node* find(Node* u, int k) {
  while (u != NIL && k != u->key) {
    if (k < u->key) {
      u = u->left;
    } else {
      u = u->right;
    }
  }
  return u;
}

Node* treeSuccessor(Node* x) {
  if (x->right != NIL) {
    return treeMinimum(x->right);
  }
  Node* y = x->parent;
  while (y != NIL && x == y->right) {
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node* z) {
  Node* y; // node to delete
  Node* x; // child of node y

  if (z->left == NIL || z->right == NIL) {
    y = z;
  } else {
    y = treeSuccessor(z);
  }

  if (y->left != NIL) {
    x = y->left;
  } else {
    x = y->right;
  }

  if (x != NIL) {
    x->parent = y->parent;
  }

  if (y->parent == NIL) {
    root = x;
  } else {
    if (y == y->parent->left) {
      y->parent->left = x;
    } else {
      y->parent->right = x;    
    }
  }

  if (y != x) {
    z->key = y->key;
  }

  free(y);
}

void insert(int k) {
  Node* y = NIL;
  Node* x = root;
  Node* z;

  z = (Node*) malloc(sizeof(Node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL) {
    y = x;
    if (z->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;
  if (y == NIL) {
    root = z;
  } else {
    if (z->key < y->key) {
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void preOrder(Node* u) {
  if (u == NIL) {
    return;
  }
  cout << " " << u->key;
  preOrder(u->left);
  preOrder(u->right);
}

void inOrder(Node* u) {
  if (u == NIL) {
    return;
  }
  inOrder(u->left);
  cout << " " << u->key;
  inOrder(u->right);
}

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

  int x;
  string com;
  for (int i = 0; i < N; i++) {
    cin >> com;
    if (com == "insert") {
      cin >> x;
      insert(x);
    } else if (com == "find") {
      cin >> x;
      Node* f = find(root, x);
      if (f != NIL) {
        cout << "yes" << endl;
      } else {
        cout << "no" << endl;
      }
    } else if (com == "print") {
      inOrder(root);
      cout << endl;
      preOrder(root);
      cout << endl;
    } else if (com == "delete") {
      cin >> x;
      treeDelete(find(root, x));
    }
  }

  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> W(N);
  vector<int> V(N);
  int a, b, c;
  for(int i = 0; i < N; i++) {
    cin >> W.at(i);
  }
  for(int i = 0; i < N; i++) {
    a = a + W.at(i);
  }
  for(int i = 0; i < N; i++) {
    b = b + W.at(i);
    c = abs(a-2*b) ;
    V.at(i) = c;
  }
  sort(V.begin(), V.end());
  cout << V.at(0) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>
#include <bitset>
#include <cstdint>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

const i64 mod = 1e9 + 7;
i64 n, m;
vector<i64> a, b, dp;

i64 f(i64 x) {
  if (dp[x] >= 0) return dp[x];
  if (b[x]) return 0;
  if (x <= 1) return 1;
  return dp[x] = (f(x - 1) + f(x - 2)) % mod;
}

int main() {
  cin >> n >> m;
  read_n(a, m);
  init_n(b, n + 1);
  for (i64 x : a) {
    b[x] = 1;
  }
  init_n(dp, n + 1, -1);
  cout << f(n) << '\n';
  return 0;
}



Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define gr vector<vpii>
#define str string
#define mask vector<bool>
#define vs vector<str>
#define pq priority_queue
#define ordered_set_of(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define nub(x) x.resize(unique(all(x)) - x.begin())
#define TWO class T1, class T2
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define GAME_OVER return 0
using namespace std;
using namespace __gnu_pbds;
char _$ = ' ';
struct sep {sep(char c) {_$ = c;}};
ostream& operator<<(ostream& o, sep s) {return o;}
template<TWO> ostream& operator<<(ostream& o, pair<T1, T2> x) {return o << x.fi << ' ' << x.se;}
template<TWO> istream& operator>>(istream& i, pair<T1, T2>& x) {return i >> x.fi >> x.se;}
template<class T> ostream& operator<<(ostream& o, vector<T> x) {for (auto it : x) o << it << _$; return o;}
template<class T> istream& operator>>(istream& i, vector<T>& x) {for (auto& it : x) i >> it; return i;}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    vi a(n - 1);
    cin >> a;
    vi cnt(n + 1);
    for (int i : a) 
        cnt[i]++;
    for (int i = 1; i <= n; i++)
        cout << cnt[i] << endl;
    GAME_OVER;
}

Measured memory_bytes: 6336
import java.util.*;

public class Main {
    public static void main(String... args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        HashMap<String, Data> map = new HashMap<>();

        for (int i = 0; i < N; i++) {
            String s = scanner.next();
            map.putIfAbsent(s, new Data(s, 0));
            map.get(s).plus(1);
        }

        HashMap<Integer, ArrayList<Data>> map1 = new HashMap<>();
        // reduceでやるの大変だったのでforEachでやる
        map.values().stream().forEach(v -> {
            map1.putIfAbsent(v.getCount(), new ArrayList<>());
            map1.get(v.getCount()).add(v);
        });

        Integer max = map1.keySet().stream().max(Comparator.naturalOrder()).get();
        map1.get(max).stream().sorted(Comparator.comparing(Data::getKey)).forEach(it -> {
            System.out.println(it.getKey());
        });

    }
}

class Data {
    private String key;
    private int count;

    public Data(String key, int count) {
        this.key = key;
        this.count = count;
    }

    public void plus(int num) {
        this.count += num;
    }

    public String getKey() {
        return key;
    }

    public int getCount() {
        return count;
    }


}


Measured memory_bytes: 94240
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
	int a[4],b[4];
	while(cin>>a[0]>>a[1]>>a[2]>>a[3]>>b[0]>>b[1]>>b[2]>>b[3]){
		int hit=0,bl_a=0,bl_b=0,blow=0;
		for(int i=0;i<4;i++){
			if(a[i]==b[i])hit++;
			else{bl_a+=1<<(a[i]-1);bl_b+=1<<(b[i]-1);}
		}
		int ans=bl_a&bl_b;
		for(int i=0;i<10;i++)if(ans>>i&1)blow++;
		printf("%d %d\n",hit,blow);
	}
    return 0;
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n , w , arr[101][2]={};
ll dp[101][100001];

ll f(int i = 1 , int t = 0)
{
    ll &d = dp[i][t];
    if( i == n )
        return ( t+arr[n][0] <= w ? arr[n][1] : 0 );
    if( d != -1 )
        return d;
    d = f(i+1,t);
    if( t + arr[i][0] <= w )
        d = max( d , f(i+1,t+arr[i][0]) + arr[i][1] );
    return d;
}
int main()
{
    memset(dp,-1,sizeof dp);
    cin >> n >> w;
    for(int i=1;i<=n;++i)
        cin >> arr[i][0] >> arr[i][1];
    cout << f();
    return 0;
}

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

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

using namespace std;

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

int main(){
	int n,k; scanf("%d%d",&n,&k);
	vector<int> a(n);
	rep(i,n) scanf("%d",&a[i]);

	int mx=0,g=0;
	rep(i,n) mx=max(mx,a[i]), g=gcd(g,a[i]);

	puts(k%g==0&&k<=mx?"POSSIBLE":"IMPOSSIBLE");

	return 0;
}


Measured memory_bytes: 640
import sys

input = sys.stdin.readline


def ii():
    return int(input())


def il():
    return list(map(int, input().split()))


A, B = il()
c = 0
for i in range(A, B + 1):
    s = str(i)
    if s == s[::-1]:
        c += 1
print(c)


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

typedef long long int ll;

int main()
{
    int n, m;
  	cin>>n>>m;
  	
  	int sum = 0;
  	for(int i=0;i<m;i++)
    {
      int var;
      cin>>var;
      sum+=var;
    }
  	if(sum > n)
    {
      cout<<"-1";
    }
  else
  {
    cout<<(n - sum);
  }
   	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>

using namespace std;
int N;

long double dp[3030][3030];

long double p[3030];

int main(void) {

	cin >> N;

	for (int i = 1; i <= N; i++) { cin >> p[i]; }

	dp[0][0] = 1.0L;

	for (int i = 1; i <= N; i++) {
		for (int k = 0; k <= i; k++) {
			dp[i][k] += dp[i - 1][k] * (1.0L - p[i]);
			if (k - 1 >= 0) { dp[i][k] += dp[i - 1][k - 1] * p[i]; }
		}
	}

	long double ans = 0.0;

	for (int k = (N + 1) / 2; k <= N; k++) {
		ans += dp[N][k];
	}

	cout << setprecision(12) << fixed << ans << endl;

	//system("pause");
	return 0;
}

Measured memory_bytes: 141952
S = input()

S = S[::-1]

def solve(s):
  words = [
    'dreamer'[::-1],
    'eraser'[::-1],
    'dream'[::-1],
    'erase'[::-1],
  ]
  while s:
    for w in words:
      if s.startswith(w):
        s = s[len(w):]
        break
    else:
      return False
  return True

if solve(S):
  print('YES')
else:
  print('NO')

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

int main(){
  int A, B;
  cin >> A >> B;

  int ans = 0; //回文数をカウントする

  /*1 <= a <= 9
    0 <= b <= 9
    0 <= c <= 9
  */

  for(int a = 1; a < 10; a++){
    for (int b = 0; b < 10; b++) {
      for (int c = 0; c < 10; c++) {
        int x = a*10001 + b*1010 + c*100;
        if (x >= A && x <= B) ans++;
      }
    }
  }
  cout << ans;

  
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define reg register
#define maxn 500001
using namespace std;
inline int  read() {
    reg int s = 0, t = 0; reg char ch = getchar();
    while(ch > '9' || ch < '0') t |= ch == '-', ch = getchar();
    while(ch >= '0' && ch <= '9') s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
    return t ? -s : s;
}
int nt[maxn << 1], go[maxn << 1], fi[maxn << 1], vis[maxn << 1], deg[maxn], cnt, n;
queue <int> Q;
void add(int u, int v){
    nt[++cnt] = fi[u]; fi[u] = cnt; go[cnt] = v;
}
int main()
{
    n = read();
    for(int i = 1; i < n; i++){
        int x = read(), y = read();
        add(x, y); add(y, x);
        deg[x]++; deg[y]++;
    } 
    for(int i = 1; i <= n; i++) {
        if(deg[i] == 1) Q.push(i); 
    }
    while(!Q.empty()){
        int x = Q.front(); Q.pop(); vis[x] = 1;
        for(int i = fi[x]; i; i = nt[i]){
            int v = go[i];  if(vis[v]) continue; 
            vis[v] = 1; deg[v]--; 
            for(int j = fi[v]; j; j = nt[j]){
                int t = go[j]; if(vis[t]) continue; deg[t]--; 
                if(deg[t] == 0) {
                    printf("First\n"); return 0;
                }
                if(deg[t] == 1)  Q.push(t);
            } 
            break;
        }
    }
    printf("Second\n");
}

Measured memory_bytes: 15232
import math
def ints():
  return [int(x) for x in input().split()]
def ii():
  return int(input())

a, b, x = ints()
x /= a

if x>=a*b/2:
  space = a*b - x
  theta = math.atan(2*space/a**2)
else:
  theta = math.atan(b/(2*x/b))
  
print(theta*180/math.pi)


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

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int m;
  cin >> m;
  ll sum = 0, digit = 0;
  while (m--) {
    ll d, c;
    cin >> d >> c;
    sum += d * c;
    digit += c;
  }
  cout << (digit - 1) + ((sum - 1) / 9) << endl;
  return 0;
}

Measured memory_bytes: 384
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

const int MAX=2e6+1; //nCrのnのMAX+1
ll fac[MAX],finv[MAX],inv[MAX],sinv[MAX];

void cominit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  sinv[0]=0,sinv[1]=1;
  for (int i=2;i<MAX;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
    sinv[i]=sinv[i-1]+inv[i]%mod;
  }
}
ll com(int n,int k){ //1≦k≦n≦10^7
  if (n<k) return 0;
  if (n<0||k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
//Add cominit(); in main function.

int main(){
  cominit();
  int n; cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  ll ans=0;
  rep(i,n){
    ll left=(sinv[i+1]-1+mod)%mod;
    ll right=(sinv[n-1-i+1]-1+mod)%mod;
    ans+=a[i]*fac[n]%mod*(left+right+1)%mod;
    ans%=mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 66608
M,D = map(int,input().split())

d10 = 2
d = 2

ans = 0

flag = 0
while True:
    if flag == 1:
        break
    while True:
        if d10*10 + d > D:
            flag = 1
            break
        if d >= 10:
            break
        if d10*d <= M:
            ans += 1
        d += 1
    d10 += 1
    d = 2

print(ans)


Measured memory_bytes: 38384
M,z,s=998244353,1,0
d=[1]+[0]*7**6
e=[1]+[0]*7**6
for _ in'_'*input():
 a=input();s+=a;i=s;z*=3
 while~i:d[i]+=d[i]+d[i-a]%M;e[i]+=e[i-a]%M;i-=1
i=s
while i*2>=s:z=(z-d[i]*3)%M;i-=1
print(z+~s%2*e[s//2]*3)%M

Measured memory_bytes: 157728
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
const double pi = acos(-1);
namespace {
  template <typename T> inline void read(T &x) {
    x = 0; T f = 1;char s = getchar();
    for(; !isdigit(s); s = getchar()) if(s == '-') f = -1;
    for(;  isdigit(s); s = getchar()) x = (x << 3) + (x << 1) + (s ^ 48);
    x *= f;
  }
}
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define _for(n,m,i) for (register int i = (n); i < (m); ++i)
#define _rep(n,m,i) for (register int i = (n); i <= (m); ++i)
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
#define lowbit(x) x & (-x)
#define pii pair<int,int>
#define fi first
#define se second
int main() {
  string s, t;
  cin >> s >> t;
  int a, b; cin >> a >> b;
  string k;
  cin >> k;
  if(k == s) a--;
  if(k == t) b--;
  cout << a << " " << b << endl;
}

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

int main()
{
	constexpr char find_chars[]{ 'A', 'C', 'G', 'T' };

	std::string in;
	std::cin >> in;

	const auto input_size = in.size();
	const char* input_data = in.data();
	uint32_t out_count = 0;
	uint32_t count = 0;
	for (uint32_t i = 0; i < input_size; ++i)
	{
		bool is_correct = false;
		for (auto find_char : find_chars)
		{
			if (input_data[i] == find_char)
			{
				is_correct = true;
				break;
			}
		}

		if (is_correct)
		{
			++count;

			if ((i + 1) == input_size)
			{
				if (count > out_count)
				{
					out_count = count;
				}
			}
		}
		else
		{
			if (count > out_count)
			{
				out_count = count;
			}
			count = 0;
		}
	}

	std::cout << out_count;

	return 0;
}

Measured memory_bytes: 256
#include <cstdint>
#include <cstdio>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <cassert>
#include <stack>
#include <set>
#include <sstream>
using namespace std;
 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef long long Long;


int MA[100010], MI[100010];

int main()
{
	
	int N;
	cin >> N;
	int p = -1;
	for (int i = 0; i < N; ++i) {
		MI[i] = 1;
		MA[i] = 1000000000;
	}
	for (int i = 0; i < N; ++i) {
		int n;
		cin >> n;
		if(n != p){
			MI[i] = MA[i] = n;
		}else{
			MA[i] = n;
		}
		p = n;
	}
	p = -1;
	for (int i = 0; i < N; ++i) {
		int n;
		cin >> n;
		if(i > 0){
			if(p == n){
				if(MI[i-1] > p){
					cout << 0 << endl;
					return 0;
				}else{
					MA[i-1] = min(MA[i-1], n);
				}
			}else{
				if(MI[i-1] > p || MA[i-1] < p){
					cout << 0 << endl;
					return 0;
				}else{
					MI[i-1] = MA[i-1] = p;
				}
			}
		}
		if(i == N-1){
			if(MA[i] < n || MI[i] > n){
				cout << 0 << endl;
				return 0;
			}else{
				MI[i] = MA[i] = n;
			}
		}
		p = n;
	}
	int tot = 1;
	for (int i = 0; i < N; ++i) {
//		cout << MI[i] << " " << MA[i] << endl;
		tot = (tot * 1LL * (MA[i] - MI[i] + 1)) % 1000000007;
	}
	cout << tot << endl;
	
	
}
/*

4
5 10000
3 10000
7 10000
6 6



 */



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  i64 N, A, B, C;
  cin >> N >> A >> B >> C;
  vector<string> s(N);
  for (i64 i = 0; i < N; i++)
    cin >> s[i];
  string ans;
  for (i64 i = 0; i < N; i++)
  {
    if (s[i] == "AB")
    {
      if (A == 0 && B == 0)
      {
        cout << "No" << endl;
        return 0;
      }
      else if (A == B)
      {
        if (s[i + 1] == "AB" || s[i + 1] == "AC")
        {
          A++;
          B--;
          ans += 'A';
        }
        else
        {
          B++;
          A--;
          ans += 'B';
        }
      }
      else if (B < A)
      {
        B++;
        A--;
        ans += 'B';
      }
      else
      {
        A++;
        B--;
        ans += 'A';
      }
    }
    else if (s[i] == "BC")
    {
      if (C == 0 && B == 0)
      {
        cout << "No" << endl;
        return 0;
      }
      else if (C == B)
      {
        if (s[i + 1] == "BC" || s[i + 1] == "AC")
        {
          C++;
          B--;
          ans += 'C';
        }
        else
        {
          B++;
          C--;
          ans += 'B';
        }
      }
      else if (B < C)
      {
        B++;
        C--;
        ans += 'B';
      }
      else
      {
        C++;
        B--;
        ans += 'C';
      }
    }
    else
    {
      if (C == 0 && A == 0)
      {
        cout << "No" << endl;
        return 0;
      }
      else if (C == A)
      {
        if (s[i + 1] == "BC" || s[i + 1] == "AC")
        {
          C++;
          A--;
          ans += 'C';
        }
        else
        {
          A++;
          C--;
          ans += 'A';
        }
      }
      else if (A < C)
      {
        A++;
        C--;
        ans += 'A';
      }
      else
      {
        C++;
        A--;
        ans += 'C';
      }
    }
  }
  cout << "Yes" << endl;
  for (char i : ans)
    cout << i << endl;
  return 0;
}


Measured memory_bytes: 6652
#include<stdio.h>

#define MAX 100000

int parent(int i){
  return i / 2;
}
int left(int i){
  return 2 * i;
}
int right(int i){
  return 2 * i + 1;
}

int main(){
  int H, i, A[MAX + 1];

  scanf("%d",&H);

  for(i = 1 ; i <= H ; i++){
    scanf("%d",&A[i]);
  }
  
    for(i = 1 ; i <= H ; i++){
      printf("node %d: key = %d, ",i,A[i]);
      if(parent(i) >= 1) printf("parent key = %d, ",A[parent(i)]);
      if(left(i) <= H) printf("left key = %d, ",A[left(i)]);
      if(right(i) <= H) printf("right key = %d, ",A[right(i)]);
      printf("\n");
    }

    return 0;
	       
}

Measured memory_bytes: 608
#include <stdio.h>
int main()
{
  int N=0;
  int D=0;
  int a = 0;
  int b = 0;
  (void)scanf("%d %d",&N,&D);

  a = (N+2*D)/(1+2*D);
  printf("%d",a);
  return 0;
}

Measured memory_bytes: 128
let css = Array.init 3 @@ fun _ -> Array.init 3 @@ fun _ -> Scanf.scanf " %d" @@ (+) 0 in
let bs = Array.init 3 @@ fun i -> css.(0).(i) in
let a_s = Array.init 3 @@ fun i -> css.(i).(0) - bs.(0) in
for i = 0 to 2 do
  for j = 0 to 2 do
    if css.(i).(j) <> a_s.(i) + bs.(j) then begin print_endline "No"; exit 0 end
  done
done;
print_endline "Yes"

Measured memory_bytes: 384
H,W=map(int,input().split())
N=int(input())
A=list(map(int,input().split()))
res=[]
for i in range(N):
    res+=[i+1]*A[i]
for h in range(H):
    line=res[W*h:W*(h+1)]
    line=[str(x) for x in line]
    if h%2==0:
        print(' '.join(line))
    elif h%2==1:
        print(' '.join(line[::-1]))

Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1000000007;
const long long INF = 1LL << 60;
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    string s; cin >> s;
    SORT(s);
    if(s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) Yes;
    else No;  

    return 0;
}

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

void bubbleSort( int* a, int n )
{
    for( int i = 0; i < n; i++ )
        for( int j = n - 1; j >= 1 + i; j-- )
            if( a[j] < a[j-1] )
            {
                int temp = a[j];
                a[j] = a[j-1];
                a[j-1] = temp;
            }
}

int main()
{
    int n, a[100], b[100];;

    while( cin >> n )
    {
        if( n == 0 )
            break;

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

        b[0] = a[0];
        for( int i = 1; i < n; i++ )
            b[i] = b[i-1] + a[i];

        int sum = 0;
        for( int i = 0; i < n; i++ )
            sum += b[i];
        
        cout << sum << endl;
        
    }
    return 0;

}


Measured memory_bytes: 3056
use std::cmp::Reverse;
use proconio::{input, fastout};

#[fastout]
fn main() {
    input!{
        n: usize,
        m: usize,
        mut a: [i64; n],
    }

    let sum: i64 = a.iter().fold(0, |mut sum, &x| {sum += x; sum});
    
    a.sort_by_key(|&x| Reverse(x));
    if (&a[m-1] * m as i64 * 4) < sum {
        println!("No");
    } else {
        println!("Yes");
    }
}


Measured memory_bytes: 2192
#include<bits/stdc++.h>
#define fo(i, x, y) for(int i = x, B = y; i <= B; i ++)
#define ff(i, x, y) for(int i = x, B = y; i <  B; i ++)
#define fd(i, x, y) for(int i = x, B = y; i >= B; i --)
#define ll long long
#define pp printf
#define hh pp("\n")
using namespace std;

const int N = 2e5 + 5;

int n, x, y, p[N], q[N], t[N][2];
struct P {
	int x, y, z;
	P(int _x = 0, int _y = 0, int _z = 0) {
		x = _x, y = _y, z = _z;
	}
} a[N]; int a0;

int cmpa(P a, P b) {
	return a.x < b.x;
}

ll s[N], ans;

int main() {
	scanf("%d", &n);
	ll sq = 0;
	fo(i, 1, n) {
		scanf("%d %d", &x, &y);
		ans += x; sq += y;
		if(x > y) swap(x, y);
		a[++ a0] = P(x, i, 0), a[++ a0] = P(y, i, 1);
		p[i] = x; q[i] = y;
	}
	if(sq < ans) ans = sq;
	sort(a + 1, a + a0 + 1, cmpa);
	fo(i, 1, a0) t[a[i].y][a[i].z] = i;
	fo(i, 1, a0) s[i] = s[i - 1] + a[i].x;
	fo(i, 1, n) {
		int x = t[i][0], y = t[i][1];
		if(x > n - 2) ans = min(ans, s[n - 2] + p[i] + q[i]); else
			if(x <= n - 2 && y > n - 1) ans = min(ans, s[n - 1] + q[i]); else
				ans = min(ans, s[n]);
	}
	pp("%lld\n", ans);
}

Measured memory_bytes: 6784
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

struct Scanner<R: Read> {
    reader: R,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn safe_read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.reader
            .by_ref()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            token.parse::<T>().ok()
        }
    }

    fn read<T: FromStr>(&mut self) -> T {
        if let Some(s) = self.safe_read() {
            s
        } else {
            writeln!(std::io::stderr(), "Terminated with EOF").unwrap();
            std::process::exit(0);
        }
    }

    fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.read()).collect()
    }

    fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }
}

trait Joinable {
    fn join(self, sep: &str) -> String;
}

impl<U: ToString, T: Iterator<Item = U>> Joinable for T {
    fn join(self, sep: &str) -> String {
        self.map(|x| x.to_string()).collect::<Vec<_>>().join(sep)
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    std::thread::Builder::new()
        .stack_size(104_857_600)
        .spawn(solve)
        .unwrap()
        .join()
        .unwrap();
}

fn s(x: i64) -> i64 {
    if x == 0 {
        0
    } else {
        x / x.abs()
    }
}

fn func(a: &Vec<i64>, sign: i64) -> u64 {
    let mut sign = sign;
    let mut ans = 0;
    let mut acc = 0;
    for &x in a.iter() {
        if s(acc + x) == sign {
            acc += x;
        } else {
            ans += (acc + x - sign).abs() as u64;
            acc = sign;
        }
        sign *= -1;
    }
    ans
}

fn solve() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    loop {
        let n = sc.read();
        let a: Vec<i64> = sc.vec(n);
        let ans = func(&a, 1);
        let ans = min(ans, func(&a, -1));
        println!("{}", ans);
    }
}


Measured memory_bytes: 8572
#include<iostream>
#include<cmath>
using namespace std;
double PI = acos(-1);
double n;
 
int check(double x){
  int X=PI*x;
  for(int i=X-2;i<=X+2;i++){
    double d= (double)i / x;
    if( PI-n < d && d < PI+n )return i;
  }
  return -1;
}
 
int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    for(int i=1;i<=10000000;i++){
      int x=check(i);
      if(x==-1)continue;
      cout<<x<<"/"<<i<<endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 1228
#include <stdio.h>

int change_x(char *str, int x);

int main(void)
{
	char a[128], b[128], c[128];
	int i;

	while (~scanf(" %[^+]+%[^=]=%s", a, b, c)){
		for (i = 0; i <= 9; i++){
			if (change_x(a, i) + change_x(b, i) == change_x(c, i)) break;
		}
		if (i != 10){
			printf("%d\n", i);
		}
		else {
			puts("NA");
		}
	}

	return (0);
}

int change_x(char *str, int x)
{
	int val = 0;
	int it;

	if (*str == 'X' && str[1] != '\0' && x == 0) return (-1);

	for (it = 0; str[it] != '\0'; it++){
		val *= 10;
		if (str[it] == 'X'){
			val += x;
		}
		else {
			val += str[it] - '0';
		}
	}

	return (val);
}

Measured memory_bytes: 552
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

vs32 d;
vector< vs32 > g;
vs32 color;

enum {
    WHITE,
    GRAY,
    BLACK
};

void dijkstra(int s)
{
    d[s] = 0;
    priority_queue< pair<int, int> > pq;

    pq.push(make_pair(0, s));
    while (!pq.empty())
    {
        pair<int, int> du = pq.top(); pq.pop(); 

        int u = du.second;
        int minv = -du.first;

        color[u] = BLACK;

        if (d[u] < -minv) continue;

        for (auto dv : g[u])
        {
            int v = dv;
            if (color[v] != BLACK && d[v] > d[u] + 1)
            {
                d[v] = d[u] + 1;
                color[v] = GRAY;
                pq.push(make_pair(-d[v], v));
            }
        }
    }
}

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

    int n;
    cin >> n;

    g.resize(n);
    d.resize(n, (int)1e9);
    color.resize(n, WHITE);
    int a, b;
    rep (i, n - 1)
    {
        cin >> a >> b;
        --a; --b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    dijkstra(0);

    color.resize(n, WHITE);
    vs32 even;
    vs32 odd;
    rep (i, n)
    {
        if (d[i] & 1) even.push_back(i);
        else odd.push_back(i);
    }

    vs32 ans(n);
    int eidx = 0;
    int oidx = 0;
    if (odd.size() > n / 3 && even.size() > n / 3)
    {
        for (int i = 1; i <= n; i += 3)
        {
            ans[even[eidx++]] = i;
        }
        for (int i = 2; i <= n; i += 3)
        {
            ans[odd[oidx++]] = i;
        }
        for (int i = 3; i <= n; i += 3)
        {
            if (eidx < even.size()) ans[even[eidx++]] =  i;
            else if (oidx < odd.size()) ans[odd[oidx++]] = i;
        }
    }
    else if (even.size() <= n / 3)
    {
        int i;
        for (i = 3; eidx < even.size() && i <= n; i += 3)
        {
            ans[even[eidx++]] = i;
        }
        for (; i <= n; i += 3) ans[odd[oidx++]] = i;
        for (i = 1; i <= n; i += 3) ans[odd[oidx++]] = i;
        for (i = 2; i <= n; i += 3) ans[odd[oidx++]] = i;
    }
    else
    {
        int i;
        for (i = 3; oidx < odd.size() && i <= n; i += 3)
        {
            ans[odd[oidx++]] = i;
        }
        for (; i <= n; i += 3) ans[even[eidx++]] = i;
        for (i = 1; i <= n; i += 3) ans[even[eidx++]] = i;
        for (i = 2; i <= n; i += 3) ans[even[eidx++]] = i;
    }

    rep (i, n)
    {
        if (i > 0) cout << " ";
        cout << ans[i];
    }
    cout << "\n";
    return 0;
}



Measured memory_bytes: 16624
#include<iostream>
#include<cstring>
#define MAX 30
using namespace std;
int  dp[1<<24];
int n;
int x[MAX],y[MAX],r[MAX],c[MAX];
bool samecol(int a,int b){
	return c[a]==c[b];
}
bool check(int a,int b){//kasanaru
	if((x[a]-x[b])*(x[a]-x[b])+(y[a]-y[b])*(y[a]-y[b])<(r[a]+r[b])*(r[a]+r[b])){
		return 1;
	}else
		return 0;
}
int f(int now,int sum){
	if(dp[now]!=-1)
		return dp[now];
	int ans=0;
	bool flag=true;
	for(int i=0;i<n;i++)
	for(int j=i+1;j<n;j++){
		if((now&(1<<i))&&(now&(1<<j))&&samecol(i,j)&&!check(i,j)){
			
			bool fl=false;
			for(int k=0;k<j;k++){
				if((now&(1<<k))&&check(k,j)){
					fl=true;
					break;
				}
			}
			for(int k=0;k<i;k++){
				if((now&(1<<k))&&check(i,k)){
					fl=true;
					break;
				}
			}
			if(!fl){
			int nnow=now;
			nnow=nnow^(1<<i);
			nnow=nnow^(1<<j);
			flag=false;
			ans=max(ans,f(nnow,sum+2));
			}
		}
	}
	if(flag){
		return sum;
	}
	return dp[now]=ans;
}
int main(){
	while(cin>>n,n){
		for(int i=0;i<n;i++){
			cin>>x[i]>>y[i]>>r[i]>>c[i];
		}
		memset(dp,-1,sizeof(dp));
		f((1<<n)-1,0);
		if(dp[(1<<n)-1]==-1)
			cout<<0<<endl;
		else
			cout<<dp[(1<<n)-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
  int a,b,c,ans=0; 
  cin >> a >> b >> c;
  for(int i=a; i<=b; i++) {
      if(c%i==0) {
          ans++;
      }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3108
N,K,Q = map(int,input().split())
ANS = [0] * N
A = [int(input()) for _ in range(Q)]
for a in A:
  ANS[a-1] += 1
  
for i in range(N):
  p = K - Q + ANS[i]
  if p <= 0:
    print('No')
  else:
    print('Yes')
    
exit()


Measured memory_bytes: 8632
from collections import Counter
import sys

def prime_factorize(n):
    ans = []
    while not n%2:
        ans.append(2)
        n //= 2
    mod = 3
    while mod**2 <= n:
        if n%mod == 0:
            ans.append(mod)
            n //= mod
        else:
            mod += 2
    if n != 1:
        ans.append(n)
    counter = Counter(ans)
    return counter


def main():
    input = sys.stdin.readline
    n = int(input())
    primes = prime_factorize(n)
    ans = 0
    for v in primes.values():
        value = v
        if value <= 2:
            ans += 1
            continue
        ans += 1
        value -= 2
        k = 3
        while value > 0:
            value -= k
            k += 1
            ans += 1
            
          
    print(ans)
    
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 9480
n = int(input())
st = []
for _ in range(n):
    st.append([str(i) for i in input().split()])
x = str(input())
y = 0
flag = False
ans = 0
for i in range(n):
    st[i][1] = int(st[i][1])
    if flag:
        ans += st[i][1]
    if st[i][0] == x:
        flag = True
print(ans)


Measured memory_bytes: 38256
#include <cstdio>
#include <algorithm>
using namespace std;
int primes[10001];

bool isPrime(int n) {
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}

int main()  {

    primes[1] = 2;
    primes[2] = 5;
    int idx = 3, num = 4;
    while (idx <= 10000) {
        if (isPrime(num)) {
            primes[idx] = primes[idx-1] + num;
            idx++;
        }
        num++;
    }
    int n;
    for (; ;) {
        scanf("%d", &n);
        if (n == 0) break;
        printf("%d\n", primes[n]);
    }
    return 0;
}



Measured memory_bytes: 2712
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
#include<stdio.h>
#include <cstdint>
#include <stdlib.h> 
#include <time.h>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define RNG(x, a, n) &((x)[a]), &((x)[n])
typedef pair<int, int> PII;
typedef long long ll;
template<typename T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;


ll n, k, ans;
ll h[200005];

int main() {

	cin >> n >> k;
	rep(i, n)cin >> h[i];

	sort(h, h + n);
	reverse(h, h + n);

	rep(i, k) {
		h[i] = 0;
	}
	rep(i, n) {
		ans += h[i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
const int MIN_VAL = 1001001001;
int main(void) {
  int N,M,X;
  cin >> N >> M >> X;

  vector<int> C(N);
  int A[12][12];

  for(int i=0; i<N; i++){
      cin >> C[i];
    for(int j=0; j<M; j++){
      cin >> A[i][j];
    }
  }

  long long int ans = MIN_VAL;

  for(int b=0; b< (1<<N); b++){
    long long int C_cktmp = 0;
    vector<int> X_cktmp(M);
    for(int i=0; i<N; i++){
      if(b>>i & 1){
        C_cktmp += C[i];
        for(int j=0; j<M; j++){
          X_cktmp[j] += A[i][j];
        }
      }
    }
    bool flag = true;
    for(int j=0; j<M; j++){
      if(X_cktmp[j]<X)
        flag = false;
    }
    if(flag)
      ans = min(ans,C_cktmp);
   }

  if(ans==MIN_VAL)
    cout << -1 << endl;
  else
    cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3576
def main():
    n = int(input())
    s = input()
    ls_first = [-1 for _ in range(10)]
    ls_last = [-1 for _ in range(10)]


    for i,now in enumerate(s):
        ls_last[int(now)] = i
        if ls_first[int(now)] == -1:
            ls_first[int(now)] = i

    ans = 0
    for i in range(10):
        for j in range(10):
            if ls_first[i]==-1 or ls_last[j]==-1:
                pass
            else:
                now = set([])
                for k in range(ls_first[i]+1,ls_last[j]):
                    now.add(int(s[k]))
                ans += len(now)
    print(ans)    


if __name__ == "__main__":
    main()

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

int main(){
	int a, b;
	cin >> a >> b;
	if (a <= 8 && b <= 8) {
		cout << "Yay!";
	}
	else
	{
		cout << ":(";
	}

}

// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント: 
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します 
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


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

#define rep(i,n) for(int i=0; i<n; i++)
#define repr(i,a,b) for(int i=a; i<b; i++)

typedef long long ll;

int main(void) {
  int L,R;
  cin >> L >> R;

  if(R-L > 2019) {
    cout << 0 << endl;
    return 0;
  }

  ll ans = 2020;
  repr(i,L,R) {
    repr(j,i+1,R+1) {
      ans = min(ans, (ll)i*j%2019);
      if(ans == 0) {
        cout << 0 << endl;
        return 0;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	static ArrayList<Integer>[] lists;
	static int n;
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		int m = sc.nextInt();
		lists = new ArrayList[n + 1];
		for (int i = 1; i <= n; i ++) {
			lists[i] = new ArrayList<Integer>();
		}
		for (int i = 0; i < m; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			lists[a].add(b);
			lists[b].add(a);
		}
		int count = search(1, new boolean[n + 1]);
		System.out.println(count);
	}
	
	static int search(int idx, boolean[] arr) {
		arr[idx] = true;
		boolean flag = true;
		for (int i = 1; i <= n; i++) {
			if (!arr[i]) {
				flag = false;
				break;
			}
		}
		if (flag) {
			return 1;
		}
		int ret = 0;
		for (int x : lists[idx]) {
			if (!arr[x]) {
				ret += search(x, arr.clone());
			}
		}
		return ret;
	}
}


Measured memory_bytes: 22996
#include <iostream>

using namespace std;

int main()
{
	int x, y, z;
	int i, j;
	
	cin >> x >> y;
	
	while (y > 0){
		z = x % y;
		x = y;
		y = z;
	}
	
	cout << x << "\n";
	
	return (0);
}



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

int main(void){
    
    int N;
    string S;
    cin >> N >> S;
    
    int ans = 0;
    string pass;
    for(int i = 0; i < 1000; i++){
        
        // passwordの基準設定(000~999)
        pass = (i / 100) + '0'; 
        pass += ((i % 100) / 10) + '0';
        pass += (i % 10) + '0';
        
        int keta = 0;
        for(int j = 0; j < N; j++){
            if(pass[keta] == S[j]) keta++;
        }
        if(keta == 3) ans++;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 3236
import itertools

A = [list(map(int, input().split())) for l in range(3)]
N = int(input())
b = [int(input()) for i in range(N)]

A = list(itertools.chain.from_iterable(A))

X = []

for c in b:
    if c in A:
        X.append(A.index(c))

if (0 in X and 1 in X and 2 in X) or \
        (3 in X and 4 in X and 5 in X) or \
        (6 in X and 7 in X and 8 in X) or \
        (0 in X and 3 in X and 6 in X) or \
        (1 in X and 4 in X and 7 in X) or \
        (2 in X and 5 in X and 8 in X) or \
        (0 in X and 4 in X and 8 in X) or \
        (2 in X and 4 in X and 6 in X):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include<iostream>
using namespace std;
#define MAX 100000
typedef long long ll;

int n, k;
ll T[MAX];

int check(ll P) {
	int i = 0;
	for (int j = 0; j < k; j++) {
		ll s = 0;
		while (s + T[i] <= P) {
			s += T[i];
			i++;
			if (i == n)return n;
		}
	}
	return i;
}

int solve() {
	ll left = 0;
	ll right =100000 * 10000;
	ll mid;
	while (left+1 < right) {
		mid = (left + right) / 2;
		int v = check(mid); //
		if (v >= n)right = mid;
		else left = mid;
	}
	return right;
}

int main() {

	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> T[i];
	}
	ll ans = solve();
	cout << ans << endl;
}


Measured memory_bytes: 3868
import java.util.*;
import java.io.*;

public class Main {
	static int mod = (int) 1e9 + 7;

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int N = fs.nextInt(), Q = fs.nextInt();
		int stop[][] = new int[N][3];
		for(int i=0;i<N;i++) {
			int s = fs.nextInt(), t = fs.nextInt(), x = fs.nextInt();
			stop[i][0] = s;
			stop[i][1] = t; //通行止は[s,t)と解釈して良い。
			stop[i][2] = x;			
		}
		int D[] = new int[Q];
		for(int i=0;i<Q;i++)D[i] = fs.nextInt();
		
		TreeMap<Integer, Integer> tm = new TreeMap<>();
		
		for(int i=0;i<Q;i++) {
			tm.put(D[i], i); //keyに出発時刻、valueには解答番号
		}
		
		//通行止めになる座標が小さいものから処理するために、stopをxで昇順ソート
		Arrays.sort(stop, (s1,s2)->s1[2]-s2[2]);
		
		int ans[] = new int[Q];
		Arrays.fill(ans, -1);
		for(int i=0;i<N;i++) {
			int s = stop[i][0], t= stop[i][1], x=stop[i][2];
			int os = s - x, ot = t - 1 - x;
			while(tm.ceilingKey(os)!=null) {
				int under = tm.ceilingKey(os);
				if (under <= ot) {
					int qnum = tm.get(under);
					ans[qnum]=x;
					tm.remove(under);
				}else {
					break;
				}
			}
		}
		StringBuilder sb = new StringBuilder();
		for(int a:ans) {
			sb.append(a + "\n");
		}
		System.out.println(sb.toString());
	}
}

//高速なScanner
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: 98488
#include <cstdio>

#define maxn 100010
struct Edge
{
	Edge *next;
	int to;
} *last[maxn], e[maxn << 1], *ecnt = e;
inline void link(int a, int b)
{
	*++ecnt = (Edge) {last[a], b}; last[a] = ecnt;
	*++ecnt = (Edge) {last[b], a}; last[b] = ecnt;
}
int fa[maxn], dep[maxn], size[maxn];
void dfs(int x)
{
	dep[x] = dep[fa[x]] + 1;
	size[x] = 1;
	for (Edge *iter = last[x]; iter; iter = iter -> next)
		if (iter -> to != fa[x])
		{
			fa[iter -> to] = x;
			dfs(iter -> to);
			size[x] += size[iter -> to];
		}
}
int main()
{
	int n; scanf("%d", &n);
	for (int i = 1; i < n; ++i)
	{
		int a, b; scanf("%d%d", &a, &b);
		link(a, b);
	}
	dfs(1);
	int lim = (dep[n] - 2) / 2, x = n;
	for (int i = 1; i <= lim; ++i) x = fa[x];
	puts(size[x] >= n - size[x] ? "Snuke" : "Fennec");
	return 0;
}

Measured memory_bytes: 8320