akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> 

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  int N,W;
  cin>>N>>W;
  vector<int>w(N),v(N);
  for(int i=0;i<N;i++)cin>>w[i]>>v[i];
  vector<vector<ll>>dp(N+1,vector<ll>(W+1,0));
  for(int i=0;i<N;i++){
    for(int j=0;j<=W;j++){
      if(j-w[i]>=0)dp[i+1][j]=max(dp[i][j],dp[i][j-w[i]]+v[i]);
      else dp[i+1][j]=dp[i][j];
    }
  }
  ll ans=0;
  for(int i=0;i<=W;i++)ans=max(ans,dp[N][i]);
  cout<<ans<<endl;

  return 0;
}


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

int main(void) {
	int N;
	cin >> N;
	vector<int> B(N - 1);
	int ans = 0;
	for (int i = 0; i < N - 1; i++) {
		cin >> B[i];
	}
	for (int i = 0; i < N - 1; i++) {
		if (i < N - 2) {
			ans += min(B[i], B[i + 1]);
		} else {
			ans += B[i];
		}
	}
	cout << ans + B[0] << "\n";

	return 0;
}


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

typedef long long int   ll;
#define int             ll
#define FIO             ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl            "\n"
#define scan(n)         scanf("%lld",&n)
#define pb              push_back
#define PI              3.1415926535897932384626433832795
#define rep0            for(int i=0;i<n;i++)
#define rep1            for(int i=1;i<=n;i++)
#define inputar0(ar)    for(int i=0;i<n;i++)cin>>ar[i]
#define inputar1(ar)    for(int i=1;i<=n;i++)cin>>ar[i]
#define showar0(ar)     for(int i=0;i<n;i++)cout<<ar[i]<<" "
#define showar1(ar)     for(int i=1;i<=n;i++)cout<<ar[i]<<" "
int mod=1000000007;
int maxn=200001;
int binpow(int a,int b,int mod){int res=1;while(b>0){if(b%2){res=(res*a)%mod;b--;}a=(a*a)%mod;b/=2;}return res%mod;}
int binpow(int a,int b){int res=1;while(b>0){if(b%2){res=(res*a);b--;}a=(a*a);b/=2;}return res;}
bool isPrime(int n){if(n==1)return false;for(int i=2;i*i<=n;i++){if(n%i==0)return false;}return true;}
int mul(int a,int b){return ((a%mod)*(b%mod))%mod;}

