akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 5;
const int mod = 1e9 + 7;
const int dx[] = {0, 0, -1, +1}, dy[] = {-1, +1, 0, 0};

int H, W, n;
int x[70], y[70];
bool mark[70][70];
int cntx, cnty, d[70][70], X[70], Y[70];
int posx[MAX], posy[MAX], cntrow[MAX], cntcol[MAX];
vector<int> zx, zy;
int ans;

void add(int &x, int y) {
	x += y; while(x < 0) x += mod; while(x >= mod) x -= mod;
}

void bfs(int sx, int sy) {
	for (int i = 1; i <= cntx; ++i) for (int j = 1; j <= cnty; ++j) d[i][j] = -1;
	queue< pair<int,int> > q; q.push(make_pair(sx, sy)); d[sx][sy] = 0;
	while(!q.empty()) {
		int x = q.front().first, y = q.front().second; q.pop();
		for (int dir = 0; dir < 4; ++dir) {
			int nx = x + dx[dir], ny = y + dy[dir];
			if (nx < 1 || nx > cntx || ny < 1 || ny > cnty || d[nx][ny] != -1) continue;
			if (mark[nx][ny]) continue;
			d[nx][ny] = d[x][y] + 1;
			q.push(make_pair(nx, ny));
		}
	}

	int w = 1LL * X[sx] * Y[sy] % mod;
	for (int i = 1; i <= cntx; ++i) {
		for (int j = 1; j <= cnty; ++j) {
			if (i == sx && j == sy) continue;
			if (d[i][j] == -1) continue;
			int wij = 1LL * X[i] * Y[j] % mod;
			int cur = 1LL * w * wij % mod;
			add(ans, 1LL * d[i][j] * cur % mod);
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> H >> W >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> x[i] >> y[i];
		cntrow[x[i]]++;
		cntcol[y[i]]++;
	}
	long long blank = 0;
	for (int row = 0; row < H - 1; ++row) {
		blank += W - cntrow[row];
		if (cntrow[row] == 0 && cntrow[row+1] == 0) 
			add(ans, ( (blank % mod) * ((1LL * H * W - n - blank) % mod) ) % mod);
	}
	blank = 0;
	for (int col = 0; col < W - 1; ++col) {
		blank += H - cntcol[col];
		if (cntcol[col] == 0 && cntcol[col+1] == 0)
			add(ans, ( (blank % mod) * ((1LL * H * W - n - blank) % mod) ) % mod);
	}
	ans = 2LL * ans % mod;

	// compress the cells
	for (int i = 1; i <= n; ++i) zx.push_back(x[i]);
	for (int i = 1; i <= n; ++i) zy.push_back(y[i]);
	sort(zx.begin(), zx.end()); zx.erase(unique(zx.begin(), zx.end()), zx.end());
	sort(zy.begin(), zy.end()); zy.erase(unique(zy.begin(), zy.end()), zy.end());

	for (int i = 0; i < zx.size(); ++i) {
		X[++cntx] = zx[i] - (i == 0 ? -1 : zx[i - 1]) - 1;
		if (X[cntx] <= 0) --cntx;
		X[++cntx] = 1; // zx[i]
		posx[zx[i]] = cntx;
	}
	X[++cntx] = H - zx.back() - 1;
	if (X[cntx] <= 0) --cntx;

	for (int i = 0; i < zy.size(); ++i) {
		Y[++cnty] = zy[i] - (i == 0 ? -1 : zy[i - 1]) - 1;
		if (Y[cnty] <= 0) --cnty;
		Y[++cnty] = 1; // zy[i]
		posy[zy[i]] = cnty;
	}
	Y[++cnty] = W - zy.back() - 1;
	if (Y[cnty] <= 0) --cnty;

	// mark all black cells
	for (int i = 1; i <= n; ++i) mark[posx[x[i]]][posy[y[i]]] = true;

	// new board: [1...cntx][1...cnty]
	for (int i = 1; i <= cntx; ++i) {
		for (int j = 1; j <= cnty; ++j) if (!mark[i][j]) {
			bfs(i, j);
		}
	}

	cout << 1LL * ans * (int)(5e8 + 4) % mod << endl;
}

Measured memory_bytes: 12672
from sys import stdin, setrecursionlimit
setrecursionlimit(10000000)

input = stdin.readline
lmi = lambda: list(map(int, input().split()))
mi = lambda: map(int, input().split())
si = lambda: input().strip('\n')
ssi = lambda: input().strip('\n').split()


a, b = mi()
x = a+b
y = a-b
z = a*b
print(max(x, y, z))

Measured memory_bytes: 3064
n, m = gets.split.map(&:to_i)
abs = n.times.map { gets.split.map(&:to_i) }.sort_by { |a, b| a }

ans = 0

abs.each do |a, b|
  if b >= m
    ans += a * m
    m = 0
  else
    ans += a * b
    m -= b
  end

  break if m == 0
end

puts ans


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

#define pout(n)  printf ("%d\n", n)

#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)

typedef long long int ll;
using namespace std;
 
int main() {
    char w[101];
    scanf("%s", w);
 
    for (char c='a'; c<='z'; ++c)
        if (count(w, w+strlen(w), c) & 1) {
            printf("No\n");
            return 0;
        }
 
    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 256
// "header" {{{
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <tuple>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int> 
#define int int64_t
#define Fixed fixed << setprecision(10)
#define moke_pair make_pair
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const long long mod = 1000000007;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

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

inline int64_t updiv(int64_t n,int64_t d){
    return ((n + d -1) / d);
}
/*
inline double Sqrt( const double &x) 
{
	double         xHalf = 0.5 * x;
	int64_t  tmp   = 0x5FE6EB50C7B537AAl - ( *(int64_t*)&x >> 1);
	double         xRes  = * (double*)&tmp;

	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	xRes *= ( 1.5 - ( xHalf * xRes * xRes ) );
	return xRes * x;
}
*/
// }}}

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;
    cin >> n >> m;
    vector<string> a(n),b(m);
    rep(i,n){
        cin >> a[i];
    }
    rep(i,m){
        cin >> b[i];
    }
    rep(i,n-m+1){
        rep(j,a[0].size()-b[0].size()+1){
            rep(k,m){
                rep(l,b[0].size()){
                    if(b[k][l] != a[i+k][j+l]){
                        goto ng;
                    }
                }
            }
            return cout << "Yes\n",0;
            ng:;
        }
    }

    cout << "No\n";

    return 0;
}


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

using namespace std;

void Main() {
    int r, g, b;
    cin >> r >> g >> b;

    int n = r * 100 + g * 10 + b;
    cout << (n % 4 == 0 ? "YES" : "NO") << endl;
}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 3564
s = input()
k = int(input())

length = len(s)
sub = []
for item in "abcdefghijklmnopqrstuvwxyz":
  if item in s:
    for i, c in enumerate(s):
      if c == item:
        for j in range(0,length - i + 1):
          if j > 5:
            break
          if j==0:
            if s[i] not in sub:
              sub.append(s[i])
          else: 
            if s[i:i+j] not in sub:
              sub.append(s[i:i+j])
    if len(sub) >= k:
      break
print(sorted(sub)[k-1])

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

int main(){
    long double a, b; cin >> a >> b;
    unsigned long long r = floor(a * b);
    cout << r << endl; 
}

Measured memory_bytes: 3728
#include <stdio.h>

int main(void){
	int sum, a, i;
	while(1){
		scanf("%d", &sum);
		if(sum==0) break;
		
		for(i=0; i<9; i++){
			scanf(" %d", &a);
			sum -= a;
		}

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

	}
	
	return 0;
}

Measured memory_bytes: 596
#include<stdio.h>
#include<string.h>
int main(){
	char s[22];
	int i;
	fgets(s, 22, stdin);
	s[strlen(s)-1] = '\0';
	for(i = strlen(s)-1; i >= 0; i--){
		putchar(s[i]);
	}
	putchar('\n');
	return 0;
}

Measured memory_bytes: 524
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#define LL long long
#define rint register int
#define pii pair<int,int>
#define mid ((l+r)>>1)
#define MAXN 200005
#define INF 0x3f3f3f3f
using namespace std;

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <vector>
#include <map>
#define LL long long
#define rint register int
#define MAXN 200005
#define INF 0x3f3f3f3f
using namespace std;

int n, cnt, head[MAXN], maxlen;

struct Edge {int next, to;} edge[MAXN*2];

void addedge(int from, int to)
{
    edge[++cnt].next=head[from];
    edge[cnt].to=to;
    head[from]=cnt;
}

int dfs(int x, int fa)
{
    int len1=0, len2=0;
    for(int i=head[x]; i; i=edge[i].next)
    {
        int to=edge[i].to;
        if(to==fa) continue;
        int len=dfs(to, x)+1;
        if(len>len1) len2=len1, len1=len;
        else if(len>len2) len2=len;
    }
    if(len1+len2+1>maxlen) maxlen=len1+len2+1;
    return len1;
}

int main()
{
	scanf("%d", &n);
	for(rint i=1, x, y; i<n; ++i)
	{
		scanf("%d%d", &x, &y);
		addedge(x, y);
		addedge(y, x);
	}
	dfs(1, 0);
	if(maxlen%3==2) printf("Second\n");
	else printf("First\n");
}

Measured memory_bytes: 13056
fn is_prime(x: i64) -> bool {
    let mut ans = true;
    for i in 2..x {
        if i * i > x {
            break;
        }
        if x % i == 0{
            ans = false;
            break;
        }
    }
    ans
}


fn main() {
    let mut x = read();

    while !is_prime(x) {
        x += 1;
    }
    println!("{:?}", x);

}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

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

using ll = long long;
using ull = unsigned long long;
using namespace std;
constexpr int inf = 1<<30;
constexpr int mo = 1e9+7;
constexpr ll infl = 1ll<<60;


int main(){
    cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    
    int n;
    cin>>n;
    vector<ll> a(n);
    ll sum = 0;
    vector<ll> s(n);
    for(auto & b : a) cin>>b,sum+=b,sum%=mo;
    s[0] = a[0];
    for(int i=1;i<n;++i){
        s[i] = s[i-1] + a[i];
        s[i] %=mo;
    }
    ll ret =0ll;
    for(int i=0;i<n;++i){
        ll tmp = sum - s[i];
        if(tmp < 0)tmp +=mo;
        tmp %= mo;
        ret += (tmp * a[i])%mo;
        ret %= mo;
    }
    cout  << ret << endl;
    return 0;
    
}


Measured memory_bytes: 6364
require "set"

N, U, V = gets.chomp.split(" ").map(&:to_i)
LINKS = {}
(N-1).times do |i|
  a, b = gets.chomp.split(" ").map(&:to_i)
  LINKS[a] ||= Set.new
  LINKS[b] ||= Set.new
  LINKS[a] << b
  LINKS[b] << a
end

def calc_depth(root_id)
  visited = Set.new([root_id])
  depth = {}
  depth[root_id] = 0
  stack = [root_id]
  while !stack.empty?
    n_id = stack.pop
    LINKS[n_id].each do |on_id|
      next if visited.include?(on_id)
      visited << on_id
      depth[on_id] = depth[n_id] + 1
      stack.push(on_id)
    end
  end
  depth
end

d1 = calc_depth(U)
d2 = calc_depth(V)

max_dist = d1[V]
1.upto(N) do |i|
  max_dist = d2[i] if d1[i] < d2[i] && max_dist < d2[i]
end
puts max_dist - 1


Measured memory_bytes: 73084
N = int(input())
A = [int(input()) for i in range(N)]
A = sorted(A)
h = N // 2
if N % 2 == 0:
    ans = sum(A[h:])*2 - sum(A[:h])*2 - A[h] + A[h-1]
else:
    ans1 = sum(A[h-1:])*2 - sum(A[:h-1])*2 - (A[h-1] + A[h]) * 3
    ans2 = sum(A[h:])*2 - sum(A[:h])*2 - (A[h] + A[h+1])
    ans = max(ans1, ans2)
print(ans)

Measured memory_bytes: 82984
n = int(input())
A = list(map(int,input().split()))

ANS = [0 for i in range(n)]
for i in range(n,0,-1):
    k = n//i
    su = 0
    #print(i)
    #print((i,i**k+i,i))
    for j in range(i,i*k+i,i):
        su += ANS[j-1]
    if (su%2)!=A[i-1]:
        ANS[i-1] += 1

#print(ANS)

print(sum(ANS))
for i in range(len(ANS)):
    if ANS[i]==1:
        print(i+1)

Measured memory_bytes: 70620
//Author: AnandRaj uux
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll; 

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test() int t;cin>>t;while(t--)
#define forn(i,f,n) for(int i=f;i<f+n;i++)
#define rforn(i,l,n) for(int i=l;i>l-n;i--)
#define all(v) v.begin(),v.end()
#define prin(V) for(auto v:V) cout<<v<<" ";cout<<endl
#define take(V,f,n) for(int i=f;i<f+n;i++) cin>>V[i]
#define what(x) cerr<<#x<<" = "<<x<<endl
#define KStest() int t,t1;cin>>t;t1=t;while(t--)
#define KScout cout<<"Case #"<<t1-t<<": "

const int MOD = 1e9+7,MAX = 1e5+5;
/////////////////FastExp///////////////////
ll powN(ll a,ll p)
{
	if(p==0) return 1;
	ll z=powN(a,p/2);
	z=(z*z)%MOD;
	if(p%2) z=(z*a)%MOD;
	return z;
}
/////////////////FastExp///////////////////
//////////////////Sieve////////////////////
vector<bool> is_prime(MAX+1, true);
void Sieve()
{
	is_prime[0] = is_prime[1] = false;
	int i,j;
	for (i = 2; i*i <= MAX; i++) 
	{
    	if (is_prime[i]) 
    	{
        	for (j = i * i; j <= MAX; j += i)
            	is_prime[j] = false;
    	}
	}
}
//////////////////Sieve////////////////////

int main()
{
	int n;
	cin>>n;
	vi A(n-1);
	take(A,0,n-1);
	vi In(n);
	for(int i=0;i<n-1;i++)
	{
		In[A[i]-1]++;
	}
	for(int i=0;i<n;i++) cout<<In[i]<<endl;
}		

Measured memory_bytes: 4840
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
int A[30]={};
int B[30]={};
int C[30]={};
int F[30]={};

int main(){
    int N;
    cin >> N;
    rep(i,N){
        cin >> A[i];
    }
    for(int i=1;i<N;i++){
        if(A[i] - A[i-1] == 1){
            F[A[i-1]-1] = 1;
        }   
    }
    //rep(i,N){
    //    cout << F[i]<< ' ';
    //}
    //cout << endl;
    int sum = 0;
    rep(i,N){
        cin >> B[i];
        sum += B[i];
    }
    //cout << sum << endl;
    rep(i,N-1){
        cin >> C[i];
        if(F[i]==1){
            sum += C[i];
            //cout << C[i]<<endl;
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		Long H = sc.nextLong();

		int a = (int) Math.floor(calcLog((long) 2, H) + 1);
		
		long cnt = (long) (Math.pow(2, a) - 1);

		System.out.print(cnt);

		sc.close();

	}

	static double calcLog (Long a, Long b) {
		double value = Math.log(b) / Math.log(a);
		return value;
	}
	
	
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
#define __lcm(a,b) ((a)/__gcd(a,b)*(b))
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}

int main()
{
	int a=read(),b=read();
	cout<<(a-(b<a))<<endl;
	return 0;
}



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

int main() {
    int a;
    cin >> a;
    int x=0,y=0;
    for (int i = 1;i <= a; i++) {
        if (i % 2 == 0) {
            x++;
        }
    }
    for (int i = 1;i <= a;i++) {
        if (i % 2 != 0) {
            y++;
        }
    }

    cout << x * y << endl;
    
    

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize ("-O3")
    using namespace std;
    #define ll long long
    #define ld long double
    #define vll vector<ll>
    #define mll map<ll,ll>
    #define pll pair<ll,ll>
    #define ff first
    #define ss second
    #define pb push_back
    #define deb(x) cout<<#x<<" : "<<x<<endl;
    #define deb2(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
    #define deb3(x,y,z) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
    #define deb4(w,x,y,z) cout<<#w<<" : "<<w<<"\t"<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<"\t"<<#z<<" : "<<z<<endl;
    #define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define printv(a)  for(ll i=0;i<a.size();i++)  cout<<a[i]<<" ";
   
   
    const int mod=1e9+7;
    const int N=1e6+5; 
   
    bool sortbysec(const pair<pair<ll,ll>,ll> &a, 
                      const pair<pair<ll,ll>,ll> &b) 
        { 
            return (a.second > b.second); 
        } 
        ll powermod(ll x, ll y, ll p)
        {
            ll res = 1;
            x = x % p;
            while (y > 0)
            {
                if (y & 1) res = (res*x) % p;
                y = y>>1;
                x = (x*x) % p;
            }
            return res;
        }
       
        bool isprime(int n) 
        { 
            if (n <= 1)  return false; 
            if (n <= 3)  return true; 
            if (n%2 == 0 || n%3 == 0) return false; 
            for (int i=5; i*i<=n; i=i+6) 
                if (n%i == 0 || n%(i+2) == 0) 
                   return false; 
           return true; 
        }
       
        
     
        int main()
    {
        FAST;
        ll n;
        cin>>n;
         vector<long double> dp(n+1,0);
        dp[0]=1;
        vector<long double> a(n);
        for(ll i=0;i<n;i++)
        {
            ld x;
            cin>>x;
            for(ll j=i+1;j>=0;j--)
            {
                dp[j]=(j==0?0:dp[j-1]*x)+dp[j]*(1-x);
            }
        }
        ld ans=0;
        for(ll i=0;i<=n;i++)
        {
            ll tails=n-i;
            if(i>tails)
            ans+=dp[i];
        }
        cout<<fixed<<setprecision(12)<<ans;
    
        return 0;
    }

Measured memory_bytes: 384
//Reversing number
#include<stdio.h>
int main()
{
    int n;
    scanf("%d",&n); int a[n];
    for (int i = 0; i < n; i++)
    {
        scanf("%d",&a[i]);
    }
    int tmp;
    for ( int i = 0; i < n/2; i++)
    {
        tmp=a[i];
        a[i]=a[n-i-1];
        a[n-i-1]=tmp;
    }
    for (int i = 0; i < n; i++)
    {
        printf("%d",a[i]);
        if(i<n-1)putchar(' ');
    }
    puts("");
    
    return 0;
    
}



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


int dp__[100];

//最大公約数
ll gcd(ll x, ll y){
  if(x % y == 0) return y;
  return gcd(y, x % y);
}
//最小公倍数
ll lcm(ll x, ll y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp__[n] = 1;
  if(dp__[n] != -1) return dp__[n];
  return dp__[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


int main(){
  int s;
  cin >> s;
  int left = s / 100;
  int right = s % 100;

  if(left >= 1 && left <= 12){
    if(right >= 1 && right <= 12) cout << "AMBIGUOUS" << endl;
    else cout << "MMYY" << endl;
  }
  else if(right >= 1 && right <= 12) cout << "YYMM" << endl;
  else cout << "NA" << endl;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lambda(res,...) (function<res(__VA_ARGS__)>)[&](__VA_ARGS__) -> res
#define method(name,res,...) function<res(__VA_ARGS__)> name = (function<res(__VA_ARGS__)>)[&](__VA_ARGS__) -> res
#define foreach(i,n) for(auto &i:(n))

using namespace std;
using ll = long long;


vector<ll> func(ll x,ll y,ll z,int n){
	vector<ll> line({x,y,z});
	sort(line.begin(),line.end());
	x = line[0];
	y = line[1];
	z = line[2];
	vector<ll> res(n,0);
	method(mul,ll,ll x){
		return x * (x+1) / 2;
	};

	ll sq = x * y;

	for(int i=0;i<x+y+z-2;++i){
		ll &it = res[i%n];
		it += sq;
		ll dis = max(0ll,i-z+1);
		it -= mul(dis);
		if(dis>x){
			it += mul(dis-x);
		}
		if(dis>y){
			it += mul(dis-y);
		}
		ll below = max(0ll,x+y-i-2);
		it -= below * (below + 1) / 2;
		if(below>x){
			it += mul(below-x);
		}
		if(below>y){
			it += mul(below-y);
		}
	}
	return res;
}

vector<ll> operator+(vector<ll> a,vector<ll> b){
	for(int i=0;i<a.size();++i){
		a[i] += b[i];
	}
	return a;
}


vector<ll> operator-(vector<ll> a,vector<ll> b){
	for(int i=0;i<a.size();++i){
		a[i] -= b[i];
	}
	return a;
}

vector<ll> operator*(vector<ll> a,ll k){
	foreach(i,a){
		i = i * k;
	}
	return a;
}

int main(){
	vector<ll> cube(3);
	vector<ll> origins(3);
	int n;
	foreach(i,cube)cin>>i;
	foreach(i,origins)cin>>i;
	cin >> n;
	vector<vector<ll>> lines(3);
	for(int i=0;i<3;++i){
		lines[i].emplace_back(1);
		lines[i].emplace_back(origins[i]+1);
		lines[i].emplace_back(cube[i]-origins[i]);
	}
	vector<ll> ans(n,0);
	for(int i=0;i<3;++i){
		for(int j=0;j<3;++j){
			for(int k=0;k<3;++k){
				int sign = (lambda(int,vector<int> line){
						int res = 1;
						foreach(i,line){
						if(i==0)res = -res;
						}
						return res;
						})({i,j,k});
				ans = ans + func(lines[0][i],lines[1][j],lines[2][k],n) * sign;
			}
		}
	}
	{
		bool flag = false;
		foreach(i,ans){
			if(flag)cout << " ";
			cout << i;
			flag = true;
		}
		cout << endl;
	}
}




Measured memory_bytes: 3180
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let s: Vec<String> = read_vec();
    println!(
        "{}{}{}",
        ((s[0].chars().next().unwrap() as u8) + ('A' as u8) - ('a' as u8)) as char,
        ((s[1].chars().next().unwrap() as u8) + ('A' as u8) - ('a' as u8)) as char,
        ((s[2].chars().next().unwrap() as u8) + ('A' as u8) - ('a' as u8)) as char
    );
}


Measured memory_bytes: 4352
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		long N = sc.nextLong();
		long K = sc.nextLong();
		long a = N%K;
		
		System.out.println(Math.min(a, K-a));
	}
}

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

from bisect import bisect_left


def solve(s, t):
    a = ord('a')
    pos_list = [[] for _ in range(26)]
    for i, ch in enumerate(s):
        pos_list[ord(ch)-a].append(i)
    for ch in t:
        if not pos_list[ord(ch)-a]:
            return -1
    cc = 0
    s_len = len(s)
    for ch in t:
        pl = pos_list[ord(ch)-a]
        cc_mod = cc % s_len
        cc_ofs = (cc // s_len) * s_len
        i = bisect_left(pl, cc_mod)
        if i < len(pl):
            cc = cc_ofs + pl[i] + 1
        else:
            cc = cc_ofs + s_len + pl[0] + 1

    return cc


if __name__ == '__main__':
    s = input().strip()
    t = input().strip()

    ans = solve(s, t)

    print(ans)


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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if(abs(a - c) <= d){
    cout << "Yes" <<endl;
  }
  else if(abs(a - b) <= d && abs(b - c) <= d){
    cout << "Yes" <<endl;
  }
  else{
    cout <<"No" <<endl;
  }
}


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

#define int long long
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define yn(x) ((x) ? "YES" : "NO")

typedef pair <int, int> ii;
typedef pair <ii, int> iii;

const int siz = 2e5 + 10;
const int SIZ = 1e6 + 10;
const int mod = 1e9 + 7;
const int maxx = 2e9;
const int MAXX = 1e12;
const string file = "2";



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

//    freopen ((file + ".inp").c_str(), "r", stdin);
//    freopen ((file + ".out").c_str(), "w", stdout);

    int n;
    cin >> n;

    vector <int> pos, neg;
    for (int i = 1; i <= n; i++) {
        int x, y;
        cin >> x >> y;

        pos.push_back(x + y);
        neg.push_back(x - y);
    }

    sort (all(pos));
    sort (all(neg));

    cout << max(pos.back() - pos.front(), neg.back() - neg.front());

//    cerr << "Time: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

    return 0;
}


Measured memory_bytes: 6648
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int h, w; cin >> h >> w;
  V<string> s(h); for (int i = 0; i < h; ++i) cin >> s[i];
  VV<> cY; assign(cY, h + w - 1, h + w);
  VV<> cX; assign(cX, h + w - 1, h + w);
  for (int X = 0; X < h + w - 1; ++X) for (int Y = 0; Y < h + w - 1; ++Y) {
    int d = 1;
    if (X - Y + h - 1 & 1 or X + Y - h + 1 & 1) d = 0;
    int x = X - Y + h - 1 >> 1, y = X + Y - h + 1 >> 1;
    if (x < 0 or x >= h or y < 0 or y >= w) d = 0;
    else if (s[x][y] != '#') d = 0;
    cY[X][Y + 1] = cY[X][Y] + d;
    cX[Y][X + 1] = cX[Y][X] + d;
  }
  lint res = 0;
  for (int X = 0; X < h + w - 1; ++X) for (int Yl = 0; Yl < h + w - 1; ++Yl) for (int Yr = Yl + 1; Yr < h + w - 1; ++Yr) {
    if (X - Yl + h - 1 & 1 or X + Yl - h + 1 & 1 or X - Yr + h - 1 & 1 or X + Yr - h + 1 & 1) continue;
    int xl = X - Yl + h - 1 >> 1, yl = X + Yl - h + 1 >> 1;
    int xr = X - Yr + h - 1 >> 1, yr = X + Yr - h + 1 >> 1;
    if (xl < 0 or xl >= h or yl < 0 or yl >= w or xr < 0 or xr >= h or yr < 0 or yr >= w) continue;
    if (s[xl][yl] != '#' or s[xr][yr] != '#') continue;
    if (X - Yr + Yl >= 0) res += cY[X - Yr + Yl][Yr + 1] - cY[X - Yr + Yl][Yl];
    if (X + Yr - Yl < h + w - 1) res += cY[X + Yr - Yl][Yr + 1] - cY[X + Yr - Yl][Yl];
  }
  for (int Y = 0; Y < h + w - 1; ++Y) for (int Xl = 0; Xl < h + w - 1; ++Xl) for (int Xr = Xl + 1; Xr < h + w - 1; ++Xr) {
    if (Xl - Y + h - 1 & 1 or Xl + Y - h + 1 & 1 or Xr - Y + h - 1 & 1 or Xr + Y - h + 1 & 1) continue;
    int xl = Xl - Y + h - 1 >> 1, yl = Xl + Y - h + 1 >> 1;
    int xr = Xr - Y + h - 1 >> 1, yr = Xr + Y - h + 1 >> 1;
    if (xl < 0 or xl >= h or yl < 0 or yl >= w or xr < 0 or xr >= h or yr < 0 or yr >= w) continue;
    if (s[xl][yl] != '#' or s[xr][yr] != '#') continue;
    if (Y - Xr + Xl >= 0) res += cX[Y - Xr + Xl][Xr] - cX[Y - Xr + Xl][Xl + 1];
    if (Y + Xr - Xl < h + w - 1) res += cX[Y + Xr - Xl][Xr] - cX[Y + Xr - Xl][Xl + 1];
  }
  cout << res << '\n';
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

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

    int K;
    cin >> K;
    vector<int> A(K);
    for (int i = 0; i < K; ++i)
        cin >> A[i];

    bool isok = true;
    ll mi = 2, ma = 2;
    for (int i = K - 1; i >= 0; --i) {
        ll nmin = (mi + A[i] - 1) / A[i] * A[i];
        ll nmax = ma / A[i] * A[i] + A[i] - 1;
        mi = nmin, ma = nmax;
        if (mi > ma) {
            isok = false;
            break;
        }
    }

    if (isok)
        cout << mi << " " << ma << endl;
    else
        cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 640
#include <cassert>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef pair<int, int> PII;

#define debug(args...) {vector<string> _v = split(#args, ','); err(_v.begin(), args); puts("");}
vector<string> split(const string& s, char c) {vector<string> v; stringstream ss(s); string x; while (getline(ss, x, c)) v.push_back(x); return v;}
void err(vector<string>::iterator it) {}
template<typename T, typename... Args> void err(vector<string>::iterator it, T a, Args... args) {cerr << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << ", "; err(++it, args...);}

#if (( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)
#define lld I64d
#else
#define lld lld
#endif

#define pb push_back
#define mp make_pair
#define all(x)  (x).begin(),(x).end()
#define tr(c, it)   for(auto it=c.begin(); it!=c.end(); it++)
#define clr(a, b)   memset(a, b, sizeof(a))

const int INF = 0x3f3f3f3f;

int n;

int main()
{
#ifdef LOCAL
    freopen("in", "r", stdin);
    //freopen("out", "w", stdout);
#endif

    int cas = 1;
    //scanf("%d", &T);
    while(~scanf("%d",&n))
    {
        if(n < 1200)
            puts("ABC");
        else
            puts("ARC");



    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

double t;

int main(){
	cin>>t;
	cout<<syosu(5)<<t*pi*2<<endl;
}

Measured memory_bytes: 3756
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] dp = new int[n][3];
		int[][] abc = new int[n][3];

		for(int i = 0; i < n; i++) {
			abc[i][0] = sc.nextInt();
			abc[i][1] = sc.nextInt();
			abc[i][2] = sc.nextInt();
		}

		dp[0][0] = abc[0][0];
		dp[0][1] = abc[0][1];
		dp[0][2] = abc[0][2];

		for(int i = 1; i < n; i++) {
			for(int j = 0; j < 3; j++) {
				dp[i][j] = max(dp[i][j], dp[i - 1][(j + 1) % 3] + abc[i][j]);
				dp[i][j] = max(dp[i][j], dp[i - 1][(j + 2) % 3] + abc[i][j]);
			}
		}

		System.out.println(max(max(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]));

		sc.close();
	}

	public static int max(int x, int y) {
		if(x < y) return y;
		else return x;
	}
}


Measured memory_bytes: 101772
#include <iostream>
using namespace std;
int main (){
   
   int n,ass,sum = 0;
   cin>>n>>ass;
  while(ass--){
int num;
cin>>num;
sum+=num;
}
 int max = (n-sum >= 0) ? n-sum : -1; 
cout<<max<<endl;
   return 0;
}

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

int     main() {
        int H, W;
        cin >>H >>W;
        vector<vector<int>> c(10, vector<int> (10));
        for (int i=0; i<10; i++)
                for (int j=0; j<10; j++)
                        cin >>c.at(i).at(j);
        vector<int> A(10, 0);
        for (int i=0; i<H; i++)
                for (int j=0; j<W; j++) {
                        int AA;
                        cin >>AA;
                        if (AA>=0)
                                A.at(AA)++;
                }
        vector<int> L(10, 0);
        vector<bool> Fixed(10, false);
        for (int i=0; i<10; i++)
                L.at(i)=c.at(i).at(1);
        while (true) {
                int LL=100000;
                int CC=-1;
                for (int i=0; i<10; i++) {
                        if (Fixed.at(i)) continue;
                        if (L.at(i)<LL) {
                                LL=L.at(i);
                                CC=i;
                        }
                }
                if (CC==-1)
                        break;
                Fixed.at(CC)=true;
                for (int i=0; i<10; i++) {
                        if (Fixed.at(i)) continue;
                        L.at(i)=min(L.at(i), LL+c.at(i).at(CC));
                }
        }
        int S=0;
        for (int i=0; i<10; i++)
                S += A.at(i)*L.at(i);
        cout <<S <<endl;
        return 0;
};

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int bingo[3][3];
bool flag[3][3];
int cnt[2][105];
int h, w;
int choco[1010][1010];
int s[11][11];

int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	map<int, int>mp;
	rep(i, n) {
		cin >> a[i];
		mp[a[i]]++;
		mp[a[i] - 1]++;
		mp[a[i] + 1]++;
	}
	int ans = 0;
	for (auto p : mp) {
		int x = p.second;
		ans = max(ans, x);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5120
def main():
    n,m,x = map(int, input().split())
    c = [0]*n
    a = [0]*n
    
    for i in range(n):
        line = list(map(int, input().split()))
        c[i] = line[0]
        a[i] = line[1:]
    
    costs = []
    
    def func(i, points, cost, x):
        if i == n:
            if all([point >= x for point in points]):
                costs.append(cost)
            else:
                return None
        
        if all([point >= x for point in points]):
            costs.append(cost)
            return None
        
        func(i+1, points, cost, x)
        func(i+1, [points[j] +a[i][j] for j in range(m)], cost+c[i], x)
    
    func(0, [0]*m, 0, x)
    
    if len(costs) == 0:
        return -1
    
    return min(costs)

print(main())

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

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

    int len = s.length();

    int s_che[26];
    int t_che[26];
    for(int i = 0; i < 26; i++){
        s_che[i] = 0;
        t_che[i] = 0;
    }

    for(int i = 0; i < len; i++){
        s_che[s[i] - 'a']++;
        t_che[t[i] - 'a']++;
    }

    vector<int> s_cou;
    vector<int> t_cou;
    for(int i = 0; i < 26; i++){
        if(s_che[i] != 0){
            s_cou.push_back(s_che[i]);
        }

        if(t_che[i] != 0){
            t_cou.push_back(t_che[i]);
        }
    }

    sort(s_cou.begin(), s_cou.end());
    sort(t_cou.begin(), t_cou.end());
    int s_size = s_cou.size();
    int t_size = t_cou.size();

    int flag = 0;
    if(s_size != t_size){
        flag = 1;
    }else{
        for(int i = 0; i < s_size; i++){
            if(s_cou[i] != t_cou[i]){
                flag = 1;
                break;
            }
        }
    }

    if(flag == 1){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

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

int main(int argc, char const *argv[])
{
   string week[] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
   string S;
   cin >> S;
   int ans;
   for(int i = 0; i < 7; i++)
   {
      if(week[i] == S)
      {
         ans = 7 - i;
      }
   }
   cout << ans << endl;

   return 0;
}


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

using namespace std;

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

	if(S[5] == '0' && S[6] < '5'){
		cout << "Heisei" << endl;
	} else {
		cout << "TBD" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<vector>
#include<utility>
#include<queue>

using namespace std;
#define INF 999999999
typedef pair<int,int> pii;
#define rep(i,n) for(int i=0;i<(n);i++)
vector<vector<char> > inp;
int w,h;

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

struct st{
    pii p;
    int bef;
    int c;
    bool operator < (const st & a) const{
        return this->c > a.c;
    }
};
int cost[65][65][2];

#define y first
#define x second
int solve(vector<pii> poses){
    fill(**cost,**cost+65*65*2,INF);
    int ret = INF;
    priority_queue<st> que;
    for(int i = 0; i < poses.size(); i++) {
        pii pos = poses[i];
        que.push(st{pos,0,0});
        que.push(st{pos,1,0});
        cost[pos.y][pos.x][0] = 0;
        cost[pos.y][pos.x][1] = 0;
    }
    while(que.size()){
        st q = que.top();
        que.pop();
        int val, add;
        val = q.c;
        rep(i,9){
            pii nex = q.p;
            int dir = q.bef ? 1 : -1;
            nex.y += dy[i];
            nex.x += dx[i] * dir;
            int bef = !q.bef;
            if(nex.y<0||nex.x<0||nex.y>=h||nex.x>=w)continue;
            if(inp[nex.y][nex.x] == 'T') {
                ret = min(ret,val);
                continue;
            }
            else if(inp[nex.y][nex.x] == 'S') {
                add = 0;
            }
            else if(inp[nex.y][nex.x] == 'X') {
                continue;
            }
            else {
                add = inp[nex.y][nex.x] - '0';
            }
            if(cost[nex.y][nex.x][bef]>val+add){
                que.push(st{nex,bef,val+add});
                cost[nex.y][nex.x][bef]=val+add;
            }
        }
    }
    if(ret == INF) return -1;
    return ret;
}

int main(){
    while(cin>>w>>h,w||h){
        inp.clear();
        inp.resize(h,vector<char>(w));
        rep(i,h){
            rep(j,w){
                cin>>inp[i][j];
            }
        }
        vector<pii> vp;
        rep(i,h)rep(j,w)if(inp[i][j]=='S')vp.push_back(pii(i,j));
        cout<<solve(vp)<<endl;
    }
 }

Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
int n, m, px, py;
bool vis[maxn + 10];
vector<int> ansl, ansr, g[maxn + 10];
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; ++i) {
		int l, r; scanf("%d%d", &l, &r);
		g[l].push_back(r); g[r].push_back(l);
	}
	vis[px = py = 1] = 1;
	ansl.push_back(1);
	for (;;) {
		bool upd = 0;
		for (int i = 0; i < (int)g[px].size(); ++i) {
			int e = g[px][i];
			if (!vis[e]) {
				ansl.push_back(e); vis[e] = 1;
				px = e; upd = 1;
				break;
			}
		}
		if (upd) continue;
		for (int i = 0; i < (int)g[py].size(); ++i) {
			int e = g[py][i];
			if (!vis[e]) {
				ansr.push_back(e); vis[e] = 1;
				py = e; upd = 1;
				break;
			}
		}
		if (upd) continue;
		break;
	}
	printf("%d\n", (int)(ansl.size() + ansr.size()));
	for (int i = (int)ansl.size() - 1; i >= 0; --i) printf("%d ", ansl[i]);
	for (int i = 0; i < (int)ansr.size(); ++i) printf("%d ", ansr[i]);
}


Measured memory_bytes: 6904
#!/usr/bin/env python3
INF = 10**7
import sys
input = sys.stdin.readline
from collections import*

def bfs():
    q = deque([(sx, sy)])
    dist = [[INF] * W for _ in range(H)]
    dist[sx][sy] = 0
    
    while q:
        x, y = q.popleft()
        b = dist[x][y]
        if (x, y) == (gx, gy):
            return b
        for dx, dy in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
            nx, ny = x + dx, y + dy
            if 0 <= nx < H and 0 <= ny < W and dist[nx][ny] > b and c[nx][ny] == ".":
                dist[nx][ny] = b
                q.appendleft((nx, ny))
        B = b + 1
        for dx in range(-2, 3):
            for dy in range(-2, 3):
                nx, ny = x + dx, y + dy
                if 0 <= nx < H and 0 <= ny < W and dist[nx][ny] > B and c[nx][ny] == ".":
                    dist[nx][ny] = B
                    q.append((nx, ny)) 
    return -1

H, W = map(int, input().split())
cx, cy = map(int, input().split())
dx, dy = map(int, input().split())
sx, sy, gx, gy = cx - 1, cy - 1, dx - 1, dy - 1
c = [input()[:-1] for _ in range(H)]
ans = bfs()
print(ans if ans != INF else -1)

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

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;

int main(){
	int n;
	vector<int> h(100010);
	
	cin >> n;
	vector<long long> cost(100010,INF);

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

	cost[0] = 0;
	cost[1] = abs(h[1]-h[0]);
	for(int i=2; i<n; i++){
		chmin(cost[i],cost[i-1]+abs(h[i]-h[i-1]));
		chmin(cost[i],cost[i-2]+abs(h[i]-h[i-2]));
	}

	cout << cost[n-1] << endl;
}

Measured memory_bytes: 4576
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

N, W = i_l()

values = []
weigth = []
for _ in range(N):
    v, w = i_l()
    values.append(v)
    weigth.append(w)

dp = [[0 for _ in range(10010)] for _ in range(110)]

for i in range(N):
    for w in range(W+1):
        if w >= weigth[i]:
            dp[i+1][w] = max(dp[i][w-weigth[i]]+values[i], dp[i][w])
        else:
            dp[i+1][w] = dp[i][w]


print(dp[N][W])


Measured memory_bytes: 43120
#include<bits/stdc++.h>
using namespace std;
bool vis[10000];
int c=0,g[100][100],n;
void dfs(int v)
{
	if(vis[v])
	return;
	//printf("%d ...",v);
	c++;
	vis[v]=true;
	for(int i=1;i<=n;i++)
	if(g[v][i])
	dfs(i);
}

int main()
{
	int i,j,s=0,u,v,p=1,m,ans=0;
	scanf("%d %d",&n,&m);
	for(i=0;i<m;i++)
	scanf("%d %d",&u,&v),g[u][v]=1,g[v][u]=1;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			for(int k=1;k<=n;k++)
			vis[k]=false;
			if(g[i][j]==1)
			{
				g[i][j]=0;
				g[j][i]=0;
				c=0;
				dfs(1);
				if(c!=n)
				ans++;
				g[i][j]=1;
				g[j][i]=1;
			}
		}
	}
	printf("%d",ans/2);
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int A, B;
    scanf("%d %d", &A, &B);

    int ans = 0;
    for (int i = 0; i < 10000000; i++) {
        int a;
        if (i == 0) {
            a = 1;
        } else {
            a = 0;
        }
        if (a + (A * i) - (i - 1) >= B) {
            ans = i;
            break;
        }
    }

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

    return 0;
}


