akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
long long dp[1600009],i,j,ans,sum,a[1600009],x,n,m,k,inf=9999999999999;

int main()
{
	
	cin>>n;
	
	for(i=1;i<=200008;i++)
	dp[i]=inf;
	
	dp[0]=0;
	
	a[1]=1;
	
	x=6;k=1;
	while(x<=n)
	{
		k++;
		a[k]=x;
		x*=6;
	}

	x=9;
	while(x<=n)
	{
		k++;
		a[k]=x;
		x*=9;
	}
		
	
	for(i=0;i<=n;i++)
	{
		for(j=1;j<=k;j++)
		{
			if((i+a[j])<=n){
			
		dp[i+a[j]]=min(dp[i+a[j]],i+a[j]);
		dp[i+a[j]]=min(dp[i]+1,dp[i+a[j]]);

	}
	
		  }
	//cout<<dp[i]<<endl;
	}
	
	cout<<dp[n]<<endl;


	return 0;
}

Measured memory_bytes: 2304
from sys import stdin

N = 5
a = [int(input()) for i in range(N)] 

idx = 0
wk = 9
for i,d in enumerate(a):
    dd = d % 10
    if dd == 0:
        continue
    if dd < wk:
        wk = dd
        idx = i

a[N-1],a[idx] = a[idx],a[N-1]

sum = 0
for i in range(N-1):
    if (a[i] % 10) != 0:
        sum += int((a[i] / 10 + 1)) * 10
    else:
        sum += int(a[i])

sum += a[N-1]

print(sum)

Measured memory_bytes: 3064
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    List<Long> list = new ArrayList<>();
    String[] S = sc.nextLine().split(" ");
    for(int i = 0; i < N; i++){
      long n = Long.parseLong(S[i]);
      list.add(n);
    }
    
    Collections.sort(list, Collections.reverseOrder());
    
    long len1 = 0;
    long len2 = 0;
    long tem = list.get(0);
    for(int i = 1; i < N; i++){
      if(len1 > 0 && len2 > 0){
        break;
      }
      
      if(tem == list.get(i)){
        if(len1 == 0){
          len1 = tem;
          i++;
          tem = list.get(i);
        }else{
          len2 = tem;
        }
      }else{
        tem = list.get(i);
      }
    }
    
    long ans = len1 * len2;
    System.out.println(ans);
  }
}

Measured memory_bytes: 44744
#include <bits/stdc++.h>
using namespace std;
int f[100010][3],a[100010][3],n,ans;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		for(int j=0;j<3;j++)
			cin>>a[i][j];
	for(int i=1;i<=n;i++)
	{
		f[i][0]=max(f[i-1][1],f[i-1][2])+a[i][0];
		f[i][1]=max(f[i-1][0],f[i-1][2])+a[i][1];
		f[i][2]=max(f[i-1][1],f[i-1][0])+a[i][2];
	}
	for(int j=0;j<3;j++)
		ans=max(ans,f[n][j]);
	cout<<ans<<endl;
	return 0;
}

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

char a, b;

void solve() {
    cin >> a >> b;
    cout << ((a == 'H' && b == 'H') || (a == 'D' && b == 'D') ? "H\n" : "D\n"); 
}

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

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

