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

char logic(char a, char b){
	if (a == 'H'){
		if(b == 'H'){
			return 'H';
		}else if(b == 'D'){
			return 'D';
		}
	}else if(a == 'D'){
		if(b == 'D'){
			return 'H';
		}else if(b == 'H'){
			return 'D';
		}
	}
}

int main(){
	char d, h;
	
	scanf("%c %c", &d, &h); fflush(stdin);	
	
	printf("%c", logic(d, h));
	
	return 0;
}

Measured memory_bytes: 128
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
import kotlin.math.*
import kotlin.system.exitProcess

@JvmField val INPUT = System.`in`
@JvmField val OUTPUT = System.out

const val _BUFFER_SIZE = 1 shl 16
@JvmField val _buffer = ByteArray(_BUFFER_SIZE)
@JvmField var _bufferPt = 0
@JvmField var _bytesRead = 0

tailrec fun readChar(): Char {
    if(_bufferPt == _bytesRead) {
        _bufferPt = 0
        _bytesRead = INPUT.read(_buffer, 0, _BUFFER_SIZE)
    }
    return if(_bytesRead < 0) Char.MIN_VALUE
    else {
        val c = _buffer[_bufferPt++].toChar()
        if (c == '\r') readChar()
        else c
    }
}

fun readLine(): String? {
    var c = readChar()
    return if(c == Char.MIN_VALUE) null
    else buildString {
        while(true) {
            when(c) {
                '\n', Char.MIN_VALUE -> return@buildString
                else -> {
                    append(c)
                    c = readChar()
                }
            }
        }
    }
}
fun readLn() = readLine()!!

fun read() = buildString {
    var c = readChar()
    while(c <= ' ') {
        if(c == Char.MIN_VALUE) return@buildString
        c = readChar()
    }
    do {
        append(c)
        c = readChar()
    } while(c > ' ')
}
fun readInt() = read().toInt()
fun readDouble() = read().toDouble()
fun readLong() = read().toLong()
fun readStrings(n: Int) = List(n) { read() }
fun readLines(n: Int) = List(n) { readLn() }
fun readInts(n: Int) = List(n) { read().toInt() }
fun readIntArray(n: Int) = IntArray(n) { read().toInt() }
fun readDoubles(n: Int) = List(n) { read().toDouble() }
fun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }
fun readLongs(n: Int) = List(n) { read().toLong() }
fun readLongArray(n: Int) = LongArray(n) { read().toLong() }


fun main() {
    val x = readInt()
    if (x >= 30) {
        println("Yes")
    } else {
        println("No")
    }
}

Measured memory_bytes: 33976
a,b=map(int,input().split())
s=input()
if len(s) != a+b+1:
    print('No')
    exit()
else:
    if s[a] != '-':
        print('No')
        exit()
    elif s.count('-')!=1:
        print('No')
        exit()
print('Yes')
        
            

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int num = (c - 1) / b + 1;
  if (a > (num - 1) * d)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
typedef long long       ll;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define PI                acos(-1)
#define pb                push_back
#define mp                make_pair
#define all(a)            (a).begin(), (a).end()
#define clr(a,h)          memset(a, (h), sizeof(a))
#define F first
#define S second
#define f first
#define s second
#define fore(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
#define forr(i,b,e)		  for(int i=(int)b;i<(int)e;++i)
int faster_in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -faster_in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

using namespace std;
//using namespace __gnu_pbds;

typedef pair<int, int>  ii;
typedef vector<int>     vi;
typedef vector<ii>      vii;
typedef vector<ll>      vll;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
const int INF = int(1e9 + 7);

int main()
{
    std::ios::sync_with_stdio(false); cin.tie(0);
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    int n;
    cin >> n;
    set<int> s;
    fore(i, 0, n)
    {
    	int x;
    	cin >> x;
    	s.insert(x);
    }
    if (s.size() == n)
    {
    	cout << "YES" << '\n';
    }
    else
    	cout << "NO" << '\n';
    return 0;
}
// PLUS ULTRA!

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

double pi = acos(-1);

int main(){
  double a, b, x;
  cin >> a >> b >> x;

  auto ok = [&](double m) {
    if (a * tan(m) < b) {
      double s = a * b - tan(m) * a * a / 2;
      return s * a <=  x;
    } else {
      double s = b / tan(m) * b / 2;
      return s * a <= x;
    }
  };
  double l = 0; double r = pi / 2;

  rep(i,10000) {
    double m = (l + r) / 2;
    if (ok(m)) r = m;
    else l = m;
  }
  printf("%.12f\n",r * 180 / pi); 
  return 0;
} 

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>

using namespace std;

#define rep(i, n) for (size_t i = 0; i < (n); i++)

int main() {
  size_t N;
  scanf("%ld", &N);
  int ps[N], qs[N];
  rep(i, N) scanf("%d", &ps[i]);
  rep(i, N) scanf("%d", &qs[i]);
  auto diff = [=](int *ps, int *qs) {
    size_t c = 0;
    while (lexicographical_compare(ps, ps + N, qs, qs + N)) {
      next_permutation(ps, ps + N);
      c++;
    }
    return c;
  };
  printf("%ld\n", lexicographical_compare(ps, ps + N, qs, qs + N) ? diff(ps, qs) : diff(qs, ps));
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
using namespace std;
typedef long long ll;
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 main() {
	string s;
	cin >> s;
	int a = s[0];
	int b = s[1];
	int c = s[2];
	int d = s[3];
	int front = (a-'0') * 10 + (b-'0');
	int back = (c-'0')* 10 + (d-'0');
	if (front <= 12 && 1 <= front && 1 <= back && back <= 12)puts("AMBIGUOUS");
	else if (1 <= front && front <= 12 && back == 0)puts("MMYY");
	else if (1 <= front && front <= 12 && back > 12)puts("MMYY");
	else if (1 <= back && back <= 12 && front == 0)puts("YYMM");
	else if (1 <= back && back <= 12 && front > 12)puts("YYMM");
	else puts("NA");
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int A, B, C, D;
  cin >> A;
  cin >> B;
  cin >> C;
  cin >> D;

  if(A * B >= C * D)
    cout << A*B;
  else if(A*B < C*D)
    cout << C*D;

  return 0;
}

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

int a[1000];

int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	for (int i = 0; i < n; ++i)
	{
		if (a[i] % 2 == 0)
		{
			if (!(a[i] % 3 == 0 || a[i]% 5 == 0))
			{
				cout << "DENIED";
				return 0;
			}
		}
	}
	cout << "APPROVED";
	return 0;
}

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