Measured memory_bytes: 128
s = raw_input()
t = "g"*((len(s)+1)/2)+"p"*(len(s)/2)
ans = 0
for i in range(len(s)):
    if s[i]=="g" and t[i]=="p":
        ans += 1
    if s[i]=="p" and t[i]=="g":
        ans -= 1
print ans


Measured memory_bytes: 5892
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 2000000000;
constexpr ll mod = 1000000007;

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

ll gcd(ll x, ll y) {
	return y ? gcd(y, x%y) : x;
}

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	ll A, B;cin >> A >> B;
	cout << (A * B) / gcd(A, B) << "\n";


	return 0;
}


Measured memory_bytes: 256
S=input()
hantei=False
SS=sorted(S)
if(len(set(S))==2):
    if(SS[0]==SS[1] and SS[0]!=SS[2]):
        hantei=True
    else:
        hantei=False
else:
    hantei=False


if(hantei==True):
    print("Yes")
else:
    print("No")
    

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename X> ostream& operator << (ostream& x,const vector<X>& v){for(ll i=0;i<v.size();++i) x<<v[i]<<" ";return x;}
template <typename X> ostream& operator << (ostream& x,const set<X>& v){for(auto it:v) x<<it<<" ";return x;}
template <typename X, typename Y> ostream& operator << (ostream& x, const pair<X,Y>& v) {x<<v.ff<<" "<<v.ss;return x;}
template <typename T, typename S> ostream& operator << (ostream& os, const map<T, S>& v) { for (auto it : v) os << it.first << "=>" << it.second << endl; return os; }
struct pair_hash {inline std::size_t operator()(const std::pair<ll, ll> & v) const {return v.first*31+v.second;}};
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC targett("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define fr first
#define sc second
#define prnt(m) for(auto it = m.begin() ; it != m.end() ; ++it){cout<<*it<<endl;}
#define tra(it,m) for(auto it=m.begin();it!=m.end();++it)
#define DBG(x) cout<<"# # #     "<<x<<'\n';
#define fri(i,s,n) for(ll i=s;i<n;i++)
#define mod 1000000007LL
#define mod2 998244353
#define vct2 vector<vector<ll>>
#define vct vector<ll>
#define pll pair<ll,ll>
#define rz(n) resize(n)
#define all(v) v.begin(),v.end()
#define mkp make_pair
#define arrin(a,n) for(ll i = 0; i < n ; i++){cin>>a[i];}
#define arrout(a,n) for(ll i = 0;i < n; i++){cout<<a[i]<<" ";}
#define ex(s) cout<<s<<endl,exit(0);
#define inf 4e18
#define five 100005;
#define six 1000005;
#define prllclock cerr<<"Time"<<1000*(ld)clock()(ld)CLOCKS_PER_SEC<<"ms\n";
//_______________________________________________________________________________
int main()
{
              int n,m;
              cin>>n>>m;
              int a[m];
              arrin(a,m);
              int sum = 0;
              fri(i,0,m){sum += a[i];}
              sum -= n;
              sum *= -1;
              if(sum<=-1){cout<<-1;}
              else{cout<<sum<<endl;}
}


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

int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a>b){
        printf("a > b\n");
    }else if(a<b){
        printf("a < b\n");
    }else{
        printf("a == b\n");
    }
    return 0;
}


Measured memory_bytes: 3148
def gcd(a: int, b: int)->int:
    if a < b:
        a, b = b, a
    return a if b == 0 else gcd(b, a % b)


def mysterious_light(N: int, X: int)->int:
    g = gcd(N, X)
    return 3 * max(N-g, g)


if __name__ == "__main__":
    N, X = map(int, input().split())

    ans = mysterious_light(N, X)
    print(ans)


Measured memory_bytes: 3060