int main(){

    int N, Y;
    cin >> N >> Y;

    for(int i = 0; i <= N; i++){
        for(int j = 0; i + j <= N; j++){
            if(10000*i + 5000*j + 1000*(N - i - j) == Y){
                cout << i << " " << j << " " << (N - i - j) << endl;
                return 0;
            }
        }
    }

    cout << -1 << " " << -1 << " " << -1 << endl;

    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

using System.Collections;

class Program
{
    static void Main()
    {
        int N = int.Parse(Console.ReadLine());

        Console.WriteLine(Enumerable.Range(N, 1000).First(n => isZorome(n)));

    }

    static bool isZorome(int n)
    {
        var x = n % 10;

        while(n != 0)
        {
            if (n % 10 != x)
            {
                return false;
            }
            n /= 10;
        }

        return true;
    }
    
}

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

int main(){
    int n, k;
    cin >> n >> k;
    int count, x;
    rep(i,n){
        cin >> x;
        if(abs(k-x) < x){
            count += 2*abs(k-x);
        }
        else count += 2*x;
    }
    cout << count << endl;
}

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

#define MAX 301

int dp[3][MAX][MAX];
int N, M, v[MAX][3], w[MAX];

void solve(){
  for(int k = 0 ; k < 3 ; k++){
    for(int i = 0 ; i < N ; i++){
      for(int j = 0 ; j <= M ; j++){
	if(j < w[i]) dp[k][i+1][j] = dp[k][i][j];
	else dp[k][i+1][j] = max(dp[k][i][j], dp[k][i+1][j-w[i]] + v[i][k]);
      }
    }
  }
}

int main(){
  string name;
  int V, D, L;
  
  while(cin >> N >> M){
    memset(dp, 0, sizeof(dp));
    for(int i = 0 ; i < N ; i++){
      cin.ignore();
      getline(cin, name);
      cin >> w[i] >> v[i][0] >> v[i][1] >> v[i][2];
    }
    
    solve();
    
    int ans = 0;
    for(int k = 0 ; k < 3 ; k++){
      ans = max(ans, dp[k][N][M]);
    }
    
    bool flag = false;
    for(int i = 0 ; i < N ; i++){
      if(M >= w[i]) flag = true;
    }
    
    if(flag) cout << ans << endl;
    else cout << 0 << endl;
  }
  return 0;
}

Measured memory_bytes: 2276
#include <stdio.h>

int main(){
	int i,a[5];
	for(i = 0;i < 5;i++) {
		scanf("%d",&a[i]);
		if(a[i] < 40) a[i] = 40;
	}
	printf("%d\n",(a[0] + a[1] + a[2] + a[3] + a[4]) / 5);
	return 0;
}

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

int d[10];
int N, k;

bool chk(int n)
{
    while (n) {
        int rem = n % 10;
        n /= 10;
        if (d[rem]) return false;
    }
    return true;
}

int dfs(int n)
{
    if (chk(n)) return n;
    return dfs(n+1);
}

int main()
{
    cin >> N >> k;
    for (int i = 1; i <= k; i++) {
        int tmp;
        cin >> tmp;
        d[tmp]++;
    }

    cout << dfs(N);
}


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

int n;

void dfs (string & s, int index) {
	if (index == n) {
		cout << s << endl;
		return;
	}
	for (int c = 0; c < n; c++) {
		bool valid = false;
		for (int i = 0; i < index; i++) {
			if (s[i] == 'a' + (c - 1)) {
				valid = true; break;
			}
		}
		if (c == 0 || valid) {
			s[index] = 'a' + c;
			dfs (s, index + 1);
		}
	}
}

int main() {
	cin >> n;
	string s = string (n, 'a');
	dfs (s, 1);
	return 0;
}


Measured memory_bytes: 1536
#include<cstdio>
#include<iostream>
#include<algorithm>
#define llint long long int
using namespace std;
int main(void){
	llint n,t,mati=0,sai=0;cin>>n>>t;
	for(int i=0;i<n;i++){
		llint h;cin>>h;
		if(sai<h){sai=h;}
		mati+=h;
		cout<<max((llint)1,1+ (sai+t-mati)/sai)<<endl;
	}
	return 0;
}

Measured memory_bytes: 3120
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main(){
  int N,M,X; cin>>N>>M>>X;
  vector<int>C(N);
  vector<vector<int>> A(N,vector<int>(M));
  for(int i=0;i<N;i++){
    cin>>C[i];
    for(int j=0;j<M;j++)cin>>A[i][j];
  }
  int ans=1000000000;
  bool fin=false;
  for(int bit=0;bit< (1<<N) ;bit++){
    vector<int> argo(M,0);
    int tmp=0;
    for(int i=0;i<N;i++){
      if(bit & (1<<i)){
        tmp+=C[i];
        for(int j=0;j<M;j++)argo[j]+=A[i][j];
      }
      else continue;
    }
    bool tes=true;
    for(int j=0;j<M;j++){
      if(argo[j]<X){
        tes=false;
        break;
      }
    }
    if(tes){
      ans=min(tmp,ans);
      fin=true;
    }
  }
  cout<<(fin ? ans : -1)<<endl;
}

Measured memory_bytes: 3636
#include <iostream>

using namespace std;

void insertSort(int Array[],int n) {
	
	for (int i = 1; i < n; i++) {

		int tmp = Array[i];
		int j = i - 1;
		while(j >= 0 && Array[j] > tmp)
		{
			Array[j + 1] = Array[j];
			j--;
		}
		Array[j + 1] = tmp;

		for (int k = 0; k < n; k++) {
			cout << Array[k] << ((k == n - 1) ? "\n" : " ");
		}
	}
}

int main(void){
	int n;
	cin >> n;
	int *Array = new int[n];

	for (int i = 0; i < n; i++) {
		cin >> Array[i];
		cout << Array[i] << ((i == n - 1) ? "\n" : " ");
	}

	insertSort(Array, n);

	delete[] Array;
	return 0;
}


Measured memory_bytes: 3116
#include <iostream>
using namespace std;
int main(){
  string S,T,U;
  int A,B;
  cin >> S >> T;
  cin >> A >> B;
  cin >> U;
  cout << (S==U?A-1:A) << " " << (T==U?B-1:B) << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int keta(ll A)
{
        int cnt = 0;
        while (A)
        {
                cnt++;
                A /= 10;
        }
        return cnt;
}

int main()
{
        ll N;
        cin >> N;
        int ans = 1000000;
        for (ll A = 1; A * A <= N; A++)
        {
                if (N % A != 0)
                {
                        continue;
                }
                ll B = N / A;
                int AN = keta(A), BN = keta(B);
                ans = min(ans, max(AN, BN));
        }
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 256
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	static int[] l;
	static int n;
	static int a;
	static int b;
	static int c;
	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

        n=gi();
        a=gi();
        b=gi();
        c=gi();
        l=new int[n];

        for (int i=0; i<n;i++) {
            l[i]=gi();
        }

        System.out.println(f(0,0,0,0));
	}

	public static int f(int cur, int av, int bv, int cv) {
        if(cur==n) {
        	if (av==0 || bv==0 || cv==0) {
        		return 100000;
        	} else {
        		return Math.abs(av-a) +Math.abs(bv-b) + Math.abs(cv-c) - 30;
        	}
        }

        int ret1 = f(cur+1, av + l[cur], bv, cv) + 10;
        int ret2 = f(cur+1, av, bv+ l[cur], cv) +10;
        int ret3 = f(cur+1, av, bv, cv+ l[cur]) +10;
        int ret4 = f(cur+1, av, bv, cv);

        return Math.min(Math.min(ret1, ret2), Math.min(ret3, ret4));

	}

	public static int mp(LinkedList<Integer> li, int m) {
		int v = 0;
		Iterator<Integer> it=li.iterator();
		while (it.hasNext()) {
			int ii=it.next();
            v +=l[ii];
		}

		return (10*(li.size()-1)) + Math.abs(v-m);
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

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

int main(){

  int x;
  cin>>x;

  int h = x / 3600;
  int m = (x / 60) % 60;
  int s = x % 60;
  cout<<h<<":"<<m<<":"<<s<<endl;

  return 0;
}



Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int a,b,c,n,ans,h,w,temp,p[300000],q,l[200000],r[200000];
string s;
int main(){
    cin>>n>>q;
    cin>>s;
    for(int i=0;i<q;i++){
        cin>>l[i]>>r[i];
    }
    for(int i=0;i<s.length()-1;i++){
        if(s[i]=='A'&&s[i+1]=='C'){a++;}
        p[i+1]=a;
    }
    for(int i=0;i<q;i++){
        cout<<p[r[i]-1]-p[l[i]-1]<<endl;
    }
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(v) v.begin(), v.end()
#define ll long long
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;

//snippets:tmp,cl,cvl,cs,co,coy,con,cov

int main(){
    string s;
    cin >> s;
    ll count=0;
    rep(i,6){
        count+=s[i]-'0';
    }
    cout << count << endl;
}

Measured memory_bytes: 256
n = int(input())
s = input()
x = 0
y = 0
for i in range(n):
    if s[i] == '(':
        x += 1
    elif s[i] == ')':
        x -= 1
    if x < 0:
        y += 1
        x += 1
print('(' * y + s + ')' * x)

Measured memory_bytes: 3060
use std::collections::{HashSet, VecDeque};

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

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

fn main() {
    input! {
        n: usize, // node count
        q: usize, // query count
        edges: [(usize1, usize1); n-1], // usize1 translate 1-origin to 0-origin
        queries: [(usize1, usize); q]
    }

    let mut edgemap = Vec::new();
    edgemap.resize(n, Vec::new());

    for (n0, n1) in edges {
        edgemap[n0].push(n1);
        edgemap[n1].push(n0);
    }

    let mut qmap = Vec::new();
    qmap.resize(n, 0);
    for (node, score) in queries {
        qmap[node] += score;
    }

    let mut ans = Vec::new();
    ans.resize(n, 0);

    {
        let mut visit = HashSet::new();
        let mut queue = VecDeque::new();

        queue.push_back((0, 0));
        while queue.len() > 0 {
            let (n, ctx) = queue.pop_front().unwrap();
            let score = qmap[n];
            ans[n] = ctx+score;
            visit.insert(n);
            for ref nx in edgemap[n].clone() {
                if !visit.contains(&nx) {
                    queue.push_back((*nx, ans[n]));
                }
            }
        }
    }

    let a: Vec<String> = ans.iter().map(|i| i.to_string()).collect();
    println!("{}", a.join(" "))
}


Measured memory_bytes: 39236
#%%
from itertools import product

#%%
def resolve():
    h,w=map(int,input().split())
    A=['.'+input()+'.' for _ in range(h)]
    A=['.'*(w+2)]+A+['.'*(w+2)]
    flag = 1

    for i,j in product(range(1,h+1),range(1,w+1)):
        if A[i][j]=='#':
            flag = min(flag,A[i-1][j]=='#' or A[i+1][j]=='#' or A[i][j-1]=='#' or A[i][j+1]=='#')

    print("Yes" if flag else "No")
resolve()

Measured memory_bytes: 39024
alp = ('A'..'Z').to_a
Alp = {}
alp.each_with_index do |x, i|
    Alp[i] = x
end

newStrings = []
N = gets.to_i
S = gets.chomp.split('')
S.each do |x|
    i = Alp.key(x)+N
    i -= 26 if i >= 26
    newStrings << Alp[i]
end

puts newStrings.join

Measured memory_bytes: 2300
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int list[] = new int[n];
		for(int i=0; i<n; i++){
			list[i] = sc.nextInt();
		}

		Arrays.sort(list);
		
		int max = list[n-1];
		int sum = 0;
		for(int j=0; j<n-1; j++){
			sum += list[j];
		}

		if(max < sum){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
    }
}

Measured memory_bytes: 22740
#include <stdio.h>

struct node{
  int parent;
  long int distance;
};

int root(int i, struct node *x){
  int k = i;
  while(x[k].parent != k){
    k = x[k].parent;
  }
  return k;
}

long int get_distance(int i, struct node *x){
  int k = i; long int d = 0;
  while(x[k].parent != k){
    d += x[k].distance;
    k = x[k].parent;
  }
  return d;
}

int
main(int argc, char *argv[])
{
  int n, m, l, r, flag = 0; long int d;
  struct node x[100000];
  scanf("%d %d", &n, &m);
  for(int i = 0; i < n; i++){
    x[i].parent = i;
    x[i].distance = 0;
  }
  for(int i = 0; i < m; i++){
    scanf("%d %d %ld", &l, &r, &d);
    l--; r--;
    if(x[r].parent == r){
      if(root(l, x) == r) flag++;
      x[r].parent = root(l, x);
      x[r].distance = d + get_distance(l, x);
    }
    else{
      if(root(r, x) != root(l, x)){
	long c = get_distance(l, x), e = get_distance(r, x);
	int u = root(l, x), v = root(r, x);
	x[r].parent = u;
	x[r].distance = c + d;
	long int D = c + d - e;
	if(D >= 0){
	  x[v].parent = u;
	  x[v].distance = D;
	}
	else{
	  x[u].parent = v;
	  x[u].distance = -D;
	}
      }
      else{
	if(get_distance(l, x) - get_distance(r, x) !=  -d){
	  flag++;
	}
      }
    }
  }

  if(flag > 0) printf("No\n");
  else printf("Yes\n");

  return 0;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<iostream>
#include<cstdlib>

using namespace std;

int top, S[1000];

void push(int);
int pop(void);

int main(void){
    int a,b;
    top = 0;
    char s[100];
    while(EOF != scanf("%s",s)){
        switch(s[0]){
            case '+':
                a=pop();
                b=pop();
                push(a+b);
                break;
            case '-':
                b=pop();
                a=pop();
                push(a-b);
                break;
            case '*':
                a=pop();
                b=pop();
                push(a*b);
                break;
            default :
                push(atoi(s));
                break;
        }
    }
    cout<<pop()<<endl;
    return 0;
}

void push(int x){
    S[++top] = x;
}

int pop(void){
    --top;
    return S[top+1];
}





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

using namespace std;

using ll = long long;

int main() {
    ll N, A, B;cin >> N >> A >> B;
    cout<<max((B * (N - 1) + A) - (A * (N - 1) + B) + 1, 0LL)<<endl;
    return 0;
}

Measured memory_bytes: 256
r, c = (int(x) for x in input().split())
A = [[0 for i in range (c+1)] for j in range (r+1)]

for _ in range(r):
    a = [int(x) for x in input().split()]
    for i,j in enumerate(a):
        A[_][i] = j
        A[-1][i] += j
    A[_][i+1] = sum(a)

A[-1][-1] = sum(A[-1])

for _ in range(r+1):
    for i in range(c+1):
        if i == c:
            print(A[_][i],end="")
            continue
        print(A[_][i],end="")
        print(" ", end="")
    print()    


Measured memory_bytes: 6740
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	x := intScanner()
	a := intScanner()
	b := intScanner()
	fmt.Println(x - a - (x-a)/b*b)
}


Measured memory_bytes: 1772
/*
  AOJ #0346
  title:Rectangle Made with Bars
  @kankichi573
 */
#include <stdio.h>
#include <string.h>

int sort;
int len[12];
int hist[12];
void dump()
{
  int i;
  
  for(i=0;i<sort;i++)
      printf("%d %d|",len[i],hist[i]);
  printf("\n");
}

int main()
{
  int i,j,s,ret;

  sort=0;
  memset(hist,0,sizeof(hist));
  for(i=0;i<12;i++)
    {
      scanf("%d",&s);
      for(j=0;j<sort;j++)
	{
	  if(len[j]==s)
	    {
	      hist[j]++;
	      goto next;
	    }
	}
      hist[sort]=1;
      len[sort]=s;
      sort++;
    next:
      ;
    }
  //dump();
  if((hist[0] % 4)==0 && (hist[1] % 4)==0 && (hist[2] % 4)==0 && sort <=3)
    printf("yes\n");
  else
    printf("no\n");

  
  return(0);
}

Measured memory_bytes: 580
import functools

MOD = 10**9 + 7


def lcm(a, b) -> int:
    c, d = a, b
    while d != 0:
        c, d = d, c % d
    return a // c * b


def inv_mod(x):
    return pow(x, MOD - 2)


def pow(x: int, n: int) -> int:
    res = 1
    while n > 0:
        if n & 1 == 1:
            res = res * x % MOD
        x = x * x % MOD
        n >>= 1

    return res


def main():
    N = int(input())
    an = list(map(int, input().split()))

    lcm_an = functools.reduce(lcm, an)
    lcm_an %= MOD

    ans = 0
    for a in an:
        ans = (ans + lcm_an * inv_mod(a)) % MOD

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 42972
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
from bisect import bisect_left, bisect_right
import random
from itertools import permutations, accumulate, combinations
import sys
import string



INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7


def sequence_xor(x):
    if x % 4 == 1:
        return 1
    elif x % 4 == 3:
        return 0
    elif x % 4 == 0:
        return x
    else:
        return x + 1


a, b = LI()
print(sequence_xor(a - 1) ^ sequence_xor(b))



Measured memory_bytes: 39152
def factor(x):
    ans = []
    for i in range(1, x+1):
        if x % i ==0:
            ans.append(i)
    return sorted(ans)
n = int(input())
count = 0
if n < 105:
    print(count)
else:
    for i in range(105, n+1,2):
        if len(factor(i))==8:
            count +=1
    print(count)

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

int main() {
  int c[3][3];
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> c[i][j];
    }
  }

  int a[3], b[3];
  a[0] = 0;
  b[0] = c[0][0] - a[0];  // 11
  a[1] = c[1][0] - b[0];  // 21
  a[2] = c[2][0] - b[0];  // 31
  b[1] = c[0][1] - a[0];  // 12
  b[2] = c[0][2] - a[0];  // 13

  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (a[i] + b[j] != c[i][j]) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
#define endl "\n"
#define IOS ios::sync_with_stdio(false); cin.tie(nullptr); cout.precision(10); cout << fixed;
 
const int N = 1e5+5;
string a[] = {"SAT","FRI","THU","WED", "TUE", "MON", "SUN"};
 
int32_t main()
{
   string s;
   cin >> s;
   for(int i = 0; i < 7; i++)
   {
      if(a[i] == s)
         return cout << i+1, 0;
   }
   return 0;
}

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

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

    sort(a, a + n);
    cout << a[n - 1] - a[0] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define pb push_back
#define mod 1000000007
#define inf 10000000007
#define ff first
#define ss second
#define endl "\n"
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

int main()
{
    IOS
    int n,ans= 0,a1 = 0;
    cin>>n;
    int a[n+1];
    map<int,int> mp;
    vector<pair<int,int> > vp1,vp2;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i = 1;i<=n;i+=2)
    {
        mp[a[i]]++;
    }
    int f = 0;
    for(map<int,int>::iterator it = mp.begin();it!=mp.end();it++)
    {
        vp1.push_back(make_pair(it->second,it->first));
    }
    
    mp.clear();
    f = 0;
    for(int i = 2;i<=n;i+=2)
    {
        mp[a[i]]++;
    }
    for(map<int,int>::iterator it = mp.begin();it!=mp.end();it++)
    {
        vp2.push_back(make_pair(it->second,it->first));
    }
    sort(vp1.begin(),vp1.end());
    sort(vp2.begin(),vp2.end());
    reverse(vp1.begin(),vp1.end());
    reverse(vp2.begin(),vp2.end());
    int k = n/2;
    if(vp1[0].second != vp2[0].second)
    {
        cout<<n-vp1[0].first-vp2[0].first;
    }
    else
    {
        if(vp1.size() == 1 && vp2.size() == 1)
        {
            cout<<k;
        }
        else if(vp1.size() == 1)
        {
            cout<<k-vp2[1].first;
        }
        else if(vp2.size() == 1)
        {
            cout<<k-vp1[1].first;
        }
        else
        {
            cout<<min(n-vp1[0].first-vp2[1].first,n-vp1[1].first-vp2[0].first);
        }
    }
    return 0;

}


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

using namespace std;

int main()
{
    string a,b;
    cin>>a>>b;
    int res=0,ans=0;
    for(int i=0;i<a.size();i++)
    {
        int t=i;
        ans=0;
        if(t+b.size()<=a.size())
        {
            for(int j=0;j<b.size();j++)  if(a[t++]==b[j]) ans++;
            res=max(res,ans);
        }
        else break;
    }
    cout<< b.size()-res <<endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int mod=1e9+7;
const int N=4e4+5;

int main(){
ios::sync_with_stdio(0);
ll x,sum=100,cnt=0;
cin>>x;
while(x>sum){
    sum*=1.01;
    cnt++;
}
cout<<cnt<<endl;
return 0;
}

Measured memory_bytes: 3648
n=int(input())
s=[input() for i in range(n)]
m,a,r,c,h=0,0,0,0,0
for i in range(len(s)):
    x=s[i][0]
    if x=="M":m+=1
    elif x=="A":a+=1
    elif x=="R":r+=1
    elif x=="C":c+=1
    elif x=="H":h+=1
print(m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h)


Measured memory_bytes: 55640
/**
Author : Dhruvil Patel (Dp)
**/

#include <bits/stdc++.h>

using namespace std;

long long int gcd(long long int a , long long int b)
{
    if(b==0)
    {

        return a;
    }
    return gcd(b,a%b);


}
long long int maxix(long long int a,long long int b)
{
    if(a>b)
    {

        return a;
    }
    return b;

}
long long int minix(long long int a,long long int b)
{

    if(a<b)
    {

        return a;
    }
    return b;
}

int isprime(long long int n)
{
  if(n==1) {return 0;}
long long int c=0,i;

for(i=1;i<=sqrt(n);i++)
{
  if(n%i==0)
  {c++;}
}

  if(c==1)
  {
    return 1;
  }
  return 0;
}


void solve()
{

char a;
cin>>a;

if(a<97)
{
  cout<<"A";
}
else{
  cout<<"a";
}
}


int main()
{

  // #ifndef ONLINE_JUDGE
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  // #endif

  long long int t;

  solve();


  return 0;
}


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

#define calc(x) (x*M_PI/180.0)

using namespace std;

int main()
{
  int a, b;
  double x=0, y=0, r=0;

  while(scanf("%d,%d",&a,&b) != EOF && !(a == 0 && b == 0)){
    x += (double)a*sin(calc(r));
    y += (double)a*cos(calc(r));
    r += (double)b;
  }
  printf("%d\n%d\n", (int)x, (int)y);

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

typedef long long i64;

set<int> D;
bool hate(i64);

int main(void) {
    i64 N, K;
    cin >> N >> K;

    int d, i;
    for (i=0; i<K; i++) {
        cin >> d;
        D.insert(d);
    }

    while (hate(N)) {
        N++;
    }

    cout << N << endl;

    return 0;
}


bool hate(i64 N) {
    int d;
    while (N) {
        d = N % 10;
        if (D.count(d)) return true;

        N /= 10;
    }
    return false;
}


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

#define INTINF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int tmp;
	ll ans = 0;
	int n;
	cin >> n;
	ll a[n+1], sum = 0;
	REP(i, n+1){
		cin >> a[i];
		sum += a[i];
	}
	bool ch = true;
	ll now = 1;
	REP(i, n+1){
		if(now < a[i]) ch = false;
		ans += now;
		sum -= a[i];
		now -= a[i];
		now = min(sum, now * 2);
	}
	if(ch)cout << ans << endl;
	else cout << -1 << endl;
}


Measured memory_bytes: 4380
import java.util.Scanner;

public class Main {
	public static void main(String[]args){
		
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		
		
		int x = 0;
		int max = x;
		
		
		char[] s = new char [N];
		s = scan.next().toCharArray();
		
		for(int i = 0;i<N;i++){
			if(s[i]=='I'){
				x+=1;
				if(max<x){
					max=x;
				}
				
			}
			
			if(s[i]=='D'){
				x-=1;
				
			}
			
		}
		
		
		
		System.out.println(max);
		
		
	}

}


Measured memory_bytes: 23892
#include <stdio.h>
#define N 1000

void trace(int *, int);

int main(void){
  
  int n,i,j,key;
  int A[N+1];
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++) scanf("%d",&A[i]);
    
  
  trace( A, n);
  
  for(i=1;i<=n-1;i++){
    
    key = A[i];
    
    j = i -1;
    
    while( j >= 0 && A[j] > key ){
      
      A[j+1] = A[j];
      
      j--;
    }
    
    A[j+1] = key;
    
    trace(A,n);
    
  }

  return 0;
}

void trace( int A[], int n){
  
  int i;
   
  for (i=0;i<n;i++){
    if( i > 0) printf(" ");
    printf("%d",A[i]);
  }
  printf("\n");
}

Measured memory_bytes: 608
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <unordered_map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;
using ll = long long;

ll L, N;
vector<ll> X;

void input() {
    cin >> L >> N;
    X.resize(N);
    for (auto& v : X)
        cin >> v;
//    L = 10, N = 3;
//    X = vector<ll>{2, 7, 9};
}

ll solve() {
    vector<ll> clenl(N), clenr(N);
    clenl[0] = X[0] * 2;
    for (ll i = 1; i < N; i++) {
        clenl[i] = clenl[i - 1] + X[i] * 2;
    }
    vector<ll> RX(N);
    transform(X.begin(), X.end(), RX.begin(), [](ll x) {
        return L - x;
    });
    clenr[N - 1] = RX[N - 1] * 2;
    for (ll i = N - 2; i >= 0; i--) {
        clenr[i] = clenr[i + 1] +  RX[i] * 2;
    }
    
    ll ans = 0;
    for (ll i = 0; i < N * 2; i++) {
        ll k = i % N;
        bool fleft = i < N;
        ll cans = 0;
        if (fleft) {
            ll resi = N - k - 1;
            ll cl = resi / 2;
            cans += clenl[k + cl] - (k > 0 ? clenl[k - 1] : 0);
            if (resi % 2 == 0)
                cans -= X[k + cl];
            ll cr = resi / 2 + resi % 2;
            if (cr > 0) {
                cans += clenr[N - cr];
                if (resi % 2)
                    cans -= RX[N - cr];
            }
        } else {
            ll resi = k;
            ll cl = resi / 2 + resi % 2;
            if (cl > 0) {
                cans += clenl[cl - 1];
                if (resi % 2)
                    cans -= X[cl - 1];
            }
            ll cr = resi / 2;
            cans += clenr[k - cr] - (k < N - 1 ? clenr[k + 1] : 0);
            if (resi % 2 == 0)
                cans -= RX[k - cr];
        }
        
        ans = max(ans, cans);
    }
    return ans;
}


int main() {
    input();
    cout << solve() << endl;;
    
    return 0;
}



Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1e9+7;
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}
int main(){
  ll N;
  cin>>N;

  
  vector<string>s(N);
  
  for(ll i=0;i<N;i++){
    cin>>s[i];
    sort(s[i].begin(),s[i].end());
  }
  
  sort(s.begin(),s.end());
  
  ll ans=0;
  ll sum=1;
  
  for(ll i=1;i<N;i++){
    
    if(s[i-1]==s[i]){
      sum++;
    }
    
    else if(sum>0&&s[i-1]!=s[i]){
      ans+=(sum*(sum-1))/2;
        sum=1;
    }
    
    if(i==N-1&&sum>0){
      ans+=sum*(sum-1)/2;
  }
  }
  
  cout<<ans<<endl;
  

  
}

