akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main() {
    char s[10];
    scanf("%s", s);
    sort(s, s + 4);
    printf((s[0] == s[1] && s[1] != s[2] && s[2] == s[3]) ? "Yes\n" : "No\n");
    return 0;
}


Measured memory_bytes: 256
n, k = input().split()
k = int(k)
s = input()

target = s[k-1]
rep = 'a'
if target == 'A':
    rep = 'a'
elif target == 'B':
    rep = 'b'
else:
    rep = 'c'

res = s[:k-1] + rep + s[k:]
print(res)


Measured memory_bytes: 3060
n = int(input())
li = list(map(int,input().split()))
list.sort(li,reverse = True)
total = 0
switch = 0
for i in range(2*n):
    if switch == 0:
        switch += 1
    elif switch == 1:
        switch -= 1
        total += li[i]
print(total)

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

using namespace std;

int main () {
    int n;
    cin >> n;
    int a1 = (int) M_PI * (n * n);
    int a2 = (int) M_PI * (1 * 1);

    cout << (int) a1/a2 << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		int a = st.nextInt();
		int b = st.nextInt();
		int c = st.nextInt();

		if((a < b) && (b < c)){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

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

#define INF INT_MAX/2;
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long ;

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

   int N;
   cin>>N;
   vector<int>p(N);
   for(int i=0;i<N;i++)cin>>p[i];
   sort(p.begin(),p.end());
   p[N-1] = p[N-1]/2;
   ll ans = 0;
   for(int i=0;i<N;i++)ans+=p[i];
   cout<<ans<<endl;
   return 0; 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1000000007;
const int INF = INT_MAX / 2;

int main(){
    int N; cin >> N;
    int is_increase = -1;
    int a; cin >> a;
    int prev = a;
    int cnt = 1;
    for (int i = 1; i < N; i++)
    {
        cin >> a;
        if(is_increase==-1){
            if(prev>a) is_increase = 0;
            else if(prev<a) is_increase = 1;
        } else if(is_increase==1){
            if(prev>a){
                cnt++;
                is_increase = -1;
            } 
        } else {
            if(prev<a){
                cnt++;
                is_increase = -1;
            }
        }
        prev = a;
    }
    cout << cnt << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#define mp make_pair
#define F first
#define S second
#define mod ((ll)(1e9+7))
#define ll long long int

using namespace std;

int main()
{
    ll k, s;
    cin >> k >> s;
    ll res = 0;
    for(ll i = 0 ; i <= k ; i++){
        for(ll j = 0 ; j <= k ; j++){
            if(s - i - j >= 0 && s - i - j <= k) res++;
        }
    }
    cout << res;
    return 0;
}










Measured memory_bytes: 256
import sys
N = int(input())
for h in range(1,3501):
    for n in range(1,3501):
        if 4*h*n -N*h -N*n <= 0: continue
        w = N*h*n/(4*h*n -N*h -N*n)
        if not 0<w<=3500: continue 
        if w.is_integer()==True:
            print(h,n,int(w))
            sys.exit()

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


int main() {
    int n; cin >> n;
    if(n % 2 == 0)print(n/2);
    else print(1 + (n/2) );

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

int main(){
    int n,m;
    while(cin >> n >> m,n){
        double table[105][105];
        rep(i,n){
            rep(j,n){
                cin >> table[i][j];
            }
        }

        double dp[105][105] = {{0}}; //????????????????????\????????\??????
        rep(i,105) dp[i][0] = 1;
        range(i,1,m){
            rep(j,n){
                rep(k,n){
                    dp[j][i] = max(dp[j][i], dp[k][i - 1] * table[k][j]);
                }
            }
        }
        
        double maxi = 0;
        rep(i,n){
            maxi = max(maxi, dp[i][m - 1]);
        }
        cout <<fixed << setprecision(2) << maxi << endl;
    }
}

Measured memory_bytes: 3364
import sys

H,W,N=map(int,input().split())
sr,sc=map(int,input().split())
sr-=1
sc-=1
S=list(input())
T=list(input())
#4方向全てにおいて阻止できるか
dic1={"U":0,"D":1,"R":2,"L":3}
dic2={"U":1,"D":0,"R":3,"L":2}
dic3={"U":-1,"D":1,"R":1,"L":-1}
data=[[sr],[sr],[sc],[sc]]
for i in range(N):
    data[dic1[S[i]]].append(dic3[S[i]])
    data[dic2[T[i]]].append(dic3[T[i]])

h=data[0]
for i in range(1,len(h)):
    h[i]=min(H-1,h[i]+h[i-1])
    if h[i]==-1:
        print("NO")
        sys.exit()
h=data[1]
for i in range(1,len(h)):
    h[i]=max(0,h[i]+h[i-1])
    if h[i]==H:
        print("NO")
        sys.exit()
h=data[3]
for i in range(1,len(h)):
    h[i]=min(W-1,h[i]+h[i-1])
    if h[i]==-1:
        print("NO")
        sys.exit()
h=data[2]
for i in range(1,len(h)):
    h[i]=max(0,h[i]+h[i-1])
    if h[i]==W:
        print("NO")
        sys.exit()
print("YES")

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

double P,E,T;

double f(int K,double L,double R){
	if(K==0)return abs( T - (L+R)*0.5 ) < E + 1e-10;
	else{
		double M = (L+R) * 0.5;
		if(M>T){
			return f(K-1,L,M) * (1-P) + f(K-1,M,R) * P;
		}else{
			return f(K-1,L,M) * P + f(K-1,M,R) * (1-P);
		}
	}
}
int main(){
	int K , L , R;
	cin >> K >> L >> R >> P >> E >> T;
	printf("%.7f\n",f(min(K,17),L,R));
}

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

int main() {
  string s;
  cin >> s;

  int end=0;
  ll ans=0;
  bool flag=false;
  int j;
  for (j=0; j<s.size(); j++) {
    if (s[j]=='B')
      break;
  }
  end=j;    
      
  for (int i=j; i<s.size(); i++) {
    if (s[i]=='B') continue;
    ans+=i-end;
    end++;
   
  }
  cout<<ans<<endl;
  return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  ll N = nextLong();
  ll ans = N;
  for (ll d = 1; d * d <= N; d++) {
    if (N % d == 0) {
      ll val = d + (N/d) - 2;
      chmin(ans, val);
    }
  }
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 256
vert,hori = gets.chomp.split(" ").map(&:to_i)
coin = Array.new(vert).map{Array.new(hori, 0)}
for i in 0..vert - 1
  coin[i] = gets.chomp.split(" ").map(&:to_i)
end
ans = []
for i in 0..vert - 1
  for j in 0..hori - 1
    if coin[i][j] % 2 == 1
      if j != hori - 1
        coin[i][j] -= 1
        coin[i][j + 1] += 1
        ans.push("#{i + 1} #{j + 1} #{i + 1} #{j + 2}")
      elsif i != vert - 1
        coin[i][j] -= 1
        coin[i + 1][j] += 1
        ans.push("#{i + 1} #{j + 1} #{i + 2} #{j + 1}")
      end
    end
  end
end

puts ans.length
for i in 0..ans.length - 1
  puts ans[i]
end


Measured memory_bytes: 18684
'use strict'

function main(s) {

  s = s.split('\n')[0].split(' ').map(x => Number(x));
  const a = s[0];
  const b = s[1];
  const c = s[2];
  const d = s[3];
  const indirect = (Math.abs(b - a) <= d && Math.abs(c - b) <= d);
  const direct = (Math.abs(c - a) <= d);
  const ans = (indirect || direct) ? 'Yes' : 'No';

  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
def myAnswer(N:int,M:int) -> int:
   if(N == 1 and M == 1): return 1
   if(min(N,M) == 1): return max(N,M) - 2
   if(min(N,M) == 2): return 0
   return N*M - (max(N,M) * 2 + (min(N,M) - 2) * 2)

def modelAnswer():
   return
def main():
   N,M = map(int,input().split())
   print(myAnswer(N,M))
if __name__ == '__main__':
   main()


Measured memory_bytes: 3060
S = int(raw_input())

if S == 10**18:
  print 0,0,10**9,0,0,10**9
  exit(0)

x1 = y1 = 0
x2 = 10**9
y2 = 1
y3 = S/(10**9) + 1
x3 = 10**9 - (S%(10**9))

print x1,y1,x2,y2,x3,y3


Measured memory_bytes: 2568
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct node{
  struct node *prev;
  struct node *next;
  int key;
};
 
typedef struct node *NodePointer;
NodePointer nil;

NodePointer search(int k){
  NodePointer x; 
  x=nil->next;
  while(x!=nil && x->key!=k){
    x=x->next;
  }
  return x;
}
 
void insert(int k){
  NodePointer x;
  x=malloc(sizeof(struct node));
  x->key=k;
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
}
 
void deleteNode(NodePointer x){
  x->prev->next=x->next;
  x->next->prev=x->prev;
}
 
void delete(int k){
  NodePointer x;
  x=search(k);
  if(x==nil){
    return;
  }
  deleteNode(x);
}
 
void deleteFirst(){
  NodePointer x;
  x=nil->next;
  deleteNode(x);
}
 
void deleteLast(){
  NodePointer x;
  x=nil->prev;
  deleteNode(x);
}
 
int main(){
  int n,i,k,flag=1;
  char c[20];
  NodePointer x;
  nil=malloc(sizeof(struct node));
  nil->prev=nil;
  nil->next=nil;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",c);
    if(c[0]=='i'){
      scanf("%d",&k);
      insert(k);
    }
    else if(c[0]=='d'){
      if(strlen(c)>6){
	if(c[6]=='F'){
	  deleteFirst(); 
	}
	else if(c[6]=='L'){
	  deleteLast();
	}
      }
      else{
	scanf("%d",&k);
	delete(k);
      }
    }
  }
  x=nil->next;
  while(1){
    if(x==nil){
      break;
    }
    if(flag==0){
      printf(" ");
    }
    printf("%d",x->key);
    x=x->next;
    flag=0;
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 34976
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
#else
	#define DBG(X)
#endif

using std::cin;
using std::cout;
using std::vector;
using std::string;
using std::pair;
using std::swap;
using std::sort;
using std::lower_bound;
using std::unique;
using std::abs;

using int64 = long long int;
using pii   = pair<int, int>;
using pii64 = pair<int64, int64>;

const int NIL = -1;
const int INF = (int)2e9;
const int64 INF64 = (int64)2e18;

void init_IO() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
}

template<typename T>
std::ostream& operator<<(std::ostream& os, const vector<T>& vec) {
	os << '[';
	int fst = 1;

	for(auto& elem: vec) {
		if(fst == 0) {
			os << ' ';
		}

		os << elem;
		fst = 0;
	}

	os << ']';
	return os;
}

const int MOD = (int)1e9 + 7;
const int MAX_N = 2007;

int add(int x, int y) {
	return (x + y >= MOD ? x + y - MOD : x + y);
}

int dp[MAX_N][MAX_N], pref[MAX_N][MAX_N], n, m;
int a[MAX_N], b[MAX_N];

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

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

	for(int j = 0; j < m; ++j) {
		cin >> b[j];
	}

	pref[0][0] = dp[0][0] = 1;

	for(int i = 1; i < MAX_N; ++i) {
		pref[0][i] = add(pref[0][i - 1], dp[0][i]);
	}

	for(int i = 1; i <= n; ++i) {
		pref[i][0] = dp[i][0];

		for(int j = 1; j <= m; ++j) {
			if(a[i - 1] == b[j - 1]) {
				dp[i][j] = pref[i - 1][j - 1];
			}		

			pref[i][j] = add(pref[i][j - 1], dp[i][j]);
		}
	
		for(int j = 0; j <= m; ++j) {
			pref[i][j] = add(pref[i][j], pref[i - 1][j]);
		}
	}

	cout << pref[n][m] << '\n';
}

int main() {
	init_IO();
	solve();

	return 0;
}


Measured memory_bytes: 31616
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define P pair<ll,ll>
#define Graph vector<vector<P>>
#define fi first
#define se second
constexpr ll mod=1000000007;
constexpr ll INF=(1ll<<60);
constexpr double pi=3.14159265358979323846;
template<typename T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<typename T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}


int main(){
    ll n;cin>>n;
    vector<ll> d(n);
    rep(i,n) cin>>d[i];

    ll sum=0;
    rep(i,n-1){
        for(ll j=i+1;j<n;j++){
            sum+=d[i]*d[j];
        }
    }
    cout<<sum<<endl;
    return 0;
}

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

int main() {
    int h, w;
    cin >> h >> w;
    vector<string> grid(h);
    rep(i, h) cin >> grid[i];

    int i = 0, j = 0;
    while(i < h && j < w){
        grid[i][j] = '.';
        if(j+1 < w && grid[i][j+1] == '#'){
            j++;
            continue;
        }
        if(i + 1 < h && grid[i+1][j] == '#'){
            i++;
            continue;
        }
        break;
    }
    if(i == h-1 && j == w-1){
        rep(s,h){
            rep(t,w){
                if(grid[s][t] == '#'){
                    puts("Impossible");
                    return 0;
                }
            }
        }
        puts("Possible");
    } else
        puts("Impossible");
}

Measured memory_bytes: 384
#! /usr/bin/env python3

from fractions import gcd
# from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement

ans = lambda x : x % 998244353
MOD = 998244353

N = int(input())
D = [int(_) for _ in input().split()]

c = Counter(D)

ans = 1 * (not D[0]) * (c[0] == 1)
for i in range(1, max(c.keys())+1):
    ans *= pow(c[i-1], c[i], MOD)
    ans %= MOD

print(ans)


Measured memory_bytes: 23260
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N;
ll K;
ll P[5010];
ll C[5010];
ll ans = -0x7f7f7f7f7f7f7f7f;
int main() {
	cin >> N >> K;
	for (ll i = 1; i <= N; i++) cin >> P[i];
	for (ll i = 1; i <= N; i++) cin >> C[i];
	for (ll i = 1; i <= N; i++) {
		ll cur = i;
		ll now = 0;
		ll num = 0;
		while (cur != i || !num) {
			cur = P[cur];
			now += C[cur];
			num++;
		}
//		cout << num << endl;
		//it will jump NUM times back to i
		ll tim = K / num;
		if (num >= K) {
			ll newnum = 0;
			ll newcur = i;
			ll newnow = 0;
			while (newnum < K) {
				newcur = P[newcur];
				newnow += C[newcur];
				ans = max(ans, newnow);
				newnum++;
			}
		} else {
			ll newnum = 0;
			ll newcur = i;
			ll newnow = 0;
			while (newnum < num) {
//				cout << newcur << endl;
				newcur = P[newcur];
				newnow += C[newcur];
				ans = max(ans, newnow);
				newnum++;
			}
//			cout << newnow << endl;
			if (now >= 0) {
				newnow = now * (tim - 1);
				newnum = 0;
				newcur = i;
				while (newnum < num) {
					newcur = P[newcur];
					newnow += C[newcur];
					ans = max(ans, newnow);
					newnum++;
				}
				now = now * tim;
				ans = max(ans, now);
				newnum = 0;
				tim = K % num;
//				cout << tim << endl;
				newcur = i;
				while (newnum < tim) {
					newcur = P[newcur];
					now += C[newcur];
					ans = max(ans, now);
					newnum++;
				}
			}
		}
//		cout << ans << endl;
	}
	cout << ans;
	return 0;
}
/*
4 200
2 1 4 3
-100 -10000 -25 50
*/

Measured memory_bytes: 3616
tmp_xy = input().split()
x = int(tmp_xy[0])
y = int(tmp_xy[1])

flg = False
for n_tsuru in range(x + 1):
    n_kame = x - n_tsuru
    if(y == (n_kame * 4) + (n_tsuru * 2)):
        flg = True
        break
if flg:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9120
#include <iostream>
#include <algorithm>
#include <unordered_set>

using namespace std;

#define ll long long

int main(){
  ll n;
  cin >> n;
  unordered_set<string> us;
  for(ll i = 0; i < n; i++){
    string a,b;
    cin >> a >> b;
    if(a == "insert"){
      us.insert(b);
    }else{
      if(us.find(b) == us.end()){
	cout << "no\n";
      }else{
	cout << "yes\n";
      }
    }
  }
}

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

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		List<String> list = new ArrayList<String>();
		for (int i = 0; i < s.length(); i++) {
			String sSub = String.valueOf(s.charAt(i));
			if ("0".equals(sSub)) {
				list.add(sSub);
			} else if ("1".equals(sSub)) {
				list.add(sSub);
			} else {
				if (list.size() != 0) {
					list.remove(list.size() - 1);
				}
			}
		}
		for (String str : list) {
			System.out.print(str);
		}
	}

}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define sz(a) (ll)(a.size())
#define pll pair<ll,ll>
ll a[100005][4];
ll try1(ll i,ll n,ll temp,ll dp[][4])
{
	if(dp[i][temp]!=-1)
		return dp[i][temp];

	if(i>=n)
		return 0;

	if(i==0 && temp==3)
	{
		dp[i][temp] = max(a[i][0]+try1(i+1,n,0,dp),max(a[i][1]+try1(i+1,n,1,dp),a[i][2]+try1(i+1,n,2,dp)));
		return dp[i][temp];
	}
	else if(temp==0)
	{
		dp[i][temp] = max(a[i][1]+try1(i+1,n,1,dp),a[i][2]+try1(i+1,n,2,dp));
		return dp[i][temp];
	}
	else if(temp==1)
	{
		dp[i][temp] = max(a[i][0]+try1(i+1,n,0,dp),a[i][2]+try1(i+1,n,2,dp));
		return dp[i][temp];
	}
	else if(temp==2)
	{
		dp[i][temp] = max(a[i][1]+try1(i+1,n,1,dp),a[i][0]+try1(i+1,n,0,dp));
		return dp[i][temp];
	}
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,i,j;
	cin>>n;

	ll dp[100005][4];

	for(i=0;i<100005;i++)
		for(j=0;j<4;j++)
			dp[i][j]=-1;

	for(i=0;i<n;i++)
		cin>>a[i][0]>>a[i][1]>>a[i][2];

	cout<<try1(0,n,3,dp)<<endl;
	return 0;
}

Measured memory_bytes: 12800
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
#define ll long long
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x%mod;
}

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

int comb(int x, int y) {
	if (y > x)return 0;
	if (x == y)return 1;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

int a, b;

signed main() {
	cin >> a >> b;
	cout << (a * 3 + b) / 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pcc pair<char,char>
#define vi vector <int>
#define vl vector <ll>
#define sd(x) scanf("%d",&x)
#define slld(x) scanf("%lld",&x)
#define pd(x) printf("%d",x)
#define plld(x) printf("%lld",x)
#define pds(x) printf("%d ",x)
#define pllds(x) printf("%lld ",x)
#define pdn(x) printf("%d\n",x)
#define plldn(x) printf("%lld\n",x)
#define INF 2e9
#define INFLL 4e18
using namespace std;
ll powmod(ll base,ll exponent,ll mod){ // with mod < 1e9
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	return ans;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b,a%b);
}
const int upperlimit = 1e6+1;
const int mod = 1e9+7;
ll func(ll a,ll d){
	ll ans=a;a/=d;ans-=a;
	return ans;
}
int main() {
	ll a,b,c,d;
	slld(a);slld(b);slld(c);slld(d);
	ll ans=func(b,c)-func(a-1,c);
	ans+=func(b,d)-func(a-1,d);
	d/=gcd(d,c);
	d*=c;
	ans-=func(b,d)-func(a-1,d);
	plld(ans);
	return 0;
}

Measured memory_bytes: 256
a = [1,3, 5,7,8,10,12]
b = [4,6,9,11]
c = [2]

x, y = map(int,input().split())
ans = []

for i in a,b:
    if x in i and y in i:
        ans.append('Yes')
    else:
        ans.append('No')
        
if 'Yes' in ans:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
import java.util.Scanner;

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

    Scanner sc = new Scanner(System.in);

    int a = sc.nextInt();
    int b = sc.nextInt();

    if (a > 0 && a < 10 && b > 0 && b < 10) {
      System.out.println(a * b);
    } else {
      System.out.println(-1);
    }
  }
}


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

