akhauriyash/Code-Regression huggingface dataset:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = map(int, input().split())
E = []
for _ in range(M):
  a, b = map(int, input().split())
  E.append((a-1, b-1))
ans = 0
r = 0
while r < M:
  uf = UnionFind(N)
  i = 0
  while i < M:
    if i != r:
      a, b = E[i]
      uf.union(a, b)
    i += 1
  i = 0
  while i < N:
    _ = uf.find(i)
    i += 1
  if uf.group_count() > 1:
    ans += 1
  r += 1
print(ans)

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

const long long INF = 1LL << 60;
int MOD = 1000000007;
int PI = 3.14159265358979323846;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define For(i,s,n) for (int i=s;i<(int)(n);i++)
#define vi vector<int>
#define vii vector< vector<int> >
#define All(c) (c).begin(), (c).end()
#define Print(x) cout<<(x)<<"\n"
#define Sort(v) sort(All(v))
#define Reverse(v) reverse(All(v))


//日立製作所 社会システム事業部 PC 2020 A

string S;

int main() {

	cin >> S;
	if (S.size() % 2) Print("No");
	else {
		bool flag = true;
		rep(i, S.size() / 2) {
			if (S[2 * i] != 'h' || S[2 * i + 1] != 'i') flag = false;
		}
		if (flag) Print("Yes");
		else Print("No");
	}
}


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

int main() {
	int n, ans = 0;
  	string s;
  	cin >> n >> s;
  	for (int i = 3; i <= n; i++)
      	if (s[i - 1] == 'C' && s[i - 2] == 'B' && s[i - 3] == 'A')
          	ans++;
 	return cout << ans << "\n", 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
using namespace std;

int main() {
	int N, A;
	string S;
	cin >> N >> A >> S;
	S[A - 1] += ('a'-'A');
	cout << S;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;

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

    vl h(n+2);
    rep(i, n) {
        cin >> h[i];
    }
    h[n] = h[n+1] = INF;

    vl dp(n+10, INF);  // dp[i] : 足場i(iは0-index)に移動するコストの最小値
    dp[0] = 0;
    rep(i, n) {
        chmin(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
        chmin(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
    }

    out(dp[n-1]);
    re0;
}

Measured memory_bytes: 4848
#include<bits/stdc++.h>
using namespace std;
template <typename T> using vec = vector<T>;

int main()
{
    int n;
    cin >> n;
    int ac=0,wa=0,tle=0,re=0;
    string s;
    for (int i = 0; i < n; i++)
    {
        cin >> s;
        if (s=="AC")
        {
            ac++;
        }
        else if (s=="WA")
        {
            wa++;
        }
        else if (s=="TLE")
        {
            tle++;
        }
        else
        {
            re++;
        }
    }
    cout << "AC x " << ac << endl;
    cout << "WA x " << wa << endl;
    cout << "TLE x " << tle << endl;
    cout << "RE x " << re << endl;
    
    
}

Measured memory_bytes: 3572
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::num;

fn main() {
    input! {
        n: i32,
        ver: [(i32, i32, i32); n],
    }
    let mut v = ver;
    v.insert(0, (0, 0, 0));
    let yes = v.windows(2).all(|w| {
        let (t, x, y) = w[0];
        let (nt, nx, ny) = w[1];
        let time = nt - t;
        let dist = (nx - x).abs() + (ny - y).abs();
        dist <= time && dist % 2 == time % 2
    });
    if yes {println!("Yes")} else {println!("No")}
}


Measured memory_bytes: 6396
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

const int N = 100005;

int n;
long long arr[N];
long long a[N];

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    a[i] = arr[i];
  }
  long long l = 1, r = 2e18, ans = -1;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    long long x = mid;
    for (int i = 0; i < n; i++) {
      x -= (x % a[i]);
    }
    if (x > 2) {
      r = mid - 1;
    } else if (x < 2) {
      l = mid + 1;
    } else {
      ans = mid;
      r = mid - 1;
    }
  }
  if (ans == -1) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << " ";
  l = 0, r = 2e18;
  long long ans2 = -1;
  while (l <= r) {
    long long mid = (l + r) >> 1;
    long long x = mid;
    for (int i = 0; i < n; i++) {
      x -= (x % a[i]);
    }
    if (x > 2) {
      r = mid - 1;
    } else if (x < 2) {
      l = mid + 1;
    } else {
      ans2 = mid;
      l = mid + 1;
    }
  }
  cout << ans2 << endl;
  return 0;
}


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

#define ll long long
#define lst(x) x.size()-1
#define ld long double
#define pr pair<ll,ll>
#define loop(i, n) for(ll i=0 ; i<n ; ++i)
#define rep(i, x, n) for(ll i=x ; i<=n ; ++i)
#define iteloop(type, data, name, it) for(type<data>::iterator it=name.begin() ;it!=name.end() ; ++it)

using namespace std;

const ll N = 3e2 + 5, M = 1e6+5 , C=1e3+5, MOD = 1e9 + 7, OO = 1e9+5;
ll arr[N],n,k;
ll memo[N][N][N];


