akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;


namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            checked
            {
                string[] s;
#if true
                int N = int.Parse(Console.ReadLine());
#else
                s = Console.ReadLine().Split(' ');
                int N = int.Parse(s[0]);
                int K = int.Parse(s[1]);
#endif

                int[,] v = new int[N,3];

#if true
                for (int i = 0; i < N; i++)
                {
                    s = Console.ReadLine().Split(' ');
                    v[i, 0] = int.Parse(s[0]);
                    v[i, 1] = int.Parse(s[1]);
                    v[i, 2] = int.Parse(s[2]);
                }
#else
                for (int i = 0; i < N; i++)
                {
                    v[i] = int.Parse(Console.ReadLine());
                }
#endif

                for (int i = 1; i < N; i++)
                {
                    v[i, 0] += Math.Max(v[i - 1, 1], v[i - 1, 2]);
                    v[i, 1] += Math.Max(v[i - 1, 0], v[i - 1, 2]);
                    v[i, 2] += Math.Max(v[i - 1, 0], v[i - 1, 1]);
                }

                Console.WriteLine(Math.Max(v[N - 1, 0], Math.Max(v[N - 1, 1], v[N - 1, 2])));
            }
        }
    }
}

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

long make(long N,long X){
    long i=N,a=0;
    while(X>0){
        while((pow(2,i+2)-3)>X && X>0){i--;X--;}
        if(X==(pow(2,i+2)-3)){
            X-=pow(2,i+2)-3;
            a+=pow(2,i+1)-1;
        }else if(X>0){
            X-=pow(2,i+2)-3+1;
            a+=pow(2,i+1);
        }
    }
    return a;
}
int main(void){
    long N;
    long X,k;
    scanf("%ld%ld",&N,&X);
    k=make(N,X);
    printf("%ld\n",k);
    return 0;
}




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

int main(void){
    int A,B,C,ans;
    cin>>A>>B>>C;

    if(A==B)
        ans=C;
    else if(A==C)
        ans=B;
    else
        ans=A;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
int INF=1<<29;

int main(){
    ios::sync_with_stdio(false);
	int N,ans1=0,ans2=0;
	cin>>N;
	vector<int>p(N+1);
	for(int i=1;i<N+1;i++) cin>>p[i];
	vector<int> s(p),t(p);

	for(int i=1;i<N;i++){
		if(s[i]==i){
			swap(s[i],s[i+1]);
			ans1++;
		}
	}
	if(s[N]==N) ans1++;

	for(int i=N-1;i>1;i--){
		if(t[i]==i){
			swap(t[i],t[i-1]);
			ans2++;
		}
	}
	if(t[1]==1) ans2++;

	int res=max(ans1,ans2);
	cout<<res<<endl;
	return 0;
}


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

#define  int        long long int
#define    bp(x)           __builtin_popcountll(x)
 #define  ld         long double
 #define  f(i,j,n)            for(int i = j; i <= n; i++)
#define  r(i,n,j)       for(int i = n; i >= j; i--)
 #define  all(container)       container.begin() , container.end()
#define  sz(container)   (int)container.size()
 #define  ff             first
#define  ss             second
 #define  pii      pair <int , int>
#define  sp(x)       setprecision(x)
 #define  endl    "\n"
#define  mod  1000000007
 #define  pb    push_back
#define  mp    make_pair
 #define  T     int ttt; cin >> ttt; while(ttt--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

int power(int x, int y, int p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0;
    while (y > 0)  
    {     
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res; 
}

int32_t main()
{
    fast
    int n;
    cin>>n;
    int a[n+1],ans=0;
    f(i,1,n)    cin>>a[i];
    sort(a+1,a+n+1);
    f(i,1,n)
        f(j,i+1,n)
            f(k,j+1,n)
                if(a[i]+a[j]>a[k] && a[i]!=a[j] && a[j]!=a[k])
                    ans++;
    cout<<ans;
}

Measured memory_bytes: 3656
def dp(i, j, memo):
    key = "{}.{}".format(i, j)

    if i == 1:
        memo[key] = 1
        return memo[key]

    if key in memo:
        return memo[key]

    if j == 0:
        memo[key] = dp(i-1, j, memo) + dp(i-1, j+1, memo)
        return memo[key]

    if j == 9:
        memo[key] = dp(i-1, j-1, memo) + dp(i-1, j, memo)
        return memo[key]

    memo[key] = dp(i-1, j-1, memo) + dp(i-1, j, memo) + dp(i-1, j+1, memo)
    return memo[key]


k = int(input())
memo = {"1.0": 0}

num = 0

i = 1
j = 0

while(num < k):
    j += 1
    j %= 10
    if j == 0:
        i += 1
    else:
        num += dp(i, j, memo)

p = k - num + dp(i, j, memo)
ans = [j]
for l in range(1, i):
    n = 0
    x = max(-1, ans[-1] - 2)
    while n < p and x < 10:
        x += 1
        n += dp(i-l, x, memo)
    ans.append(x)
    p = p - n + dp(i-l, x, memo)

print("".join(map(str, ans)))


Measured memory_bytes: 3192
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Split(bufio.ScanWords)
	N := readInt()
	A := make([]int, N)
	x1 := 0
	for i := range A {
		A[i] = readInt()
		if i%2 == 0 {
			x1 += A[i]
		} else {
			x1 -= A[i]
		}
	}

	res := x1
	tmp := x1
	fmt.Println(res)
	for i := 1; i < N; i++ {
		res = (A[i-1] - tmp/2) * 2
		tmp = res
		fmt.Println(res)
	}
}

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

func checkError(err error) {
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}

func read() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	res, err := strconv.Atoi(read())
	checkError(err)
	return res
}

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