int main(){
    int R;
    cin >> R;
    if(R < 1200){
        cout << "ABC" << endl;
    }
    else if(R < 2800){
        cout << "ARC" << endl;
    }
    else{
        cout << "AGC" << endl;
    }
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	var s string
	if sc.Scan() {
		s = sc.Text()
	}

	ss := strings.Split(s, " ")
	A, _ := strconv.Atoi(ss[0])
	B, _ := strconv.Atoi(ss[1])

	var result int
	if A+B < A-B {
		result = A - B
	} else {
		result = A + B
	}

	if result < A*B {
		result = A * B
	}

	fmt.Println(result)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
    cout << fixed << setprecision(10);
    string s;
    ll k;
    cin >> s >> k;
    rep(i,int(s.size())){
        int sub = 'z' - s[i]  + 1;
        //cout << sub << endl;
        if(sub <= k && i != int(s.size()) - 1 && s[i] != 'a'){
            s[i] = 'a';
            k -= sub;
            //cout << k << " k" << endl;
        }
        if(sub <= k && i == int(s.size()) - 1){
            // cout << "Yes2" << endl;
            int subsub = (k - sub) % ('z' - 'a' + 1);
            s[i] = char('a' + subsub);
        }
        if(sub > k && i == int(s.size() - 1) ){
            // cout << "Yes2" << endl;
            // cout << sub << " sub" << endl;
            s[i] = char(s[i] + k);
        }
    }
    cout << s << endl;
            // cout << ('z' - 'a') << endl;
    return 0;
}


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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s, t; cin >> s >> t;
    if (t.size() == s.size() + 1) {
        if (t.substr(0, s.size()) == s) {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    return 0;
}

Measured memory_bytes: 3608
#include<stdio.h>
#include<stdlib.h>
int main(){
  int a,c=0,d=0,min,s,x,i;
  int *b;
  scanf("%d",&a);
  b=(int *)malloc(sizeof(int) * a);
  for(i=0;i<a;i++){
    scanf("%d",&b[i]);
  }
  while(c<a-1){
    min=b[c];
    for(i=c;i<a;i++){
      if(min>b[i]){min=b[i];s=i;}
    }
      if(min<b[c]){x=b[c];b[c]=b[s];b[s]=x;d++;}
  c++;
  }
  for(i=0;i<a;i++){
  printf("%d",b[i]);
  if(i!=a-1)printf(" ");
  }
  printf("\n");
  printf("%d\n",d);
  return 0;
}




Measured memory_bytes: 2052
#include <iostream>
#include <vector>;
using namespace std;
int main()
{
    int a[10],N,maxi,j,i,sum;
    cin>>N;
    for(i=1;i<=N;i++){
        cin>>j;
        a[i-1]=j;
    }

    maxi=a[0];
    sum=a[0];
    for(i=1;i<N;i++){
        sum+=a[i];
        if(a[i]>=a[i-1])
            maxi=a[i];
        else
            a[i]=a[i-1];

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

}


Measured memory_bytes: 3592
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int n; cin>>n;
    vector<int> p(n);
    for(int i=0; i<n; i++) cin>>p[i];

    set<P> st;
    for(int i=0; i<n; i++){
        auto itr = st.lower_bound(P(p[i] - 1, -1));

        if(!st.size() || itr == st.end()){
            st.emplace(p[i], 1);
        }
        else if((*itr).first == p[i] - 1){
            st.emplace(p[i], (*itr).second + 1);
            st.erase(itr);
        }
        else{
            st.emplace(p[i], 1);
        }
    }

    int ans = 0;
    for(auto i : st){
        chmax(ans, i.second);
    }

    ans = n - ans;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 10368
n,k=map(int,input().split())
s=list(map(int,list(input())))
t=[0]+[1 if s[0]==1 else -1]
ans=0
for i in range(1,n):
    if s[i]==s[i-1]:
        t[-1]=i+1 if s[i]==1 else -i-1
    else:
        t+=[i+1 if s[i]==1 else -i-1]
for i in range(len(t)-1):
    temp=0
    l=k*2+1 if t[i+1]>0 else k*2
    temp=abs(t[min(len(t)-1,i+l)])-abs(t[i])
    ans=max(ans,temp)
print(ans)

Measured memory_bytes: 8340
// Original: https://github.com/tanakh/competitive-rs
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

mod util {
    #[allow(dead_code)]
    pub fn chmin<T>(x: &mut T, y: T) -> bool
    where
        T: PartialOrd + Copy,
    {
        *x > y && {
            *x = y;
            true
        }
    }

    #[allow(dead_code)]
    pub fn chmax<T>(x: &mut T, y: T) -> bool
    where
        T: PartialOrd + Copy,
    {
        *x < y && {
            *x = y;
            true
        }
    }

    /// 整数除算切り上げ
    #[allow(dead_code)]
    pub fn roundup(a: i64, b: i64) -> i64 {
        (a + b - 1) / b
    }

    #[allow(dead_code)]
    pub fn ctoi(c: char) -> i64 {
        c as i64 - 48
    }
}

#[allow(unused_imports)]
use util::*;

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, VecDeque};

fn main() {
    input! {
        n:i64
    }

    let nax = 1i64 << 50;
    let mut ans = nax;
    for i in 2.. {
        if i * i > n {
            break;
        }

        if n % i == 0 {
            let j = n / i;
            chmin(&mut ans, i + j - 2);
        }
    }

    if ans == nax {
        println!("{}", n - 1);
    } else {
        println!("{}", ans);
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
          
          #define F first
          #define S second
          #define N 222222
          #define M 1000000007
          #define pb push_back
          #define cend(s) return cout << s, 0
          using namespace std;
          typedef long long ll;
          typedef vector<int> vi;
          ll ar[32232];
          int main()
          {
            int q, k, t = 0;
            cin >> q >> k;
            while(q--)
            {
              ll x, y;
              cin >> x >> y;
              double d = sqrt(x*x*1.0 + y*y*1.0);
              if(d <= k)
                t++;
            }
            cend(t);
          }

Measured memory_bytes: 3700
/* * * * * * * * * * * **
*                      *
*	   saurabh8522	   *
*	  I will handle	   *
*		   IT.		   *
*                      *
* * * * * * * * * * * **/
#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define ld long double
#define zero(a) memset((a),0,sizeof((a)))
#define one(a) memset((a),1,sizeof((a)))
#define minus(a) memset((a),-1,sizeof((a)))
#define all(g) g.begin(),g.end()
#define ppb pop_back
using namespace std;
typedef long long int ll;
#define MOD 1000000007
ll extgcd(ll a,ll b,ll& x,ll& y){if(b==0){x=1;y=0;return a;}else{int g=extgcd(b,a%b,y,x);y-=a/b*x;return g;}}
ll modpow(ll a,ll b) {ll res=1;a%=MOD;for(;b;b>>=1){if(b&1)res=res*a%MOD;a=a*a%MOD;}return res;}
ll numdigit(ll n){return floor(log10(n)) + 1;}
bool isPowerTwo (ll x) { return x && (!(x&(x-1))); } 
int  main(){
	FastRead;
	ll t=1;
	// cin>>t;
	while(t--){
		ll n,k;
		cin>>n>>k;
		vector<ll>v(n);
		for(ll i=0;i<n;i++){
			cin>>v[i];
		}
		ll dp[n];
		for(int i=0;i<n;i++){
			dp[i]=INT_MAX;
		}
		dp[0]=0;
		dp[1]=abs(v[1]-v[0]);
		// cout<<dp[0]<<" "<<dp[1]<<endl;
		for(int i=2;i<n;i++){
			for(int j=1;j<=k;j++){
				if(i-j>=0){
					dp[i]=min(dp[i],dp[i-j]+abs(v[i]-v[i-j]));
				}
			}
			// cout<<i<<" "<<dp[i]<<endl;
		}
		cout<<dp[n-1]<<endl;
	}
}

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

using namespace std;
using llint = long long;
using pint = pair<int,int>;

#define LOG(x) cout << "# " << #x <<" => "<< (x) <<endl

const int INF = 1<<28;
const llint LLINF = 1LL<<60;

int n, ans = INF;
vector<int> w;

vector<int> cumelativeSum(vector<int> &a){
    int n = a.size();
    vector<int> c(n);

    c.at(0) = a.at(0);

    for (int i = 1; i < n; ++i) {
        c.at(i) = a.at(i) + c.at(i-1);
    }

    return c;
}

int main() {
    // Input
    cin >> n;

    w.resize(n);
    for (int i = 0; i < n; ++i) cin >> w.at(i);

    // Solve
    vector<int> c = cumelativeSum(w);

    for (int i = 0; i < n; ++i)
    {
        int sum1, sum2;

        sum1 = c.at(i);
        sum2 = c.at(n-1) - c.at(i);

        ans = min(ans, abs(sum2-sum1));
    }

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

Measured memory_bytes: 256
from sys import stdin

K, N = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(x) for x in input().split()]
ans1 = 100000000000000000
for i in range(N-1):
    if i == 0:
        ans1 = min(a[N-1]-a[0], K-(a[1]-a[0]))
        continue
    # print(a[i]+K-a[i+1])
    # print(K-(a[i]-a[i-1]))
    # print()
    ans = min(a[i]+K-a[i+1], K-(a[i]-a[i-1]))
    if ans1 > ans:
        ans1 = ans
print(ans1)


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

int main() {
	int n, h[100001]; cin>>n;
	for(int i=0;i<n;i++) scanf("%d",&h[i]);
	if(n==1){
		cout<<"Yes"; return 0;
	}
	if(n==2){
		if(h[1]>=h[0]){
			cout<<"Yes";
			return 0;
		}
		else{
			cout<<"No";
			return 0;
		}
	}
	if(n>=3){
		h[0]-=1;
		if(h[0]>h[1]){
			cout<<"No"; return 0;
		}
	}
	for(int i=1;i<n-1;i++){
		if(h[i]>h[i-1]) h[i]-=1;
		if(h[i]>h[i+1]){
			cout<<"No"; return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 640
num5 = 0
num7 = 0

a, b, c = (int(x) for x in input().split())

if (a == 5):
    num5 = num5 +1
elif (a == 7):
    num7 = num7 +1

if (b == 5):
    num5 = num5 +1
elif (b == 7):
    num7 = num7 +1

if (c == 5):
    num5 = num5 +1
elif (c == 7):
    num7 = num7 +1

if (num5 == 2) and (num7 == 1):
    print("YES")
else:
    print("NO")


Measured memory_bytes: 9104
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>

using namespace std;
int DP[2][2002][3001];

int main(){
	
	
	int n, m, s;
	while(true){
		cin >> n >> m >> s;
		if(n == 0){
			break;
		}
		n *= n;
		
		for(int i = 0; i <= m; i++){
			for(int j = 0; j <= s; j++){
				DP[0][i][j] = 0;
				DP[1][i][j] = 0;
			}
			DP[1][i][i] = 1;
		}
		DP[1][0][0] = 0;
		
		for(int i = 2; i <= n; i++){
			for(int j = 1; j <= m; j++){
				for(int k = j; k <= s; k++){
					DP[i % 2][j][k] = DP[i % 2][j - 1][k - 1] + DP[(i + 1) % 2][j - 1][k - j];
					DP[i % 2][j][k] %= 100000;
				}
			}
		}
		
		int ans = 0;
		for(int i = 0; i <= m; i++){
			ans += DP[n % 2][i][s];
			ans %= 100000;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 49940
#include <iostream>
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <array>
#include <queue>
#include <map>
#include <stack>
#include <cstdint>
typedef long long int llint;

int main(void){
  llint a, b;
  std::cin >> a >> b;

  llint aa = a;
  llint bb = b;
  while(aa != bb){
    if(aa<bb) aa+=a;
    else      bb+=b;
  }

  std::cout << aa << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
//typedef LL int;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
int main(){
    int n;
    cin >> n;
    vector<int> a;
 
    REP(i, n*3){
        int x;
        cin >> x;
        a.pb(x);
    }
 
    VSORT(a);
    
    LL ans = 0;
    REP(i, n*3){
        if(i < n) continue;
        if((n+i) % 2 == 0){
            ans += a[i];
        }
    }
 
    cout << ans << endl;
 
}

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

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll x, y, z; cin >> x >> y >> z;
  if (x > y) swap(x, y);
  if (y > z) swap(y, z);
  cout << x * y / 2 << endl;

  return 0;
}



Measured memory_bytes: 3648
#include <cstdio>
#include <algorithm>
#include <cmath>

int W, H, N;
int ans = 0;

int main(){
	scanf("%d%d%d", &W, &H, &N);
	
	int tmp_w, tmp_h;
	for(int i = 0; i < N; ++i){
		int x, y;
		scanf("%d%d", &x, &y);
		if(i == 0){
			tmp_w = x, tmp_h = y;
			continue;
		}

		int w_diff = tmp_w - x, h_diff = tmp_h - y;

		if(w_diff > 0 && h_diff > 0){
			ans += std::max(w_diff, h_diff);
		}
		else if(w_diff < 0 && h_diff < 0){
			ans += std::max(-w_diff, -h_diff);
		}
		else{
			ans += abs(w_diff) + abs(h_diff);
		}

		tmp_w = x, tmp_h = y;
	}

	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 2736
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all(C) std::begin(C), std::end(C)

int32_t N;
int32_t a[10000];
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N;
	for (size_t i = 0; i < N; i++)
	{
		in >> a[i];
	}

	std::sort(a, a + N, std::greater<>{});

	int32_t sum = 0;
	for (size_t i = 0; i < N; i++)
	{
		if (i & 1) {
			sum -= a[i];
		}
		else {
			sum += a[i];
		}
	}

	out << sum << endl;

	return 0;
}
#endif

#if 0
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all(C) std::begin(C), std::end(C)

int32_t H,W;


template<typename T, typename U>
std::enable_if_t<std::rank<T>::value == 0> fill_all(T& arr, const U& v) {
	arr = v;
}
template<typename ARR, typename U>
std::enable_if_t<std::rank<ARR>::value != 0> fill_all(ARR& arr, const U& v) {
	for (auto& i : arr) {
		fill_all(i, v);
	}
}

char map[60][60];
int32_t D[55][55];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> H>>W;
	for (size_t i = 0; i <= W+1; i++) {
		map[0][i] = '#';
		map[H+1][i] = '#';
	}
	int W_COUNT = 0;
	for (size_t i = 1; i <= H; i++)
	{
		map[i][0] = '#';
		in >> (map[i] + 1);
		W_COUNT += std::count_if(map[i] + 1, map[i] + 1 + W, [](char c) {return c == '.'; });
		map[i][W+1] = '#';
	}

	fill_all(D, 505050);
	std::queue<std::pair<int, int>> queue;
	queue.emplace(1, 1);
	D[1][1] = 1;
	while (!queue.empty())
	{
		auto top = queue.front(); queue.pop();

		int cost = D[top.first][top.second] + 1;
		const int diff[] = { 0,1,0,-1,0 };
		for (size_t i = 0; i < 4; i++)
		{
			std::pair<int, int> next = top;
			next.first += diff[i];
			next.second += diff[i+1];
			if (cost < D[next.first][next.second] && map[next.first][next.second]=='.') {

				queue.emplace(next);
				D[next.first][next.second] = cost;
			}
		}

	}

	if (D[H][W]== 505050) {
		out << -1 << endl;
	}
	else {
		out << W_COUNT- D[H][W] << endl;
	}

	return 0;
}
#endif


Measured memory_bytes: 888
#include <bits/stdc++.h>
#define N 1005

using namespace std;

short n, m;
char a[N][N];
bool mark[N][N];

struct Element
{
    short lin, col;
    short nivel;
};

queue < Element > c;

short dl[] = {-1, 0, 1,  0};
short dc[] = { 0, 1, 0, -1};

bool inline Verif(Element v)
{
    if(a[v.lin - 1][v.col] == '.' || a[v.lin + 1][v.col] == '.' || a[v.lin][v.col + 1] == '.' || a[v.lin][v.col - 1] == '.')
        return true;

    return false;
}

bool inline Inside(Element p)
{
    if(p.lin >= 1 && p.lin <= n && p.col >= 1 && p.col <= m)
        return true;

    return false;
}

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    short cnt = 0, i, j;

    cin >> n >> m;

    for(i = 1 ; i <= n ; ++i)
        for(j = 1 ; j <= m ; ++j)
            cin >> a[i][j];

    short ans = 0;
    bool ok = 0;
    Element p, v;

    for(i = 1 ; i <= n ; i++)
        for(j = 1 ; j <= m ; j++)
        {
            if(a[i][j] == '#')
            {
                c.push(Element{i, j , 1});
                mark[i][j] = 1;
            }
        }

    int nivel = 1;

    while(!c.empty())
    {
        p = c.front();
        c.pop();

        if(Inside(p) == false)
            continue;

        if(Verif(p) == true && p.nivel == nivel)
            ++ans , nivel++;

        a[p.lin - 1][p.col] = a[p.lin + 1][p.col] = a[p.lin][p.col - 1] = a[p.lin][p.col + 1] = '#';

        //for(i = 1 ; i <= n ; i++)
            //for(j = 1 ; j <= m ; j++)

        for(short t = 0 ; t < 4 ; t++)
        {
            v = {p.lin + dl[t], p.col + dc[t] , nivel};

            if(Inside(v) && !mark[v.lin][v.col])
                c.push(v), mark[v.lin][v.col] = 1 ;
        }
    }

    cout << ans;

    return 0;
}


Measured memory_bytes: 8448
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	string s;
	cin>>s;
	int l=s.length();
	int n=l+1;
	vector<int> a(n,0);
	if(s[0]=='<'){
		a[0]=0;
	}
	if(s[l-1]=='>'){
		a[l]=0;
	}
	FOR(i,0,l-1){
		if(s[i]=='>'&&s[i+1]=='<'){
			a[i+1]=0;
		}
	}
	FOR(i,0,l){
		if(s[i]=='<'){
			a[i+1]=max(a[i+1],a[i]+1);
		}
	}
	FORD(i,l,0){
		if(s[i]=='>'){
			a[i]=max(a[i],a[i+1]+1);
		}
	}
	LL ans=0;
	FOR(i,0,n){
		ans+=a[i];
	}
	cout<<ans<<endl;


}


Measured memory_bytes: 2820
n,d=map(int,input().split())
x=[[int(i) for i in input().split()] for j in range(n)]
ans=0
for i in range(n):
    for j in range(n-1,0,-1):
        if j==i:
            break
        s=0
        for k in range(d):
            s+=(x[i][k]-x[j][k])**2
        
        s=s**0.5
        if int(s)==s:
            ans+=1
print(ans)

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



namespace ConsoleApplication2
{

    class Program
    {
        static void Main(string[] args)
        {

            
            int  wrong=0;

            string[] mass = Console.ReadLine().Split(' ');

            string[] input = Console.ReadLine().Split(' ');


            int[] listinput = new int[int.Parse(mass[0])];

            for (int i=0;i< int.Parse(mass[0]); i++)
            {
                listinput[i] = int.Parse(input[i]);

                if(listinput[i]!=i+1)
                {
                    wrong++;
                }
            }

            if(wrong>2)
            {
                Console.WriteLine( "NO");

            }
            else
            {
                Console.WriteLine("YES");
            }
        }
    }
}

Measured memory_bytes: 11092
l_h,l_w = gets.chomp.split(" ").map{|i|i = i.to_i}
s_h,s_w = gets.chomp.split(" ").map{|i|i = i.to_i}
puts (l_h*l_w)-( l_h*s_w + l_w*s_h ) + s_w*s_h

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

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

    vector<char> v(n);
    rep(i, k){
        cin >> v[i];
    }

    int ans;
    for(int i=n; i<88889; i++){
        string str = to_string(i);
        bool ng = false;
        for(char c : v){
            if(str.find(c) != string::npos){
                ng = true;
                break;
            }
        }
        if(!ng){
            cout << i;
            break;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
 
signed main(){
	int x;
	cin >> x;
	int ans = (x / 11) * 2;
	x %= 11;
	if(x > 6) cout << ans + 2 << endl;
	else if(x == 0) cout << ans << endl;
	else cout << ans + 1 << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = 0;
		String s="";
		try {
			s = br.readLine();
			//n = Integer.parseInt(br.readLine());
		} catch (NumberFormatException | IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
		String[] str = new String[3];
		str = s.split("");
		//System.out.println(str[0]);
		List<Integer> ret = new ArrayList<Integer>();

		for(int j = 0; j<3;j++){
			if(str[j].equals("1"))ret.add(9);
			else ret.add(1);
		}

		String ans = String.valueOf(ret.get(0)) + String.valueOf(ret.get(1)) + String.valueOf(ret.get(2));
		System.out.println(ans);



	}
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n) ; ++i)
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define emb emplace_back
#define fcout cout << fixed << setprecision(15)


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

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}
bool checked[50][50];

int main() {
  int h,w;
  cin >> h >> w;
  h--;w--;
  checked[0][0] = true;

  int white=0;
  char meiro[h+1][w+1];
  rep(i,h+1) rep(j,w+1) {
    cin >> meiro[i][j];
    if(meiro[i][j] == '.') white++;
  }
  queue<P> que;
  que.push(P(0,0));
  int dx[] = {1,-1,0,0},dy[] = {0,0,-1,1};
  vector<vector<vector<P>>> route(h+1,vector<vector<P>>(w+1));
  route[0][0].emb(P(0,0));

  while(que.size()) {
    P tmp = que.front();que.pop();
    rep(i,4) {
      int nx = tmp.fi + dx[i],ny = tmp.se + dy[i];
      if(0 <= nx and nx <= h and 0 <= ny and ny <= w and meiro[nx][ny] == '.' and !checked[nx][ny]) {
        checked[nx][ny] = true;
        route[nx][ny] = route[tmp.fi][tmp.se];
        route[nx][ny].emb(P(tmp.fi,tmp.se));
        que.push(P(nx,ny));
        if(nx==h and ny == w) {
          cout << white - route[nx][ny].size() << endl;
          return 0;
        }
      }
    }
  }
  cout << "-1" << endl;
  return 0;
}


Measured memory_bytes: 2304
#![allow(non_snake_case)]
use proconio::input;
// use std::collections::HashMap;

fn main() {
    input! {
        N: i32,
    }

    if N / 100 == 7 || (N / 10) % 10 == 7 || N % 10 == 7 {
        println!("Yes");
    } else {
        println!("No");
    }

}


Measured memory_bytes: 2040