akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (long long  i=a;i<n;i++)
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
map<int, int> cnt;
bool is_prime(long long x) {
	if (x == 1)
		return false;
	if (x == 2 || x == 3)
		return true;
	if (x % 6 != 1 && x % 6 != 5)
		return false;
	int s = sqrt(x);
	for (int i = 5; i <= s; i += 6)
		if (x%i == 0 || x % (i + 2) == 0)
			return false;
	return true;
}

void pfc(long long n, unordered_set<int> &st) {//快速质因数分解 
	
	long long i = 0;
	if (n == 1)
	{
		st.insert(1);
		return ;
	}
	while (i<n)
	{
		if (is_prime(n)) {
			st.insert(n);
			return ;
		}
		for (i = 2; i<n; i++)
		{
			if (n%i == 0)
			{
				st.insert(i);
				n /= i;
				break;
			}

		}
	}
	st.insert(n);
	
	return ;
}
int Gcd(int a, int b)
{
	if (0 == b) return a;
	else return Gcd(b, a % b);
}
void solve() {
	int n;
	cin >> n;
	VI a(n);
	rep(i, 0, n)cin >> a[i];
	int NG = a[0];
	for (int i = 1; i < n; i++) {
		NG = Gcd(NG, a[i]);
	}
	for (int i = n - 1; i >= 0; i--) {
		unordered_set<int> st;
		pfc(a[i], st);
		for (auto v : st) {
			if (v == 1)continue;
			if (cnt.count(v)) {
				if (NG == 1) {
					cout << "setwise coprime";
					return;
				}
				cout << "not coprime";
				return;
			}
			cnt[v]++;
		}
	}
	cout << "pairwise coprime";
//	return;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int T_ = 1;
	//cin >> T_;
	for (int i = 0; i < T_; i++)solve();
	return 0;
}



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

