akhauriyash/Code-Regression huggingface dataset:
using System;
using System.IO;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
public static class P {
  public static void Main() {
    var nm = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int n = nm[0];
    int m = nm[1];
    var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
    int inf = int.MaxValue;
    int[] dp = Enumerable.Repeat(inf, n + 1).ToArray();
    dp[0] = 0;
    foreach (int i in Enumerable.Range(0, n + 1)) {
      foreach (int x in a) {
        if (n < i + x) continue;
        dp[i + x] = Min(dp[i + x], dp[i] + 1);
      }
    }
    // Console.WriteLine("dp: {0}", String.Join(" ", dp.Select(x => x.ToString("D"))));
    Console.WriteLine(dp[n]);
  }
}



Measured memory_bytes: 18524
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()
#define var(t, ...) t __VA_ARGS__;in,__VA_ARGS__;

void Calc();
int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
template<class A>int comp(A a, A b) { return a < b ? 1 : b < a ? -1 : 0; }
struct Scanner {
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) cin >> i; return a; }
  string Line() const { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

/*---------------------------------------------------------------------*/


void Calc() {

  string s = in;
  string t = in;
  int n = size(s);
  map<char, set<char>> m;
  map<char, set<char>> m2;
  rep(i, n) {
    m[t[i]].insert(s[i]);
    m2[s[i]].insert(t[i]);
  }

  int cnt = 0;
  for (auto& i : m) {
    cnt += i.second.size() != 1;
  }
  for (auto& i : m2) {
    cnt += i.second.size() != 1;
  }


  if (cnt) {
    cout << ("No") << endl;
    return;
  }


  cout << ("Yes") << endl;
}


Measured memory_bytes: 916
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include <cmath>
#include <limits>
#include<set>
#include <queue>

using namespace std;
#define int long  long int
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

signed main()
{
	int N;
	cin >> N;
	vector<int>A(N), C(N - 1);
	int sum = 0;
	for (int i = 0; i < N; i++)cin >> A[i];
	for (int i = 0; i < N; i++)
	{
		int num;
		cin >> num;
		sum += num;
	}
	for (int i = 0; i < N - 1; i++)cin >> C[i];

	for (int i = 0; i < N - 1; i++)
	{
		if (A[i + 1] == A[i] + 1)sum += C[A[i] - 1];
	}
	cout << sum;
}

Measured memory_bytes: 256
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

int main() {
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  VL as(N);
  FOR(a,as) {
    cin >> a;
  }
  ll ans = 0;
  bool ok;
  do {
    ok = true;
    ll s = 0;
    FOR(a,as) {
      if(a >= N) {
        ok = false;
        s += a / N;
        ans += a / N;
      }
    }
    FOR(a,as) {
      ll ops = a / N;
      a -= ops * N;
      a += s - ops;
    }
  } while(!ok);
  cout << ans << endl;
  return 0;
}


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

typedef long long ll;

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

  int n;
  double ans;

  cin >> n;
  cout << (double)(n - n / 2) / (double)n  << endl;

  return 0;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;
#pragma endregion

void solve() {
    int n, m;
    cin >> n >> m;
    int sum = 0;
    for (int i=0; i<m; ++i) {
        int tmp;
        cin >> tmp;
        sum += tmp;
    }
    if (sum > n) cout << -1 << '\n';
    else cout << n - sum << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 3640
/**
*    author:  yuya1234
*    created: 13.07.2020 16:31:06
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define FORV(i,v) for(auto i=v.begin(); i!=v.end();i++)

#define SORT(s) sort((s).begin(),(s).end())
#define SORTD(s) sort((s).rbegin(),(s).rend())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define SZ(x) ((int)(x).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))

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 gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  //std::cout << std::fixed << std::setprecision(15);

  int n;
  cin>>n;

  int p[n];
  REP(i,n)cin>>p[i];

  int ans=0;
  REP(i,n-1){
    if(p[i]==i+1){
      if(i==0 || p[i]!=i+2){
        swap(p[i],p[i+1]);
      }
      else swap(p[i],p[i-1]);
      ans++;
    }
  }

  if(p[n-1]==n){
        swap(p[n-1],p[n-2]);
        ans++;
  }

  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 4040
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)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (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::cmp::{min, max};

fn main() {
    input!{
        s: chars
    }
    let mut ans = 0;
    for i in 0..s.len() - 1 {
        if s[i] != s[i + 1] {
            ans += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] strs = br.readLine().split("\\s+");
		int n = Integer.parseInt(strs[0]);
		int m = Integer.parseInt(strs[1]);

		int[][] A = new int[n][m];
		int[] b = new int[m];
		int[] c = new int[n];
		
		for (int i = 0; i < n; i++) {
			strs = br.readLine().split("\\s+");
			for (int j = 0; j < m; j++) A[i][j] = Integer.parseInt(strs[j]);
		}
		
		for (int i = 0; i < m; i++) b[i] = Integer.parseInt(br.readLine());
		
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				c[i] += A[i][j] * b[j];
			}
			System.out.println(c[i]);
		}
		
	}
}

Measured memory_bytes: 30624
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000



int main(){
	
	vector<vector<int>> c(3,vector<int>(3));
	
	for(int i=0;i<3;i++){
		for(int j=0;j<3;j++){
			cin>>c[i][j];
		}
	}
	
	for(int i=-1000;i<=1000;i++){
		vector<int> a(3),b(3);
		for(int j=0;j<3;j++){
			b[j] = c[0][j]-i;
		}
		for(int j=0;j<3;j++){
			a[j] = c[j][0]-b[0];
		}
		
		bool f = true;
		for(int j=0;j<3;j++){
			for(int k=0;k<3;k++){
				if(c[j][k]!=a[j]+b[k])f=false;
			}
		}
		
		if(f){
			cout<<"Yes"<<endl;
			return 0;
		}
		
	}
		
		
	cout<<"No"<<endl;
	
		
    return 0;
}


Measured memory_bytes: 256
N = int(input())
SP = [input().split() for _ in range(N)]

L = []
for i in range(N):
  L.append([SP[i][0], int(SP[i][1]), i + 1])

L.sort(key = lambda x: x[1], reverse = True)
L.sort(key = lambda x: x[0])

for i in L:
  print(i[2])

Measured memory_bytes: 38512
n, m = map(int,input().split())
if n-m == 1:
    print(0)
    exit()
a = list(map(int,input().split()))
way = [[] for i in range(n)]
for i in range(m):
    x,y = map(int,input().split())
    way[x].append(y)
    way[y].append(x)

#グラフをグループ化するやつ
import queue
def grouping(n,arr):
    gr = []
    al = [-1 for i in range(n)]
    q = queue.Queue()
    for i in range(n):
        if al[i] == 0:
            continue
        else:
            gi = []
            q.put(i)
            al[i] = 0
            while not q.empty():
                qi = q.get()
                gi.append(qi)
                for ai in arr[qi]:
                    if al[ai] < 0:
                        q.put(ai)
                        al[ai] = 0
            gr.append(gi)
    return gr

grp = grouping(n,way)
if len(grp)-2 > n-len(grp):
    print("Impossible")
    exit()
o2 = [0 for i in range(n-len(grp))]
o1 = [0 for i in range(len(grp))]
i1 = 0

for j,gi in enumerate(grp):
    m = 10**10
    f = True
    for i in gi:
        if m > a[i]:
            if f:
                f = False
            else:
                o2[i1] = m
                i1 += 1
            m = a[i]
        else:
            o2[i1] = a[i]
            i1 += 1
    o1[j] = m

o2.sort()
ans = sum(o1)
for i in range(len(o1)-2):
    ans += o2[i]
print(ans)


Measured memory_bytes: 31272
#include <stdio.h>

int gcd(int a, int b);

int main(void){
  int K;
  double sum=0;
  scanf("%d", &K);
  int a,b,c;
  for(a=1;a<=K;a++){
    for(b=1;b<=K;b++){
      for(c=1;c<=K;c++){
        sum+=gcd(gcd(a,b),c);
      }
    }
  }
  
  printf("%.0lf", sum);
  
  return 0;
}

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

Measured memory_bytes: 1744
import java.util.*;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long x = sc.nextLong();
        long t = sc.nextLong();
        long result = (n / x) * t;
        if(n % x != 0) {
            result += t;
        }
        System.out.println(result);
    }
}

Measured memory_bytes: 35564
#include<iostream>
#include<string>
#include<stack>/*** LIFO *** stack<type> var;
push(), top():to get data, pop():to remove, size(), empty() ***/
using namespace std;

#define Fp(I, STAT, END) for(int I = STAT; I < END; I++)
#define Fm(I, STAT, END) for(int I = STAT; I > END; I--)

int main(){
    string S;
    cin >> S;
    if(S == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
}


Measured memory_bytes: 3628
n, w = map(int, input().split())
dp = [1001001001] * (1000 * n + 1)
dp[0] = 0
for _ in range(n):
    wi, vi = map(int, input().split())
    for i in range(1000 * n, vi - 1, -1):
        dp[i] = min(dp[i], dp[i-vi] + wi)
print(max(filter(lambda v: dp[v] <= w, range(1000 * n + 1))))

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

int n;
int a[2][105];

int change_row(int k){
  int sum=0;
  rep(i,n){
    if(i<k)sum+=a[0][i];
    else sum+=a[1][i];
  }
  return sum+a[0][k];
}

int main(){
  cin >> n;
  rep(i,2){
    rep(j,n){
      cin >> a[i][j];
    }
  }

  int max=0;
  rep(i,n){
    int tmp=change_row(i);
    if(max<tmp)max=tmp;
  }
  cout << max << endl;
}


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

int main()
{
ll n ;
cin >> n ;
vector<ll> a(n);
rep(i, n){
  cin >> a[i];
}
vector<ll> b(n);
rep(i, n){
  cin >> b[i];
}
vector<ll> c(n-1);
rep(i, n-1){
  cin >> c[i];
}
rep(i,n){
  ans+=b[a[i]-1];
}
rep(i,n-1){
  if(a[i]==a[i+1]-1)ans+=c[a[i]-1];
}
cout << ans << endl;
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> //H - Grid 1
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int maxn = 3010;
const int mod = 1e9 + 7;
typedef long long int ll;


ll dp[maxn][maxn],v[maxn];
ll sum[maxn];
int n,m,ans;


ll solve(int i,int j)
{
	if(i == j) return dp[i][j] = v[i];
	if(dp[i][j] != -1) return dp[i][j];

	return dp[i][j] = sum[j] - sum[i-1] - min(solve(i+1,j),solve(i,j-1));
}

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

	for(int i=0;i<maxn;++i)
		for(int j=0;j<maxn;++j)
			dp[i][j] = -1;

	for(int i=1;i<=n;++i)
	{		
		cin>>v[i];
		sum[i] = sum[i-1] + v[i];
	}

	ll X = solve(1,n);
	ll Y = sum[n] - X;

	cout<<X - Y<<"\n";
}

Measured memory_bytes: 74568
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2000;
int main()
{
    std::ios::sync_with_stdio(false);
    string s, t;
    cin >> s >> t;
    int ans = s.size();
    for(int i = 0;i <= s.size() - t.size();i++){
        int cnt = 0;
        //cout << s[i] << endl;
        for(int j = 0;j < t.size();j++){
            if(t[j] != s[i + j]) cnt++;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3604
#pragma GCC optimize(3,"Ofast","inline")
#include<bits/stdc++.h>
#define forsaken
#ifdef forsaken
  #define dbg(args...) do {cout << #args << " : "; err(args);} while (0)
#else
  #define dbg(...)
#endif
void err() {std::cout << std::endl;}
template<typename T, typename...Args>
void err(T a, Args...args){std::cout << a << ' '; err(args...);}
#define IO ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(a,b) memset(a,b,sizeof(a))
#define msn(a,n,b) for(int i=0;i<=n;i++)a[i]=b
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define fi first
#define se second
using namespace std;
bool Finish_read;
template<class T>inline void read(T &x){Finish_read=0;x=0;int f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;if(ch==EOF)return;ch=getchar();}while(isdigit(ch))x=x*10+ch-'0',ch=getchar();x*=f;Finish_read=1;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
mt19937 rng_32(chrono::steady_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const int mod=1e9+7;
const int seed=233;
const double PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const int max_n=200005;
namespace {
    inline int Add(int x,int y){return (x+=y)>=mod?x-mod:x;}
	inline int Sub(int x,int y){return (x-=y)<0?x+mod:x;}
    inline int Mul(int x,int y) {return 1ll*x*y%mod;}
    inline int Pow(int x,int y=mod-2){int res=1;while(y){if(y&1)res=1ll*res*x%mod;x=1ll*x*x%mod;y>>=1;}return res;}
}
int n;
int c[max_n];
int res[max_n];
int pre[max_n];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",c+i);
    res[0]=1;
    for(int i=1;i<=n;i++)
    {
        int x=c[i];
        res[i]=Add(res[i],res[i-1]);
        if(pre[x]&&i-pre[x]!=1)res[i]=Add(res[i],res[pre[x]]);
        pre[x]=i;
        //cout<<i<<' '<<res[i]<<endl;
    }
    printf("%d\n",res[n]);
    return 0;
}


Measured memory_bytes: 2560
//おまじない
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define INF 1e9+7
#define roop(i,m,n) for(int i=m;i<n;i++)
#define mroop(i,m,n) for(int i=m;i<n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;

//おまじない



int main() {
	//(int)'a'は97 (int)'A'は65
	char a[11], b[11], c[11];
	cin >> a >> b >> c;

	int a1,a2, b1,b2, c1,c2;
	a1 = (int)a[0];
	b1 = (int)b[0];
	c1 = (int)c[0];
	for (int i = 0; a[i] != '\0'; i++) {
		a2 = (int)a[i];
	}

	for (int i = 0; b[i] != '\0'; i++) {
		b2 = (int)b[i];
	}

	for (int i = 0; c[i] != '\0'; i++) {
		c2 = (int)c[i];
	}

	if (a2 == b1 && b2 == c1) {
		YES;
	}
	else {
		NO;
	}


	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 ALL(v) (v).begin(),(v),end()
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;

template<typename A,typename B> inline void chmin(A &a,B b){if(a>b) a=b;}
template<typename A,typename B> inline void chmax(A &a,B b){if(a<b) a=b;}
//-----------------------------------------------------------------------

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

    int n;
    while(cin>>n,n)
    {
        int ans=0;
        bool l,r,f;
        l=r=f=false;
        REP(i,n){
            string s; cin>>s;
            if(s=="lu") l=true;
            else if(s=="ru") r=true;
            else if(s=="ld") l=false;
            else r=false;

            if(l==r && l!=f){
                ans++;
                f=l;
            }
        }
        cout<<ans<<endl;
    }
}

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

int main(){
  long n;
  vector<long> a, pos;
  long ans = 0;
  long negp =0;
  long t;

  cin >> n;
  for(int i = 0; i < n; ++i){
    cin >> t;
    a.push_back(t);
  }
  for(int i = 0; i < n; ++i){
    cin >> t;
    if(a[i] < t){
      ++ans;
      negp += a[i] - t;
    }else if(a[i] > t){
      pos.push_back(a[i] - t);
    }
  }
  
  if(ans == 0){
    cout << ans << endl;
    return 0;
  }
  sort(pos.begin(), pos.end(), greater<long>());
  for(int i = 0; i < pos.size(); ++i){
    negp += pos[i];
    ++ans;
    if(negp >= 0){
      break;
    }
  }
  if(negp < 0){
    ans = -1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1908
//カタラン数を語らん!w

#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 2000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144*2
#define REP(a,b) for(long long a = 0;a < b;++a)
vector<pair<long long, long long>> vertexs[500];
pair<long long, long long> dijk[500][500];
int main(){
#define int long long
	iostream::sync_with_stdio(false);
	int n, m, l;
	cin >> n >> m >> l;
	REP(i, m) {
		long long a, b, c;
		cin >> a >> b >> c;
		if (c > l) continue;
		vertexs[a].push_back(make_pair(b, c));
		vertexs[b].push_back(make_pair(a, c));
	}
	for (int i = 1; i <= n; ++i) {
		REP(q, 500) {
			dijk[i][q] = make_pair(1000, 0);
		}
		priority_queue<tuple<long long, long long, long long>, vector<tuple<long long, long long, long long>>, greater<tuple<long long, long long, long long>>> next;
		next.push(make_tuple(0, 0, i));
		dijk[i][i] = make_pair(0, 0);
		while (next.empty() == false) {
			tuple<long long, long long, long long> now = next.top();
			next.pop();
			int spot = get<2>(now);
			if (get<0>(now) != dijk[i][spot].first || get<1>(now) != dijk[i][spot].second) continue;
			REP(q, vertexs[spot].size()) {
				int next_point = get<0>(now);
				int next_cost = get<1>(now) + vertexs[spot][q].second;
				if (next_cost > l) {
					next_cost = vertexs[spot][q].second;
					next_point++;
				}
				int itr = vertexs[spot][q].first;
				if (dijk[i][itr].first > next_point || (dijk[i][itr].first == next_point && dijk[i][itr].second > next_cost)) {
					dijk[i][itr] = make_pair(next_point, next_cost);
					next.push(make_tuple(next_point, next_cost, itr));
				}
			}
		}
		REP(q, 500) {
			if (dijk[i][q].first == 1000) {
				dijk[i][q].first = -1;
			}
		}
	}
	int query;
	cin >> query;
	REP(i, query) {
		int a, b;
		cin >> a >> b;
		cout << dijk[a][b].first << endl;
	}
}

Measured memory_bytes: 5248
#include<bits/stdc++.h>
using namespace std;
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define F first
#define S second
#define pb emplace_back
#define mt make_tuple
#define gcd __gcd
#define PI 3.141592653589
// Input
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define llin(a) cin >> a
#define inl(a) scanf("%lld",&a)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define twod(mat,i,j,n,m) rep(i,n){rep(j,m)in(mat[i][j]);}
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
// Output
#define pr(a) printf("%d ",a)
#define pr2(a,b) printf("%d %d\n",a,b)
#define pr3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out(a) printf("%d\n",a)
#define outl(a) printf("%lld\n",a)
#define llpr(a) cout << a << " "
#define llout(a) cout << a << "\n"
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
// Iterator
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define all(vec) vec.begin(),vec.end()
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define tf(mytuple) get<0>(mytuple)
#define ts(mytuple) get<1>(mytuple)
#define tt(mytuple) get<2>(mytuple)
// Debug
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define what(x) cerr << #x << " : " << x << "\n"
#define ck printf("continue\n")
#define debug(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
	cerr << *it << " = " << a << "\n";
	err(++it, args...);
}
// Data Type
#define ll long long int
#define ii pair<int,int>
#define pli pair<ll,int>
#define triple tuple<int,int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<pair<int,int>,int> >
#define vvii vector<vector<pair<int,int> > >
#define M 1000000007
#define N 100005  //check the limits, man
ll pro(ll a,ll b)
{
    return (a*b)%M;
}
ll make(vi &v,int n)
{
    int i,a=n-1;
    ll temp=0,z;
    reverse(all(v));
    rep(i,n)
    {
        z=a;
        z*=v[i],z%=M;
        temp+=z;
        a-=2;
    }
    return temp%M;
}
int main()
{
    ll ans=1;
    int n,m,i;
    in2(n,m);
    vi v;
    v.resize(n);
    read(v,i,n);
    ans=pro(ans,make(v,n));
    v.resize(m);
    read(v,i,m);
    ans=pro(ans,make(v,m));
    llout(ans);
}








Measured memory_bytes: 1024
a, b, k = map(int, input().split(' '))

if k >= a+b: print("0 0")
else:
    if a > k:
        print(a-k, b)
    else:
        if b-k+a >= 0:
            print(0, b-k+a)
        else:
            print(0, 0)

Measured memory_bytes: 2940
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
#include <stack>
using namespace std;
#define ll int64_t
const long mod = 1e9 + 7;


const long LINF = 1e13;
const long LLINF = 1e18;
const long ALPHABET = 26;

template <class T>
void Swap(T& r, T& l) {
  T tmp = r;
  r = l;
  l = tmp;
}

template<typename T>
istream& operator >> (istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x; //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいい
  return is;
}


int main() {
  string s;
  long n,m;
  cin >> s;

  // vector<long> a(n);
  // vector<long> b(n);
  // cin >> b;

  long ans = 0;
  long tmp =0;
  for (int i = 0; i < s.size(); ++i){
    if (s[i]== 'A' ||s[i]== 'C' ||s[i]== 'T' ||s[i]== 'G'  ){
      tmp++;
    }else{
      tmp = 0;
    }
    if (tmp > ans){
      ans = tmp;
    }
  }


  bool an = true;
  



  cout << ans <<endl;
  // cout << (an?"yes":"no");

}




















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

int n, A[30];
int solve(int i, int m)
{
    if(m == 0)   return 1;
    if(i >= n)   return 0;
    int res = solve(i+1,m) || solve(i+1,m-A[i]);
    return res;
}
int main()
{
    int q, m[205];
    cin >> n;
    for(int i=0; i<n; i++)
        cin >> A[i];
    cin >> q;
    for(int i=0; i<q; i++)
    {
        cin >> m[i];
        int k = 0;
        if(solve(k,m[i]))
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }
    return 0;
}

Measured memory_bytes: 3112
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

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

  while(true) {
    int n;
    cin >> n;
    if(!n) break;
    vector<string> t(n);
    REP(i, n) cin >> t[i];

    vector<bool> del(n, false);
    REP(i, n) REP(j, n) {
      if(i==j || del[i] || del[j] || t[i].size() < t[j].size()) continue;
      REP(k, t[i].size()-t[j].size()+1) {
        string tmp = t[i].substr(k, t[j].size());
        // cout << tmp << endl;
        if(tmp == t[j]) del[j] = true;
      }
    }

    vector<string> s;
    REP(i, n) if(!del[i]) s.PB(t[i]);
    n = s.size();

    // cout << s << endl;

    VVI trans(n, VI(n, 0));
    REP(i, n) REP(j, n) {
      if(i==j) continue;
      REP(k, min(s[i].size(), s[j].size())) {
        string tmp1 = s[i].substr(s[i].size()-k-1), tmp2 = s[j].substr(0, k+1);
        // cout << tmp1 << " " << tmp2 << endl;
        if(tmp1 == tmp2) trans[i][j] = k+1;
      }
    }

    // REP(i, n) cout << trans[i] << endl;

    VVI dp(1LL<<n, VI(n, INF));
    REP(i, n) dp[1<<i][i] = s[i].size();
    REP(i, 1LL<<n) REP(j, n) {
      if(dp[i][j] == INF) continue;
      REP(k, n) {
        if(i&1<<k) continue;
        chmin(dp[i|1<<k][k], dp[i][j]+((int)s[k].size()-trans[j][k]));
      }
    }

    int ans = INF;
    REP(i, n) chmin(ans, dp[(1LL<<n)-1][i]);
    cout << ans << endl;
  }

  return 0;
}



Measured memory_bytes: 5356
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init)                                          \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T> using VEC = std::vector<T>;
template <class T> using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail> void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec)
    os << v << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int cnt = 0;
  int left = 0;
  int right = 0;
  REP(i, 0, n) {
    if (s[i] == '(')
      cnt++;
    else {
      cnt--;
      if (cnt < 0) {
        left++;
        cnt++;
      }
    }
  }

  right = cnt > 0 ? cnt : 0;
  DUMP(cnt, left);
  REP(i, 0, left) cout << "(";
  cout << s;
  REP(i, 0, right) cout << ")";
  cout << endl;


return 0;
}


Measured memory_bytes: 256
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
 
    return divisors


n = int(input())
ans = 0
if n < 105:
    print(0)
else:
    for i in [i for i in range(105,n+1) if i %2 == 1]:
        m = make_divisors(i)
        if len(m) == 8:
            ans += 1   
    print(ans)

Measured memory_bytes: 3064
S = str(input())

if S[0]=='R':
	if S[1]=='R':
		if S[2]=='R':
			print(3)
		else:
			print(2)
	else:
		print(1)
else:
	if S[1]=='R':
		if S[2]=='R':
			print(2)
		else:
			print(1)
	else:
		if S[2]=='R':
			print(1)
		else:
			print(0)

Measured memory_bytes: 61648
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for (int i = 0; i < int(n); ++i)
#define sz(x) ((int) (x).size())
typedef long double ld;
typedef long long ll;
typedef long long i64;

const int M = 100100;

int n;
int a[M];

void read() {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
}

bool First(int *a) {
    int sum = 0;
    for (int i = 0; i < n; ++i)
        sum ^= a[i] % 2;
    return sum != n % 2;
}

void first() {
    cout << "First\n";
    exit(0);
}

void second() {
    cout << "Second\n";
    exit(0);
}

int gcd(int x, int y) {
    while (x) {
        y %= x;
        swap(x, y);
    }
    return y;
}

bool End() {
    for (int i = 0; i < n; ++i)
        if (a[i] != 1)
            return false;
    return true;
}

bool win() {
    if (First(a))
        return true;

    if (End())
        return false;

    int cnt = 0;
    int at = -1;
    for (int i = 0; i < n; ++i)
        if (a[i] % 2 == 1) {
            ++cnt;
            if (a[i] > 1)
                at = i;
        }

    if (cnt != 1 || at == -1)
        return false;
    a[at]--;
    
    int g = 0;
    for (int i = 0; i < n; ++i)
        g = gcd(a[i], g);

    if (g == 1)
        return false;

    for (int i = 0; i < n; ++i)
        a[i] /= g;

    return !win();
}

int main() {
#ifdef LOCAL
    assert(freopen("d.in", "r", stdin));
#endif
    ios_base::sync_with_stdio(false);

    read();
    if (win())
        first();
    else
        second();

}



Measured memory_bytes: 640
#include<iostream>

using namespace std;

typedef long long llint;

const int MAXN = 100005;
const int MOD = 1000000007;

llint n, val, x, y;
llint l[MAXN];
llint fact[MAXN];
llint inv[MAXN];
llint p[MAXN];

llint mul (llint a, llint b) {
	return (a*b)%MOD;
}

llint sub (llint a, llint b) {
	if (a-b<0) return a-b+MOD; return a-b;
}

llint pot (llint x, llint n) {
	if (n==0) return 1;
	if (n&1) {
		return mul(pot(x, n-1), x);
	} else {
		llint t=pot(x, n/2);
		return mul(t, t);
	}
}

llint nck (llint nn, llint kk) {
	return mul(fact[nn], mul(inv[kk], inv[nn-kk]));
}

int main () {
	fact[0]=inv[0]=1;
	for (int i=1; i<MAXN-2; i++) {
		fact[i]=mul(fact[i-1], i);
		inv[i]=pot(fact[i], MOD-2);
	}
	cin >> n;
	for (int i=0; i<n+1; i++) {
		cin >> l[i];
		p[l[i]]++;
	}
	for (int i=1; i<=n; i++) {
		if (p[i]==2) {
			val=i;
			break;
		}
	}
	for (int i=0; i<n+1; i++) {
		if (l[i]==val) {
			x=i;
			break;
		}
	}
	for (int i=n; i>=0; i--) {
		if (l[i]==val) {
			y=i;
			break;
		}
	}
	llint dist=x+n-y;
	for (int i=1; i<=n+1; i++) {
		llint res=nck(n+1, i);
		if (dist>=i-1) res=sub(res, nck(dist, i-1));
		cout << res << endl;
	}
	return 0;
}







Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(auto (i) = (n)*0; (i) < (n); (i)++)
#define RNG(i, a, b) for(auto (i) = (a); (i) < (b); (i)++)
#define RBF(i, v) for(auto& (i) : (v))
#define ALL(x) (x).begin(), (x).end()

using LL = long long;
using UL = unsigned;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = static_cast<LL>(1e18) + 2;
const int INF = static_cast<int>(1e9) + 2;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }

std::vector<int64_t> inv, fact_inv, com;
void combination_init(int64_t k_max, int64_t mod, int64_t n = -1) {
	int64_t size = k_max + 5;
	inv = std::vector<int64_t>(size);
	fact_inv = std::vector<int64_t>(size);
	inv[1] = 1;
	fact_inv[0] = fact_inv[1] = 1;
	for (int64_t i = 2; i < size; i++) {
		inv[i] = mod - inv[mod % i] * (mod / i) % mod;
		fact_inv[i] = fact_inv[i - 1] * inv[i] % mod;
	}
	if (n >= 0) {
		com = std::vector<int64_t>(size);
		com[0] = 1;
		for (int64_t i = 1; i < size; i++) {
			com[i] = com[i - 1] * ((n - i + 1) * inv[i] % mod) % mod;
		}
	}
}

signed main() {
	LL x, y;
	cin >> x >> y;

	LL n1 = -1, n2 = 0;
	bool cant = true;
	while (n1 <= x) {
		n1++;
		LL x2 = x - n1, y2 = y - n1 * 2;
		if (x2 < 0 || y2 < 0) {
			continue;
		}
		if (x2 == 2 * y2) {
			cant = false;
			n2 = y2;
			break;
		}
	}

	if (cant) {
		col(0);
		return 0;
	}

	LL n = n1 + n2;
	combination_init(n1, MOD, n);
	col(com[n1]);
	return 0;
}

Measured memory_bytes: 13108
import Control.Applicative( (<$>))
import Control.Monad( replicateM)
import Data.List( sort)

main = do
    n_ <- readLn
    ss_ <- replicateM n_ readLn
    let
	perfect = sum ss_
	sortedSs = sort ss_

	exclude []	= 0
	exclude (s:ss)
	  | 0 /= s`rem`10   = perfect - s
	  | otherwise	    = exclude ss

    print $ if perfect `rem` 10 /= 0
		then perfect
		else exclude sortedSs

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

int N, M;
bool edge[10][10];

void input() {
  std::cin >> N >> M;
  for (int i = 0; i < M; i++) {
    int s, t;
    std::cin >> s >> t;
    edge[s-1][t-1] = true;
    edge[t-1][s-1] = true;
  }
}

int main() {
  std::memset(edge, 0, sizeof(edge));
  input();
  int cnt = 0;
  std::vector<int> v(N);
  for (int i = 0; i < N; i++) v[i] = i;
  
  do {
    int i = 0;
    while (edge[v[i]][v[i+1]]) {
      i++;
      if (i > N-2) break;
    }
    if (i == N-1) cnt++;
  } while (std::next_permutation(v.begin()+1, v.end()));
  
  std::cout << cnt << std::endl;
  
  
  return 0;
}


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

int N, M, K;
vector<int> edges[100000];
vector<pair<int, int> > blockships;
int group[100001] = {0}, cnt = 0;
int size[100001] = {0}, ans[100000] = {0};

void dfs(int u)
{
    group[u] = cnt;
    for (int i = 0; i < edges[u].size(); i++)
    {
        int v = edges[u][i];
        if (group[v] == 0)
        {
            dfs(v);
        }
    }
}

int main()
{
    cin >> N >> M >> K;
    for (int i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        edges[a].push_back(b);
        edges[b].push_back(a);
        ans[a]--, ans[b]--;
    }

    for (int i = 0; i < K; i++)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        blockships.push_back(make_pair(a, b));
    }
    
    for (int i = 0; i < N; i++)
    {
        if (group[i] == 0)
        {
            cnt++;
            dfs(i);
        }
    }

    for (int i = 0; i < N; i++)
    {
        size[group[i]]++;
    }

    for (int i = 0; i < N; i++)
    {
        ans[i] += size[group[i]] - 1;
    }

    for (int i = 0; i < K; i++)
    {
        int a = blockships[i].first, b = blockships[i].second;
        if (group[a] == group[b])
        {
            ans[a]--, ans[b]--;
        }
    }


    for (int i = 0; i < N; i++)
    {
        cout << ans[i] << " ";
    }
    // system("pause");
}

Measured memory_bytes: 8440
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (long long i = 0; i < n; i++)
#define RREP(i, n) for (long long i = n - 1; 0 <= i; i--)
#define FOR(i, start, end) for (long long i = start; i < end; i++)
#define RFOR(i, start, end) for (long long i = start - 1; 0 <= i; i--)
#define ALL(a) a.begin(), a.end()
using ll = long long;
using namespace std;
const int INF32       = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7        = 1'000'000'007;
const int MOD9        = 1'000'000'009;
template <class T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
void print() { std::cout << '\n'; }
template <class H, class... T> void print(H &&head, T &&... args) {
    std::cout << head;
    sizeof...(args) == 0 ? std::cout << "" : std::cout << ' ';
    print(std::forward<T>(args)...);
}
template <class T> void print(std::vector<T> &v) {
    for (int i = 0; i < v.size(); i++) {
        std::cout << v[i];
        i == v.size() - 1 ? std::cout << '\n' : std::cout << ' ';
    }
}
template <class T> void print(std::vector<std::vector<T>> &v) {
    for (int i = 0; i < v.size(); i++) {
        for (int j = 0; j < v[i].size(); j++) {
            std::cout << v[i][j];
            j == v[i].size() - 1 ? std::cout << '\n' : std::cout << ' ';
        }
    }
}

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

    string s;
    cin >> s;
    vector<int> num(4);
    REP(i, 4) { num[i] = s[i] - '0'; }
    REP(bit, (1 << 3)) {
        int sum    = num[0];
        string ans = to_string(num[0]);
        REP(i, 3) {
            if (bit & (1 << i)) {
                ans += "+" + to_string(num[i + 1]);
                sum += num[i + 1];
            } else {
                ans += "-" + to_string(num[i + 1]);
                sum -= num[i + 1];
            }
        }
        if (sum == 7) {
            ans += "=7";
            print(ans);
            return 0;
        }
    }

    return 0;
}

