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


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

    int n;
    cin>>n;

    vector<pair<int, int>> v(n);
    for (int i=0; i<n; i++) {
        cin>>v[i].first;
        v[i].second = i;
    }

    sort(v.begin(), v.end());

    long long ans = 0;
    for (int i=0; i<n; i++)
        if (i%2 != v[i].second%2)
            ans++;

    cout<<ans/2<<endl;
}


Measured memory_bytes: 3940
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int number = scan.nextInt();
		for(int i = 1; i<=number; i++){
			int x = i;
			if(x%3==0){
				System.out.print(" "+i);
			}else if(x % 10 == 3){
				System.out.print(" "+i);
			}else{
				while(true){
				if(x%10==3){
					System.out.print(" "+i);
					break;
			}
			x = x/10;
			if(x==0){
				break;
			}
			}
			}
		}
		System.out.println();
	    }
	}
 


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

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	ll n,k;
	cin>>n>>k;
	n %= k;
	cout<<min(n,k-n)<<endl;
	return 0;
}

Measured memory_bytes: 3564
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
long long n,a[10],b[10],cnt1[5555],cnt2[5000*5000+10];
int main()
{
	cin>>n>>a[0]>>a[1]>>a[2]>>b[0]>>b[1]>>b[2];
	for(long long i=0;i<3;i++)
	{
		for(long long j=a[i];j<=n;j++)
		{
			cnt1[j]=max(cnt1[j],cnt1[j-a[i]]+b[i]-a[i]);
		}
	}
	long long k=cnt1[n]+n;
	for(long long i=0;i<3;i++)
	{
		for(long long j=b[i];j<=k;j++)
		{
			cnt2[j]=max(cnt2[j],cnt2[j-b[i]]+a[i]-b[i]);
		}
	}
	cout<<cnt2[k]+k<<endl;
	return 0;
}

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

double sign;
double ans;

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

	for(ll i = 0; i <= 1000; i++){
		for(ll j = 0; j < i; j++){
			if(pow(i,5) - pow(j,5) == n){
				cout << i << " " << j << endl;
				return 0;
			}
			if(pow(i,5) + pow(j,5) == n){
				cout << i << " " << -j << endl;
				return 0;
			}
		}
	}
}


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

using namespace std;
typedef long long ll;
using Graph =vector<int>;
typedef pair<int,int> P;
const ll MAX_N=131072;
const ll INF=1000000;
const ll MOD=1000000007;

int main(){
    int A,B,C;cin>>A>>B>>C;
    if ((A==5 &&B==5&&C==7) ||(A==5 &&B==7&&C==5)||(A==7 &&B==5&&C==5)) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
import java.util.List;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);
	    String s=gs();
	    String t=gs();
	    int c=0;
	    for (int i=0; i<3;i++) {
	    	if(s.charAt(i)==t.charAt(i))c++;
	    }

	   
	    System.out.print(c);

//        if (a>=3200) {
//        	System.out.print(s);
//        }else {
//        	System.out.print("red");
//        }


	}
	// 文字列として入力を取得
	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: 35636
#include <bits/stdc++.h>

#define whole(f, x, ...)                                 \
  ([&](decltype((x)) whole) {                            \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__); \
  })(x)

using namespace std;
using ll = long long;

void solve() {
  int s, w;
  cin >> s >> w;

  if (w >= s) {
    cout << "unsafe" << endl;
  } else {
    cout << "safe" << endl;
  }
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


Measured memory_bytes: 3640
indirect enum BinaryTree {
    case node(BinaryTree, Int, BinaryTree)
    case empty

    init(array: [Int]) {
        guard !array.isEmpty else {
            self = .empty
            return
        }

        self = .node(
            .init(array: array, index: 1, depth: 1),
            array[0],
            .init(array: array, index: 2, depth: 1)
        )
    }

    private init(array: [Int], index: Int, depth: Int) {
        if index >= array.count {
            self = .empty
            return
        }
        self = .node(
            .init(array: array, index: index * 2 + 1, depth: depth+1),
            array[index],
            .init(array: array, index: index * 2 + 2, depth: depth+1)
        )
    }

    func count() -> Int {
        switch self {
        case .node(let left, let value, let right):
            var count = 0
            if case .node = left {
                count += value + left.count()
            }
            if case .node = right {
                count += value + right.count()
            }
            return count
        case .empty:
            return 0
        }
    }
 }

let n = readLine()!
var AN = readLine()!.split(separator: " ").compactMap { Int($0) }.sorted(by: { $0 > $1 })
let first = AN[0]
AN.removeFirst()
let binaryTree = BinaryTree(array: AN)
print(first + binaryTree.count())


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

using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <class T, class U>
void chmax(T &a, U b) {
    if (a < b) a = b;
}
template <class T, class U>
void chmin(T &a, U b) {
    if (b < a) a = b;
}

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 50);

