akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int K = sc.nextInt();
    int A = sc.nextInt();
    int B = sc.nextInt();
    int ans = 0;
    for (int i = A; i <= B; i++){
      if (i%K == 0) ans++;
    }
    System.out.println(ans > 0 ? "OK" : "NG");
  }
}

Measured memory_bytes: 35616
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;

int main() {
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;

  int ans = INT_MAX;

  for (const int i : boost::irange(0, max(X, Y) + 1)) {
    int price = 2 * C * i + A * max(0, X - i) + B * max(0, Y - i);
    ans = min(ans, price);
  }

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


Measured memory_bytes: 256
n = int(input())
l = list(map(int, input().split()))
 
ans = 0

def func(l, pn):
  ans = 0
  sum_ = 0
  for i in range(n):
    sum_ += l[i]
    if sum_ >= 0 and pn[i] < 0:
      ans += sum_+1
      sum_ = -1
    elif sum_ <= 0 and pn[i] > 0:
      ans += -sum_+1
      sum_ = 1
    else:
      continue
  return ans

pn1 = [1 if i%2 == 0 else -1 for i in range(n)]
pn2 = [-1 if i%2 == 0 else 1 for i in range(n)]

print(min(func(l, pn1), func(l, pn2)))

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

int main(){
    int n;
    cin >> n;
    int ind = -1, ans = 1<<30;
    for(int i = 0; i < n; i++){
        int x;  cin >> x;
        if(x < ans){
            ind = i;
            ans = x;
        }
    }
    cout << ind+1 << endl;
    return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    int ans = 0;
    priority_queue<int> que;
    vector<int> v[100010];
    rep(i, N) {
        int A, B;
        cin >> A >> B;
        v[A].push_back(B);
    }
    rep(i, M) {
        for(auto& e: v[i + 1]) {
            que.push(e);
        }
        if(que.size()) {
            ans += que.top(); que.pop();
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9032
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt(), b = scan.nextInt(), c = scan.nextInt();

        int[] num = {a, b, c};
        Arrays.sort(num);
        System.out.println(num[0] + " " + num[1] + " " + num[2]);
    }
}

Measured memory_bytes: 26092
import copy
import sys
from _operator import itemgetter
from collections import Counter
from math import log2, pi, ceil

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

flag = True
s = input()
for i in range(3):
    if s[i] == s[i+1]:
        flag = False
        break
print("Good" if flag else "Bad")

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

int main(){
  int A[2000001], B[2000001], C[10001], n;
  for(int i = 0; i <= 10000; i++) C[i] = 0;
  cin >> n;
  for(int i = 1; i <= n; i++){
    cin >> A[i];
    C[A[i]]++;
  }
  for(int i = 1; i <= 10000; i++) C[i] += C[i-1];
  for(int i = n; i > 0; i--){
    B[C[A[i]]] = A[i];
    C[A[i]]--;
  }
  for(int i = 1; i <= n; i++) cout << B[i] << (i == n ? '\n' : ' ');
  return 0;
}


Measured memory_bytes: 18764
#include <bits/stdc++.h>
#include <unistd.h>
#include <random>

using namespace std;
typedef long long int LL;
typedef long long int LLint;
typedef pair<int,int> intpair;
typedef pair<bool,bool> boolpair;
typedef pair<string,string> strpair;
typedef pair<LL,LL> LLpair;
typedef pair<double,double> doublepair;
typedef pair<float,float> floatpair;
typedef vector<int> intvector;
typedef vector<bool> boolvector;
typedef vector<string> strvector;
typedef vector<LL> LLvector;
typedef vector<double> doublevector;
typedef vector<float> floatvector;
#define wait(sec) usleep((sec) * 1000000)
#define ED return 0;
#define TEST cout << "OK" << endl;
#define UP(a,b) ((a+(b-1))/b)
#define SORT(vec) sort(vec.begin(),vec.end());
#define DOUBLECHANGE(count) cout << setprecision(count);
#define REV(vec) reverse(vec.begin(),vec.end());
#define ipow(x,y) LL(pow(x,y))
#define INF 999999999
const long long mod = 1000000007;

int main(){
//    random_device rnd;
//    mt19937 mt(rnd());
      cin.tie(0);
      ios::sync_with_stdio(false);
      intvector antena (5);
      for(int i = 0;i < 5;i++){
          cin >> antena[i];
      }
      int k;
      cin >> k;
      SORT(antena);
      if(antena[4]-antena[0] > k){
          cout << ":(" << endl;
          return 0;
      }
      cout << "Yay!" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
const int INF = 1e9;


int N;
int memo[110000];

// nの値段を引き出すのに必要な最小回数
int rec(int n){
    if(n == 0) return 0;
    if(~memo[n]) return memo[n];

    int ret = n;
    for(int i = 1; i <= n; i *= 6){
        ret = min(ret, rec(n-i) + 1);
    }

    for(int i = 1; i <= n; i *= 9){
        ret = min(ret, rec(n-i) + 1);
    }
    return memo[n] = ret;
}



int main(){
    cin >> N;
    REP(i,110000) memo[i] = -1;

    cout << rec(N) << endl;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#include <map>
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using Graph = vector<vector<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;
}
ll modinv(ll a, ll m){
    ll b = m, u = 1, v = 0;
    while(b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if(u < 0) u += m;
    //cout << u << endl;
    return u;
}

ll paty_counter(ll level, ll x){
    ll size = pow(2, level+2) - 3;
    ll pmi = pow(2, level) - 1;
    if(x == 0){
        return 0;
    }else if(level == 0){    
        return 1;
    }else{
        if(x <= (size - 1)/2){
            return paty_counter(level-1, x-1);
        }else{
            return pmi + 1 + paty_counter(level-1, x - pow(2, level+1) + 3 - 2);
        }
    }

}
 
using namespace std;
using Graph = vector<vector<int>>;

// 深さ優先探索
vector<bool> seen;
static ll x;
void dfs(const Graph &G, int v) {
    seen[v] = true;
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue;
        dfs(G, next_v); // 再帰的に探索
        x ++;
    }
}

ll fr(ll n){
    ll ans = 1;
    REP(i, n){
        ans *= i+1;
        ans %= MOD;
    }
    return ans;
}

ll conb(ll n, ll k){
    return fr(n)% MOD * modinv(fr(k) * fr(n-k) % MOD, MOD) % MOD;
}


int main() {
    ll n;
    string S;
    cin >> n >> S;
    deque<ll> r, w;
    
    REP(i,n){
        if(S[i] == 'R'){
            r.push_back(i);
        } else {
            w.push_back(i);
        }
    }
    r.push_front(-1);
    w.push_back(n+1);
    ll itr = 0;
    while(true){
        if(r.back() < w.front()){
            break;
        }
        ll R = r.back();
        r.pop_back();
        ll W = w.front();
        w.pop_front();
        r.insert(lower_bound(r.begin(),r.end(),W), W);
        w.insert(lower_bound(w.begin(),w.end(),R), R);
        itr ++;
    }
    cout << itr << endl;
}



Measured memory_bytes: 5272
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=vector<ll>;
using mat=vector<vec>;
#define For(i,a,b) for(i=a;i<b;i++)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define all(v) (v).begin(),(v).end()
#define vsort(v) sort(all(v))
#define mod 1000000007
using data=pair<ll,ll>;
int main(){
  ll i,n,m,ans=0;
  cin>>n>>m;
  vector<data>  v(n);
  rep(i,n){
    cin>>v[i].first>>v[i].second;
  }
  vsort(v);
  i=0;
  while(m>0){
    if(v[i].second<m){
      m-=v[i].second;
      ans+=v[i].first*v[i].second;
      i++;
    }else{
      ans+=v[i].first*m;
      cout<<ans<<endl;
      return 0;
      }
  }
  
  
}


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

using Edge = tuple<int, int>;

static const int MAXN = 2010;
static vector<int> tree[MAXN];
static int dist[MAXN][MAXN];

void dfs(int u, int root, int par, int d) {
    dist[root][u] = d;

    for (int to : tree[u]) {
        if (to == par) continue;
        dfs(to, root, u, d + 1);
    }
}

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

    vector<Edge> E;
    for (int i = 0; i < N - 1; i++) {
        int A, B;
        cin >> A >> B;
        A--; B--;

        tree[A].push_back(B);
        tree[B].push_back(A);

        E.emplace_back(A, B);
    }

    for (int u = 0; u < N; u++) {
        dfs(u, u, -1, 0);
    }

    int ans = MAXN;

    // 木の中心を全探索
    if (K % 2 == 0) {
        // ある頂点u in Vが存在して, 任意の頂点v in Vに対してdist[u][v] <= K / 2
        for (int u = 0; u < N; u++) {
            int score = 0;
            for (int v = 0; v < N; v++) {
                if (dist[u][v] > K / 2) score++;
            }
            ans = min(ans, score);
        }
    } else {
        // ある辺e in Eが存在して, 任意の頂点v in Vに対してdist[e.endpoint][v] <= (K - 1) / 2
        for (Edge& e : E) {
            int end1, end2;
            tie(end1, end2) = e;

            int score = 0;
            for (int v = 0; v < N; v++) {
                if (min(dist[end1][v], dist[end2][v]) > (K - 1) / 2) score++;
            }
            ans = min(ans, score);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 16256
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 1e5
#define INF 1<<30
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S;
ll ans = 0;

int main() {
	cin >> N >> M;
	vector<pair<ll, ll>>d(N);
	for (int i = 0; i < N; i++)cin >> d[i].first >> d[i].second;
	sort(d.begin(), d.end());
	for (int i = 0; i < N; i++) {
		if (d[i].second < M) {
			M -= d[i].second;
			ans += d[i].first*d[i].second;
		}
		else {
			ans += M * d[i].first;
			break;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
// Ver19.03
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define ull unsigned long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  char s[100001];
  scanf("%s", s);
  for (int i = 0; i < strlen(s); i++)
  {
    if (i % 2 == 0)
    {
      putchar(s[i]);
    }
  }
  puts("");
  return 0;
}

Measured memory_bytes: 256
// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
//
// See the bottom of file for solution.
// -----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (N, K) = read!(usize, usize);
    let H = read![[i64]];

    let mut dp = vec![std::i64::MAX; N];
    dp[0] = 0;
    for i in 0..N {
        for k in 1..K + 1 {
            if i + k < N {
                dp[i + k] = min(dp[i + k], dp[i] + (H[i] - H[i + k]).abs())
            }
        }
    }

    println!("{}", dp[N - 1])
}


Measured memory_bytes: 6524
//g++  5.4.0

#include<bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define int long long
#define pb push_back
#define pii pair< int,int >
#define fast ios::sync_with_stdio(0) , cin.tie(0) , cout.tie(0) ;

const int nax = 1e5+1;
vector<int> rg[nax] , dp(nax,-1);


signed main()
{
    fast;
    
    int n , m ;
    cin >> n >> m ;
    
    while( m-- )
    {
        int u,v;
        cin >> u >> v;
        rg[ v ].pb( u );
    }
    
    function< int(int) > dp_work = [&](int v)
    {
        if( dp[v] != -1 ) return dp[v];
        dp[ v ] = 0;
        for( auto u : rg[v] )
            dp[ v ] = max( dp_work( u ) + 1 , dp[v] );
        return dp[ v ];
    };
    
    int ans = 0;
    for(int i=1 ; i<=n ; i++ ) ans = max( ans , dp_work( i ) );
    cout << ans;
}





Measured memory_bytes: 14080
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	static int[][] ans;
	static int alphabet=26;
	public static void main(String[] args) {
		SC sc = new SC(System.in);
		int H=sc.nextInt();
		int W=sc.nextInt();
		int[] cha=new int[alphabet];
		ans=new int[H][W];
		Arrays.fill(cha, 0);
		for(int i=0; i<H; i++) {
			String a=sc.next();
			for(int j=0; j<W; j++) {
				cha[a.charAt(j)-'a']++;
			}
		}
		if(H%2==1 && W%2==1) {//奇数ｘ奇数
			boolean kisu=false;
			for(int i=0; i<alphabet; i++) {
				if(!kisu && cha[i]%2==1) {
					kisu=true;
				}
				else if(kisu && cha[i]%2==1) {
					pl("No");
					System.exit(0);
				}
			}
			int make4=(H/2)*(W/2);
			for(int i=0; i<alphabet; i++) {
				if(cha[i]>=4) {
					make4-=cha[i]/4;
				}
			}
			if(make4>0) {
				pl("No");
				System.exit(0);
			}
			//ここまで来たならOK
			pl("Yes");
		}
		else if(H%2==0 && W%2==0) {//偶数ｘ偶数
			for(int i=0; i<alphabet; i++) {
				if(cha[i]%4!=0) {
					pl("No");
					System.exit(0);
				}
			}
			//ここまで来たならOK
			pl("Yes");
		}
		else {
			if(H%2==1) {
				int make4=((H-1)/2)*(W/2);
				for(int i=0; i<alphabet; i++) {
					if(cha[i]>=4) {
						make4-=cha[i]/4;
					}
					if(cha[i]%2==1) {
						pl("No");
						System.exit(0);
					}
				}
				if(make4>0) {
					pl("No");
					System.exit(0);
				}
				//ここまで来たならOK
				pl("Yes");
			}
			else if(W%2==1) {
				int make4=(H/2)*((W-1)/2);
				for(int i=0; i<alphabet; i++) {
					if(cha[i]>=4) {
						make4-=cha[i]/4;
					}
					if(cha[i]%2==1) {
						pl("No");
						System.exit(0);
					}
				}
				if(make4>0) {
					pl("No");
					System.exit(0);
				}
				//ここまで来たならOK
				pl("Yes");
				System.exit(0);
			}
		}
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
}

Measured memory_bytes: 24404
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n,x;
  cin >> n >> x;
  int m[n];
  int ans=n;
  for(int i=0;i<n;i++){
     cin >> m[i];
     x-=m[i];
  }
   sort(m,m+n);
   ans+=(x/m[0]);
   cout << ans << endl;
}


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

int dp[100005][5];

int main(){
    int n; cin>>n;
    vector<vector<int>> v(n,vector<int>(3));
    for(int i=0;i<n;i++){
        cin>>v[i][0]>>v[i][1]>>v[i][2];
    }

    for(int i=1;i<=n;i++){
        for(int j=0;j<3;j++){
            dp[i][j]=max(dp[i-1][(j+1)%3]+v[i-1][(j+1)%3],dp[i-1][(j+2)%3]+v[i-1][(j+2)%3]);
        }
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
}

Measured memory_bytes: 7680
k, n = map(int, input().split())
a_list = list(map(int, input().split()))

interval = []
ans = 1e+9
for i in range(len(a_list)):
    if i == 0:
        distance = a_list[-1] - a_list[0]
    else:
        interval = a_list[i] - a_list[i-1]
        distance = k - interval
    ans = min(ans, distance)
print(ans)



Measured memory_bytes: 25836
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 10000000000000000ll
#define MAXN 1000001
#define eps 0.0000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}

// string to integer stuuu()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

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

#define S second
#define F first
#define int long long  

//////////

signed main()
{
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
	int r,g,b,n;
	cin>>r>>g>>b>>n;
	int ans=0;
	for(int i=0;i<=n;++i)
	{
		for(int j=0;j<=n;++j)
		{
			if((n-r*i-g*j)%b==0&&n-r*i-g*j>=0)
				++ans;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define INF 987654321987654321
#define PI 3.14159265358979323846264
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
int MOD = 998244353;
ll POW(ll a, ll b, ll MMM = MOD) { ll ret = 1; for (; b; b >>= 1, a = (a*a) % MMM)if (b & 1)ret = (ret*a) % MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,-1,1,0 }, dy[] = { 1,0,0,-1 };
int ddx[] = { 0,0,1,1,1,-1,-1,-1 }, ddy[] = { 1,-1,1,0,-1,1,0,-1 };

string s;
int d[200000][3][3][2];
int n, x;
int go(int N, int k, int pre, int c)
{
	if (N == n)
	{
		if (c && k == x)return 1;
		return 0;
	}
	int &ret = d[N][k][pre][c];
	if (ret != -1)return ret;
	ret = 0;
	fup(i, 0, 2, 1)
	{
		if (pre == i)ret = (ret + go(N + 1, (k + i) % 3, i, 1)) % MOD;
		else ret = (ret + go(N + 1, (k + i) % 3, i, c)) % MOD;
	}
	return ret;
}
int main() {
	MEM_1(d);
	cin >> s;
	n = s.length();
	if (n <= 6)
	{
		set<string> S;
		S.insert(s);
		while (1)
		{
			vector<string> temp;
			int nowsz = S.size();
			for (auto it = S.begin(); it != S.end(); it++)
			{
				string ss = *it;
				fup(i, 1, n - 1, 1)
				{
					if (ss[i] != ss[i - 1])
					{
						string t = ss;
						t[i] = t[i - 1] = 3 * 'a' + 3 - ss[i] - ss[i - 1];
						temp.push_back(t);
					}
				}
			}
			for (string t : temp)S.insert(t);
			if (S.size() == nowsz)break;
		}
		return !printf("%d", S.size());
	}
	bool ok = 1;
	int last = 1;
	fup(i, 0, n - 1, 1)
	{
		x += s[i] - 'a';
		if (i > 0)
		{
			if(s[i] != s[0])ok = 0;
			if (s[i] == s[i - 1])last = 0;
		}
	}
	if (ok)return !printf("1");
	x %= 3;
	int ans = 0;
	fup(i, 0, 2, 1)
		ans = (ans + go(1, i, i, 0))%MOD;
	printf("%d", (ans+last)%MOD);
}

Measured memory_bytes: 33412
#include "bits/stdc++.h"
#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
using ull = unsigned long long;
using ll = long long;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;


int main(){
    string s;
    cin >> s;
    int A = s[0] - '0', B = s[1] - '0', C = s[2] - '0', D = s[3] - '0';
    if(A - B - C - D == 7) printf("%d-%d-%d-%d=7\n", A, B, C, D);
    else if(A - B - C + D == 7) printf("%d-%d-%d+%d=7\n", A, B, C, D);
    else if(A - B + C - D == 7) printf("%d-%d+%d-%d=7\n", A, B, C, D);
    else if(A + B - C - D == 7) printf("%d+%d-%d-%d=7\n", A, B, C, D);
    else if(A - B + C + D == 7) printf("%d-%d+%d+%d=7\n", A, B, C, D);
    else if(A + B + C - D == 7) printf("%d+%d+%d-%d=7\n", A, B, C, D);
    else if(A + B - C + D == 7) printf("%d+%d-%d+%d=7\n", A, B, C, D);
    else if(A + B + C + D == 7) printf("%d+%d+%d+%d=7\n", A, B, C, D);
}

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

typedef long long ll;

int main () {
	int M, N;
	cin >> N >> M;
	if (N%2) {
		for (int i=1; i<=M; i++)
			cout << i << " " << 2*M+1-i << endl;
	} else {
		int i=1;
		while (i<=M/2) {
			cout << i << " " << 2*M+2-i << endl;
			i++;
		}
		while (i<=M) {
			cout << i << " " << 2*M+1-i << endl;
			i++;
		}
	}
	return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
 
int main() {
    int N, K;
    cin >> N >> K;
    vector<int> P(N), C(N);
    rep(i, N) cin >> P.at(i);
    rep(i, N) cin >> C.at(i);
    rep(i ,N) P.at(i) --;
    ll ans = -1e18;
    rep(si, N){
        int x = si;
        vector<int> s;
        ll total = 0;
        while(1){
            x = P.at(x);
            s.push_back(C.at(x));
            total += C.at(x);
            if (x == si) break;
        }
        int l = s.size();
        ll t = 0;
        rep(i, l){
            t += s.at(i);
            if(i >= K) break;
            ll now = t;
            if(total > 0){
                ll roop = (K - (i + 1)) / l;
                now += roop * total;
            }
            ans = max(ans, now);
        }
    }
    cout << ans << endl;
}

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

int main(void) {
        int a;
        int b;

        for (a=1; a < 10; a++) {
                for (b=1; b < 10; b++) {
                        cout << a << "x" << b << "=" << a*b << endl;
                }
        }

        return 0;
}

Measured memory_bytes: 3096
// template version 1.15
using namespace std;
#include <bits/stdc++.h>

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define slice(l, r) substr(l, r-l)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
#else
    #define dump(...) 42
    #define dump_1d(...) 42
    #define dump_2d(...) 42
    #define cerrendl 42
#endif
//}}}

signed main() {
    int n,m;cin>>n>>m;
    vector<int> a(n);
    int s = 0;
    rep(i, n) {
        cin>>a[i];
        s += a[i];
    }
    dump(a);

    cout << max(-1LL, n-s) << endl;
    return 0;
}


Measured memory_bytes: 11056
#include <queue>
#include <vector>
#include <cstring>
#include <iostream>
using namespace std;
int H, W, ax, ay, bx, by, x[52][52], dp[52][52][52][52];
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
int main() {
	while(cin >> W >> H >> ax >> ay >> bx >> by) {
		for(int i = 0; i < H + 2; i++) {
			for(int j = 0; j < W + 2; j++) {
				x[i][j] = 1;
				if(i && i != H + 1 && j && j != W + 1) scanf("%d", &x[i][j]);
			}
		}
		memset(dp, -1, sizeof(dp)); dp[ay][ax][by][bx] = 0;
		queue<vector<int> > que; que.push({ax, ay, bx, by});
		bool flag = false;
		while(!que.empty()) {
			vector<int> v1 = que.front(); que.pop();
			for(int i = 0; i < 4; i++) {
				vector<int> v2 = v1;
				if(!x[v1[1] + dy[i]][v1[0] + dx[i]]) v2[0] += dx[i], v2[1] += dy[i];
				if(!x[v1[3] - dy[i]][v1[2] - dx[i]]) v2[2] -= dx[i], v2[3] -= dy[i];
				if(v2[0] == v2[2] && v2[1] == v2[3]) {
					flag = true; break;
				}
				if(dp[v2[1]][v2[0]][v2[3]][v2[2]] == -1) {
					dp[v2[1]][v2[0]][v2[3]][v2[2]] = dp[v1[1]][v1[0]][v1[3]][v1[2]] + 1;
					que.push(v2);
				}
			}
			if(flag) {
				cout << dp[v1[1]][v1[0]][v1[3]][v1[2]] + 1 << endl; break;
			}
		}
		if(!flag) cout << "NA" << endl;
	}
}

Measured memory_bytes: 32356
s = input()

count = 0
if len(s) % 2 == 0:
    start = s[:len(s) // 2]
    end = s[len(s) // 2: len(s)]
    end = end[::-1]

    for i, st in enumerate(start):
        if st != end[i]:
            count = count + 1
else:
    start = s[:len(s) // 2]
    end = s[len(s) // 2: len(s)]
    end = end[::-1]

    for i, st in enumerate(start):
        if st != end[i]:
            count = count + 1

print(count)

Measured memory_bytes: 3064
n = int(input())
a = [int(i) for i in input().split()]

ans = []

now = a[0]
flag = 'u'

for i in range(n-1):
    if flag == 'u':
        if now < a[i+1]:
            ans.append(a[i])
            if i == n-2:
                #print(i)
                ans.append(a[i+1])
                break
            #print(i)
            flag = 'd'
        now = a[i+1]
        
    else:
        if now > a[i+1]:
            ans.append(now)

            #print(i)
            flag = 'u'
        now = a[i+1]

if flag == 'd':
    ans.append(a[n-1])

okane = 1000
#print(ans)
for i in range(len(ans)//2):
    okane += (okane // ans[2*i])*(ans[2*i+1]-ans[2*i])
    #print(okane)
    #okane -= kosu * ans[i]
print(okane)   


Measured memory_bytes: 62012
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StackControler readDataArr = new StackControler(in.readLine()
				.split(" "));
		System.out.println(readDataArr.calcData());
	}
}

class Stack {
	private int[] stack;
	private static int pointer = 0;

	Stack(int[] stack) {
		this.stack = stack;
	}

	public void push(int data) {
		stack[pointer] = data;
		pointer++;
	}

	public int pop() {
		pointer--;
		return stack[pointer];
	}

}

class StackControler {
	private Stack stack;
	private String[] readData;
	private int operand2, operand1, result, strToIntData;

	StackControler(String[] readData) {
		this.readData = readData;
	}

	public int calcData() {
		String tempStrData;
		stack = new Stack(new int[100]);
		for (int i = 0; i < readData.length; i++) {
			tempStrData = readData[i];

			if (tempStrData.equals("+")) {
				operand1 = stack.pop();
				operand2 = stack.pop();
				result = operand2 + operand1;
				stack.push(result);
			} else if (tempStrData.equals("-")) {
				operand1 = stack.pop();
				operand2 = stack.pop();
				result = operand2 - operand1;
				stack.push(result);
			} else if (tempStrData.equals("*")) {
				operand1 = stack.pop();
				operand2 = stack.pop();
				result = operand2 * operand1;
				stack.push(result);
			} else {
				strToIntData = Integer.parseInt(readData[i]);
				stack.push(strToIntData);
			}
		}
		return stack.pop();
	}
}

Measured memory_bytes: 24472
#!/usr/bin/env python
# coding: utf-8
#
    
def main(a,b):
    if 0 == a * b % 2:
        print('No')
    else:
        print('Yes')
    
    
if __name__ == '__main__':
    try:
        a,b  = list(map(int,input().strip().split(' ')))
        main(a, b)
    except EOFError:
        pass


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vi cnt(n,0);
  vi a(n);
  rep(i,n) {
    cin >> a.at(i);
    cnt[a[i]]++;
  }
  if(n%2==0) {
    bool ok = true;
    for(int i = 1; i <= n-1; i+=2) {
      if(cnt[i]!=2) ok = false;
    }
    if(!ok) cout << 0 << endl;
    else {
      int m = n/2;
      ll ans = 1;
      rep(i,m) {
        ans *= 2;
        ans %= mod;
      }
      cout << ans << endl;
    }
  }
  else {
    bool ok = true;
    for(int i = 0; i <= n-1; i+=2) {
      if(i==0) {
        if(cnt[i]!=1) ok = false;
      }
      else {
        if(cnt[i]!=2) ok = false;
      }
    }
    if(!ok) cout << 0 << endl;
    else {
      int m = (n-1)/2;
      ll ans = 1;
      rep(i,m) {
        ans *= 2;
        ans %= mod;
      }
      cout << ans << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define SFOR(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define INF INT_MAX
#define endl '\n'
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
int main(){
   cin.tie(0);
   ios::sync_with_stdio(false);
   int maxi=-1,ans=0,n,d[21];
   cin>>n;
   FOR(i,n){
     cin>>d[i];
     if(d[i]>=maxi){
      ans++;
     }
     maxi=max(d[i],maxi);
   }
   cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdbool.h>
#define M 8
#define FREE 1
#define NFREE -1

int n;
int row[M];
int col[M];
int dpos[2*M-1];
int dneg[2*M-1];
bool G[M][M];
void qutQueen(int);
void printBoard();

int main(){
  int i;
  int j;
  int x;
  int y;

  for(i=0;i<M;i++){
    row[i] = FREE;
    col[i] = FREE;
  }
  for(i=0;i<2*M-1;i++){
    dpos[i] = FREE;
    dneg[i] = FREE;
  }

  for(i=0;i<M;i++){
    for(j=0;j<M;j++){
      G[i][j] = false;
    }
  }
  
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf(" %d %d",&x,&y);
    G[x][y] = true;
  }
  qutQueen(0);
  return 0;
}

void printBoard(){
  int i;
  int j;

  for(i=0;i<M;i++){
    for(j=0;j<M;j++){
      if(G[i][j]){
        if(row[i] != j) return;
      }
    }
  }

  for(i=0;i<M;i++){
    for(j=0;j<M;j++){
      if(row[i] == j) printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}

void qutQueen(int i){
  int j;

  if(i == M){
    printBoard();
    return;
  }

  for(j=0;j<M;j++){
    if(col[j] == NFREE || dpos[i+j] == NFREE || dneg[i-j+M-1] == NFREE) continue;
    row[i] = j;
    col[j] = dpos[i+j] = dneg[i-j+M-1] = NFREE;
    qutQueen(i+1);
    row[i] = col[j] = dpos[i+j] = dneg[i-j+M-1] = FREE;
  }
}




Measured memory_bytes: 2112
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
struct Dice {
	int d[6], E, S, U;
	void init(int a[]) {
		rep(i, 6)d[i] = a[i];
		E = 2; S = 1; U = 0;
	}
	void rotate(char C) {
		int a = E, b = S, c = U;
		switch (C) {
		case'E':E = U; U = 5 - a; break;
		case'N':U = S; S = 5 - c; break;
		case'S':S = U; U = 5 - b; break;
		case'W':U = E; E = 5 - c; break;
		case'R':S = E; E = 5 - b; break;
		case'L':E = S; S = 5 - a; break;
		}
	}
	int rotate(int a, int b) {
		rep(k, 2) {
			rep(i, 4) {
				rep(j, 4) {
					if (a == d[U] && b == d[S])return d[E];
					rotate('E');
				}
				rotate('S');
			}
			rotate('L');
		}
	}
	bool operator==(Dice b) {
		rep(k, 2) {
			rep(i, 4) {
				rep(j, 4) {
					if (b.d[b.U] == d[U] && b.d[b.S] == d[S] && b.d[b.E] == d[E] &&
						b.d[5 - b.U] == d[5 - U] && b.d[5 - b.S] == d[5 - S] && b.d[5 - b.E] == d[5 - E])
						return true;
					rotate('E');
				}
				rotate('S');
			}
			rotate('L');
		}
		return false;
	}
};
Dice d[100]; int a[100][6];
int main() {
	int n; cin >> n;
	rep(i, n) {
		rep(j, 6)cin >> a[i][j];
		d[i].init(a[i]);
	}
	rep(i, n)for (int j = i + 1; j < n; j++) {
		if (d[i] == d[j]) {
			puts("No"); return 0;
		}
	}
	puts("Yes");
}


Measured memory_bytes: 3104
import  java.util.*;
class Main{
  static class UnFd{
    int n;
    int[] par;
    int[] siz;
    int forest;
    UnFd(int n){
      this.n=n;
      par=new int[n];
      siz=new int[n];
      for(int i=0;i<n;i++){
        par[i]=i;
        siz[i]=1;
      }
      forest=n;
    }
    int forest(){
      return forest;
    }
    boolean isRoot(int i){
      return i==par[i];
    }
    int rootOf(int i){
      if(isRoot(i)){
        return i;
      }
      return par[i]=rootOf(par[i]);
    }
    int sizeOf(int i){
      return siz[rootOf(i)];
    }
    boolean isSame(int i,int j){
      return rootOf(i)==rootOf(j);
    }
    void merge(int i,int j){
      i=rootOf(i);
      j=rootOf(j);
      if(i==j){
        return;
      }
      par[i]=j;
      siz[j]+=siz[i];
      forest--;
    }
  }
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int m=sc.nextInt();
    int k=sc.nextInt();
    int[] sub=new int[n];
    UnFd uf=new UnFd(n);
    for(int i=0;i<m;i++){
      int a=sc.nextInt()-1;
      int b=sc.nextInt()-1;
      uf.merge(a,b);
      sub[a]++;
      sub[b]++;
    }
    for(int i=0;i<k;i++){
      int c=sc.nextInt()-1;
      int d=sc.nextInt()-1;
      if(uf.isSame(c,d)){
        sub[c]++;
        sub[d]++;
      }
    }
    for(int i=0;i<n-1;i++){
      System.out.print((uf.sizeOf(i)-sub[i]-1)+" ");
    }
    System.out.println((uf.sizeOf(n-1)-sub[n-1]-1));
  }
}

Measured memory_bytes: 113268
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#define INF 10000000
using namespace std;
typedef pair<int,int> P;

int n;
int ba[10];

bool all(int,int,int);

int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<10;j++){
      cin >> ba[j];
    }
    if(all(0,0,0)){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }
}

bool all(int end,int l,int r){
  if(end==10){
    return true;
  }
  if(ba[end]>l){
    return all(end+1,ba[end],r);
  }
  if(ba[end]>r){
    return all(end+1,l,ba[end]);
  }
  return false;
}

Measured memory_bytes: 1152
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int t=0,num[100];

void push(int);
int pop(void);

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

  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      a=pop();
      b=pop();
      push(a+b);

    } 

    else if ( s[0] == '-' ){
      a=pop();
      b=pop();
      push(b-a);
    } 

    else if ( s[0] == '*' ){
      a=pop();
      b=pop();
      push(a*b);
    } 

    
    else {
      push(atoi(s));

    }
  }
    printf("%d\n",num[0]);

  return 0;
}

void push(int x){
  num[t]=x;
  t++;
}

int pop(){
  int x;
  t--;
  x=num[t];

  return x;
}

Measured memory_bytes: 548
// ALDS1_11_D.cpp
// Graph I - Connected Components

#include <iostream>
#include <vector>
#include <queue>
using namespace std;

void bfs(vector<vector<int>> &sns, vector<int> &color, int x)
{
    if (color[x] != -1 || sns[x].empty()) return;
    queue<int> mq;
    mq.push(x);
    while(!mq.empty()) {
        int curr = mq.front();
        mq.pop();
        color[curr] = x;
        for (int i = 0; i < sns[curr].size(); i++) {
            int next = sns[curr][i];
            if (color[next] == -1) {
                mq.push(next);
                color[next] = x;
            }
        }
    }
}

void assignColor(vector<vector<int>> &sns, vector<int> &color)
{
    for (int i = 0; i < sns.size(); i++) {
        bfs(sns, color, i);
    }
}

int main()
{
//    freopen("ALDS1_11_D_in22.txt", "r", stdin);
//    freopen("out22.txt", "w", stdout);
    int m, n, q;
    cin >> n >> m;
    vector<vector<int> > sns(n, vector<int>());
    int x, y;
    for (int i = 0; i < m; i++) {
        cin >> x >> y;
        sns[x].push_back(y);
        sns[y].push_back(x);
    }
    vector<int> color(n, -1);
    assignColor(sns, color);
    cin >> q;
    while (q--) {
        cin >> x >> y;
        if (color[x] == color[y] && color[x] != -1) cout << "yes" << endl;
        else cout << "no" << endl;
    }
    return 0;
}

Measured memory_bytes: 8544
#include<stdio.h>
#include<string.h>
char b[100];
int rotate(char a[], char c[])
{
    int i,j,len=strlen(a);
    int k=0;
    for(k; k<len; k++)
    {
        *b=a[len-1-k];
        for(i=len-k,j=1; j<len; i++,j++)
        {
            if(i>=len)
                i=0;
            *(b+j)=a[i];

        }
        *(b+j)='\0';
        int l=0;
        if(strcmp(c,b)==0)
        {
            return 1;
        }
    }
    return 0;
}
int main()
{
    char p[100], q[100];
    scanf("%s %s",p,q);
    if(rotate(p,q))
        printf("Yes\n");
    else
        printf("No\n");
    return 0;

}


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

using namespace std;

int dp[1<<13];

pair<int,int> a[1010];

int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		int cost,k;
		scanf("%d%d",&cost,&k);
		int tmp=0;
		for(int j=0;j<k;j++){
			int x;
			scanf("%d",&x);
			tmp|=(1<<(x-1));
		}
		a[i].first=cost;a[i].second=tmp;
	}
	
	memset(dp,0x3f,sizeof(dp));
	dp[0]=0;
	for(int i=1;i<=m;i++){
		for(int j=0;j<(1<<n);j++){
			dp[a[i].second|j]=min(dp[a[i].second|j],dp[j]+a[i].first);
		}
	}
	int num=(1<<n)-1;
	printf("%d",dp[num]==0x3f3f3f3f?-1:dp[num]);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstring>
#include<cstdio>
#include <sstream>
#include <cctype>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#define all(a) (a).begin(),(a).end()

using namespace std;


string toString(int a){
  ostringstream oss;
  oss << a;
  return oss.str();
}

int toInt(string s){
  istringstream iss(s);
  int a;
  iss >> a;
  return a;
}

vector<int> toVec(string s){
  vector<int>res;
  for(int i=s.size()-1;i>=0;i--){
    res.push_back(s[i]-'0');
  }
  return res;
}

int VecToInt(vector<int>v){
  int res=0;
  for(int i=0;i<v.size();i++){
    res+=v[i]*pow(10.,(double)v.size()-i-1);
  }
  return res;
}

int main(void){

  string a;
  int L;

  while(cin >> a >> L,L){
    int cnt=1;
    map<string,int> p;
    p[a]=cnt;

    while(true){

      if(a.size()<L)
	for(int i=a.size();i<L;i++)a+='0';
      
      vector<int>num=toVec(a);
      sort(all(num),greater<int>());
      int Max=VecToInt(num);
      
      sort(all(num));
      int Min=VecToInt(num);
      
      a=toString(Max-Min);

      if(p[a]>0){
	cout << p[a]-1 <<" "<<  a << " " << cnt-p[a]+1 << endl;
	break;
      }
      cnt++;
      p[a]=cnt;
    }
    
  }
  
  return 0;
}

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

int n,c;
long long mp[110][100010];
long long arr[100010],w[100010];

long long solve(int n,int c){
	if(n==0||c==0)return 0;
	if(mp[n][c])return mp[n][c];
	long long result;
	if(w[n]>c)result=solve(n-1,c);
	else {
		long long a = arr[n]+solve(n-1,c-w[n]);
		long long b = solve(n-1,c);
		result=max(a,b);
	}
	mp[n][c]=result;
	return result;
}

int main(){
	/*#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	#endif
	ios::sync_with_stdio(false);
    cin.tie(0);*/
	
	cin>>n>>c;
	for(int i=1;i<=n;i++){
		long long a,b;cin>>a>>b;
		arr[i]=b;w[i]=a;
	}
	cout<<solve(n,c);

	return 0;
}

Measured memory_bytes: 80128
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) { if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(DUMPALL_ITR, (q).size()) { cerr << (q)[DUMPALL_ITR] << (DUMPALL_ITR == DUMPALL_ITR_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using  ld = long double;
using namespace std;

// 標準入出力
struct inp {
    size_t sz;
    inp(size_t _sz = 1) : sz(_sz) {}
    template <typename T> operator T () const { T a; cin >> a; return a; }
    template <typename T> operator vector<T> () const { vector<T> a(sz); for (size_t i = 0; i < sz; i++) cin >> a[i]; return a; }
    template <typename T, typename U> operator pair<T, U> () const { T f; U s; cin >> f >> s; return pair<T, U>(f, s); }
};
inp inp1; // input one
template <typename T> void say(T &x, char end = '\n') { cout << x << end; }
template <typename T> void say(vector<T> &x, char sep = ' ', char end = '\n') { for (size_t i = 0, sz = x.size(); i < sz; i++) { cout << x[i] << (i == sz-1 ? end : sep); } }

// モジュール


// 処理内容
int main() {
    
    ios::sync_with_stdio(false); // stdioを使うときはコメントアウトすること
    cin.tie(nullptr);            // インタラクティブ問題ではコメントアウトすること
    
    ll a = inp1;
    ll b = inp1;
    ll c = a ^ b;
    say(c);
    
}

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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  int B=0;
  for(int i=0;i<N;i++){
    cin >> A.at(i);
    B^=A.at(i);
  }
  for(int i=0;i<N;i++){
    int C=B^A.at(i);
    cout << C;
    if(i==N-1){
      cout << endl;
    }
    else{
      cout << " ";
    }
  }
}

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

int main(){
  int n;
  cin>>n;
  int vec[n];
  for(int i=0;i<n;i++){
    cin>>vec[i];
  }
  int ans[n+1]={};
  int vecb[n]={};
  int answer=0;
  for(int i=n-1;i>=0;i--){
    int sum=0;
    for(int j=i+1;j<n+1;j+=i+1){
      sum+=ans[j];
    }
    if(sum%2!=vec[i]){
      vecb[answer]=i+1;
      answer++;
      ans[i+1]=1;
    }
  }
  cout<<answer<<endl;
  for(int i=0;i<answer;i++){
    cout<<vecb[i]<<endl;
  }
}

Measured memory_bytes: 5932
import numpy as np
from collections import defaultdict
from functools import reduce
from itertools import product

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

light = defaultdict(list)

for i in range(m):
    A = list(map(int, input().split()))
    for s in range(1, A[0]+1):
        light[i].append(A[s]-1)

p = list(map(int, input().split()))
res = 0


for state in product([0,1], repeat=n):
    for i in range(m):
        if len(list(filter(lambda s: state[s] == 1, light[i])))%2 != p[i]:
            break
    else:
        res += 1

print(res)










Measured memory_bytes: 12512
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  map<int, int> m0, m1;
  rep(i, n) if (i & 1) m1[a[i]]++;
  rep(i, n) if ((i & 1) == 0) m0[a[i]]++;
  int a1[2] = {}, a0[2] = {};
  vector<pair<int, int>> v1, v2;
  for (auto s : m1) {
    v1.push_back(make_pair(-s.second, s.first));
  }
  for (auto s : m0) {
    v2.push_back(make_pair(-s.second, s.first));
  }
  sort(v1.begin(), v1.end());
  sort(v2.begin(), v2.end());
  if (v1.size() == 1 && v2.size() == 1) {
    if (v1[0].second == v2[0].second) {
      cout << min(-v1[0].first, -v2[0].first) << endl;
      return 0;
    }
    cout << 0 << endl;
    return 0;
  } else if (v1.size() == 1) {
    if (v2[0].second == v1[0].second) {
      cout << n + v2[1].first + v1[0].first << endl;
    } else {
      cout << n + v2[0].first + v1[0].first << endl;
    }
  } else if (v2.size() == 1) {
    if (v2[0].second == v1[0].second) {
      cout << n + v2[0].first + v1[1].first << endl;
    } else {
      cout << n + v2[0].first + v1[0].first << endl;
    }
  } else {
    if (v2[0].second == v1[0].second) {
      cout << min(n + v2[0].first + v1[1].first, n + v2[1].first + v1[0].first)
           << endl;
    } else {
      cout << n + v2[0].first + v1[0].first << endl;
    }
  }
}


Measured memory_bytes: 6520