Measured memory_bytes: 256
a, b, e = int(input()), int(input()), int(input())

n = e*3
c = n - a - b
h = n - b - e
g = n - e - c
d = n - a - g
f = n - e - d
i = n - a - e
print(a,b,c)
print(d,e,f)
print(g,h,i)


Measured memory_bytes: 38384
#include<cstdio>
#include<algorithm>
const int N=100007;
int read(){int x;scanf("%d",&x);return x;}
int d[N],p[N],e[N],f[N],id[N],w[N*2];
int main()
{
    int n=read(),m=read();
    for(int i=1;i<=n;++i) d[p[i]=i]=read();
    std::sort(p+1,p+n+1,[](int i,int j){return d[i]<d[j];});
    for(int i=1,u,v;i<=m;++i)
	if(d[u=read()]==d[v=read()])
	{
	    if(!f[u]&&!f[v]) f[u]=1;
	    if(!f[u]) f[u]=-f[v];
	    if(!f[v]) f[v]=-f[u];
	    if(f[u]==-f[v]) w[i]=d[u];
	}
	else
	{
	    if(d[u]<d[v]) std::swap(u,v);
	    e[u]=v,id[u]=i;
	}
    for(int i=1,x;i<=n;++i)
	if(!f[x=p[i]])
	{
	    if(!e[x]) return puts("-1"),0;
	    f[x]=f[e[x]],w[id[x]]=d[x]-d[e[x]];
	}
    for(int i=1;i<=n;++i) putchar(f[i]>0? 'B':'W');
    for(int i=1;i<=m;++i) printf("\n%d",w[i]? w[i]:1000000000);
}


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