int main() {
    int x, a, b;  cin >> x >> a >> b;
    cout << x - a - b*((x - a) / b) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
using namespace std;
#define ll long long ;

int a, b, x, c;

int cha(int x){
	int n = 10000;
	int s;
	int y[4];
	for (int i = 0; i < 4; i++)
	{
		y[i] = x / n;
		x = x % n;
		n = n / 10; 
	}
	s = x * 10000 + y[3] * 1000 + y[2] * 100 + y[1] * 10 + y[0];
	return s;
}


int main(){
	cin >> a >> b;
	for (int i = a; i <= b; i++){
		if (cha(i) == i) c++;
	}
	cout << c << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ed cout<<"\n";
using namespace std;

int main() {
  speed;
	int n;
	int h[20];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> h[i];
	}
	int ans=1;
	for (int i = 1; i < n; i++) {
		int count = 0;
		for (int j = i-1; j >= 0; j--) {
			if (h[i] - h[j] >= 0)count++;
          else{
            count=0;
            break;
          }
		}
		if (count >0 )ans++;
	}
		cout << ans ;
  ed;
	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
import math
from decimal import Decimal
'''
A, B = map(str, sys.stdin.readline().split())
A = Decimal(A)
B = Decimal(B)
print(A * B//1)
'''
A, B = map(str, sys.stdin.readline().split())
A = int(A)
B = int(float(B)*100+0.5)
print(A*B//100)

Measured memory_bytes: 9920
def calc(l):
    if l == "":
        return 0

    left = l.count("<")
    right = l.count(">")

    if left == 0:
        return right * (right + 1) // 2

    if right == 0:
        return left * (left + 1) // 2

    return left * (left - 1) // 2 + right * (right - 1) // 2 + max(right, left)

def f():
    S = input()
    res = 0
    l = ""
    for s in S:
        if l == "":
            l += s
            continue

        if l[-1] == ">" and s == "<":
            res += calc(l)
            l = "<"
        else:
            l += s
    res += calc(l)
    print(res)


if __name__ == '__main__':
    f()


Measured memory_bytes: 4212
#include <bits/stdc++.h>
#include <iomanip>
#include <algorithm>
#define ll long long
#include <unordered_map>
using namespace std;
 
int main() {
  ll N, prod = 1;
  bool zerojudge = 0, overflowjudge = 0;
  cin >> N;
  vector<ll> A(N);
  for(ll i = 0; i < N; i++) {
    cin >> A.at(i);
    if(A.at(i) == 0) {
      cout << 0 << endl;
      zerojudge = 1;
    }
  }
  if(zerojudge == 0) {
    for(ll i = 0; i < N; i++) {
      if(A.at(i) <= 1000000000000000000 / prod) prod *= A.at(i);
      else {
        overflowjudge = 1;
        break;
      }
    }
    if(overflowjudge == 0) cout << prod << endl;
    else cout << -1 << endl;
  }
}


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

int main(){
    double a, b;
    cin >> a >> b;
    int ans = 10000;
    for (int i = 1; i < 10000;i++){
        if(int((double)i * 0.08) == a && int((double)i * 0.1) == b && ans > i)
            ans = i;
    }
    if(ans == 10000)
        ans = -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
pf = {}
ans = 1
m = int(input())
for i in range(2, m+1):
    for j in range(2, int(i**0.5)+1):
        while i%j==0:
            pf[j]=pf.get(j,0)+1
            i//=j
    if i>1:
        pf[i]=pf.get(i,0)+1

for v in pf.values():
    ans *= v+1
print(ans%(10**9+7))


Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long 

int main(int argc, char const *argv[]){
	char str[24];
	scanf("%s",str);
	str[6 - 1] = ' ';
  	str[14 - 1] = ' ';
  	printf("%s",&str);
}


Measured memory_bytes: 128
menu = [ int(input()) for i in range(5)]
menu_per = []
for j in menu:
  if j % 10 != 0:
    menu_per.append(10 - (j % 10))
  else:
    menu_per.append(0)
ans = sum(menu) + sum(menu_per)
max_menu_per = max(menu_per)
ans = ans - max_menu_per
print(ans)

    

Measured memory_bytes: 3060
a, b, k = map(int, input().split())
for i in range(k):
    if(i%2):
        #b
        if(b%2):
            b -=1
        a += b//2
        b = b // 2
    else:
        if(a%2):
            a -=1
        b += a//2
        a = a // 2
print(a, b)

Measured memory_bytes: 2940
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

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

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL n;
    cin>>n;
    VL p(n);
    REP(i,n)cin>>p[i];
    bool yes = false;
    VL x = p;
    SORT(x);
    REP(i,n){
        FOR(j, i + 1, n){
            swap(p[i], p[j]);
            if(p == x){
                yes = true;
                goto END;
            }
            swap(p[i], p[j]);
        }
    }
END:
    if(x == p)yes = true;
    PUTS(yes ? "YES" : "NO");
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <map>
#define ll long long
#define REP(i, x) for(int (i) = 0; (i) < (x); (i) ++)
#define pi 3.1415926535
const int MOD = 1000000007;
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (b - a == c - b) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
class Point
  def initialize(x, y)
    @x, @y = x, y
  end

  def +(other)
    Point.new(other.x + @x, other.y + @y)
  end

  def -(other)
    Point.new(@x - other.x, @y - other.y)
  end

  def *(number)
    Point.new(@x * number, @y * number)
  end

  def /(number)
    Point.new(@x / number, @y / number)
  end

  def description
    "#{"%.8f"%(@x)} #{"%.8f"%(@y)}"
  end

  attr_reader :x, :y
end

class Line
  def initialize(start_point, end_point)
    @start_point = start_point
    @end_point = end_point
  end

  def koch_curve
    line1, line2, line3 = trisect
    s = line2.start_point
    t = line2.end_point
    radian = (radian(s, t) * 180.0 / Math::PI - 120) * Math::PI / 180.0
    ux = Math.cos(radian) * line2.length + s.x
    uy = Math.sin(radian) * line2.length + s.y
    u = Point.new(ux, uy)
    line2_1 = Line.new(line2.start_point, u)
    line2_2 = Line.new(u, line2.end_point)
    return line1, line2_1, line2_2, line3
  end

  def radian(t, s)
    Math.atan2(t.y - s.y, t.x - s.x)
  end

  def length
    a = @end_point.x - @start_point.x
    b = @end_point.y - @start_point.y
    Math.sqrt(a ** 2 + b ** 2)
  end

  def trisect
    diff = @end_point - @start_point
    line2 = Line.new @start_point + diff / 3.0, @start_point + diff / 3.0 * 2
    line1 = Line.new @start_point, line2.start_point
    line3 = Line.new line2.end_point, @end_point
    return line1, line2, line3
  end

  attr_reader :start_point, :end_point
end

n = gets.to_i
lines = [Line.new(Point.new(0.0, 0.0), Point.new(100.0, 0.0))]
n.times do
  lines = lines.flat_map{|l| l.koch_curve}
end

puts lines.first.start_point.description
lines.each {|l| puts l.end_point.description}

Measured memory_bytes: 9284
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n;
    cin>>n;
    vector<string> s(n);
    rep(i,n){
        cin>>s[i];
        sort(all(s[i]));
    }

    sort(all(s));

    ll ans=0;
    ll cnt=1;
    rep(i,n-1){
        if(s[i]!=s[i+1]){
            ans+=cnt*(cnt-1)/2;
            cnt=1;
        }
        else cnt++; 
    }
    ans+=cnt*(cnt-1)/2;

    cout<<ans<<endl;
}


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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 10000000000
#define MOD 1000000007
using ll = long long;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
using Graph = vector<vector<int>>;


vector<ll> x,y;
int N;

ll f0(int i){
    return x[i] - y[i]; 
}

ll f1(int i){
    return x[i] + y[i]; 
}

int main(){
    cin>>N;
    x.resize(N);
    y.resize(N);
    rep(i,N){
        cin>>x[i]>>y[i];
    }
    ll f0max,f0min,f1max,f1min;
    rep(i,N){
        if(i==0){
            f0max=f0(i);
            f0min=f0(i);
            f1max=f1(i);
            f1min=f1(i);
        }else{
            f0max=max(f0max,f0(i));
            f0min=min(f0min,f0(i));
            f1max=max(f1max,f1(i));
            f1min=min(f1min,f1(i));
        }
    }
    cout<<max(f0max-f0min,f1max-f1min)<<endl;
}


Measured memory_bytes: 6348
#include<cstdio>
#include<string>
#include<cstring>
using namespace std;
int A,B,k,a,b;
int main()
{
	scanf("%d%d%d",&A,&B,&k);
	for (int i=1;i<=k;++i)
	if (i&1){
		if (A&1) --A;A/=2,B+=A;
	}else{
		if (B&1) --B;B/=2,A+=B;
	}
	printf("%d %d\n",A,B);return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include <iostream>

#ifndef U_L_LONG
typedef unsigned long long ULLONG;
#endif
#ifndef L_LONG
typedef long long LLONG;
#endif
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}

template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}

static void ABC090C_FlipFlip();

#if 1
int main()
{
	ABC090C_FlipFlip();
	fflush(stdout);
	return 0;
}
#endif

static void ABC090C_FlipFlip()
{
	LLONG N, M;
	get2int<LLONG>(N, M);

	LLONG even = 0;
	if ((N > 1) && (M > 1)) {
		even = (N + M - 2) * 2;
	}
	else if ((N * M) == 1) {
		even = 0;
	}
	else {
		even = 2;
	}

	printf("%lld\n", (N * M) - even);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define vec_input(v) for(auto it=v.begin();it!=v.end();it++){cin>>*it;}
#define vec_output(v) for(auto it=v.begin();it!=v.end();it++){if(it!=v.begin())cout<<" ";cout<<*it;}cout<<endl;
#define vec_debug(v) for(auto it=v.begin();it!=v.end();it++){cerr<<*it<<" ";}cerr<<endl;
#define yn(ans) cout<<(ans?"Yes":"No")<<endl
#define YN(ans) cout<<(ans?"YES":"NO")<<endl
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;

//等差数列の和を求める(初項,項数,公差)
long long int arith_sum1(long long int a,long long int n,long long int d){
    return n*(2*a+(n-1)*d)/2;
}
//等差数列の和を求める(初項,末項,項数)
long long int arith_sum2(long long int a,long long int l,long long int n){
    return n*(a+l)/2;
}
//初項1，末項n，項数1の数列の和を求める
long long int series_sum(long long int n){
    return n*(n+1)/2;
}
//各桁の数の和を求める
template <typename T>
T digitsum(T n){
    string s=to_string(n);
    T sum=0;
    T d=1;
    for(T e=0;e<s.length();e++){
        sum+=(n/d)%10;d*=10;
    }
    return sum;
}
template <typename T>
bool isPrime(T n){
    if(n<=1)return false;
    if(n==2||n==3)return true;
    if(n%2==0||n%3==0)return false;
    for(T q=5;q*q<=n;q+=4){
        if(n%q==0)return false;
        q+=2;
        if(n%q==0)return false;
    }
    return true;
}
template <typename T>
vector<pair<T, T>> prime_factor(T n) {
    vector<pair<T, T>> ret;
    T tmp=0;
    if(n%2==0){
        tmp=0;while(n%2==0){tmp++;n/=2;}
        ret.push_back(make_pair(2, tmp));
    }
    if(n%3==0){
        tmp=0;while(n%3==0){tmp++;n/=3;}
        ret.push_back(make_pair(3, tmp));
    }
    for (T i=5;i*i<=n;i+=4) {
        if(n%i==0){
            tmp=0;while(n%i==0){tmp++;n/=i;}
            ret.push_back(make_pair(i,tmp));
        }
        i+=2;
        if(n%i==0){
            tmp=0;while(n%i==0){tmp++;n/=i;}
            ret.push_back(make_pair(i,tmp));
        }
    }
    if(n!=1)ret.push_back(make_pair(n,1));
    return ret;
}
long long int intpow(long long int x,long long int n){
    long long int ans=1;
    for(int i=0;i<n;i++){
        ans*=x;
    }
    return ans;
}
template <typename T>T intlog(T x){
    string a=to_string(x);
    return a.length()-1;
}
long long int combination(long long int a,long long int b){
    queue<long long int> bunsi,bunbo;
    long long int ans=1;
    b=min(b,a-b);
    for(int i=0;i<b;i++){
        bunsi.push(a-i);
        if(b-i>=2)bunbo.push(b-i);
    }
    while(bunsi.size()!=0||bunbo.size()!=0){
        ans*=bunsi.front();
        bunsi.pop();
        if(ans%bunbo.front()==0){
            ans/=bunbo.front();
            bunbo.pop();
        }
    }
    return ans;
}

int main(){
    string s,t;
    cin>>s>>t;
    int ans=0;
    rep(i,s.length()){
        if(s[i]!=t[i])ans++;
    }
    cout<<ans<<endl;
}

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

ll n,a[MXN],b[MXN],m;


int main(){
	cin>>n;
	rep(i,n+1)cin>>a[i];
	rep(i,n)cin>>b[i];
	
	rep(i,n){
		if(a[i]>=b[i]){
			m+=b[i];
		}
		else {
			if(b[i]-a[i]-a[i+1]<=0)
			{
				a[i+1]-=(b[i]-a[i]);
				m+=b[i];
			}
			else
			{
				m+=a[i]+a[i+1];
				a[i+1]=0;
			}
			//cout<<a[i+1]<<" ";
		}
	}
	cout<<m<<'\n';
	return 0;
}


Measured memory_bytes: 1792
n = int(input())
'''
lst = {}
for i in range(n):
    s, t = map(str, input().split())
    lst[s] = int(t)
print(lst)
'''
lst = []
for i in range(n):
    s, t = map(str, input().split())
    lst.append([s, int(t)])
title = input()
#print(lst)
for i in range(n):
    if title == lst[i][0]:
        id = i
        break
#print("id",id)
time_cnt = 0
for i in range(id+1, n):
    time_cnt+=lst[i][1]
print(time_cnt)


Measured memory_bytes: 3064
N = gets.to_i
words = []
N.times do
  words << gets.chomp
end
for i in 0..N-2
  if words[i][words[i].length-1] != words[i+1][0]
    puts "No"
    exit
  end
  for j in 0...N
    if words[i] == words[j] && i != j then puts "No" ; exit end
  end
end
puts "Yes"

Measured memory_bytes: 3836
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  int n;
  cin >> n;
  vector<P> vc;
  REP(i, n) {
    int a;
    cin >> a;
    vc.push_back(P(a, i));
  }
  sort(ALL(vc));
  REP(i, n) cout << vc[i].second + 1 << " ";
  cout << "\n";
  return 0;
}

Measured memory_bytes: 2544
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

N = I()
L = []

for i in range(N):
    L.append(S())

max = []
m = 0
cnt = Counter(L)

for v, c in cnt.most_common():
     if m < c:
        max.clear()
        max.append(v)
        m = c
     elif m == c:
        max.append(v)

for s in sorted(max):
    print(s)

Measured memory_bytes: 45320
#include<stdio.h>

#define MAX 500
static const int INFTY = (1<<21);
 
int main(){
  int n, i, j, e, sum,k,a,v1;
  int key,p[MAX],v[MAX],u,c[MAX],m[MAX][MAX];
   
  scanf("%d", &n);
  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      m[i][j] = INFTY;
    }
  }
   
  for ( i = 0; i < n; i++ ){
    scanf("%d %d", &u, &k);
    for ( j = 0; j < k; j++ ){
      scanf("%d %d", &v1, &a);
      m[u][v1] = a;
    }
  }
  for(i=0;i<n;i++){
    c[i]=INFTY;
    p[i]=-1;
    v[i]=0;
  }
  c[0]=0;
 
  while(1){
    key=INFTY;
    u=-1;
    for(i=0;i<n;i++){
      if(key>c[i] && !v[i]){
    u=i;
    key=c[i];
      }
    }
    if(u==-1)break;
    v[u]=1;
    for(j=0;j<n;j++){
      if(m[u][j]+c[u]<c[j] && !v[j]){
    p[j]=u;
    c[j]=c[u]+m[u][j];
      }
    }
  }
   
  for ( i = 0; i < n; i++ ){
    printf("%d %d\n", i, (c[i]==INFTY?-1:c[i]));
  }
   
  return 0;
}

