akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <algorithm>
#include <cstddef>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <deque>
#include <list>
#if __cplusplus >= 201103L
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
//add #define GRAPH for graph theory problems
#define mp make_pair
#define pb push_back
#ifdef GRAPH
typedef pair <int, int> Edge;
#define v first
#define w second
#endif
#ifdef GEOMETRY
typedef pair <int, int> Point;
#define x first
#define y second
#endif
#ifdef FILEIO
#define FILEOPEN(in, out) freopen(in, "r", stdin);freopen(out, "w", stdout);
#endif
using LL = long long;
using ULL = unsigned long long;
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define rep(i, n) for (int (i) = 0; (i) < n; (i)++)
#define until(x) while (!x)
#define fail(s) assert(!s)
const int INF = 0x3f3f3f3f;
const int EPS = 1e-6;
const int MAXN = 410;
LL prefix[MAXN], dp[MAXN][MAXN], n, a[MAXN];
int main()
{
	cin >> n;
	memset(dp, INF, sizeof(dp));
	memset(prefix, 0, sizeof(prefix));
	for (int i = 1; i <= n; i++)cin >> a[i];
	for (int i = 1; i <= n; i++)prefix[i] = prefix[i - 1] + a[i];
	for (int i = 1; i <= n; i++)dp[i][i] = 0;
	for (int i = 2; i <= n; i++) {
		for (int l = 1; l <= n - i + 1; l++) {
			int r = l + i - 1;
			if (l > r)continue;
			for (int k = l; k < r; k++) 
				dp[l][r] = min(dp[l][r], dp[l][k] + dp[k + 1][r]);
			dp[l][r] += prefix[r] - prefix[l - 1];
		}
	}
	cout << dp[1][n] << endl;
	return 0;
}


Measured memory_bytes: 1536
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

// Manages Union-Find Forest.
class UnionFindForest {
  std::vector<int> parent_;
  std::vector<int> rank_;
  std::vector<int> size_;

public:
  // Initialize forest.
  // parent_[i]=i, rank_[i]=0, size_[i]=1.
  UnionFindForest(const int &n);
  // Get the number of the root of the node q.
  int Root(const int &q);
  // Return true if the roots of x and y is same.
  bool IsSame(const int &x, const int &y);
  // Unite the tree x and tree y.
  void Unite(int x, int y);
  // Get the number of nodes which are the same group as node q.
  int Size(const int &q);
};
UnionFindForest::UnionFindForest(const int &n) {
  parent_.resize(n);
  rank_.resize(n);
  size_.resize(n);
  for (int i = 0; i < n; i++) {
    parent_[i] = i;
    rank_[i]   = 0;
    size_[i]   = 1;
  }
}
int UnionFindForest::Size(const int &q) {
  return size_[Root(q)];
}

int UnionFindForest::Root(const int &q) {
  if (parent_[q] == q) {
    return q;
  } else {
    return parent_[q] = Root(parent_[q]);
  }
}

bool UnionFindForest::IsSame(const int &x, const int &y) {
  return Root(x) == Root(y);
}

void UnionFindForest::Unite(int x, int y) {
  x = Root(x);
  y = Root(y);
  if (x == y) return;
  if (rank_[x] < rank_[y]) {
    parent_[x] = y;
    size_[y] += size_[x];
    size_[x] = 0;

  } else {
    parent_[y] = x;
    size_[x] += size_[y];
    size_[y] = 0;
    if (rank_[x] == rank_[y]) rank_[x]++;
  }
}

using namespace std;

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int n,m;
  cin>>n>>m;
  vector<pair<int,int>> a(n);
  for(int i = 0; i < n; ++i){
    int v;
    cin>>v;
    a[i]=make_pair(v,i);
  }
  UnionFindForest uf(n);
  for(int i = 0; i < m; ++i){
    int x,y;
    cin>>x>>y;
    uf.Unite(x,y);

  }
  vector<pair<int,int>> cost[100000];
  for(int i=0;i<n;i++){
    cost[uf.Root(i)].push_back(a[i]);
  }
  for(int i=0;i<n;i++){
    std::sort(cost[i].begin(), cost[i].end());
  }
  vector<int> first,second;
  vector<bool> used(n);
  int count=0;
  int64_t result=0;
  for(int i=0;i<n&&count<2*(n-m-1);i++){
    if(cost[i].empty()) continue;

    result+=(int64_t)cost[i][0].first;
    used[cost[i][0].second]=true;
    count++;

  }
  vector<int> unused_cost;
  for(int i=0;i<n;i++){
    if(!used[i]){
      unused_cost.push_back(a[i].first);
    }
  }
  std::sort(unused_cost.begin(), unused_cost.end());
  int itr=0;
  for(;count<2*(n-m-1);count++){
    if(itr>=unused_cost.size()){
      cout<<"Impossible"<<endl;
      return 0;
    }
    result+=(int64_t)unused_cost[itr];
    itr++;

  }
  cout<<result<<endl;







  return 0;
}

