akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

int h, w;
int cnt = 0;
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
char s[51][51];
int main()
{
	cin >> h >> w;
	REP(i, 0, h) REP(j, 0, w) {
		cin >> s[i][j];
		if (s[i][j] == '.') cnt++;
	}

	if (s[0][0] == '#' || s[h - 1][w - 1] == '#') {
		cout << -1 << endl;
		return 0;
	}

	int hist[51][51];
	REP(i, 0, 51) REP(j, 0, 51) hist[i][j] = -1;
	hist[0][0] = 0;
	queue<pair<int, int>> q;
	q.push({ 0, 0 });

	while (!q.empty()) {
		int y = q.front().first;
		int x = q.front().second;
		q.pop();
		
		REP(k, 0, 4) {
			int ny = y + dy[k];
			int nx = x + dx[k];

			if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
			if (s[ny][nx] == '#') continue;
			if (hist[ny][nx] != -1) continue;

			hist[ny][nx] = hist[y][x] + 1;
			q.push({ ny, nx });
		}
	}
	
	if (hist[h - 1][w - 1] == -1) cout << -1 << endl;
	else cout << cnt - (hist[h - 1][w - 1] + 1) << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	long long n,p=1;
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		p=p*i;
		if(p>1000000007)
			p=p%1000000007;
	}
	cout<<p;
	return 0;
}


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

#define N 8
#define FREE -1 // おける
#define NOT_FREE 1 // おけない

int row[N], col[N], dpos[2 * N - 1], dneg[2 * N - 1];
bool X[N][N];

void initialize()
{
    memset(row, FREE, sizeof(row));
    memset(col, FREE, sizeof(col));
    memset(dpos, FREE, sizeof(dpos));
    memset(dneg, FREE, sizeof(dneg));
}

void printBoard()
{
    rep(i, N)
    {
        rep(j, N)
        {
            if (X[i][j]) {
                if (row[i] != j) {
                    return;
                }
            }
        }
    }
    rep(i, N)
    {
        rep(j, N)
        {
            cout << ((row[i] == j) ? "Q" : ".");
        }
        cout << endl;
    }
}

void rec(int i)
{
    if (i == N) {
        printBoard();
        return;
    }
    rep(j, N)
    {
        // (i,j)が他のクイーンに襲撃されている場合は無視
        if (col[j] == NOT_FREE || dpos[i + j] == NOT_FREE || dneg[i - j + N - 1] == NOT_FREE) {
            continue;
        }
        // (i,j)にクイーンを配置
        row[i] = j;
        // クイーンの置けない部分を指定する
        col[j] = dpos[i + j] = dneg[i - j + N - 1] = NOT_FREE;
        // 次の行を試す
        rec(i + 1);
        // (i,j)に配置されているクイーンを取り除く
        row[i] = col[j] = dpos[i + j] = dneg[i - j + N - 1] = FREE;
    }
    // クイーンの配置に失敗
}

int main()
{
    initialize();

    memset(X, false, sizeof(X));

    int k;
    cin >> k;
    rep(i, k)
    {
        int r, c;
        cin >> r >> c;
        X[r][c] = true;
    }

    rec(0);

    return 0;
}



Measured memory_bytes: 3120
#include <iostream>

using namespace std;

int main()
{
    int A, B, C, no_of_operations;
    cin >> A >> B >> C >> no_of_operations;
    
    while(A >= B && no_of_operations > 0)
    {
        B *= 2;
        no_of_operations--;
    }
    
    while(B >= C && no_of_operations > 0)
    {
        C *= 2;
        no_of_operations--;
    }
    
    cout << (A < B && B < C ? "Yes\n" : "No\n");
    return 0;
}


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

INF = float('inf')


def LI(): return list(map(int, sys.stdin.readline().split()))


def I(): return int(sys.stdin.readline())


def LS(): return sys.stdin.readline().split()


def S(): return sys.stdin.readline().strip()


def IR(n): return [I() for i in range(n)]


def LIR(n): return [LI() for i in range(n)]


def SR(n): return [S() for i in range(n)]


def LSR(n): return [LS() for i in range(n)]


def SRL(n): return [list(S()) for i in range(n)]


def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]


mod = 10 ** 9 + 7

h,w,m= LI()
s=set()
D1=defaultdict(int)
D2=defaultdict(int)
for _ in range(m):
    h,w=LI()
    D1[h-1]+=1
    D2[w-1]+=1
    s.add((h-1,w-1))

h_max = max(D1.values())
w_max = max(D2.values())
A=[i for i,v in D1.items() if v==h_max]
B=[i for i,v in D2.items() if v==w_max]

flg = 1
for i in A:
    for j in B:
        if (i, j) not in s:
            flg = 0
            break

print(w_max+h_max-flg)






