akhauriyash/Code-Regression huggingface dataset:
h,w = map(int,input().split())
grid = [list(input()) for i in range(h)]

def judge (y,x):
    if y == 0:
        if x == 0:
            # gridの一番左上 → 右か下が # ならOK
            if grid[y][x+1] == '#' or grid[y+1][x] == '#':
                return True
            else:
                return False
        elif x == w-1:
            # gridの一番右上 → 左か下が # ならOK
            if grid[y][x-1] == '#' or grid[y+1][x] == '#':
                return True
            else:
                return False
        else:
            # girdの一番上列 → 左右か下が # ならOK
            if grid[y][x-1] == '#' or grid[y+1][x] == '#' or grid[y][x+1] == '#':
                return True
            else:
                return False
    elif y == h-1:
        if x == 0:
            # gridの一番左下 → 右か上が # ならOK
            if grid[y][x+1] == '#' or grid[y-1][x] == '#':
                return True
            else:
                return False
        elif x == w-1:
            # gridの一番右下 → 左か上が # ならOK
            if grid[y][x-1] == '#' or grid[y-1][x] == '#':
                return True
            else:
                return False
        else:
            # girdの一番下列 → 左右か上が # ならOK
            if grid[y][x-1] == '#' or grid[y-1][x] == '#' or grid[y][x+1] == '#':
                return True
            else:
                return False
    elif x == 0:
        # grid の一番左列。左上と左下のパターンは考えなくてOK
        if grid[y][x+1] == '#' or grid[y-1][x] == '#' or grid[y+1][x] == '#':
            return True
        else:
            return False
    elif x == w-1:
        # grid の一番右列。右上と右下のパターンは考えなくてOK
        if grid[y][x-1] == '#' or grid[y-1][x] == '#' or grid[y+1][x] == '#':
            return True
        else:
            return False
    else:
        # 端っこの列じゃない場合
        if grid[y+1][x] == '#' or grid[y-1][x] == '#' or grid[y][x+1] == '#' or grid[y][x-1] == '#':
            return True
        else:
            return False

for line in range(h):
    for p in range(w):
        if grid[line][p] == "#":
            if judge (line,p):
                pass
            else:
                print ("No")
                exit ()
print ("Yes")


Measured memory_bytes: 9332
def longest_acgt(t):
    helix = ["A","C","G","T"]
    length = 0
    max_length = 0
    for c in t:
        if c in helix:
            length += 1
        else:
            if max_length < length:
                max_length = length
                length = 0
    if max_length < length:
        max_length = length
    return max_length


t = input()
print(longest_acgt(t))

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

int main() {
    int N;
    string S, T;
    cin >> N;
    cin >> S >> T;
    rep(i, N) cout << S[i] << T[i];
    cout <<'\n';
    return 0;
}


Measured memory_bytes: 256
# solution

import itertools
import numpy as np
from scipy.sparse.csgraph import dijkstra
from scipy.sparse import csr_matrix

int1 = lambda x: int(x) - 1

N, M, R = map(int, input().split())
T = sorted(list(map(int1, input().split())))
A = np.array([tuple(map(int, input().split())) for _ in range(M)]).T

matr = csr_matrix((A[2], (A[0] - 1, A[1] - 1)), shape=(N, N))
way = [dijkstra(matr, indices=t, directed=False)[T].astype(int).tolist() for t in T]

result = float('inf')
for t in itertools.permutations(range(R)):
    tmp = 0
    for i in range(R - 1):
        tmp += way[t[i]][t[i + 1]]
    result = min(result, tmp)
print(result)

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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

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