Measured memory_bytes: 800
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,s,min=0,count=0;
  char c;
  int a[55][5] = {};
  cin >> n >> m;
  for(int i=1; i<=n; i++){
    for(int j=1; j<=m; j++){
      cin >> c;
      if(c=='W') a[i][0]++;
      if(c=='B') a[i][1]++;
      if(c=='R') a[i][2]++;
    }
  }
  count += 2*m-a[1][0]-a[n][2];
  min = n*m;
  for(int i=1; i<=n-2; i++){
    for(int j=2; j<=n-i; j++){
      s = 0;
      for(int k=2; k<=n-1; k++){
        if(j > k){
          s += m -a[k][0];
        }
        if(j+i > k && k >= j){
          s += m -a[k][1];
        }
        if(k >= j+i){
          s += m -a[k][2];
        }
      }
      if(min >= s){
        min = s;
      }
    }
  }
  count += min;
  cout << count << endl;
 return 0;
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
 
typedef long long ll;
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define forr(i, a, b) for(int i = (a); i < (int) (b); i++)
#define forn(i, n) forr(i, 0, n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define DBG(x) cerr << #x << " = " << (x) << endl
#define DBGV(v,n) forn(i,n) cout << v[i] << " "; cout << endl
#define esta(x,c) ((c).find(x) != (c).end())
#define RAYA cerr << "===============================" << endl
#define MAXN 2005
#define INF 1000000007
 
 
int main()
{ 
	FIN;
	
	#ifdef input
		//freopen("test1.txt", "r", stdin);
	#endif
	
	int x, n;
	cin >> x >> n;
	vector <int> v(n);
	forn(i,n) cin >> v[i];
	bool d=false;
	int pos = x;
	while(d==false)
	{
		d=true;
		forn(i,n) if(v[i]==pos) d=false;
		if(d==true) break;
		pos++;
	}
	int ans=pos;
	pos = x; d=false;
	while(d==false)
	{
		d=true;
		forn(i,n) if(v[i]==pos) d=false;
		if(d==true) break;
		pos--;
	}
	if(x-pos <= ans-x) ans=pos;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>
 
int main(void)
{
    double w;
     
    while (scanf("%lf", &w) != EOF){
         
        if (w > 91.00){
            printf("heavy\n");
        }
        else if (w > 81.00){
            printf("light heavy\n");
        }
        else if (w > 75.00){
            printf("middle\n");
        }
        else if (w > 69.00){
            printf("light middle\n");
        }
        else if (w > 64.00){
            printf("welter\n");
        }
        else if (w > 60.00){
            printf("light welter\n");
        }
        else if (w > 57.00){
            printf("light\n");
        }
        else if (w > 54.00){
            printf("feather\n");
        }
        else if (w > 51.00){
            printf("bantam\n");
        }
        else if (w > 48.00){
            printf("fly\n");
        }
        else {
            printf("light fly\n");
        }
    }
    return (0);
}

Measured memory_bytes: 608
import java.util.*;

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    private boolean check(int i, char[] c, char[] s) {
        int base = i;
        for (int j = 0; j < s.length; j++) {
            if (c[base + j] != s[j]) return false;
        }
        return true;
    }

    public void run() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String s = sc.next();
        String t = sc.next();

        int cnt = 0;
        for (int i = 0; i < Math.min(s.length(), t.length()); i++) {
            String pre = s.substring(s.length() - (i + 1), s.length());
            String suf = t.substring(0, i + 1);
            if (pre.equals(suf)) {
                //System.out.println("ok: cnt:" + pre.length());
                cnt = Math.max(cnt, pre.length());
            }
        }

        System.out.println(Math.max(N, s.length() + t.length() - cnt));
        
        return;
    }

}