ll dp(int i=1,int lft=k,int lst=0){
    if(i>=n)return 0;
    ll &res=memo[i][lft][lst];
    if(~res)return res;

    ll x=max(0ll,arr[i]-arr[lst]);
    res=x + dp(i+1,lft,i);
    if(lft>0){
        // try back
        res = min(res, dp(i + 1, lft - 1 ,lst ));

        // try front
        x=max(0ll,arr[i+1]-arr[lst]);
        res=min(res , dp(i+1,lft-1,i+1) + x);
    }
    return res;
}
int main() {
    cin.sync_with_stdio(false), cin.tie(0), cout.tie(0);
#ifndef ONLINE_JUDGE
  //  freopen("in.txt", "rt", stdin);
    // freopen("in.txt", "wt" , stdout);
#endif
    cin>>n>>k;
    rep(i,1,n){
        cin>>arr[i];
    }
    n++;
    memset(memo,-1,sizeof(memo));
    cout<<dp()<<endl;
}


Measured memory_bytes: 221952
#include <iostream>
#include <string>
#include <vector>

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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;

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

  bool has_A = false;
  bool has_C = false;
  rep(i, S.size())
  {
    if (S[i] == 'A')
    {
      if (i != 0 || has_A)
      {
        cout << "WA" << endl;
        return 0;
      }
      has_A = true;
    }
    else if (S[i] == 'C')
    {
      if (i < 2 || i >= S.size() - 1 || has_C)
      {
        cout << "WA" << endl;
        return 0;
      }
      has_C = true;
    }
    else if ('A' <= S[i] && S[i] <= 'Z')
    {
      cout << "WA" << endl;
      return 0;
    }
  }

  if (!has_A || !has_C)
  {
    cout << "WA" << endl;
    return 0;
  }

  cout << "AC" << endl;

  return 0;
}


Measured memory_bytes: 256
n=int(input())
ue=list(map(int,input().split()))
shita=list(map(int,input().split()))
data=[]
now=sum(shita)+ue[0]
data.append(now)
for i in range(n-1):
    now=now-shita[i]+ue[i+1]
    data.append(now)
print(max(data))

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