int main() {
  int h, w, m;
  cin >> h >> w >> m;
  vector<P> hw(m);
  vector<int> hh(h, 0);
  vector<int> ww(w, 0);
  set<P> s;
  rep(i, m) {
    int hhh, www;
    cin >> hhh >> www;
    hhh--;
    www--;
    hh.at(hhh)++;
    ww.at(www)++;
    hw.at(i) = P(hhh, www);
    s.emplace(hhh, www);
  }
  int hMax = -1;
  vector<int> hi;
  int wMax = -1;
  vector<int> wi;
  rep(i, h) {
    if (hh.at(i) > hMax) {
      hMax = hh.at(i);
      hi.clear();
      hi.push_back(i);
    } else if (hh.at(i) == hMax) {
      hi.push_back(i);
    }
  }
  rep(i, w) {
    if (ww.at(i) > wMax) {
      wMax = ww.at(i);
      wi.clear();
      wi.push_back(i);
    } else if (ww.at(i) == wMax) {
      wi.push_back(i);
    }
  }
  int res = hMax + wMax;
  bool cross = true; // 交点に爆破対象
  for (int i : hi) {
    for (int j : wi) {
      if (s.count(P(i, j)) > 0) {
        continue;
      }
      // 爆破対象がない交点があった
      cross = false;
      break;
    }
    if (!cross) {
      break;
    }
  }
  if (cross) {
    res--;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 26152
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)

	x := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&x[i])
	}

	var c int
	for i := 0; i < n; i++ {
		var y int
		fmt.Scan(&y)

		if x[i] > y {
			c += x[i] - y
		}
	}

	fmt.Println(c)
}


Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int gi(){
	int x=0,w=1;char ch=getchar();
	while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
	if (ch=='-') w=0,ch=getchar();
	while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
	return w?x:-x;
}
char s[100005];int n;
int main(){
	scanf("%s",s+1);n=strlen(s+1);
	if (s[1]=='0'||s[n]=='1') return puts("-1"),0;
	for (int i=1;i<n;++i)
		if (s[i]!=s[n-i]) return puts("-1"),0;
	for (int i=n-1,rt=n;i;--i){
		printf("%d %d\n",rt,i);
		if (s[i]=='1') rt=i;
	}
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793
#define all(v) v.begin(),v.end()


ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    if(b==0) return a;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    return a/g*b;
}
ll rep_jijo(ll n,ll x){
    if(x==0) return 1;
    if(x%2==0){
        ll t=rep_jijo(n,x/2);
        return t*t%mod;
    }
    return n*rep_jijo(n,x-1)%mod;
}
 
int main(){
  vector<char>c(9);
  rep(i,9) cin >> c[i];
  cout << c[0] << c[4] << c[8] <<endl;
  return 0;
}


Measured memory_bytes: 256
io = STDIN
s=io.gets.chomp
if s=~/(0[1-9]|1[012])(0[1-9]|1[012])/
  puts 'AMBIGUOUS'
elsif s=~/\d\d(0[1-9]|1[012])/
  puts 'YYMM'
elsif s=~/(0[1-9]|1[012])\d\d/
  puts 'MMYY'
else
  puts 'NA'
end


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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

void dfs(vs& grid,int i,int j,char c)
{
	int h=grid.size(),w=grid[0].size();
	if(i<0 || h<=i || j<0 || w<=j || grid[i][j]!=c) return;
	grid[i][j]='.';
	rep(k,4) dfs(grid,i+"\xff\x1\0\0"[k],j+"\0\0\xff\x1"[k],c);
}

int main()
{
	for(int h,w;cin>>h>>w && h|w;){
		vs grid(h,"#");
		rep(i,h) cin>>grid[i];
		int res=0;
		rep(i,h) rep(j,w) if(grid[i][j]!='.'){
			dfs(grid,i,j,grid[i][j]);
			res++;
		}
		cout<<res<<endl;
	}
}

Measured memory_bytes: 3952
use std::collections::HashSet;

fn main() {
    let n: usize = read();
    let mut claims: Vec<Vec<Vec<usize>>> = vec![vec![vec![]; n - 1]; n];
    for i in 0..n {
        let a: usize = read();
        claims[i] = vec![vec![]; a];
        for j in 0..a {
            claims[i][j] = read_vec();
        }
    }
    let mut ans = 0;

    for i in 0..2usize.pow(n as u32) {
        let mut hone: HashSet<usize> = HashSet::new();
        let mut okk = true;
        for b in 0..n {
            if i & (1 << b) != 0 {
                hone.insert(b);
            }
        }

        'outer: for h in &hone {
            'inner: for j in 0..(claims[*h].len()) {
                if (claims[*h][j][1] == 0 && hone.contains(&(claims[*h][j][0] - 1)))
                    || (claims[*h][j][1] == 1 && !hone.contains(&(claims[*h][j][0] - 1)))
                {
                    okk = false;
                    break 'outer;
                }
            }
        }
        if okk {
            ans = std::cmp::max(ans, hone.len());
        }
    }
    println!("{}", ans);
}

#[allow(dead_code)]
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()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

using ll = long long;
using P = pair<ll,ll>;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")


P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main(){
  int n,a,b;cin>>n>>a>>b;
  cout << min(a,b) << " " << max(0,a+b-n) << endl;
}

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

using namespace std;

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

  int len = s.size();
  int m = len / 2;

  int result = 0;
  for (int i = 0; i < m; i++) {
    if (s[i] != s[len - 1 - i]) {
      result++;
    }
  }

  cout << result << endl;
  
  return 0;
}


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

#define int long long
signed main()
{
    int n,a,b;
    cin>>n>>a>>b;
    if(a==0){
        cout<<"0\n";
        return 0;
    }
    if(b==0){
        cout<<n<<endl;
        return 0;
    }
    int ans=(n/(a+b))*a+min(a,n%(a+b));
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    /* code */
    unsigned int a, b, c; cin >> a >> b >> c;
    if(b>=c) cout << b+c << endl;
    else if(a+b>=c) cout << b+c << endl;
    else cout << a+b +b + 1 << endl;
    return 0;
}


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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000007
#define EPS 1E-12

