akhauriyash/Code-Regression huggingface dataset:
N, K = map(int, input().split())
A = list(map(int, input().split()))

lenA = len(A)
for i in range(K):
    B = [0 for _ in range(lenA)]
#    print(B)
    for j in range(lenA):
        num = A[j]
#        print(j, num)
        if j - num >= 0:
            B[max(0, j - num)] += 1
        else:
            B[0] += 1
        if j + num + 1 < lenA:
            B[min(lenA, j + num + 1)] -= 1
#        print(j, B)
    for i in range(1, lenA):
        B[i] = B[i-1] + B[i]
    if all([a == b for a, b in zip(A,B)]):
#        print('same')
        break
    else:
        A = B
#print(i+1)
print(' '.join(map(str, A)))

Measured memory_bytes: 183468
S = input()
#複数の定義はまとめられる
cntA, cntB = 0, 0

for i, t in enumerate(S):
    if i%2 == 0:
        if t == '0': #標準入力Sはstr型だから0ではなく'0'のようにする
            cntA += 1
        else:
            cntB += 1
    else:
        if t == '1':
            cntA += 1
        else:
            cntB += 1
print (min(cntA, cntB)) 

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

vector<bool> vec(10,true);

int solve(int val,int N,bool flag){
    if(val>=N) return val;
    int ans = INT_MAX;
    if(flag){
        for(int i=1;i<10;++i){
            if(vec[i]==true) ans = min(ans,solve(val*10 +i,N,false));
        }
    }
    else{
        for(int i=0;i<10;++i){
            if(vec[i]==true) ans = min(ans,solve(val*10 +i,N,false));
        }
    }
    return ans;
}

int main(){
    int N,k,t;
    cin>>N>>k;
    for(int i=0;i<k;++i){
        cin>>t;
        vec[t]=false;
    }
    cout<<solve(0,N,true);
    return 0;
}


Measured memory_bytes: 256
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 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, 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")
    };
}