Measured memory_bytes: 191876
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n;
    vector<int> v;
    for(int i=0;i<n;i++){
        int k;
        cin>>k;
        v.pb(k);
    }
    sort(v.begin(),v.end());
    ll ans=10000000000;
    for(int i=-100;i<=100;i++){
        ll count=0;
        for(int j=0;j<n;j++){
            count+=(v[j]-i)*(v[j]-i);
        }
        if(count<ans){
            ans=count;
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
n = I()
a = LI()
b = [None for i in range(n-1)]
for i in range(n-1):
    a[i+1] += a[i]
for i in range(n-1):
    b[i] = abs(2*a[i]-a[n-1])
print(min(b))
#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 25264
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

struct Info{
	char name[21];
	int length;
};

void strcpy(char* to,char* str){
	for(int i=0;str[i] != '\0';i++){
		to[i] = str[i];
		to[i+1] = '\0';
	}
}

int main(){

	int N,cost[14][14],limit,count,tmp,ans,next_state,num_town;
	int** dp = new int*[14];
	bool* check = new bool[16384];
	for(int i = 0; i < 14; i++){
		dp[i] = new int[16384];
	}

	Info first_info[14],info[14];
	bool FLG,part_sentence[14];

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		for(int i = 0; i < N; i++){
			scanf("%s",first_info[i].name);
			for(first_info[i].length = 0; first_info[i].name[first_info[i].length] != '\0';first_info[i].length++);
		}

		for(int i = 0; i < 14;i++)part_sentence[i] = false;

		for(int i = 0; i < N; i++){
			for(int k = 0; k < N; k++){
				if(i != k && first_info[i].length <= first_info[k].length){
					for(int left = 0; first_info[k].length-left >= first_info[i].length;left++){
						FLG = true;

						for(int a = 0; a < first_info[i].length; a++){
							if(first_info[i].name[a] != first_info[k].name[left+a]){
								FLG = false;
								break;
							}
						}

						if(FLG){
							part_sentence[i] = true;
							break;
						}
					}

				}
			}
		}

		num_town = 0;

		for(int i = 0; i < N; i++){
			if(part_sentence[i] == false){
				strcpy(info[num_town].name,first_info[i].name);
				info[num_town].length = first_info[i].length;
				num_town++;
			}
		}

		N = num_town;

		for(int i = 0; i < N; i++){
			for(int k = 0; k < N; k++){
				if(i == k)continue;

				count = 0;

				for(int left = 0; left < info[i].length;left++){
					FLG = true;
					for(int a = left; a < info[i].length && (a-left) < info[k].length;a++){
						if(info[i].name[a] != info[k].name[a-left]){
							FLG = false;
							break;
						}
					}
					if(FLG){
						count = info[i].length-left;
						break;
					}
				}

				cost[i][k] = count;
			}
		}

		limit = pow(2,N);
		for(int i = 0; i < limit;i++)check[i] = false;

		for(int i = 0; i < N;i++){
			for(int k = 0; k < limit; k++){
				dp[i][k] = BIG_NUM;
			}
		}

		for(int i = 0; i < N; i++){
			tmp = pow(2,i);
			dp[i][tmp] = info[i].length;
			check[tmp] = true;
		}

		for(int state = 0; state <= limit-2; state++){
			if(!check[state])continue;
			for(int k = 0; k < N; k++){
				if(dp[k][state] == BIG_NUM)continue;
				for(int a = 0; a < N; a++){
					if(state & (1 << a)){
						//Do nothing
					}else{
						next_state = state + pow(2,a);
						if(dp[a][next_state] > dp[k][state] + info[a].length - cost[k][a]){
							dp[a][next_state] = dp[k][state] + info[a].length - cost[k][a];
							check[next_state] = true;
						}
					}
				}
			}
		}

		ans = BIG_NUM;
		for(int i = 0; i < N; i++){
			ans = min(ans,dp[i][limit-1]);
		}

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

	return 0;
}

Measured memory_bytes: 3684
import math
N,D = list(map(int, input().split()))
#dlist = []
ans = 0
for i in range(N):
  x,y = list(map(int, input().split()))
  d = math.sqrt(x*x + y*y)
  if(d <= D):
    ans += 1
  #dlist.append(d)
#print(dlist)
print(ans)

Measured memory_bytes: 9200
#[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)*}
    };
}

#[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, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

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

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

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn print_lcs(a: &Vec<char>, b: &Vec<char>, lcs: &Vec<Vec<usize>>, i: usize, j: usize) {
    if i == 0 || j == 0 {
        return;
    }
    if a[i-1] == b[j-1] {
        print_lcs(a, b, lcs, i-1, j-1);
        print!("{}", a[i-1]);
    } else {
        if lcs[i-1][j] >= lcs[i][j-1] {
            print_lcs(a, b, lcs, i-1, j);
        } else {
            print_lcs(a, b, lcs, i, j-1);
        }
    }
}

fn solve() {
    input!{
      s: chars,
      t: chars,
    }

    let n = s.len();
    let m = t.len();
    let mut dp = vec![vec![0; m+1]; n+1];

    for i in 0..n {
        for j in 0..m {
            if s[i] == t[j] {
                dp[i+1][j+1] = dp[i][j] + 1;
            } else {
                dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
            }
        }
    }
    print_lcs(&s, &t, &dp, n, m);
}

fn main() {
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 94588
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();

        int x = sc.nextInt();
        
        if (x >= 30) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

    static class MyScanner {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 1 << 15);
        StringTokenizer tokenizer;

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

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

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

using namespace std;

#define fileInput(problemName) freopen ((string(problemName) + ".inp").c_str(), "r", stdin);freopen ((string(problemName) + ".out").c_str(), "w", stdout);
#define ll long long

const ll inf = 1e9 + 7;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 7;

int n, w;
int a[N], b[N];
long long f[107][N];

main() {
    //fileInput("knapsack-1");
    cin >> n >> w;
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> b[i];
    }
    memset(f, 0, sizeof(f));
    for (int i = 1; i <= n; i++) f[i][0] = 0;
    for (int j = 1; j <= w; j++) f[0][j] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= w; j++) {
            if (a[i] <= j) f[i][j] = max(f[i - 1][j], f[i - 1][j - a[i]] + b[i]);
            else f[i][j] = f[i - 1][j];
        }
    }
    cout << f[n][w] << endl;
}