const int MAX_N = 50000;
int prime[MAX_N];
bool isPrime[MAX_N+1];
int ptr;
int n;
int res[MAX_N+1];

int main()
{
  prime[ptr++] = 2;
  for(int i=3; i<MAX_N; i+=2){
    if(!isPrime[i]){
      prime[ptr++] = i;
      for(int j=2*i; j<MAX_N; j+=i){
        isPrime[j] = true;
      }
    }
  }

  rep(i, ptr) erep(j, i, ptr){
    if(prime[i] + prime[j] > MAX_N) break;
    res[prime[i] + prime[j]] += 1;
  }

  while((cin >> n) && n){
    cout << res[n] << endl;
  }


  /*
  while((cin >> n) && n){
    if(n & 1){
      cout << 0 << endl;
      continue;
    }

    int p = lower_bound(prime, prime+ptr, n) - prime;
    int res = 0;
    rep(i, p){
      if(prime[i] > n - prime[i]) break;
      res += upper_bound(prime, prime+p, n-prime[i]) - lower_bound(prime, prime+p, n-prime[i]);
    }
    cout << res << endl;
  }
  */
  return 0;
}

Measured memory_bytes: 1428
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}

void solve()
{
	string s;
	cin >> s;
	int res = 10000;
	rep(i, sz(s) - 3 + 1){
		int x = atoi(s.substr(i, 3).c_str());
		res = min(res, abs(x - 753));
	}
	cout << res;
}


 
 
int main()
{
    Red;
  	// int T; cin >> T; while(T--)
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define pr pair<ll,ll>
#define MAX 1000000
using namespace std;
typedef long long int ll;
#define mod 998244353
void sync(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}

int main(){
	sync();
	ll m,n;
	cin>>n>>m;
	ll a[n];
	ll sum=0;
	for(ll i=0;i<n;i++)cin>>a[i],sum+=a[i];
	sum=ceil(sum/(4*m+0.0));
	sort(a,a+n,greater<ll>());
	ll tem=0;
	for(ll i=0;i<n;i++)
	{
		if(a[i]<sum)break;
		else tem++;
	}
	if(tem>=m)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    readonly Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int N = cin.nextint;
        int A = cin.nextint;
        int B = cin.nextint;
        var P = cin.scanint;
        var W = new int[3];
        for (int i = 0; i < N; i++)
        {
            if (P[i] <= A)
            {
                W[0]++;
            }
            else if(P[i] <= B)
            {
                W[1]++;
            }
            else
            {
                W[2]++;
            }
        }

        WriteLine(W.Min());

    }

}

class Scanner
{
    string[] s; int i;
    readonly char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
    public void join<T>(IEnumerable<T> values) { WriteLine(string.Join(" ", values)); }
}

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

#define endl '\n'
#define PB push_back
#define PF push_front
#define MP make_pair
#define fi first
#define se second
#define all(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

const int INF = 1e9 + 7;
const ll LINF = 1e18 + 14;

int main(){
    ios_base::sync_with_stdio(false); //cin.tie(nullptr); cout.tie(nullptr);
    string s;
    cin >> s;
    cout << s;
    if (s.back() == 's') {
        cout << "es";
    }
    else {
        cout << "s";
    }
    return 0;
} 


Measured memory_bytes: 3648
#include<stdio.h>

int main(void)
{
	int i,c[7],a[7],b[7];
	for(i=0;i<7;i++){
		scanf("%d %d",&a[i],&b[i]);
		c[i]=a[i]-b[i];
	}
	for(i=0;i<7;i++){
		printf("%d\n",c[i]);
	}
	return 0;
}


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

struct Edge {
  int to, cost;
};
vector<vector<Edge>> es;
typedef pair<long long, int> T;
void dijkstra(int s, int dst, vector<long long>& dist, int v1, int v2) {
  priority_queue<T, vector<T>, greater<T>> pq;
  pq.emplace(0, s);
  dist[s] = 0;
  while (!pq.empty()) {
    T t = pq.top();pq.pop();
    long long cost = t.first;
    int v = t.second;
    if (v == dst) break;
    for (const auto& e : es[v]) {
      if (v == v1 && e.to == v2 || v == v2 && v1 == e.to) continue;
      long long nextcost = cost + e.cost;
      if (dist[e.to] > nextcost) {
        pq.emplace(nextcost, e.to);
        dist[e.to] = nextcost;
      }
    }
  }
}