Measured memory_bytes: 21972
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));

  for($i=0; $i<=25; $i++){
    for($j=0; $j<=20; $j++){
      if($i*4+$j*7==$n){
        echo "Yes";
        exit;
      }
    }
  }
  echo "No";

Measured memory_bytes: 16168
H, W = map(int, input().split())
grid = [list(map(int, input().split())) for _ in range(H)]
# print(*grid, sep='\n')
ans = []
left = True
flag = True
for i in range(H):
    if left:
        for j in range(W):
            if grid[i][j] % 2 == 1:
                if j == W-1:
                    if i == H-1:
                        flag = False
                    else:
                        grid[i][j] -= 1
                        grid[i+1][-1] += 1
                        ans.append([i, j, i+1, W-1])
                else:
                    grid[i][j] -= 1
                    grid[i][j+1] += 1
                    ans.append([i, j, i, j+1])
        left = False
    else:
        for j in reversed(range(W)):
            if grid[i][j] % 2 == 1:
                if j == 0:
                    if i == H-1:
                        flag = False
                    else:
                        grid[i][j] -= 1
                        grid[i+1][0] += 1
                        ans.append([i, j, i+1, 0])
                else:
                    grid[i][j] -= 1
                    grid[i][j-1] += 1
                    ans.append([i, j, i, j-1])
        left = True
    if not flag:
        break