fn main() {
    input! {
        v: [i32; 3],
    }
    v.sort();
    let res = v[2] * 10 + v[1] + v[0];
    println!("{}", res);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(x) x.begin(), x.end()
#define mod 1000000007
typedef long long ll;

int main(){
  string str;
  cin >> str;
  int left = 0, right = 0;
  ll sum = 0;
  bool reset = true;
  rep(i, str.length()){
    if(str[i] == '<'){
      if(reset){
        if(left == right){
          for(int j=0; j<=left-1; j++){
            sum += j*2;
          }
          sum += left;
        }else{
          int big = max(left, right);
          int small = min(left, right);
          for(int j=0; j<=big; j++){
            sum += j;
          }
          for(int j=0; j<=small-1; j++){
            sum += j;
          }
        }
        left = 1;
        right = 0;
        reset = false;
      }else{
        left++;
      }
    }else{
      right++;
      reset = true;
    }
  }
  if(left == right){
    for(int j=0; j<=left-1; j++){
      sum += j*2;
    }
    sum += left;
  }else{
    int big = max(left, right);
    int small = min(left, right);
    for(int j=0; j<=big; j++){
      sum += j;
    }
    for(int j=0; j<=small-1; j++){
      sum += j;
    }
  }
  cout << sum << endl;
}




Measured memory_bytes: 900
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();

		// Nが条件に合致するかどうかのフラグ
		boolean flg = false;

		// i * j = N となるようなi,jを全探索する
		for (int i = 1; i <= 9; i++) {
			for (int j = 1; j <= 9; j++) {
				if (i * j == N) {
					flg = true;
					break;
				}
			}
			if (flg) {
				break;
			}
		}
		if (flg) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

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

int main() {
    string s,t;
    set<string> r;
    int K;
    cin >> s >> K;

    rep(i,K)
        rep(j,s.size()-i)
            r.insert(s.substr(j,i+1));

    for(auto p : r)
        if(--K == 0) {
            cout << p << endl;
            return 0;
        }
}

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

int main(){
	int x,y;
	while(cin >> x >> y){
		if(x < y){
			x^=y;
			y^=x;
			x^=y;
		}
		while(y){
			x %= y;
			if(x < y){
				x^=y;
				y^=x;
				x^=y;
			}
		}
		cout << x << endl;
	}
}

Measured memory_bytes: 1160
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

fn main() {
    input! {
        n: usize,
        mut a: [u64;n]
    }

    a.sort();
    let mut ans: Vec<u64> = Vec::new();
    let mut exclude: HashSet<u64> = HashSet::new();

    for i in a {
        let mut flag = false;

        if ans.last() == Some(&i) {
            exclude.insert(i);
            continue;
        }

        let divs = divisor(i);
        for v in divs {
            if ans.binary_search(&v).is_ok() {
                flag = true;
                break;
            }
        }

        if !flag {
            ans.push(i);
        }
    }

    println!("{}", ans.len() - exclude.len());
}

fn divisor(n: u64) -> Vec<u64> {
    let mut res = vec![];
    let mut i = 1;

    while i * i <= n {
        if n % i == 0 {
            res.push(i);
            if i != n / i {
                res.push(n / i);
            }
        }
        i += 1;
    }

    res.sort();
    res
}


Measured memory_bytes: 7072
def gcd(x, y):
    if y == 0:
        return x
    return gcd(y, x%y)

def lcm(x, y):
    return x*y // gcd(x, y)


N_len_S, M_len_T = map(int, input().split())
S = input()
T = input()
g = gcd(N_len_S, M_len_T)
l = lcm(N_len_S, M_len_T)

ans = l
for k in range(g):
    # S[i]. T[j] : 文字列 X を構成したとき重なる文字。これらが等しければよい数字。
    i = N_len_S // g * k
    j = M_len_T // g * k
    if S[i] != T[j]:
        ans = -1
        break
print(ans)


Measured memory_bytes: 3316
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstddef>
#include<queue>
#include<math.h>
#include<iomanip>
using namespace std;

int main()
{
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for(int i = 0; i < s.size(); ++i){
        if(s.at(i) != t.at(i)) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3812
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define PI 3.14159265358979

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int i;
	ll ans,cnt[26];
	fill(cnt,cnt+26,0ll);
	string a;
	cin >> a;
	ans = a.l_ength();
	ans *= (ans-1);
	ans /= 2;
	++ans;
	for(i=(a.l_ength()-1); i>=0; --i){
		++cnt[a[i]-'a'];
	}
	for(i=0; i<26; ++i){
		if(cnt[i]){
			ans -= (cnt[i]*(cnt[i]-1))/2;
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 640
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
ll mod = 1e9+7 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}

int main(){
	ll n ; cin >> n ;
	vvll b(200000,vll(0)) ;
	vll dp(n+1,0) ;
	dp.at(0) = 1 ;
	for(int i=1;i<=n;i++){
		ll c ; cin >> c ;
		c-- ;
		dp.at(i) += dp.at(i-1) ;
		b.at(c).push_back(i) ;
		if(b.at(c).size()>=2&&i-1>b.at(c).at(b.at(c).size()-2)){
			dp.at(i) += dp.at(b.at(c).at(b.at(c).size()-2)) ;
		}
		dp.at(i) %= mod ;
	}
//	for(auto i:dp) cout << i << " " ; cout << endl ;
	cout << dp.at(n) << endl ;
//	cout << mod << endl ;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,i;
  cin>>n;
  int a[n],b[n];
  for(i=0;i<n;i++){
    cin>>a[i];
    b[i]=a[i];
  }
  sort(a,a+n);
  for(i=0;i<n;i++){
    if(b[i]==a[n-1]){
      cout<<a[n-2]<<endl;
    }else{
      cout<<a[n-1]<<endl;
    }
  }
}


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

string s3[3] = { "aab", "c.b", "cdd" };
string s4[4] = { "aacd", "bbcd", "efgg", "efhh" };
string s5[5] = { "..abc", "..abc", "ddeff", "gge.h", "aabbh" };
string s[1009];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	if (n == 2) {
		cout << -1 << '\n';
		return 0;
	}
	if (n == 7) {
		cout << ".aabbcc" << '\n' << "a....dh" << '\n' << "a....dh" << '\n' << "bddee.." << '\n' << "bff.gg." << '\n' << "c..i..j" << '\n' << "c..i..j" << '\n';
		return 0;
	}
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			s[i] += '.';
	if (n == 11) {
		for (int i = 0; i < 3; i++)
			for (int j = 0; j < 3; j++)
				s[i][j] = s3[i][j];
		for (int i = 3; i < n; i += 4) {
			for (int j = 0; j < 4; j++)
				for (int k = 0; k < 4; k++)
					s[i + j][i + k] = s4[j][k];
		}
		int t = 'k';
		for (int i = 3; i < n; i += 2)
			for (int j = 0; j < 3; j++) {
				s[i][j] = s[i + 1][j] = s[j][i] = s[j][i + 1] = t;
				t++;
			}
	}
	else if (n % 3 == 0) {
		for (int i = 0; i < n; i += 3) {
			for (int j = 0; j < 3; j++)
				for (int k = 0; k < 3; k++)
					s[i + j][i + k] = s3[j][k];
		}
	}
	else {
		int t = 0;
		while (t < n) {
			if ((n - t) % 4 != 0) {
				for (int i = 0; i < 5; i++)
					for (int j = 0; j < 5; j++)
						s[t + i][t + j] = s5[i][j];
				t += 5;
			}
			else {
				for (int i = 0; i < 4; i++)
					for (int j = 0; j < 4; j++)
						s[t + i][t + j] = s4[i][j];
				t += 4;
			}
		}
	}
	for (int i = 0; i < n; i++)
		cout << s[i] << '\n';
	return 0;
}

Measured memory_bytes: 2304
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int a[4]={};
  int one=0,n=0,se=0,fo=0;
  for(int i=0;i<=3;i++){
    cin>>a[i];
    if(a[i]==1) one++;
    else if(a[i]==9) n++;
    else if(a[i]==7) se++;
    else if(a[i]==4) fo++;
  }

  if(one==1&&n==1&&se==1&&fo==1) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;

  return 0;
}


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

int main(int argc, const char * argv[])
{
    int n;
    while (cin >> n) {
        int cnt = 0;
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                for (int k = 0; k < 10; k++) {
                    for (int l = 0; l < 10; l++) {
                        if (i+j+k+l == n) {
                            cnt++;
                        }
                    }
                }
            }
        }
        cout << cnt << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>

int main() {
    unsigned long answer = 0;
    unsigned long N = 0, num_passenger[5] = {0, 0, 0, 0, 0}, min_passenger = 0;

    // input
    std::cin >> N;
    for (int i = 0; i < 5; i++) {
        std::cin >> num_passenger[i];
    }

    // process
    min_passenger = num_passenger[0];
    for (int i = 1; i < 5; i++) {
        if (num_passenger[i] < min_passenger) {
            min_passenger = num_passenger[i];
        }
    }

    answer += 4;
    answer += N / min_passenger;
    if ((N % min_passenger) > 0) {
        answer++;
    }

    // output
    std::cout << answer << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,K,x=1;
    cin>>N>>K ;
  for(int i=0;i<N;i++){
  if (x+K<2*x){
  x+=K;
  }
    else {
    x*=2;
    }
  }
  cout<<x<<endl;
}
  

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>

int main(){
    int N, K;
    int h[110000];
    int dp[110000];
    int i, j, k;
    int dpmin;
    int dpa;

    for(i=0; i<110000; i++){
        dp[i] = 1000000000;
    }

    scanf("%d %d", &N, &K);
    for(i=0; i<N; i++){
        scanf("%d", &h[i]);
    }
    dp[0] = 0;

    for(i=0; i<N; i++){
        for(j=1; j<=K; j++){
            dpa = dp[i] + abs(h[i] - h[i+j]);
            if(dpa<dp[i+j]){
                dp[i+j] = dpa;
            }
        }
    }
    printf("%d", dp[N-1]);

    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
#define ull unsigned long long
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ull n,i;
	cin>>n;
	ull a[n];
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	if(n%2==0)
	{
		cout<<a[(n/2)]-a[(n/2)-1];
	}
	else
	cout<<"0";
	return 0;
}

Measured memory_bytes: 1152
//
//  main.cpp
//  APG4b
//
//  Created by 安藤光希 on 2020/03/21.
//  Copyright © 2020 安藤光希. All rights reserved.
//


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


int main() {
    
    int H, W;
    cin >> H >> W;
    
    vector<string> compo(H);
    
    for (int i = 0; i < H; i++){
        cin >> compo.at(i);
    }
    
    for (int i = 0; i < W+2; i++){
        cout << "#";
    }
    
    cout << endl;
    
    for (int i = 0; i < H; i++){
        cout << "#" << compo.at(i) << "#"<< endl;
    }
    for (int i = 0; i < W+2; i++){
        cout << "#";
    }
    
    cout << endl;
    
    
}

// cin >> N;
// cout << N << endl;

/*
https://atcoder.jp/contests/apg4b/tasks/APG4b_n
 https://atcoder.jp/contests/apg4b/tasks/APG4b_cq
 https://atcoder.jp/contests/practice
 */


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

using namespace std;

int main()
{
	int N, M;
	cin >> N >> M;
	vector < int >P(M);
	vector < int >Y(M);

	for (int i = 0; i < M; i++) {
		cin >> P[i] >> Y[i];
	}

	vector < int >v[N + 1];
	for (int i = 0; i < M; i++) {
		v[P[i]].push_back(Y[i]);
	}
	for (int i = 0; i <= N; i++) {
		sort(v[i].begin(), v[i].end());
	}

	for (int i = 0; i < M; i++) {
		cout << setfill('0') << setw(6) << P[i];
		cout << setfill('0') << setw(6) <<
		    lower_bound(v[P[i]].begin(), v[P[i]].end(), Y[i]) -
		    v[P[i]].begin() + 1 << endl;
	}

	return 0;
}


Measured memory_bytes: 7808
package main

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

func main() {
  var w [100]int
  sc := bufio.NewScanner(os.Stdin)
  sc.Split(bufio.ScanWords)

  sc.Scan()
  n, _ := strconv.Atoi(sc.Text())

  for i := 0; i < n; i++ {
    sc.Scan()
    w[i], _ = strconv.Atoi(sc.Text())
  }

  out := math.MaxInt32
  for i := 0; i < n; i++ {
    left := 0
    for j := 0; j <= i; j++ {
      left += w[j]
    }
    right := 0
    for j := i + 1; j < n; j++ {
      right += w[j]
    }
    if int(math.Abs(float64(left - right))) < out {
      out = int(math.Abs(float64(left - right)))
    }
  }
  fmt.Println(out)

}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define mod                     (int)1000000007
#define INF                     (int)0x3f3f3f3f

using namespace std;

typedef long long i64; 

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
char a[101], b[400];
     
int main(void) {
  scanf("%s %s", a, b);
  strcat(b, a);
  printf("%s\n", b);  
  return 0;
}

Measured memory_bytes: 256
import math
a,b,h,m=map(int,input().split())
tyok=h*30+m*0.5
tank=m*6

sa=max(tyok,tank)-min(tank,tyok)

c=a**2+b**2-2*a*b*math.cos(math.radians(sa))
print(math.sqrt(c))

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

#define ll long long int
#define ull unsigned long long int
#define db double
#define ld long double
#define MOD 1000000007
#define inf (1LL << 62)
#define pi acos(-1.0)
#define si(a) scanf("%lld",&a)
#define sd(n) scanf("%lf", &n)
#define for1(i, stop) for(ll i = 1; i <= stop; i++)
#define for0(i, stop) for(ll i = 0; i < stop; i++)
#define rep1(i, start) for(ll i = start; i >= 1; i--)
#define rep0(i, start) for(ll i = (start-1); i >= 0; i--)
#define loop(i, start, stop, inc) for(ll i = start; i <= stop; i += inc)
#define pb(v,a) v.push_back(a)
#define pll pair <ll, ll>
#define mp make_pair
#define pbp(v,a,i) v.push_back(make_pair(a,i))
#define srt(v) sort(v.begin(),v.end())
#define rv(v) reverse(v.begin(),v.end())
#define ms(n, i) memset(n, i, sizeof(n))
#define debug printf("Debug\n");
#define en '\n'



#define _fastio  ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
/*typedef tuple<ll,ll,ll>tpl;

ll bigmod(ll n,ll pow)
{
    if(pow==0)
        return 1;
    if(pow==1)
        return n%MOD;

    ll ans=bigmod(n,pow/2);
    ans=(ans*ans)%MOD;

    if(pow%2==1)
    {
        ans=(ans*n)%MOD;
    }
    return ans%MOD;
}

ll fact[1000005];

ll nCr(ll n,ll r)
{

    ll ans=fact[n];
    ans=(ans*bigmod(fact[r],MOD-2))%MOD;
    ans=(ans*bigmod(fact[n-r],MOD-2))%MOD;
    return ans;
} */

int main()
{
    _fastio
    ll k;
    cin >> k;
 
    ll sum = 0;
    for(int i=0;i<1000000;i++)
    {
        sum*=10;
        sum+=7;
        sum%=k;
 
        if(sum == 0)
        {
            cout << i+1 << endl;
            return 0;
        }
    }
 
    cout << -1 << endl;
}


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

using namespace std;

#define int long long

const int N = 16, inf = 1e18 + 123;
int n, a[N][N], cost[1 << N], dp[1 << N];

int32_t main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) cin >> a[i][j];

    for (int mask = 0; mask < (1 << n); ++mask) {
        for (int i = 0; i < n; ++i) if ( (mask >> i) & 1) {
            for (int j = i + 1; j < n; ++j) if ( (mask >> j) & 1) {
                cost[mask] += a[i][j];
            }
        }
    }

    for (int mask = 0; mask < (1 << n); ++mask) dp[mask] = -inf;

    dp[0] = 0;
    for (int mask = 1; mask < (1 << n); ++mask) {
        for (int sMask = mask; sMask; sMask = (sMask - 1) & mask) dp[mask] = max(dp[mask], cost[sMask] + dp[mask ^ sMask]);
    }

    cout << dp[(1 << n) - 1];

    return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <ctime>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	while(1){
		int n,q; cin >> n >> q;
		if(n+q == 0) break;
		vl cnt(101,0);
		rep(i,n){
			ll m; cin >> m;
			rep(j,m){
				ll a; cin >> a;
				cnt[a]++;
			}
		}
		ll ans = 0;
		ll mn = 0;
		rep(i,101){
			if(chmax(mn, cnt[i])){
				ans = i;
			}
		}
		if(mn < q) cout << 0 << endl;
		else cout << ans << endl;
	}
}