using namespace std;
map<string,int> mp;
map<string,int>::iterator itr;

int main()
{
   
    int n, q, val;
    string key;
    cin>>n;
    while(n--){
        cin>>q;
        switch (q)
        {
            case 0:
                cin>>key>>val;
                mp[key]=val;
                break;

            case 1:
                cin>>key;
                itr=mp.find(key);
                if(itr!=mp.end()) cout<<itr->second<<endl;
                else cout<<0<<endl;
                break;
            case 2:
                cin>>key;
                mp.erase(key);
                break;
        }
    }


    return 0;
}



Measured memory_bytes: 27720
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(){return +cin[cid++];}
function nextstr(){return cin[cid++];}
function nextbig(){return BigInt(cin[cid++]);}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(String(myOut));

function main(){
  var n = next();
  var a = nexts(3*n);
  a.sort((a,b)=>b-a);
  var ans = 0;
  for(var i = 0; i < n; i++){
    ans += a[i*2+1];
  }
  return ans;
}

Measured memory_bytes: 63292
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl = input.ReadLine().Split(' ');
        var a = int.Parse(spl[0]);
        var b = int.Parse(spl[1]);
        var c = int.Parse(spl[2]);

        var n = int.Parse(input.ReadLine());

        if (a >= b && a >= c) return a * Pow(2, n) + b + c;
        if (b >= a && b >= c) return b * Pow(2, n) + a + c;
        if (c >= a && c >= b) return c * Pow(2, n) + a + b;

        return 0;
    }

    static long Pow(long x, long n) {
        long ans = 1;
        while (n > 0) {
            if (n % 2 == 1) {
                ans = ans * x;
            }
            x = x * x;
            n /= 2;
        }
        return ans;
    }
}


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