signed main(){
    int t=1;
//    scan(t);
    while(t--){
        int l,r,k;cin>>l>>r>>k;
        int quo1=l/k;
         int quo2=r/k;
         int rem=l%k;
         int count;
         if(rem==0)
         {
           count=quo2-quo1+1;
         }
         else
         {
            count=quo2-quo1;
          }
          cout<<count<<endl;

    }
}


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

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	sort(A.begin(), A.end());
	long long sum = 0;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (sum * 2 >= A[i]) {
			ans++;
			sum += A[i];
		}
		else {
			ans = 1;
			sum += A[i];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 768
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,A,B;
	while(cin>>N>>A>>B) {
		VI a(N);
		REP(i, N) cin>>a[i];
		ll ans = 0;
		RANGE(i, 1, N) {
			ll w = (a[i]-a[i-1])*A;
			ans += min(w, B);
		}
		
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 1024
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  const int INF=100000000;
  int n,t,dp[3010][3010],i,j;
  cin >> n >> t;
  vector<P> a(n);
  for(i=0;i<n;i++){
    cin >> a[i].first >> a[i].second;
  }
  for(i=0;i<=n;i++){
    for(j=0;j<=t;j++){
      dp[i][j]=-INF;
    }
  }
  sort(a.begin(),a.end());
  dp[0][0]=0;
  for(i=0;i<n;i++){
    for(j=0;j<=t;j++){
      if(j==t){
        dp[i+1][j]=max(dp[i][j],dp[i+1][j]);
        continue;
      }
      if(j+a[i].first>t){
        dp[i+1][t]=max(dp[i+1][t],dp[i][j]+a[i].second);
      }
      else{
        dp[i+1][j+a[i].first]=max(dp[i+1][j+a[i].first],dp[i][j]+a[i].second);
      }
      dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
    }
  }
  int ans=0;
  for(i=0;i<=t;i++){
    ans=max(ans,dp[n][i]);
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;
using ll = long long;


int main()
{
	int n;
	cin >> n;
	vector<int> a(n); for(int i = 0; i < n; i++)cin >> a[i];
	for(int i = 1; i < n; i++) {
		a[i] = __gcd(a[i], a[i - 1]);
	}
	cout << a[n - 1] << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<stdio.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
typedef pair<int , int > pii;
#define MOD 1000000007
#define MOD1 998244353
#define ff first
#define ss second
#define bn cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define sz(a) int((a).size())
#define o(a) cout << a
#define MAX6 1000006
#define int ll
#define all(x) x.begin(), x.end()
#define ppii pair<int,pii>
#define vi vector<int>
#define vii vector<pii>
#define viii vector<ppii>
#define vs vector<string>
#define pb push_back
#define eb emplace_back
#define endl '\n'
#define MAX5 300005
#define MAX7 10000007
#define rep(i,a,b)  for (__typeof((b)) i=(a);i<=(b);i++)
#define nrep(i,b,a)  for (__typeof((b)) i=(b);i>=(a);i--)
#define mem(a) memset(a,0,sizeof(a))
#define memneg(a) memset(a,-1,sizeof(a))
//#define se second
#define LN 14
#define LIM 22
#define MAX_ALPHA 26
const long long INF64 = 1e18;
const ll INF = 1e9;
const double PI = acos(-1);
#define ld long double
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
inline void max_self(ll &a, ll b)
{
  a = max(a,b);
}
 
inline void min_self(ll &a,ll b)
{
  a = min(a,b);
}
 
inline void add_self(ll &a, ll b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
 
inline void sub_self(ll &a, ll b) {
  a -= b;
  if (a < 0) a += MOD;
}
 
inline int mul(int a, int b) {
  return (int) ((long long) a * b % MOD);
}
 
 
ll gcd(ll a,ll b)
{
  if(b == 0)
    return a;
  else 
    return gcd(b, a%b);
}
 
 
int countDigits(int x)
{
  int cnt = 0;
  while(x)
  {
    x /= 10;
    cnt++;
  }
  return cnt;
}
 
 
ll binExpo(ll a,ll b)
{
  ll res = 1;
  while(b)
  {
    if(b&1)
      res = (res * a)%MOD;
    a = (a * a)%MOD;
    b /= 2;
  }
  return res%MOD;
}
 
int sum(int a) {
    int result = 0;
    while (a > 0) {
        result += a % 10;
        a /= 10;
    }
    return result;
}



signed main()
{
  
  // ios_base::sync_with_stdio(false);
  // cin.tie(0);
  // cout.tie(0);
  int n;
  cin>>n;
  //cout<<"HI\n";
  vector<double > dp(n+1);
  dp[0] = 1;

  rep(coins, 0, n-1)
  {
    double p_heads;
    scanf("%lf", &p_heads);
    for(int i = coins + 1;i >= 0;i--)
    {
      dp[i] = (i == 0 ? 0 : dp[i-1] * p_heads) + dp[i] * (1 - p_heads);
    }
  }
  double ans = 0;
  for(int heads = 0;heads <= n;heads++)
  {
    int tails = n - heads;
    if(heads > tails)
      ans += dp[heads];
  }
  printf("%.10lf\n", ans);
  return 0;
}

Measured memory_bytes: 384
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    int[] a = new int[M];
    for (int i = 0; i < M; i++) a[i] = scanner.nextInt();
    int[] cost = new int[] {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

    int[] dp = new int[N + 1];
    for (int i = 1; i <= N; i++) dp[i] = -1;
    for (int i = 1; i <= N; i++)
      for (int j = 0; j < M; j++)
        if (i >= cost[a[j]]) dp[i] = Math.max(dp[i], dp[i - cost[a[j]]] + 1);

    int k = dp[N];
    List<Integer> list = new ArrayList<>();
    for (int i = 0; i < k; i++) {
      int d = 0;
      for (int j = 0; j < M; j++) {
        if (N >= cost[a[j]] && dp[N] - dp[N - cost[a[j]]] == 1) {
          d = Math.max(d, a[j]);
        }
      }
      list.add(d);
      N -= cost[d];
    }
    Collections.sort(list);
    StringBuilder sb = new StringBuilder();
    for (int i = list.size() - 1; i >= 0; i--) sb.append(list.get(i));
    System.out.println(sb.toString());
  }
}


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

int main() {
    ll n, capacity;
    cin >> n >> capacity;
    vector<ll> w(n+1), v(n+1);
    for(int i = 1; i <= n; i++) cin >> w[i] >> v[i];

    // 重みをグループ分け
    ll w1 = w[1];
    vector<vector<ll>> items(4);
    vector<vector<ll>> vcumsum(4);
    for(int i = 1; i <= n; i++) items[w[i]-w1].push_back(v[i]);
    for(int i = 0; i < 4; i++) sort(items[i].begin(), items[i].end(), greater<ll>());
    for(int i = 0; i < 4; i++) {
        vcumsum[i].push_back(0);
        for(int j = 1; j <= items[i].size(); j++) {
            vcumsum[i].push_back(vcumsum[i][j-1] + items[i][j-1]);
        }
    }
    
    ll ans = -1;
    // どの重みの物をいくつ使うかで4重ループを回す。
    for(int i = 0; i <= items[0].size(); i++) {
        for (int j = 0; j <= items[1].size(); j++) {
            for (int k = 0; k <= items[2].size(); k++) {
                for (int l = 0; l <= items[3].size(); l++) {
                    ll total_w = i * w1 + j * (w1+1) + k * (w1+2) + l * (w1+3);
                    if (total_w > capacity) break;
                    ans = max(vcumsum[0][i] + vcumsum[1][j] + vcumsum[2][k] + vcumsum[3][l], ans);
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
package main

import (
  "fmt"
)

func main() {
  var (
    n,a,b int
  )
  fmt.Scan(&n)
  fmt.Scan(&a)
  fmt.Scan(&b)

  fmt.Println(check(n,a,b))
}

func check(n,a,b int) int {
  if a==0 {
    return 0
  } else {
    x := n/(a+b)
    y := n%(a+b)
    if y>a {
      return x*a + a
    } else {
      return x*a + y
    }
  }
}


Measured memory_bytes: 512
n=int(input())
a=list(map(int,input().split()))+[0]
c=a[0]
t=0
s=0
for i in range(n+1):
  if(c!=a[i]):
    c=a[i]
    s+=t//2
    t=1
  else:
    t+=1
print(s)


Measured memory_bytes: 3060
import collections

N = int(input())
A = list(map(int, input().split()))

# 数値Aの頻度
ndic = collections.Counter(A)

mem = {}
tcmb = 0
for j in ndic:
    if ndic[j] == 1:
        continue
    
    if ndic[j] in mem:
        tcmb += mem[ndic[j]]
    else:
        mem[ndic[j]] = int((ndic[j] * (ndic[j] -1)) / 2)
        tcmb += mem[ndic[j]]
        
for i in A:
    cmb  = tcmb - (ndic[i] - 1)
    print(cmb)

Measured memory_bytes: 87884
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x,n;
  cin >> x >> n;
  vector <int> p(n);
  for(int i=0;i<n;i++){
    cin >> p.at(i);
  }
  
  int ab=0;
  while(1){
    bool found=false;
    for(int i=0;i<n;i++){
      if((ab+x)==p.at(i)){
        found = true;
        break;
      }
    }
    if(found==false){
      cout << ab+x << endl;
      break;
    }else if(ab>=0){
      ab++;
      ab*=-1;
    }else{
      ab*=-1;
    }
  }
  return 0;
}

Measured memory_bytes: 3620
/*
class Comb{
    
private:
    std::vector<long long> fac(100100), inv(100100), finv(100100); //階乗 / 逆元 / inv * fac
    
public:

    Comb()
    {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for(int i = 2;i < 1000100; 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;
        }
    }
     
    long long comb(int n,int r){
        if(n < r) return 0;
        if(n < 0 || r < 0)return 0;
        return fac[n] * (finv[r] * finv[n - r] % mod) % mod;
    }
    
    long long f(int n){
        return fac[n]
    }
    
};
 

*/

#include<bits/stdc++.h>
int main()
{
    int h,w,a,b;
    std::cin >> h >> w >> a >> b;
    std::cout << (h - a) * (w - b) << std::endl;
}

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

int main(int argc, char const *argv[]) {
  vector<vector<int>> C(3);

  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      int temp = 0;
      cin >> temp;
      C[i].push_back(temp);
    }
  }
  int a[3];
  a[0] = 0;
  int b[3];
  bool flag = true;
  for (int i = 0; i < 3; i++) {
    b[i] = C[0][i];
  }
  for (int j = 0; j < 3; j++) {
    a[j] = C[j][0] - b[0];
  }

  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (a[i] + b[j] != C[i][j]) {
        flag = false;
      }
    }
  }

  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 384
# coding: utf-8
import math

N, M = [int(s) for s in input().strip().split()]

if N == 1:
    print(M)
    exit()

ROOT_M = int(math.sqrt(M))
divisors = []
for d in range(1, ROOT_M+1):
    if M % d == 0:
        divisors.append(d)
        divisors.append(M//d)

divisors.sort()
MAX_VAL = int(M/N)
for d in divisors:
    if d > MAX_VAL:
        break
    max_gcd = d

print(max_gcd)


Measured memory_bytes: 3060
'use strict'

function Main(input) {
  const P = Number(input.split("\n")[0].split(" ")[0])
  const Q = Number(input.split("\n")[0].split(" ")[1])
  const R = Number(input.split("\n")[0].split(" ")[2])

  const max = Math.max(P, Q, R)
  console.log(P + Q + R - max)
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim())


Measured memory_bytes: 21952
import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int size = sc.nextInt();
    String s = sc.next();
    int ans = (size - s.replaceAll("ABC", "").length()) / 3;
    System.out.println(ans);
  }
}


Measured memory_bytes: 23124
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a%b);
}

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

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////



int main() {
	ll N, D;
	cin >> N >> D;

	cout << (N - 1) / (2 * D + 1) + 1;

	system("PAUSE");
}

Measured memory_bytes: 504
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>

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

const int INF = 9999999;

vector <string> map;
int Sx,Sy;

int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int H,W,N;
int bfs(int target,vector<vector<int> > d){
  queue<P> que;
  que.push(P(Sx,Sy));
  d[Sy][Sx]=0;
  P p;
  while(que.size()){
	p = que.front(); que.pop();
	if((int)(map[p.second][p.first]-'0') == target)break;
	for(int i=0;i<4;++i){
  	int nx = p.first+dx[i];
  	int ny = p.second+dy[i];
  	if(0<=nx&&0<=ny && nx<W&&ny<H && map[ny][nx]!='X' && d[ny][nx] == INF ){
      que.push(P(nx,ny));
      d[ny][nx]=d[p.second][p.first]+1;
  	}
	}
  }
  Sx=p.first; Sy=p.second;
  return d[p.second][p.first];
}

int main(){
  int ans = 0;
  cin >> H >> W >> N;
  for(int i=0;i<H;++i){
	string temp;
	cin >> temp;
	for(int j=0;j<W;++j)
  	if(temp[j]=='S'){
      Sx=j;
      Sy=i;
  	 }
	   map.push_back(temp);
  }
  vector<vector<int> > d;
  vector<int> x;x.resize(W,INF);
  for(int i=0;i<H;++i)d.push_back(x);
  for(int i=1;i<=N;++i)ans+=bfs(i,d);
  cout << ans << endl;
}


Measured memory_bytes: 11824
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
#define irep(i, begin_i, end_i)for (ll i = (ll)begin_i; i > (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    int n; cin>>n;
    vi a(n+1,0);
    rep(i,1,n+1){
        cin>>a[i];
    }
    vi kubaru(n+1,0);
    vi ans;
    for(int i=n;i>0;i--){
        int numbox=n/i;
        bool cnt=false;
        rep(j,1,numbox+1){
           if(kubaru[i*j])cnt^=kubaru[i*j];
        }
        if(cnt!=a[i]){
            kubaru[i]^=true;
            ans.push_back(i);
        }
    }
    cout<<ans.size()<<endl;
    rep(i,0,ans.size())cout<<ans[i]<<" ";
    return 0;
}




Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
template <typename T,typename U>pair<T,U> operator+(const pair<T,U> & l,const std::pair<T,U> & r) { return {l.first+r.first,l.second+r.second};}
typedef long long int ll;
const ll mod =1e9+7;
#define endl '\n'

int32_t main()
{

  IOS
  int k;
  string s;
  cin>>k>>s;
  if(s.size()<=k){
    cout<<s<<endl;
  }
  else{
    cout<<s.substr(0,k)<<"...";
  }
}


Measured memory_bytes: 3664
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	int a, b;
	cin >> a >> b;
	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
		cout << "Possible" << endl;
	else
		cout << "Impossible" << endl;

} 