Measured memory_bytes: 2988
/*input
3
1 1
2 4
3 2
*/
#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;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=4e3+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=1e9+7;
const ld PI=3.14159265358979323846;
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define MP make_pair
ll mult(ll a,ll b){
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
int c[maxn][maxn];
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int n;
    cin>>n;
    int mx=0,mn=INT_MAX;
    int mx2=-INT_MAX,mn2=INT_MAX;
    REP(i,n){
        int x,y;
        cin>>x>>y;
        MXTO(mx,x+y);
        MNTO(mn,x+y);
        MNTO(mn2,x-y);
        MXTO(mx2,x-y);
    }
    cout<<max(mx-mn,mx2-mn2)<<'\n';
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <algorithm>
#include <stdio.h>
#include <math.h>
using namespace std;
 
#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;
 
struct edge {
	int to, cost;
	edge(int t,int c):to(t),cost(c) {}
};
 
int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int ddx[]={1,1,1,0,-1,-1,-1,0},ddy[]={1,0,-1,-1,-1,0,1,1};
 
ll mypow(ll x,ll n,ll m) {	//xのn乗をmで割った余り
	if(n==0) return 1;
	if(n%2==0) return mypow(x*x%m,n/2,m);
	else return x*mypow(x,n-1,m)%m;
}
 
//-----------------------------------------------------------------------------
 
int n;
ll a[55];
ll mi=LINF,ma=-LINF;
int i1,i2;
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
 
	cin>>n;
	REP(i,n) {
		cin>>a[i];
		if(a[i]<mi) mi=a[i],i1=i;
		if(a[i]>ma) ma=a[i],i2=i;
	}
		if(abs(ma)>abs(mi)) {
			cout<<2*n-1<<endl;
			REP(i,n) cout<<i2+1<<' '<<i+1<<endl;
        		REP(i,n-1) {
			        cout<<i+1<<' '<<i+2<<endl;
		        }
		}
		else {
			cout<<2*n-1<<endl;
			REP(i,n) cout<<i1+1<<' '<<i+1<<endl;
		        for(int i=n-1;i>0;i--) {
			       cout<<i+1<<' '<<i<<endl;
		        }
		}
	
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int jude = 0;
        double sum = 0;
        int[] a = new int[n];
        for(int i = 0; i<n; i++){
            a[i] = sc.nextInt();
            sum = sum + a[i];
        }
        sum = sum / (4 * m);
//        System.out.println(sum);
        for(int i = 0; i<n; i++){
            if(sum <= a[i]){
                jude++;
            }
        }
        if(jude < m){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
        sc.close();
    }
}

