akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
	char buf[2048];
	
	fgets(buf, 2048, stdin);
	
	int w, h;
	
	h = atoi(strtok(buf, " "));
	w = atoi(strtok(0, " "));
	
	int **data = malloc(sizeof(int*) * h);
	int **counts = malloc(sizeof(int*) * h);
	
	for(int y = 0; y < h; y ++){
		int* line = data[y] = malloc(sizeof(int) * w);
		int* c_line = counts[y] = malloc(sizeof(int) * w);
		fgets(buf, 2048, stdin);
		for(int x = 0; x < w; x ++){
			line[x] = (buf[x] == '#');
			c_line[x] = -1;
		}
	}
	
	for(int y = 0; y < h; y ++){
		int* line = data[y];
		int* c_line = counts[y];
		int count = -1;
		for(int x = 0; x < w; x ++){
			int c = line[x];
			if(c){
				c_line[x] = 0;
				count = 0;
			}else{
				if(count >= 0){
					count ++;
					c_line[x] = count;
				}
			}
		}
		count = -1;
		for(int x = w - 1; x >= 0; x --){
			int count2 = c_line[x];
			if(count2 >= 0 && (count == -1 || count2 <= count)){
				count = count2;
			}else if(count >= 0){
				count ++;
				c_line[x] = count;
			}
		}
	}

	for(int x = 0; x < w; x ++){
		int count = -1;
		for(int y = 0; y < h; y ++){
			int count2 = counts[y][x];
			if(count2 >= 0 && (count == -1 || count2 <= count)){
				count = count2;
			}else if(count >= 0){
				count ++;
				counts[y][x] = count;
			}
		}
		count = -1;
		for(int y = h - 1; y >= 0; y --){
			int count2 = counts[y][x];
			if(count2 >= 0 && (count == -1 || count2 <= count)){
				count = count2;
			}else if(count >= 0){
				count ++;
				counts[y][x] = count;
			}
		}
	}

	int max = 0;
	for(int y = 0; y < h; y ++){
		int* c_line = counts[y];
		for(int x = 0; x < w; x ++){
			int count = c_line[x];
			if(max < count){
				max = count;
			}
		}
	}
	
	printf("%d\n", max);
	
	return 0;
}




Measured memory_bytes: 8064
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=1e5+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
#endif
}
char s[N];
int n;
void input()
{
	scanf("%s",s+1);
	n=strlen(s+1);
}
bool check()
{
	if(s[1]=='0'||s[n]=='1'||s[n-1]=='0')return false;
	For(i,1,n-1)if(s[i]!=s[n-i])return false;
	return true;
}
bool used[N];
vector<int>E;
int now;
void work()
{
	now=1;
	if(!check()){puts("-1");return;}	
	For(i,1,n)if(s[i]=='1')used[i]=1,E.push_back(i);
	For(i,1,E.size()-1)
	{
		printf("%d %d\n",E[i-1],E[i]);
		For(j,1,E[i]-E[i-1]-1)
		{
			while(used[now])now++;
			printf("%d %d\n",E[i],now++);
		}
	}
	//cerr<<now<<' '<<n<<endl;
	For(i,now,n)if(!used[i])printf("%d %d",i,n-1);
}
int main()
{
//	file();
	input();
	work();
	return 0;
}


Measured memory_bytes: 2040
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

char str[2][105];
int N;

int main() {
	scanf("%d %s %s", &N, str[0], str[1]);
	for(int l = N; ~l; l--) {
		bool flag = false;
		for(int i = 0; i < l; i++)
			if(str[0][N+i-l] != str[1][i]) {
				flag = true; break;
			}
		if(flag) continue;
		printf("%d\n", 2*N-l);
		return 0;
	}
	return 0;
}

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

ll d(ll num)
{
	assert(num >= 0);

	ll d{1};
	for (ll i = 10;; i *= 10, ++d)
	{
		if (num < i) return d;
	}
}

int main(int argc, char **argv)
{
	ll n; cin >> n;

	ll a, b;

	ll ans{LLONG_MAX};

	for (a = 1; a * a <= n; ++a)
	{
		if (n % a != 0) continue;

		b = n / a;
		ll m = max(d(a), d(b));
		ans = min(ans, m);
	}

	std::cout << ans << std::endl;
}


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

int asc(const void *a, const void *b) {
  return *(int *)b - *(int *)a;
}

int main()
{
    int n,l[2000],i,j,k;
    long long ans = 0;

    scanf("%d",&n);
    for(i = 0; i < n;i++)scanf("%d",&l[i]);

    qsort(l,n,sizeof(int),asc);

    for (i = 0; i < n; i++)
    {
        for (j = i + 1; j < n; j++)
        {
            for (k = j + 1; k < n; k++)
            {
                if(l[i] < l[j] + l[k])ans++;
            }
        }
    }
    printf("%lld",ans);
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

template<typename T>
void trace(T *a, int s, int n) {
    for (int i=s; i<n; i++) {
	cout<<a[i]<<" ";
    }
    cout<<endl;
}



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


int n;
void dfs(string s, char hi) {
    if ((int)s.length() == n) {
	cout<<s<<"\n";
    } else {
	for (char c='a'; c<=hi; c++) {
	    dfs(s+c, c==hi? char(c+1): hi);
	}
    }
}


int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n;
    dfs("",'a');
  

    return 0;
}