void solve(long long A, long long B) {
    int ans = inf;
    rep(i, 1000000) {
        if (int(i * 0.08) == A and int(i * 0.1) == B) chmin(ans, i);
    }

    if (ans == inf) ans = -1;
    cout << ans << endl;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    solve(A, B);
    return 0;
}


Measured memory_bytes: 256
S = input()
rl = []
ids = []
c = 1
for i,(a,b) in enumerate(zip(S,S[1:])):
    if a==b:
        c += 1
    else:
        rl.append(c)
        c = 1
        ids.append(i)
rl.append(c)

ans = [0] * len(S)
for i,(r,l) in enumerate(zip(rl[::2],rl[1::2])):
    j = ids[i*2]
    s = (r+l)//2
    if r%2 == l%2:
        ans[j] = ans[j+1] = s
    elif r%2:
        ans[j] = s+1
        ans[j+1] = s
    else:
        ans[j] = s
        ans[j+1] = s+1

print(*ans)

Measured memory_bytes: 11116
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<int> x(N),y(N),h(N);
    for(int i=0;i<N;i++){
        cin>>x[i]>>y[i]>>h[i];
    }
    int MAX=100;
    for(int posY=0;posY<=MAX;posY++){
        for(int posX=0;posX<=MAX;posX++){
            int needH=-1;
            for(int i=0;i<N;i++){
                if(h[i]>0){
                    int tmp=h[i]+abs(posY-y[i])+abs(posX-x[i]);
                    if(needH==-1){
                        needH=tmp;
                    }else{
                        if(needH !=tmp){
                            needH=-2;
                            break;
                        }
                    }
                }
            }
            if(needH==-2)continue;
            for(int i=0;i<N;i++){
                if(h[i]==0){
                    int dist=abs(posY-y[i])+abs(posX-x[i]);
                    if(needH > dist){
                        needH = -2;
                        break;
                    }
                }
            }
            if(needH == -2)continue;
            cout<<posX<<" "<<posY<<" "<<needH<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
mod = 10 ** 9 + 7

A.sort()
if N % 2 == 0:
    # print(A[0:N:2])
    # print(A[1:N+1:2])
    if A[0:N:2] != A[1:N+1:2]:
        print(0)
        exit(0)
else:
    if A[0] != 0:
        print(0)
        exit()
    if A[1:N-1:2] != A[2:N:2]:
        print(0)
        exit()

print(2 ** (N // 2) % mod)

Measured memory_bytes: 14008
#include <iostream>
#include <string>

int main(){

  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  std::string s;
  std::cin >> s;

  int counter;
  
  if (s[0] == 'o') counter += 1;
  if (s[1] == 'o') counter += 1;
  if (s[2] == 'o') counter += 1;
  std::cout << 700 + 100 * counter << '\n';

}


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

#define rep(i, a, b) for (int i = int(a); i < int(b); i++)
#define rrep(i, a, b) for (int i = int(a) - 1; i >= b; i--)
#define sz(x) (int)(x).size()

using namespace std;
using ll = long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

int main() {
  string s;
  cin >> s;
  if (s == "AAA" || s == "BBB") {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}

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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}



int main(){
  string S;cin>>S;
  bool ok=true;
  if(S[0]!='A')ok=false;
  int cn=0;
  f(i,2,S.size()-1)if(S[i]=='C')cn++;
  if(cn!=1)ok=false;
  string han ="ABDEFGHIJKLMNOPQRSTUVWXYZ";
  rep(i,25){
    if(ok){
     f(j,1,S.size()){
      if(S[j]==han[i]){
       ok=false;
        break;
      }      
     }
    }
    
           
  }
  if(S[1]=='C')ok=false;
  if(S[S.size()-1]=='C')ok=false;
    
  if(ok)cout<<"AC"<<endl;
  else cout<<"WA"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
void Digvijay()
{
   int n,a,b;
   cin>>n>>a>>b;
   vector<int> arr(n);
   for(auto& it:arr)cin>>it;
   int ans=0;
   for(int i=1;i<n;i++)
   {
       int val=arr[i]-arr[i-1];
       if(val*a<b)ans+=val*a;
       else ans+=b;

   }
   cout<<ans<<"\n";
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int _=1;
    //cin>>_;
    for(int __=0;__<_;__++)
    {
        Digvijay();
    }
}

Measured memory_bytes: 3968
n = int(input())

s = input()

s_list = list(s)
flag = True
if n % 2 == 1:
    print('No')
    flag = False

if flag:
    if "".join(s_list[:int(n/2)]) == "".join(s_list[int(n/2):]):
        print('Yes')
    else:
        print('No')


Measured memory_bytes: 2940
n=int(input())
a=[int(input()) for _ in range(n)]
b=[0]*(n+1)
count=0
w=1
for i in range(n):
    if b[2]:
        print(count)
        exit()
    b[a[w-1]]+=1
    w=a[w-1]
    count+=1
print("-1")

Measured memory_bytes: 13756
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		int c=scan.nextInt();
		int fig=0;
		for(int i=1;i!=b+1;i++) {
			if((b*i+c)%a==0) {
				fig=1;
			}
		}
		System.out.println(fig==1?"YES":"NO");
	}
}

Measured memory_bytes: 23252
n = int(input())
a = list(map(int,input().split()))
ans = 0
ng = False
while True:
  for i in range(n):
    if a[i]%2==0:
      a[i] //= 2
    else:
      ng = True
      break
  if ng:
    break
  ans += 1
print(ans)

Measured memory_bytes: 3060
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut memo = vec![false; 1001];
    for b in 1..1000 {
        for p in 2..1000 {
            let x = (b as i64).pow(p) as usize;
            if x < 1001 { memo[x] = true; }
        }
    }
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    for x in (1..n+1).rev() {
        if memo[x] {
            put!(x);
            return;
        }
    }
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 4352
#include<stdio.h>
#define NIL -1
#define N 100000

typedef struct _tree{
  int parent;
  int right;
  int left;
}tree;

tree T[N];

int D[N];

int depth(int,int);

void print(int);

int main(){
  int num,i,j;
  int v,d,c,l,r;

  scanf("%d",&num);
  for(i=0;i<num;i++) {
    T[i].parent = T[i].right = T[i].left = NIL;
  }

  for(i=0;i<num;i++){
    scanf("%d%d",&v,&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(j==0) T[v].left = c;
      else T[l].right = c;
      l = c;
      T[c].parent = v;
    }
  }

  for(i=0;i<num;i++){
    if(T[i].parent == NIL) r = i;
  }

  depth(r,0);

  for(i=0;i<num;i++) {
    print(i);
    printf("\n");
  }

  return 0;


}

int depth (int x,int y)
{

  D[x] = y;
  if(T[x].right != NIL) depth(T[x].right,y);//右の兄弟に同じ深さを設定
  if(T[x].left != NIL) depth(T[x].left,y+1);//最も左の子に自分の深さを＋１

}

void print(int u){
  int i,c;

  printf("node %d: ",u);
  printf("parent = %d, ",T[u].parent);
  printf("depth = %d, ",D[u]);

  if(T[u].parent == NIL) printf("root, ");
  else if(T[u].left == NIL) printf("leaf, ");
  else printf("internal node, ");

  printf("[");
  for(i=0,c = T[u].left; c!=NIL;i++,c = T[c].right){
    if(i) printf(", ");
    printf("%d",c);
  }
  printf("]");

}
  



Measured memory_bytes: 7416
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class Main {
	/*??¶?´???????????????????*/
	public static void judge(int parse[],int leng){
		for(int j=0;j<leng;j++){
			if(parse[j]<1||parse[j]>10000){
				System.out.println("??\?????????1~10000??\???????????§???.???????????????.");
				System.exit(0);
			}
		}
	}

	public static void main(String[] args) throws IOException{
		String str;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		str = br.readLine();

		/*???????????£?¨?*/
		String[] st = str.split(" ");
		int len=st.length; //?????????????´???°
		int parse[] = new int[len]; //String???int????????¨??????
		int temp=0; //??\???????????¨?????°

		for(int p=0;p<len;p++){
			parse[p]=Integer.parseInt(st[p]); //String???int??????
		}

		judge(parse,len); //??¶?????????.????????????????????°????????????

		 /*for(int i=0;i<st.length;i++){
		 System.out.println("st["+i+"]="+st[i]); //?????????????´??¢????
		 }*/

		/*????????¨????????????*/
		Arrays.sort(parse); //???????????????
		System.out.println(parse[0]+(" ")+parse[1]+(" ")+parse[2]);

		}
	}

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

typedef long long ll;
const int mod = 1e9 + 7;

ll N;
vector<ll> A;

int main() {
    cin >> N;
    A.resize(N);
    rep(i, N) cin >> A[i];

    deque<ll> dq;
    rep(i, N) {
        ll idx = lower_bound(dq.begin(), dq.end(), A[i]) - dq.begin();
        if (idx == 0) {
            dq.push_front(A[i]);
        } else {
            dq[idx - 1] = A[i];
        }
    }

    cout << dq.size() << endl;
}

Measured memory_bytes: 1792
import java.util.*;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
      
        int t = sc.nextInt();
      
        long result = 0;
          
        for (int i = 1; i < n; i++) {
          int a = sc.nextInt();
          result += a * t;
          t += a;
        }

        System.out.println(result);
    }
}


Measured memory_bytes: 22868
n =  int(input())
nums = list(map(int,input().split(" ")))
ref = nums[-1]

def partition(A,p,refValue):
    i = p
    for j in range(p,len(A)):
        if A[j] <= refValue:
            tmp = A[j]
            A[j] = A[i]
            A[i] = tmp
            i += 1

partition(nums,0,ref)
indexes = [i for i, x in enumerate(nums) if x == ref]

ans = ""
for i in range(n):
    if i == indexes[-1]:
        ans += "[" + str(nums[i]) + "] "
    else:
        ans += str(nums[i]) + " "

print(ans[0:-1])



Measured memory_bytes: 16388
n, m = map(int, input().split())
a = []
for i in range(m):
    a.append(int(input()))

dp = [1] * (n + 10)
for i in range(len(a)):
    dp[a[i]] = 0

for i in range(n + 1):
    if i == 0 or i == 1:
        dp[i] = dp[i] * 1
    else:
        dp[i] = dp[i] * (dp[i - 2] + dp[i - 1])

print(dp[n] % 1000000007)


Measured memory_bytes: 462708
n = int(input())

doc = {}
for i in range(n):
    s = input()
    if i == 0:
        for j in range(len(s)):
            doc[s[j]] = doc.get(s[j], 0) + 1
        dockeys = list(doc.keys()).sort()
    else:
        tmp = {}
        for j in range(len(s)):
            tmp[s[j]] = tmp.get(s[j], 0) + 1
        dockeys = list(doc.keys())
        for k in dockeys:
            doc[k] = min(doc[k], tmp.get(k, 0))



ans = ""
dockeys = list(doc.keys())
dockeys.sort()

for k in dockeys:
    ans += k*doc[k]

print(ans)

Measured memory_bytes: 3064
N, W = map(int, input().split(' '))
items = [tuple(map(int, input().split(' '))) for _ in range(N)]

dp = [0] * (W + 1)

for w in range(W + 1):
    for value, weight in items:
        if weight <= w:
            dp[w] = max(dp[w], dp[w - weight] + value)

print(dp[W])



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

int main(){
    long H;
    cin >> H;

    long step = 0;
    do{
        H =  H / 2;
        step++;
    }while(H);

    // cout << pow(2,step) - 1 << endl;
    printf("%ld\n", (long)pow(2,step) - 1);

    return 0;
}

Measured memory_bytes: 256
N, M,X,Y=[int(i) for i in input().split()]
x = [int(i) for i in input().split()]
y = [int(i) for i in input().split()]
mx = max(x)
my = min(y)
ok = False
for i in range(X+1, Y+1):
   if mx<i and i<=my:
     ok =True

if ok:
    print("No War")
else:
    print("War")

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

int main(void)
{
  int a,b,c;
  cin>>a>>b;
  if(a<1||a>9||b<1||b>9)
  {
    cout<<"-1"<<endl;
  }else
  {
    c=a*b;
    cout<<c<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int k;

long long sum;

int cmmdc(int a , int b)
{
    int r = 0;
    while(b)
    {
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}

int main()
{
    cin >> k;
    for(int a = 1 ; a <= k ; a ++)
        for(int b = 1 ; b <= k ; b ++)
            for(int c = 1 ; c <= k ; c ++)
            {
                int rez = cmmdc(a , b);
                rez = cmmdc(rez , c);
                sum += rez;
            }
    cout << sum;
    return 0;
}


Measured memory_bytes: 3632
using System;
using System.Linq;

class D
{
	static void Main()
	{
		var a = Console.ReadLine().Split().Select(int.Parse).ToArray();

		var M = 1000000007;
		for (int i = 1; i <= a[1]; i++)
			Console.WriteLine(ModNcr(a[0] - a[1] + 1, i, M) * ModNcr(a[1] - 1, i - 1, M) % M);
	}

	static long ModPow(long b, int i, int mod)
	{
		for (var r = 1L; ; b = b * b % mod)
		{
			if (i % 2 > 0) r = r * b % mod;
			if ((i /= 2) < 1) return r;
		}
	}
	static long ModInv(int x, int p) => ModPow(x, p - 2, p);
	static long ModFactorial(int n, int mod) { for (long x = 1, i = 1; ; x = x * ++i % mod) if (i >= n) return x; }
	static long ModNpr(int n, int r, int mod)
	{
		if (n < r) return 0;
		for (long x = 1, i = n - r; ; x = x * ++i % mod) if (i >= n) return x;
	}
	static long ModNcr(int n, int r, int p) => n < r ? 0 : n - r < r ? ModNcr(n, n - r, p) : ModNpr(n, r, p) * ModInv((int)ModFactorial(r, p), p) % p;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<int> v(n);
    vector<ll> num(3, 0);
    for (int i = 0; i < n; ++i) {
        if(s[i] == 'R'){
            v[i] = 0;
            num[0]++;
        }
        if(s[i] == 'G'){
            v[i] = 1;
            num[1]++;
        }
        if(s[i] == 'B'){
            v[i] = 2;
            num[2]++;
        }
    }

    ll res = num[0] * num[1] * num[2];

    for (int left = 0; left < n - 1; ++left) {
        for (int right = left + 1; right < n; ++right) {
            if((right - left) % 2) continue;
            if(v[left] == v[right]) continue;
            int mid = (right + left) / 2;
            if(v[left] != v[mid] && v[mid] != v[right]) res--;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int n,a[100001],b[100001],i=1,j,saidai=0,m=0;
  
    cin >> n;
  
    for(i=0;i<n+1;i++)
    {
        cin >> a[i];
        saidai+=a[i];
    }
  
    for(i=0;i<n;i++)
    {
        cin >> b[i];
    }
  
    for(i=0;i<n;i++)
    {
        if(a[i]<b[i])
        {
            a[i+1] -= (b[i]-a[i]);
            if(a[i+1]<0)
            {
                a[i+1]=0;
            }
            a[i]=0;
        }
        else
        {
            a[i] -= b[i];
        }
    }
  
    for(i=0;i<n+1;i++)
    {
            m+=a[i];
    }

    cout << saidai-m << endl;
    
    
    
    return 0;

}


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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1000000000;
const int MOD = 1000000007;
const double eps = 1e-9;

int main(int argc, char *argv[]) {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    vector<int> a(3);
    rep(i, 3) cin >> a[i];

    vector<int> cnt(2, 0);
    rep(i, 3) {
        if (a[i] == 5) cnt[0]++;
        if (a[i] == 7) cnt[1]++;
    }

    if (cnt[0] == 2 && cnt[1] == 1) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

void solve(){
    int n;
    cin >> n;

    // for (char i = 'a'; i <= 'z'; i++) {
    //     cout << i << endl;
    // }
    
    vector<map<char, int>> v(n);
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;

        for (int j = 0; j < (int)s.size(); j++) {
            v[i][s[j]]++;
        }
    }

    vi numalpha(27);
    int idx=0;
    for (char c = 'a'; c <= 'z'; c++) {
        int count=INT_MAX;
        for (int i = 0; i < n; i++) {
            count = min(count, v[i][c]);
        }
        numalpha[idx] = count;
        idx++;
    }

    for (int i = 0; i < 27; i++) {
        // cout << numalpha[i] << endl;
        if (numalpha[i] != 0) {
            for (int j = 0; j < numalpha[i]; j++) {
                cout << (char)('a' + i);
            }
        }
    }
    cout << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdlib>
using Int = long long;
Int INF = 1LL << 60;

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

/*
Int N;
std::vector<Int> h(N);
std::vector<Int> dp(N);
*/

Int rec(Int i,const std::vector<Int>& h,std::vector<Int>& dp) {

	if (dp[i] < INF) return dp[i];

	if (i == 0) return 0;

	Int res = INF;
	chmin(res, rec(i - 1,h,dp) + std::abs(h[i] - h[i - 1]));
	if (i > 1)chmin(res, rec(i - 2,h,dp) + std::abs(h[i] - h[i - 2]));

	return dp[i] = res;
}

int main() {
	Int N;
	std::cin >> N;
	
	std::vector<Int> h(N);
	for (Int i = 0; i < N; i++)std::cin >> h[i];

	std::vector<Int> dp(N);
	for (Int i = 0; i< N; i++)dp[i] = INF;

	std::cout << rec(N - 1,h,dp) << std::endl;

}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define inf 1e9

int helper(int *a, int i, int n, int *dp){
    if(i>=n-1) return 0;

    if(dp[i]!=inf) return dp[i];
    int op1 = abs(a[i]-a[i+1]) + helper(a, i+1, n, dp) ;
    int op2 = abs(a[i]-a[i+2]) + helper(a, i+2, n, dp) ;
    return dp[i] = min(op1,op2);
}
int main() {
    int n;
    cin>>n;
    int a[n];
    int dp[n];
    
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) dp[i]=inf;
    cout<<helper(a,0,n,dp);
}


Measured memory_bytes: 12132
import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long result[] = new long[N];
        long Comparison[] = new long[N];
        long min;
        long anc = 0;
        for(int i = 0;i < N;i++){
            result[i] = sc.nextInt();
            if(i < 1){
                Comparison[i] = result[i];
            }else{
                if(Comparison[i - 1] < result[i]){
                    Comparison[i] = result[i];
                }else{
                    Comparison[i] = Comparison[i-1];
                }
            }
        }
        for(int i = 0;i < N;i++){
            if(result[i] != Comparison[i]){
                min = Comparison[i] - result[i];
                anc += min;
            }
        }
        System.out.println(anc);
    }
}


Measured memory_bytes: 62856
import java.util.*;
import java.io.*;

import static java.lang.System.in;

public class Main {
    public static void main(String[] args)throws IOException{
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong(),b=sc.nextLong(),c=sc.nextLong(),d=sc.nextLong();
        long dx=Math.abs(a-c),dy=Math.abs(b-d);
        long ans = help(Math.min(dx,dy),Math.max(dx,dy));
        System.out.println(ans);
    }
    static long help(long w, long h){
        if(w==0) return 0;
        // w<=h
        long c = gcd(w,h);
        if(c==1) return w+h-1;
        else return c*help(w/c,h/c);
    }
    static long gcd(long a, long b){
        if(a<b){
            long c=a;
            a=b;
            b=c;
        }
        while(a%b!=0){
            long c = a%b;
            a = b;
            b = c;
        }
        return b;
    }
}


Measured memory_bytes: 23636
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N, K;
  while (cin >> N >> K) {
    vector<ll> H(N);
    for (auto& x : H) cin >> x;
    sort(H.rbegin(), H.rend());
    ll res = 0;
    for (int i = K; i < N; i++) res += H[i];
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n) REP(i,0,n)
int x,y;
void solve() {
  int step = 0;
  if (x < y) swap(x,y);
  while (y != 0) {
    x = x % y;
    swap(x,y);
    step++;
  }
  cout<<x<<" "<<step<<endl;
}

int main (int argc, char const* argv[]) {
  while (cin>>x>>y, x||y) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 0
import sys
import math
i=list(map(int,input().split()))
m=i[0]
n=i[1]
k=1000000007
def pw(m,n):
  if n==0:
    return 1
  elif n==1:
    return m%k
  else:
    if n%2==0:
      return pw(m,n//2)**2%k
    elif n%2==1:
      return (pw(m,n//2)**2*m)%k
    
print(pw(m,n))
    


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

using namespace std;

typedef long long ll;
template<typename T> bool chmax(T &a, T b) {if(a <= b){a = b; return true;}return false;}
template<typename T> bool chmin(T &a, T b) {if(a >= b){a = b; return true;}return false;}

int main(void){
    ll n;
    vector<ll> a(5);
    cin >> n >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
    sort(a.begin(), a.end());
    ll ans = ceil((n - 1)/ a[0]) + 5;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
using namespace std;

int main(){
    int x,y;
    cin >> x >> y;
    int ans = 0;
    if(x == 1 && y == 1){
        ans += 400000;
    }
    if(x == 1){
        ans += 300000;
    }    
    if(y == 1){
        ans += 300000;
    }
    if(x == 2){
        ans += 200000;
    }
    if(y == 2){
        ans += 200000;
    }
        if(x == 3){
        ans += 100000;
    }
        if(y == 3){
        ans += 100000;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import math
a,b,h,m=map(int,input().split())
H=((h%12)*30)+0.5*m
M=(m*6)
x=abs(H-M)
y=360-x
l=[x,y]
l.sort()
sita=l[0]
sita=math.radians(sita)
c=a**2+b**2-2*(a*b*math.cos(sita))
c=math.sqrt(c)
print(c)

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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);

    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n; i++)
        cin >> b[i];
    for (int i = 0; i < n; i++)
        cin >> c[i];
    sort(a.begin(), a.end());
    sort(c.begin(), c.end());
    ll ans = 0;
    for (int i = 0; i < n; i++)
    {
        ll sum = 1;
        auto iter1 = lower_bound(a.begin(),a.end(),b[i]);
        auto iter2 = upper_bound(c.begin(),c.end(),b[i]);
        sum *= (iter1 - a.begin());
        sum *= (c.end() - iter2);
        ans += sum;
    }
    cout << ans << endl;
}

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()



int main()
{
   ll N;
   ll n = 0;

    cin >> N;

   for ( int i = 1; i <= N; i++ )
   {
       if( i % 3 == 0 && i % 5 == 0 )
       {
           continue;
       }
       else if( i % 3 == 0 )
       {
           continue;
       }
       else if( i % 5 == 0 )
       {
           continue;
       }
       else
       {
           n += i;
       }
       
   }

    cout << n << endl;
    
}


Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <math.h>

typedef long long ll;
typedef long double ld;
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define PRECISION std::cout << std::fixed << std::setprecision(20);
  
using namespace std;
 
const ll inf = 1e18+1;
const int N = 4e5+1;
const ll mod = 1e9+7;
const int bits = 19;

void solve(){
    string s;
    cin>>s;
    int n = s.size();
    for(int i=0;i<n;i++){
        if(s[i]=='?') s[i] = 'D';
    }

    cout<<s<<"\n";
}

int main(){
    FASTIO;
    PRECISION;
    
    int t;
    // cin>>t;
    t = 1;
    while(t--){
        solve();
    }
}

Measured memory_bytes: 3732
# デバッグ用
GBN_DEBUG = False
def dprn(s, i):
    if GBN_DEBUG: print(", " + s + " = " + str(i), end = "")
def dprns(s):
    if GBN_DEBUG: print(", " + s, end = "")
def dprni(i):
    if GBN_DEBUG: print(i, end=" ")
def endl(): 
    if GBN_DEBUG: print('')
def puts(s): print(s)

#本体ここから

#S = input()
X = int(input())
#S, T = input().split()
#N, M = map(int, input().split())
#W = [input() for _ in range(N)]
#A = list(map(int, input().split()))

#GBN_DEBUG = True

c500 = X // 500
X -= c500 * 500
c5 = X // 5

print(c500 * 1000 + c5 * 5)


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

int n, m, l = -1, r = 1000000;

int main(){

    scanf("%d %d", &n, &m);

    for(int i = 0, a, b; i < m; i++){
        scanf("%d %d", &a, &b);
        if(a > l){
            l = a;
        }
        if(b < r){
            r = b;
        }
    }

    printf("%d\n", max(r - l + 1, 0));

    return 0;
}


Measured memory_bytes: 256
n = int(input())

X=[]
Y=[]
for i in range(n):
    x,y = map(int,input().split())
    X.append(x)
    Y.append(y)

D = []
for i in range(n):
    for j in range(i+1,n):
        D.append(((X[i]-X[j])**2+(Y[i]-Y[j])**2)**0.5)

# print(D)
ans = sum(D)*2/n
print(ans)

Measured memory_bytes: 9312
#include <iostream>

using namespace std;

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

   int M = 0;
   for (int i = 0; i < N; i++){
       M += a[i] - 1;
   }
   cout << M << endl;
}

Measured memory_bytes: 256
import sys

class alphabet(): #Trueなら大文字
    def __init__(self, capitalize):
        self.num = dict() #あるアルファベットが最初から何番目か、0-indexed
        self.index = dict() #i番目のアルファベット
        self.abc = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n"\
            ,"o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
        if capitalize: 
            for i in range(26): self.abc[i] = self.abc[i].upper()
        for i, a in enumerate(self.abc):
            self.num[a] = i
            self.index[i] = a

def solve():
    S = list(input())
    length = len(S)
    K = int(input())
    changed = 0
    AB = alphabet(False)
    for i, s in enumerate(S):
        aId = AB.num[s]
        if aId == 0: continue
        else:
            toA = 26 - aId
            if K - changed >= toA: 
                S[i] = "a"
                changed += toA
    if K - changed > 0:
        aId = AB.num[S[length - 1]]
        S[length - 1] = AB.index[(aId + K - changed) % 26]
    print("".join(map(str, S)))
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 4792
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        var n = Console.ReadLine();
        var a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

        if (a.Where(x => x % 2 == 0).All(x => x % 3 == 0 || x % 5 == 0))
        {
            Console.WriteLine("APPROVED");
            return;
        }

        Console.WriteLine("DENIED");
    }
}

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

int main() {
  string s, t;
  cin >> s >> t;
  int res = INT_MAX;

  for (int i = 0; i < s.size() - t.size() + 1; i++) {
    int d = 0;
    for (int ti = 0; ti < t.size(); ti++) {
      if (s[i + ti] != t[ti]) d++;
    }
    res = min(res, d);
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 3616
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = 0

for i in range(n):
  if a[i] >= b[i]:
    c += b[i]
  else:
    c += a[i]
    c += min(a[i+1],b[i]-a[i])
    if a[i+1] >= b[i]-a[i]:
      a[i+1] = a[i+1] - (b[i] - a[i])
    else:
      a[i+1] = 0
     
print(c)


Measured memory_bytes: 18624
// need
#include <iostream>
#include <algorithm>
// data structure
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
//#include <deque>
#include <valarray>
#include <unordered_map>
#include <array>
// stream
//#include <istream>
#include <sstream>
//#include <ostream>
#include <fstream>
// etc
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
//#include <chrono>
#include <random>
#include <numeric>
using namespace std;
 
int main()
{
  int A, B;
  cin >> A >> B;
  if(B%A == 0)
    cout << A+B << endl;
   else
     cout << B-A << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	
	   

		public static void main(String[] args) {
	        Scanner sc = new Scanner(System.in);
	        char c = sc.next().charAt(0);
	        
	        if(c>='A' && c<='Z'){
	           
	           System.out.println("A");
	        }else {
	       
	        
	        System.out.println("a");
	        }
            //System.out.println(res); 
	        
	}
}

Measured memory_bytes: 36264
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sca=new Scanner(System.in);
        String num[]=new String[10001];
        for(int i=0;;i++){
            num[i] =sca.next();
            if(num[i].equals("0"))break;
        }
        for(int i=1;;i++){
            if(num[i-1].equals("0"))break;
            System.out.println("Case "+i+": "+num[i-1]);
        }         
    }   
}

Measured memory_bytes: 41668
x,y = map(int,input().split())
def framod(n, mod, a=1):
    for i in range(1,n+1):
        a=a * i % mod
    return a

def power(n, r, mod):
    if r == 0: return 1
    if r%2 == 0:
        return power(n*n % mod, r//2, mod) % mod
    if r%2 == 1:
        return n * power(n, r-1, mod) % mod

def comb(n, k, mod):
    a=framod(n, mod)
    b=framod(k, mod)
    c=framod(n-k, mod)
    return (a * power(b, mod-2, mod) * power(c, mod-2, mod)) % mod
  
if (x+y)/3 != int((x+y)/3):
    print(0)
elif (y<int((x+y)/3)) or (x<int((x+y)/3)):
    print(0)
else:
    print(comb(int((x+y)/3), int(y-((x+y)/3)),10**9+7))

Measured memory_bytes: 3064
h,w = map(int,input().split())
s = [input() for i in range(h)]
grid = [[0 for i in range(w+2)] for j in range(h+2)]
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':
            grid[i+1][j+1] = 1
for i in range(1,h+1):
    for j in range(1,w+1):
        if grid[i][j] == 1:
            if grid[i-1][j]+grid[i+1][j]+grid[i][j-1]+grid[i][j+1] == 0:
                print('No')
                exit()
print('Yes')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  int N,a,b,c,d;
  cin>>N;
  
  
  
  a=N/1000;
  b=N/100-a*10;
  c=N/10-a*100-b*10;
  d=N-a*1000-b*100-c*10;
  
  if(a==b&&b==c&&c==d){
    cout<<"Yes"<<endl;
  }
  else if(a==b&&b==c&&c!=d){
    cout<<"Yes"<<endl;
  }
  else if(a!=b&&b==c&&c==d){
    cout<<"Yes"<<endl;
  }

  else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
def main():
  N=int(input())
  A=[int(input()) for _ in range(N)]

  a=max(A)
  k=A.count(a)#リストの最大数の個数をカウント
  if k>=2:
    for i in range(N):
      print(a)
  else:
    b=A.index(a)
    for i in range(N):
      if i != b:
        print(a)
      else:
        s=sorted(A)
        print(s[N-2])

if __name__ == "__main__":
    main()

Measured memory_bytes: 14192
import sys
import itertools
import bisect
from operator import itemgetter
 
MAX_INT = int(10e15)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()
def combi(n, r):
  r = min(r, n-r)
  numer = denom = 1
  for i in range(1, r+1):
    numer = numer * (n+1-i) %mod
    denom = denom * i %mod
  return numer * pow(denom, mod-2, mod) %mod

s = S()
N = len(s)//2

if s[:N] == s[N+1:]:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 38384
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = ReadArrayInt();
            var H = input[0];
            var W = input[1];
            input = ReadArrayInt();
            var h = input[0];
            var w = input[1];

            Console.WriteLine((H-h)*(W-w));
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(NULL);
    cin.tie(0);
    cout.tie(0);
    long long s(0);
    long long dif(0);
    int n, x;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> x;
        s += x;
        dif += x * x;
    }
    cout << (s * s - dif) / 2;
    return 0;
}


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

int main(){
    long long ans=0;
    int N;cin>>N;
    int B[N-1];
    REP(i,N-1){
        cin>>B[i];
    }
    ans+=B[0]+B[N-2];
    for(int i=1;i<=N-2;i++){
        ans+=min({B[i-1],B[i]});
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
<?php
  $input = explode(" ", fgets(STDIN));
	$N = (int)$input[0];
	$L = (int)$input[1];

	for($i=0;$i<$N;$i++){
     	$array[] = fgets(STDIN); 
    }
	sort($array);
	
	$strmix = "";

	foreach( $array as $str){
		$strmix = $strmix.trim($str);
    }
	echo trim($strmix);
?>

Measured memory_bytes: 4604
/******************************************
* AUTHOR : Lokesh goel*
* NICK : InsaneNerd *
* INSTITUTION : NIT Kurukshetra *
******************************************/
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MAX 1000000000
#define N 100005
#define pii pair<int,int>
#define vp vector<pair<int,int > >
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define gsz(x) ((int)(x).size())
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);cerr.tie(NULL);
#define endl "\n"
#define ms(x,v) memset(x,v,sizeof(x))

int main()
{
	fastio;
	ll n,m,a[10001],i,j,k,sum=0;
	cin>>n>>m;
	for(i=0;i<m;i++){
		cin>>a[i];
		sum+=a[i];
	}
	if(sum<=n){
		cout<<n-sum<<endl;
	}
	else cout<<"-1"<<endl;


	return 0;
}

Measured memory_bytes: 3672