Measured memory_bytes: 23892
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

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

def main():
    a, b = rli()
    if a <= 5:
        print(0)
    elif a <= 12:
        print(b//2)
    else:
        print(b)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int n,t,c[50000],l[50000],ans=11451419;
int main(){
    cin>>n>>t;
    for(int i=0;i<n;i++){
        cin>>c[i]>>l[i];
        if(l[i]<=t)ans=min(ans,c[i]);
    }
    if(ans==11451419){
        cout<<"TLE"<<endl;
        return 0;
    }
    cout<<ans<<endl;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define     ll      long long int
vector<ll>v;
set<char>st;
int main()
{
    ll n;
    cin>>n;
    if(n%1000==0){
        cout<<0<<endl;
    }
    else{
        ll bagses=n%1000;
        cout<<1000-bagses<<endl;
    }
    return 0;
}


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

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

	for (int i = 0; i < K - 1; i++)
	{
		if (S[i] != '1') {
			cout << S[i] << endl;
			return 0;
		}
	}
	
	cout << S[(int)(K - 1)] << endl;
	return 0;
}

Measured memory_bytes: 256
x1,y1,x2,y2=map(int,input().split())
if x2 >= x1 and y2 >= y1:
  x3=x2-abs(y2-y1)
  x4=x1-abs(y2-y1)
  y3=y2+abs(x2-x1)
  y4=y1+abs(x2-x1)
elif x2 < x1 and y2 >= y1:
  x3=x2-abs(y2-y1)
  x4=x1-abs(y2-y1)
  y3=y2-abs(x2-x1)
  y4=y1-abs(x2-x1)
elif x2 < x1 and y1 >= y2:
  x3=x2+abs(y2-y1)
  x4=x1+abs(y2-y1)
  y3=y2-abs(x2-x1)
  y4=y1-abs(x2-x1)
else:
  x3=x2+abs(y2-y1)
  x4=x1+abs(y2-y1)
  y3=y2+abs(x2-x1)
  y4=y1+abs(x2-x1)
print(x3,y3,x4,y4)

Measured memory_bytes: 9092
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl; 有効桁数指定
// *min_element(c + l, c + r) *max_element(c + l, c + r) 配列の中のmin-max
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// ~ は、-1の時だけfalse

int main() {
    int k;cin>>k;
    // if(k<=9) {
    //     cout<<k<<endl;
    //     return;
    // }
    int cnt=0;
    queue<ll> que;
    rep(i,9) que.push(i+1);
    while(1) {
        ll now = que.front();que.pop();
        cnt++;
        if(cnt==k) {
            cout<<now<<endl;
            return 0;
        }
        if(now%10==0) {
            que.push(now*10);
            que.push(now*10+1);
        } else if (now%10==9) {
            que.push(now*10+(now%10-1));
            que.push(now*10+(now%10));
        } else{
            que.push(now*10+(now%10-1));
            que.push(now*10+(now%10));
            que.push(now*10+(now%10+1));
        }
    }
}

Measured memory_bytes: 5088
N=int(input())

def num_divisors_table(n):
    table=[0]*(n+1)
    for i in range(1,n+1):
        for j in range(i,n+1,i):
            table[j]+=1
    return table

l=num_divisors_table(N)
ans=0

for i in range(1,N+1):
    ans+=i*l[i]

print(ans)

Measured memory_bytes: 151288
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;

#define MAX_N 1010
#define pb push_back

int main(){
  int N, M;
  
  while(cin >> N >> M){
    if(N == 0 && M == 0) break;
    vector<int> P(N), P2;

    for(int i = 0 ; i < N ; i++){
      cin >> P[i];
      P2.pb(P[i]);
    }

    P2.pb(0);
    for(int i = 0 ; i < N ; i++){
      for(int j = 0 ; j < N ; j++){
	P2.pb(P[i]+P[j]);
      }
    }

    sort(P2.begin(), P2.end());
    
    int ans = 0;
    for(int i = 0 ; i < P2.size() ; i++){
      if(M >= P2[i]) ans = max(ans, P2[i]+upper_bound(P2.begin(), P2.end(), M-P2[i])[-1]);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 9188
#include <iostream>
#include <vector>
using namespace std;
int main(){

  int blank,n,num[10],i;
  vector <int> a,b;

  cin>>n;
  for(int j=0;j<n;j++){
  for(i=0;i<10;i++) cin>>num[i];
  blank=0;
  a.clear();
  b.clear();
  a.push_back(0);
  b.push_back(0);
  for(i=0;i<10;i++){

    if(num[i]>a.back() && num[i]>b.back()){
      if(a.back()<=b.back()){
	b.push_back(num[i]);
	continue;
      }
      else {
	a.push_back(num[i]);
	continue;
      }
    }

    if(num[i]>a.back()){
      	a.push_back(num[i]);
	continue;
    }
      if(num[i]>b.back()){
      	b.push_back(num[i]);
	continue;
    }
      
      blank=1;
      break;

  }

  if(blank==0) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
  }
  
  return 0;

}
	     
  

Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;
typedef std::vector<long long> vl;
typedef std::vector<std::vector<long long>> vvl;
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}


ll gcd(ll n, ll m) {
    ll tmp;
    while (m!=0) {
        tmp = n % m;
        n = m;
        m = tmp;
    }
    return n;
}
 
ll lcm(ll n, ll m) {
    return abs(n) / gcd(n, m)*abs(m);//gl=xy
}

using namespace std;

ll dp[200005][3];
void solve()
{
	int n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a[i];
	rep(i,200005){
		rep(j,3)dp[i][j] = -INF;
	}
	rep(i,3)dp[0][i] = 0;
	if(n%2==1){
		rep(i, n/2)
		{
			int id = 2 * i;
			rep(j,3)
			{
				if(j==0){
					chmax(dp[i + 1][0], dp[i][0] + a[id]);
					chmax(dp[i + 1][1], dp[i][0] + a[id+1]);
					chmax(dp[i + 1][2], dp[i][0] + a[id + 2]);
				}
				else if(j==1){
					chmax(dp[i + 1][1], dp[i][1] + a[id+1]);
					chmax(dp[i + 1][2], dp[i][1] + a[id + 2]);
				}
				else{
					chmax(dp[i + 1][2], dp[i][2] + a[id + 2]);
				}
			}
		}
		ll ans = -INF;
		rep(i,3){
			chmax(ans, dp[n / 2][i]);
		}
		cout << ans;
	}
	else{
		rep(i,n/2){
			int id = i * 2;
			rep(j,2){
				if(j==0){
					chmax(dp[i + 1][0], dp[i][0] + a[id]);
					chmax(dp[i + 1][1], dp[i][0] + a[id + 1]);
				}
				else{
					chmax(dp[i + 1][1], dp[i][1] + a[id + 1]);
				}
			}
		}
		ll ans = -INF;
		rep(i,2){
			chmax(ans, dp[n / 2][i]);
		}
		cout << ans;
	}
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(15);
    solve();
    return 0;
}



Measured memory_bytes: 9536
#include<bits/stdc++.h>
using namespace std;
#define var auto

vector<int> ranks;
vector<vector<int>> graph;
vector<bool> arrived;

int main(){
  int n;
  cin >> n;
  var all = 2 * n * n - 2 * n;
  ranks = vector<int>(n * n, 0);
  graph = vector<vector<int>>(n * n, vector<int>());
  arrived = vector<bool>(n * n, false);
  for (int i = 0; i < all; i++){
    int a, b;
    cin >> a >> b;
    a--;b--;
    ranks[a]++;
    graph[a].push_back(b);
    graph[b].push_back(a);
    ranks[b]++;
  }
  int top;
  for (int i = 0; i < ranks.size(); i++){
    if (ranks[i] == 2){
      top = i;
      break;
    }
  }
  vector<int> next{};
  for (int i = 0; i < n; i++){
    arrived[top] = true;
    cout << top + 1;
    if (i != n - 1) cout << ' ';
    else cout << '\n';
    int ntop = -1;
    for (var&& item : graph[top]){
      if (arrived[item]) continue;
      arrived[item] = true;
      if (ranks[item] <= 3 && ntop == -1 && i != n - 1){
	ntop = item;
      }
      else{
	next.push_back(item);
      }
    }
    top = ntop;
  }

  
  for (int itr = 0; itr < n - 1; itr++){
    vector<int> nnext{};
    bool first = true;
    for (var&& elem : next){
      if (!first) cout << ' ';
      first = false;
      cout << elem + 1;
      for (var&& item : graph[elem]){
	if (arrived[item]) continue;
	arrived[item] = true;
	nnext.push_back(item);
      }
    }
    cout << '\n';
    next = nnext;
  }
}



Measured memory_bytes: 3516
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>
#include <regex>
#include <functional>
#include <algorithm>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
const int MOD = 1000000007;
const int MAX_N = 100000;

typedef long long ll;

int main() {
    const double PI = 3.14159;
    int r;
    cin >> r;
    cout << std::setprecision(8) << r * 2.0 * PI << endl;
}

Measured memory_bytes: 3788
#include <stdio.h>

int main(void){
  int n,i,j,k,b,count=0,result=0;
  int a[3][3]={0};
  
  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      scanf("%d", &a[i][j]);
    }
  }
  scanf("%d",&n);
  for(k=0;k<n;k++){
    scanf("%d",&b);
    
    for(i=0;i<3;i++){
      for(j=0;j<3;j++){
		if(a[i][j] == b) a[i][j] = 0;
      }
    }
  }
  for(i=0;i<3;i++){
    count=0;
    for(j=0;j<3;j++){
	  if(a[i][j] == 0) count++;
    }
    if(count >= 3) result=1;
  }
  for(j=0;j<3;j++){
    count=0;
    for(i=0;i<3;i++){
	  if(a[i][j] == 0) count++;
    }
    if(count >= 3) result=1;
  }
  count=0;
  for(i=0;i<3;i++){
	if(a[i][i] == 0) count++;
  }
  if(count >= 3) result=1;
  count=0;
  for(i=0;i<3;i++){
	if(a[i][2-i] == 0) count++;
  }
  if(count >= 3) result=1;

  if(result==1) printf("Yes");
  else printf("No");
  
  return 0;
}

Measured memory_bytes: 128
/**
   Solution by Abil
**/
# include <bits/stdc++.h>

# define fr first
# define sc second
# define pb push_back
# define mk make_pair
# define sz(s) s.size()
# define all(s) s.begin(),s.end()
# define int long long

using namespace std;

const long long N = (1e5 + 10);
const long long mod = (1e9 + 7);
const long long inf = (1e9 + 7);

int dp[3005][3005][2], arr[N];

int ans(int l,int r,int per){
    if(l > r){
        return 0;
    }
    if(dp[l][r][per] != -1){
        return dp[l][r][per];
    }
    if(per == 0){
       return dp[l][r][per] = max(ans(l + 1,r,1 - per) + arr[l],ans(l,r - 1,1 - per) + arr[r]);
    }
    if(per == 1){
       return dp[l][r][per] = min(ans(l + 1,r,1 - per) - arr[l],ans(l,r - 1,1 - per) - arr[r]);
    }
}
main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    for(int i = 1;i <= n; i++){
        cin >> arr[i];
    }
    memset(dp,-1,sizeof(dp));
    cout << ans(1,n,0);
}