Measured memory_bytes: 3576
#include <iostream>
#include <vector>
#include <string>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <climits>
#include <iomanip>
#include <deque>
#include <limits>

using namespace std;

const int CONSUMPTION_TAX = 0.1;

int main()
{
  int64_t N;

  cin >> N;

  int64_t sum = 0;
  for (int i = 1; i <= N; i++) {
    if (i % 3 != 0 && i % 5 != 0) {
      sum += i;
    }
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <utility>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <map>
#include <unordered_map>
#include <limits>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;

int main()
{
    ll X, Y;
    scanf("%lld %lld", &X, &Y);

    if (Y % 2 == 0 && Y <= 4 * X && Y >= 2 * X)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
}


Measured memory_bytes: 3748
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
int a[3000],b[3000],c[3000][3001],n,m,l;
int fn(int p,int q){  
  if(p==n)
    return 0;
  if(c[p][q]>=0)
    return c[p][q];
  int mx=0;
  mx=max(mx,fn(p+1,q));
  mx=max(mx,((l<=q||q+b[p]<=l)&&q+b[p]<=m?a[p]+fn(p+1,q+b[p]):0));
  mx=max(mx,(q<l&&l+b[p]<=m?a[p]+fn(p+1,l+b[p]):0));
  return c[p][q]=mx;
}
int main(){
  int i;
  scanf("%d%d%d",&n,&m,&l);
  for(i=0;i<n;++i)
    scanf("%d%d",a+i,b+i);
  memset(c,-1,sizeof(c));
  printf("%d\n",fn(0,0));
  return 0;
}

Measured memory_bytes: 35000
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;

int main()
{
    fastio;
    long long n,i,sum=0,mx=0;
    static long long ara[200003];
    cin>>n;
    for(i=0;i<n;i++)
        cin>>ara[i];
    for(i=0;i<n;i++)
    {
        if(ara[i]>=mx)
            mx=ara[i];
        else
            sum=sum+mx-ara[i];
    }
    cout<<sum<<"\n";
    return 0;
}


Measured memory_bytes: 5132
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;



int main(void){
  int n, a, b;
  cin >> n >> a >> b;
  string s;
  cin >> s;
  int ca = 0, cb = 0;
  REP(i, 0, n) {
    bool pass;
    switch(s[i]) {
    case 'a':
      if (ca + cb < a + b) {
	ca++;
	pass = true;
      } else {
	pass = false;
      }
      break;
    case 'b':
      if (ca + cb < a + b && cb < b) {
	cb++;
	pass = true;
      } else {
	pass = false;
      }
      break;
    default:
      pass = false;
      break;
    }
    cout << (pass ? "Yes" : "No") << endl;
  }
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define clr(x) memset(x,0,sizeof x)
#define For(i,a,b) for (int i=(a);i<=(b);i++)
#define Fod(i,b,a) for (int i=(b);i>=(a);i--)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define outval(x) cerr<<#x" = "<<x<<endl
#define outtag(x) cerr<<"-----------------"#x"-----------------\n"
#define outarr(a,L,R) cerr<<#a"["<<L<<".."<<R<<"] = ";\
                    For(_x,L,R) cerr<<a[_x]<<" ";cerr<<endl;
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair <int,int> pii;
LL read(){
    LL x=0,f=0;
    char ch=getchar();
    while (!isdigit(ch))
        f=ch=='-',ch=getchar();
    while (isdigit(ch))
        x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
    return f?-x:x;
}
const int N=155;
int n,K,mod;
void Add(int &x,int y){
	if ((x+=y)>=mod)
		x-=mod;
}
int dp[N][N][N];
pair <int,int> p[N];
namespace so1{
	int dp[N];
	void Solve(){
		dp[0]=1;
		For(i,1,n+1){
			For(j,max(i-K/2-1,0),i-1)
				Add(dp[i],dp[j]);
		}
		cout<<(LL)dp[n/2+1]*dp[(n+1)/2+1]%mod<<endl;
	}
}
int main(){
	n=read(),K=read(),mod=read();
	if (K%2==0)
		return so1::Solve(),0;
	For(i,1,n/2)
		p[i].se=i*2;
	For(i,1,(n+1)/2)
		p[i+(K-1)/2].fi=i*2-1;
	int m=(n+1)/2+(K-1)/2;
	dp[0][0][0]=1;
	For(i,1,m)
		For(j,0,n)
			For(k,0,n){
				int v=dp[i-1][j][k];
				if (!v||j>=K+2)
					continue;
				Add(dp[i][0][0],v);
				if (p[i].fi){
					if (j>0)
						Add(dp[i][j+1][0],v);
					else
						Add(dp[i][0][0],v);
				}
				if (p[i].se)
					Add(dp[i][0][k+1],v);
				if (p[i].fi&&p[i].se)
					Add(dp[i][max(j+1,k+2)][k+1],v);
			}
	int ans=0;
	For(i,0,n)
		For(j,0,n)
			if (i<K+2)
				Add(ans,dp[m][i][j]);
	cout<<ans<<endl; 
	return 0;
}

Measured memory_bytes: 12672
#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair <int, int> pii;

inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}

const int MAXN = 100005;

struct Edge
{
	int u, v, w;
	bool operator < (const Edge &b) const
	{
		return w < b.w;
	}
} e[MAXN];

int n, m, c, f[MAXN], g[MAXN], col[MAXN];
LL ret;

inline int FindF(int x)
{
	while (x ^ f[x])
		x = f[x] = f[f[x]];
	return x;
}

inline int FindG(int x)
{
	while (x ^ g[x])
		x = g[x] = g[g[x]];
	return x;
}

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = Read(), m = Read(), c = Read() - 1;
	for (int i = 1; i <= n; i ++)
		col[i] = Read(), f[i] = i;
	for (int i = 1; i <= c + 1; i ++)
		g[i] = i;
	for (int i = 1; i <= m; i ++)
		e[i].u = Read(), e[i].v = Read(), e[i].w = Read();
	sort(e + 1, e + m + 1);
	for (int i = 1; i <= m; i ++)
	{
		if (!c)
			break;
		int u = FindF(e[i].u), v = FindF(e[i].v), cu = col[u], cv = col[v];
		if (u == v)
			continue;
		f[u] = v, col[v] = cv ? cv : cu;
		if (cu && cv)
		{
			cu = FindG(cu), cv = FindG(cv);
			if (cu == cv)
				continue;
			g[cu] = cv, c --, ret += e[i].w;
		}
		else
			c --, ret += e[i].w;
	}
	if (c)
		ret = -1;
	return printf("%lld\n", ret), 0;
}


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

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    vector<lli> a(n * 3);
    cin >> a;

    const lli inf = 1LL << 60;
    vector<lli> v(n * 3, -inf);
    vector<lli> u(n * 3, inf);

    {
      priority_queue<lli, vector<lli>, greater<lli>> q;
      lli sum = 0;
      for (int i = 0; i < a.size(); ++i) {
        sum += a[i];
        q.push(a[i]);
        if (n < q.size()) {
          sum -= q.top();
          q.pop();
        }
        if (q.size() == n) {
          v[i] =  sum;
        }
      }
    }

    {
      priority_queue<lli, vector<lli>, less<lli>> q;
      lli sum = 0;
      for (int i = a.size() -1; 0 <= i; --i) {
        sum += a[i];
        q.push(a[i]);
        if (n < q.size()) {
          sum -= q.top();
          q.pop();
        }
        if (q.size() == n) {
          u[i] =  sum;
        }
      }
    }

    // cout << v << endl;
    // cout << u << endl;

    lli mx = -inf;
    for (int i = n - 1; i < 2 * n; ++i) {
      setmax(mx, v[i] - u[i + 1]);
    }
    cout << mx << endl;
  }

  return 0;
}