Measured memory_bytes: 1536
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        int K = scanner.nextInt();

        ArrayList<String> strings = new ArrayList<>();

        for (int i = 0; i < s.length(); i++) {
            for (int j = 1; j < 6; j++) {
                if (i + j > s.length()) {
                    break;
                }

                String sub = s.substring(i, i + j);
                if (!strings.contains(sub)){
                    strings.add(sub);
                }
            }
        }

        // sort
        Collections.sort(strings);
        System.out.print(strings.get(K - 1));
    }
}


Measured memory_bytes: 24132
#include<stdio.h>

main(){
	int num1, num2, num3;
	
	scanf("%d %d %d", &num1 ,&num2, &num3);
	
	if(num1 < num2){
		if(num2 < num3)
			printf("%d %d %d\n", num1, num2, num3);
			
		else if(num3 < num1)
			printf("%d %d %d\n", num3, num1, num2);
		
		else
			printf("%d %d %d\n", num1, num3, num2);
	}
	
	else if(num2 < num1){
		if(num3 < num2)
			printf("%d %d %d\n", num3, num2, num1);
		
		else if(num1 < num3)
			printf("%d %d %d\n", num2, num1, num3);
		
		else
			printf("%d %d %d\n", num2, num3, num1);
	}
	
	return 0;
}
	
	

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

int main() {
	// your code goes here
	int n, k;
	cin >> n >> k;
	int arr[n];
	int dp[n+1];
	
	for(int i = 0; i < n; i++){
		cin >> arr[i];
		dp[i+1] = INT_MAX;
	}
	dp[0] = 0;
	for(int i = 0; i < n; i++){
		for(int j = i+1; j <= i+k; j++){
			if(j < n){
				dp[j] = min(dp[j], dp[i]+abs(arr[j]-arr[i]));
			}
		}
	}
	cout << dp[n-1] << "\n";
	return 0;
}

Measured memory_bytes: 4420
import math

N, A, B = [int(_) for _ in input().split()]
H = [int(input()) for _ in range(N)]


def chk(k):
    a_cnt = 0
    for h in H:
        tmp = h - B * k
        if tmp > 0:
            a_cnt += math.ceil(tmp / (A - B))
    return k >= a_cnt


def find(l, r):
    if l > r: return l
    m = (l + r) // 2
    if chk(m):
        r = m - 1
    else:
        l = m + 1
    return find(l, r)


print(find(0, 10 ** 9))


Measured memory_bytes: 7196
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define dbg(x) cout << #x << '=' << x << '\n';
#define ll long long
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define ld long double
#define pld pair<ld,ld>
#define lg length()
#define sz size()
#define pb push_back
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005
#define x1 xdddddddddddddddddd
#define y1 ydddddddddddddddddd

ll n,h,t,p,cnt;

pl a[100005];