func max(a int, b int) int {
	return -min(-a, -b)
}

func pow(a int, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func sqrt(a int) float64 {
	return math.Sqrt(float64(a))
}


Measured memory_bytes: 4992
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
count=0
for i in range(n):
  a=list(map(int,input().split()))
  sum=0
  for j in range(m):
    sum=sum+b[j]*a[j]
  if sum+c>0:
    count=count+1
print(count)

Measured memory_bytes: 3064
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<queue>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
ll a[1000005],b[1000005],v[100005];
char h[100005][3];
int main ()
{
    ll n,t,k,x,sum=0,i,ans1=0,ans2=0,m;
    scanf("%lld%lld",&n,&m);
    for(i=1;i<=m;i++)
    {
        scanf("%lld %s",&a[i],h[i]);
    }
   for(i=1;i<=m;i++)
    {
        if(h[i][0]=='W'&&v[a[i]]!=1)
        {
            b[a[i]]++;
           // printf("b[%lld]=%lld\n",i,b[i]);
        }
        if(h[i][0]=='A'&&v[a[i]]!=1)
        {
            ans1++;ans2+=b[a[i]];
            v[a[i]]=1;

        }
    }
    printf("%lld %lld\n",ans1,ans2);
}


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

A = sorted(map(int, list(input().split())))
B = sorted(map(int, list(input().split())))
C = sorted(map(int, list(input().split())))

i = 0

ans = 0
li = []

i = 0

for Bi in B:
    while i < N and Bi >= C[i]:
        i += 1
    li += [N - i]

i = N - 1

o_ans = 0
for Ai in A[::-1]:
    while i >= 0 and Ai < B[i]:
        o_ans += li[i]
        i -= 1
    ans += o_ans

print(ans)

Measured memory_bytes: 23308
d = int(input())
c = list(map(int, input().split()))
csum = 0
for i in range(26):
    csum += c[i]
s = [ [] for _ in range(d)]
for i in range(d):
    s[i] = list(map(int, input().split()))
t = [0 for _ in range(d)]
for i in range(d):
    t[i] = int(input())-1
lastDI = [-1 for _ in range(26)]
ans = 0
for i in range(d):
    ans += s[i][t[i]]
    lastDI[t[i]] = i
    for j in range(26):
        ans = ans - c[j]*(i-lastDI[j])
    print(ans)

Measured memory_bytes: 9516
import math

result=0
n=int(input())
rml=[]

li=list(map(int,input().split()))
for i in range(len(li)-1):
    for j in range(i+len(li)):
        rml.append(j)

for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if li[i]+li[j]<=li[k] or li[i]==li[j]:
                continue
            if li[j]+li[k]<=li[i] or li[j]==li[k]:
                continue
            if li[k]+li[i]<=li[j] or li[k]==li[i]:
                continue
            #print(i+1,j+1,k+1)
            result+=1
print(result)

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

int main() {
	string S;
	cin >> S;
	vector<string> week{ "SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN" };

	int ans = 0;
	for (int i = 0; i < 7;i++) {
		ans++;
		if (S == week[i]) {
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val list = List.fill(n)(sc.nextInt)
    if(list.max < list.sum - list.max){
      println("Yes")
    }
    else{
      println("No")
    }
  }
}

Measured memory_bytes: 25536
import math
X, K, D = map(int,input().split())

max_x = X + K * D
min_x = X - K * D

res = 0

if max_x <= 0:
  res = abs(max_x)
  print(res)
  exit()
elif min_x >= 0:
  res = abs(min_x)
  print(res)
  exit()

a = (K*D -X) / (2*D)

max_x = 2 * math.ceil(a) * D + min_x
min_x = 2 * math.floor(a) * D + min_x
res = min(abs(max_x), abs(min_x))
print(res)




Measured memory_bytes: 62208
/*
    安定なソート
    https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/all/ALDS1_2_C
*/
#include <bits/stdc++.h>
using namespace std;

void trace(vector<pair<string, int>> &C) {
    for (size_t i = 0; i < C.size(); i++) {
        cout << C[i].first << C[i].second;
        cout << ((i != C.size() - 1) ? " " : "\n");
    }
}

void BubbleSort(vector<pair<string, int>> &C, int N) {
    for (int i = 0; i < N - 1; i++) {
        for (int j = N - 1; j > i; j--) {
            if (C[j - 1].second > C[j].second) {
                swap(C[j], C[j - 1]);
            }
        }
    }

    trace(C);
}

void SelectionSort(vector<pair<string, int>> &C, int N) {
    for (int i = 0; i < N - 1; i++) {
        int minj = i;
        for (int j = i; j < N; j++) {
            if (C[j].second < C[minj].second) {
                minj = j;
            }
        }
        swap(C[i], C[minj]);
    }
    trace(C);
}

void Compare(vector<pair<string, int>> &A, vector<pair<string, int>> &B) {
    for (size_t i = 0; i < A.size(); i++) {
        if (A[i].first != B[i].first || A[i].second != B[i].second) {
            cout << "Not stable" << endl;
            return;
        }
    }
    cout << "Stable" << endl;
}

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

    int N;
    cin >> N;
    vector<pair<string, int>> vp1(N);
    vector<pair<string, int>> vp2(N);
    for (int i = 0; i < N; i++) {
        string input;
        cin >> input;
        vp1[i].first = input[0];
        vp1[i].second = int(input[1] - '0');
    }

    copy(vp1.begin(), vp1.end(), vp2.begin());

    BubbleSort(vp1, N);
    cout << "Stable" << endl;

    SelectionSort(vp2, N);
    Compare(vp1, vp2);
}


Measured memory_bytes: 3244
#include <iostream>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <stack>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

int main()
{
    int n, q;
    int S[10000], T[500];
    cin >> n;
    REP(i, n)
    {
        cin >> S[i];
    }
    cin >> q;
    REP(i, q)
    {
        cin >> T[i];
    }
    sort(S, S + n);
    sort(T, T + q);

    int count = 0;
    REP(i, n)
    {
        if (i > 0 && S[i] == S[i-1])
            continue;
        if (binary_search(T, T+q, S[i]))
            count++;
    }

    cout << count << endl;
}


Measured memory_bytes: 3176
#include <stdio.h>

int main(void)
{
	int i,num;
	
	char str[100];
	
	scanf("%s", str);
	
	num = 0;
	
	for(i = 0; str[i] != '\0'; i++)
	{
		if( str[i] == '+'){
			num++;
		}else if(str[i] == '-'){
			num--;
		}
	}
	printf("%d", num);
	
	return 0;
}


Measured memory_bytes: 128
#![allow(clippy::needless_range_loop)]
#![allow(unused_macros)]
#![allow(dead_code)]

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

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

use std::cmp::min;

fn main() {
    input! {
        n: String,
    }
    let ans = n
        .bytes()
        .rev()
        .map(|x| (x - b'0') as usize)
        .chain(std::iter::once(0))
        .fold((0, 1), |(no_carry, carry), x| {
            (
                min(no_carry + x, carry + x + 1),
                min(no_carry + 10 - x, carry + 10 - (x + 1)),
            )
        });

    println!("{}", std::cmp::min(ans.0, ans.1));
}


Measured memory_bytes: 3960
#include <iostream>

#define endl '\n'
#define desync                        \
    ios_base::sync_with_stdio(false); \
    cout.tie(NULL);                   \
    cin.tie(NULL)

using namespace std;

int AC, WA, TLE, RE;

int main()
{

    int n;
    string in;

    cin >> n;

    while(n--){
        cin >> in;

        if(in == "AC"){
            AC++;
        }else if(in == "WA"){
            WA++;
        }
        else if(in == "TLE"){
            TLE++;
        }
        else if(in == "RE"){
            RE++;
        }
    }

    cout << "AC x " << AC << endl;
    cout << "WA x " << WA << endl;
    cout << "TLE x " << TLE << endl;
    cout << "RE x " << RE << endl;

    return 0;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a, b; cin >> a >> b;
    if(a > 9 || b > 9) cout << -1;
    else cout << a * b;

    return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;
typedef pair<ll  ,ll > pll;

const ll maxn =2e6;
const ll mod = 1e9+7;
const ld PI = 4 * atan((ld) 1);

#define pb(x) push_back(x);
#define endl '\n'
#define dokme(x) cout << x ;  return(0);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_init freopen("input.txt", "r+", stdin); freopen("output.txt", "w+", stdout);
#define ms(x , y) memset(x , y , sizeof x);
ll pw(ll a, ll b) {
    return (!b ? 1 : (b & 1 ? a * pw(a * a % mod, b / 2) % mod : pw(a * a % mod, b / 2) % mod));
}

string s , t , u;
int a , b;

int main(){
    migmig
    cin >> s >> t ;
    cin >> a >> b;
    cin >> u;
    a-=(s == u);
    b-=(s != u);
    cout << a << ' ' << b;


    return(0);
}


//When we hit our lowest point, we are open to the greatest change.
//If I try, I fail. If I don't try, I'm NEVER GOING TO GET IT.
//Sometimes, life is like this dark tunnel. You can't always see the light at the end of the tunnel. But if you just keep moving... you will come to a better place.
//It is important to draw wisdom from diffrent places. If you take it from only one place it becomes rigid and stale.


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include  <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
#define endl '\n'
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> index_set;
using vi = vector<int>;
#define pb push_back
#define rsz resize
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

using ii = pair<int,int>;
#define f first
#define s second
#define mp make_pair
#define pb push_back
const int m = 1000000007;
int main() {
	//ios::sync_with_stdio(false);
	//cin.tie(nullptr);
	int k;
	cin >> k;
	int n = 0;
	int ans = 0;
	for(int i = 1; i<2*k; i++){
		n = (n*10 +7)%k;
		if(!n){
			cout << i <<endl;
			return 0;
		}
		ans = -1;
	}
	cout << ans <<endl;
	
	return 0;    
}


Measured memory_bytes: 3624
/*
author : nit1n
created :  31.08.2020 15:31:30
*/
#include<bits/stdc++.h>
#define int long long
using namespace std ;


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

	int k ;
	string s ; 
	cin >> k >> s ;
	if(s.size() <=k)
		cout << s  ; 
	else
		cout << s.substr(0, k ) << "..."  ;
}


Measured memory_bytes: 3616
def main(N, lines):
    a = sorted(map(lambda line: line[0], lines))
    b = sorted(map(lambda line: line[1], lines))

    if N % 2 == 1:
        mi = a[N // 2]
        ma = b[N // 2]
        print(int(ma - mi + 1))
    else:
        mi = (a[N // 2 - 1] + a[N // 2])
        ma = (b[N // 2 - 1] + b[N // 2])
        print(int(ma - mi + 1))


N = int(input())
lines = []
for i in range(N):
    lines.append(list(map(int, input().split())))
main(N, lines)


Measured memory_bytes: 49136
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    if(A+B==4){
      System.out.println(2);
    }else if(A+B==3){
      System.out.println(3);
    }else{
      System.out.println(1);
    }
  }
}

Measured memory_bytes: 35820
#include<stdio.h>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
long long  mod = 1000000007;
int main()
{
	int H, W;
	char S[110][110];
	scanf("%d%d", &H, &W);
	for (int i = 0; i < H; i++) {
		scanf("%s", S[i]);
	}
	for (int i = 0; i < H; i++) {
		printf("%s\n", S[i]);
		printf("%s\n", S[i]);
	}
	return 0;
}

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


int main() {
  int n,  x;
  cin>>n;
  for(int i=1; i<=n; i++){
    x=i;
    if(x%3==0){
      cout<<" "<<i;
      continue;
    }
    while(x>0){
      if(x%10==3){
        
      cout<<" "<<i;
      break;
      }
      x/=10;
    }
  }
    
    cout<<endl;
      
    
  
  
}


Measured memory_bytes: 3116
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] a = new long[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextLong();
		}
		sc.close();

		List<Long> list0 = new ArrayList<Long>();
		List<Long> list1 = new ArrayList<Long>();
		List<Long> list2 = new ArrayList<Long>();
		long sum = 0;
		long min = Integer.MAX_VALUE;
		long min1 = Integer.MAX_VALUE;
		long min2 = Integer.MIN_VALUE;
		for (int i = 0; i < n; i++) {
			if (a[i] == 0) {
				list0.add(a[i]);
			} else if (a[i] > 0) {
				list1.add(a[i]);
				min1 = Math.min(min1, a[i]);
			} else {
				list2.add(a[i]);
				min2 = Math.max(min2, a[i]);
			}
			long aa = Math.abs(a[i]);
			sum += aa;
			min = Math.min(min, aa);
		}

		long val = 0;
		if (list1.size() > 0 || list2.size() > 0) {
			if (list1.size() == 0) {
				if (list2.size() == 1) {
					System.out.println(sum);
				} else {
					System.out.println(sum - 2 * min);
				}
				if (min == 0) {
					list0.remove(list0.size() - 1);
				} else {
					val = min2;
					list2.remove(min2);
				}
			} else if (list2.size() == 0) {
				if (list1.size() == 1) {
					System.out.println(sum);
				} else {
					System.out.println(sum - 2 * min);
				}
				if (min == 0) {
					list0.remove(list0.size() - 1);
				} else {
					val = min1;
					list1.remove(min1);
				}
			} else {
				System.out.println(sum);
				if (list2.size() > 0) {
					val = min2;
					list2.remove(min2);
				}
			}
		} else {
			System.out.println(sum);
			list0.remove(list0.size() - 1);
		}

		for (int i = 0; i < list1.size() - 1; i++) {
			System.out.println(val + " " + list1.get(i));
			val -= list1.get(i);
		}
		if (list1.size() > 0) {
			long last = list1.get(list1.size() - 1);
			System.out.println(last + " " + val);
			val = last - val;
		}
		for (int i = 0; i < list2.size(); i++) {
			System.out.println(val + " " + list2.get(i));
			val -= list2.get(i);
		}
		for (int i = 0; i < list0.size(); i++) {
			System.out.println(val + " " + list0.get(i));
		}
	}
}


Measured memory_bytes: 80072
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

int N;
vector<int> A;
bool sieve[1000001];

int main(int argc, char* argv[]) {
  cin >> N;
  A.resize(N);
  for (size_t i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A.begin(), A.end());

  for (int i = 0; i <= 1000000; i++) {
    sieve[i] = true;
  }

  for (int i = 0; i < A.size(); i++) {
    if (i > 0 && A[i - 1] == A[i]) {
      sieve[A[i]] = false;
      continue;
    }

    for (int j = 2; A[i] * j <= 1000000; j++) {
      sieve[A[i] * j] = false;
    }
  }

  int res = 0;
  for (int i = 0; i < A.size(); i++) {
    if (sieve[A[i]]) {
      res++;
    }
  }
  cout << res << endl;

  return 0;
}

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

static const int MAX = 1000000;

int main() {
	int s, a[MAX];
	cin >> s;
	a[0] = s;
	
	if(s == 1 || s == 2){
		cout << "4" << endl;
		return 0;
	}
	
	for(int i = 1; i < MAX; i++)
	{
		if(a[i-1] % 2 == 0){
			a[i] = a[i-1] / 2;
		}else if(a[i-1] % 2 != 0){
			a[i] = (a[i-1] * 3) + 1;
		}
		//cout  << " " << a[i] << " ";
		if(a[i] == a[i -3]){
			cout << i + 1 << endl;
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <ctype.h>
using namespace std;
void str_toupper(char *str)
{
	do{
		*str = toupper(*str);
	}while(*str++);
}
int main(void)
{
	char str[10000];
	fgets(str,sizeof(str),stdin);
	str_toupper(str);
	cout << str;
	return 0;
}

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

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

int n;
cin>>n;
int l=n%10;
if(l==2||l==4||l==5||l==7||l==9)
cout<<"hon"<<endl;
if(l==0||l==1||l==6||l==8)
cout<<"pon"<<endl;
if(l==3)
cout<<"bon"<<endl;

}



Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		//		new Main().solveA();
		new Main().solveB();
		// new Main().solveC();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		int numM = 0;

		try {
			scanner = new Scanner(System.in);
			numM = scanner.nextInt();

			System.out.println(24 + 24 - numM);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int numA = 0;
		int numB = 0;
		String s = "";

		try {
			scanner = new Scanner(System.in);
			numA = scanner.nextInt();
			numB = scanner.nextInt();
			s = scanner.next();
			try {
				String wkA = s.substring(0, numA);
				String wkB = s.substring(numA + 1, s.length());
				Integer.parseInt(wkA);
				Integer.parseInt(wkB);

				if (numA + numB + 1 == s.length()) {
					String wk = s.substring(numA, numA + 1);
					if (wk.equals("-")) {
						System.out.println("Yes");
						return;
					}
				}
			} catch (NumberFormatException e) {
				//				e.printStackTrace();
			}

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
		System.out.println("No");
	}

	private void solveC() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

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

#define mod 1000000007
#define ten5 100005
#define ten6 1000005
#define PI 3.1415926

typedef long long LL;


//int numAC[ten5];
//int numWA[ten5];

int main(void)
{
    long long int sum=0,range=0,ceiling;
    double ans=0.0,half;
    long long int m,n,o,i,j,k=0,money;
    long long int a1,a2=0,a3=0,ar,as,at1;
    char c;
    //vector <int> v;
    //float f,g,h;
    //int c,d,big=0;
    string s,s1;
    cin>>n>>m;
    if(m==1) cout<<0;
    else
    {
        cout<<n-m;
    }
    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define leadinz zero str.erase(0, min(str.find_first_not_of('0'), str.size()-1));
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
string text="abcdefghijklmnopqrstuvwxyz";
const int maxn=1e6+7;
//        .--------------.
//        | Try First One|
//        '--------------'
//                |     .--------------.
//                |     |              |
//                V     V              |
//              .--------------.       |
//              |      AC.     |<---.  |
//              '--------------'    |  |
//              (True)|  |(False)   |  |
//           .--------'  |          |  |
//           |           V          |  |
//           |  .--------------.    |  |
//           |  |   Try Again  |----'  |
//           |  '--------------'       |
//           |                         |
//           |  .--------------.       |
//           '->| Try Next One |-------'
//              '--------------'
ll bin_pow(ll a,ll b,ll m)
{
    ll res=1;
    a%=m;
    while(b>0){
        if(b&1)res=res*a%m;
        b>>=1;
        a=a*a%m;
    }
    return res;
}
bool miller_rabin(ll d,ll n)
{
    ll a=2+rand()%(n-4);
    ll x=bin_pow(a,d,n);
    if(x==1 || x==n-1)return true;
    while(d!=n-1){
        x=(x*x)%n;
        d*=2;
        if(x==1)return false;
        if(x==n-1)return true;
    }
    return false;
}
bool prime(ll n,ll k)
{
    if(n==1 || n==4)return false;
    if(n<=3)return true;
    ll d=n-1;
    while(d%2==0)d/=2;
    for(int i=0;i<k;i++){
        if(!miller_rabin(d,n))return false;
    }
    return true;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k,n;
    cin>>k>>n;
    map<int,int>mp;
    for(int i=0;i<k+1;i++)mp[i]++;
    int cnt=0;
    for(int i=0;i<k+1;i++){
        for(int j=0;j<k+1;j++){
            int sum=n-i-j;
            if(mp.find(sum)!=mp.end())cnt++;
        }
    }
    cout<<cnt;
}


Measured memory_bytes: 384
def check():
    N, M = map(int, input().split())
    A = sorted([int(i) for i in input().split()])
    sousa = sorted([[int(i) for i in input().split()] for i in range(M)],
                   reverse=True, key=lambda x:x[1])
    index = 0
    for cnt, value in sousa:
        for i in range(cnt):
            if index == N:
                break
            if A[index] < value:
                A[index] = value
            else:
                return(sum(A))
            index += 1
    return(sum(A))
print(check())

Measured memory_bytes: 27768
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a[] = new int[n];
    int b[] = new int[n-1];
    int total = 0;
    for(int i=0 ; i<n-1 ; i++){
      b[i] = sc.nextInt();
    }

    a[0] = b[0];

    for(int i=0 ; i<n-1 ; i++){
      if(a[i]>b[i]){
        a[i] = b[i];
      }
      a[i+1] = b[i];
    }
    for(int i=0 ; i<n ; i++){
      // System.out.println(a[i]);
      total = total + a[i];
    }
    System.out.println(total);
  }
}


Measured memory_bytes: 23892
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,s=1;
	
	cin>>n>>k;
	s=k;
	for(int i=2;i<=n;i++)
	{
		s*=(k-1);
		
	}
	cout<<s;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;

int main() {

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n){
        cin >> a[i];
    }
    sort(all(a));

    ll m = 1e9;
    ll x = a[n-1], y;
    rep(i, n){
        if(abs(x/2 - a[i]) < m){
            y = a[i];
            m = abs(x/2 - a[i]);
        }
        if(abs((x+1)/2 - a[i]) < m){
            y = a[i];
            m = abs((x+1)/2 - a[i]);;
        }
    }
    cout << x << " " << y << endl;

    return 0;
}

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

using std::cout;
using std::cin;
using std::endl;
using std::swap;
using std::min;

const int INF = 2147483647;

struct Puzzle{

    int p[33];
    
    void in() {
        for (int i = 1; i <= 30; i++) {
            cin >> p[i];
        }
    }

    bool solved() {
        // front
        for (int i = 1; i < 9; i++) {
            if(p[i] != p[i+1]) return false;
        }
        // back
        for (int i = 22; i < 24; i++) {
            if(p[i] != p[i+1]) return false;
        }
        // side1
        for (int i = 10; i < 12; i++) {
            if(p[i] != p[i+1]) return false;
        }
        // side2
        for (int i = 13; i < 15; i++) {
            if(p[i] != p[i+1]) return false;
        }
        // side3
        for (int i = 16; i < 18; i++) {
            if(p[i] != p[i+1]) return false;
        }
        // side4
        for (int i = 19; i < 21; i++) {
            if(p[i] != p[i+1]) return false;
        }

        return true;
    }

    void rotation1() {
        swap(p[ 1], p[28]);
        swap(p[ 2], p[29]);
        swap(p[ 3], p[30]);
        swap(p[16], p[15]);
        swap(p[19], p[21]);
    }
    void rotation2() {
        swap(p[ 3], p[22]);
        swap(p[ 6], p[25]);
        swap(p[ 9], p[28]);
        swap(p[12], p[19]);
        swap(p[13], p[15]);
    }
    void rotation3() {
        swap(p[ 7], p[22]);
        swap(p[ 8], p[23]);
        swap(p[ 9], p[24]);
        swap(p[13], p[18]);
        swap(p[10], p[12]);
    }
    void rotation4() {
        swap(p[ 1], p[24]);
        swap(p[ 4], p[27]);
        swap(p[ 7], p[30]);
        swap(p[21], p[10]);
        swap(p[16], p[18]);
    }

};

int slv(int n, Puzzle a) {
    if ( 8 < n ) return INF;
    if ( a.solved() ) return n;

    a.rotation1();
    int aa = slv( n + 1, a);
    a.rotation1();
    a.rotation2();
    int b = slv( n + 1, a);
    a.rotation2();
    a.rotation3();
    int c = slv( n + 1, a);
    a.rotation3();
    a.rotation4();
    int d = slv( n + 1, a);
    
    return min( aa, min( b, min ( c, d)));
}

int main() {

    int n;

    cin >> n;

    Puzzle p;

    for( int i = 0; i < n; i++) {
        p.in();
        cout << slv(0, p) << endl;
    }

    return 0;
}


Measured memory_bytes: 3100
# coding:utf-8

import sys
import math
import time
#import numpy as np
import collections
from collections import deque
from collections import Counter
import queue
import copy
import bisect
import heapq
import itertools



sys.setrecursionlimit(10**7)
#N, Q = map(int, input().split())
#G = [list(input()) for i in range(H)]
#INF = V * 10001
#A = [int(i) for i in input().split()]
#AB = [list(map(int, input().split())) for _ in range(K)]

A, B =  map(int,input().split())
ans = A*B
print(ans)


Measured memory_bytes: 68688
#include<stdio.h>
#include<string.h>
int main()
{
int i;
int N;
int D1;
int D2;
int count=0;
int clear=0;
int flag=0;

scanf("%d",&N);
for(i=1;i<N+1;i++){
scanf("%d %d",&D1,&D2);
if(D1==D2 && count == 0 && clear==0 ){count=1; clear=1;}
else if(D1==D2 && count == 1 && clear==1 ){count=2;}  
else if(D1==D2 && count == 2 && clear==1 ){count=3;flag=1;}
else{ clear=0; count=0;}
}

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

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

#define ll long long
#define pb push_back
const int N = 1e5+12;
int n,m,k;


int main()
{
    int T;
    cin >> n >> T;
    int x = 0;
    int mn = N;
    while(n--)
    {
        int x,y;
        cin >> x >> y;
        if(y <= T)
        {
            mn = min(mn,x);
        }
    }
    if(mn == N)
        cout << "TLE";
    else  cout << mn;
}


Measured memory_bytes: 256
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10 ** 9

def dfs(cur, a, b, c):
    if cur == N:
        return  abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
    ret0 = dfs(cur + 1, a, b, c)
    ret1 = dfs(cur + 1, a + l[cur], b, c) + 10
    ret2 = dfs(cur + 1, a, b + l[cur], c) + 10
    ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10
    return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))


Measured memory_bytes: 3064
#from numpy import*
#from scipy import*
from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby
from operator import mul
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
#input=sys.stdin.readline  #危険！基本オフにしろ！
sys.setrecursionlimit(10**6)


def main():
    n=int(input())
    s=set()
    for i in "SHDC":
        for j in range(1,14):
            s.add((i,str(j)))
    x=sorted(s-set(tuple(input().split())for i in range(n)),key=lambda x:int(x[1]))
    
    for j in "SHCD":
        for i in x:
            if j==i[0]:
                print(*i)
if __name__ == '__main__':
    main()


Measured memory_bytes: 6916
import java.util.Scanner;

public class Main {

public static void main(String args[]) {
	Scanner s = new Scanner(System.in);
	int a =s.nextInt();
	int b= s.nextInt();
	if(a<b) System.out.println("a < b");
	if(a>b) System.out.println("a > b");
	if(a==b) System.out.println("a == b");
	s.close();
}


}



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

template <typename T>
class StarrySkyTree {
private:
  int n;
  T init;
  vector<T> seg, __add;

  int size (int N) {
    int ret;
    for (ret = 1; ret < N; ret <<= 1);
    return ret;
  }

  T query(int a, int b, int k, int l, int r) {
    if (r <= a or b <= l) return int(1e9); ///
    if (a <= l and r <= b) return seg[k] + __add[k];

    T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
    T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
    return (min(vl, vr) + __add[k]); ///
  }

  void _add(int a, int b, int x, int k, int l, int r) {
    if (r <= a || b <= l) return; // ???????????????????????§????????°??????
    if (a <= l && r <= b) { // ?????¨?????????????????¨??????????????????????????°x?????????????????????
        __add[k] += x;
        return;
    }

    _add(a, b, x, k * 2 + 1, l, (l + r) / 2);
    _add(a, b, x, k * 2 + 2, (l + r) / 2, r);

    seg[k] = min(seg[k * 2 + 1] + __add[k * 2 + 1], seg[k * 2 + 2] + __add[k * 2 + 2]); ///
  }

public:
  ///
  StarrySkyTree (int N) : n(size(N)), seg(size(N) * 2, 0), __add(size(N) * 2, 0), init(0) {}

  // [l, r) ???????????§???????????¨?????¨???!!! ... [l, r]??????find(l, r + 1)
  T find(int l, int r) {
    return query(l, r, 0, 0, n);
  }

  // [a, b) ??? x ?????????????????????
  void add(int a, int b, int x) {
      _add(a, b, x, 0, 0, n);
  }
};

int main() {
    int n, q, a, s, t, x;
    cin >> n >> q;

    StarrySkyTree<int> sst(n);

    for (int i = 0; i < q; ++i) {
        cin >> a;
        if (a == 0) {
            cin >> s >> t >> x;
            s--, t--;
            sst.add(s, t + 1, x);
        }
        else {
            cin >> x;
            x--;
            cout << sst.find(x, x + 1) << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 4936
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n;
  cin >> n;
  vec a(n);
  for(ll i=0;i<n;i++) {
    cin >> a[i];
  }
  sort(a.begin(),a.end());
  ll sum=0;
  ll ans=1;
  for(ll i=0;i<n-1;i++) {
    sum+=a[i];
    if(2*sum>=a[i+1]) {
      ans++;
    }
    else {
      ans=1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1152
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin,(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int h,w,d;
    cin >> h >> w >> d;
    int a[h][w],total[d];
    map<int,pair<int,int> >m;
    REP(i,h){
        REP(j,w){
            cin >> a[i][j];
            m[a[i][j]] = make_pair(i,j);
        }
    }
    ll answer = 0;
    int q;
    cin >> q;
    int l[q],r[q],left[h*w+1],right[h*w+1];
    REP(i,q){
        cin >> l[i] >> r[i];
    }
    
    FOR(i,0,h*w+1){
        int lx,ly,px,py;
        ly = m[i].first,lx = m[i].second;
            
        
        if(i<=d){
            left[i]=0;
            //continue;
        }
        
        else{
            ly = m[i].first,lx = m[i].second;
            py = m[i-d].first,px = m[i-d].second;
            left[i] = left[i-d]+abs(lx-px)+abs(ly-py);
        }

        //cout << i << " " << lx << " " << ly << endl;
        
    }
    
    FORR(i,h*w,0){
        if(i > h*w-d){
            right[i] = 0;
            continue;
        }
        
        int ly = m[i].first,lx = m[i].second;
        int py = m[i+d].first,px = m[i+d].second;
        right[i] = right[i+d] + abs(lx-px)+abs(ly-py);
    }

    FORR(i,h*w,h*w-d+1){
        total[i%d]=left[i];
    }

    /*REP(i,h*w+1)cout << left[i] << " ";
    cout << endl;
    REP(i,h*w+1)cout << right[i] << " ";
    cout << endl;*/
    
    REP(i,q){
        cout << left[r[i]]+right[l[i]]-total[l[i]%d] << endl;
    }
    
    return 0;
}

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

int main(){
    int K, A, B;
    cin >> K;
    cin >> A >> B;
    if (A % K == 0 || B % K == 0) {
        cout << "OK";
    }
    else {
        if (B / K != A / K) {
            cout << "OK";
        }
        else {
            cout << "NG";
        }
    }
} 

Measured memory_bytes: 3624
using System;
using System.Collections.Generic;
using System.Text;

namespace AtTest.ForBlue.ABC_078
{
    class D
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int z = int.Parse(input[1]);
            int w = int.Parse(input[2]);
            var array = new int[n];
            string[] input2 = Console.ReadLine().Split(' ');
            for (int i = 0; i < n; i++)
            {
                array[i] = int.Parse(input2[i]);
            }

            int abs1 = Math.Abs(array[array.Length - 1] - w);
            int abs2 = 0;
            if (n >= 2) abs2 = Math.Abs(array[array.Length - 2] - array[array.Length - 1]);
            if (abs1 < abs2)
            {
                Console.WriteLine(abs2);
            }
            else
            {
                Console.WriteLine(abs1);
            }
        }
    }
}


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

#define MAX_SOLIDITY 20123 // I checked this value from the editorial since you don't know what the max value is it going to be. 

using namespace std;

class Block
{
    public:
    int weight, solidity;
    long long value; 
    void read(int w, int s, long long v)
    {
        weight = w;
        solidity = s;
        value = v;
    }
    bool operator <(const Block& otherBlock) const
    {
        return weight + solidity < otherBlock.weight + otherBlock.solidity;
    }
};

long long dp[MAX_SOLIDITY+1]; // DDP in the case is the value of blocks with total weight i

int main()
{
    int nBlocks, maxSolidity = 20123; 
    int bW, bS; long long bV;
    long long answer = 0;
    cin >> nBlocks;
    vector<Block> bloques;
    for (int i = 0; i < nBlocks; i++)
    {
        Block happyBlock;
        cin >> bW >> bS >> bV;
        happyBlock.read(bW, bS, bV);
        bloques.push_back(happyBlock);
    }
    sort(bloques.begin(), bloques.end());
    for (int i = 0; i < nBlocks; i++)
    {
        for(int j = min(bloques[i].solidity, maxSolidity - bloques[i].weight); j >= 0; j--)
            dp[j + bloques[i].weight] = max(dp[j + bloques[i].weight], dp[j] + bloques[i].value);
    }
    for(int i = 0; i <= maxSolidity; i++)
    {
        if(dp[i] > answer)
            answer = dp[i];
    }
    cout << answer;
}

Measured memory_bytes: 384
a = gets.chomp.split('')
q = gets.chomp.to_i
flag = true
q.times do
  u, f, c = gets.chomp.split
  if u.to_i == 1
    if flag
      flag = false
    else
      flag = true
    end
  else
    if flag && f.to_i == 1 || !flag && f.to_i != 1
      a.unshift(c)
    else
      a.push(c)
    end
  end
end

if !flag
  a.reverse!
end
puts a.join('')


Measured memory_bytes: 28796
def read_input():
    n, k = map(int, input().split())
    dlist = list(map(int, input().split()))

    return n, k, dlist


def check_inclusion(dislike, target):
    return any(d in target for d in dislike)


def submit():
    n, k, dlist = read_input()

    target = n
    checkee = [int(digit) for digit in str(target)]

    while check_inclusion(dlist, checkee):
        target += 1
        checkee = [int(digit) for digit in str(target)]

    print(target)

if __name__ == '__main__':
    submit()


Measured memory_bytes: 3060
#17:33
n,m = map(int,input().split())
mod = 10 ** 9 + 7
i = 2
tmp = 0
fact = []
while i ** 2 <= m:
  if m % i == 0:
    m //= i
    tmp += 1
  else:
    if tmp > 0:
      fact.append(tmp)
    i += 1
    tmp = 0
if m == i:
  tmp += 1
  fact.append(tmp)
else:
  if tmp > 0:
    fact.append(tmp)
  if m > 1:
    fact.append(1)
#print(fact)
ans = 1
def inv(y):
  z = 1
  while y != 1:
    z *= mod // y + 1
    z %= mod
    y = y - mod % y
  return z
#print(inv(5))
for x in fact:
  for j in range(x):
    ans *= n+j
    ans %= mod
    ans *= inv(j+1)
    ans %= mod
print(ans)

Measured memory_bytes: 3064
import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val A = Array(N) { sc.next().toLong() }
        var ans = 1L
        if (A.contains(0L)) {
            pw.println("0")
            return
        }
        A.forEach {
            val prev = ans
            ans *= it
            if (ans > 1000000000000000000L || ans < prev) {
                pw.println("-1")
                return
            }
        }
        pw.println(ans)
    }
}


Measured memory_bytes: 64628
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 k = sc.nextInt();
		int res=0;
		for(int i=0;i<k;i++)
        {
            if(a!=0)
            {
            	res=res+1;
                a--;
            }
            else if(b!=0)
            {
            	res+=0;
                b--;
            }
            else
            {
            	res=res-1;
                c--;
            }
        }
		System.out.println(res);
	}
}

Measured memory_bytes: 35776
#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct BIT{
public:
    vector<T> array;
    const int n;
    BIT(int _n): array(_n + 1, 0), n(_n) {}
    T sum(int i){
        T s = 0;
        while(i > 0){
            s+= array[i];
            i -= i & -i;
        }
        return s;
    }
    T sum(int left, int right){
        T lsum = sum(left-1);
        T rsum = sum(right);
        return rsum - lsum;
    }
    void add(int place, T x){
        int i = place;
        while(i <= n){
            array[i] += x;
            i += i & -i;
        }
    }
};
int main(void){
    int n,q; cin>>n>>q;
    BIT <int> bina(n);
    for(int i=0;i<q;i++){
        int a,b,c; cin>>a>>b>>c;
        if(a==0) bina.add(b,c);
        else cout<<bina.sum(b,c)<<endl;
    }
    return 0;
}