Measured memory_bytes: 87212
// This is the start of shubhams template//
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long int
void input(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
}
#define deg(x) cout<<#x<<" = "<<x;
#define vll vector<int>
#define pb push_back
#define pll pair<int,int>
#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define INF LONG_LONG_MAX
#define mod 998244353
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define cases int t; cin>>t; while(t--)
#define array(a,n) vll a(n); rep(i,0,n) cin>>a[i];
#define sortall(a) sort(a.begin(),a.end())
#define printall(a) rep(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;
//this is the end of shubhams template //
int power(int a,int n);
void solve();

int32_t main()
{
	input();
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
   int n ,k,sum = 0;
   cin>>n>>k;
   vector<vector<int>>a(k,vector<int>(2));

   for(int i = 0;i<k ;i++)
   	cin>>a[i][0]>>a[i][1];

   int dp[n+1]={};
   int pref[n+1] = {};
   dp[1] = pref[1] = 1;
   for(int i = 2;i<= n ;i++)
   {
   	 for(int j= 0;j<k ;j++)
   	 {
   	 	if(i>a[j][0])
   	 	{
   	 		dp[i] += pref[i -a[j][0]];
   	 		if(i > a[j][1])
   	 			dp[i] -= pref[i-a[j][1]-1];
   	 		
   	 		dp[i] = (dp[i] + mod)%mod; 
   	 	}
   	 }
   	 pref[i]+= (pref[i-1]+dp[i])%mod;
   }
  // for(int i = 0;i<=n  ;i++)
  // 	cout<<pref[i]<<endl;
  cout<<dp[n]<<endl;
}
int power(int a,int n)
{
    if(n==0)
        return 1;
    if(n%2!=0)
    {
        return (a*power((a*a),n/2));
    }
    return power((a*a),n/2);
}

//shubham gupta


Measured memory_bytes: 6768
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
#include <iomanip>

typedef long long ll;
const ll MOD = 998244353;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;


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

    vector<ll> dp(n+1,0);
    vector<ll> add(n+1,0),sub(n+1,0);
    ll diff = 0;
    dp[0] = 1;
    for(int i = 0; i < n; i++){
        diff += add[i];
        diff -= sub[i];
        if(diff < 0) diff += MOD;
        diff %= MOD;
        if(dp[i] == 0) dp[i] = diff;
        for(int j = 0; j < k; j++){
            ll l = i + lr[j].first;
            ll r = i + lr[j].second;
            l = min(l, n);
            r = min(r, n);
            add[l] += dp[i];
            add[l] %= MOD;
            sub[r] += dp[i];
            sub[r] %= MOD;
        }
    }

    cout << dp[n-1] << endl;

    return 0;
}

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

#define josh 0
#define ll long long
#define llu long long unsigned
#define ii pair<int ,int>
#define iii pair<int, ii>
#define all(v) (v).begin(), (v).end()
#define vout(v) for(auto i:v)cout<<i<<" "; cout<<endl;
#define loop(x, n, p) for(int i=x; p>0 ? i<n : i>=n; i+=p)
#define deb(x) cout<<#x<<" "<<x<<endl;
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define file(x) if(x=="in")freopen("input.txt", "r", stdin); \
                else{freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);}



template <typename... T>
void read(T&... args){
    ((cin>>args), ...);
}

template <typename T>
T get(T& a){
    read(a);
    return a;
}



struct Converter{
template<typename T>
    T toNum(string s, T& n){
        stringstream ss; ss<<s;
        ss>>n;
        return n;
    }
template <typename T>
    string toString(T& n){
        stringstream ss; ss<<n;
        string s; ss>>s;
        return s;
    }

}convert;

struct Prime{

    bool isPrime[10000007]={0};
    std::vector<int> primeContain;

    void sieve(int n){

        memset(isPrime, true, sizeof(isPrime));

        for (int p=2; p*p<=n; p++){
            if (isPrime[p] == true){
                for (int i=p*p; i<=n; i += p)
                    isPrime[i] = false;
            }
        }
        isPrime[0]=0, isPrime[1]=0;
        loop(2, n+7, 1)
            if(isPrime[i])
                primeContain.push_back(i);

    }


    bool primeDigit(int n){
        while(n){
            int t=n%10;
            if(t!=2 && t!=3 && t!=5 && t!=7)
                return false;
            n/=10;
        }
        return true;
    }


}prime;


struct Algo{

    int josephusDP[100005];

    int josephus(int n, int k){ //O(N)
        if(josephusDP[n]!=-1)return josephusDP[n];
        if(n==1)return 1;  ///return 0;  //for 0 based
        return josephusDP[n] = (josephus(n-1, k)+k-1)%n+1;   ///return (josephus(n-1, k)+k)%n;  //for 0 based
    }

}algo;


void cppCheck(){
    if( __cplusplus == 201103L ) std::cout << "C++11\n" ;
    else if( __cplusplus == 199711L ) std::cout << "C++98\n" ;
    else std::cout << "pre-standard C++\n" ;
}