/*
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/



//************** StrAnge.R *********************

#define ll              long long int
#define ull             unsigned long long
#define ld              long double
#define lll             __int128
#define vi              vector<int>
#define vl              vector<ll>
#define vvi             vector<vector<int> >
#define pii             pair<int,int>
#define piii            pair<int,pair<int,int> >
#define pll             pair<ll,ll>
#define vii             vector<pii>

#define sz(v)           ((int)(v).size())
#define all(s)          s.begin(),s.end()
#define allr(s)         s.rbegin(),s.rend()
#define unq(c)          (sort(all(c)), c.resize(distance(c.begin(),unique(all(c)))))
#define get_pos(c,x)    (lower_bound(all(c),x)-c.begin())

#define MS0(v)          memset((v), 0, sizeof((v)))
#define MS1(v)          memset((v), -1, sizeof((v)))
#define LEN(v)          strlen(v)

#define MP              make_pair
#define pb              push_back
#define pob             pop_back
#define ff              first
#define ss              second
#define sc              scanf
#define pf              printf
#define endl            "\n"

#define TEST_CASE       int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define PRINT_CASE      printf("Case %d: ",cs)

#define vpf(v)          for(int i=0;i<v.size();i++){cout<<v[i];if(i!=v.size()-1)cout<<" ";else cout<<"\n";}
#define vsc(v)          for(int i=0;i<v.size();i++)cin>>v[i];

#define REP(i, n)       for (int i = 0; i < (n); i++)
#define REPP(i, a, b)   for (int i = (a); i < (b); i++)
#define FOR(i, a, b)    for (int i = (a); i <= (b); i++)
#define FORS(i, s)      for (int i = 0; s[i]; i++)

#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fileio          freopen("in.txt","r",stdin);freopen("out.txt","w",stdout)

#define intlim          2147483648
#define infinity        (1LL<<50)
#define intmx           INT_MAX
#define PI              3.14159265358979323846264338327950L // acos(-1.0)

#define gcd(a, b)       __gcd(a, b)
#define lcm(a, b)       ((a)*((b)/gcd(a,b)))


int on_bit(int N,int pos){return N = N | (1<<pos);}
int off_bit(int N,int pos){return N = N & ~(1<<pos);}
bool check_bit(ll N,int pos){return (bool)(N & (1<<pos));}


#define start_clock     clock_t tStart = clock()
#define end_clock       printf("\n>>Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC)

template<class T>inline bool read(T &x){int c=getchar();int sgn=1;while(~c&&c<'0'||c>'9'){if(c=='-')sgn=-1;c=getchar();}for(x=0;~c&&'0'<=c&&c<='9';c=getchar())x=x*10+c-'0'; x*=sgn; return ~c;}


//******************* my code starts here **********************************


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

    cout << fixed << setprecision(10) << pow((l/3.0), 3) << "\n";

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
using Graph = vector<vector<int>>;
int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    char s;
    int cnt=0;
    rep(i,3){
        cin>>s;
        if(s=='1')cnt++;
    }
    cout<<cnt<<endl;

    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n;
	cin>>n;
	string s;
	cin>>s;
	int cnt = 1;
	for(int i = 1; i < n; i++){
		if(s[i] != s[i - 1])cnt++;
	}
	cout<<cnt<<endl;

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;

template <typename T>
ostream& operator <<(ostream& out, const vector<T>& vec) {
    out << "[";
    for (int x : vec) out << x << ", ";
    out << "]";
    return out;
}

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file
    #define dbg_var(x) cerr << #x << ": " << x << endl;
#endif


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector<LL> a(n+1);
    for(int i=1; i<=n; i++) cin >> a[i];
    if(a[1] != 0) {cout << "-1\n"; return 0;}
    LL ans = 0;
    for(int i=1; i<=n; i++){
        if(i < n and a[i+1] > a[i] + 1) {cout << "-1\n"; return 0;}
        if(i == n or a[i+1] != a[i] + 1) ans += a[i];
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 1792
import sys
def dif(two_lists):
    return [abs(two_lists[1][i] - two_lists[0][i]) for i in range(3)]


n = int(input())

txy = [[0, 0, 0]] + [[int(s) for s in line.split()] for line in sys.stdin]
dtxy = list(map(dif, zip(txy, txy[1:])))

for i in range(n):
    dt, dx, dy = dtxy[i]
    if  dx + dy > dt or (dt - dx - dy) % 2:
        print("No")
        exit()
print("Yes")


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

#define int         long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000000000000007LL
#define rep(i,a,b)  for(int i=a;i<b;i++)
using namespace std;
int a,b,c,d;
mi mp;
int f(int n){
    if(n==0) return 0;
    if(n==1) return d;
    if(mp.count(n)) return mp[n];
    int ans=hell;
    if(n<=hell/d) ans=n*d;    
    ans=min(ans,(n%2)*d+f(n/2)+a);
    ans=min(ans,(n%3)*d+f(n/3)+b);
    ans=min(ans,(n%5)*d+f(n/5)+c);
    if(n%2) ans=min(ans,(2-n%2)*d+f(n/2+1)+a);
    ans=min(ans,(3-n%3)*d+f(n/3+1)+b);
    ans=min(ans,(5-n%5)*d+f(n/5+1)+c);
    return mp[n]=ans;
}
void solve(){
    mp.clear();
    int n;
    cin>>n>>a>>b>>c>>d;
    cout<<f(n)<<endl;
}

signed main(){
    // ios::sync_with_stdio(false);
    // cin.tie(0);
    // cout.tie(0);
    int t=1;
    cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 4464
#include<bits/stdc++.h>
using namespace std;
#define ll  long long
#define endl '\n'
#define FASTINOUT ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const ll mod = 998244353;
const int N=5009;
int main()
{
    FASTINOUT;
    ll x,y;
    cin>>x>>y;
    cout<<(x)*(x-1)/2+(y*(y-1))/2<<endl;
    return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val s = readLine()!!.split(" ").map { it.toCharArray() }[0]
    val r = readLine()!!.split(" ").map { it.toCharArray() }[0]
    var n = 0
    for (i in 0..2){
        if (s[i] == r[i]){
            n++
        }
    }
    println(n)
}

Measured memory_bytes: 38000
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

  if (x == 1 || x == 2 * N - 1) {
    cout << "No" << endl;
    return 0;
  }

  if (N == 2) {
    cout << "Yes" << endl;
    cout << "1 2 3" << endl;
    return 0;
  }

  vector<int> a(2 * N - 1, 0);
  vector<bool> used(2 * N, false);

  used[x] = true;
  used[x - 1] = true;
  used[x + 1] = true;
  if (x == 2) {
    a[N - 2] = x + 1;
    a[N - 1] = x;
    a[N] = x - 1;
    a[N + 1] = x + 2;
    used[x + 2] = true;
  } else {
    a[N - 2] = x - 1;
    a[N - 1] = x;
    a[N] = x + 1;
    a[N + 1] = x - 2;
    used[x - 2] = true;
  }

  int j = 1;
  for (int i = 0; i < (int)(2 * N - 1); ++i) {
    if (a[i] != 0) continue;
    while (used[j]) ++j;
    a[i] = j++;
  }

  cout << "Yes" << endl;
  for (int i = 0; i < (int)(2 * N - 1); ++i) cout << a[i] << endl;
  return 0;
}


Measured memory_bytes: 2304
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int m=scan.nextInt();
        int l=scan.nextInt();
        long outPint;
        int[][] matrixa=new int[n][m];
        int[][] matrixb=new int[m][l];
        
        for(int i=0; i<n; i++)
            for(int j=0; j<m; j++)
                matrixa[i][j]=scan.nextInt();
        
        for(int i=0; i<m; i++)
            for(int j=0; j<l; j++)
                matrixb[i][j]=scan.nextInt();
        
        for(int i=0; i<n; i++){
            for(int j=0; j<l; j++){
                outPint=0;
                for(int k=0; k<m; k++){
                    outPint+=matrixa[i][k]*matrixb[k][j];
                }
                System.out.print(outPint);
                if(j!=l-1)
                    System.out.print(" ");
            }
            System.out.println();
        }    
        
    }
}


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

typedef pair<int,int> ii;
typedef pair<int, ii> II;
#define fi first
#define se second

const int N = 550;

int A, B;
int n, S, T;
int nx[N][N], ny[N][N];
int a[N][N];

bool check(int x, int y, int ni, int nj) {
	int rem = a[x][y] - ni * x - nj * y;
	if (rem < 0) return false;

	for (int i = 1; i <= A; ++i) for (int j = 1; j <= B; ++j) {
		if (rem + ni * i + nj * j < a[i][j]) return false;
	}

	return true;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> A >> B;
	for (int i = 1; i <= A; ++i) {
		for (int j = 1; j <= B; ++j) cin >> a[i][j], nx[i][j] = -1, ny[i][j] = -1;
	}	

	for (int i = 1; i <= A; ++i) {
		for (int j = 1; j <= B; ++j) {
			for (int ni = 0; ni <= 100; ++ni) for (int nj = 0; nj <= 100; ++nj) {
				if (check(i, j, ni, nj)) {
					nx[i][j] = ni, ny[i][j] = nj; break;
				}
			}
		}
	}

	S = ++n;
	T = ++n;
	vector<II> X, Y, edges;

	for (int i = 1; i <= A; ++i) {
		for (int j = 1; j <= B; ++j) {
			if (nx[i][j] == -1 || ny[i][j] == -1) return cout << "Impossible\n", 0;
			int rem = a[i][j] - nx[i][j] * i - ny[i][j] * j;

			int lastS = S;
			for (int k = 0; k < min(nx[i][j], (int)X.size()); ++k) {
				edges.push_back(X[k]);
				lastS = X[k].se.se;
			}
			nx[i][j] -= X.size();
			while (nx[i][j]-- > 0) {
				++n; X.push_back(II(-1, ii(lastS, n))); lastS = n;
				edges.push_back(X.back());
			}


			int lastT = T;
			for (int k = 0; k < min(ny[i][j], (int)Y.size()); ++k) {
				edges.push_back(Y[k]);
				lastT = Y[k].se.fi;
			}
			ny[i][j] -= Y.size();
			while (ny[i][j]-- > 0) {
				++n; Y.push_back(II(-2, ii(n, lastT))); lastT = n;
				edges.push_back(Y.back());
			}

			edges.push_back(II(rem, ii(lastS, lastT)));
		}
	}

	assert(n <= 300);

	sort(edges.begin(), edges.end());
	edges.erase(unique(edges.begin(), edges.end()), edges.end());
	cout << "Possible\n";
	cout << n << ' ' << edges.size() << endl;
	for (auto e : edges) {
		cout << e.se.fi << ' ' << e.se.se << ' ';
		if (e.fi < 0) cout << (e.fi == -1 ? 'X' : 'Y') << endl;
		else cout << e.fi << endl;
	}
	cout << S << ' ' << T << endl;
}

Measured memory_bytes: 384
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	n := readInt()
	a := make([][]int, 2)
	a[0] = make([]int, n)
	a[1] = make([]int, n)
	for i := range a[0] {
		a[0][i] = readInt()
	}
	for i := range a[1] {
		a[1][i] = readInt()
	}

	sum0 := cumulativeSum(a[0])
	sum1 := cumulativeSum(a[1])

	var ans int64
	for i := 0; i < n; i++ {
		ans = maxInt64(ans, sum0(0, i+1)+sum1(i, n))
	}
	println(ans)

}

// -----------------------------------------------------------------------------

// cumlativeSum returns a function func(i, j int) int64 which returns
// the sum of a[i:j]
func cumulativeSum(a []int) func(int, int) int64 {
	n := len(a)
	b := make([]int64, n+1)
	for i := 0; i < n; i++ {
		b[i+1] = int64(a[i]) + b[i]
	}
	return func(i, j int) int64 {
		return b[j] - b[i]
	}
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main()
{
  int n;
  cin >> n;
  
  int p[n];
  rep(i,n) cin >> p[i];
  
  int min = 1e9;
  int ans = 0;
  for(int i = 0; i < n; i++){
    if(p[i] <= min){
      min = p[i];
      ans++;
    }
  }
  
  cout << ans << endl;
      
}

Measured memory_bytes: 4416
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <utility>
using namespace std;
#define INF 100000000
#define ll long long
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define rep(i, n) for(int (i)=1; (i)<=(n); (i)++)
typedef pair<int, int> P;

int update(int N){
    if(N == 0){
        return 0;
    }else if(N < 4){
        return -1;
    }else{
        return max(update(N-4), update(N-7));
    }
}

int main(){
    int N;
    cin >> N;
    int t;
    t = update(N);
    if(t == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

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

	double sum = 0;

	for (int i=0; i<N; ++i)
	{
		double num;
		string S;
		cin >>  num >> S;
		if (S == "BTC")
		{
			sum += 380000 * num;
		} else {
			sum += num;
		}
	}
	cout << sum << endl;
	
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
#include <functional>
using namespace std;
typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA cerr << "AAAAA" << endl
#define debug_ cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    cout << #v << endl;                \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;
#define debug_vec2(v)                         \
    cout << #v << endl;                       \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cout << v[i][j] << " ";           \
        }                                     \
        cout << endl;                         \
    }

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

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

template <typename T>
void quit(T a)
{
    cout << a << endl;
    exit(0);
}

using Graph = vector<vector<int>>;
using P = pair<int, int>;
using P1 = pair<int, pair<int, int>>; // クラスカル法とかで、{cost, {from, to}}的に使う。
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double pi = acos(-1);

int main()
{
    int n;
    cin >> n;
    vector<pair<string, int>> mp(4);
    mp[0].fi = "AC";
    mp[0].se = 0;
    mp[1].fi = "WA";
    mp[1].se = 0;
    mp[2].fi = "TLE";
    mp[2].se = 0;
    mp[3].fi = "RE";
    mp[3].se = 0;
    for (int i = 0; i < n; i++)
    {
        string s;
        cin >> s;
        if (s == "AC")
        {
            mp[0].se++;
        }
        else if (s == "WA")
        {
            mp[1].se++;
        }
        else if (s == "TLE")
        {
            mp[2].se++;
        }
        else
        {
            mp[3].se++;
        }
    }
    for (int i = 0; i < 4; i++)
    {
        cout << mp[i].fi << " x " << mp[i].se << endl;
    }

    return 0;
}


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

int main() {
  string N;
  cin >> N;
  if (N.at(0) == N.at(1) && N.at(1) == N.at(2)) {
    cout << "Yes" << endl;
  }
  else if (N.at(3) == N.at(2) && N.at(1) == N.at(2)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
open Str
let () =
  let n = read_int () in
  let rec loop n t h = match n with
      0 -> Printf.printf "%d %d\n" t h
    | i -> Scanf.scanf "%s %s\n" (fun x y -> if x > y then loop (n-1) (t+3) h
                                             else if x = y then loop (n-1) (t+1) (h+1)
                                             else loop (n-1) t (h+3)
             )
  in loop n 0 0
;;


Measured memory_bytes: 2796
from math import *

a, b, c = map(int, input().split())
f = - 1
if c >= 90:
    c = 180 - c
    f = 1
c = radians(c)
h = b * sin(c)
s = a * h / 2
l = a + b + sqrt(pow(a + f * sqrt(b * b - h * h), 2) + h * h)
print(s)
print(l)
print(h)



Measured memory_bytes: 5692
//master
import java.io.*;
import java.util.*;
public class Main {
    static int[][] memo;
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        long a = sc.nextLong();
        long b = sc.nextLong();
        long n = sc.nextLong();
        long k = Math.min(b-1,n);
        long ans = a*k/b - a*(k/b);
        p(ans);
}

    public static <T> void p(T message) {
        System.out.println(message);
    }

    public static <T> void pe(T message) {
        System.err.println(message);
    }

    public static <T> void pp(T message) {
        System.out.print(message);
    }
    
}
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
 
    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }
 
    private boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
 
    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }
 
    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
 
    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
 
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
 
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 25348
import sys

def comb(n, r, mod=None):
    if r == 0 or r == n:
        return 1
    r = min([r, n-r])
    x, y = 1, 1
    ans = 1
    for i in range(1, r+1):
        if mod:
            x *= n+1-i
            y *= i
            x %= mod
            y %= mod
        else:
            ans *= n+1-i
            ans //= i
    ans = x*pow(y, mod-2, mod)%mod if mod else ans
    return ans


def main():
    h, w, k = map(int, input().split())
    mod = pow(10,9)+7
    
    if w == 1:
        print(1)
        sys.exit()
    
    comb_list = [[0]*11 for _ in range(11)]
    for i in range(11):
        for j in range(11):
            if i >= j:
                comb_list[i][j] = comb(i, j)
    
    key_list = [1]*10
    for i in range(1, 10):
        key = 0
        for j in range(1, 10):
            if i < j*2-1:
                break
            key += comb_list[i-j+1][j]
        key_list[i] += key
    
    
    dp = [[0]*w for _ in range(h)]
    for i in range(h):
        if i == 0:
            dp[0][0] = key_list[w-2]
            dp[0][1] = key_list[w-3] if w != 2 else 1
            continue
        if w == 2:
            dp[i][0] = (dp[i-1][0]+dp[i-1][1])%mod
            dp[i][1] = (dp[i-1][0]+dp[i-1][1])%mod
            continue
            
        for j in range(w):
            if j == 0:
                dp[i][j] = (dp[i-1][j]*key_list[w-2]+dp[i-1][j+1]*key_list[w-3])%mod
            elif j == w-1:
                dp[i][j] = (dp[i-1][j]*key_list[w-2]+dp[i-1][j-1]*key_list[w-3])%mod
            else:
                dp[i][j] = 0
                dp[i][j] += (dp[i-1][j-1]*key_list[max([0, j-2])]*key_list[max([0, w-2-j])])%mod
                dp[i][j] += (dp[i-1][j]*key_list[max([0, j-1])]*key_list[max([0, w-2-j])])%mod
                dp[i][j] += (dp[i-1][j+1]*key_list[max([0, j-1])]*key_list[max([0, w-3-j])])%mod
                dp[i][j] %= mod
    print(dp[h-1][k-1])
                                                                           

if __name__ == "__main__":
    main()

Measured memory_bytes: 3192
#include <bits/stdc++.h>
#define endl '\n';

typedef long long ll;

using namespace std;

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

    int n;

    cin >> n;

    cout << (n * 800) - ((n / 15) * 200) << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

    private void run() {
        Scanner scanner = new Scanner(System.in);
        String a = scanner.next();
        if(a.equals("AAA") || a.equals("BBB")) {
            System.out.println("No");
        }else {
            System.out.println("Yes");
        }

    }
}


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

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define EPS 1e-8
#define DEB 0


char field[512];
int memo[2][512];
class state{
  public:
	int h,id;
	state(int _h, int _i){
		h = _h;
		id = _i;
	}
};

int main(){
	int w,h;
	
	while(scanf(" %d%d ",&h,&w),w|h){
		memset(memo,0,sizeof(memo));
		int maxarea = 0;
		rep(i,h){
			int cur = i%2;
			int next = (i+1)%2;
			scanf("%s",field);
			if( i==0 ){
				rep(j,w){
					memo[next][j] = (field[j]=='.' ? 1 : 0);
				}
			}else{
				rep(j,w){
					memo[next][j] = (field[j]=='.' ? memo[cur][j]+1 : 0);
				}
			}
			memo[next][w] = 0;

#if DEB
			rep(j,w){
				printf("%2d ",memo[next][j]);
			}
			puts("");
#endif			

			stack<state> st;
			rep(j,w+1){
				int nh = memo[next][j];
				if( st.empty() ){
					st.push(state(nh,j));
				}else if( st.top().h < nh ){
					st.push(state(nh,j));
				}else if( st.top().h > nh ){
					int prev = j-1;
					int tmp;
					while( !st.empty() && st.top().h >= nh ){
#if DEB
						printf("maxarea:%d  (%d-%d+1)*%d\n",maxarea,prev,st.top().id,st.top().h);
#endif						
						maxarea = max(maxarea, (prev-st.top().id+1)*st.top().h);
						tmp = st.top().id;
						st.pop();
					}
					st.push(state(nh,tmp));
				}
			}
		}

		printf("%d\n",maxarea);
	}
	
	return 0;
}

Measured memory_bytes: 0
import java.io.*;
import java.math.*;
import java.util.*;
public class Main { 

	public static void main(String[] args) { 
		Scanner input = new Scanner(System.in);
		int N = input.nextInt();
		ArrayList<Integer> primes = new ArrayList<Integer>();
		long ans = 1;
		long mod = (long)(1e9+7);
		int[] cnts = new int[10001];
		for (int i = 2; i <= N; i++) {
			if (Prime(i)) primes.add(i);
		}
		for (int i = 1; i <= N; i++) { //i=factor
			for (int j = 0; j < primes.size(); j++) {
				int curfactor = i;
				while (curfactor%primes.get(j)==0) {
					cnts[primes.get(j)]++;
					curfactor/=primes.get(j);
				}
				if (curfactor==1) break;
			}
		}
		for (int i = 1; i <= N; i++) {
			int curchoices = cnts[i]+1;
			ans*=curchoices;
			ans%=mod;
		}
		System.out.println(ans);
	}
	public static boolean Prime(int N) {
		for (int i = 2; i*i<=N; i++) {
			if (N%i==0) return false;
		}
		return true;
	}
}

Measured memory_bytes: 23764
L, R = map(int, input().split())

flag3 = flag673 = False
if R % 3 == 0 or L % 3 == 0:
    flag3 = True
for i in range((L // 673) * 673, 2 * 10 ** 9, 673):
    if L <= i and i <= R:
        flag673 = True
        break

ans = 0
if (flag3 and flag673) is False:
    ans = 10**9
    if R - L > 2100:
        R = L + 2100
    for i in range(L, R + 1):
        for j in range(i + 1, R + 1):
            if (i * j) % 2019 < ans:
                ans = (i * j) % 2019
print(ans)


Measured memory_bytes: 3188
#include <stdio.h>
#include <limits.h>

/* 命令 */
int STRAIGHT = 0;
int RIGHT = 1; /* 右に90度回転し直進 */
int BACK = 2; /* 右に180度回転し直進 */
int LEFT = 3; /* 右に270度回転し直進 */
int HALT = 4;
int OUT = 5; /* 盤面外 */
/* 各方向を向いているときの移動ベクトル (dx,dy) (北, 東, 南, 西) */
int MOVEMENT[4][2] = { {0, -1}, {1, 0}, {0, 1}, {-1, 0} };
/* 入力された条件 */
int w, h, s[30][30]; /* 盤面 */
int c[4]; /* 定められたコスト */