Measured memory_bytes: 141568
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	nums := ScanNums(n)
	isNonDecreasing := true

	for i := n - 1; i > 0; i-- {
		if nums[i-1] <= nums[i] {
			continue
		} else if nums[i-1]-1 <= nums[i] {
			nums[i-1] = nums[i-1] - 1
		} else {
			isNonDecreasing = false
			break
		}
	}

	if isNonDecreasing {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

func ScanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		fmt.Scan(&num)
		nums = append(nums, num)
	}
	return
}


Measured memory_bytes: 5504
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
#define PI acos(-1.0);

const double EPS = 1e-10;

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
	int N; cin >> N;
	vector<int> A(N);
	rep(i,N) cin >> A[i];
	bool ok = true;
	rep(i,N){
		if(A[i] % 2 == 0){
			if(A[i] % 3 != 0 && A[i] % 5 != 0) ok = false;
		}
	}
	cout << (ok?"APPROVED":"DENIED") << endl;
}



Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    S = input()
    W = {'SUN': 7,
         'MON': 6,
         'TUE': 5,
         'WED': 4,
         'THU': 3,
         'FRI': 2,
         'SAT': 1}

    print(W[S])


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int ans=N;
    for(int i = 1;i<=(N+1)/2;i++){
        int A = i,B = N-i;
        int ap,bp;
        if(A>=10000){
            ap = 4;
        }else if(A>=1000){
            ap = 3;
        }else if(A>=100){
            ap = 2;
        }else if(A>=10){
            ap = 1;
        }else{
            ap = 0;
        }
        if(B>=10000){
            bp = 4;
        }else if(B>=1000){
            bp = 3;
        }else if(B>=100){
            bp = 2;
        }else if(B>=10){
            bp = 1;
        }else{
            bp = 0;
        }
        // cout<<"ap="<<ap<<" bp="<<bp<<endl;
        int as=0,bs=0;
        for(int j = 0;j<=ap;j++){
            // cout<<A%(int)pow(10,j+1)<<endl;
            // cout<<A%(int)pow(10,j)<<endl;
            as += (A%((int)pow(10,j+1)))/pow(10,j);
        }
        for(int j = 0;j<=bp;j++){
            bs += (B%((int)pow(10,j+1)))/pow(10,j);
        }
        int sum = as + bs;
        // cout <<"i="<<i <<" as:"<<as << " bs:" <<bs <<endl;
        ans = min(ans,sum);
    }
    cout << ans << endl;
}

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