/*................................let's do it bitch............................................*/








int main(){


    double n, x, t; read(n, x, t);
    cout<<(int)(t*(ceil(n/x)));

return josh;
}















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

int main(){
  string S, T;
  cin >> S >> T;

  int N=S.size();
  bool ans = true;

  for (int i = 0; i < N; i++) {
    if (S.at(i)!=T.at(i)) {
      ans=false;
      break;
    }
  }

  if (ans) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 3632
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<random>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

#define FOR(i,a,b) for(long long i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define FORR(i,a,b) for(long long i=(a);i>=(b);--i)
#define REPR(i,n)   FORR(i,n,0)

using namespace std;
typedef pair<long long, long long> pll;
typedef long long ll;

ll h,w;
char a[1010][1010];
ll c[1010][1010]={0};

signed main() {
    queue<pll>q;
	cin>>h>>w;
    for(int i=0;i<h;++i){
        cin>>a[i];
        for(int j=0;j<w;++j)c[i][j]=-1;
    }

    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            if(a[i][j]=='#'){
                q.push(pll(i,j));
                c[i][j]=0;
            }
        }
    }
	
    ll dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
    while(!q.empty()){
        ll x=q.front().first,y=q.front().second;
        q.pop();
        for(int i=0;i<4;++i){
            if(x+dx[i]>=0&&x+dx[i]<h&&y+dy[i]>=0&&y+dy[i]<w){
                if(c[x+dx[i]][y+dy[i]]==-1){
                    q.push(pll(x+dx[i],y+dy[i]));
                    c[x+dx[i]][y+dy[i]]=c[x][y]+1;
                }
            }
        }
    }

    ll ans=-1;
    for(int i=0;i<h;++i){
        for(int j=0;j<w;++j){
            ans=max(ans,c[i][j]);
        }
    }
	
    cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 25524
#include<iostream>
#include<math.h>
#define MOD 256
using namespace std;
int main(){
  int n;
  int i,j,k,l;
  int s,a,c,bs,ba,bc;
  int r[16][16][16][260];
  for(s=0;s<16;s++){
    for(a=0;a<16;a++){
      for(c=0;c<16;c++){
	r[s][a][c][0]=s;
	for(i=0;i<260-1;i++){
	  r[s][a][c][i+1]=(a*r[s][a][c][i]+c)%MOD;
	}
      }
    }
  }
  cin >> n;
  while(n!=0){
    int inf = 1 << 5;
    double m=inf,o=0;
    int ma[260]={};
    for(i=0;i<n;i++) cin >> ma[i];
    float co[260]={};
    for(s=0;s<16;s++){
      for(a=0;a<16;a++){
	for(c=0;c<16;c++){
	  o=0;
	  for(i=0;i<260;i++) co[i]=0;
	  for(i=0;i<n;i++){
	    k=(ma[i]+r[s][a][c][i+1])%MOD;
	    co[k]+=1;;
	  }
	  for(i=0;i<260;i++){
	    if(co[i]!=0){
	      
	      o-=(co[i]/n)*log(co[i]/n);
	      //cout << i <<" "<<co[i]<< endl;
	    }
	  }
	  
	  if(m>o){
	    m=o;
	    bs=s;ba=a;bc=c;
	  }
	}
      }
    }
    cout << bs << " " << ba << " " << bc << endl;
    cin >> n;
  }
}

Measured memory_bytes: 5364
#include <bits/stdc++.h>
using namespace std;
// #define int long long
typedef long long ll;
typedef pair<int,int> pii;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);v++)
#define FOR(v,a,n) for(int v=a;v<(int)(n);v++)
#define FORE(x,arr) for(auto &x:arr)
#define REP(v,n) FOR(v,0,n)
#define RREP(v,n) for(int v=(int)(n);v>=0;v--)
#define ALL(c) begin(c),end(c)
const int DX[4]={0,1,0,-1}, DY[4]={-1,0,1,0};
const int INF = 1e9;
const ll INFLL = 1e18;
template<class T,class U>ostream&operator<<(ostream &os,const pair<T,U> &p){
    os<<"("<<p.first<<","<<p.second<<")";return os;}
template<class T>ostream&operator<<(ostream &os,const vector<T> &v){
    ITR(i,v)os<<*i<<(i==end(v)-1?"":" ");return os;}
//------------------------------------------------------------------------------

signed main() {
    int s=0,t=0;
    REP(i,4) {
        int a;
        cin>>a;
        s+=a;
    }
    REP(i,4) {
        int a;
        cin>>a;
        t+=a;
    }
    cout<<max(t,s)<<endl;
    return 0;
}

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

int main() {
    int H, W;
    cin >> H >> W;

    vector<string> a(H);
    string waku = "";

    long sum, avg = 0;
    for(int i = 0 ; i < H ; i++){
        cin >> a.at(i);

    }

    for(int i = 0 ; i < W ; i++)
        waku += "#";

    waku  += "##";

    cout << waku << endl;

    for(int i = 0 ; i < H ; i++){
        cout << '#' << a.at(i) << '#' << endl;
    }

    cout << waku << endl;

}

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

using namespace std;