/* 指定された座標のブロックを返す */
int getCell(int x, int y) {
	if (x < 0 || x >= w || y < 0 || y >= h) return OUT;
	return s[y][x];
}

/* 幅優先探索 */
int memo[30][30][4]; /* 探索のメモ (あるマスにある向きで到達するまでの最小コスト) */
int UNREACHED = INT_MAX;
typedef struct { int cost; int x; int y; int angle; } Log; /* 探索状態 */

/* FIFOキュー */
typedef Log Data;
Data queue[2000]; int queue_size = 2000; int queue_head; int queue_length;
void initqueue() {
	queue_length = 0;
}
void enqueue(Data d) {
	queue[(queue_head + queue_length) % queue_size] = d;
	queue_length++;
}
Data dequeue() {
	Data d = queue[queue_head];
	queue_head = (queue_head + 1) % queue_size;
	queue_length--;
	return d;
}

/* 幅優先探索をしてゴールのマスに到達するまでに掛かったコストを返す */
int search(Log l) {
	int min = UNREACHED;
	int i;
	/* この試行が現在いるブロックまでの最短経路か確認する */
	if (l.cost > memo[l.y][l.x][l.angle]) return UNREACHED;

	/* 次の動作 */
	for (i = 0; i < 4; i++) {
		/* 次の動作を行った場合の状態を作る */
		Log next;
		next.angle = (l.angle + i) % 4;
		next.x = l.x + MOVEMENT[next.angle][0];
		next.y = l.y + MOVEMENT[next.angle][1];
		next.cost = l.cost;
		if (i != getCell(l.x, l.y)) next.cost += c[i]; /* マスの命令に従わない場合のみコストが掛かる */

		int cell = getCell(next.x, next.y); /* 次に踏むマス */

		if (/* cell == HALT && */ next.x == w - 1 && next.y == h - 1) {
			/* ゴールに到達 */
			if (next.cost < min) min = next.cost;
		} else if (cell == OUT) {
			/* 盤面外に前進し失格 */
			continue;
		} else {
			/* 次に探索する状態をキューに入れる */
			if (next.cost < memo[next.y][next.x][next.angle]) {
				memo[next.y][next.x][next.angle] = next.cost;
				enqueue(next);
			}
		}
	}

	return min;
}