int main() {
	ll n;
	cin >> n;
	vector<ll> a(n);
	for (ll i = 0; i < n; ++i)cin >> a[i];
	for (ll i = 0; i < n; ++i)a[i] -= i;
	set<ll> s;
	map<ll, ll> m;
	for (ll x : a) {
		++m[x];
	}
	ll ans = 0;
	for (ll i = 0; i < n - 1; ++i) {
		ll target = -a[i] - 2 * i;
		ans += m[target];
		--m[a[i]];
	}
	cout << ans << endl;
}


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

int main(){
  string s, t;
  cin >> s >> t;
  
  int count = 0;
  for (int i = 0; i < 3; i++){
    if (s[i] == t[i]){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3600
import java.util.*;
public class Main {
	static int[] f=new int[112345];
	static long[] sz=new long[112345];
	static int[] can=new int[112345];
	static int[] tot=new int[112345];
	public static class edge implements Comparable<edge> {
		int u,v,w;
		@Override
		public int compareTo(edge o) {
			return w-o.w;
		}
	}
	public static int F(int x) {
		return x==f[x]?x:(f[x]=F(f[x]));
	}
	public static void U(int x,int y,int w) {
		int fx=F(x),fy=F(y);
		if (fx==fy) {
			++tot[fx];
			if (w<=sz[fx]) ++can[fx];
			return;
		}
		sz[fx]+=sz[fy];
		f[fy]=fx;
		tot[fx]+=tot[fy]+1;
		if (w<=sz[fx]) can[fx]=tot[fx];
		else can[fx]+=can[fy];
		return;
	}
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt();
		int m=in.nextInt();
		edge[] e=new edge[m];
		for (int i=1;i<=n;++i) {
			sz[i]=in.nextLong();
			f[i]=i;
		}
		for (int i=0;i<m;++i) {
			e[i]=new edge();
			e[i].u=in.nextInt();
			e[i].v=in.nextInt();
			e[i].w=in.nextInt();
		}
		Arrays.sort(e,0,m);
		for (int i=0;i<m;++i) U(e[i].u,e[i].v,e[i].w);
		System.out.println(tot[F(1)]-can[F(1)]);
	}
}

Measured memory_bytes: 116440
function main(input){
    let int =parseInt;
    let lines = input.split("\n");
    let sLen = int(lines[0]);
    let tLen = int(lines[2]);
    let s = lines[1].split(" ").map(item=>int(item));
    let t = lines[3].split(" ").map(item=>int(item));
    let count = 0;

    
    for(let i=0;i<tLen;i++){
        let left = 0;
        let right = sLen;
        let middle =Math.floor((left+right)/2);
        
        while(left<right){
            middle =Math.floor((left+right)/2);
            if(s[middle]===t[i]){
                count++;
                break;
            }else if(s[middle]>t[i]){
                right = middle;
            }else{
                left = middle+1;
            }
            

        }
    }
    console.log(count);
    
    
}


main(require("fs").readFileSync("/dev/stdin","utf-8"));


Measured memory_bytes: 30792
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);
		
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int d=sc.nextInt();
		
		//開始はaとcのでかいほう
		
		int start=Math.max(a, c);
		int end=Math.min(b,d);
		
		if(end-start>0) {
			System.out.println(end-start);
			
		}else {
			System.out.println(0);
		}

		sc.close();


	}



}



Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;