# print(grid)
print(len(ans))
for a in ans:
    a = list(map(lambda x: x+1, a))
    a = list(map(str, a))
    print(" ".join(a))


Measured memory_bytes: 69340
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
class Counting():
    def __init__(self,maxim,mod):
        maxim += 1

        self.mod = mod
        self.fact = [0]*maxim
        self.fact[0] = 1
        for i in range(1,maxim):
            self.fact[i] = self.fact[i-1] * i % mod

        self.invfact = [0]*maxim
        self.invfact[maxim-1] = pow(self.fact[maxim-1],mod-2,mod)
        for i in reversed(range(maxim-1)):
            self.invfact[i] = self.invfact[i+1] * (i+1) % mod


    def nCk(self,n,r):
        if n < 0 or n < r: return 0
        return self.fact[n] * self.invfact[r] * self.invfact[n-r] % self.mod

    def nPk(self,n,r):
        if n < 0 or n < r: return 0
        return self.fact[n] * self.invfact[n-r] % self.mod

        

def main():
    N,M=mi()
    MOD=10**9+7

    if N == 1:
        print(1)
        exit()
    
    def prime_array(n):
        a = []
        b = set()
        while n % 2 == 0:
            a.append(2)
            b.add(2)
            n //= 2
        f = 3
        while f * f <= n:
            if n % f == 0:
                a.append(f)
                b.add(f)
                n //= f
            else:
                f += 2
        if n != 1:
            a.append(n)
            b.add(n)
        return a,b

    P,P_set = prime_array(M)
    P_count = {p:0 for p in P_set}
    for p in P:
        P_count[p] += 1
    
    ans = 1
    counting = Counting(3*10**5+10,MOD)
    for p,e in P_count.items():
        ans *= counting.nCk(e+N-1,e)
        ans %= MOD

    
    print(ans % MOD)



if __name__ == "__main__":
    main()

Measured memory_bytes: 74288
#[allow(unused_macros)]
macro_rules! get {
    ([$t:ty] ; $n:expr) => {
        (0..$n)
        .map(|_| get!([$t])).collect::<Vec<_>>()
    };
    ($($t:ty),+ ; $n:expr) => {
        (0..$n).map(|_| get!($($t),+)).collect::<Vec<_>>()
    };
    ([$t:ty]) => {
        rl().split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<$t>>()
    };
    ($t:ty) => {
        rl().parse::<$t>().unwrap()
    };
    ($($t:ty),*) => {
        {
            let line =rl();
            let mut iter = line.split_whitespace();
            ($(iter.next().unwrap().parse::<$t>().unwrap()),*)
        }
    };
}
fn rl() -> String {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    line.trim().to_string()
}

fn main() {
    let (n, k, q) = get!(i64, i64, i64);
    let mut v = vec![0i64; n as usize];
    for _ in 0..q {
        let mut tmp = get!(i64);
        tmp -= 1;
        v[tmp as usize] += 1;
    }
    //eprintln!("n: {}, k: {}, q: {}", n, k, q);
    //eprintln!("{:?}", v);
    for i in 0..v.len() {
        if k - (q - v[i]) <= 0 {
            println!("No");
        } else {
            println!("Yes");
        }
    }
}


Measured memory_bytes: 4732
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

void Fill(const char *const t, const int64_t t_size, char *const dest) {
  strncpy(dest, t, t_size);
}