int main(void) {
	int min, i, j, k;

	/* データセット毎の処理 */
	while (scanf("%d%d", &w, &h) == 2 && w > 0 && h > 0) {
		/* 各マスに割り当てられた命令を読み込む */
		for (i = 0; i < h; i++) for (j = 0; j < w; j++) {
			scanf("%d", &s[i][j]);

			/* メモを初期化する */
			for (k = 0; k < 4; k++) memo[i][j][k] = UNREACHED;
		}
		/* コストを読み込む */
		for (i = 0; i < 4; i++) scanf("%d", &c[i]);

		/* 探索の始点をキューに入れる */
		Log l = {0, 0, 0, 1}; /* 北西隅のマスで東向き */
		enqueue(l);

		/* 幅優先探索する */
		min = UNREACHED;
		while (queue_length > 0) {
			int cost = search(dequeue());
			if (cost < min) min = cost;
		}

		/* 結果を出力する */
		printf("%d\n", min);
	}

	return 0;
}

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

using i32 = std::int_fast32_t;
using i64 = std::int_fast64_t;
template <typename T> constexpr T inf = numeric_limits<T>::has_infinity ? numeric_limits<T>::infinity() : numeric_limits<T>::max() / 4;

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (int i = start, i##_len = stop; i < i##_len; ++i)
#define RREP(i, n) for (int i = n; i-- > 0;)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COMP(key) [](const auto& a, const auto& b) { return a.key < b.key; }

template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& a) { return is >> a.first >> a.second; }
template<typename T> istream& operator>>(istream& is, vector<T>& a) { for (T& x : a) is >> x; return is; }