int main(void) {
  int N;
  cin >> N;
  es.resize(N);
  vector<vector<int>> A(N, vector<int>(N));
  priority_queue<tuple<int,int,int>> pq;

  long long ret = 0;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      cin >> A[i][j];
      if (i > j) {
        es[i].push_back(Edge{j, A[i][j]});
        es[j].push_back(Edge{i, A[i][j]});
        pq.emplace(A[i][j], i, j);
        ret += A[i][j];
      }
    }
  }
  vector<vector<int>> orgA = A;

  vector<vector<int>> count(N, vector<int>(N));
  for (int k = 0; k < N; k++) {
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        A[i][j] = min(A[i][j], A[i][k] + A[k][j]);
        if (A[i][j] == A[i][k] + A[k][j]) {
          if (i != k && j != k) {
            if (A[i][j] == A[i][k] + A[k][j])
              count[i][j]++;
          }
        }
      }
    }
  }
  bool ok = true;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      if (A[i][j] != orgA[i][j]) ok = false;
    }
  }
  if (!ok) {
    cout << -1 << endl;
    return 0;
  }

  while (!pq.empty()) {
    vector<long long> dist(N);
    fill(dist.begin(), dist.end(), 1e18);
    tuple<int,int,int> t = pq.top(); pq.pop();
    int val = get<0>(t);
    int v1 = get<1>(t), v2 = get<2>(t);
    // dijkstra(v1, v2, dist, v1, v2);
    if (count[v1][v2]) {
      ret -= val;
    }
  }
  cout << ret << endl;

  return 0;
}

Measured memory_bytes: 3128
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		int xs = Integer.parseInt(sa[0]);
		int ys = Integer.parseInt(sa[1]);
		int xt = Integer.parseInt(sa[2]);
		int yt = Integer.parseInt(sa[3]);
		int n = Integer.parseInt(br.readLine());
		Node[] arr = new Node[n + 2];
		Node ns = new Node();
		ns.x = xs;
		ns.y = ys;
		arr[0] = ns;
		Node nt = new Node();
		nt.v = n + 1;
		nt.x = xt;
		nt.y = yt;
		nt.d = 1e18;
		arr[n + 1] = nt;
		for (int i = 1; i <= n; i++) {
			sa = br.readLine().split(" ");
			Node node = new Node();
			node.v = i;
			node.x = Integer.parseInt(sa[0]);
			node.y = Integer.parseInt(sa[1]);
			node.r = Integer.parseInt(sa[2]);
			node.d = 1e18;
			arr[i] = node;
		}
		br.close();

		double[][] d = new double[n + 2][n + 2];
		for (int i = 0; i <= n + 1; i++) {
			for (int j = 0; j <= n + 1; j++) {
				if (i != j) {
					double c = Math.hypot(arr[i].x - arr[j].x, arr[i].y - arr[j].y) - arr[i].r - arr[j].r;
					c = Math.max(c, 0);
					d[i][j] = c;
					d[j][i] = c;
				}
			}
		}

		Set<Integer> set = new HashSet<>();
		for (int i = 0; i <= n + 1; i++) {
			set.add(i);
		}
		double[] dist = new double[n + 2];
		Arrays.fill(dist, 1e18);
		dist[0] = 0;
		PriorityQueue<Node> que = new PriorityQueue<Node>();
		Node first = arr[0];
		que.add(first);
		while (!que.isEmpty()) {
			Node cur = que.poll();
			if (set.remove(cur.v)) {
				for (int i : set) {
					double alt = cur.d + d[cur.v][i];
					if (dist[i] > alt) {
						dist[i] = alt;
						Node next = new Node();
						next.v = i;
						next.d = alt;
						que.add(next);
					}
				}
			}
		}
		System.out.println(dist[n + 1]);
	}

	static class Hen {
		int v, c;

		public Hen(int v, int c) {
			this.v = v;
			this.c = c;
		}
	}

	static class Node implements Comparable<Node> {
		int v, x, y, r;
		double d;

		public int compareTo(Node o) {
			return Double.compare(d, o.d);
		}
	}
}


Measured memory_bytes: 66620
#undef NDEBUG
#include <bits/stdc++.h>

using namespace std;

#define all(v) (v).begin(), (v).end()

using li = long long;
using ld = long double;

void solve(bool);

int main() {
#ifdef YA
    auto s = clock();
    assert(freopen("input.txt", "r", stdin));
    // assert(freopen("output.txt", "w", stdout));
#else
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
#endif

    cout << fixed << setprecision(20);

    srand(time(0));
    solve(true);

#ifdef YA1
    while (true) solve(false);
#endif

#ifdef YA
    cout << endl << endl << "time = " << (clock() - s) / (double)CLOCKS_PER_SEC << endl;
#endif

    return 0;
}