int main(void)
{
    string S, T;
    getline(cin, S);
    getline(cin, T);

    int counter = 0;
    int countMax = 0;
    int loopnum = S.length() - T.length();

    if (loopnum == 0)
    {
        loopnum = 1;
    }

    for (int i = 0; i < loopnum; ++i)
    {
        counter = 0;
        for (int j = 0; j < T.length(); ++j)
        {

            if (S[i + j] == T[j])
            {
                counter++;
            }
            else
            {
            }
        }
        if (counter > countMax)
        {
            countMax = counter;
        }
    }

    cout << (T.length() - countMax) << "\n";
}


Measured memory_bytes: 3164
s_ = input()
answ = float("inf")
for i in s_:
    s = s_
    ans = 0
    while len(set(s)) != 1:
        a = ""
        for j in range(len(s) - 1):
            if s[j] == i or s[j + 1] == i:
                a += i
            else:
                a += s[j]
        ans += 1
        s = a
    answ = min(answ, ans)
print(answ)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int in() {int x; cin>>x; return x;}
ll lin() {ll x; cin>>x; return x;}
string sin() {string x;cin>>x;return x;}
using graph = vector<vector<int>>;
using graph2 = vector<vector<pair<int, int>>>;

int main(){
    ll x;
    cin>>x;
    ll a=(x-1)/11;
    if((x-1)%11>5){
        cout<<2*a+2<<endl;
    }
    else{
        cout<<2*a+1<<endl;
    }
}

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

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

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

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

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

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

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

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