void LOG(const int& x) { cerr << x << "\n"; }
template<typename T> void LOG(const vector<T>& a) { for (const T& x : a) cerr << x << " "; cerr << "\n"; }
template<typename T, std::size_t S> void LOG(const T (&a)[S]) { REP(i, S) cerr << a[i] << " "; cerr << "\n"; }
template<typename T, std::size_t S, std::size_t R> void LOG(const T (&a)[S][R]) { REP(i, S) { REP(j, R) cerr << a[i][j] << " "; cerr << "\n"; } }

i64 ceil(i64 a, i64 b) { return (a - 1) / b + 1; }
i64 gcd(i64 a, i64 b) { while (b != 0) { i64 t = b; b = a % b; a = t; } return a; }
i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
i64 gcd(const vector<i64>& v) { return accumulate(ALL(v), 1LL, static_cast<i64(*)(i64, i64)>(gcd)); }
i64 lcm(const vector<i64>& v) { return v.empty() ? 0LL : accumulate(v.begin() + 1, v.end(), v[0], static_cast<i64(*)(i64, i64)>(lcm)); }
i64 pow(i64 x, i64 y, i64 z) { i64 a = 1; while (y > 0) { if (y & 1) a = a * x % z; x = x * x % z; y /= 2; } return a; }
i64 inv(i64 x, i64 m) { return pow(x, m - 2, m); }