const int maxn = 1e3 + 555;

int n;
int d[maxn][maxn];
vector <int> g[maxn];

int bfs(int st) {
    vector <int> d(n + 5, -1);
    vector <int> q;
    d[st] = 0;
    q.push_back(st);
    int l = 0;
    while (l < (int)q.size()) {
        int v = q[l++];
        for (int to : g[v]) {
            if (d[to] == -1) {
                q.push_back(to);
                d[to] = d[v] + 1;
            }
        }
    }
    return q.back();
}

void bfs1(int st) {
    vector <int> d(n + 5, -1);
    vector <int> q;
    d[st] = 0;
    q.push_back(st);
    int l = 0;
    while (l < (int)q.size()) {
        int v = q[l++];
        for (int to : g[v]) {
            if (d[to] == -1) {
                q.push_back(to);
                d[to] = d[v] + 1;
                continue;
            }
            if (d[to] == d[v] - 1 || d[to] == d[v] + 1) {
                continue;
            }
            if (d[to] == d[v]) {
                cout << "-1" << endl;
                return;
            }
            assert(false);
        }
    }
    cout << d[q.back()] + 1 << endl;
}

const int inf = 1e9;

void solve(bool __attribute__((unused)) read) {
    cin >> n;
    for (int i = 0; i < n; ++i) {
        string s;
        cin >> s;
        for (int j = 0; j < n; ++j) {
            if (s[j] == '1') {
                g[i].push_back(j);
                d[i][j] = 1;
            } else {
                d[i][j] = inf;
            }
        }
        d[i][i] = 0;
    }
    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 mx = 0;
    int v = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (d[i][j] > mx) {
                mx = d[i][j];
                v = i;
            }
        }
    }
    bfs1(v);
}


Measured memory_bytes: 1408
#include <numeric>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>

using namespace std;

using ll = long long;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)

#define input(...) __VA_ARGS__; in(__VA_ARGS__)

#if __has_include("debugger.cpp")
  #include "debugger.cpp"
#else
void print() {
  std::cout << std::endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  cout << head;
  if (sizeof...(tail) > 0) cout << " ";
  print(std::forward<Tail>(tail)...);
}
# endif

void in() { }

template <class Head, class... Tail>
void in(Head&& head, Tail&&... tail) {
  cin >> head;
  in(std::forward<Tail>(tail)...);
}

int main() {
  ll input(n, k);
  vector<ll> a(n);
  REP(i, n) cin >> a[i];
  if (*max_element(a.begin(), a.end()) < k) {
    print("IMPOSSIBLE");
    return 0;
  }
  ll p = a[0];
  REP(i, n - 1) {
    p = gcd(p, a[i + 1]);
  }
  print(k % p == 0 ? "POSSIBLE" : "IMPOSSIBLE");
}


Measured memory_bytes: 3948
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define mp make_pair
// GCD inbuilt func: __gcd(a,b)
// LCM formula: (a*b)/__gcd(a,b)

int main(){
	ios::sync_with_stdio(false);
    cin.tie(NULL);
	// CODE goes here
    ll x,k,d;
    cin >> x >> k >> d;
    x=abs(x);
    if(x/d==0){
    	if(k%2) cout << abs(x-d);
    	else cout << x;
    }
    else{
    	if(k<=x/d){
    		cout << x-k*d;
    		return 0;
    	}
    	if((k-(x/d))%2==0) cout << x-(x/d)*d;
    	else cout << abs(x-(x/d)*d-d);
    }
	return 0;
}


Measured memory_bytes: 3688
// http://koturn.hatenablog.com/entry/2016/02/04/050000#cpp
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  int N, A, B;
  cin >> N >> A >> B;
  int trainTotal;
  trainTotal = N * A;
  if (trainTotal > B)
  {
    cout << B << endl;
  }
  else
  {
    cout << trainTotal << endl;
  }

  return EXIT_SUCCESS;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#undef int
#define mk make_pair
#define pb push_back
#define pf push_front
typedef pair<int, int> pii;
const int mod = 1000000007;
const int INF = 1000000009;
const long long INFL = 1000000000000000018ll;

int N, a[100100];
int sum, dif[100100];

signed main()
{
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        sum += a[i];
    }
    int s = N * (N + 1) / 2;
    if(sum % s){
        printf("NO\n");
        return 0;
    }
    int num = sum / s;
    a[N] = a[0];
    for(int i = 0; i < N; i++){
        dif[i] = a[i + 1] - a[i];///差を取る
        dif[i] -= num;///操作の回数だけ差が+1されていると考えてみると1-Nの回数だけ無駄に-1されることになる。
        if(dif[i] > 0){
            printf("NO\n");
            return 0;
        }
        dif[i] = -dif[i];
        if(dif[i] % N){
            printf("NO\n");
            return 0;
        }
    }
    int cnt = 0;
    for(int i = 0; i < N; i++){
        cnt += dif[i] / N;
    }
    if(cnt == num){
        printf("YES\n");
    }
    else {
        printf("NO\n");
    }


    return 0;
}
/*


*/




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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }
template<typename A, size_t N, typename T>
void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