Measured memory_bytes: 9072
n, s = map(int, input().split())
x = list(map(int, input().split()))

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a%b)

diff = []

for i in x:
    diff.append(abs(i-s))

ans = diff[0]
for i in diff:
    ans = (gcd(ans, i))

print(ans)

Measured memory_bytes: 19952
#include <bits/stdc++.h>
using namespace std;
#define pii             pair <int, int>
#define ff              first
#define ss              second
#define eps             1e-10
#define LL              long long
#define pb              push_back
#define mk              make_pair
#define inf             0x3f3f3f3f
#define vi              vector <int>
#define all(a)          a.begin(), a.end()
#define Unique(a)       sort(all(a)), a.erase(unique(all(a)), a.end())
#define Iterator(a)     __typeof__(a.begin())
#define rIterator(a)    __typeof__(a.rbegin())
#define FOR(a,it)       for(Iterator(a) it = a.begin();it != a.end(); it++)
#define rFOR(a,it)      for(rIterator(a) it = a.rbegin();it != a.rend(); it++)
#define MAX             256
#define ULL             unsigned long long

const int N = 2000006;
const int MOD = 1e9 + 7;

int cost[11][11], dp[11];
int org[222][222], row, col;

int ans_me() {
    memset(dp, inf, sizeof dp);
    queue <int> Q;
    Q.push(1);
    dp[1] = 0;
    while(!Q.empty()) {
        int top = Q.front(); Q.pop();
        for(int i = 0; i < 10; i++) {
            if(i == top) continue;
            if(dp[i] > dp[top] + cost[i][top]) {
                dp[i] = dp[top] + cost[i][top];
                Q.push(i);
            }
        }
    }
}