struct InitCpp { InitCpp() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } initCpp;

// dp[s] = s が開けられる最小値
i64 dp[1 << 12];
signed main() {
  i64 N, M;
  cin >> N >> M;
  vector<i64> a(M), b(M);
  vector<i64> c(M);
  REP(k, 1 << N) {
    dp[k] = inf<i64>;
  }
  dp[0] = 0;
  REP(i, M) {
    cin >> a[i] >> b[i];
    REP(_, b[i]) {
      i64 k;
      cin >> k;
      c[i] |= 1 << (k - 1);
    }
    REP(k, 1 << N) {
      dp[k | c[i]] = min(dp[k | c[i]], dp[k] + a[i]);
    }
  }
  i64 ans = dp[(1 << N) - 1];
  cout << (ans == inf<i64> ? -1 : ans) << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdlib>
#include <vector>
using namespace std;
int main()
{
    vector<vector <int>> a;
    int n, q, t, x, m, query;
    cin >> n >> q;
    a.resize(n);
    for (int i=0; i<q; ++i){
        cin >> query;
        switch(query){
            case 0:
                cin >> t >> x;
                a[t].push_back(x);
                break;
            case 1:
                cin >> t;
                if(!a[t].empty()){
                    m = a[t].size();
                    for (int i=0; i<m; ++i){
                        if(i == m-1){
                            cout << a[t][i] << endl;
                        }
                        else {
                            cout << a[t][i] << " ";
                        }
                    }
                }
                else {
                    cout << endl;
                }
                break;
            case 2:
                cin >> t;
                if(!a[t].empty()){
                    a[t].clear();
                }
                break;
        }
    }
}


Measured memory_bytes: 5864
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
#define dame { printf("No\n"); return 0;}
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)