Measured memory_bytes: 7680
#include<stdio.h>
const int MAX_V = 100000;
int main(){
	int prime[MAX_V+1];
	int i, j, v, n;
	for(i = 2; i <= MAX_V; i++){
		prime[i] = 1;
	}
	for(i = 2; i * i <= MAX_V; i++){ 
		if(prime[i]){
			for(j = 2 * i; j <= MAX_V; j += i){
				prime[j] = 0;
			}
		}
	}
	for(;;){
		scanf("%d", &n);
		if(n == 0) break;
		for(i = n - 2; i >= 2; i--){
			if(prime[i] == 1 && prime[i + 2] == 1){
				printf("%d %d\n", i, i + 2);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 2084
#![allow(unused_imports)]
#![cfg_attr(feature = "cargo-clippy", allow(redundant_field_names))]

use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::{self, BufWriter, Read, Write};
use std::ops::{Add, Div, Mul, Sub};
use std::str::{self, FromStr};
use std::{cmp, fmt};

fn main() {
    let (d, n): (u32, u32) = {
        let mut sc = InputScanOnce::new(io::stdin(), 1024);
        (sc.next(), sc.next())
    };
    let r = match (d, n) {
        (0, 100) => 101,
        (1, 100) => 10100,
        (2, 100) => 1010000,
        (0, n) => n,
        (1, n) => 100 * n,
        (2, n) => 10000 * n,
        _ => unreachable!(),
    };
    println!("{}", r);
}

struct InputScanOnce {
    buf: Vec<u8>,
    pos: usize,
}

#[allow(dead_code)]
impl InputScanOnce {
    fn new<R: Read>(mut reader: R, estimated: usize) -> Self {
        let mut buf = Vec::with_capacity(estimated);
        let _ = io::copy(&mut reader, &mut buf).unwrap();
        InputScanOnce { buf: buf, pos: 0 }
    }

    #[inline]
    fn next<T: FromStr>(&mut self) -> T
    where
        T::Err: fmt::Debug,
    {
        let mut start = None;
        loop {
            match (self.buf[self.pos], start.is_some()) {
                (b' ', true) | (b'\n', true) => break,
                (_, true) | (b' ', false) | (b'\n', false) => self.pos += 1,
                (_, false) => start = Some(self.pos),
            }
        }
        let target = &self.buf[start.unwrap()..self.pos];
        unsafe { str::from_utf8_unchecked(target) }.parse().unwrap()
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T>
    where
        T::Err: fmt::Debug,
    {
        (0..n).map(|_| self.next()).collect()
    }

    fn pairs<T1: FromStr, T2: FromStr>(&mut self, n: usize) -> Vec<(T1, T2)>
    where
        T1::Err: fmt::Debug,
        T2::Err: fmt::Debug,
    {
        (0..n).map(|_| (self.next(), self.next())).collect()
    }

    fn trios<T1: FromStr, T2: FromStr, T3: FromStr>(&mut self, n: usize) -> Vec<(T1, T2, T3)>
    where
        T1::Err: fmt::Debug,
        T2::Err: fmt::Debug,
        T3::Err: fmt::Debug,
    {
        (0..n)
            .map(|_| (self.next(), self.next(), self.next()))
            .collect()
    }

    fn mat<T: FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>>
    where
        T::Err: fmt::Debug,
    {
        (0..m).map(|_| self.vec(n)).collect()
    }

    fn strings_as_mat<T, F: FnMut(u8) -> T>(&mut self, h: usize, mut f: F) -> Vec<Vec<T>> {
        (0..h)
            .map(|_| {
                let l = self.next::<String>();
                l.as_bytes().iter().cloned().map(&mut f).collect()
            })
            .collect()
    }
}


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<ll> vll;

#define PI (2*acos(0.0))
#define eps 1e-9
#define pb push_back
#define endl "\n"
#define watch(x) cout << (#x) << " is " << (x) << endl;
#define show(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi] << " "; cout << endl;
#define showpair(v) for(int fi = 0; fi < v.size(); fi++) cout << v[fi].first << " " << v[fi].second << endl;
#define ff first
#define ss second
#define fu cout << "lol" << endl;
#define precision(n) cout << fixed << setprecision(n);
#define lb lower_bound
#define up upper_bound
#define vscan for(i = 0;i<n;i++){cin>>in; v.pb(in);}
#define all(a) a.begin(), a.end()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mem(a,val) memset(a,val,sizeof(a))
#define loop(i,n) for(i = 0; i < n; i++)
#define TC() ull T; cin>>T; while(T--)
#define IN(x) {scanf("%d",&x);}
#define LL(x) {scanf("%lld",&x);}
#define CC(x) {scanf("%c",&x);}
#define pfl(x) printf("%d\n",x)
#define pfll(x) printf("%lld\n",x)
#define newl puts("")
#define space printf(" ")
#define MOD 1000000007
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL);

int main()
{
    int i = 0, j = 0, cs = 0, in;
    int n; cin>>n;
    vi v(n);
    for(i = 0; i < n; i++) cin>>v[i];
    sort(all(v), greater<int>());
    ll ans = v[0];
    int cnt = 2;
    i = 1;
    while(cnt < n){
        if(cnt + 1 == n){
            ans += v[i], cnt++;
            continue;
        }
        ans += 2*v[i], cnt += 2, i++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4048
import copy
# from math import gcd


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

def lcm(a, b):
    return (a // gcd(a, b)) * b
def main():
    n, m = map(int, input().split())
    A = set([int(x) for x in input().split()])
    a_lcm = 1
    for a in A:
        a_lcm = lcm(a_lcm, a)
        # mがlcmの半分よりも小さかったら0
        if (a_lcm / 2) > m:
            print(0)
            exit()
    for a in A:
        if (a_lcm / 2) % a == 0:
            print(0)
            exit()
    # # あとは定数倍の数調べて終わり
    ans = int((m - (a_lcm / 2)) // a_lcm) + 1
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 20896
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define sc(x) scanf("%lld",&x);
#define fi first
#define se second
#define endl '\n'
#define P pair<int,int>
priority_queue<int> pq;
signed main()
{
    int x;
    int n,m;
    sc(n)sc(m)
    int ans = 0;
    for(int i=0;i<n;i++){
        sc(x)
        ans += x;
        pq.push(x);
    }
    int k = m;
    while(!pq.empty()){
        if(k == 0){
            puts("Yes");
            return 0;
        }
        if(pq.top()*4*m >= ans){
            k--;pq.pop();
        }else{
            puts("No");
            return 0;
        }
    }
    if(k == 0){
            puts("Yes");
            return 0;
        }

}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <sstream>
#include <fstream>
#include <numeric>

#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)

using namespace std;
typedef long long unsigned int ll;

int main() {
  int n;
  cin >> n;
  vector<int> vs1(100005);
  vector<int> vs2(100005);
  int v;
  for (int i = 0; i < n; ++i) {
    cin >> v;
    if (i % 2 == 0) {
      vs1[v - 1] += 1;
    }
    else {
      vs2[v - 1] += 1;
    }
  }


  vector<size_t> indices1(vs1.size());
  vector<size_t> indices2(vs2.size());

  iota(indices1.begin(), indices1.end(), 0);
  iota(indices2.begin(), indices2.end(), 0);  

  sort(indices1.begin(), indices1.end(), [&vs1](size_t i1, size_t i2) {
					   return vs1[i1] > vs1[i2];
					 });
  sort(indices2.begin(), indices2.end(), [&vs2](size_t i1, size_t i2) {
					   return vs2[i1] > vs2[i2];
					 });

  int ans;
  if (indices1[0] == indices2[0]) {
    int ans1 = 0, ans2 = 0;
    ans1 = (n / 2 - vs1[indices1[0]]) + (n / 2 - vs2[indices2[1]]);
    ans2 = (n / 2 - vs1[indices1[1]]) + (n / 2 - vs2[indices2[0]]);
    ans = min(ans1, ans2);
  }
  else {
    ans = (n / 2 - vs1[indices1[0]]) + (n / 2 - vs2[indices2[0]]);
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2560
// Problem : E - Count Median
// Contest : AtCoder - AtCoder Beginner Contest 169
// URL : https://atcoder.jp/contests/abc169/tasks/abc169_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db long double
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define mi map<int,int>
#define ml map<ll,ll>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define MAX 4294967295
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MAXN 15000005
#define inf 1e10
#define PI acos(-1.0)
#define int long long

void solve(){
    int n;
    cin>>n;
    vi a(n), b(n);
    int ans;
    for(int i=0;i<n;i++) cin>>a[i]>>b[i];
    sort(all(a)), sort(all(b));
    if(n % 2 == 0){
        int l = a[n/2] + a[n/2-1];
        int r = b[n/2] + b[n/2-1];
        ans = r-l+1;
    } else {
        int l = a[(n-1)/2];
        int r = b[(n-1)/2];
        ans = r-l+1;
    }
    cout<<ans<<endl;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int t;
    //cin>>t;
    t = 1;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 6364
from collections import defaultdict
from fractions import gcd
N, M = map(int, input().split())
S = input()
T = input()
L = N * M // gcd(N, M)
ds = L // N
dt = L // M
dict_s = defaultdict(str)
dict_t = defaultdict(str)

for i in range(N):
  dict_s[i*ds] = S[i]
  
for i in range(M):
  dict_t[i*dt] = T[i]

for key in dict_s.keys():
  if key in dict_t.keys():
    if dict_s[key] != dict_t[key]:
      print(-1)
      exit()
print(L)

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

int main(){
	int n;
	cin >> n;
	string s;
	vector<vector<char>> memo;
	rep(i,n){
		cin >> s;
		vector<char> t;
		rep(j,10){
			t.push_back(s[j]);
		}
		sort(t.begin(),t.end());
		memo.push_back(t);
	}
	sort(memo.begin(),memo.end());
	ll cnt(1),ans(0);
	rep(i,n-1){
		if(equal(memo[i].cbegin(), memo[i].cend(), memo[i+1].cbegin())){
			cnt++;
		}else if(cnt != 1){
			ans += cnt*(cnt-1)/2;
			cnt = 1;
		}
	}
	if(cnt != 1) ans += cnt*(cnt-1)/2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 6580
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	vector<int> a(3);
	rep(i,3) cin >> a[i];
	int ans = 0;
	while(a[0] != a[1] || a[1] != a[2] || a[2] != a[0]){
		sort(a.begin(), a.end());
		if(a[1] != a[2]){
			a[0]++;
			a[1]++;
		}
		else{
			a[0] += 2;
		}
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define printYes() cout << "Yes" << endl;
#define printNo() cout << "No" << endl;
#define printVector(v) rep(i, v.size()) cout << v[i] << endl;

int main()
{
  int N, K;
  cin >> N >> K;
  long long zero_count = 0;
  long long harf_K_count = 0;
  long long ans = 0;

  rep(i, N)
  {
    if ((i + 1) % K == 0)
      zero_count++;
    if ((i + 1) % K == (K / 2))
      harf_K_count++;
  }
  if (K % 2 == 1)
  {
    ans = zero_count * zero_count * zero_count;
  }
  else
  {
    ans = zero_count * zero_count * zero_count;
    ans += harf_K_count * harf_K_count * harf_K_count;
  }

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

Measured memory_bytes: 256
suits = ['S','H','C','D']

table = [[False]*14 for i in range(4)]

n = int(input())

for loop in range(n):

    mark,num = input().split()
    num = int(num)

    if mark == 'S':
        table[0][num] = True
    elif mark == 'H':
        table[1][num] = True
    elif mark == 'C':
        table[2][num] = True
    else:
        table[3][num] = True

for i in range(4):
    for k in range(1,14):
        if table[i][k] == False:
            print("%s %d"%(suits[i],k))



Measured memory_bytes: 5604
using System;
using System.Text;

namespace _077_RunLength
{
	class Program
	{
		static void Main ( string[] args )
		{
			string inputStr;
			StringBuilder output = new StringBuilder (100 * 50);

			while ((inputStr = Console.ReadLine ()) != null)
			{
				int lastIndex = 0;
				int index = 0;

				while ((index = inputStr.IndexOf ("@", lastIndex)) != -1)
				{
					output.Append (inputStr.Substring (lastIndex, index - lastIndex));
					output.Append (inputStr[index + 2], inputStr[index + 1] - '0');

					lastIndex = index + 3;
				}

				output.AppendLine (inputStr.Substring (lastIndex, inputStr.Length - lastIndex));
			}

			Console.Write (output);
		}
	}
}

Measured memory_bytes: 9548
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_139
{
    class B
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] ab = ReadInts();
            int a = ab[0];
            int b = ab[1];
            int res = (b - 1) / (a - 1);
            if ((b - 1) % (a - 1) > 0) res++;
            WriteLine(res);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

int main(){
	lint h,num=0;
	lint sum=0;
	cin>>h;
	while(1<h){
		h/=2;
		num++;
	}
	rep(i,num+1)sum+=pow(2,i);
	cout<<sum<<endl;
}


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

using namespace std;
int main(void){
    // Your code here!
    int N, W;
    cin >> N >> W;
    int dp[N+1][W+1];
    int v[N], w[N];
    
    
    
    for(int i = 0; i < N; i++){
        cin >> v[i] >> w[i];
    }
    
    dp[0][0] = 0;
    for(int i = 0; i <= W; i++) dp[0][i] = 0;
    for(int i = 1; i <= N; i++) dp[i][0] = 0;
    
    for(int i = 0; i < N; i++){
        for(int j = 1; j <= W; j++){
            if(j- w[i] >= 0){
                dp[i+1][j] = max(dp[i][j], dp[i+1][j - w[i]] + v[i]);
            } else{
                dp[i+1][j] = dp[i][j];
            }
        }
    }
    
    cout << dp[N][W] << endl;
}



Measured memory_bytes: 7056
#include <cmath>
#include <cstdio>

using namespace std;

int main()
{
    long long n , lim , i , div ;

    scanf ( "%lld" , & n ) ;

    lim = ( int ) sqrt ( ( double ) n ) ;

    for ( i = lim ; i >= 1 ; -- i )
        if ( n % i == 0 )
        {
            div = i ;
            break ;
        }

    printf ( "%lld" , div + n / div - 2 ) ;

    return 0;
}


Measured memory_bytes: 128
#include<iostream>

int main(void){
	int n;
	std::cin >> n;
	
	int cards[4][13] = {{},{},{},{}};
	
	for (int i =1; i <=n; i++){
		char c;
		int r;
		std::cin >> c >> r;
		if (c == 'S') cards[0][r-1] = 1;
		if (c == 'H') cards[1][r-1] = 1;
		if (c == 'C') cards[2][r-1] = 1;
		if (c == 'D') cards[3][r-1] = 1;
	}
	
	for (int i = 0; i < 4; i ++){
		if (i == 0){
			for (int j = 0; j < 13; j++ ){
				if (cards[i][j] == 0){
					std::cout << "S " <<  j+1 << std::endl;
				}
			}
		}
		if (i == 1){
			for (int j = 0; j < 13; j++ ){
				if (cards[i][j] == 0){
					std::cout << "H " <<  j+1 << std::endl;
				}
			}
		}
		if (i == 2){
			for (int j = 0; j < 13; j++ ){
				if (cards[i][j] == 0){
					std::cout << "C " <<  j+1 << std::endl;
				}
			}
		}
		if (i == 3){
			for (int j = 0; j < 13; j++ ){
				if (cards[i][j] == 0){
					std::cout << "D " <<  j+1 << std::endl;
				}
			}
		}
	}
	
	return 0;
}

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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
  const char* c = strchr(na + 1, ',');
  cerr.write(na, c - na) << " : " << arg1 << " , ";
  __f(c + 1, args...);
}
#define endl "\n"
#define all(v) v.begin(), v.end()
#define UNIQUE(v) sort(all(v)),v.erase(unique(all(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int inf = 1e9;
const LL INF = 1e18;
const int N = 1e5 + 5;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    //freopen("input.txt", "r", stdin);
  #endif // LOCAL
  int n, m;
  cin >> n >> m;
  vector <int> a(n + 1);
  int tot = 0;
  for (int i = 1; i <= n; i++) cin >> a[i], tot += a[i];
  int can = 0;
  for (int i = 1; i <= n; i++) {
    if (a[i] * 4 * m >= tot) can++;
  }
  cout << ((can >= m) ? "Yes" : "No") << endl;
  return 0;
}



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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repp(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perr(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)

typedef long long LL;
typedef long double LD;

int main(){
  int n;
  cin >> n;
  vector<LL> v(n);
  rep(i,n) cin >> v[i];
  LL ans=0;
  repp(i,1,n){
    int kab=0;
    LL s=0,t=0;
    for(;kab<n-1;kab+=i){
      int a = n-1-kab;
      if(a<=i) break;
      if(a%i==0&&a<=kab) break;
      t+=v[a];
      s+=v[kab];
      ans=max(ans,s+t);
    }
  }
  cout << ans << endl;
  return 0;
}


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

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

    while(s.size() != 1){
        s.erase(0,1);
    }

    int n = stoi(s);

    if(n == 0 || n == 1 || n == 6 || n == 8) cout<<"pon"<<endl;
    else if(n == 3) cout<<"bon"<<endl;
    else cout<<"hon"<<endl;

    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	int l = 0, r = n;
	rep(i, m){
		int il, ir;
		cin >> il >> ir;
		if(l < il) l = il;
		if(ir < r) r = ir;
	}
	if(r < l) cout << 0 << endl;
	else cout << r-l+1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i,n) for(int i = 1; i < n+1 ;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 INF 2e9
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}


int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    int k;
    cin >> k;
    ll ans = 0;
    REP1(i,k){
        REP1(j,k){
            REP1(l,k){
                ans+=gcd(gcd(i,j),l);
            }
        }
    }
    cout << ans << endl;
}


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

const int N = 100005;

int bit[N];

void update(int pos){
	for (; pos < N; pos += (pos & (-pos))){
		bit[pos]++;
	}
}

int query(int pos){
	int ans = 0;
	for (; pos > 0; pos -= (pos & (-pos))){
		ans += bit[pos];
	}
	return ans;
}

int fat(int x){
	if(x == 0) return 1;
	return x * fat(x-1);
}

int solve(vector < int >& vet){
	memset(bit, 0, sizeof bit);
	int ans = 0;
	for (int i=vet.size()-1; i>=0; i--){
		ans += fat((int)vet.size()-1-i) * query(vet[i]-1);
		update(vet[i]);
	}
	return ans;
}

int main(){
	int n;
	scanf("%d", &n);
	vector < int > v(n);
	for (int i=0; i<n; i++){
		scanf("%d", &v[i]);
	}
	int a = solve(v);
	for (int i=0; i<n; i++){
		scanf("%d", &v[i]);
	}
	int b = solve(v);
	printf("%d\n", abs(a-b));
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i) = 0; (i) <(n); (i)++) 
#define so(v) sort(v.begin(),v.end())
using ll = long long;
using vi=vector<int>;
using vii=vector<vi>;


const int MAX = 510000;
const int MOD = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll f(ll n,ll m){
  //k=0の時の答え
  ll ans=m;
  rep(i,n-1){
    ans*=m-1;
    ans%=MOD;
  }
  return ans;
}
int main() {
    // 前処理
    COMinit();
    ll n,m,k;cin>>n>>m>>k;
    ll answer=0;
    ll ff=f(n-k,m);
    for(int i=k;i>=0;i--){
      answer+=(COM(n-1,i)%MOD)*(ff%MOD)%MOD;
      ff=(ff*(m-1))%MOD;
      answer%=MOD;
    }
    cout << answer << endl;
    //cout<<COM(n-1,1)%MOD<<endl;
}

Measured memory_bytes: 15596
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	H, W := ReadInt(), ReadInt()
	m := make(map[int]int)

	for i := 0; i < H; i++ {
		line := ReadString()
		for j := 0; j < W; j++ {
			m[int(line[j])]++
		}
	}

	g1, g2, g4 := 0, 0, 0
	for _, v := range m {
		if v%2 == 1 {
			g1++
		} else if v%4 == 2 {
			g2++
		} else {
			g4++
		}
	}

	if H%2 == 1 && W%2 == 1 {
		g1--
	}
	if g1 > 0 {
		fmt.Println("No")
		return
	}

	if H%2 == 1 {
		g2 -= W / 2
	}
	if W%2 == 1 {
		g2 -= H / 2
	}
	if g2 > 0 {
		fmt.Println("No")
		return
	}

	fmt.Println("Yes")
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1864
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#include <math.h>
#define lli long long int
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const lli ths = 1LL << 40;
const int NN = 5e3 + 6;

lli dp[N];

void solve()
{
    lli h, n;
    cin>>h>>n;
    lli a[n], b[n];
    for(int i = 0; i < n; i ++) {
        cin>>a[i] >> b[i];
    }
    for(int i = 1; i < N; i ++)
        dp[i] = inf;
    for(int i = 0; i <= h; i ++) {
        for(int j = 0; j < n; j ++) {
            dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j]);
        }
    }
    lli ans = inf;
    for(int i = h; i < N; i ++) {
        ans = min(ans, dp[i]);
    }
    cout<<ans;
    cout<<'\n';
    return ;
}

/*
*/

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

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



Measured memory_bytes: 2688
#include <iostream>
#include<map>
#include<vector>
#include<algorithm>
#include <stdio.h>
#include<set>
#include<string>
#include<math.h>
#include<cmath>
#include<iomanip>
#include<queue>
#include<stack>
#define ll long long
using namespace std;
long double pi = 3.14159265358979323846;
#define fast ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

int main()
{
	
		ll n,m;  cin >> n>>m;
		if (m >= n)
			cout << "unsafe";
		else
			cout << "safe";
	
	 return 0;

}



Measured memory_bytes: 3596
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
      
const int MAXN =1e5+10;
      
char s[MAXN][10+10];
long long int march[5+5];
int main()
{
	int N =0;
	scanf("%d",&N);
	long long int ans =0;
	for(int i=0;i<N;i++)
	{
		scanf("%s",&s[i]);
	}
	for(int i=0;i<N;i++)
	{
		if(s[i][0]=='M')    march[0]++;
		if(s[i][0]=='A')    march[1]++;
		if(s[i][0]=='R')    march[2]++;
		if(s[i][0]=='C')    march[3]++;
		if(s[i][0]=='H')    march[4]++;
	}
	ans=march[0]*march[1]*march[2]+march[0]*march[1]*march[3]+march[0]*march[1]*march[4]+march[0]*march[2]*march[3]+march[0]*march[2]*march[4]+march[0]*march[3]*march[4]+march[1]*march[2]*march[3]+march[1]*march[2]*march[4]+march[1]*march[3]*march[4]+march[2]*march[3]*march[4];
printf("%lld",ans);
	return 0;
	}

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

const int INF = 1e9;
using ll = long long;

int n,m;

vector<pair<ll,ll>> es;

map<ll,ll> s;
int k = 0;
ll id(int v, int c){
    ll x = (ll)v<<32|c;
    if(s.count(x)) return s[x];
    s[x] = k++;
    return s[x];
}

unordered_set<int> cs[100010];

struct edge { int dst, wgt; };

vector<vector<edge>> g;

void ae(int a, int b, int w){
    g[a].push_back({b,w});
    g[b].push_back({a,w});
}

deque<int> q;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin >> n >> m;
    rep(i,n) cs[i].insert(id(i,0));
    rep(i,m){
        int a,b,c;
        cin >> a >> b >> c;
        --a; --b;
        ll x = id(a,c);
        ll y = id(b,c);
        es.emplace_back(x,y);
        cs[a].emplace(x);
        cs[b].emplace(y);
    }
    int k = 0;
    unordered_map<ll,int> idid;
    for(auto &p : s){
        idid[p.second] = k++;
    }
    g.assign(k,{});
    for(auto &e : es){
        ll a,b;
        tie(a,b) = e;
        int x = idid[a];
        int y = idid[b];
        ae(x,y,0);
    }

    rep(i,n){
        int h = idid[id(i,0)];
        for(auto &c : cs[i]) if(c != h) ae(h,idid[c],1);
    }

    int ans = -2;

    int src = idid[id(0,0)];
    int dst = idid[id(n-1,0)];
    int *dist = new int[k];
    fill(dist, dist+k, INF);
    dist[src] = 0;
    q.push_back(src);
    while(q.size()){
        int v = q.front();
        q.pop_front();

        if(v == dst){
            ans = dist[v];
            break;
        }

        for(auto &e : g[v]){
            if(dist[e.dst] != INF) continue;
            dist[e.dst] = dist[v] + e.wgt;
            if(e.wgt == 0) q.push_front(e.dst);
            else q.push_back(e.dst);
        }
    }

    // rep(i,k) cout << dist[i] << ' ';
    // cout << endl;

    cout << ans/2 << endl;
}


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

#define int long long

string s;
int p = 0;
int P, Q, R;

int dfs() {
  char c = s[p++];
  if ( isdigit(c) ) return c-'0';
  if ( c == 'P' ) return P;
  if ( c == 'Q' ) return Q;
  if ( c == 'R' ) return R;
  if ( c == '-' ) return 2-dfs();
  if ( c == '(' ) {
    int l = dfs();
    char c_ = s[p++];
    int r = dfs();
    p++;    
    if ( c_ == '*' ) return min(l, r);
    if ( c_ == '+' ) return max(l, r);
  }
  return 0;  
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  
  while ( cin >> s, s != "." ) {
    int cnt = 0;
    for ( P = 0; P <= 2; P++ ) {
      for ( Q = 0; Q <= 2; Q++ ) {
	for ( R = 0; R <= 2; R++ ) {
	  p = 0;
	  if ( dfs() == 2 ) cnt++;
	}
      }
    }
    cout << cnt << endl;  
  }  
       
  return 0;
}



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

int main(){
  int A,B,a;

  cin>>A>>B;

  if(A>=B){
    a=A;
    A-=1;
  }
  else{
    a=B;
    B-=1;
  }
  a+=max(A,B);
  cout<<a<<endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
 
char str[110];
int i,j,k,l,m,n;
int n,e,s,w,un,up;
int a[7],b[7], qu[25],qf[25],ufl[25];
int t;
 
void input() {
  for(i=0;i<6;i++){
    scanf("%d",&a[i+1]);
    b[i+1] = a[i+1];
    // printf("a[%d] = %d\n",i+1,a[i+1]);
  }
 
  scanf("%d",&n);
  //printf("n = %d\n",n);
 
  for(i=0;i<n;i++) {
    scanf("%d %d",&qu[i],&qf[i]);
    //  printf("qu[%d] = %d qf[%d] = %d\n",i,qu[i],i,qf[i]);
  }
}
 
void N() {
  t = a[1];
  a[1] = a[2];
  a[2] = a[6];
  a[6] = a[5];
  a[5] = t;
}
 
void S() {
  t = a[1];
  a[1] = a[5];
  a[5] = a[6];
  a[6] = a[2];
  a[2] = t;
}
 
void E() {
  t = a[1];
  a[1] = a[4];
  a[4] = a[6];
  a[6] = a[3];
  a[3] = t;
}
 
void W() {
  t = a[1];
  a[1] = a[3];
  a[3] = a[6];
  a[6] = a[4];
  a[4] = t;
}
 
void UF() {
 
  if(qu[k] == a[1]) { // if qu == 1;
    // printf("qu == 1\n");
    if(qf[k] == a[3]) strcpy( str, "NWS");
    else if(qf[k] == a[5]) strcpy(str ,"NEES");
    else if(qf[k] == a[4]) strcpy(str,"NES");
  }  else if(qu[k] == a[2]) {  // if qu == 2;
    // printf("qu == 2\n");
    if(qf[k] == a[3])  strcpy( str, "NWS");
    else if(qf[k] == a[1] ) strcpy(str ,"NEES");
    else if(qf[k] == a[4]) strcpy(str,"NES");
    N();
  } else if(qu[k] == a[3]){ // if qu == 3;
    //   printf("qu(%d) == %d\n",qu[k],a[3]);
     
    if(qf[k] == a[6])  strcpy( str, "NWS");
    else if(qf[k] == a[5])  strcpy(str ,"NEES");
    else if(qf[k] == a[1]) strcpy(str,"NES");
    W();
  } else if(qu[k] == a[4]) {
    if(qf[k] == a[1]) strcpy( str, "NWS");
    if(qf[k] == a[5])  strcpy(str ,"NEES");
    if(qf[k] == a[6]) strcpy(str,"NES");
    E();
  } else if(qu[k] == a[5]) {
    if(qf[k] == a[3]) strcpy( str, "NWS");
    else if(qf[k] == a[6])  strcpy(str ,"NEES");
    else if(qf[k] == a[4]) strcpy(str,"NES");
    S();
  } else if(qu[k] == a[6]) {
    if(qf[k] == a[3]) strcpy( str, "NWS");
    else if(qf[k] == a[2])  strcpy(str ,"NEES");
    else if(qf[k] == a[4]) strcpy(str,"NES");
    N();
    N();
  }
 
 
}
 
void reset() {
  // printf("before reset str = '%s'\n",str);
  strcpy(str , "");
  for(i=1;i<=6;i++){
    //  printf("before reset a[%d] = %d\n",i,a[i]);
    a[i] = b[i];
    //     printf("a[%d] = %d\n",i,a[i]);
  }
  // printf("str = '%s'\n",str);
}
 
 
void output() {
  /*  printf("%d\n",a[1]); */
 
  printf("%d\n",a[3]);
}
 
void IF() {
 
  // scanf("%s",str);
 
  for(i=0;i<strlen(str);i++) {
 
    if(str[i] == 'N') N();
    else if(str[i] == 'S') S();
    else if(str[i] == 'W') W();
    else if(str[i] == 'E') E();
  }
}
 
int main() {
 
  k = 0;
 
  input();
 
  for(j=0;j<n;j++) {
    UF();
     
    IF();
 
    output();
 
    reset();
    k = k + 1;
 
  }
 
 
  return 0;
}


Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vp = vector<P>;
using vt = vector<T>;

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

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  FORe(i, 1, n) {
    if(i%3!=0 && i%5!=0) ans += i;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3624
/*#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>*/
#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);(i)--)
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
const ll mod = 1e9 + 7;
ll dx[4] = {1,0,-1,0};
ll dy[4] = {0,1,0,-1};

int main(){
    ll n;
	cin >> n;
	vll v(n);
	rep(i,n) {
		cin >> v[i];
		v[i]--;
	}
	ll val=0;
	rep(i,n+1){
		val = v[val];
		if(val == 1){
			cout << i+1 << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}  


Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>

int x[16][16];
int y[16][16];
int A[16]={};
int N;

int judge(int bit)
{
    int mask;
    for(int i=0; i<N; i++) { //N人について正直か不親切かを判定する
        if(!(bit & 1<<i)) continue;

        for(int j=0; j<A[i]; j++) {
            mask=(1 << (x[i][j]-1));
            if(y[i][j]==1 && !(bit & mask)) return 0; //正直者の証言と仮定したものが等しいか比べる。
            if(y[i][j]==0 && (bit & mask)) return 0; //bit & maskをしたとき、maskで残した部分のフラグが立っていなかったら0を返すことになるのでif文の条件を満たさなくなる。
        }
        // printf("true:%d\n", i);
    }
    return 1;
}

int main()
{
    int cnt=0;
    int max=0;
    scanf("%d", &N);

    for(int i=0; i<N; i++) { //人数、証言の数、どの人が正直or不親切かを読み取る
        scanf("%d", &A[i]);
        for(int j=0; j<A[i]; j++) {
            scanf("%d %d", &x[i][j], &y[i][j]);
        }
    }


    for(int i=0; i<(1<<N); i++) {
        int bit=i;
        //printf("%d回目\n", i);
        if(judge(bit)) {
            for(int j=0; j<N; j++) {
                if(bit & 1<<j) cnt++;
            }
            //printf("%d人:%d回目\n", cnt, i);
            if(max<cnt) max=cnt;
            cnt=0;
        }
    }

    printf("%d", max);

}

Measured memory_bytes: 1696
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(Math.abs(a+b)%2==0 || a-b==0){
            System.out.println(Math.abs(a+b)/2);
            return;
        }
        System.out.println("IMPOSSIBLE");
    }
}

Measured memory_bytes: 23892
#include<bits/stdc++.h>
 
#define debug(x) cout << '>' << #x << ':' << x << endl;
 
#define nitro ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);
const int mod = 1e9+7;
using namespace std;
using ll = long long int;
const ll invmod = 998244353; 
const int N = 5*(int)(1e5) + 1;
const int MAXN = 1e5+10;
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
 
 
bool compareByfirst(tuple<int, int, int>&a, tuple<int, int, int>&b)
{
	return get<0>(a) > get<0>(b);
}
bool compareBySecond(tuple<int, int, int>&a, tuple<int, int, int>&b)
{
	return get<1>(a) < get<1>(b);
}
 
int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	//clock_t time_req;time_req = clock();
	nitro;
	int x, y;
	cin >> x >> y;
	bool flag = false;
	for(int i = 0; i <= x; i++)
	{
		int cranes = i;
		int turtles = x-i;

		if(cranes*2 +turtles*4 == y)
		{
			flag = true;
			break;
		}
	}
	if(flag) cout << "Yes" << '\n';
	else cout << "No" << '\n';
}

Measured memory_bytes: 3600
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

const double EPS = 1.0e-5;

int elementaryMatrix(vector<vector<double> >& mat)
{
    const int n = mat.size();
    const int m = mat[0].size();
    int y = 0;
    int x = 0;
    while(y < n && x < m){
        int tmp = y;
        for(int i=y+1; i<n; ++i){
            if(abs(mat[i][x]) > abs(mat[tmp][x]))
                tmp = i;
        }
        if(abs(mat[tmp][x]) > EPS){
            mat[y].swap(mat[tmp]);
            for(int i=y+1; i<n; ++i){
                for(int j=m-1; j>=x; --j){
                    mat[i][j] -= mat[y][j] * (mat[i][x] / mat[y][x]);
                }
            }
            ++ y;
        }
        ++ x;
    }
    mat.resize(y);
    return y;
}

bool linearSystem(vector<vector<double> >& mat, vector<double>& x)
{
    int n = mat[0].size() - 1;
    if(elementaryMatrix(mat) != n || mat[n-1][n-1] == 0)
        return false;

    x.resize(n);
    for(int i=n-1; i>=0; --i){
        x[i] = mat[i][n];
        for(int j=i+1; j<n; ++j)
            x[i] -= mat[i][j] * x[j];
        x[i] /= mat[i][i];
    }
    return true;
}

int main()
{
    for(;;){
        int d;
        cin >> d;
        if(d == 0)
            return 0;

        vector<double> f(d+3);
        for(int i=0; i<d+3; ++i)
            cin >> f[i];

        vector<vector<double> > mat(d+3, vector<double>(d+2));
        for(int i=0; i<d+3; ++i){
            for(int j=0; j<=d; ++j){
                mat[i][j] = pow((double)i, d-j);
                mat[i][d+1] = f[i];
            }
        }

        for(int i=0; i<d+3; ++i){
            vector<vector<double> > mat2 = mat;
            mat2.erase(mat2.begin()+i);

            vector<double> x;
            if(linearSystem(mat2, x)){
                cout << i << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 1268
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, int(n) + 1)
#define RREP(i, n) RFOR(i, 0, n)
#define RREP1(i, n) RFOR(i, 1, int(n) + 1)
#define ALL(c) begin(c), end(c)

int _ = (
#ifndef LOCAL
    std::cin.tie(nullptr), std::ios::sync_with_stdio(false),
#endif
    std::cout.precision(10), std::cout.setf(std::ios::fixed));

using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <typename T> using vec = std::vector<T>;
using namespace std;

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

  const regex re("^A[a-z](?:[a-z]*C[a-z]*)[a-z]$");
  cout << (regex_match(S, re) ? "AC" : "WA") << endl;
  return 0;
}


Measured memory_bytes: 3748
def dp():
  N, W = map(int, input().split())
  WV = (map(int, input().split()) for _ in range(N))

  DP = [0] * (W+1)
  for w, v in WV:
    for j in range(W, w-1, -1):
      dp = DP[j-w] + v 
      if DP[j] < dp:
        DP[j] = dp
  return max(DP)
print(dp())


Measured memory_bytes: 7668
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_f(const void *a, const void *b) {
	return *((size_t *)a) < *((size_t *)b) ? -1 : 1;
}

static size_t comb(const size_t n, const size_t r) {
	size_t result = 1;

	for (size_t i = 0; i < r; i++) {
		result *= n - i;
		result /= i + 1;
	}

	return result;
}

static uint64_t gcd(uint64_t m, uint64_t n)
{
	uint64_t temp;

	while (m%n != 0) {
		temp = n;
		n = m % n;
		m = temp;
	}

	return n;
}

static char S[100001];

int main(void) {
	scanf("%s", S);

	size_t count[2] = { 0, 0 };

	const size_t length = strlen(S);

	for (size_t i = 0; i < length; i++) {
		count[S[i] - '0']++;
	}

	printf("%zu\n", MIN(count[0], count[1])*2);

	return 0;
}


Measured memory_bytes: 256
#include<iostream>//A
#include<cstdio>
#include<string>
using namespace std;
int main()
{
    string a,b;
    cin >> a >> b;
    int k=a.size(),sum=0;
    for(int i=0;i<k;i++) sum+=(a[i]==b[i]);
    printf("%d\n",sum);
}

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

using ll=long long;
int n, a, sum, minimum = INT_MAX;

int main(){
  cin >> n;
  rep(i,n){
    cin >> a;
    sum += a;
    if(a%10 != 0) minimum = min(minimum, a);
  }
  if(sum%10 != 0) cout << sum << endl;
  else if(minimum == INT_MAX) cout << 0 << endl;
  else cout << sum - minimum << endl;
}

Measured memory_bytes: 256
n, m = list(map(int, input().split()))
broken = [False] * (n + 1)
for _ in range(m):
    broken[int(input())] = True

dp = [0] * (n + 1)
dp[0] = 1
dp[1] = 1 if not broken[1] else 0
MOD = 10 ** 9 + 7

for i in range(2, n + 1):
    if not broken[i - 1]:
        dp[i] += (dp[i - 1])
    if not broken[i - 2]:
        dp[i] += (dp[i - 2])
    dp[i] %= MOD

print(dp[n])


Measured memory_bytes: 13544
#include <bits/stdc++.h>
using namespace std;
constexpr int INF = 1e9;

int main() {
  int h, w, y1, x1, y2, x2;
  cin >> h >> w >> y1 >> x1 >> y2 >> x2;
  y1--, x1--, y2--, x2--;
  vector<string> s(h);
  for (auto &e : s) cin >> e;

  vector<vector<int>> d(h, vector<int>(w, INF));
  d[y1][x1] = 0;

  priority_queue<tuple<int, int, int>> q;
  q.push(make_tuple(0, y1, x1));
  while (!q.empty()) {
    tuple<int, int, int> t = q.top();
    q.pop();
	int dyx = get<0>(t);
	int y = get<1>(t);
	int x = get<2>(t);
    if (dyx > d[y][x]) continue;

    for (int dy = -2; dy <= 2; dy++) {
      int yt = y + dy;
      if (yt < 0|| yt >= h) continue;
      for (int dx = -2; dx <= 2; dx++) {
        int xt = x + dx;
        if (xt < 0 || xt >= w) continue;
        if (s[yt][xt] == '#') continue;

        int dt = d[y][x] + (abs(dy) + abs(dx) > 1 ? 1 : 0);
        if (dt < d[yt][xt]) {
          d[yt][xt] = dt;
          q.push(make_tuple(-dt, yt, xt));
        }
      }
    }
  }

  cout << (d[y2][x2] != INF ? d[y2][x2] : -1) << endl;
}

Measured memory_bytes: 9428