int main()
{
    scanf("%d %d", &row, &col);
    for(int i = 0; i < 10; i++) for(int j = 0; j < 10; j++) scanf("%d", &cost[i][j]);
    for(int i = 0; i < row; i++) for(int j = 0; j < col; j++) scanf("%d", &org[i][j]);
    ans_me();
    LL res = 0;
    for(int i = 0; i < row; i++) for(int j = 0; j < col; j++) if(org[i][j] != -1) res += dp[org[i][j]];
    printf("%lld\n", res);
    return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<string.h>
#include<math.h>
#include <stdlib.h>
#include<ctype.h>
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}
int main() {

	int A,B,C,D;
	scanf("%d %d %d %d",&A,&B,&C,&D);
	
	for(int i=0;i<10000;i++){
		C = C-B;
		if(C<=0){
			printf("Yes");
			return 0;
		}
		A = A-D;
		if(A<=0){
			printf("No");
			return 0;
		}
	}
	
}

Measured memory_bytes: 1728
s = input()
for i in range(len(s)):
    str = s[:-(i+1)]
    str_half_length = int(len(str) / 2)
    str_1 = str[str_half_length:]
    str_2 = str[:str_half_length]
    if str_1 == str_2:
        print(str_half_length * 2)
        exit()


Measured memory_bytes: 2940
def main():
    import sys
    from collections import Counter
    input = sys.stdin.readline
    N = int(input())
    A = Counter([int(x) for x in input().strip().split()])
    Q = int(input())
    ans = sum([k * v for k, v in A.items()])
    for q in range(Q):
        b, c = [int(x) for x in input().strip().split()]
        ans = ans + c * A[b] - b * A[b] 
        A[c] += A[b]
        A[b] = 0
        print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 23224