fn main() {
    input! {
        n: usize,
        d: [i64; n],
    }
    let mut h = std::collections::HashMap::new();
    for i in d.iter() {
        if !h.contains_key(&i) {
            h.insert(i, 1);
        }
    }
    println!("{}", h.len());
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>
using namespace std;
int main() {
    int N, A;
    cin >> N >> A;
    if((N%500)<=A){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3608
#include <iostream>
#include <vector>
#include <unordered_set>
#include <limits>

using namespace std;
typedef long long ll;

int main(){
    ll n, m, p;
    cin >> n >> m >> p;

    vector<vector<pair<int, int>>> to(n);
    vector<vector<int>> from(n);
    for(int i = 0; i < m; ++i){
        int a, b, c;
        cin >> a >> b >> c;
        a--; b--;
        if(a == b && c - p <= 0){ continue; }
        to.at(a).push_back(make_pair(b, c - p));
        from.at(b).push_back(a);
    }

    vector<bool> can_go(n, false);
    can_go.at(n - 1) = true;
    unordered_set<int> cur[2];
    cur[0].insert(n - 1);
    for(int i = 0; i < n; ++i){
        cur[(i + 1) % 2].clear();
        for(int x : cur[i % 2]){
            for(int next : from.at(x)){
                if(!can_go.at(next)){
                    can_go.at(next) = true;
                    cur[(i + 1) % 2].insert(next);
                }
            }
        }
    }

    vector<ll> coins(n, numeric_limits<ll>::min());
    coins.at(0) = 0;
    cur[0].clear();
    cur[0].insert(0);
    int count = 0;
    while(cur[count % 2].size()){
        cur[(count + 1) % 2].clear();
        for(int x : cur[count % 2]){
            for(auto& p : to.at(x)){
                if(coins.at(p.first) < coins.at(x) + p.second
                   && can_go.at(p.first)){
                    cur[(count + 1) % 2].insert(p.first);
                    coins.at(p.first) = coins.at(x) + p.second;
                }
            }
        }
        if(count > m + 1 && cur[(count + 1) % 2].size()){
            cout << -1 << endl;
            return 0;
        }
        count++;
    }
    cout << max(0LL, coins.at(n - 1)) << endl;
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void){
	int sum;
	int max;
	int N,L;

	max=0;
	sum=0;
	scanf("%d",&N);
	for(int i=0; i<N; i++){
		scanf("%d",&L);
		if(max<L){
			sum+=max;
			max=L;
		}else{
			sum+=L;
		}
	}

	if(max<sum){
		printf("Yes\n");
	}else{
		printf("No\n");
	}

}

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


    int main (){
        ll a,b,c,k;
        cin >> a >> b >> c >> k;
        ll ans =0;
        if(k%2==0){
            ans=a-b;
        }
        else{
            ans=b-a;
        }
       
        cout << ans << endl;
        return 0;
    }

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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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

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



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,t; cin>>n>>t;
  vll a(n);
  rep(i,n) cin>>a[i];
  map<ll,ll> m;
  ll l=0;
  while(l<n){
    ll r=l;
    while(r<n and a[l]<=a[r]){
      ll d=a[r]-a[l];
      // cout<<a[r]<<' '<<a[l]<<endl;
      m[d]++;
      r++;
    }
    if(r==l) r++;
    l=r;
  }
  ll maxd=0;
  ll ans=0;
  for(auto e: m){
    // cout<<e.first<<" "<<e.second<<endl;
    if(chmax(maxd,e.first)) ans=e.second;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 7296
#include <iostream>

using namespace std;

int main()
{
    int n,m,a[201][201],c[11][11];

    cin>>n>>m;

    for(int i = 0 ; i < 10 ; i++)
        for(int j = 0 ; j < 10 ; j++)
            cin>>c[i][j];

    for (int k = 0; k < 10; ++k)
        for (int i = 0; i < 10; ++i)
            for (int j = 0; j < 10; ++j)
                if (c[i][k] + c[k][j] < c[i][j])
                    c[i][j] = c[i][k] + c[k][j];

    int s=0;

    for(int i = 0 ; i < n ; i++)
        for(int j = 0 ; j < m ; j++){
            cin>>a[i][j];
            if(a[i][j]!=-1)
                s+=c[a[i][j]][1];
        }

    cout<<s;
}


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

int main(){
  int k;
  string s;
  cin >> k >> s;
  if(s.size() <= k) cout << s << endl;
  else{
    rep(i,k) cout << s.at(i);
    cout << "..." << endl;
  }
}


Measured memory_bytes: 3632
/*
	Created by Rahul Goel.
*/

#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1000000007;
const int INF = 1000000000;

#define pii pair < int, int >
#define vi vector < int >
#define vvi vector < vector < int > >
#define vpii vector < pair < int, int > >
#define vvpii vector < vector < pair < int, int > > >
#define pb push_back
#define f first
#define s second
#define mp make_pair

int main()
{
	int mat[3][3];
	for(int i=0; i<3; i++)
		for(int j=0; j<3; j++)
			cin >> mat[i][j];
	int n;
	cin >> n;
	while(n--){
		int num;
		cin >> num;

		for(int i=0; i<3; i++)
			for(int j=0; j<3; j++)
				if(mat[i][j] ==  num)
					mat[i][j] = 0;
	}

	int flag = false;

	if((mat[0][0] || mat[0][1] || mat[0][2]) == 0)
		flag = true;
	if((mat[1][0] || mat[1][1] || mat[1][2]) == 0)
		flag = true;
	if((mat[2][0] || mat[2][1] || mat[2][2]) == 0)
		flag = true;
	if((mat[0][0] || mat[1][0] || mat[2][0]) == 0)
		flag = true;
	if((mat[0][1] || mat[1][1] || mat[2][1]) == 0)
		flag = true;
	if((mat[0][2] || mat[1][2] || mat[2][2]) == 0)
		flag = true;
	if((mat[0][0] || mat[1][1] || mat[2][2]) == 0)
		flag = true;
	if((mat[0][2] || mat[1][1] || mat[2][0]) == 0)
		flag = true;

	if(flag)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
import Data.List

main = do
    n <- readLn
    let xs = sort . map snd $ factorize n
    let as = scanl1 (+) [1..]
    print $ solve 0 0 as xs

solve k _ _ [] = k
solve k l (a:as) (x:xs) | x < a = solve (k+l) l (a:as) xs
                        | otherwise = solve k (l+1) as (x:xs)

primes :: Integral a => [a]
primes = map fromIntegral primes'
  where
    primes' = [2, 3, 5] ++ f 5 7 (drop 2 primes')
    f m s (p:ps) = [n | n <- ns, gcd m n == 1] ++ f (m * p) (p * p) ps
      where
        ns = [x + y | x <- [s,s + 6 .. p * p - 2], y <- [0, 4]]

isPrime :: Integral a => a -> Bool
isPrime n = (n > 1) && isPrime' primes
  where
    isPrime' (x:xs)
      | x * x > n = True
      | rem n x == 0 = False
      | otherwise = isPrime' xs

factorize :: Integral a => a -> [(a, Int)]
factorize 1 = [(1, 0)]
factorize n = format $ factorize' n primes
  where
    format ps = [(x, length xs) | xs@(x:_) <- group ps]
    factorize' n ps@(p:ps')
      | p * p > n = [n]
      | rem n p == 0 = p : factorize' (div n p) ps
      | otherwise = factorize' n ps'

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

static const int N = 1000;

int lcs(string X, string Y){
  int c[N+1][N+1];
  int m = X.size(), n = Y.size();
  int maxl = 0;
  X = " " + X;
  Y = " " + Y;
  for(int i=1; i<=m; i++) c[i][0] = 0;
  for(int j=1; j<=n; j++) c[0][j] = 0;

  for(int i=1; i<=m; i++){
    for(int j=1; j<=n; j++){
      if(X[i] == Y[j]){
        c[i][j] = c[i-1][j-1] + 1;
      } else {
        c[i][j] = max(c[i-1][j] , c[i][j-1]);
      }
      maxl = max(maxl, c[i][j]);
    }
  }
  return maxl;
}


int main(){
    ios::sync_with_stdio(false);
    string s1, s2;
    int n;
    cin >> n;
    for(int i=0; i<n; i++){
      cin >> s1 >> s2;
      cout << lcs(s1, s2) << endl;
    }
}

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

int parent(int a[],int x){
    if(a[x]==x) return x;
    else return a[x]=parent(a,a[x]);
}

void unite(int x,int y,int a[]){
    int dx=parent(a,x);
    int dy=parent(a,y);
    if(dx!=dy)
    a[dx]=dy;
}

int main(){
   ll n,m;
   cin>>n>>m;
   int a[n+1];
   for(int i=1;i<n+1;i++)
   a[i]=i;
   while(m--){
     ll u,v;
     cin>>u>>v;
     unite(u,v,a);
   }
   unordered_map<int,int>mp;
   for(int i=1;i<=n;i++){
       //cout<<parent(a,i)<<" ";
       mp[parent(a,i)]++;
   }
   int maxi=INT_MIN;
   for(auto i:mp)
    maxi=max(maxi,i.second);
    cout<<maxi;
   return 0;
}


Measured memory_bytes: 12240
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  LL H, W; cin >> H >> W;
  if (H == 1 || W == 1) {
    cout << 1 << endl;
    return 0;
  }
  LL S = H * W + 1LL;
  cout << S / 2LL << endl;
}


Measured memory_bytes: 256
a = []

for i in range(3):
    a.append(list(map(int, input().split())))

sa1 = a[0][0] - a[1][0]
sa2 = a[0][0] - a[2][0]

if sum(a[0]) == sum(a[1]) + 3 * sa1 == sum(a[2]) + 3 * sa2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a*b>c){
    cout<<c<<"\n";
  }
  if(a*b<=c){
    cout<<a*b<<"\n";
  }
  return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define int long long
#define endl '\n'
#define MOD 1000000007

int digit(int n){
    int dig = 0;
    while(n > 0){
        dig++;
        n /= 10;
    }
    return dig;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;

    int odd = 0;
    for (int i = 1; i <= n; i++)
        if (digit(i) & 1)
            odd++;
    cout << odd << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ff first               // For pairs
#define ss second              // For pairs
#define sz(a) int((a).size())  // Function to determine size of any container
#define pb push_back           // Pushback to vector
#define mp make_pair           // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end()
#define tr(container, it) for (auto it = container.begin(); it != container.end(); it++)  //traversing macro
#define lp(it, it1, it2) for (auto it = it1; it < it2; it++)                              //loop
#define present(c, x) (c.find(x) != c.end())
using namespace std;
using namespace std::chrono;
typedef vector<ll> vi;            // Vector of long long
typedef vector<vi> vvi;           // Vector of vi
typedef vector<pair<ll, ll>> ii;  // Vector of pairs
typedef vector<ii> vii;           // Vector of ii
int main() {
    string s, t, ans = "";
    cin >> s >> t;
    ll l1 = s.length(), l2 = t.length();
    vvi dp(l1 + 1, vi(l2 + 1));
    for (int i = 1; i <= l1; i++) {
        for (int j = 1; j <= l2; j++) {
            if (s[i - 1] == t[j - 1]) {
                dp[i][j] = dp[i - 1][j - 1] + 1;
            } else
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
        }
    }
    ll i = l1, j = l2;
    while (dp[i][j]) {
        if (s[i - 1] == t[j - 1]) {
            ans += s[i - 1];
            i = i - 1;
            j = j - 1;
        } else if (dp[i - 1][j] > dp[i][j - 1])
            i = i - 1;
        else
            j = j - 1;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 70784
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
    ll n,m,x,y,cnt=0;
    cin>>n>>m;
    for(ll i=0;i<n;i++)
    {
        cin>>x>>y;
        if(x*x+y*y<=m*m)
            cnt++;
    }
    cout<<cnt;
    return 0;
}


Measured memory_bytes: 3680
fun main(args: Array<String>) {
    println(readInt().pow(2))
}

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

fun Int.pow(n:Int) = Math.pow(this.toDouble(), n.toDouble()).toInt()

Measured memory_bytes: 31400
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <utility>

using namespace std;

int main(const int argc, const char **argv){
  string input;
  cin >> input;

  for(char c: input){
    if(c == '1'){
      cout << 9;
    }else if(c == '9'){
      cout << 1;
    }else{
      cout << c;
    }
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;

//定数
//円周率
const double pi = 3.141592653589793238462643383279;
//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 100000000000000000; // = 10^17
//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";
//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7
//前処理テーブルの大きさ指定
const int MAX = 1200000; // = 10^6 + 2*(10^5)
//ちなみに、1024MBで持てる最大長の配列は10^8程度

//データ構造
//隣接リスト用構造体（有向グラフ向け）
struct edge {
  ll to; // E.toでその辺の終点へアクセスできる。
  ll cost; // e.costでその辺の重みにアクセスできる。
};
//Union_Find木
struct UnionFind {
  vector<int> UF; // UF.at(i) : iの親の番号
  vector<int> SIZE; // SIZE.at(root(i)) : iと連結されてる要素の数
  UnionFind(int N) : UF(N), SIZE(N, 1) { // 最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) {
      UF.at(i) = i;
    }
  }
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (UF.at(x) == x) {
      return x;
    }
    return UF.at(x) = root(UF.at(x));
  }
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); // xの根をrx
    int ry = root(y); // yの根をry
    if (rx == ry) {
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    }
    // xとyの根が同じでない(=同じ木にない)時：小さい方の根を大きい方の根につける。
    if (SIZE.at(rx) < SIZE.at(ry)) {
      UF.at(rx) = ry;
      SIZE.at(ry) += SIZE.at(rx);
      SIZE.at(rx) = 0;
    }
    else {
      UF.at(ry) = rx;
      SIZE.at(rx) += SIZE.at(ry);
      SIZE.at(ry) = 0;
    }
  }
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す。
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { // xと連結されてる要素の数を返す。
    return SIZE.at(root(x));
  }
};

//関数 (計算量)
//ctoi (O(1))
int ctoi(char c){
  if (c == '0') return 0;
  if (c == '1') return 1;
  if (c == '2') return 2;
  if (c == '3') return 3;
  if (c == '4') return 4;
  if (c == '5') return 5; 
  if (c == '6') return 6;
  if (c == '7') return 7;
  if (c == '8') return 8;
  if (c == '9') return 9;
  return -1;  
}
//to_char (O(1))
char to_char(int i){
  if (i == 0) return '0';
  if (i == 1) return '1';
  if (i == 2) return '2';
  if (i == 3) return '3';
  if (i == 4) return '4';
  if (i == 5) return '5';
  if (i == 6) return '6';
  if (i == 7) return '7';
  if (i == 8) return '8'; 
  if (i == 9) return '9';
  return ' ';  
}

//メイン処理
int main() {
  cout << fixed << setprecision(16); //精度向上
  //ここまでテンプレ
  int N;
  cin >> N;
  int C = 0;
  bool ok = false;
  for (int i = 0; i < N; i++) {
    int A, B;
    cin >> A >> B;
    if (A == B) {
      C++;
    }
    else {
      C = 0;
    }
    if (C == 3) {
      ok = true;
    }
  }
  if (ok) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}
  
  
  
  
  
  
  

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

    vector<int> ans(n+1);
    for(int x = 1; x*x <= n; x++){
        for(int y = 1; y*y <= n; y++){
            for(int z = 1; z*z<=n; z++){
                ll sum = x*x + y*y + z*z + x*y + y*z + z*x;
                if (sum <= n) ans[sum]++;
            }
        }
    }

    for(int i = 1; i <= n; i++){
        cout << ans[i] << endl;
    }

    return 0;
}

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