using namespace std;

//YUIOPHJKLNM
bool isLeft(char c){
	string list = "yuiophjklnm";
	//stringのsize()はO(1)、char配列のstrlen(str)はO(n)
	for(int i=0;i<list.size();i++){
		if(list[i] == c){
			return true;
		}
	}
	return false;
}

int main(){
	while(true){
		string str;
		cin >> str;
		if(str == "#"){
			break;
		}
		int cnt = 0;//手の入れ替わる回数
		bool prev = isLeft(str[0]);//前のキーが左手だったらtrue
		for(int i=0;i<str.size();i++){//1から始めてもよい
			bool now = isLeft(str[i]);
			if(prev != now){
				cnt ++;
			}
			prev = now;
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1192
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<cmath>
using namespace std;
struct point
{
	double x, y;
}pos[105];
bool cmp(point a, point b)
{
	if (atan2(a.y, a.x) != atan2(b.y, b.x))
		return atan2(a.y, a.x) < atan2(b.y, b.x);
	else return a.x < b.x;
}
int main()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> pos[i].x >> pos[i].y;
	sort(pos, pos + n, cmp);
	long long ans = 0;
	for (int i = 0; i < n; i++)
	{
		long long x = 0, y = 0;
		for (int j = 0; j < n; j++)	//注意可能构成环的情况
		{
			x += pos[(i + j) % n].x, y += pos[(i + j) % n].y;
			ans = max(ans, x * x + y * y);
		}
	}
	cout << fixed << setprecision(20) << sqrt(ans) << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

int a[maxn],b[maxn];

int main()
{
	int n=read();
	for(int i=1;i<=n;i++) a[i]=read(),b[i]=a[i]-i;
	sort(b+1,b+n+1);
	ll p=b[(n+1)/2],ans=0;
	for(int i=1;i<=n;i++) ans+=abs(p-b[i]);
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}
struct Edge {
    ll to, cap, rev;
};

vector< vector<Edge> > G;

void add_edge(ll from, ll to, ll cap) {
    G[from].pb({to, cap, (ll)G[to].size()});
    G[to].pb({from, 0, (ll)G[from].size()-1});
}

ll dfs(ll v, ll t, ll f, vector<bool>& used) {
    if (v == t) return f;
    if (used[v]) return 0;
    used[v] = true;
    EACH(e, G[v]) {
        if (e.cap > 0) {
            ll d = dfs(e.to, t, min(f, e.cap), used);
            if (d > 0) {
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

ll max_flow(ll s, ll t) {
    ll res = 0;
    while (1) {
        vector<bool> used(G.size(), false);
        ll f = dfs(s, t, inf, used);
        if (f == 0) break;
        res += f;
    }
    return res;
}

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

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int m, n;
    while (cin >> m >> n, m || n) {
        vector<int> b(m), r(n); cin >> b >> r;
        vector<int> bid(m), rid(n);
        REP(i, m) bid[i] = i;
        REP(i, n) rid[i] = m+i;
        int s = m+n, t = s+1;
        G.clear();
        G.resize(t+1);
        REP(i, m) REP(j, n) {
            if ( gcd(b[i], r[j]) > 1 ) {
                add_edge(bid[i], rid[j], 1);
            }
        }
        REP(i, m) add_edge(s, bid[i], 1);
        REP(i, n) add_edge(rid[i], t, 1);
        cout << max_flow(s, t) << endl;
    }
}

Measured memory_bytes: 11260
//Relive your past life.
//Face your demons.
//The past is never dead,it is not even past.
//The memories are not only the key to the past but...also to the future.
//coded in Rusty Lake
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define ll   long long
#define pb   push_back
#define mp   make_pair
#define orz  1000000007
using namespace std;
int n,k,a[100005],m;
int main(){
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;++i)scanf("%d",a+i);
    for(int i=1;i<n;++i)if(a[i]+a[i+1]>=k)m=i;
    if(!m){
        puts("Impossible");
        return 0;
    }
    printf("Possible\n");
    for(int i=1;i<m;++i)printf("%d\n",i);
    for(int i=n-1;i>m;--i)printf("%d\n",i);
    printf("%d\n",m);
    //system("pause");
    return 0;
}


Measured memory_bytes: 1152
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include<bitset>
#include <iomanip>

using namespace std;
#define modd 1000000007


typedef pair<long long, long long> pl;



#define ll long long




/*
class UnionFind {
public:
	vector <ll> par;
	vector <ll> siz;
	vector <ll> gr;

	// Constructor
	UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) ,gr(sz_){
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
		for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
	}

	// Member Function
	// Find
	ll root(ll x) { // 根の検索
		while (par[x] != x) {
			x = par[x] = par[par[x]]; // x の親の親を x の親とする
		}
		return x;
	}

	// Union(Unite, Merge)
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;

		// merge technique（データ構造をマージするテク．小を大にくっつける）
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}



	bool issame(ll x, ll y) { // 連結判定
		return root(x) == root(y);
	}

	ll size(ll x) { // 素集合のサイズ
		return siz[root(x)];
	}


};*/


long long N, M, K, a, b, c, d, e, H, W, L;
ll A[200005] = {};
ll B[200005] = {};
ll C[200005] = {};
bool f, ff;
string S[2];
set <long long>sll;
pl bufpl;
vector <long long>vl[3];
vector <pl>vpl;
vector <string> vs;
set<ll> llset;

/*struct ST
{
	long long Kati;
	int bangou;

	bool operator<(const ST& another) const
	{
		return Kati < another.Kati;//比較
	};

};



vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/


long long modinv(long long aa, long long mm) {
	long long bb = mm, uu = 1, vv = 0;
	while (bb) {
		long long tt = aa / bb;
		aa -= tt * bb; swap(aa, bb);
		uu -= tt * vv; swap(uu, vv);
	}
	uu %= mm;
	if (uu < 0) uu += mm;
	return uu;
}



ll minn, maxx;
double ansa;
bool fl[4];


int main() {

	cin >>N>> a>>b;
	d = abs(N - a);
	e = abs(N - b);

	if (d < e) {
		cout << 'A' << endl;
	}
	else {
		cout << 'B' << endl;
	}
	return 0;

}


Measured memory_bytes: 256
import Control.Monad
import Data.Maybe
import Data.Char
import Data.List (unfoldr)
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS

tuplify2 (x:y:_) = (x,y)
tuplify2 _ = undefined

--Input functions with ByteString
readInt = fst . fromJust . BS.readInt
readIntTuple = tuplify2 . map readInt . BS.words
readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine
getIntN n = map readInt <$> replicateM (fromIntegral n) BS.getLine
getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine
getIntMatrix = map readIntList . BS.lines <$> BS.getContents
getIntTuple = readIntTuple <$> BS.getLine
getIntNTuples n = map readIntTuple <$> replicateM (fromIntegral n) BS.getLine
getIntTuples = map readIntTuple . BS.lines <$> BS.getContents


main = do
  [x,y] <- getIntList

  -- 最初: しない 最後: しない
  let d1 = y - x
  -- 最初: する 最後: しない
  let d2 = y + x + 1
  -- 最初: しない 最後: する
  let d3 = - y - x + 1
  -- 最初: する 最後: する
  let d4 = - y + x + 2
  print $ minimum $ filter (\n -> n > 0) [d1,d2,d3,d4]

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

def main():
    f = 0
    p = s[0]
    for ss in range(1, n):
        if s[ss] <= p:
            f += p - s[ss]
        else:
            p = s[ss]
    
    print(f)
    return
main()



Measured memory_bytes: 32244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;else return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N , H;
	cin >> N >> H;
	vector<ll> A,B;
	FOR(i,0,N){
		ll a,b;
		cin >> a >> b;
		A.push_back(a);
		B.push_back(b);
	}
	ll ans = 0;
	SORT(A);SORT(B);
	REV(A);REV(B);
	FOR(i,0,N){
		if(A[0]<B[i]){
			H -= B[i];
			ans++;
		}else{
			break;
		}
		if(H<=0)break;
	}
	if(H<=0){
		cout << ans << endl;
	}else{
		ans += (H+A[0]-1)/A[0];
		cout << ans << endl;
	}
}


Measured memory_bytes: 2036
//In The Name Of Allah
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define double long double 
#define fi first
#define se second
#define pii pair<int, int>
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")

const int mod = 1e9 + 7, N = 1e6 + 1000;
int type[N];
signed main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  int a[n], b[m];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    type[a[i]] = 1;
  }
  for (int i = 0; i < m; i++) {
    cin >> b[i];
    type[b[i]] += 2;
  }
  sort(a, a + n);
  sort(b, b + m);
  for (int i = 1; i < n; i++) {
    if (a[i] == a[i - 1]) {
      cout << "0\n";
      return 0;
    }
  }
  for (int i = 1; i < m; i++) {
    if (b[i] == b[i - 1]) {
      cout << "0\n";
      return 0;
    }
  }
  int ans = 1;
  for (int i = 1; i <= n * m; i++) {
    if (type[i] == 0) {
      ans *= (m - (upper_bound(b, b + m, i) - b)) * (n - (upper_bound(a, a + n, i) - a)) - (n * m - i);
    } else if (type[i] == 1) {
      ans *= (m - (upper_bound(b, b + m, i) - b));
    } else if (type[i] == 2) {
      ans *= (n - (upper_bound(a, a + n, i) - a));
    }
    ans = max(ans, 0ll);
    ans %= mod;
  }
  cout << ans << "\n";
}



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

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(a) a.begin(), a.end()
#define ll long long
#define mod 1e9+7

using namespace std;

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

  if (
    (a + b) ==  c
    || (b + c) ==  a
    || (c + a) ==  b
  ) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,x,n) for(int i=(x);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define int long long
using namespace std;
const int MOD=1e9+7;
const int INF=1e10;

signed main(){
  int n;
  cin>>n;
  char mp[500][500];
  rep(i,n)rep(j,n)cin>>mp[i][j];

  int ans=0;

  rep(B,n){
    bool flag=true;
    rep(i,n){
      rep(j,n){
        if(mp[i][(j+B)%n]!=mp[j][(i+B)%n])flag=false;
      }
      if(!flag)break;
    }
    if(flag)ans++;
  }
  cout<<ans*n<<endl;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	string S;
	scan(S);
	int N=S.size();
	ll MOD=1e+9+7;
	ll toori[11][11][11][13]={};
	vll stock[13];
	rep(i,1000){
		int c=i%10,b=i/10%10,a=i/100;
		toori[a][b][c][i%13]++;
		toori[10][b][c][i%13]++;
		toori[a][10][c][i%13]++;
		toori[a][b][10][i%13]++;
		toori[10][10][c][i%13]++;
		toori[10][b][10][i%13]++;
		toori[a][10][10][i%13]++;
		toori[10][10][10][i%13]++;
	}
	int count=0;
	for(int i=N-1;i>=0;i-=3,count++){
		int a,b,c;
		if(S[i]=='?') c=10;
		else c=(S[i]-'0');
		if(i-1<0) b=0;
		else if(S[i-1]=='?') b=10;
		else b=(S[i-1]-'0');
		if(i-2<0) a=0;
		else if(S[i-2]=='?') a=10;
		else a=(S[i-2]-'0');
		rep(j,13){
			if(count%2==0) stock[j].push_back(toori[a][b][c][j]);
			else stock[j].push_back(toori[a][b][c][(13-j)%13]);
		}
	}
	int M=stock[0].size();
	ll dp[13]={},newdp[13]={};
	dp[0]=1;
	/*rep(j,13){
		printf("%lld ",toori[7][10][4][j]);
	}
	kaigyo;
	rep(i,M){
		printf("i:%d   ",i);
		rep(k,13){
			printf("%lld ",stock[k][i]);
		}
		kaigyo;
	}*/
	rep(i,M){
		rep(j,13){
			rep(k,13){
				newdp[(j+k)%13]+=(dp[j]*stock[k][i])%MOD;
				newdp[(j+k)%13]%=MOD;
			}
		}
		rep(j,13) dp[j]=newdp[j],newdp[j]=0;
	}
	/*ll sum=0;
	rep(j,13){
		printf("%lld ",dp[j]);
		sum+=dp[j];
	}
	kaigyo;
	prin(sum);*/
	prin(dp[5]);
	return 0;
}


Measured memory_bytes: 4580
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
using ll = long long;
const ll INF = 1e9 + 7;

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

	ll ans = INF;
	SORT(h);
	rep(i, 0, n - k + 1) {
		ll mn = h[i], mx = h[i + k - 1];
		ans = min(ans, mx - mn);
	}

	cout << ans << endl;

	return 0;
}


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

int main()
{
    int a, b, k;
    cin >> k >> a >> b;
    if (k == 1)
    {
        cout << "OK";
    }
    else
    {
        if (a % k == 0)
        {
            k = a;
        }
        else
        {
            k = a - a % k + k;
        }
        if (b >= k && a <= k)

        {
            cout << "OK";
        }
        else
        {
            cout << "NG";
        }
    }
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>

using namespace std;

const int MaxN = 1e5 + 5;

struct Point
{
	int value, id;

	Point(int value, int id)
		:value(value), id(id)
	{
	}

	friend bool operator < (const Point &a, const Point &b)
	{
		return a.value < b.value;
	}
};

struct Edge
{
	int u, v, w;

	Edge(int u, int v, int w)
		:u(u), v(v), w(w)
	{
	}

	friend bool operator < (const Edge &a, const Edge &b)
	{
		return a.w < b.w;
	}
};

vector<Point> Xi, Yi;
vector<Edge> edges;
int N, fa[MaxN];

int find(int x)
{
	return x == fa[x] ? x : fa[x] = find(fa[x]);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin >> N;
	for (int i = 1; i <= N; i++)
	{
		int x, y;
		cin >> x >> y;
		Xi.emplace_back(Point(x, i));
		Yi.emplace_back(Point(y, i));
	}
	sort(Xi.begin(), Xi.end());
	sort(Yi.begin(), Yi.end());
	for (int i = 0; i < N - 1; i++)
	{
		edges.emplace_back(Edge(Xi[i].id, Xi[i + 1].id, Xi[i + 1].value - Xi[i].value));
		edges.emplace_back(Edge(Yi[i].id, Yi[i + 1].id, Yi[i + 1].value - Yi[i].value));
	}
	sort(edges.begin(), edges.end());
	for (int i = 1; i <= N; i++)
		fa[i] = i;
	int cnt = 0;
	long long ans = 0;
	for (auto e : edges)
	{
		int fx = find(e.u), fy = find(e.v);
		if (fx != fy)
		{
			fa[fy] = fx;
			cnt++;
			ans += e.w;
			if (cnt == N - 1)
				break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 7144
#include <iostream>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <string.h>

using namespace std;

// NG

int N, M;
int a[200000];
long b[200000];

int main(int argc, char** argv) {
    cin >> N >> M;
    for (int i=1;i<=N;i++) cin >> a[i];

    for (int i=1;i<=N;i++) b[i] = (a[i] + b[i - 1]) % M;

    map<long, long> m;
    long ans = 0;
    for (int i=1;i<=N+1;i++) {
        ans += m[b[i]];
        m[b[i]] += 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    int n;
    cin >> n;
    double pi = 3.14159265358979;
    cout <<fixed << setprecision(10) <<  n*2*pi << endl;
}


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

int main(){
    int n;
    scanf("%d",&n);
    int arr[n+1];
    int sum=0;
    for(int i=0;i<n;i++){
        scanf("%d",&arr[i]);
        sum+=arr[i];
    }
    sum=round(sum/(double)n);
    long long int ans = 0;
    for(int i=0;i<n;i++)
        ans += (arr[i]-sum)*(arr[i]-sum);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define longlongvector vector<long long> 
#define intvector vector<int> 
#define size size()
using namespace std;

int n, m, k;



int main()
{
	int a, b; 

	cin >> a >> b; 
	int x = 0 , d ;
	for (int i = 0; i < b; i++)
	{
		cin >> d;
		x += d;
	}


	if (x > a) cout << -1 << endl;
	else cout << a-x << endl;

	system("pause");
}

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


int main(){
  int n;
  cin >> n;
  vector<string> ans;
  map<string,int> mp;
  for(int i=0;i<n;++i){
    string s,s1;
    cin >> s >> s1;
    if(s=="insert"){
      mp[s1]++;
    }else{
      if(mp[s1]>0) ans.push_back("yes");
      else ans.push_back("no");
    }
  }
  for(int i=0;i<ans.size();++i){
    cout << ans[i] << endl;
  }
  return 0;
}



Measured memory_bytes: 75652
#include<cstdio>
#include<algorithm>
using namespace std;

int n, w;
int a[2222][99];

bool valid(int x, int y) {
	sort(a[x]+1, a[x]+w+1);
	sort(a[y]+1, a[y]+w+1);
	
	int same = 0;
	for(int i=1, j=1;i<=w && j<=w;) {
		if (a[x][i] == a[y][j]) {
			same++; i++; j++;
		} else if (a[x][i] > a[y][j]) j++;
		else i++;
	}
	return (same == 1);
}

void chk() {
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			if (!valid(i, j)) {
				printf("wa: %d %d\n", i, j);
				for(int k=1;k<=w;k++) printf("%d%c", a[i][k], k<w ? ' ' : '\n');
				for(int k=1;k<=w;k++) printf("%d%c", a[j][k], k<w ? ' ' : '\n');
				return;
			}
	puts("ac");
}

void o() {
	for(int i=1;i<=n;i++)
		for(int j=1;j<=w;j++) printf("%d%c", a[i][j], j<w ? ' ' : '\n');
}

int main() {
	w=42;
	n=w*(w-1)+1;
	printf("%d %d\n", n, w);
	
	int num = 1;
	for(int i=1;i<=w;i++) {
		a[i][1] = 1;
		for(int j=2;j<=w;j++) a[i][j] = ++num;
	}
	/*for(int i=2;i<=w;i++)
		for(int j=i+1;j<=w;j++)
			swap(a[i][j], a[j][i]);*/
	for(int i=2;i<=w;i++) {
		int st = (i-1)*(w-1)+2;
		for(int j=st;j<st+w-1;j++) a[j][1] = i;
		
		for(int j=st;j<st+w-1;j++) {
			int x = 1, y = j-st+2;
			for(int k=2;k<=w;k++) {
				a[j][k] = a[st-w+x][y];
				x++; y++;
				if (y>w) y=2;
			}
			sort(a[j]+1, a[j]+w+1);
		}
		
		for(int j=st;j<st+w-1;j++) {
			int need_start = j-st+w+1, pos = j;
			while(a[pos][2] != need_start) pos++;
			if (pos != j) {
				for(int k=2;k<=w;k++)
					swap(a[j][k], a[pos][k]);
			}
		}
	}

	o();
	
//	chk();
	
	return 0;
}


Measured memory_bytes: 1152
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

void solve(){
    char c;
    cin >> c;
    if(c >= 'a' && c <= 'z'){
        print("a");
    }else{
        print("A");
    }


}

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

Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <queue>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
const ll MOD = 1e9+7;

ll X[101010];
ll Y[101010];
int main(){
    int n,m;
    cin >> n >> m;
    REP(i,n){
        ll x;
        cin >> x;
        X[i] = x;
    }
    REP(i,m){
        ll y;
        cin >> y;
        Y[i] = y;
    }

    ll xsum = 0;
    REP(k,n){
        xsum += (k*X[k] - (n-k-1)*X[k]);
        xsum %= MOD;
    }

    ll ysum = 0;
    REP(k,m){
        ysum += (k*Y[k] - (m-k-1)*Y[k]);
        ysum %= MOD;
    }

    ll ans = (xsum*ysum) % MOD;

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


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define endl "\n"
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 2e+9 + 10;
typedef pair<ll, ll> P;

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

  int a, b; cin >> a >> b;

  if(a == b) rep(i, a) cout << a;
  else if(a > b) rep(i, a) cout << b;
  else rep(i, b) cout << a;
  cout << endl;

  return 0;
}

Measured memory_bytes: 256
h,w = gets.split.map(&:to_i)
s = h.times.map{"#"+gets.chomp+"#"}.unshift("#"*(w+2)).push("#"*(w+2))
d = [1,0,-1,0]
dist = Array.new(h+1).map{Array.new(w+1,100000)}

que = [[1,1]]
dist[1][1] = 1
while que.any?
  x,y = que.shift
  4.times do |i|
    if s[x+d[i]][y+d[i^1]] == "." && dist[x][y]+1 < dist[x+d[i]][y+d[i^1]]
      dist[x+d[i]][y+d[i^1]] = dist[x][y]+1
      que.push([x+d[i],y+d[i^1]])
    end
  end
end

c = 0
s.each do |str|
  c += str.count(".")
end

puts [c-dist[h][w],-1].max

Measured memory_bytes: 1916
#include <iostream>
#include <map>
#include <iomanip>
using namespace std;
class Data {
    public:
        Data(int max);
        ~Data();
        void add(int, double);
        int getNum(int n);
        double getTime(int n);

    private:
        int* num;
        double* time;
        int max;
        int now_n;
};
Data::Data(int max){
    num = new int[max];
    time = new double[max];
    for(int i = 0; i < max; ++i) {
        num[i] = 0;
        time[i] = 0;
    }
    this->max = max;
    now_n = 0;
}
Data::~Data(){
    delete num;
    delete time;
}
void Data::add(int n, double t){
    if (now_n >= max) {
        return;
    }
    num[now_n] = n;
    time[now_n] = t;
    ++now_n;
}
int Data::getNum(int n){
    return num[n];
}
double Data::getTime(int n){
    return time[n];
}
#define MEMBER 8
#define RACE 3
int main(){
    map<double, int> course, ans, tmp;
    int num;
    double in;
    Data data(MEMBER);
    int count;
    int race = RACE;
    while(race--) {
        course.clear();
        for (int i = 0; i < MEMBER; i++) {
            cin >> num >> in;
            course.insert( map<double, int>::value_type(in , num));
        }
        count = 0;
        for(map<double, int>::iterator it = course.begin(); it != course.end(); ++it) {
            if ((count++) < 2) {
                data.add(it->second , it->first);
            }
            else {
                tmp.insert( map<double, int>::value_type(it->first, it->second));
            }
        }
    }
    count = 2;
    for(map<double, int>::iterator it = tmp.begin(); it != tmp.end(); ++it) {
        if (count-- <= 0) {
            break;
        }
        data.add(it->second, it->first);
    }
    //output
    for(int i = 0; i < MEMBER; ++i) {
        cout<< showpoint << data.getNum(i) << " " << setprecision(4) << data.getTime(i) << endl;
    }
}

Measured memory_bytes: 1296
#include <bits//stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i,n) for(int i = n-1;i >= 0;i--)
#define ALL(obj) begin(obj), end(obj)
int n, h, w,l,q,a,b;
int main(void) {
    cin >> n;vector<int> x(n); vector<vector<int>> dob(n+1, vector<int>(22));
    rep(i, n) cin >> x[i];
    cin >> l >> q;
    rep(i, n) dob[i][0] = upper_bound(ALL(x),x[i] + l) - x.begin() - 1;// 1日で行け最大地点
    rep(i, 20) rep(j, n) dob[j][i + 1] = dob[dob[j][i]][i]; // doubling
    rep(i, q) {
        cin >> a >> b; a--; b--;
        if (a > b) swap(a, b);// a> b のとき a<bでも問題ない
        int ans = 0;
        rrep(j, 21) if (dob[a][j] < b) a = dob[a][j], ans += (1 << j);
        ans++; cout << ans << endl;
    }
}

Measured memory_bytes: 15408
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int k; rd(k);
  int[] digit;
  while(k){
    digit~=k&1;
    k/=2;
  }
  reverse(digit);

  struct E{int u, v, w;}
  E[] edges;
  int n=1; k=1;
  foreach(d; digit[1..$]){
    foreach(ref e; edges) e.w*=2;
    edges~=E(n, n+1, 0);
    edges~=E(n, n+1, 1);
    k*=2;
    if(d){
      edges~=E(1, n+1, k);
      k++;
    }
    n++;
  }

  writeln(n, " ", edges.length);
  foreach(e; edges){
    writeln(e.u, " ", e.v, " ", e.w);
  }

}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}

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

int main(){
  cin >> n;
  int def_half_n = n/2+2;
  int def_n = n;
  cout << n << ":";
  while(n%2==0){
    cout << " " << 2;
    n /= 2;
  }
  if(n==1){cout << endl; return 0;}
  for(int i = 3;i*i<=n;i+=2){
    while(n%i==0){
      cout << " " << i;
      n /= i;
    }
    if(n==1)break;
  }
  if(n != 1)cout << " " << n;
  cout << endl;
  return 0;
}

Measured memory_bytes: 3108
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <math.h>
#include <unordered_map>
#include <numeric>
#include <sstream>
using namespace std;

int main()
{
/* ---------------------------------- */
	int n,tmp,sum=0;
	std::vector<int> v;

	std::cin >> n;

	for (int i = 0; i < n; i++) {
		scanf("%d", &tmp);
		v.push_back(tmp);
	}
/* ---------------------------------- */

	std::sort(v.rbegin(), v.rend()); //降順

	for (int i = 1; i < n; i++) {
		sum+=v[i];
	}

	if(v[0]<sum){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}

	return 0;
}


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

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

ll ctoi(char a){
    return ll(a-'0');
}

void solve(long long  N, long long P, string S){
    vector<ll> U(N+1,0); 
    ll res = 0;
    for (int i=N-1;i>=0;i--){
        ll digit = ctoi(S[i]);
        res += digit* modpow(10,N-i+1,P) %P;
        res %= P;
        U[i] = res;
    }
    vector<ll> res_count(P,0);
    for (const ll &a : U){
        res_count[a]+=1;
    }
    ll count = 0;
    if (P==2||P==5){
        for(ll i=0;i<N;i++){
            if (ctoi(S[i])%P == 0) count+= i+1;
        }
    }else{
        for (const ll &a : res_count){
            count+= a*(a-1)/2;
        }
    }
    printf("%lld\n",count);

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    ll N;
    cin >> N;
    long long P;
    scanf("%lld",&P);
    string S;
    cin >> S;
    solve(N, P, S);
    return 0;
}


Measured memory_bytes: 2308
N,L=map(int,input().split())
aji=[L+i-1 for i in range(1,N+1)]
aji_abs=[]
for i in range(N):
    aji_abs.append(abs(aji[i]))

ind=aji_abs.index(min(aji_abs))

print(sum(aji)-aji[ind])


Measured memory_bytes: 2940
#include <stdio.h>
#include <string.h>
 
char main(){
  char a[11],b[11],c[11];
  int aa,bb,cc;
  scanf("%s %s %s",a,b,c);
  aa=strlen(a);
  bb=strlen(b);
  cc=strlen(c);
  if(a[aa-1]==b[0] && b[bb-1]==c[0]){
    printf("YES\n");
  }else{
    printf("NO\n");
  }
  return 0;
}

Measured memory_bytes: 128
object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N = sc.nextInt()
    val C, S, F = new Array[Int](N - 1)
    (0 until N - 1) foreach { i =>
      val c, s, f = sc.nextInt()
      C(i) = c
      S(i) = s
      F(i) = f
    }

    def solve(N: Int, C: Array[Int], S: Array[Int], F: Array[Int]): Seq[Int] = {
      @scala.annotation.tailrec
      def loop(i: Int, time: Int): Int =
        if (i < N - 1) {
          if (time < S(i)) loop(i + 1, S(i) + C(i))
          else if (time % F(i) == 0) loop(i + 1, time + C(i))
          else loop(i + 1, F(i) * (time / F(i) + 1) + C(i))
        } else time
      (0 until N) map (i => loop(i, 0))
    }

    println(solve(N, C, S, F).mkString("\n"))
  }

}


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

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> c(H);
    rep(i, H) cin >> c[i];

    int ans = 0;
    vector<vector<int>> cnt(H, vector<int>(W, 0));
    rep(i, H) {
        int l = 0, r = 0;
        while (l < W) {
            if (r >= W || c[i][r] == '#') {
                if (r != l)
                    for (int j = l; j < r; ++j) {
                        cnt[i][j] = r - l;
                    }
                ++r, l = r;
            } else
                ++r;
        }
    }
    rep(i, W) {
        int l = 0, r = 0;
        while (l < H) {
            if (r >= H || c[r][i] == '#') {
                if (r != l)
                    for (int j = l; j < r; ++j) {
                        ans = max(ans, cnt[j][i] + r - l - 1);
                    }
                ++r, l = r;
            } else
                ++r;
        }
    }

    cout << ans << endl;
}


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

int main(int argc, char *argv[])
{
  int x,y,w[1000];
  cin >> x >> y;

  for(int i=0; i<x; i++)
    cin >> w[i];

  int num = x;
  while(num%y)
    num += x;

  int sum = 0;
  int ind = 0;

  for(int i=0; i<num; i+=y){
    int max=ind;
    int min=ind;
    ++ind;

    for(int j=1; j<y; j++,ind++){
      ind %= x;
      if(w[max] < w[ind])
	max = ind;

      else if(w[min] > w[ind])
	min = ind;
    }

    sum += (w[max]-w[min]);
  }

  cout << sum<< "\n";
}

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> x(M), y(M);
    for (int i = 0; i < M; i++) {
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
    }
    vector<vector<int>> dp(N, vector<int>(2, 0));
    for (int i = 0; i < N; i++) {
        dp[i][0] = 1;
    }
    dp[0][1] = 1;
    for (int i = 0; i < M; i++) {
        if (dp[x[i]][1] == 1) {
            if (dp[x[i]][0] == 1) dp[x[i]][1] = 0;
            dp[x[i]][0]--;
            dp[y[i]][0]++;
            dp[y[i]][1] = 1;
        } else {
            dp[x[i]][0]--;
            dp[y[i]][0]++;
        }
    }
    int sum = 0;
    for (int i = 0; i < N; i++) {
        sum += dp[i][1];
    }
    cout << sum << endl;
}

Measured memory_bytes: 6528
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define INF 100000000000
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using P = pair<int, int>;

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

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

long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

int main()
{
    ll a, b ,c, k;
    cin >> a >> b >> c >> k;
    
    ll ans = 0;
    while(k--) {
        if (a > 0) {
            ans++;
            a--;
        } else if (b > 0) {
            b--;
            continue;
        } else {
            ans--;
            c--;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3624
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(a > b){
            System.out.println("a > b");
        }else if(a == b){
            System.out.println("a == b");
        }else if(a < b){
            System.out.println("a < b");
        }
        sc.close();
    }
}


Measured memory_bytes: 26272
#include <iostream>
using namespace std;
const int NMAX = 100;
const int MMAX = 1000;
const int INF = 100000;

int main() {
  int n, m;
  cin >> n >> m;
  int a[MMAX], b[MMAX], c[MMAX];
  for (int i = 0; i < m; i++) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;
  }
  int d[NMAX][NMAX];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) d[i][j] = 0;
      else d[i][j] = INF;
    }
  }
  for (int i = 0; i < m; i++) {
    d[a[i]][b[i]] = c[i];
    d[b[i]][a[i]] = c[i];
  }
  for (int k = 0; k < n; k++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
  int ans = m;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j < n; j++) {
      if (d[j][a[i]] + c[i] == d[j][b[i]]) {
        ans--;
        break;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<algorithm>
#define f first
#define s second
#define pb push_back
using namespace std;
typedef long long ll;
map<string, int>mmp;
vector<string> vec;
int main(){
	int n;
	string s;
	std::ios::sync_with_stdio(false);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>s;
		mmp[s]++; 
	}
	int max = 0;
	for(auto it:mmp){
		if(it.s >= max)
			max = it.s;	
	}
	for(auto it:mmp){
		if(it.s == max)
			cout<<it.f<<endl;
	}
	return 0;
}

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

int main()
{
	int n;
	cin >> n;
	long long ma = -10000000, mi = 10000000, sum = 0;
	for( int i = 0; i < n; i++ ) {
		long long a;
		cin >> a;
		ma = max( ma, a );
		mi = min( mi, a );
		sum += a;
	}

	cout << mi << " " << ma << " " << sum << endl;
}



Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<int>; using VVI = vector<VI>; using VVVI = vector<VVI>;
const int inf=1e9+7;
const ll INF=1LL<<60;
const ll mod=1e9+7;

int n,m;
VVI e(100010);
VVI res(100010);
VI cal(100010,-1);
vector<char> op(100010);
VI val(100010);
VVI power(24,VI(100010,0));

VVI anse(24);

int b[2][4]={{0,0,1,1},{0,1,0,1}};

VI Po(100010,-2);


void dfs(int u,int pa,int stage){
  if(pa>=0){
    if(op[u]=='|'){
      cal[u]=cal[pa]|b[val[u]][stage];
    }
    else if(op[u]=='&'){
      cal[u]=cal[pa]&b[val[u]][stage];
    } 
    else {
      cal[u]=cal[pa]^b[val[u]][stage];
    }
  }
  if(e[u].size()==1&&pa>=0){
    res[u].pb(cal[u]);
  }
  for(int nex:e[u]){
    if(nex==pa) continue;
    dfs(nex,u,stage);
  }
}

void dfs2(int u,int pa,bool depth){
  if(depth==0) Po[u]=-1; //A
  else Po[u]=inf; //B
  for(int nex:e[u]){
    if(nex==pa) continue;
    if(Po[nex]==-2) dfs2(nex,u,!depth);
    if(depth==0) Po[u]=max(Po[u],Po[nex]);
    else Po[u]=min(Po[u],Po[nex]);
  }
}

int main(){
  int i,j;
  cin>>n>>m;
  for(i=1;i<n;i++){
    string s;
    cin>>s;
    op[i]=s[3];
    val[i]=s[4]-'X';
  }
  for(i=0;i<n-1;i++){
    int u,v;
    cin>>u>>v;
    e[u].pb(v);
    e[v].pb(u);
  }
  VI x(m),y(m);
  for(i=0;i<m;i++){
    cin>>x[i]>>y[i];
  }
  for(i=0;i<4;i++) {
    cal=VI(100010,-1);
    cal[0]=0;
    dfs(0,-1,i);
  }
  for(i=0;i<n;i++){
    if(res[i].size()>=1){
      //cout<<i<<endl;
      //cout<<res[i][0]<<" "<<res[i][1]<<" "<<res[i][2]<<" "<<res[i][3]<<endl;
    }
  }

  map <vector<int>,int > mapp;
  vector<int> perm={0,1,2,3};
  int index=0;
  do{
    Po=VI(100010,-2);
    mapp[perm]=index;
    for(i=0;i<n;i++){
      if(res[i].size()==0) continue;
      for(j=0;j<4;j++) power[index][i]+=(1<<perm[j])*res[i][j];
      Po[i]=power[index][i];
    }

    dfs2(0,-1,0);
    int anspow=Po[0];
    int fl;
    for(i=0;i<n;i++){
      if(res[i].size()>0&&Po[i]==anspow) {
        fl=i;
      }
    }
    anse[index]=res[fl];

    index++;
  } while(next_permutation(perm.begin(),perm.end()));

  for(i=0;i<m;i++){
    ll ans=0;
    int ord=3;
    VI cnt(4,0);
    vector<int> f(4);
    for(j=15;j>=0;j--){
      int u=2*((x[i]>>j)&1)+((y[i]>>j)&1);
      if(cnt[u]==0){
        cnt[u]++;
        f[u]=ord;
        ord--;
      }
    }
    for(int u=0;u<4;u++){
        if(cnt[u]==0){
          f[u]=ord;
          ord--;
        }
    }
    int type=mapp[f];
    
    for(j=15;j>=0;j--){
      if(((x[i]>>j)&1)==0&&((y[i]>>j)&1)==0){
        ans+=(anse[type][0])<<j;
      }
      else if(((x[i]>>j)&1)==0&&((y[i]>>j)&1)==1){
        ans+=(anse[type][1])<<j;
      }
      else if(((x[i]>>j&1)&1)==1&&((y[i]>>j)&1)==0){
        ans+=(anse[type][2])<<j;
      }
      else {
        ans+=(anse[type][3])<<j;
      }
    }
    cout<<ans<<endl;
    
  }
}



Measured memory_bytes: 30688
#include<stdio.h>
#include<string.h>
int main(){
    char a[15],b[15],c[15];
    int a1,a2,a3;
    scanf("%s%s%s",a,b,c);
   // printf("%s %s %s",a,b,c);
    a1=strlen(a);
    a2=strlen(b);
    if(a[a1-1]==b[0]&&b[a2-1]==c[0])printf("YES\n");
    else printf("NO\n");
   return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll>pll;
typedef pair<ll,pair<ll,ll>>plll;
#define fastread() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
#define vll(v) v.begin(),v.end()
#define all(x) x.rbegin(),x.rend()
#define min3(a, b, c)   min(a, min(b, c))
#define max3(a, b, c)   max(a, max(b, c))
#define F first
#define S second
#define in  freopen("input.txt", "r", stdin)
#define out  freopen("output.txt", "w", stdout)
#define minheap int,vector<int>,greater<int>
#define pb push_back
#define eb emplace_back
#define ischar(x)  (('a' <= x && x <= 'z') || ('A' <= x && x <= 'Z'))
#define isvowel(ch) ((ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u')||(ch=='A'|| ch=='E' || ch=='I'|| ch=='O'|| ch=='U'))
#define bug cout<<"BUG"<<endl;
const int Max = 2e6 + 10;
const int Mod = 1e9 + 7;
const double PI  =3.141592653589793238463;


ll dp[3001][3001];

ll sign[3001][3001],n,m;


string str,ptr;

void LCS()
{
        ll i,j;

        n=str.size(),m=ptr.size();


         for(i=1; i<=n; i++)
         {
             for(j=1; j<=m; j++)
             {
                if(str[i-1]==ptr[j-1])
                {
                    dp[i][j]=dp[i-1][j-1]+1;
                    sign[i][j]='c';
                }
                else if(dp[i-1][j]>=dp[i][j-1])
                {
                    dp[i][j]=dp[i-1][j];
                    sign[i][j]='u';
                }
                else
                {
                    dp[i][j]=dp[i][j-1];
                    sign[i][j]='l';
                }
             }
         }
}


string Find_string()
{
    ll i=n,j=m;

    string ans;



      while(i>0 and j>0)
      {
          if(sign[i][j]=='c')
          {
              ans+=str[i-1];
              i--;
              j--;
          }
          else if(sign[i][j]=='u')
            i--;

          else j--;
      }

     reverse(vll(ans));

     return ans;


}
int main()
{

   fastread();

   ll i,j,p,a,sum=0,k,t,b,c,d,cnt=0,q,l,r;




   bool flag=true;


      cin>>str>>ptr;

      LCS();

      cout<<Find_string()<<endl;




}



Measured memory_bytes: 144324