import itertools
h,w,k = map(int,input().split())
C = [list(input()) for i in range(h)]

ans = 0
for tate in itertools.product([0,1], repeat=h):
    for yoko in itertools.product([0,1], repeat=w):
        cnt = 0
        for i in range(h):
            for j in range(w):
                if tate[i] or yoko[j]:continue
                cnt += C[i][j] == "#"
        if cnt == k:
            ans += 1
print(ans)


Measured memory_bytes: 9192
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	string S;
	cin >> S;
	if (S[2]==S[3] && S[4]==S[5])
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";

	}

	return 0;
}

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

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

    int N, Q;
    cin >> N >> Q;

    string s;
    cin >> s;

    vs32 ac(N, 0);
    for (int i = 1; i < N; ++i)
    {
        if (s[i - 1] == 'A' && s[i] == 'C')
        {
            ac[i] = ac[i - 1] + 1;
        }
        else
        {
            ac[i] = ac[i - 1];
        }
    }

    int l, r;
    int ans;
    rep (i, Q)
    {
        cin >> l >> r;
        ans = ac[r - 1] - ac[l - 1];
        cout << ans << "\n";
    }

    return 0;
}



Measured memory_bytes: 1488
#include <cstdio>
#include <vector>
#include <queue>

using namespace std;

int field[10][10];
int costs[7][7][10][10]; // floor, north, x, y

struct Task {
	int floor, north, west, x, y;
};
struct TaskComparator {
	bool operator()(const Task &a, const Task &b){
		return costs[a.floor][a.north][a.x][a.y] > costs[b.floor][b.north][b.x][b.y];
	}
};

int main(){
	while(true){
		for(int i = 0; i < 7; ++i){
			for(int j = 0; j < 7; ++j){
				for(int k = 0; k < 10; ++k){
					for(int l = 0; l < 10; ++l){
						costs[i][j][k][l] = 0x7fffffff;
					}
				}
			}
		}
		int h, w;
		scanf("%d%d", &h, &w);
		if(h == 0 && w == 0){ break; }
		for(int i = 0; i < h; ++i){
			for(int j = 0; j < w; ++j){
				scanf("%d", &(field[j][i]));
			}
		}
		int sx, sy, gx, gy;
		scanf("%d%d%d%d", &sy, &sx, &gy, &gx);
		priority_queue<Task, vector<Task>, TaskComparator> q;
		Task task = { 6, 5, 4, sx, sy };
		costs[6][5][sx][sy] = 0;
		q.push(task);
		while(!q.empty()){
			task = q.top(); q.pop();
			if(task.x == gx && task.y == gy){ break; }
			int cost = costs[task.floor][task.north][task.x][task.y];
			if(task.x > 0){	// ツ青シツ陛サツ古シ
				int tmp = cost + task.west * field[task.x - 1][task.y];
				if(tmp < costs[task.west][task.north][task.x - 1][task.y]){
					costs[task.west][task.north][task.x - 1][task.y] = tmp;
					Task t = { task.west, task.north, 7 - task.floor, task.x - 1, task.y };
					q.push(t);
				}
			}
			if(task.x < w - 1){	// ツ督個陛サツ古シ
				int tmp = cost + (7 - task.west) * field[task.x + 1][task.y];
				if(tmp < costs[7 - task.west][task.north][task.x + 1][task.y]){
					costs[7 - task.west][task.north][task.x + 1][task.y] = tmp;
					Task t = { 7 - task.west, task.north, task.floor, task.x + 1, task.y };
					q.push(t);
				}
			}
			if(task.y > 0){	// ツ北ツ陛サツ古シ
				int tmp = cost + task.north * field[task.x][task.y - 1];
				if(tmp < costs[task.north][7 - task.floor][task.x][task.y - 1]){
					costs[task.north][7 - task.floor][task.x][task.y - 1] = tmp;
					Task t = { task.north, 7 - task.floor, task.west, task.x, task.y - 1 };
					q.push(t);
				}
			}
			if(task.y < h - 1){	// ツ禿ャツ陛サツ古シ
				int tmp = cost + (7 - task.north) * field[task.x][task.y + 1];
				if(tmp < costs[7 - task.north][task.floor][task.x][task.y + 1]){
					costs[7 - task.north][task.floor][task.x][task.y + 1] = tmp;
					Task t = { 7 - task.north, task.floor, task.west, task.x, task.y + 1 };
					q.push(t);
				}
			}
		}
		printf("%d\n", costs[task.floor][task.north][task.x][task.y]);
	}
	return 0;
}