struct Node {
  int key;
  Node *parent, *left, *right;
};

Node *NIL, *root;

void insert(int key) {
  Node *x, *y, *z;

  z = new Node;
  z->key = key;
  z->left = NIL;
  z->right = NIL;
  y = NIL;
  x = root;

  while (x != NIL) {
    y = x;
    if (z->key < y->key) x = x->left;
    else x = x->right;
  }

  z->parent = y;
  if (y == NIL) root = z;
  else if (z->key < y->key) y->left = z;
  else y->right = z;
}

Node* find(Node *node, int key) {
  while (node != NIL && node->key != key) {
    if (key < node->key) node = node->left;
    else node = node->right;  
  }
  return node;
}

void del(Node *z) {
  Node *y;  // 実際に削除されるノード
  Node *x;  // yの子

  // y, z を決める
  if (z->left != NIL && z->right != NIL) {
    y = z->right;
    while (y->left != NIL) {
      y = y->left;
    }
    x = y->right;
  } else {
    y = z;
    if (z->left == NIL) x = y->right;
    else x = y->left;
  }

  // pointer つなぎ替え

  if (x != NIL) x->parent = y->parent;

  if (y->parent == NIL) root = x;
  else if (y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if (y != z) z->key = y->key;    
    
  delete y;
}

void inorder(Node *node) {
  if (node == NIL) return;
  inorder(node->left);
  cout << " " << node->key;
  inorder(node->right);
}

void preorder(Node *node) {
  if (node == NIL) return;
  cout << " " << node->key;
  preorder(node->left);
  preorder(node->right);
}

void print() {
  inorder(root);
  cout << endl;
  preorder(root);
  cout << endl;
}

int main() {
  int i, m, key;
  string command;

  cin >> m;
  for (i = 0; i < m; i++) {
    cin >> command;
    if (command[0] == 'i') {
      cin >> key;
      insert(key);
    } else if (command[0] == 'f') {
      cin >> key;
      if (find(root, key) != NIL) cout << "yes" << endl;
      else cout << "no" << endl;
    } else if (command[0] == 'd') {
      cin >> key;
      Node *z = find(root, key);
      if (z != NIL) del(z);
      else cout << "not found." << endl;
    } else {
      print();
    }
  }      

  return 0;
}



Measured memory_bytes: 21892
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define REP(i,n)    for(int i = 0; i < (int)n; i++)
#define MAX_N   100000
typedef long long ll;

void solve(){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    int ans = 301;
    REP(i,3)
        for(int j = i + 1; j < 3; j++)
        ans = min(a[i] + a[j], ans);
    cout << ans << endl;
}

int main(){
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>


int main(void){
  long long int N, W;
  std::cin >> N >> W;
  std::vector<long long> w;
  std::vector<long long> v;
  for(size_t i=0;i<N;i++){
    long long wtmp, vtmp;
    std::cin >> wtmp >> vtmp;
    w.push_back(wtmp);
    v.push_back(vtmp);
  }
  std::vector<std::vector<long long>> result;
  std::vector<long long> a(W+1, 0);
  result.push_back(a);
  for(size_t i=0;i<N;i++){
    int j=0;
    std::vector<long long> target = result[i];
    while(j+w[i]<=W){
      target[j+w[i]]= std::max(result[i][j]+v[i], target[j+w[i]] );
      j++;
    }
    result.push_back(target);
  }
  std::cout << result[N][W];
}


Measured memory_bytes: 80752
#include <cstdio>
#include <string>
#include <set>

using namespace std;

int n, x;
int a[100010];
int d[100010];

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

int main()
{
	scanf("%d%d", &n, &x);
	
	for (int i = 0 ; i < n ; i++)
	{
		scanf("%d", &(a[i]));
		if (a[i] > x)
			d[i] = a[i] - x;
		else
			d[i] = x - a[i];
	}
	
	int gd = d[0];
	for (int i = 1 ; i < n ; i++)
	{
		if (gd >= d[i])
			gd = gcd(gd, d[i]);
		else
			gd = gcd(d[i], gd);
	}
	
	printf("%d\n", gd);
		
	return 0;
}

Measured memory_bytes: 896