signed main(){
    int a,b,k;
    cin >> a >> b >>k;
    int A[1000] = {};
    int id = 0;
    FOR(i,1,min(a,b) +1){
        if( a%i == 0 and b %i ==0){
            A[id] = i;
            id ++;
        }
    }
    cout << A[id - k ] << endl;

}


Measured memory_bytes: 256
void main() {
  problem();
}

void problem() {
  const N = scan!int;
  const M = scan!int;
  const X = scan!int;
  auto C = new int[N];
  int[][] A;

  foreach(i; 0..N) {
    C[i] = scan!int;
    A ~= scan!int(M);
  }

  int[] bitNums = 12.iota.map!(x => 2.pow(x)).array;

  void solve() {
    int answer = int.max;
    foreach(combinationNumber; 0..2.pow(N)) {
      auto comb = bitNums.map!(b => (combinationNumber & b) == b);

      int price;
      auto manabi = new int[M];
      foreach(i; 0..N) {
        if (comb[i]) continue;

        price += C[i];
        foreach(a; 0..M) manabi[a] += A[i][a];
      }

      if (manabi.any!(m => m < X)) continue;
      if (answer > price) answer = price;
    }

    writeln(answer == int.max ? -1 : answer);
  }

  solve();
}

// ----------------------------------------------

import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons, std.numeric;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; }
T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
void deb(T ...)(T t){ debug writeln(t); }
alias Point = Tuple!(long, "x", long, "y");

// -----------------------------------------------


Measured memory_bytes: 2768
loop do
  n, k = gets.split.map(&:to_i)
  break if n == 0
  a = []
  n.times { a << gets.to_i }
  # puts
  max = a[0..k-1].inject(:+)
  before = max
  1.upto(n - k) do |i|
    val = before - a[i - 1] + a[i + k - 1]
    before = val
    # p [a, i, k, val].to_s
    max = val if val > max
  end

  puts max
end

Measured memory_bytes: 9844
import collections
n = int(input())
a = list(map(int, input().split()))

c_0 = collections.Counter(a[::2])
c_1 = collections.Counter(a[1::2])

if len(c_0.most_common()) == 1 and len(c_1.most_common()) == 1:
  if c_0.most_common()[0][0] == c_1.most_common()[0][0]:
    print(n // 2)
  else:
    print(0)
elif len(c_0.most_common()) == 1:
  if c_0.most_common()[0][0] == c_1.most_common()[0][0]:
    print(n // 2 - c_1.most_common()[1][1])
  else:
    print(n // 2 - c_1.most_common()[0][1])
elif len(c_1.most_common()) == 1:
  if c_0.most_common()[0][0] == c_1.most_common()[0][0]:
    print(n // 2 - c_0.most_common()[1][1])
  else:
    print(n // 2 - c_0.most_common()[0][1])
elif c_0.most_common()[0][0] == c_1.most_common()[0][0]:
  if c_0.most_common()[0][1] > c_1.most_common()[0][1]:
    print(n - c_0.most_common()[0][1] - c_1.most_common()[1][1])
  elif c_0.most_common()[0][1] < c_1.most_common()[0][1]:
    print(n - c_0.most_common()[1][1] - c_1.most_common()[0][1])
  else:
    print(n - c_0.most_common()[0][1] - max(c_0.most_common()[1][1],c_1.most_common()[1][1]))
else:
  print(n - c_0.most_common()[0][1] - c_1.most_common()[0][1])

Measured memory_bytes: 18656