Measured memory_bytes: 0
// C - Repsept
#include <bits/stdc++.h>
using namespace std;

int f(int k){
	int r=7%k, i=1;
	set<int> s;
	while(!s.count(r)){
		if(!r) return i;
		i++;
		s.insert(r);
		r = (r*10 + 7) % k;
	}
	return -1;
}

int main(){
	int k; cin>>k;
	cout<< f(k) <<endl;
}


Measured memory_bytes: 50440
#include <algorithm>
#include <bitset>
#include <cctype>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

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

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define S first
#define E second

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int main(void){
    for(int n, res; cin >> n, n; cout << res << endl){
        vi dates(n);
        vi sat(n);

        rep(i, n){
            int m, l; cin >> m >> l;
            sat[i] = l;

            rep(j, m){
                int s, e; cin >> s >> e;
                s -= 6, e -= 6;

                range(k, s, e){
                    dates[i] |= (1 << k);
                }
            }
        }

        vvi dp(2, vi(1 << 16, -1));
        dp[0][0] = 0;

        rep(i, n){
            dp[1] = dp[0];

            rep(j, 1 << 16){
                if(dp[0][j] == -1) continue;

                if((j & dates[i]) != 0){
                    continue;
                }
                int next = j | dates[i];

                dp[1][next] = max(dp[1][next],
                                  dp[0][j] + sat[i]);
            }
            dp[0] = dp[1];
        }

        res = *max_element(all(dp[1]));
    }

	return 0;
}

Measured memory_bytes: 1940
from heapq import heappop, heappush

n,m = map(int, input().split())
s = input()

heap = [(0,n)]
turn = [-1]*(n+1)
turn[-1] = 0
for i in range(n-1, -1, -1):
    if s[i] == "1":
        continue
    while heap and heap[0][1]-i>m:
        heappop(heap)
    if not heap:
        break
    cnt, prev = heap[0]
    turn[i] = cnt+1
    heappush(heap, (turn[i], i))

if turn[0] == -1:
    print(-1)
    exit()
prev_turn=turn[0]
prev_ind = 0
ans = []
for i in range(1, n+1):
    if prev_turn-turn[i] == 1:
        ans.append(i-prev_ind)
        prev_ind = i
        prev_turn = turn[i]
print(*ans)

Measured memory_bytes: 54748
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include<queue>

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
int gcd(int a, int b){return b ? gcd(b, a%b) : a;}