Measured memory_bytes: 7296
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,mod,x,ans;
int a[1000005];
int a2[1000005];
signed main()
{
	cin>>n>>x>>mod;
	int pos=0,len=0,pos2=n,sum=0;
	if(n<=100000)
	{
		for(int i=1;i<=pos2;i++)
		{
			ans+=x;
			x=(x*x)%mod;
		}
		cout<<ans;
		return 0;
	}
	for(int i=1;i<=n;i++)
	{
		ans+=x;
		a[x]=i;
		a2[i]=x;
		x=(x*x)%mod;
		if(a[x])
		{
			pos=a[x];
			pos2-=i;
			len=max(1LL,i-pos+1);
			for(int k=pos;k<=i;k++) sum+=a2[k];
			break;
		}
	}
	ans+=(pos2/len)*sum;
	pos2%=len;
	for(int i=1;i<=pos2;i++)
	{
		ans+=x;
		x=(x*x)%mod;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
// clang-format off

using LL = long long;
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
 
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
// clang-format on

void solve(long long N, long long K) {
  // solver code

  int cnt = 0;

  while (N + 1 > pow(K, cnt)) {
    cnt++;
  }

  cout << cnt << endl;
}

int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  solve(N, K);
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
int main(){
  int A,B,C;
  str S;
  cin>>A>>B;
  if(A>B){
    if(A-1>B)cout<<A+A-1<<endl;
    else if(A-1<=B)cout<<A+B<<endl;
  }
  if(A<B){
    if(B-1>A)cout<<B+B-1<<endl;
    else if(A>=B-1)cout<<A+B<<endl;
  }
  else if(A==B)cout<<A+A<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<array>

using namespace std;
 
int main(){
    int a,b;
    cin >> a >> b;
    if((a%2 != 0) && (b%2 != 0))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


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

using namespace std;

int main() {
	int a;
	cin >> a;
	vector<int> b(a);
	for (int i = 0; i < a; i++) {//read
		cin >> b.at(i);
	}
	if (b.at(0) != 0) {
		cout << 0 << endl;
		return 0;
	}
	sort(b.begin(), b.end());
	int xm = 0, im = 0;
	for (int i = 0; i < a; i++) {//0
		if (b.at(i) == 0) {
			xm++;
			im++;
		}
		else {
			break;
		}
	}
	if (xm == 0||xm>1) {
		cout << 0 << endl;
		return 0;
	}
	int64_t ans=1;
	int xn = 0;
	for (int j = 1; j < a; j++) {//1~
		for (int i = im; i < a; i++) {
			if (b.at(i) == j) {
				xn++;
				im++;
			}
			else {
				if (xn == 0) {
					if (b.at(i) > j) {
						cout << 0 << endl;
						return 0;
					}
				}
				break;

			}
		}
		for (int k = 0; k < xn; k++) {
			ans *= xm;
			ans = ans % 998244353;
		}
		xm = xn;
		xn = 0;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo 1e18
#define endl '\n'
#define si size()
#define all(v) v.begin(),v.end()
#define FASTIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define Matrix vector< vector < long long > >
#define vi vector<int>
#define vll vector<ll>
#define vd vector<double>
#define vs vector<string>



using namespace std;

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

const long double Pi=acos(-1),e=2.718;
const int N=1e2+10,mod=1e9+7;
int main ()
{
    FASTIO
    string s;
    cin >> s;
    char c=s[s.si-1];
    if(c=='3'){
        cout << "bon" << endl;
    }
    else if(c=='0' || c=='6' || c=='1' || c=='8'){
        cout << "pon" << endl;
    }
    else {
        cout << "hon" << endl;
    }
    return 0;
}
/**

*/


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


  int h,m,s;
 
  cin >>s;
  
  h=s/3600 ;
  
  s=s%3600;

  m=s/60;

  s%=60;

  cout<<h<<":"<<m<<":"<<s<<endl;
  
  return 0;
}

Measured memory_bytes: 3084
def deque(a):
    n = len(a)
    cur = [(x, 0) for x in a]
    nxt = [(0, 0)] * n
    for l in range(2, n + 1):
        for i in range(n - l + 1):
            j = i + l - 1
            x, y = cur[i]
            z, t = cur[i + 1]
            if a[i] + t - z > a[j] + y - x:
                nxt[i] = (a[i] + t, z)
            else:
                nxt[i] = (a[j] + y, x)
        cur, nxt = nxt, cur
    return cur[0][0] - cur[0][1]


def main():
    input()  # n
    a = [int(x) for x in input().split()]
    return deque(a)


print(main())


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

int main(){
  int a,b,c;
  cin >>a >>b >>c;
  if(a==b) cout << c << endl;
  if(a==c) cout << b << endl;
  if(b==c) cout << a << endl; 
  return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc127/tasks/abc127_a

#include <bits/stdc++.h>
using namespace std;
int main() {
    int a, b;
    cin >> a >> b;

    if(a <= 5) cout << 0 << endl;
    else if(a <= 12) cout << b/2 << endl;
    else cout << b << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
const int maxn=20010;
const int INF=1<<28;
struct edge{
	int to,dis,cost;
};
typedef pair<int,int> P;
int n,m;
vector<edge> g[maxn];
int d[maxn];
int pay[maxn];
void dijkstra(int s)
{
	priority_queue<P,vector<P>, greater<P> >que;
	fill(d,d+n+1,INF);
	fill(pay,pay+n+1,INF);
	d[s]=0;
	que.push(P(0,s));
	while(!que.empty())
	{
		P p=que.top(); que.pop();
		int v=p.second;
		if(d[v]<p.first)  continue;
		for(int i=0;i<g[v].size();i++)
		{
			edge e=g[v][i];
			//cout<<e.to<<"abd"<<endl;
			if(d[e.to]>d[v]+e.dis){
				d[e.to]=d[v]+e.dis;
				pay[e.to]=e.cost;
				//num[e.to]=min(num[e.to],pay[e.to]);
				que.push(P(d[e.to],e.to));
			}else if(d[e.to]==d[v]+e.dis){
				pay[e.to]=min(e.cost,pay[e.to]);
			}
		}
	}
}
int main()
{
    while(cin>>n>>m)
	{
		if(n+m==0)  break;
		for(int i=0;i<=maxn-1;i++) g[i].clear();
		for(int i=0;i<m;i++)
		{
			int u,v,d,c;
			scanf("%d%d%d%d",&u,&v,&d,&c);
			edge e;
			e.to=v,e.dis=d,e.cost=c;
			g[u].push_back(e);
			edge e1;
			e1.to=u,e1.dis=d,e1.cost=c;
			g[v].push_back(e1);
		}
		dijkstra(1);
		int sum=0;
		for(int i=2;i<=n;i++){
			sum+=pay[i];
		}
		cout<<sum<<endl;
	}
    return 0;
}

Measured memory_bytes: 5428
#include<iostream>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if((a==1||a==2)&&(b==1||b==2))
        cout<<"3"<<endl;
    else if((a==2||a==3)&&(b==3||b==2))
        cout<<"1"<<endl;
    else if((a==1||a==3)&&(b==3||b==1))
        cout<<"2"<<endl;
    return 0;
}


Measured memory_bytes: 256
from itertools import combinations
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
for p, q in combinations([a, b, c, d, e], 2):
    if abs(p - q) > k:
        print(":(")
        exit()
print("Yay!")


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it=x.begin();it!=x.end();it++) cout<<*it<<' '; cout<<endl;
#define printii(x)  for(auto it=x.begin();it!=x.end();it++) cout<<*it.F<<' '<<*it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)
ll dp[2002][2002];

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,x,t,m;
	cin>>n;
	vii b(n);
	for(int i=0;i<n;i++){
		cin>>b[i].F;
		b[i].S = i;
	}
	sort(all(b),greater<ii>());
	for(int i=1;i<=n;i++){
		for(int j=0;j<=i;j++){
			if(i!=j){
				dp[i][j] = max(dp[i][j], dp[i-1][j] + abs(n-i+j - b[i-1].S)*b[i-1].F);
			}   
			if(j){
				dp[i][j] = max(dp[i][j], dp[i-1][j-1]+ abs(j-1 - b[i-1].S)*b[i-1].F);
			}
		}
	}
	ll ans = -1;
	for(int j=0;j<=n;j++){
		ans = max(ans, dp[n][j]);
	}
	cout<<ans;




	return 0;
}






Measured memory_bytes: 26304
def main():
    n = int(input())
    l = []
    d = {}
    for i in range(n):
        s,p = input().split()
        if s not in l:
            l.append(s)
            d[s] = []
        d[s].append([int(p), i+1])
    
    for i in sorted(l):
        for j in sorted(d[i], reverse=True):
            print(j[1])
main()  

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

int main() {
    int N, A, B;
    cin>>N>>A>>B;
    string str;
    cin>>str;
    vector<bool> status(N, false);
    int j_pass = 0;
    int o_pass = 0;
    for (int i = 0; i < N; i++) {
        if (str[i] == 'a') {
            if (j_pass + o_pass < A + B) {
                status[i] = true;
                j_pass++;
            }
        }
        else if (str[i] == 'b') {
            if (j_pass + o_pass < A + B && o_pass < B ) {
                status[i] = true;
                o_pass++;
            }
        }
    }
    for (int i = 0 ; i < N; i++) {
        if (status[i]) {
            cout<<"Yes"<<endl;
        }
        else {
            cout<<"No"<<endl;
        }
    }
    //std::cout << "Hello, World!" << std::endl;
    return 0;
}

Measured memory_bytes: 896
/*
 * Since g++10 is released, some characters is not valid inside #if 0 :(
 * So, why not using clang++? :D

 * Date:
  echo -n '  ' && date +%Y.%m.%d # Just Run this (Type !!sh in Vim).

 * Solution:
  To be updated after "Accept".

 * Digression:

 * CopyRight:
          ▁▃▄▄▄▃▃▃▃▄▶
        ▗▇▀▔    ▔▔▔▔
       ▄▛   ▃▅━━■▄▂
      ▟▊   ▐▘     ▀▙
     ▟▜▌   ▐▖   ▋  ▐▍
    ▟▘ ▜   ▝▀▇▆●▘  ▐▌
  ▗▟▘   ▜▃       ▁▅▛
  ▔▀▼▅▄▃▃██▅▄▄▄▅■▀▔
        ▔▔▔▔▔▔
 */

#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
	template<class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator () (a...); }
} read;

const int maxn = 200005;
int a[maxn], b[maxn];

int main () {
	int n = read, m = read;
	for (int i = 1; i <= n; i ++) read(a[i]);
	while (m --) {
		for (int i = 1; i <= n; i ++) {
			int l = std::max(1, i - a[i]), r = std::min(i + a[i], n);
			++ b[l];
			-- b[r + 1];
		}
		bool full = 1;
		for (int i = 1; i <= n; i ++) {
			a[i] = b[i] + a[i - 1];
			b[i] = 0;
			full &= a[i] == n;
		}
		if (full) break;
	}
	for (int i = 1; i <= n; i ++)
		printf("%d ", a[i]);
	puts("");
}


Measured memory_bytes: 3292
#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
struct node
{
	int l,r,data,miner;
};
struct note
{
	int v,next;
};
node tree[5000001];
note edge[5000001];
long long a[5000001],p[5000001],s1,s2,ans[5000001],res[5000001],head[5000001],len,in[5000001],n,length;
priority_queue<int>q;
void add(int x,int y)
{
	edge[++len].v=y;
	edge[len].next=head[x];
	head[x]=len;
	in[y]++;
	return;
}
void build(int k,int l,int r)
{
	tree[k].l=l;
	tree[k].r=r;
	tree[k].data=1e9;
	if (l==r)
		return;
	int mid=(l+r)/2;
	build(k*2,l,mid);
	build(k*2+1,mid+1,r);
	return;
}
void adder(int k,int x,int d)
{
	if (tree[k].l==tree[k].r)
	{
		tree[k].data=d;
		return;
	}
	int mid=(tree[k].l+tree[k].r)/2;
	if (x<=mid)
		adder(k*2,x,d);
	else
		adder(k*2+1,x,d);
	tree[k].data=min(tree[k*2].data,tree[k*2+1].data);
	return;
}
int query(int k,int l,int r)
{
	if (l>r)
		return 1e9;
	if (tree[k].l==l&&tree[k].r==r)
		return tree[k].data;
	int mid=(tree[k].l+tree[k].r)/2;
	if (l<=mid&&r<=mid)
		return query(k*2,l,r);
	if (l>=mid+1&&r>=mid+1)
		return query(k*2+1,l,r);
	return min(query(k*2,l,mid),query(k*2+1,mid+1,r)); 
}
void top_sort()
{
	int top;
	for (int i=1;i<=n;++i)
		if (in[i]==0)
			q.push(-i);
	while (!q.empty())
	{
		top=-q.top();
		q.pop();
		ans[top]=++length;
		for (int i=head[top];i>0;i=edge[i].next)
		{
			in[edge[i].v]--;
			if (in[edge[i].v]==0)
				q.push(-edge[i].v);
		}
	}
	return;
}
int main()
{
	int k;
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;++i)
	{
		scanf("%d",&a[i]); 
		p[a[i]]=i;
	}
	build(1,1,n);
	for (int i=n;i>=1;--i)
	{
		s1=query(1,max(p[i]-k+1,1ll),p[i]-1);
		if (s1!=1e9)
			add(p[i],p[s1]);
		s2=query(1,p[i]+1,min(p[i]+k-1,n));
		if (s2!=1e9)
			add(p[i],p[s2]);
		adder(1,p[i],i);
	}
	top_sort();
	for (int i=1;i<=n;++i)
		printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 58880
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
char a;
int main(){
    cin>>a;
    if(a>='a'&&a<='z'){
        cout<<'a'<<endl;
    }else{
        cout<<'A'<<endl;
    }
    return 0;
}


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

int main() {
    char a;
    cin >> a;

    if (a >= 'a' && a <= 'z') {
        cout << 'a' << endl;
    } else {
        cout << 'A' << endl;
    }

    return 0;
}


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

int main()

{
    unsigned long long int a,b,GCD,LCM,m,temp;

    while( scanf("%llu %llu", &a, &b) != EOF)
    {
        m = a*b;
        {
            while(b!=0)
            {
                temp = b;
                b = a % b;
                a = temp;
            }
        GCD = a;
        }

        LCM = (m / GCD);
        printf("%llu %llu\n", GCD, LCM);
    }

    return 0;
}

Measured memory_bytes: 604
def func(x):
    if(x % 100 != 0):
        return 0
    else:
        return func(x / 100) + 1

if __name__ == '__main__':
    d, n = map(int, input().split())
    x = 1
    cnt = 0
    while True:
        if func(x) == d:
            cnt += 1
        if cnt == n:
            print(x)
            exit()
        x += 1

    

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

using namespace std;
#define taskname "TEST"
#define pb	push_back
typedef long double ld;
typedef long long ll;
const int maxn = 1e5 + 5;
int n ,  a , b;
int h[maxn];
ll nh[maxn];

int MinTime(ll need , ll left)
{
    int l = 0;
    int h = left;
    while(l <= h)
    {
        int mid = l + h >> 1;
        if((ll)mid * a + b * (left - mid) >= need)h = mid - 1;
        else l = mid + 1;
    }
    return l;
}

bool chk(ll nTime)
{
    int used = 0;
    for(int i = n ; i >= 1 ; --i)
    {
        int w = MinTime(h[i] - (ll)used * b , nTime);
        nTime -= w;
        used += w;
        if(nTime < 0)return 0;
    }
    return 1;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	if(fopen(taskname".INP","r"))
        freopen(taskname".INP", "r",stdin) ,
        freopen(taskname".OUT", "w",stdout);
    cin >> n >> a >> b;
    for(int i = 1 ; i <= n ; ++i)cin >> h[i];
    sort(h + 1 , h + n + 1);
    ll l = 1;
    ll h = 1e14;
    while(l <= h)
    {
        int mid = l + h >> 1;
        if(chk(mid))h = mid - 1;
        else l = mid + 1;
    }
    cout << l;
}


Measured memory_bytes: 640