Measured memory_bytes: 3116
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 300000;
const int mod = 1e9 + 7;
const int K = 60;
const int M = 16;
int a[N], p[N];
int binpow(int x, int y){
    int res = 1;
    while(y){
        if (y % 2) res = res * x % mod;
        y /= 2;
        x = x * x % mod;
    }
    return res;
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n, k;
    cin >> n >> k;
    int ans = 0;
    for (int i = k; i >= 1; i--){
        int x = k / i;
        a[i] = binpow(x, n) % mod;
        for (int j = i + i; j <= k; j += i) a[i] = (a[i] - a[j] + mod) % mod;
        ans = (ans + i * a[i]) % mod;
    }
    cout << ans;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 100000000000

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

	ll N, K;
	cin >> N >> K;

	vector<ll> h(N);
	rep(i, N) {
		cin >> h[i];
	}

	sort(ALL(h));

	ll ans = INF;
	ll diff = 0;
	rep(i, N - K + 1) {
		diff = h[i + K - 1] - h[i];
		ans = min(ans, diff);
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    lli n;
    cin>>n;
    lli i,a[n+2],cur,ans[n+2]={0};
    for(i=1;i<n;i++) 
    {
        cin>>a[i];
        ans[a[i]]++;
    }
    
    for(i=1;i<=n;i++) cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 6768