int main(){
    int n; cin >> n;
    for(int i = 1; i <= 50000; i++){
        if(int(i*1.08) == n){
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct point{
	int v;
	point *l,*r,*pa;
	point(){l=r=pa=NULL;}
	point(int vv):v(vv){l=r=pa=NULL;}
};
point root;
void insert(int v){
	point *p=&root;
	while(1){
		if(v>=p->v){
			if(!(p->r)){
				p->r=new point(v);
				p->r->pa=p;
				break;
			}else p=p->r;
		}
		else{
			if(!(p->l)){
				p->l=new point(v);
				p->l->pa=p;
				break;
			}else p=p->l;
		} 
	}
}
void dfs1(point *p){
	if(!p)return;
	dfs1(p->l);
	printf(" %d",p->v);
	dfs1(p->r);
}
void dfs2(point *p){
	if(!p)return;
	printf(" %d",p->v);
	dfs2(p->l);
	dfs2(p->r);
}
void print(){
	dfs1(&root);printf("\n");
	dfs2(&root);printf("\n");
}
int main(){
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int T;cin>>T;
	string s;int vv;
	bool first=0;
	while(T--){
		cin>>s;
		if(s=="insert")cin>>vv,first?(insert(vv),0):(root.v=vv,first=!first);
		else print();
	}
	return 0;
}


Measured memory_bytes: 26736
S = int(input())
s1 = S//100
s2 = S%100

if s1 > 0 and s1 <=12:
  flag1 = True
else:
  flag1 = False
if s2 > 0 and s2 <=12:
  flag2 = True
else:
  flag2 = False
  
if flag1 and flag2:
  print("AMBIGUOUS")
if not flag1 and flag2:
  print("YYMM")
if flag1 and not flag2:
  print("MMYY")
if not flag1 and not flag2:
  print("NA")

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

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
        #define eprintf(...) 42
#endif

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define all(x) (x).begin(),(x).end()
#define foreach(u,v) for(auto (u) : (v))
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pll;
typedef vector<ll> vl;

const int inf = 1e9;
const ll linf = 1LL<<60;
const ll mod = 1e9 + 7;
const double eps = 1e-9;

/*
*/

int main()
{ 
  int a, b, k;
  cin >> a >> b >> k;

  int cnt = 0;
  for(int i = min(a, b); i > 0; i--){
    if(a%i == 0 and b%i == 0) cnt++;
    if(cnt == k){
      cout << i << endl;
      break;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
#define ll long long
#define pi (acos(-1))
// https://atcoder.jp/contests/abc172/tasks/abc172_d
int main()
{   
    int s;
    std::cin >> s;
    int a, b;
    a = s / 100;
    b = s % 100;
   
    if (1 <= a && a <= 12)
    {
        if (1 <= b && b <= 12) { std::cout << "AMBIGUOUS" << std::endl; }
        else
        {   
            std::cout << "MMYY" << std::endl;
        }
    }
    else    
    {
        if (1 <= b && b <= 12) { std::cout << "YYMM" << std::endl; }
        else
        {
            std::cout << "NA" << std::endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3524
#include <bits/stdc++.h>
#include<iostream>
#include <ctype.h>
#include <sstream>
using namespace std;
using Graph = vector<vector<int>>;
#define  itn int
using ll=int64_t;
#define rep(i,n) for (int i = 0; i < (int) (n); i++)
using vi = vector<int>;
using vll = vector<ll>;
//GCD
long long gcd(long long a, long long b)
{if(a<b) swap(a,b);
   if (a%b == 0){return(b);}
   else{return(gcd(b, a%b));}
}
//lcm
long long lcm(long long a, long long b)
{return a * b / gcd(a, b);}

long long bikkuri(long long k){
    long long sum = 1;
    for (long long i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}
int main() {
int n,m;
cin>>n>>m;
vi a(n);
for (int i = 0; i < n; i++) {
  cin>>a.at(i);
}
sort(a.begin(),a.end());
int k=0;
for (int i = 0; i < m; i++) {
  k+=a.at(i);
}
cout<<k;
}


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

#define X real()
#define Y imag()

using Vector2 = complex<double>;
const double EPS = 1e-8;
const double PI = 3.14159265359;

// Vector2
double dot(Vector2 a, Vector2 b){
    return (a.X * b.X + a.Y * b.Y);
}

double cross(Vector2 a, Vector2 b){
    return (a.X * b.Y - a.Y * b.X);
}

int ccw(Vector2 p1, Vector2 p2, Vector2 p3){
    Vector2 a = p2 - p1;
    Vector2 b = p3 - p1;
    double dotValue = dot(a, b);
    double crossValue = cross(a, b);
    if(crossValue > EPS) return 1;  // anticlockwise
    if(crossValue < -EPS) return -1;    // clockwise
    if(dotValue < -EPS) return 2;   // p2-p1-p3
    if(norm(a) < norm(b)) return -2;    // p1-p2-p3
    return 0;   // p1-p3-p2
}

int main(){

    int x0, y0, x1, y1;
    cin >> x0 >> y0 >> x1 >> y1;
    Vector2 p0(x0, y0);
    Vector2 p1(x1, y1);

    int q;
    cin >> q;
    for(int i = 0; i < q; i++){
        int x, y;
        cin >> x >> y;
        Vector2 p(x, y);
        int temp = ccw(p0, p1, p);
        if(temp == 1){
            cout << "COUNTER_CLOCKWISE" << endl;
        }
        else if(temp == -1){
            cout << "CLOCKWISE" << endl;
        }
        else if(temp == 2){
            cout << "ONLINE_BACK" << endl;
        }
        else if(temp == -2){
            cout << "ONLINE_FRONT" << endl;
        }
        else{
            cout << "ON_SEGMENT" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 3148
if __name__ == "__main__":
    K,A,B = map(int,input().split())
    
    if B - A <= 2:
        print(K + 1)
    else :
        #所持金がAになるのにA-1回の操作が必要
        if K <= A-1:
            print(1 + K)
        else:
            #残り回数
            rest = K - (A - 1)
            if rest < 2:
                print(1 + K)
            else:
                q,r = divmod(rest,2)
                print(A + q * (B - A) + r)

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

using namespace std;

int N;
long long K;
long long MOD = 1000000007;
vector<int> graph[100005];
int sz[100005];
long long ans = 1;

void dfs(int n, int p){
    sz[n]++;
    if(!p){
        ans = K;
    }
    else{
        ans *= K-sz[p];
        sz[p]++;
        ans %= MOD;
    }
    for(int e : graph[n]){
        if(e == p){
            continue;
        }
        sz[e]++;
        dfs(e, n);
    }
}

int main(){
    cin >> N >> K;
    for(int i = 1; i<N; i++){
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    dfs(1, 0);
    cout << ans << endl;
}


Measured memory_bytes: 9600