int main(){
    cin >> n >> h;
    for(int i=1;i<=n;i++){
        cin >> a[i].y >> a[i].x;
        p=max(p,a[i].y);
    }
    sort(a+1,a+n+1);
    for(int i=n;i>=1;i--){
        if(a[i].x>=p){
            t+=a[i].x;
            if(t>=h){
                cout << n-i+1;
                return 0;
            }
        }
        else{
            cout << (h-t+p-1)/p+n-i;
            return 0;
        }
    }
    cout << (h-t+p-1)/p+n;
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main()
{
    bool reverse = false;
    string s;
    cin >> s;
    int n, front = 0, back = 0;
    cin >> n;
    char f[n], b[n];
    for(int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        if(x == 1)
        {
            reverse = !reverse;
        }
        else
        {
            int y;
            cin >> y;
            if((reverse && y == 2) || (y == 1 && !reverse))
            {
                cin >> f[front++];
            }
            else
            {
                cin >> b[back++];
            }
        }
    }
    if(reverse)
    {
        for(int i = back - 1; i >= 0; i--)
        {
            cout << b[i];
        }
        for(int i = s.size() - 1; i >= 0; i--)
        {
            cout << s[i];
        }
        for(int i = 0; i < front; i++)
        {
            cout << f[i];
        }
    }
    else
    {
        for(int i = front - 1; i >= 0; i--)
        {
            cout << f[i];
        }
        cout << s;
        for(int i = 0; i < back; i++)
        {
            cout << b[i];
        }
    }
    cout << endl;
    return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N;
    cin >> N;
    vector<ll> A(N);
    REP(i, N) cin >> A[i];
    ll S = 0;
    REP(i, N) S += A[i];
    ll res = (1ll<<60);
    ll left = 0;
    REP(i, N-1){
    	left += A[i];
    	ll right = S - left;
    	res = min(res, abs(left-right));
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    c=max(a,c);d=min(b,d);
    if (c>d) cout<<0<<endl;
    else cout<<d-c<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n, m = map(int,input().split())
B = [list(map(int,input().split())) for i in range(n)]
max_m = -1
for i in range(n):
    for j in range(1, len(B[i])):
        max_m = max(max_m, B[i][j])

C = [[] for i in range(max_m + 1)]
for i in range(n):
    for j in range(1, len(B[i])):
        C[B[i][j]].append(i)

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def size(self, x):
        if self.parents[x] < 0:
            return -self.parents[x]
        else:
            self.parents[x] = self.size(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def n_cc(self):  # 連結成分の数
        A = [i for i in self.parents if i < 0]
        return len(A)

U = UnionFind(n)
# print(C)

for i in range(len(C)):
    for j in range(len(C[i])-1):
        # print(i, j)
        U.union(C[i][j], C[i][j+1])

# print(U.parents)
# print(U.n_cc())
if U.n_cc() == 1:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 70364
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#define MOD 1000000007
#define ll long long

ll cmpfunc(const void *a, const void *b){
    return (*(ll*)b - *(ll*)a);
}

int max(int a,int b){
    return (a>b)?a:b;
}

int main(void){
    ll n,i,a,b;
    scanf("%lld %lld %lld",&n,&a,&b);
    ll h[n+1];
    ll sum=0;
    for(i=1;i<=n;i++) {scanf("%lld",&h[i]);sum+=h[i];}
    qsort(h+1,n,sizeof(ll),cmpfunc);
    ll up=(ll)ceil(1.0*h[1]/b);
    ll ans=0;
    ans=(ll)1.0*sum/(a-b+b*n);
    ll left=ans;
    ll right=up;
    ll cur=(left+right)/2;
    while(left<=right && cur>=left && cur<=right){
        ll count=0;
        for(i=1;i<=n;i++) {
            if(h[i]<=b*cur) continue;
            else {
                count+=(ll)ceil(1.0*(h[i]-b*cur)/(a-b));
                if(count>cur) break;
            }
        }
        if(count>cur){
            left=cur+1;
            cur=(left+right)/2;
        } else if(count==cur || left>=right-1){
            if(left>=right-1){
                printf("%lld\n",cur);
                return 0;
            }
            while(count==cur){
                cur--;
                count=0;
                for(i=1;i<=n;i++) {
                    if(h[i]<=b*cur) continue;
                    else {
                        count+=(ll)ceil(1.0*(h[i]-b*cur)/(a-b));
                        if(count>cur) break;
                    }
                }
                if(count!=cur){
                    printf("%lld\n",cur+1);
                    return 0;
                }
            }
            printf("%lld\n",cur);
            return 0;
        } else{
            right=cur;
            cur=(left+right)/2;
        }
        //printf("%d %d %d %d\n",count,cur,left,right);
    }
    return 0;
}


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

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

    char name[50];
    name[49] = '\0';
    char *p = &name[48];
    while (n) {
        *p-- = 'a' + ((n - 1) % 26);
        --n;
        n /= 26;
    }
    ++p;

    cout << p << endl;
}



Measured memory_bytes: 3620
n = int(input())
s = list(map(int,input().split()))

dic = {}
for i in s:
    if i not in dic:
        dic[i] = 1
    else:
        dic[i] += 1

dic2 = sorted(dic.items(),reverse=True)#[(4, 1), (3, 1), (2, 2), (1, 2)]

i = 0
h = 0
w = 0
while i < len(dic2):
    if dic2[i][1] >= 4 and h == 0 and w == 0:
        print(dic2[i][0]**2)
        exit()
    if dic2[i][1] >= 2 and h == 0:
        h = dic2[i][0]
    elif dic2[i][1] >= 2 and h != 0:
        print(h*dic2[i][0])
        exit()
    i += 1

print(0)

Measured memory_bytes: 21000
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int asc(const void *a, const void *b){
  return *(int *)a - *(int *)b;
}

int main(void)
{
  typedef char String[200001];
  String S, T;
  scanf("%s%s", S, T);
  int len = strlen(S);
  int sChar[26], tChar[26];
  for(int i = 0; i < len; i++){
    sChar[S[i]-'a']++;
    tChar[T[i]-'a']++;
  }
  qsort(sChar, 26, sizeof(int), asc);
  qsort(tChar, 26, sizeof(int), asc);

  for(int i = 25; i > -1; i--){
    if(sChar[i] != tChar[i]){
      printf("%s\n", "No");
      return 0;
    }
  }
  printf("%s\n", "Yes");
  return 0;
}


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

int main()
{

  int n,r ;
  cin >> n >> r ;
  int ans  ;
  
  if(n>=10){
    ans = r ;
  }else{
    ans = r + 100*(10-n) ;
  }
  
  cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int n;
int a[9];

int main(){
	cin>>n;
	int t;
	for(int i=0;i<n;i++){
		cin>>t;
		t/=400;
		if(t>=8){
			a[8]++;
		}else{
			a[t]++;
		}
	}
	int s=0;
	for(int i=0;i<8;i++)
		if(a[i]>0)
			s++;
		
	int m=s;
	
	if(s==0){
		s=1;
		m=a[8];
	}else{
		m+=a[8];
	}
	cout<<s<<" "<<m<<endl;
	return 0;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};

#[fastout]
fn main() {
    input! {
        n:usize
    }
    let mut ans = 0_usize;
    for i in 1..=n {
        if !(i % 3 == 0 || i % 5 == 0) {
            ans += i;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2164
#include <stack>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
#include <iomanip>
#include <string>
#include <limits>
using namespace std;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int mod = 1000000000 + 7;
vector<int> v;
class Calc
{
    // 宣言
    long long a;

    public:
        // 素因数分解
        void decompositPrime(long long a);
};

/*
 * 素因数分解
 */
void Calc::decompositPrime(long long n)
{
    // 割る数の初期値
    a = 2;
    // √n ≧ a ( n ≧ a * a ) の間ループ処理
    while (n >= a * a) {
        // a で割り切れたら、a は素因数
        // そして、割られる数を a で割る
        // a で割り切れなかったら、 a を 1 増加させる
        if (n % a == 0) {
            //printf("%d * ", a);
             v.push_back(a);
            n /= a;
        } else {
            a++;
        }
    }
    // 最後に残った n は素因数
    v.push_back(n);
    //printf("%d\n", n);
}

int main(){
    //std::stack<int> stack;
    for(int i = 0; i < 5; i++){
        int n;
        cin >> n;
        if(n == 0){
            cout << i+1 << endl;
            return 0;
        }
    }
    
    
    //cout << mat[1][n] << endl;
    return 0;
}





Measured memory_bytes: 3568
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <cassert>
using namespace std;

int main(){
    const int M = 100000;
    int N;
    cin >> N;
    vector<pair<int, int>> xy(N);
    for(int i=0; i<N; i++){
        cin >> xy[i].first >> xy[i].second;
        xy[i].first--;
        xy[i].second--;
    }

    vector<int> x2y[M];
    vector<int> y2x[M];
    for(auto z : xy){
        x2y[z.first].push_back(z.second);
        y2x[z.second].push_back(z.first);
    }

    bool visx[M];
    bool visy[M];
    fill_n(visx, M, false);
    fill_n(visy, M, false);

    set<pair<int, int>> st;

    long long ans = 0;
    for(int i=0; i<M; i++){
        if(visx[i]) continue;
        visx[i] = true;

        queue<pair<int, int>> que;
        que.push(make_pair(0, i));
        long long cnt = 0;
        long long cntx = 1, cnty = 0;
        while(!que.empty()){
            auto fr = que.front();
            que.pop();
            if(fr.first == 0){
                for(auto y : x2y[fr.second]){
                    if(!visy[y]){
                        visy[y] = true;
                        cnty++;
                        que.push(make_pair(1, y));
                    }
                    if(st.find(make_pair(fr.second, y)) == st.end()){
                        st.insert(make_pair(fr.second, y));
                        cnt++;
                    }
                }
            }else{
                for(auto x : y2x[fr.second]){
                    if(!visx[x]){
                        visx[x] = true;
                        cntx++;
                        que.push(make_pair(0, x));
                    }
                    if(st.find(make_pair(x, fr.second)) == st.end()){
                        st.insert(make_pair(x, fr.second));
                        cnt++;
                    }
                }
            }
        }
        if(cntx >= 2 && cnty >= 2)
            ans += cntx * cnty - cnt;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13696
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int L,R,d,i,t;
    scanf("%d %d %d",&L,&R,&d);
    t=0;
    for(;L<=R;L++)
    {
        if(L%d==0)
            t++;
    }
    printf("%d",t);
    return 0;
}


Measured memory_bytes: 1736
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int main(void)
{
	int N;
	cin >> N;

	vector<int> P(N);
	for(int i=0; i<N; i++)
		cin >> P[i];

	vector<int> index(N);
	for(int i=0; i<N; i++)
		index[P[i]-1] = i;

	int cnt = 1;
	int cntMax = 1;
	for(int i=0; i<N-1; i++){
		if(index[i+1] > index[i])
			cnt++;
		else
			cnt = 1;

		cntMax = max(cntMax, cnt);
	}

	cout << N - cntMax << endl;

	return 0;
}


Measured memory_bytes: 1792
import java.util.*;
public class Main{
	public static void main (String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int input = scan.nextInt();
		int output = 0;
		for (int i = 1; i < input+1; i++)
		{
			output+=i;
		}
		System.out.print(output);
	}
}

Measured memory_bytes: 21716
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl

using namespace std;

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

const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const int ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

ll gcd(ll a, ll b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

int lcm(int a, int b) { return a * b * gcd(a, b); }

bool compareP(pair<int, int> a, pair<int, int> b) {
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

int main() {
    ll a, b, ans = 0;
    cin >> a >> b;
    ll g = gcd(a, b);
    for (ll i = 2; i * i <= g; i++) {
        if (g % i == 0) {
            ans++;
            while (g % i == 0)
                g /= i;
        }
    }
    if(g > 1)
        ans++;
    cout << ans + 1 << endl;
}

Measured memory_bytes: 256
import math

N,K=map(int,input().split(" "))

s = N % K

t=abs(K-s)

a=[s,t,N]
ans = min(a)

if t>N:
  ans=N
else:
  ans=t

#print(s,t,N)

if s==0 or t==0 or N==0:
  ans=0

print(ans)

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

using namespace std;
typedef long long ll;
#define T_ template
#define Tn typename
T_ <Tn T> inline bool cmin(T & a, const T & b) { return a > b ? a = b, 1 : 0;}
T_ <Tn T> inline bool cmax(T & a, const T & b) { return a < b ? a = b, 1 : 0;}
T_ <Tn L, Tn R> ostream & operator << (ostream &out, pair<L, R> t) {
   return out << "(" << t.first << "," << t.second << ")";
}
T_ <Tn T> ostream & operator << (ostream &out, vector<T> t) {
  for (unsigned i = 0; i < t.size(); i++)
    out << (" ("[!i]) << t[i] << (",)"[i == t.size() - 1]);
  return out;
}

T_<Tn T> inline void read(T &x) {
  x = 0; char ch;
  while (!isdigit(ch = getchar()));
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
}

const int MaxN = 200010;
int n, a, b, c, d; char s[MaxN];

int main() {
  read(n); read(a); read(b); read(c); read(d);
  scanf("%s", s + 1);
  for (int p = a; p < c; p++)
    if (s[p] == '#' && s[p + 1] == '#') {
      puts("No"); return 0;    
    }
  
  for (int p = b; p < d; p++)
    if (s[p] == '#' && s[p + 1] == '#') {
      puts("No"); return 0;    
    }
  
  if (c < d) return puts("Yes"), 0;
  if (c > d) {
    for (int p = b; p <= d; p++)
      if (s[p] == '.' && s[p - 1] == '.' && s[p + 1] == '.') {
        puts("Yes"); return 0; 
      }  
    puts("No"); 
  }
     
	return 0;
}


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

using namespace std;

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

    pair<int, int> s, t;

    cin >> s.first >> s.second >> t.first >> t.second;

    int dx = abs(t.first - s.first);
    int dy = abs(t.second - s.second);
    string path = string(dx, 'R') + string(dy, 'U') + string(dx, 'L') + string(dy, 'D');
    path += "L" + string(dy + 1, 'U') + string(dx + 1, 'R') + "D";
    path += "R" + string(dy + 1, 'D') + string(dx + 1, 'L') + "U";

    cout << path << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long arr[1000000];
int main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);   
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    long long i,j,k,x,y,z;
    string s,t,s1;
    cin>>s;
    cin>>t;
    z=10000000000;
    for (i=0;i<=(s.length()-t.length());i++)
    {
    	s1=s.substr(i,t.length());
    	x=0;
    	for (j=0;j<s1.length();j++)
    	{
    		if (s1[j]!=t[j])
    		{
    			x++;
			}
		}
		z=min(z,x);
	}
	cout<<z<<endl;
}

Measured memory_bytes: 3656
# 2019/07/19
# LCSっぽい？


n=int(input())
s=[sorted(input()) for _ in range(n)]

def lcs(s1,s2):
    dp=[[0]*(len(s2)+1) for _ in range(len(s1)+1)]
    
    for i in range(len(s1)):
        for j in range(len(s2)):
            if s1[i]==s2[j]:
                dp[i+1][j+1]=dp[i][j]+1
            else:
                dp[i+1][j+1]=max(dp[i+1][j],dp[i][j+1])

    # 復元

    ans=''
    i,j=len(s1),len(s2)
    while i>=0 and j>=0:
        if dp[i-1][j]==dp[i][j]:i-=1
        elif dp[i][j-1]==dp[i][j]:j-=1
        else:
            ans=s1[i-1]+ans
            i,j=i-1,j-1
    return sorted(ans)

s1=s[0]
for i in range(1,n):
    s2=s[i]
    s1=lcs(s1,s2)

print(''.join(s1))


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

#ifdef LOCAL
#define debug(var) cerr << #var << " = " << var << endl;
#else
#define debug(var)
#endif

void init() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
}

map<int, long long> m;

void solve() {
	int n;
	long long k; scanf("%d%lld", &n, &k);
	for (int i = 0; i < n; ++i) {
		int a, b; scanf("%d%d", &a, &b);
		m[a] += b;
	}
	long long c = 0;
	for (const auto &e: m) {
		c += e.second;
		if (c >= k) {
			printf("%d", e.first);
			break;
		}
	}
}

int main() {
	init();
	int t = 1; //scanf("%d", &t);
	while (t--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 4224
#include<iostream>
#include<string>
using namespace std;
int main(){
string a,b,c;
cin>>a>>b>>c;
if(a[a.size()-1]==b[0] && b[b.size()-1]==c[0]){
	cout<<"YES"<<endl;
}
else{
	cout<<"NO"<<endl;
}

}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;


public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskT solver = new TaskT();
        solver.solve(1, in, out);
        out.close();
    }
    
    

    static class TaskT {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int ans = 0;
            int cnt = 0;
            String S = in.next();
            char last = S.charAt(0);
            if(last == 'R')
            	cnt ++;
            ans = Math.max(ans, cnt);
            for(int i = 1; i < S.length(); i++){
            	if(S.charAt(i) == 'R'){
            		cnt ++;
            		ans = Math.max(ans, cnt);
            	}
            	else
            		cnt = 0;
            }
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        
        public long nextLong() {
            return Long.parseLong(next());
        }
    }
}



Measured memory_bytes: 32924
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
#define PI 3.141592653589793

int main(){
  int N; cin >> N; pair<ll, ll> a[N];
  rep(i, N){
    ll k; cin >> k; a[i] = {k, i+1};
  }
  sort(a, a+N, greater<>());
  ll dp[N+1][N+1] = {};
  for(int i=1; i<=N; i++){
    dp[0][i] = max(dp[0][i-1] + a[i-1].first*abs(a[i-1].second-(N-i+1)), dp[0][i]);
    dp[i][0] = max(dp[i-1][0] + a[i-1].first*abs(a[i-1].second-i), dp[i][0]);
  }
  for(int i=1; i<=N; i++){
    for(int j=1; j<=N-i; j++){
      dp[i][j] = max(dp[i-1][j]+a[i+j-1].first*abs(a[i+j-1].second-i), dp[i][j-1]+a[i+j-1].first*abs(a[i+j-1].second-(N-j+1)));
    }
  }
  ll ans = 0;
  rep(i, N+1){
    ans = max(ans, dp[i][N-i]);
  }
  cout << ans << endl;
}

Measured memory_bytes: 34948
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()

class RangeSpannedGraph(object):
    def __init__(self, n, weighted = False):
        self.n = n
        self.N = N = 1 << (n - 1).bit_length()
        self._weighted = weighted
        N2, N3 = N * 2, N * 3
        ref, _add_edge = self._reflect, self._add_edge
        self.E = [[] for _ in range(N3)]
        for i in range(N - 1, 0, -1):
            cl, cr = i << 1, i << 1 | 1
            _add_edge(i, cl)
            _add_edge(i, cr)
            _add_edge(ref(cl + N2), i + N2)
            _add_edge(ref(cr + N2), i + N2)

    def _reflect(self, v):
        return v if v < 3 * self.N else v - 2 * self.N

    def add_edge(self, u, v, w = 0):
        self._add_edge(self.to_index(u), self.to_index(v ), w)

    def _add_edge(self, u, v, w = 0):
        self.E[u].append((v, w)) if self._weighted else v

    def add_range_edge(self, l0, r0, l1, r1, w):
        N, E = self.N, self.E
        E.append([])
        v = len(E) - 1
        self._add_range_edge(l0 + N, r0 + N, v, w, to = True)
        self._add_range_edge(l1 + N, r1 + N, v, 0, to = False)

    def _add_range_edge(self, l, r, v, w, to):
        N2, E = self.N * 2, self.E
        ref, _add_edge = self._reflect, self._add_edge
        while l < r:
            if l & 1:
                _add_edge(ref(l + N2), v, w) if to else _add_edge(v, l, w)
                l += 1
            if r & 1:
                r -= 1
                _add_edge(ref(r + N2), v, w) if to else _add_edge(v, r, w)
            l >>= 1
            r >>= 1

    def to_index(self, v):
        return v + self.N

from heapq import heappop, heappush
def resolve():
    n, m = map(int, input().split())
    rsg = RangeSpannedGraph(n, weighted = True)
    for _ in range(m):
        u, v, w = map(int, input().split())
        u -= 1
        rsg.add_range_edge(u, v, u, v, w)

    # Dijkstra
    E = rsg.E
    dist = [INF] * len(E)
    dist[rsg.to_index(0)] = 0
    heap = [(0, rsg.to_index(0))]
    while heap:
        d, v = heappop(heap)
        if dist[v] != d:
            continue
        for nv, w in E[v]:
            if dist[nv] > d + w:
                dist[nv] = d + w
                heappush(heap, (d + w, nv))

    ans = dist[rsg.to_index(n - 1)]
    if ans == INF:
        ans = -1
    print(ans)
resolve()

Measured memory_bytes: 261184
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <functional>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define mk make_pair

template <class key, class cmp = std::less<key>>
using ordered_set = tree<key, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod = 1e9 + 7;

void solve()
{
    ll n, m, a, b, c;
    cin >> n >> m >> a >> b >> c;
    vector<pair<ll, int>> x;

    for (int i = 0; i < a; i++)
    {
        ll l;
        cin >> l;
        x.push_back({l, 0});
    }
    for (int i = 0; i < b; i++)
    {
        ll l;
        cin >> l;
        x.push_back({l, 1});
    }
    for (int i = 0; i < c; i++)
    {
        ll l;
        cin >> l;
        x.push_back({l, 2});
    }

    sort(x.rbegin(), x.rend());

    ll aa = 0, bb = 0, cc = 0;
    ll ans = 0;
    for (int i = 0, j; i < x.size() && aa + bb + cc < n + m; i++)
    {
        if (x[i].second == 0 && aa < n)
        {
            ans += x[i].first;
            aa++;
        }
        else if (x[i].second == 1 && bb < m)
        {
            ans += x[i].first;
            bb++;
        }
        else if(x[i].second == 2)
        {
            ans += x[i].first;
            cc++;
        }
    }

    cout<<ans<<endl;
}

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

    // ll t;
    // cin >> t;

    // while (t--)
    // {
    //     solve();
    // }
    solve();
    return 0;
}

Measured memory_bytes: 10604
/*
START BY THE NAME OF ALMIGHTY ALLAH
THIS WONT BE ACCEPTED
STOP_GIVING_UP

██╗███████╗████████╗██╗ █████╗ ██╗  ██╗
██║██╔════╝╚══██╔══╝██║██╔══██╗██║ ██╔╝
██║███████╗   ██║   ██║███████║█████╔╝
██║╚════██║   ██║   ██║██╔══██║██╔═██╗
██║███████║   ██║   ██║██║  ██║██║  ██╗
╚═╝╚══════╝   ╚═╝   ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝




*/
#include<bits/stdc++.h>
#define l(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define in insert
#define mp make_pair
#define lw(v) sort(v.begin(),v.end());
#define hi(v) sort(v.begin(),v.end(),greater<long long>());
#define all(v) v.begin(),v.end()
#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long t,r=1,r1=0,r2=0,k=0,a,b,c=1,m,d=0,n,e,f,x=0,g,p=0,q=0,y=0,z=0;
    double kk=0,mm=0;
    vector<pair<long long,long long>>v;
    vector<long long>u;
    map<string,long long>s;
    std::vector<int>::iterator it;
    string  s1,s2,s3,s4;
   cin>>t>>m>>n;
   l(i,m,n+1)
   {
       if(i%t==0)
       {
           cout<<"OK";
           return 0;
       }
   }
   cout<<"NG"<<endl;
}


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

void solve () {
    long long a, b;
    cin >> a >> b;
    cout << a * b / __gcd(a, b);
}

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


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int INF = 1e9;
bool p[100010] = {};
bool good[100010] = {};
int num[100010];
int main() {
  p[2] = true;
  for (int i = 3; i <= 1e5; i++) {
    bool f = true;
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) {
        f = false;
        break;
      }
    }
    if (f) p[i] = true;
    if (f && p[(i + 1) / 2]) good[i] = true;
  }
  for (int i = 3; i <= 1e5; i++) {
    num[i] = good[i];
    num[i] += num[i - 1];
  }
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    cout << num[r] - num[l - 1] << endl;
  }
  return 0;
}


Measured memory_bytes: 1152
n = int(input())
r = list(map(int, input().split()))

num = 0
flag = 0

while True:
  for k in range(n):
    if not r[k] % 2:
      r[k] /= 2
    else:
      flag = 1
  if flag:
    break
  num += 1

print(num)

Measured memory_bytes: 3060
from itertools import permutations

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

d = dict()
for i, perm in enumerate(permutations(range(1, n + 1)), 1):
    d[perm] = i

print(abs(d[p] - d[q]))


Measured memory_bytes: 10472
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
char s[100005];
char b[100005];
int c[100005];

int main(){
	cin>>s + 1;
	int n = strlen(s + 1);
	int j = 0;
	for(int i = 1;i <= n;i++){
		if(s[i] != 'x') 
		{
			b[++j] = s[i];
			c[j] = i;
		}
	}
	//	for(int i = 1;i <= j;i++) cout<<b[i];
	int head1 = 1,tail1 = j;
	int flag = 1;
	while(head1 <= tail1)
	{
		if(b[head1] != b[tail1]) 
		{
			flag = 0;
			break;
		}
		else
		{
			head1++;
			tail1--;
		}
	}
	if(flag == 0) cout<<-1<<endl;
	/*	int mid = (j + 1) / 2;
		int sum = 0;
		if(j % 2 == 1)
		{
		int head = mid,tail = mid;
		while(head >= 1 && tail <= n){
		while()
		}
		}*/
		else
		{
			int l1 = 0,r1 = 0;
			for(int i = 1;i <= n;i++){
				if(s[i] != b[1]) l1++;
				else break;
			}
			for(int i = n;i >= 1;i--){
				if(s[i] != b[j]) r1++;
				else break;
			}
			int ans = abs(l1 - r1);
			int l,r;
			if(j % 2 == 1){
				l = (j + 1) / 2;
				r = (j + 1) / 2;
			}
			else 
			{
				l = j / 2;
				r = j / 2 + 1;
			}
			int sum = 0;
			while(l > 1 && r < j){
				sum = sum + abs(abs(c[l] - c[l - 1]) - abs(c[r] - c[r + 1]));
				l--;
				r++;
			}
			cout<<sum + ans<<endl;
		}
		return 0;
}

Measured memory_bytes: 768
import java.util.*;
public class Main {
	public static void main(String[] args){
      	//データ取り込み
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
      	int B = sc.nextInt();
      	int X = sc.nextInt();
		if(X>=A && X<=A+B ){
        System.out.println("YES");	
        }else{
        System.out.println("NO");

        }
      	      
      	
    }
}

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

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define P 1000000007
#define N 100010
int n; ll a[N], A, B;
int f[N], g[N], riA[N], riB[N];

int main() {
	cin >> n >> A >> B;
	for (int i = 0; i < n; i ++) cin >> a[i];
	riA[n-1] = riB[n-1] = n-1;
	for (int i = n-2; i >= 0; i --) {
		if (a[i+1] - a[i] >= A) riA[i] = riA[i+1];
		else riA[i] = i;
		if (a[i+1] - a[i] >= B) riB[i] = riB[i+1];
		else riB[i] = i;
	}
	f[0] = g[0] = 1;
	for (int i = 0; i < n-1; i ++) {
		// f[i]
		// first
		if (a[i+1] - a[i] >= A) {
			(f[i+1] += f[i]) %= P;
		}
		// second
		int ne = lower_bound(a, a+n, a[i]+A)-a-1;
		ne = max(ne, i+1);
		if (riB[i+1] >= ne) {
			(g[ne] += f[i]) %= P;
		}
		// g[i]
		// second
		if (a[i+1] - a[i] >= B) {
			(g[i+1] += g[i]) %= P;
		}
		// first
		ne = lower_bound(a, a+n, a[i]+B)-a-1;
		ne = max(ne, i+1);
		if (riA[i+1] >= ne) {
			(f[ne] += g[i]) %= P;
		}
	}
	printf ("%d\n", (f[n-1] + g[n-1])%P);
	return 0;
}

Measured memory_bytes: 2688
n, m = map(int, input().split())
number = ['x' for i in range(n)]
flag = True
for i in range(m):
    s, c = map(int, input().split())
    if n != 1 and s == 1 and c ==0:
        flag = False
    if number[s - 1] != 'x' and  number[s - 1] != c:
        flag = False
    number[s - 1] = c

if number[0] == 'x' and 1 < n:
    number[0] = 1
if number[0] == 'x' and 1 == n:
    number[0] = 0
for i in range(1, n):
    if number[i] == 'x':
        number[i] = 0

if flag:
    for i in range(n):
        print(number[i], end='')
else:
    print(-1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
char mp[101][101];
int dx[4]  ={1,0,-1,0};
int dy[4] = {0,1,0,-1};
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i = 0;i<n;i++)
    {
        scanf("%s",mp[i]);
    }
    for(int i = 0;i<n;i++)
    {
        for(int j = 0;j<m;j++)
        {
            if(mp[i][j] == '#')
            {
                int flag = 0;
                for(int k = 0;k<4;k++)
                {
                    int x = i + dx[k];
                    int y = j + dy[k];
                    if(x <0 || y <0 || x > n || y > m) continue;
                    if(mp[x][y] == '#') flag = 1;
                }
                if(!flag)
                {
                    //cout<<i<<' '<<j<<endl;
                    cout<<"No"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;
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; }


ll choose2(ll n) {
    return n*(n-1)/2;
}
int main() {
int n;
cin >> n;
vector<int>a(n);

rep(i,n) {
    cin >> a[i];
    a[i]--;
}
vector<int>cnt(n);
rep(i,n) cnt[a[i]]++;
ll tot = 0;

rep(i,n) {
    tot += choose2(cnt[i]);
}

rep(i,n) {
    ll ans = tot;
    ans -= choose2(cnt[a[i]]);
    ans += choose2(cnt[a[i]]-1);
    cout << ans << endl;
}
}


Measured memory_bytes: 4096
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll f(ll n, ll k)
{
    if (k == 1)
        return 0;
    while (n % k == 0)
        n /= k;
    return n % k == 1;
}
int main()
{
    ll n;
    cin >> n;
    ll t = n, ans = 0;
    n = n - 1;
    for (ll i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            if (__gcd(i, t) == 1)
                ans += f(t, i);
            if (i * i != n && __gcd(t, n / i) == 1)
                ans += f(t, n / i);
        }
    }
    n = t;
    for (ll i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            ans += f(n, i);
            if (i * i != n)
                ans += f(n, n / i);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    ll H, W, N; cin >> H >> W >> N;
    vector<int> a(N), b(N);
    vector<ll> ans(10, 0);
    ans[0] = (H-2)*(W-2);
    for(int i=0; i<N; i++) cin >> a[i] >> b[i];

    map<pair<int,int>, int> mp;

    for(int i=0; i<N; i++){
        for(int j=0; j<3; j++){
            for(int k=0; k<3; k++){
                if(a[i]-j <= 0 || b[i]-k <= 0) continue;
                if(a[i]-j >= H-1 || b[i]-k >= W-1) continue;

                //cout << a[i]-j << " " << b[i]-k << endl;
                mp[make_pair(a[i]-j, b[i]-k)]++;
            }
        }
    }

    for(auto itr=mp.begin(); itr!=mp.end(); itr++){
        ans[itr->second]++;
        ans[0]--;
    }

    for(int i=0; i<10; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 57216
n,m,xPos,yPos = list(map(int,input().split()))
x = list(map(int,input().split()))
y = list(map(int,input().split()))
x.sort(reverse=True)
y.sort()
#FIX x,y add xPos,yPos
if x[0] >= y[0] or y[0] <= xPos or x[0] >= yPos :
    print("War")
else:
    print("No War")


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x, ll y){ll r;while((r = x % y) != 0){x = y;y = r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=0,res2=INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0;
  bool judge = true;
  ll n; cin>>n;
  cin>>res;
  for(i=1;i<n;i++){
    cin>>buf;
    res=res/gcd(buf,res)*buf;

  }
  cout<<res<<endl;
  

  return 0;
}

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

int gcd(int a, int b) {
    if (b==0) return a;
    else return gcd(b, a%b);
}

int gcd(int i, int j, int k)
{
	int r = gcd(i, j);
	return gcd(r, k);
}

int main(){
  int sum = 0;
  int k = 0;
  cin >> k;
  for (int i = 1; i < k+1;i++){
    for (int j = 1; j < k+1;j++){
      for (int l = 1; l < k+1;l++){
        sum += gcd(i,j,l);
      }
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3596