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

using namespace std;

int main(void) {
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  vector<int> pattern(3);
  auto max = [](int a, int b){return (a > b) ? a : b;};
  auto min = [](int a, int b){return (a < b) ? a : b;};

  auto hoge = [](int a, int b, int x, int y) {
    if(a > b) {
      return (a - b) * x;
    } else {
      return (b - a) * y;
    }
  };
  pattern[0] = A * X + B * Y;
  pattern[1] = 2 * C * max(X, Y);
  pattern[2] = 2 * C * min(X, Y) + hoge(X, Y, A, B);
  //for(auto x: pattern) cout << x << endl;
  sort(pattern.begin(), pattern.end());
  cout << pattern[0] << endl;
  return 0;
}

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

using namespace std;

#define REP(i,n) for(int (i)=(0);(i)<(n);++i)
#define ll long long
#define INF 1000000000

int main()
{
	int n,k;
	cin >> n >> k;

	if((n+1)/2>=k)cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()
max = 0
lis = []
for i in range(N):
    X = S[0:i]
    Y=S[i:N]
    X = list(set(X))
    Y = list(set(Y))
    lis = list(set(X) & set(Y))
    l = len(lis)
    if(l>max):max=l

print(max)

Measured memory_bytes: 3064
n, h, *k = map(int, open(0).read().split())

a = 0; b = []
for i, j in zip(*[iter(k)]*2):
    a = max(a, i)
    b.append(j)
b = sorted(b, reverse = True)

ans = 0
while ans < n and b[ans] > a and h > 0:
    h -= b[ans]
    ans += 1

if h > 0: ans += (h + a - 1) // a
print(ans)

Measured memory_bytes: 25124
def main():
    N = int(input())
    S = input()

    count = 0

    for i in range(10):
        a = S.find(str(i))
        if a == -1:
            continue

        for j in range(10):
            b = S[a+1:].find(str(j))
            if b == -1:
                continue

            for k in range(10):
                if str(k) in S[a+b+2:]:
                    # print(i*100+j*10+k)
                    count += 1

    print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
import itertools
n = int(input())
S = "MARCH"
d = {s:0 for s in S}
ans = 0
for i in range(n):
  f = input()[0]
  if f in S:
    d[f] += 1
for x,y,z in itertools.combinations(d.keys(),3):
  ans += d[x] * d[y] * d[z]
print(ans)

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

int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  
  if (A+B == C+D) {
    cout << "Balanced" << endl;
  }
  else if (A+B > C+D) {
    cout << "Left" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

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

  ll ans = 0;
  vector<ll> v[11];
  v[0].push_back(0);

  rep(i, 10) {
    rep(j, v[i].size()) {
      ll tmp = v[i][j] * 10;

      if (tmp + 3 > n) break;
      v[i+1].push_back(tmp+3);
      if (tmp + 5 > n) break;
      v[i+1].push_back(tmp+5);
      if (tmp + 7 > n) break;
      v[i+1].push_back(tmp+7);
    }
  }

  rep(i, 10) {
    rep(j, v[i].size()) {
      string s = to_string(v[i][j]);
      if(s.find("3") == string::npos || s.find("5") == string::npos || s.find("7") == string::npos)
        continue;

      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


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

typedef long long ll;

#define REP(i,m,n) for(int i=(int)m; i < (int) n; ++i)
#define rep(i,n) REP(i,0,n)
#define all(a) (a).begin(), (a).end()

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

    int n, k; cin >> n >> k;
 
    int cnt = n-1;
    k--;
    cout << (cnt+k-1)/k << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<fstream>
#include <cmath>
#include <algorithm>
#include <stack>
#include <vector>
#include <random>
#include <unordered_set>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)

int main(){
    int N;
    cin >> N;
    FOR(i,0,50001){
        double A = (double)1.08*i;
        int x = A;
        if(x==N){
            cout << i << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
}


Measured memory_bytes: 256
def main():
    from sys import stdin
    from bisect import bisect_left

    readline = stdin.readline
    n, m = map(int, readline().split())
    data = [list(map(int, readline().split())) for _ in range(m)]
    t = [[] for _ in range(n)]

    for p, y in data:
        t[p - 1].append(y)

    for i in range(n):
        t[i].sort()

    for p, y in data:
        nth = bisect_left(t[p - 1], y) + 1
        print("%06d%06d" % (p, nth))

main()

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

long long n,k,num,total,arr[200001];

int main(){
	cin>>n>>k;
	for(long long i = 1;i <= n;i++){
		cin>>num;
		arr[i] = num;
	}
	sort(arr + 1,arr + n + 1);
	for(long long i = n;i >= 1;i--){
		if(k > 0){
			k--;
			continue;
		}else{
			total = total + arr[i];
		}
	}
	cout<<total<<endl;
}

Measured memory_bytes: 1792
n,ais,cumul,res =int(raw_input()),[0] + map(int,raw_input().split()) + [0],0,[]
for i in range(1,len(ais)):
	if i < len(ais) -1: res.append(-abs(ais[i] - ais[i-1]) - abs(ais[i+1] - ais[i]) + abs(ais[i+1] - ais[i-1]))
	cumul += abs(ais[i] - ais[i-1])
for v in res: print v + cumul

Measured memory_bytes: 92160
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

bool check_bingo(ll a, ll b, ll c)
{
    if (a == 0 && b == 0 && c == 0)
    {
        return true;
    }
    else
    {
        return false;
    }
}

int main()
{
    vector<vector<ll>> bingo = {};
    for (auto i = 0; i < 3; i++)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        bingo.push_back(vector<ll>{a, b, c});
    }

    ll n;
    cin >> n;

    vector<ll> bl = {};
    for (auto i = 0; i < n; i++)
    {
        ll b;
        cin >> b;
        bl.push_back(b);
    }

    for (auto b : bl)
    {
        for (auto i = 0; i < 3; i++)
        {
            for (auto j = 0; j < 3; j++)
            {
                if (bingo[i][j] == b)
                {
                    bingo[i][j] = 0;
                }
            }
        }
    }

    // 正解かチェック
    // 縦・横チェック
    for (auto i = 0; i < 3; i++)
    {
        // 横
        if (check_bingo(bingo[i][0], bingo[i][1], bingo[i][2]))
        {
            cout << "Yes" << endl;
            return 0;
        }

        // 縦
        if (check_bingo(bingo[0][i], bingo[1][i], bingo[2][i]))
        {
            cout << "Yes" << endl;
            return 0;
        }
    }

    // ななめ
    if (check_bingo(bingo[0][0], bingo[1][1], bingo[2][2]))
    {
        cout << "Yes" << endl;
        return 0;
    }

    if (check_bingo(bingo[0][2], bingo[1][1], bingo[2][0]))
    {
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
//bismillah
//author anaksoleh
//26 Dec 2019
#include <bits/stdc++.h>
using namespace std;

const int SIZE = 1e5 + 5;
int N;
bool computed[SIZE][4];
int memo[SIZE][4];
int arr[SIZE][4];

int solve(int row,int col)
{
    if(row == 1)return arr[row][col];
    if(computed[row][col])return memo[row][col];

    int best = 0;
    for(int i = 1 ; i <= 3 ; i++){
        if(i == col)continue;
        best = max(best,solve(row-1,i));    
    }
    memo[row][col] = best + arr[row][col];
    computed[row][col] = true;
    return memo[row][col]; 
}


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> N;
    for(int i = 1 ; i <= N ; i++){
        cin >> arr[i][1] >> arr[i][2] >> arr[i][3];
    }
    int ans = 0;
    for(int i = 1 ; i <= 3 ; i++) ans = max(ans,solve(N,i));
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 8448
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
      if(b&1)res = res * x % MOD;
      x = x * x % MOD;
      b>>=1;
    }
    return res;
  }

  ll modinv(ll x){
    return modpow(x, MOD-2);
  }

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  void in(t&x){
    cin >> x;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

int main(){
  int n = in();
  vector<int> ans(n+1,0);
  method(func,int,vector<int> line){
    int res = 0;
    int n = line.size();
    rep(i,n){
      rep(j,i,n){
        res += line[i] * line[j];
      }
    }
    return res;
  };
  for(int i=1;func({i})<=n;++i){
    for(int j=1;func({i,j})<=n;++j){
      for(int k=1;func({i,j,k})<=n;++k){
        ++ans[func({i,j,k})];
      }
    }
  }
  rep(i,1,n+1){
    cout << ans[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 3692
from collections import Counter


def main():
    """
    1<=N<=10^5: a_1 ... a_n
    0<=a<=10^5
    +1, -1, +0
    連続する3つの数値に対して、
    minに+1,中央に何もせず,maxに+1各操作をすると
    中央の個数が最大になる
    3つ揃わない場合もあるので、注意

    10^5で初期化 + 各数値の個数
    10^5とおりの数値についてa, a+1, a+2を想定して
        存在するものの個数をsum
    """
    N = int(input())
    counter = Counter(map(int, input().split()))
    n_max = 0

    def sort_func(t):
        return t[0]
    for a, n in sorted(counter.items(),
                       key=sort_func):

        temp_max = sum([
            counter.get(a - 1, 0),
            counter[a],
            counter.get(a + 1, 0)
        ])
        n_max = max(n_max, temp_max)
    print(n_max)

if __name__ == '__main__':
    main()


Measured memory_bytes: 16620
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (ll)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

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

    ll N;
    cin >> N;
    vector<P> job(N);
    rep(i,N){
        ll a, b;
        cin >> a >> b;
        job[i] = {b,a};
    }
    sort(ALL(job));

    ll now = 0;
    rep(i, N){
        now += job[i].second;
        if(now > job[i].first){
            print("No");
            return 0;
        }
    }

    print("Yes");

    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);


int main(){
    ll n,a;cin>>n>>a;
    ll x[n+1];rep(i,1,n)cin>>x[i];
    ll dp[n+1][n+1][2600];  //iまででj個選んで合計をkにする場合の数
    rep(i,0,n)rep(j,0,n)rep(k,0,2500)dp[i][j][k]=0;
    dp[0][0][0]=1;
    rep(i,1,n){
        rep(j,0,n){
            rep(k,0,2500){
                if(j==0 && k==0){
                    dp[i][j][k]=1;
                }else{
                    if(k-x[i]>=0){
                        dp[i][j][k]=dp[i-1][j-1][k-x[i]]+dp[i-1][j][k];
                    }else{
                        dp[i][j][k]=dp[i-1][j][k];
                    }
                }
            }
        }
    }
    ll ans=0;
    rep(i,1,n){
        ans+=dp[n][i][a*i];
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 53120
package main

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

func main() {

	numsStr := strings.Split(nextLine(), " ")
	A, _ := strconv.Atoi(numsStr[0])
	B, _ := strconv.Atoi(numsStr[1])
	X, _ := strconv.Atoi(numsStr[2])
	if X >= A && X <= A+B {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}

}

func nextLine() string {
	var sc = bufio.NewScanner(os.Stdin)
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;

int s[100005];
int dp[100005];
int main(void){
	int N,M;
	cin >> N >> M;
	for(int i=0;i<M;i++){
		int a;cin >> a;
		s[a]=1;
	}
	dp[0]=1;
	for(int i=1;i<=N;i++){
		if(s[i]!=1){
			if(i==1){ dp[i] = dp[i-1];}
			else {
				dp[i]=dp[i-1]+dp[i-2];
				dp[i]%=mod;
			}
		}else{
			dp[i]=0;
		}
	}
	cout << dp[N] << endl;
}

Measured memory_bytes: 1024
import sys
N = int(sys.stdin.readline().rstrip())
sec = []

for _ in range(N):
    x, l = map(int, sys.stdin.readline().rstrip().split())
    sec.append((x - l + 1, x + l - 1))

sec = sorted(sec, key=lambda x: x[1])
r = -10**10
ans = 0
for s, t in sec:
    if r + 1 < s:
        ans += 1
        r = t
print(ans)

Measured memory_bytes: 19028
def resolve():
    '''
    code here
    '''
    N, A, B, C, D = [int(item) for item in input().split()]
    S = input()


    if C < D:
        is_goal = True
        for i in range(A, D+1):
            if S[i-1:i+1] == '##':
                is_goal = False
                break
    else:
        is_goal = False
        for i in range(A, C+1):
            if S[i-1:i+1] == '##':
                is_goal = False

            if B <= i <= D:
                if S[i-2:i+1] == '...' :
                    is_goal = True

    print('Yes') if is_goal else print('No')

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9496
import sys
input = sys.stdin.readline
import collections
import bisect

def main():
    n = int(input())
    l = input_list()
    l.sort()
    ans = 0
    for i in range(n-2):
        for j in range(i+1, n-1):
            ind = bisect.bisect_left(l, l[i]+l[j])
            num = ind - 1 - j
            ans += num
    print(ans)


def input_list():
    return list(map(int, input().split()))


def input_list_str():
    return list(map(str, input().split()))


if __name__ == "__main__":
    main()


Measured memory_bytes: 42204
use std::io::stdin;
fn get_string() -> String {
    let mut s = String::new();
    stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

macro_rules! input {
    ($single:ty) => ( get_string().parse::<$single>().unwrap() );
    ($plural:ty,) => ({
        let line = get_string();
        line.split_whitespace().map(|v| v.parse::<$plural>().unwrap()).collect::<Vec<$plural>>()
    });
    ($($plural:ty),+) => ({
        let line = get_string();
        let mut iter = line.split_whitespace();
        ($(iter.next().unwrap().parse::<$plural>().unwrap()),+)
    });
    ($single:ty; $times:expr) => ( (0..$times).map(|_| input!($single)).collect::<Vec<$single>>() );
    ($($plural:ty),+; $times:expr) => ( (0..$times).map(|_| input!($($plural),+)).collect::<Vec<($($plural),+)>>() );
}

#[allow(dead_code)]
fn get_value<T: std::str::FromStr>() -> T {
    get_string().parse().ok().unwrap()
}
#[allow(dead_code)]
fn get_values_for<T: std::str::FromStr>(times: u64) -> Vec<T> {
    (0..times).map(|_| get_value()).collect()
}
#[allow(dead_code)]
fn get_vector<T: std::str::FromStr>() -> Vec<T> {
    get_string()
        .split_whitespace()
        .map(|v| v.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn get_vectors_for<T: std::str::FromStr>(times: u64) -> Vec<Vec<T>> {
    (0..times).map(|_| get_vector()).collect()
}

fn main() {
    let mut n = input!(i64);
    let mut ans = Vec::new();
    if n == 0 {
        ans.push(0)
    }
    while n != 0 {
        let m = (n % 2).abs();
        ans.push(m);
        if n < 0 && m == 1 {
            n = n / -2 + 1;
        } else {
            n = n / -2;
        }
    }
    println!(
        "{}",
        ans.iter().rev().map(i64::to_string).collect::<String>()
    );
}


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

int main(int argc, char const* argv[])
{
    int N,X;
    cin>>N>>X;
    int m[N];
    int counter=0;
    int gram=X;
    for (int i = 0; i < N; i++) {
        cin>>m[i];
        gram -= m[i];
        counter += 1;
    }

    sort(m, m+N);
    if(gram>m[0]){
        for(int j=gram-m[0]; gram>=m[0]; gram-=m[0]){
            counter+=1;
        }
    }
    cout<<counter<<endl;


    return 0;
}

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

int main(){
  int N;
  cin >> N;
  
  string keta = to_string(N);
  int cnt = 0;
  rep(i,keta.size()){
    if(0 == i%2 && (int)keta.size()-1 > i) cnt += 9*(pow(10,i));
    if(0 == i%2 && (int)keta.size()-1 == i) cnt += (N-pow(10,i)+1);
  }
  
  cout << cnt << endl;
}

Measured memory_bytes: 256
from collections import defaultdict
N, K, L = map(int, input().split())


class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.rank = [0] * n
        self.size = [1] * n

    # 検索
    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

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

        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
            self.size[y] += self.size[x]
            self.size[x] = 0
        else:
            self.par[y] = x
            self.size[x] += self.size[y]
            self.size[y] = 0
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # すべての頂点に対して親を検索する
    def all_find(self):
        for n in range(len(self.par)):
            self.find(n)


UF1 = UnionFind(N)
UF2 = UnionFind(N)

for k in range(K):
    p, q = map(int, input().split())
    p, q = p-1, q-1
    UF1.union(p, q)
for l in range(L):
    r, s = map(int, input().split())
    r, s = r-1, s-1
    UF2.union(r, s)

UF1.all_find()
UF2.all_find()

D = defaultdict(int)
for p1, p2 in zip(UF1.par, UF2.par):
    D[(p1, p2)] += 1

ans = [D[(p1, p2)] for p1, p2 in zip(UF1.par, UF2.par)]
print(*ans)


Measured memory_bytes: 53860
local h,w=io.read("n","n","l")
local map={}
for i=1,h do
    local s=io.read()
    for j=1,w do
        local a=s:sub(j,j)
        map[a]=(map[a] or 0)+1
    end
end

local count={}
for k,v in pairs(map) do
    count[v]=(count[v] or 0)+1
end

local g1=(h%2)*(w%2)
local g2=(h%2)*(w//2)+(w%2)*(h//2)
local g4=(h//2)*(w//2)

while g1>0 do
    local checker=false
    for i=1,10000 do
        if i%4==1 or i%4==3 then
            if count[i] and count[i]>0 then
                count[i]=count[i]-1
                count[i-1]=(count[i-1] or 0)+1
                checker=true
                g1=g1-1
            end
        end
    end
    if not checker then
        print("No")
        return
    end
end

while g4>0 do
    local checker=false
    for i=4,10000 do
        if i%2==0 then
            if count[i] and count[i]>0 then
                count[i]=count[i]-1
                count[i-4]=(count[i-4] or 0)+1
                checker=true
                g4=g4-1
            end
        end
    end
    if not checker then
        print("No")
        return
    end
end

while g2>0 do
    local checker=false
    for i=1,10000 do
        if i%2==0 then
            if count[i] and count[i]>0 then
                count[i]=count[i]-1
                count[i-2]=(count[i-2] or 0)+1
                checker=true
                g2=g2-1
            end
        end
    end
    if not checker then
        print("No")
        return
    end
end

print("Yes")

Measured memory_bytes: 2604
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int w, a, b;
    cin >> w >>  a >> b;
    if (a > b) swap(a, b);
    cout << max(0, b - (a + w));
}


Measured memory_bytes: 256
def main():
    input = sys.stdin.readline
    try:
        a,b,c,d = map(int, input().split())
        ans = min(b, d) - max(a, c)
        if ans > 0:
            print(ans)
        else:
            print(0)
        
    finally:
        input = None

import sys; sys.setrecursionlimit(50000)
if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
//it was hard to write
//so it should be hard to read
#include <bits/stdc++.h>
#define sz size
#define pb push_back
#define ll long long
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define last(x) (x).size() - 1
#define mp make_pair

using namespace std;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef double ld;

const int MAXN = 3e5 + 5;
const ll INF = 1e18 + 7;
const int inf = 1e9 + 7;
const double EPS = 1e-9;

string s;

int to_int(char a, char b, char c) {
	string str = "";
	str += a;
	str += b;
	str += c;
	int res = 0;
	// cout << str << '\n';
	for (int i = 0; i < str.sz(); i++) {
		res *= 10;
		res += (str[i] - '0');
	}
	return res;
}

int main() {
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout.precision(9);
    cout << fixed;
	cin >> s;
	int mn = inf;
	for (int i = 0; i < s.sz() - 2; i++) {
		int n = to_int(s[i], s[i + 1], s[i + 2]);
		mn = min(mn, abs(n - 753));
	}
	cout << mn;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000           // 2000000000
#define LINF 1000000000000000000 // 9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979

//.size()はunsigned int　0-1をするとオーバーフローする

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

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

int main(void) {
    char s;

    cin>>s;

    cout<<(char)(s+1)<<endl;

    
}


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

static const double pi = 3.141592653589793;

int main()
{
  double A,B,H,M ;
  cin>>A>>B>>H>>M ;
  
  double ang_M=M/30 ;
  double ang_H=((60*H)+M)/360 ;
  
  double X ;
  if(ang_M>ang_H) X=cos((ang_M-ang_H)*pi) ;
  else X=cos((ang_H-ang_M)*pi) ;
  
  
  double ans=A*A+B*B-2*A*B*X ;
  printf("%.9lf",pow(ans,0.5)) ;
  
  return 0 ;
}


Measured memory_bytes: 4352
#include <stdio.h>
int main(void){
	int a,b;
	scanf("%d%d",&a,&b);
	if(a==b){
		printf("Draw");
	}else if(a>b){
		if(b==1){
			printf("Bob");
		}else{
			printf("Alice");
		}
	}else{
		if(a==1){
			printf("Alice");
		}else{
			printf("Bob");
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n;
    cin >> n;
    int t,a;
    int ans;
    double saiteki=10000000;

    vector<int> h(n);
    cin >> t >> a;
    rep(i,n) cin >> h[i];
    
    rep(i,n){
        double heikin;
        heikin = t - h[i]*0.006;
        if(abs(heikin-a)<saiteki){
            saiteki = abs(heikin-a);
            ans =  i+1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define all(x) x.begin(),x.end()
#define sz(x) (ll)x.size() 

char c[50][50],mat[50][50];
int main()
{
    ios_base::sync_with_stdio(false);
	ll n,i,j,k,x,y,t,m;

	cin >> x >> y >> k;

	for(i=0;i<x;i++)
	{
		string s;
		cin >> s;
		for(j=0;j<y;j++)
			mat[i][j]=s[j];
	}

	ll ans=0;
	for(i=0;i<(1<<x);i++)
	{

		for(j=0;j<(1<<y);j++)
		{
			// cout<<i<<" "<<j<<endl;
			for(ll ii=0;ii<x;ii++)
				for(ll jj=0;jj<y;jj++)
					c[ii][jj]=mat[ii][jj];
			for(ll ii=0;ii<x;ii++)
			{
				if( i&(1<<ii) )
				{
					for(ll jj=0;jj<y;jj++)
						c[ii][jj]='.';
				}
			}
			for(ll ii=0;ii<y;ii++)
			{
				if( j&(1<<ii) )
				{
					for(ll jj=0;jj<x;jj++)
						c[jj][ii]='.';
				}
			}

			// if(i==1 && j==2)
			// {
			// 	for(ll ii=0;ii<x;ii++)
			// 	{
			// 		for(ll jj=0;jj<y;jj++)
			// 			cout<<c[ii][jj];
			// 		cout<<endl;
			// 	}
			// }

			ll g=0;
			for(ll ii=0;ii<x;ii++)
				for(ll jj=0;jj<y;jj++)
					if(c[ii][jj]=='#')g++;
			if(g==k)
				ans++;	
		}
	}

	cout<<ans<<endl;

}

Measured memory_bytes: 3656
N, X, Y = map(int, input().split())
count = [0] * (N-1)
for i in range(N):
    i += 1
    for j in range(N-i):
        j += i + 1
        if i < j:
            normal = j-i
            xtoy = abs(X-i) + 1 + abs(Y-j)
            ytox = abs(Y-i) + 1 + abs(X-j)
            minRoute = min([normal, xtoy, ytox])
            count[minRoute-1] += 1
for c in count:
    print(c)

Measured memory_bytes: 46428
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main(){ 
  int A,B,C,D,E,T;
  cin >> A >> B >> C >> D >> E;
  T = (60*C + D) - (60*A + B);
  cout << T - E << endl;
  
      
}


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

int S(int n)
{
    int result = 0;
    string str;
    str = to_string(n);
    for (char i : str)
    {
        result += (int)(i - '0');
    }

    return result;
}

int main()
{
    int n;
    string msg;
    cin >> n;
    msg = n % S(n) == 0 ? "Yes" : "No";

    cout << msg << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b;
  cin>>a>>b;
  if(b>0 && a>0)cout<<"Positive";
  else if(a<=0 && b>=0)cout<<"Zero";
  else{
  	if((b-a+1)%2==0)cout<<"Positive";
    else cout<<"Negative";
  }
}

Measured memory_bytes: 256
N,M = map(int,input().split())
ab = []
for i in range(N):
    ab.append(list(map(int,input().split())))

ab.sort(key=lambda x: x[0])

total_amount = 0
total_price = 0
for price,amount in ab:
    bought = min(amount,M-total_amount)
    total_amount += bought
    total_price += price * bought

print(total_price)

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

using namespace std;

bool dealed[1010];
int cnt[1010] = {};
set<int> st;

int main() {
    string s;
    bool flag = false;

    while (getline(cin, s)) {
        if (s == "") {
            flag = true;
            continue;
        }

        int no;
        s = s.substr(0, s.find(','));
        no = atoi(s.c_str());
        if (flag) {
            if (st.find(no) != st.end()) dealed[no] = true;
        } else
            st.insert(no);
        cnt[no]++;
    }

    for (int i = 1; i <= 1000; i++) {
        if (!dealed[i]) continue;
        cout << i << " " << cnt[i] << endl;
    }

    return 0;
}


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

int main() {
    char c;  
    cin >> c;
    string str = "aiueo";
    int p = 0;
    for (int i =0; i < str.size(); i++) {
        if (str.at(i) == c) {
            p++;
        }
    }

    if (p==0) {
        cout << "consonant" << endl;
    }else {
        cout << "vowel" << endl;
    }

}

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

using namespace std;

int cntPos(int a){
	if(a <= 0) return 0;
	return a;
}

int main(){
	int a, b;
	scanf("%d%d", &a, &b);
	if(a <= 0 && b >= 0){
		printf("Zero\n");
		return 0;
	}
	int all = b - a + 1;
	int pos = cntPos(b) - cntPos(a - 1);
	int neg = all - pos;
	if(neg % 2 == 0){
		printf("Positive\n");
	}else{
		printf("Negative\n");
	}
	return 0;
}


Measured memory_bytes: 128
import java.io.BufferedReader;
        import java.io.IOException;
        import java.io.InputStreamReader;
        import java.lang.reflect.Array;
        import java.math.BigInteger;
        import java.util.*;
        import java.lang.*;

public class  Main {
    static class FastReader{
        BufferedReader br;
        StringTokenizer st;

        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next(){
            while(st==null || !st.hasMoreElements()){
                try{
                    st=new StringTokenizer(br.readLine());
                }
                catch(IOException e){
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt(){
            return Integer.parseInt(next());
        }

        Long nextLong(){
            return Long.parseLong(next());
        }

        double nextDouble(){
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str="";
            try{
                str=br.readLine();
            }
            catch(IOException e){
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String[] args) {
        FastReader in = new FastReader();
        int n=in.nextInt();


        if(n%10==7 || (n/10)%10==7 || (n/100)%10==7){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


Measured memory_bytes: 32492
public class Main {


  private static void solve() {
    int n = ni();
    int m = ni();
    int[] s = na(n);
    int[] t = na(m);

    int mod = (int) 1e9 + 7;

    long[][] dp = new long[n + 1][m + 1];
    for (int i = 0; i <= n; i ++) {
      dp[i][0] = 1;
    }
    for (int j = 0; j <= m; j ++) {
      dp[0][j] = 1;
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        dp[i][j] += dp[i - 1][j];
        dp[i][j] += dp[i][j - 1];
        dp[i][j] += mod - dp[i - 1][j - 1];

        if (s[i - 1] == t[j - 1]) {
          dp[i][j] += dp[i - 1][j - 1];
        }
        dp[i][j] %= mod;
      }
    }
    System.out.println(dp[n][m]);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 82388
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int maxn=2e6+5;
const int mod=1e9+7;
inline ll fastpow(ll a,ll b) {
	ll ans=1;
	for(;b;b>>=1,a=a*a%mod) if(b&1) ans=ans*a%mod;
	return ans;
}
ll fac[maxn]={1},ifac[maxn],inv[maxn]={0,1};
inline ll C(ll n,ll m) {
	return fac[n]*ifac[n-m]%mod*ifac[m]%mod;
}
inline ll A(ll n,ll m) {
	return fac[n]*ifac[n-m]%mod;
}
inline void init() { //calculate the inversion ,factorial and inversion of factorial
	for(int i=2;i<maxn;++i) inv[i]=(mod-mod/i)*inv[mod%i]%mod;
	for(int i=1;i<maxn;i++) fac[i]=fac[i-1]*i%mod;
	ifac[maxn-1]=fastpow(fac[maxn-1],mod-2);
	for(int i=maxn-2;~i;i--) ifac[i]=ifac[i+1]*(i+1)%mod;
}
int main() {
    init();
    int k,n;string s;cin>>k>>s;n=s.length();
    ll ans=0;
    for(int i=n;i<=n+k;i++) {
    	ans=ans+C(i-1,n-1)*fastpow(25,i-n)%mod*fastpow(26,n+k-i)%mod;
    	ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 52176
#include <bits/stdc++.h>
using namespace std;
int main () {
  string S;
  cin >> S;
  int month = (S.at(5) - '0') * 10 + (S.at(6) - '0');
  int day = (S.at(8) - '0') * 10 + (S.at(9) - '0');
  if(month <= 4 && day <= 30)cout << "Heisei" << endl;
  else cout << "TBD" << endl;
  return 0;
}


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

using namespace std;

int main() {
    string s, t;
    bool flag = false;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());
   
    if (s < t)
        cout << "Yes";
    else
        cout << "No";
    
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	static int N, K;
	static int[][] g;

	public static void main(String[] args) {
		while (true) {
			N = sc.nextInt();
			K = sc.nextInt();
			if (N == 0) break;
			sc.nextLine();
			g = new int[N][N];
			for (int[] a : g) {
				Arrays.fill(a, Integer.MAX_VALUE);
			}
			for (int i = 0; i < K; ++i) {
				int t = sc.nextInt();
				int a = sc.nextInt() - 1;
				int b = sc.nextInt() - 1;
				if (t == 0) {
					System.out.println(calc(a, b));
				} else {
					int c = sc.nextInt();
					g[a][b] = g[b][a] = Math.min(g[a][b], c);
				}
			}
		}
	}

	static int calc(int start, int goal) {
		PriorityQueue<State> q = new PriorityQueue<State>();
		q.add(new State(start, 0));
		int[] best = new int[N];
		Arrays.fill(best, Integer.MAX_VALUE);
		while (!q.isEmpty()) {
			State cur = q.poll();
			if (cur.pos == goal) return cur.cost;
			for (int i = 0; i < N; ++i) {
				if (g[cur.pos][i] == Integer.MAX_VALUE) continue;
				int nc = cur.cost + g[cur.pos][i];
				if (nc < best[i]) {
					q.add(new State(i, nc));
					best[i] = nc;
				}
			}
		}
		return -1;
	}

	static class State implements Comparable<State> {
		int pos, cost;

		State(int pos, int cost) {
			this.pos = pos;
			this.cost = cost;
		}

		public int compareTo(State o) {
			return this.cost - o.cost;
		}
	}

}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
const ll ATCODER_AMARI = 1000000007; //10^9 + 7
const ll INF = 10000000000000;

//階乗関数　ATCODER_AMARIに注意
ll factorial(ll k){
  ll sum = 1;
  for(int i = 1 ; i < k + 1; i++) {
    sum *= i;
    //sum = sum % ATCODER_AMARI;
  }
  return sum;
}

int main() {
  ll a,b,c;
  cin >> a >> b >> c;
  ll x,y;
  cin >> x >> y;

  ll ans_money = 0;

  ll tmp_ans_money = INF;
  
  if(a + b >= 2 * c) {

    tmp_ans_money = 0;

    while(x != 0 && y != 0) {
      ans_money += 2 * c;
      x--;
      y--;
    }

    //cout << ans_money << endl;

    tmp_ans_money = ans_money + x * 2 * c + y * 2 * c;
  }

  ans_money += x * a;
  ans_money += y * b;

  ans_money = min(ans_money, tmp_ans_money);

  cout << ans_money << endl;
}


Measured memory_bytes: 3620
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

int main() {
	ll n,x,ans = 0;
	cin >> n >> x;

	ans += x + (n - x);

	ll wara = n - x,waru = x;
	ll waraSub,waruSub;
	while(waru){
		if(wara % waru == 0){
			ans += 2*waru*(wara/waru) - waru;
			break;
		}else{
			ans += 2*waru*(wara/waru);
		}
		waraSub = waru;
		waruSub = wara % waru;

		waru = waruSub;
		wara = waraSub;

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

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>

using namespace std;
const int maxn=2e5+5;
typedef long long ll;
unordered_map<int,bool>mp;
int main(){
    int n;
	cin>>n;
	int x;
	for(int i=0;i<n;i++){
        scanf("%d",&x);
		if(mp[x]==0)
		mp[x]=1;
		else{
			puts("NO");
			return 0;
		}
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 8060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

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

    int n = 100010;
    bool prime[100010];
    rep(i, 0, n + 1) prime[i] = true;
    prime[0] = prime[1] = false;
    for (int i = 2; i * i <= n; i++) {
        if (!prime[i]) continue;
        for (int j = i + i; j <= n; j += i) {
            prime[j] = false;
        }
    }

    int sum[n + 2] = {};
    rep(i, 1, n + 2) {
        sum[i] += sum[i - 1] + (int)(prime[i - 1] && prime[i / 2]);
    }

    rep(i, 0, q) {
        int l, r;
        cin >> l >> r;
        cout << sum[r + 1] - sum[l] << endl;
    }
    return 0;
}


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

typedef long long ll;

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

    int n, m;
    cin >> n >> m;

    int total = 0;
    for (int i = 0; i < m; i++) {
        int time;
        cin >> time;
        total += time;
    }

    cout << max(-1, n - total) << "\n";
}


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

int main(){
	int a,b;
	cin>>a>>b;
	if(a==1) a=14;
	if(b==1) b=14;
	if(a>b) cout<<"Alice"<<endl;
	if(a<b) cout<<"Bob"<<endl;
	if(a==b) cout<<"Draw"<<endl;
	return 0;

}


Measured memory_bytes: 384
#include <stdio.h>
int main(void) {
	long long a, b, k;
	scanf("%lld%lld%lld", &a, &b, &k);
	if (a >= k)
		printf("%lld %lld", a - k, b);
	else if (a + b - k >= 0)
		printf("0 %lld", a + b - k);
	else
		printf("0 0");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int m = 8; //10のm乗
  
  int digit = 1;
  for (int i = 0; i < m; i++) {
      digit *= 10;
  }
  
  int SUM = 0;
  int d1 = N;
  for (int i = m; i >= 0; i--) {
    int d0;
    
    d1 = d1 % (digit * 10);
    d0 = d1 / digit;
    SUM += d0;
    digit /= 10;
  }
  if (N % SUM == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        sc.close();

        Map<String, Integer> sMap = new HashMap<String, Integer>();
        for (int i = 0; i < S.length(); i++) {
            String s = S.substring(i, i + 1);
            Integer sCount = 1;
            if (sMap.containsKey(s)) {
                sCount = sMap.get(s) + 1;
            }
            sMap.put(s, sCount);
        }

        if (sMap.size() != 2) {
            System.out.println("No");
            return;
        }

        for (String s : sMap.keySet()) {
            if (sMap.get(s) == 2) {
                System.out.println("Yes");
                return;
            } else {
                System.out.println("No");
                return;
            }
        }

    }
}

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

const int DIM = 100005;

int arr[DIM];
long long dp[DIM][2];

int main(void)
{
    int n, p;
    cin >> n >> p;
    
    for (int i = 1; i <= n; ++i) {
        cin >> arr[i]; arr[i] &= 1;
        
        dp[i][0] = dp[i - 1][0] + dp[i - 1][0 ^ arr[i]];
        dp[i][1] = dp[i - 1][1] + dp[i - 1][1 ^ arr[i]];
        
        dp[i][arr[i]]++;
    }
    
    cout << dp[n][p] + (p == 0) << endl;
    return 0;
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-

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

count = 0

def f(l):
    global count

    # 終了条件
    if l == []:
        del l
        return

    # 再帰
    min_num = min(l)
    if min(l) > 0:
        count += min(l)
        l = list(map(lambda x: x-min(l), l))
    min_list = [i for i, x in enumerate(h) if x == min(h)]
    l = [l[:l.index(0)], l[l.index(0)+1:]]
    f(l[0])
    f(l[1])

f(h)
print(count)


Measured memory_bytes: 3188
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
        new Main().run();
    }
	public void run(){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			int n = scan.nextInt();
			int m = scan.nextInt();
			int p = scan.nextInt();
			if(n == 0 && m == 0 && p == 0){
				break;
			}
			int sum = 0;
			int a = 0;
			m--;
			for(int i = 0;i < n;i++){
				int t = scan.nextInt();
				sum += t;
				if(i == m){
					a = t;
				}
			}
			sum *= 100 - p;
			System.out.println((a==0)?0:sum/a);
		}
	}
}

Measured memory_bytes: 27876
import sys
input = sys.stdin.readline

import heapq

def main(): 

    S=list(input().split())
    S=list(S[0])
    if 0 < int(S[0]+S[1]) <= 12 and 0 < int(S[2]+S[3]) <= 12:
        print("AMBIGUOUS")
    elif 0 < int(S[0]+S[1]) <= 12:
        print("MMYY")
    elif 0 < int(S[2]+S[3]) <= 12:
        print("YYMM")
    else:
        print("NA")


if __name__ == "__main__":
    main()
    

Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
N = int(input())
A_list = list(map(int, input().split()))

ans_dict = {}
for i in range(N):
    ans_dict[A_list[i]] = i + 1

ans_list = []
for i in range(N):
    ans_list.append(ans_dict[i + 1])
print(" ".join(map(str, ans_list)))

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

#define pi 3.14159265358979323846
#define ll long long


int main()
{
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    long double hdeg=h*30;
    long double mdeg=m*6;
    hdeg+=mdeg/12;
    long double findeg=abs(hdeg-mdeg);
    long double cosDeg=cos(findeg*pi/180);
    long double aSqr=a*a;
    long double bSqr=b*b;
    long double c=sqrt(aSqr+bSqr-2*a*b*cosDeg);
    cout<<fixed<<showpoint;
    cout<<setprecision(20);
    cout<<c<<endl;


}


Measured memory_bytes: 4108
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string S;
    cin >> S;
    if (S.size() % 2 == 1) {
        cout << "No" << endl;
        return 0;
    }

    for (int i = 0; i < S.size(); i += 2) {
        if (S.substr(i, 2) == "hi") {
            continue;
        } else {
            cout << "No" << endl;;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int lim = 1e3+7;
const int mod = 1e9+7;
int a[lim][lim];

int main(){
    int m,n;
    cin>>m>>n;
    char grid[m+1][n+1];
    for(int i=1;i<=m;i++){
        for(int j=1;j<=n;j++){
            cin>>grid[i][j];
        }
    }
    bool f=false;
    for(int j=1;j<=n;j++){
        if(grid[1][j]=='#') f=true;
        if(!f) a[1][j]=1;
        else a[1][j]=0;
    }
    f=false;
    for(int i=1;i<=m;i++){
        if(grid[i][1]=='#') f=true;
        if(!f) a[i][1]=1;
        else a[i][1]=0;

    }
    for(int i=2;i<=m;i++){
        for(int j=2;j<=n;j++){
            if(grid[i][j]=='.'){
                a[i][j] = a[i-1][j]%mod + a[i][j-1]%mod;
                a[i][j]%=mod;
            }
            else a[i][j]=0;
        }
    }
    cout<<a[m][n]%mod;
    return 0;
}


Measured memory_bytes: 5120
import Control.Monad (replicateM)
import Data.List (sortBy)

conv [a, b] = (a, b)

solve k (t:ts) =
  let v = (k - snd t) in
    if v <= 0
      then fst t
      else solve v ts

main = do
  [n, k] <- fmap read <$> words <$> getLine :: IO [Int]
  ts <- fmap conv <$> fmap (fmap read) <$> fmap words <$> replicateM n getLine :: IO [(Int, Int)]
  putStrLn . show . solve k . sortBy (compare) $ ts


Measured memory_bytes: 92540
k = int(input())
if k == 1:
    print('ACL')
elif k == 2:
    print('ACLACL')
elif k == 3:
    print('ACLACLACL')
elif k == 4:
    print('ACLACLACLACL')
else:
    print('ACLACLACLACLACL')


Measured memory_bytes: 9144