int a, b, c;
void solve() {
    cin >> a >> b >> c;

    if (a == b && a != c || b == c && a != b || c == a && a != b) cout << "Yes" << endn;
    else cout << "No" << endn;

}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    cout << flush;
    return 0;
}


Measured memory_bytes: 256
def inpl(): return [int(i) for i in input().split()]

N = int(input())
H = inpl()
ans = 0
while True:
    ctr = 1
    for i in range(N):
        if H[i]:
            ans += ctr
            ctr = 0
            H[i] -= 1
        else:
            ctr = 1
    if not any(H):
        break
print(ans)

Measured memory_bytes: 3060
#include <stdio.h>

int main(void)
{
    int i, a, b, n, s, x, sum=0;

    scanf("%d%d%d", &n, &a, &b);

    for (i=1; i<=n; i++) {
        x = i;
        s = x%10;
        while (x/10>0) {
            x /= 10;
            s += x%10;
        }

        if (s>=a && s<=b)
            sum += i;
    }

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

    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;


int main() {
  int k, a, b;
  cin >> k >> a >> b;
  string ans = "NG";
  for(int i=a;i<=b;i++){
    if (i % k == 0) ans = "OK";
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3628
from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
    return int(input())

def rl():
    return list(map(int, input().split()))


def solve():
    x = ri()
    steps = 0
    bal = 100
    while bal < x:
        steps += 1
        bal += bal // 100
    print (steps)






mode = 's'

if mode == 'T':
    t = ri()
    for i in range(t):
        solve()
else:
    solve()


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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;

typedef unsigned long long ll;

const long long MOD = 1000000000 + 7;

//For DP
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;
}

//Union-Find tree
struct UnionFind{
    vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N;  i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る : root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    
    void unite(int x, int y) { //xとyの木を併合
        int rx = root(x); //xの木の根をrx
        int ry = root(y); //yの木の根をyx
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)ときはそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時 : xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};



int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    int cnt = 0;
    int max_cnt = 0;
    rep(i,n){
        if(s[i] ==  'I') cnt += 1;
        if(s[i] == 'D') cnt -= 1;
        chmax(max_cnt,cnt);
    }
    cout << max_cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<cmath>
#include<string>

#define ls (t<<1)
#define rs ((t<<1)+1)
#define mid ((l+r)>>1)
#define fi first
#define se second
#define mk make_pair
#define pb push_back

#define N 600005
#define M 200005
#define seed 23333
#define Mo 924844033

using namespace std;
int i,j,m,n,p,k,g,pr[M],fac[N],inv[N],NN,w[2][N],size[N],A[N],B[N],fa[N],x,y,rev[N],D[N];
vector<int>v[M];
int power(int x,int y,int mod)
{
		int sum=1;
		for (;y;y>>=1)
		{
				if (y&1) sum=1ll*sum*x%mod;
				x=1ll*x*x%mod;
		}
		return sum;
}
void mkprime(int x)
{
		int i;
		for (i=2;i*i<=x;++i)
			if (x%i==0)
			{
					pr[++pr[0]]=i;
					while (x%i==0) x/=i;
			}
		if (x>1) pr[++pr[0]]=x;
}
int judge(int x)
{
		if (power(x,Mo-1,Mo)!=1) return 0;
		int i;
		for (i=1;i<=pr[0];++i)
			if (power(x,(Mo-1)/pr[i],Mo)==1) return 0;
		return 1;
}
int Findg(int x)
{
		int i;
		mkprime(x-1);
		for (i=2;i<x;++i)
			if (judge(i)) return i;
		return -1;
}
void dfs(int x)
{
		int i;
		for (i=0;i<(int)v[x].size();++i)
		{
				int p=v[x][i];
				if (fa[x]==p) continue;
				fa[p]=x;
				dfs(p);
				size[x]+=size[p];
				A[size[p]]++;
		}
		size[x]++;
		A[n-size[x]]++;
}
int C(int x,int y)
{
		return 1ll*fac[x]*inv[y]%Mo*inv[x-y]%Mo;
}
void NTT(int *A,int f)
{
		int i,j,k,l,t;
		for (i=0;i<NN;++i) if (i<rev[i]) swap(A[i],A[rev[i]]); 
		for (i=1;i<NN;i<<=1)
			for (j=0,t=NN/(i<<1);j<NN;j+=(i<<1))
				for (k=0,l=0;k<i;++k,l+=t)
				{
						int x=A[j+k],y=1ll*A[j+k+i]*w[f][l]%Mo;
						A[j+k]=(x+y)%Mo; A[j+k+i]=(x-y+Mo)%Mo;
				}
		if (f)
		{
				int invn=power(NN,Mo-2,Mo);
				for (i=0;i<NN;++i) A[i]=1ll*A[i]*invn%Mo; 
		}
}
int main()
{
		g=Findg(Mo);
		fac[0]=1;
		for (i=1;i<N;++i) fac[i]=1ll*fac[i-1]*i%Mo;
		inv[N-1]=power(fac[N-1],Mo-2,Mo);
		for (i=N-2;i>=0;--i) inv[i]=1ll*inv[i+1]*(i+1)%Mo;
		scanf("%d",&n); for (NN=1;NN<n;NN<<=1); NN<<=1; 
		w[0][0]=1; w[0][1]=power(g,(Mo-1)/NN,Mo);
		for (i=2;i<N;++i) w[0][i]=1ll*w[0][i-1]*w[0][1]%Mo;
		for (i=0;i<N;++i) w[1][i]=power(w[0][i],Mo-2,Mo);
		for (i=1;i<n;++i)
		{
				scanf("%d%d",&x,&y);
				v[x].pb(y); v[y].pb(x);
		}
		dfs(1);
		for (i=0;i<n;++i) B[i]=inv[i];
		for (i=0;i<n;++i) A[i]=1ll*A[i]*fac[i]%Mo;
		A[0]=0;
 		for (i=0;i<=n;++i) if (i<n-i) swap(A[i],A[n-i]);
 		for (i=0;i<NN;++i) 
 		{
 				for (j=1,k=i;j<NN;j<<=1,k>>=1) (rev[i]<<=1)|=(k&1);
 		}
		NTT(A,0); NTT(B,0); 
 		for (i=0;i<NN;++i) A[i]=1ll*A[i]*B[i]%Mo;
		NTT(A,1);
		for (i=0;i<=n;++i) if (i<n-i) swap(A[i],A[n-i]);
		for (i=1;i<=n;++i) A[i]=1ll*A[i]*inv[i]%Mo;
		for (i=1;i<=n;++i) A[i]=(1ll*n*C(n,i)%Mo-A[i]+Mo)%Mo;
		for (i=1;i<=n;++i) printf("%d\n",A[i]); 
}


Measured memory_bytes: 43520
#include <iostream>

int main()
{
	int a, b;
	std::cin >> a >> b;
		if (a*b % 2 == 0) {
			std::cout << "Even\n";
		}
		else if (a*b % 2 == 1) {
			std::cout << "Odd\n";
		}
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
#include<map>
#include<set>
using namespace std;
#define INF 11000000000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;

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

  if(A%3==0 || B%3==0 || (A+B)%3==0) cout<<"Possible"<<endl;
  else cout<<"Impossible"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int n;
    cin >> n;
    vector<ll>a(n);
    rep(i,n)cin >> a[i];
    int ans = 0;
    int now = 0;
    rep(i,n){
        if(i == 0)continue;
        if(now == 0 && a[i]>a[i-1])now = 1;
        else if(now == 0 && a[i] < a[i-1])now = -1;
        
        if(a[i]>a[i-1] && now == -1){
            ans++;
            now = 0;
        }else if(a[i]<a[i-1] && now == 1){
            ans++;
            now = 0;
        }
        
    }
    cout << ans+1 << endl;
    return 0;
}

Measured memory_bytes: 3960
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int n,s,ans;

void dfs(int k,int now,int m){
	if(k==n){
		if(now==s) ans++;
		return;
	}
	rep(i,m+1,10){
		dfs(k+1,now+i,i);
	}
	return;
}


signed main(){
	while(1){
		cin>>n>>s;
		if(n+s==0) break;
		ans=0;
		dfs(0,0,-1);
		o(ans);
	}
}

Measured memory_bytes: 1156
{-# LANGUAGE FlexibleInstances    #-}
{-# LANGUAGE TypeSynonymInstances #-}

import           Control.Applicative
import           Control.DeepSeq
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                  as A
import qualified Data.Array.IArray           as IA
import qualified Data.Array.IO               as AI
import qualified Data.Array.MArray           as MA
import qualified Data.Array.ST               as STA
import qualified Data.Array.Unboxed          as AU
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import qualified Data.Graph                  as G
import           Data.Int
import qualified Data.IntMap                 as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Sequence               as SQ
import qualified Data.Set                    as S
import           Data.Time
import qualified Data.Tree                   as T
import qualified Data.Vector                 as V
import qualified Data.Vector.Mutable         as VM
import qualified Data.Vector.Unboxed         as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt :: IO [Int]
readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

readInts :: Int -> IO [[Int]]
readInts n = replicateM n readInt

readInteger :: IO [Integer]
readInteger = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

readIntegers :: Int -> IO [[Integer]]
readIntegers n = replicateM n readInteger

readString :: IO [String]
readString = map BS.unpack . BS.words <$> BS.getLine

readStrings :: Int -> IO [[String]]
readStrings n = replicateM n <$> readString

toPair :: [a] -> (a, a)
toPair [x, y] = (x, y)

count :: Eq a => a -> [a] -> Int
count a as = length $ filter (== a) as

put :: Show a => a -> IO ()
put = putStr . show

putLn :: Show a => a -> IO ()
putLn = print

putList :: Show a => [a] -> IO ()
putList [n] = put n
putList (n:ns) = do
  put n
  putStr " "
  putList ns

putStrList :: [String] -> IO ()
putStrList [n] = putStr n
putStrList (n:ns) = do
  putStr n
  putStr " "
  putStrList ns

yesNoUpper b
  | b = putStrLn "YES"
  | otherwise = putStrLn "NO"

yesNo b
  | b = putStrLn "Yes"
  | otherwise = putStrLn "No"

main = do
  [n, m] <- readInt
  put $ (n - 1) * (m - 1)


Measured memory_bytes: 380
import java.io.*;
import java.util.*;

public class Main {
  private static String solve(int a, int b) {
    int min = Math.min(a, b);
    int max = Math.max(a, b);
    StringBuffer sb = new StringBuffer();
    for (int i = 0; i < max; i++) {
      sb.append(min);
    }
    return sb.toString();
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int a = reader.nextInt();
    int b = reader.nextInt();
    out.println(solve(a, b));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 21204
def solve(a, b, n):
    def f(x):
        return a*x//b - a*(x//b)
    y = min(b-1,n)
    return max(f(y-i) for i in range(min([a,b,n])))
assert solve(5, 7, 4) == 2
assert solve(11, 10, 9) == 9

a, b, n = map(int, input().split())
print(solve(a, b, n))

Measured memory_bytes: 9112
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = b - 1; i >= a; i--)
#define ALL(a) a.begin(), a.end()
#define pii pair<int,int>
#pragma GCC optimize("Ofast")
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
template<class T>bool chmax(T &a, const T &b) {if(a<b){a = b; return 1;} return 0; };
template<class T>bool chmin(T &a, const T &b) {if(a>b){a = b; return 1;} return 0; };
inline void IN(void){return;}
template <typename First, typename... Rest> void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
inline void OUT(void){cout << "\n";return;}
template <typename First, typename... Rest> void OUT(First first, Rest... rest){cout << first << " ";OUT(rest...);return;}
const double EPS = 1e-9;
const int mod = 1e9 + 7;
const int INF = 1e9;
const long long LLINF = 1e18;
long long lcm(ll a, ll b){return a * b / __gcd(a,b);}
struct IoSetup { IoSetup() {
    cin.tie(nullptr);ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
} } iosetup;
template< int mod > struct ModInt {
    int x; ModInt() : x(0) {}
    ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) {if((x += p.x) >= mod) x -= mod;return *this;}
    ModInt &operator-=(const ModInt &p) {if((x += mod - p.x) >= mod) x -= mod;return *this;}
    ModInt &operator*=(const ModInt &p) {x = (int) (1LL * x * p.x % mod);return *this;}
    ModInt &operator/=(const ModInt &p) {*this *= p.inverse();return *this;}
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) { t = a / b; swap(a -= t * b, b); swap(u -= t * v, v); }return ModInt(u);}
    ModInt pow(int64_t n) const {ModInt ret(1), mul(x); while(n > 0) {if(n & 1) ret *= mul;mul *= mul;n >>= 1;}return ret;}
    friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x;}
    friend istream &operator>>(istream &is, ModInt &a) { int64_t t; is >> t; a = ModInt< mod >(t); return (is); }
    static int get_mod() { return mod; }
}; using modint = ModInt< mod >;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
    iosetup;
    int N; cin >> N;
    int t = N;
    int cnt = 0;
    while(t > 0){
        cnt += t % 10;
        t /=10;
    }
    if(N % cnt == 0) puts("Yes");
    else puts("No");

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long X = sc.nextLong();
		long K = sc.nextLong();
		long D = sc.nextLong();
		if (X < 0) X = -X;
		if (X * 1.0 / D > K) {
			System.out.println(X - K * D);
			return;
		}
		if ((X / D + K % 2) % 2 == 0) {
			System.out.println(X % D);
		} else {
			System.out.println(Math.abs(X % D - D));
		}
	}
}


Measured memory_bytes: 35652