bool Match(const string &S, const int64_t start, const string &T) {
  const int64_t s_len = static_cast<int64_t>(S.length());
  const int64_t t_len = static_cast<int64_t>(T.length());
  if (start + t_len > s_len) {
    return false;
  }
  for (int64_t i = 0; i < t_len; ++i) {
    if (S.c_str()[start + i] != T.c_str()[i] && S.c_str()[start + i] != '?') {
      return false;
    }
  }
  return true;
}

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

  string S, T;
  cin >> S >> T;
  char modified[51];
  for (char &ch : modified) {
    ch = '\0';
  }
  const char *t = T.c_str();
  int64_t s_size = static_cast<int64_t>(S.length());
  int64_t t_size = static_cast<int64_t>(T.length());
  if (s_size < t_size) {
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  strncpy(modified, S.c_str(), s_size);
  int64_t count = 0;
  bool is_okay = false;
  for (int64_t start = s_size - 1; start >= 0; --start) {
    if (Match(S, start, T)) {
      Fill(t, t_size, &modified[start]);
      is_okay = true;
      break;
    }
  }
  if (is_okay) {
    for (int64_t i = 0; i < s_size; ++i) {
      if (modified[i] == '?') {
        modified[i] = 'a';
      }
    }
    cout << string(modified) << endl;
  } else {
    cout << "UNRESTORABLE" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
# Aizu Problem 0276: Temperature Difference

import sys, math, os, datetime

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


for line in sys.stdin:
    a, b = [int(_) for _ in line.split()]
    print(a - b)

Measured memory_bytes: 8244
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <cassert>
#include <exception>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define sz size()
#define print(X) cout << (X) << endl
const ll INF = 1e+9+7;
ll n,m,l;
string s,t;
ll d[200010],dp[550][550];

int main(){
  cin >> n >> m;
  l = 0;
  if(m == 0)print(n * n);
  else{
    lep(i,m + 1,n){
      l += (n / i) * (i - m);
      if(n % i >= m)l += n % i - m + 1;
    }
    print(l);
  }
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define FOR0(i,n) for(int i=0, _##i=(n); i<_##i; ++i)
#define FOR(i,l,r) for(int i=(l), _##i=(r); i<_##i; ++i)
#define FORD(i,l,r) for(int i=(r), _##i=(l); --i>=_##i; )
#define repi(i,a) for(__typeof((a).begin()) i=(a).begin(), _##i=(a).end(); i!=_##i; ++i)
#define dwni(i,a) for(__typeof((a).rbegin()) i=(a).rbegin(), _##i=(a).rend(); i!=_##i; ++i)
#define SZ(a) ((int)((a).size()))
#define printCase() "Case #" << caseNum << ": "
#define pb push_back
#define mp make_pair
#define INF ((int)1e9)
#define SYNC std::ios::sync_with_stdio(false)
#define ff first
#define ss second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main() {
	SYNC;
	int n, m, q, x1, x2, y1, y2;
	char x;
	bitset<2005> grid[2005];
	cin >> n >> m >> q;
	FOR(i,1,n+1) FOR(j,1,m+1) {
		cin >> x;
		if(x=='1') grid[i][j] = 1;
	}
	int ver[2005][2005] = {}, he[2005][2005] = {}, ve[2005][2005] = {};
	FOR(i,1,n+1) {
		FOR(j,1,m+1) {
			ver[i][j] = ver[i][j-1]+ver[i-1][j]-ver[i-1][j-1];
			he[i][j] = he[i][j-1]+he[i-1][j]-he[i-1][j-1];
			ve[i][j] = ve[i][j-1]+ve[i-1][j]-ve[i-1][j-1];
			if(grid[i][j]) {
				ver[i][j]++;
				if(grid[i][j-1]) he[i][j]++;
				if(grid[i-1][j]) ve[i][j]++;
			}

		}
	}
	while(q--) {
		cin >> x1 >> y1 >> x2 >> y2;
		int vc =  (ver[x2][y2] + ver[x1-1][y1-1] - ver[x1-1][y2] - ver[x2][y1-1]);
		int hec = (he[x2][y2] + he[x1-1][y1] - he[x1-1][y2] - he[x2][y1]);
		int vec = (ve[x2][y2] + ve[x1][y1-1] - ve[x1][y2] - ve[x2][y1-1]);
		//DEBUG(vc); DEBUG(hec); DEBUG(vec);
		cout << vc - hec - vec << endl;
	}
}

Measured memory_bytes: 49408
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

char mp[21][21];
int ans[21][21];
constexpr int dx[] = { -1,0,1,0 };
constexpr int dy[] = { 0,1,0,-1 };

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h, w;
	cin >> h >> w;
	rep(i, h)rep(j, w) cin >> mp[i][j];
	auto bfs = [&](int sx, int sy) {
		queue<P> que;
		que.push(P(sx, sy));
		ans[sx][sy] = 0;
		while (!que.empty()) {
			P p = que.front(); que.pop();
			rep(i, 4) {
				int nx = p.first + dx[i], ny = p.second + dy[i];
				if (nx < 0 || ny < 0 || nx >= h || ny >= w) continue;
				if (ans[nx][ny] != inf) continue;
				if (mp[nx][ny] == '#') continue;
				ans[nx][ny] = ans[p.first][p.second] + 1;
				que.push(P(nx, ny));
			}
		}
		return;
	};
	int j_ans = 0;
	rep(i, h)rep(j, w) {
		if (mp[i][j] == '#') continue;
		rep(k, h)rep(l, w) ans[k][l] = inf;
		bfs(i, j);
		rep(k, h)rep(l, w) if(mp[k][l] != '#' && ans[k][l] != inf)j_ans = max(j_ans, ans[k][l]);
	}
	dunk(j_ans);
	return 0;
}


Measured memory_bytes: 256
/**
  * @brief atcoder
  * @author yao
  */
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <climits>
#define ft first
#define sd second
#ifdef DBG
#   define dbg_pri(x...) fprintf(stderr,x)
#else
#   define dbg_pri(x...) 0
#   define NDEBUG
#endif //DBG
#include <cassert>

typedef unsigned int uint;
typedef long long int lli;
typedef unsigned long long int ulli;

#define N 262144

int a[N];

int main()
{
    int n,k;
    scanf("%d%d", &n, &k);
    for(int i=0;i<n;++i) scanf("%d", &a[i]);
    for(int i=k,j=0;i<n;++i,++j)puts(a[i]>a[j] ? "Yes" : "No");
    return 0;
}


Measured memory_bytes: 2436
// Problem : D - Powerful Discount Tickets
// Contest : AtCoder - AtCoder Beginner Contest 141
// URL : https://atcoder.jp/contests/abc141/tasks/abc141_d
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a) for (int i=0; i<(a); i++)
#define rep1(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rep(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define imax INT_MAX
#define imin INT_MIN
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
	 
	ios_base::sync_with_stdio(0); cin.tie(0); 
	int n,m;
	cin>>n>>m;
	vi a(n);
	map<ll,ll> map;
	loop(i,n)
	{
		cin>>a[i];
		map[a[i]]++;
	}
	while(m--)
	{
		auto i=map.rbegin();
		i->s--;
		map[i->f/2]++;
		if(i->s==0)
		{
			map.erase(i->f);
		}
	}
	ll ans=0;
	trav(i,map)
	ans+=i.f*i.s;
	cout<<ans;
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 9856
#include <stdio.h>
int gcd(int x,int y);

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

int gcd(int x , int y)
{
	int z;
	
	if( x < y)
	{
		z = y%x;
		
		while(z!=0)
		{
			y = x;;
			x = z;
			z = y % x;
		}
	}
	
	return x;
}


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

using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    if(a >= b){
        swap(a,b);
    }
    for(int i = 0;i < b; i++){
        cout << a;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define INF (1<<30)

vector<ll> seg_tree;
ll N;

void init(vector<ll> &v){
  ll n = v.size();
  N = pow(2, ceil(log2(n))); 
  seg_tree.resize(2*N-1);

  for(ll i=0;i<N;i++) seg_tree[N-1+i] = (i>=n?0:v[i]);
  for(ll i=N-2;i>=0;i--) seg_tree[i] = max(seg_tree[2*i+1], seg_tree[2*i+2]);
}

void update(ll ind, ll val){
  ind += N - 1;
  seg_tree[ind] = val;
  while(ind > 0){
    ind = (ind - 1) / 2;
    seg_tree[ind] = max(seg_tree[2*ind+1], seg_tree[2*ind+2]);
  }
}
ll query(ll a, ll b, ll ind, ll l, ll r){
  if(r < a || b < l) return 0;
  if(a <= l && r <= b) return seg_tree[ind];
  else return max(query(a, b, 2*ind+1, l, (l+r)/2), 
                  query(a, b, 2*ind+2, (l+r)/2+1, r));
}

int main(){
  ll n;
  cin >> n;
  vector<ll> h(n), a(n);
  init(h);
  for(ll i = 0; i < n; i++){
    cin >> h[i];
    h[i]--;
  }
  for(ll i = 0; i < n; i++){
    cin >> a[i];
  }
  for(ll i = 0; i < n; i++){
    ll segmax = query(0, h[i], 0, 0, N-1);
    update(h[i], segmax + a[i]);
  }
  cout << seg_tree[0] << endl;
}

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

typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define REP(i,n) for (int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
 
using namespace std;

int a[1000000] = {0};

signed main(){
    
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 1;i < s.size() ;i++){
        if(s[i-1] != s[i]) ans++;
    }

    cout << ans;


    return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#include <complex>
#include <iomanip>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <functional>

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

using std::map;
using std::set;
using std::bitset;
using std::vector;
using std::string;
using std::multimap;
using std::multiset;
using std::deque;
using std::queue;
using std::stack;
using std::pair;
using std::iterator;

using std::sort;
using std::stable_sort;
using std::reverse;
using std::max_element;
using std::min_element;
using std::unique;
using std::ios_base;
using std::swap;
using std::fill;

using std::setprecision;
using std::fixed;

using std::min;
using std::max;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef string S;

namespace MySpace{

};

#define F(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define fi first
#define se second
#define re return
#define all(x) (x).begin(), (x).end()

inline int nextInt()
{
    int x = 0;
    char c = getchar();
    int mi = (c == '-');
    if (c == '-') c = getchar();
    while ('0' <= c && c <= '9')
    {
        x = 10 * x + c - '0';
        c = getchar();
    }
    if (mi) return x * -1;
    return x;
}

ll h, w;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> h >> w;
    ll ans = 1e18;
    for (int i = 1; i < h; i++)
    {
        ll s1 = i * w;
        long long r = w / 2;
        ll s2 = r * (h - i);
        ll s3 = h * w - s1 - s2;
        ans = min(ans, max(s1, max(s2, s3)) - min(s1, min(s2, s3)));
        ll r2 = (h - i) / 2;
        s2 = r2 * w;
        s3 = h * w - s2 - s1;
        ans = min(ans, max(s1, max(s2, s3)) - min(s1, min(s2, s3)));
    }
    swap(h, w);
    for (int i = 1; i < h; i++)
    {
        ll s1 = i * w;
        long long r = w / 2;
        ll s2 = r * (h - i);
        ll s3 = h * w - s1 - s2;
        ans = min(ans, max(s1, max(s2, s3)) - min(s1, min(s2, s3)));
        ll r2 = (h - i) / 2;
        s2 = r2 * w;
        s3 = h * w - s2 - s1;
        ans = min(ans, max(s1, max(s2, s3)) - min(s1, min(s2, s3)));
    }
    cout << ans;
}


Measured memory_bytes: 256
/***************************************************
 * Problem Name : B - Echo.cpp
 * Problem Link : https://atcoder.jp/contests/abc145/tasks/abc145_b
 * OJ           : atCoder
 * Verdict      : Trying
 * Date         : 2019-11-22
 * Problem Type :
 * Author Name  : Saikat Sharma
 * University   : CSE, MBSTU
 ***************************************************/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <cstdlib>
#include <deque>
#include <stack>
#include <bitset>
#include <cassert>
#include <map>
#include <set>
#include <cassert>
#include <iomanip>
#include <random>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;

#define __FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define __FileRead freopen ("input.txt", "r", stdin)
#define __FileWrite freopen ("output.txt", "w", stdout)
#define SET(a,v) memset(a,v,sizeof(a))
#define SZ(v) (int)v.size()
#define pii pair<int,int>
#define pil pair <int, ll>
#define pli pair <ll, int>
#define pll pair <ll, ll>
#define debug cout <<"######\n"
#define debug1(x) cout <<"### " << x << " ###\n"
#define debug2(x,y) cout <<"# " << x <<" : "<< y <<" #\n"
#define nl cout << "\n";
#define sp cout << " ";
#define sl(n) scanf("%lld", &n)
#define sf(n) scanf("%lf", &n)
#define si(n) scanf("%d", &n)
#define ss(n) scanf("%s", n)
#define pf(n) scanf("%d", n)
#define pfl(n) scanf("%lld", n)
#define all(v) v.begin(), v.end()
#define rall(v) v.begin(), v.end()
#define srt(v) sort(v.begin(), v.end())
#define r_srt(v) sort(v.rbegin(), v.rend())
#define rev(v) reverse(v.begin(), v.end())
#define Sqr(x) ((x)*(x))
#define Mod(x, m) ((((x) % (m)) + (m)) % (m))
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define pb push_back
#define mk make_pair
#define MAX 100005
#define INF 1000000009
#define MOD 1000000007

template<class T>
using min_heap = priority_queue<T, std::vector<T>, std::greater<T>>;
template<typename T>
using ordered_set  = tree<T, null_type, less<T>, rb_tree_tag,
      tree_order_statistics_node_update>;

template <typename T> string toString ( T Number ) {
    stringstream ss;
    ss << Number;
    return ss.str();
}
template<typename T> int toInt (T str) {
    stringstream ss;
    ss << str;
    int num;
    ss >> num;
    return num;
}
ll lcm (ll a, ll b) {
    return a * b / __gcd (a, b);
}
/************************************ Code Start Here ******************************************************/
int main () {
    __FastIO;
    //~ cout << setprecision (10);
    //~ cout << fixed;
    int n;
    cin >>n;
    string str;
    cin >> str;
    if(n&1){
		cout << "No\n";
		exit(0);
	}
	for(int i = 0, j = n/2; j<n; i++, j++){
		if(str[i] != str[j]){
			cout << "No\n";
			exit(0);
		}
	}
	cout << "Yes\n";
    return 0;
}


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

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

    std::vector<std::vector<int>> matrix(26, std::vector<int>(n, 0));
    for(int i = 0; i < n; ++i){
        std::string s;
        std::cin >> s;
        int sz = s.size();
        for(int j = 0; j < sz; ++j){
            ++matrix.at(s.at(j) - 97).at(i);
        }
    }

    std::string ans = "";
    for(int i = 0; i < 26; ++i){
        int val = *std::min_element(matrix.at(i).begin(), matrix.at(i).end());
        for(int j = 0; j < val; ++j){
            ans += (char)(i + 97);
        }
    }

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

    return 0;
}

Measured memory_bytes: 256
while True:
    H, W = map(int,input().split())
    if H==0 and W==0:
        break
    for y in range(W):
        print('#', end="")
    print()
        
    for x in range(H-2):
        print('#',end="")
        for y in range(W-2):
            print('.', end="")
        print('#',end="")
        print()
        
    for y in range(W):
        print('#', end="")
    print()
        
    print()



Measured memory_bytes: 7004
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define MIN(a,b) ((a) <= (b) ? (a) : (b))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort( ALL(v) )

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

int main()
{


    int a,b,c,d; cin>>a>>b>>c>>d;

    bool turn = 0 ;
    bool win = 0 ;
    while(true){

        if(turn == 0){

            c-=b;
            if(c<=0){
                win = 1 ; break;
            }
            turn = 1;
        }
        else{
            a-=d;
            if(a<=0){
                win = 0;
                break;
            }
            turn = 0  ;
        }
    }

    if(win == 0){
        cout <<"No"<<endl;
    }
    else
        cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 3620
#include<stdio.h>

int r0,w0,c,r,i;

int main()
{
	for(;;)
	{
		scanf("%d %d %d %d",&r0,&w0,&c,&r);
		if(r0 == 0 && w0 == 0 && c == 0 && r == 0)break;
		
		for(i = 0;;i++)
		{
			int y = ((r0 + (i*r)) / c) - w0;
			if(y >= 0)break;
		}
		printf("%d\n",i);
		
	}
	
	return 0;
}

Measured memory_bytes: 2756
#include <iostream>
#include <vector>
#include <string>
#include <numeric>

using namespace std;

const long long INF = 1e18;

bool larger(vector<int> v1, vector<int> v2){
    int sum1 = accumulate(v1.begin(), v1.end(), 0);
    int sum2 = accumulate(v2.begin(), v2.end(), 0);
    if (sum1 > sum2)  return true;
    else if (sum1 < sum2)  return false;
    else {
        for (int j=9; j>=0; j--){
            if (v1[j] > v2[j])  return true;
            else if (v1[j] < v2[j])  return false;
        }
        return true;
    }
}

int main(){
    vector<int> num(10, -1);
    int costs[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    int n, m;  cin >> n >> m;
    vector< vector<int> > dp(n+10, num);
    dp[0] = vector<int>(10, 0);
    vector<int> a(m);
    for (int i=0; i<m; i++){
        cin >> a[i];
    }

    for (int i=0; i<=n; i++){
        for (int j=0; j<m; j++){
            if (dp[i][0] != -1){
                int aj = a[j];
                vector<int> v = dp[i];
                v[aj] += 1;
                dp[i+costs[aj]] = larger(v, dp[i+costs[aj]]) ? v : dp[i+costs[aj]];
            }
        }
    }

    vector<int> dpn = dp[n];
    for (int i=9; i>0; i--){
        if (dpn[i] != 0)  cout << string(dpn[i], '0'+i);
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 1024