int main() {
    int A, B, C, D, P;
    cin >> A >> B >> C >> D >> P;
    if (P * A <= (B + max(P - C, 0) * D)) cout << P * A << endl;
    else cout << (B + max(P - C, 0) * D) << endl;

    return 0;
}

Measured memory_bytes: 3096
X,Y,A,B,C=map(int,input().split())
p=sorted(map(int,input().split()))
q=sorted(map(int,input().split()))
r=sorted(map(int,input().split()))
ans=[]
ans+=p[A-X:]
ans+=q[B-Y:]
ans.sort()
j=0
k=0
for i in ans:
	if len(r)>1:
		k=r[-1]
	elif len(r)==1:
		k=r[0]
	else:
		break
	if i<k:
		ans[j]=r.pop()
		j+=1
	else:
		break
print(sum(ans))



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

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  
  for(int i = 0; i < N; i++){
    cin >> a.at(i);
  }
  
  int c = 1;
  int s = a.at(0);
  
  while(s != 2 && c < N){
    c++;
    s = a.at(s - 1);
  }
  
  if(c < N){
    cout << c << endl;
  }else{
    cout << -1 << endl;
  }
}


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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

bool p[100001];
ll sum[100001];

int main(){
  repl(i,2,100001)p[i]=true;
  for(int i=2;i<=100000;i++){
    if(p[i]){
      for(int j=i*2;j<=100000;j+=i)p[j]=false;
    }
  }
	repl(i,1,100001){
    if(i%2==1&&p[i]&&p[(i+2)/2]){
      sum[i+1]=1;
    }
  }
  rep(i,100000)sum[i+1]+=sum[i];

  ll q;
  cin>>q;
  while(q--){
    ll l,r;
    cin>>l>>r;
    cout<<sum[r+1]-sum[l]<<endl;
  }

	return 0;
}


Measured memory_bytes: 1536