const double PI = acos(-1);

int main() {
  int a, b, h, m;
  cin >> a >> b >> h >> m;
  double c1 = double(60*h+m) / 720 * 2 * PI;
  double c2 = double(m) / 60 * 2 * PI;
  double x = a * cos(c1) - b * cos(c2);
  double y = a * sin(c1) - b * sin(c2);
  double ans = sqrt(x * x + y * y);
  printf("%.10f\n", ans);
  return(0);
}


Measured memory_bytes: 4120
#include<iostream>
#include<cstdio>

using namespace std;

int ball[11];
int a[11],b[11];
bool ans;

bool dfs(int i,int p,int q)
{
	 if(ball[i] < a[p] && ball[i] < b[q]) return false;
	 if(i == 9) return true;
	 bool tmp = false;
	 if(a[p] < ball[i])
	 {
		 a[p+1] = ball[i];
		 tmp = (tmp || dfs(i+1,p+1,q));
	 }
	 if(b[q] < ball[i])
	 {
	 	b[q+1] = ball[i];
		 tmp = (tmp || dfs(i+1,p,q+1));
	 }
	 return tmp;
}


int main ()
{
	int n;
	cin >> n;
	for(int i= 0;i<n;i++)
	{
		a[0]=0,b[0]=0;
		for(int j = 0;j < 10;j++) cin >> ball[j];
		a[1] = ball[0];
		ans = dfs(1,0,0);
		if(ans) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N;
  cin >> N;
  vector<int> L(N);
  REP(i, N) { cin >> L.at(i); }
  int sum = accumulate(L.begin(), L.end(), 0);
  int longest = *max_element(L.begin(), L.end());

  if (longest < sum - longest) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, x, n) for (int i = (x); i < (n); i++)
#define all(v) (v).begin(), (v).end()
#define int long long
using namespace std;
const int MOD = 1e9 + 7;
const int INF = 1e10;
template<typename T> void cmax(T &a, T b) { a = max(a, b); }
template<typename T> void cmin(T &a, T b) { a = min(a, b); }

signed main() {
  int a, b;
  cin >> a >> b;
  if (a * b % 2 == 0) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
  return 0;
}


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

int main() {
  int c5, c7;
  vector<int> vec(3);
  
  for (int i = 0; i < 3; i++) {
    cin >> vec.at(i);
  }
  
  
  for (int x: vec) {
    if (x == 5) {
      c5++;
  }
    if (x == 7) {
      c7++;
    }
  }
  
  if (c5 == 2 && c7 == 1) {
    printf("YES");
  } else {
    printf("NO");
  }
  
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(void)
{
  int i, N, max, cnt=1;
  scanf("%d", &N);
  int H[N];
  for(i=0;i<N;i++){
    scanf("%d", &H[i]);
  }
  max=H[0];
  for(i=1;i<N;i++){
    if(H[i]>=max){
      max=H[i];
      cnt++;
    }
  }
  printf("%d \n", cnt);
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	final int MOD = 1000000007;
	final int MAX = Integer.MAX_VALUE;
	final long LMAX = Long.MAX_VALUE;
	final int LEN = 100000;

	void doIt() {
		int n = sc.nextInt();
		int p[] = new int[n];
		for(int i = 0; i < n; i++) {
			p[i] = sc.nextInt();
		}
		int ans = 0;
		for(int i = 1; i < n - 1; i++) {
			if(p[i - 1] < p[i] && p[i] < p[i + 1]) ans++;
			else if(p[i - 1] > p[i] && p[i] > p[i + 1])ans++;
		}
		System.out.println(ans);
		
	}
	public static void main(String[] args) {
		new Main().doIt();
	}
}


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

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

    vl a(n);
    rep(i, n) {
        cin >> a[i];
    }

    vl rui(n+1);  // rui[i+1] : a[0]からa[i]までの累積和
    rep(i, n) {
        rui[i+1] = rui[i] + a[i];
    }

    vvl dp(n+1, vl(n+1));  // dp[l][r] : 区間[l,r)のスライムたちを1匹に合成するのに必要なコストの最小値
    exrep(len, 2, n) {  // 区間の長さが1のときはdp[l][r]=0なので区間の長さが2以上のときを考える 
        for(ll l = 0; l + len <= n; l++) {
            ll r = l + len;

            /* 区間[l,r)のスライムたちを1匹に合成する手順は以下。
               まず区間[l,x)と区間[x,r)に分ける。
               次にコストdp[l][x]で[l,x)のスライムたちを1匹のスライムAに合成する。
               同様にコストdp[x][r]で[x,r)のスライムたちも1匹のスライムBに合成する。
               スライムAとスライムBの大きさの合計は区間[l,r)のスライムたちの大きさの合計に等しい。
               よって、最初に位置x (l < x < r) で区間[l,r)を分けたときの最小コストは dp[l][x] + dp[x][r] + (sum_{l <= i < r} a[i]) となる。
               あとは位置xを全て試して、(sum_{l <= i < r} a[i]) = rui[r] - rui[l] と累積和で高速に求めればよい。 */

            ll u = INF;  // dp[l][x] + dp[x][r] の最小値
            exrep(x, l+1, r-1) {  
                chmin(u, dp[l][x] + dp[x][r]);
            }

            dp[l][r] = u + rui[r] - rui[l];
        }
    }
    
    out(dp[0][n]);
    re0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 200009
#define mod 1000000007
ll n,m,i,j,k,l,t,a,b,arr[10];
int main()
{
    scanf("%lld %lld %lld",&n,&m,&k);
    arr[n]++;
    arr[m]++;
    arr[k]++;
    if(arr[5]==2 && arr[7]==1)
        printf("YES\n");
    else
        printf("NO\n");
}


Measured memory_bytes: 256