akhauriyash/Code-Regression huggingface dataset:
# from line_profiler import LineProfiler
from collections import deque
from sys import stdin

def main():
    while(True):
        W, H = map(int, stdin.readline().split())
        if not W: break
        tx,ty = map(int, stdin.readline().split())
        kx,ky = map(int, stdin.readline().split())
        ma = [[0]+[abs(1-int(a)) for a in stdin.readline().split()]+[0] for i in range(H)]
        ma = [[0]*(W+2)] + ma + [[0]*(W+2)]
        que = deque([[tx,ty,kx,ky,0]])
        pas = set()
        ans = "NA"
        while(que):
            tx,ty,kx,ky,c = que.popleft()
            if tx == kx and ty == ky:
                ans = c
                break
            if c+1 > 100: continue
            for dx,dy in [[-1,0],[0,-1],[1,0],[0,1]]:
                tdx, tdy =  dx * ma[ty+dy][tx+dx],  dy * ma[ty+dy][tx+dx]
                kdx, kdy = -dx * ma[ky-dy][kx-dx], -dy * ma[ky-dy][kx-dx]
                ttx,tty,kkx,kky = tx+tdx,ty+tdy,kx+kdx,ky+kdy
                if (ttx,tty,kkx,kky) in pas: continue
                que.append([ttx,tty,kkx,kky,c+1])
                pas.add((ttx,tty,kkx,kky))
        print(ans)

if __name__ == "__main__":
    # prf = LineProfiler()
    # prf.add_function(main)
    # prf.runcall(main)
    # prf.print_stats()
    main()


Measured memory_bytes: 35200
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define mem(i,j) memset(i,j,sizeof (i));
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using uint = uint32_t;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
/*-----------------------------------------------------------------------------------------------------*/

const int N = 2e5 + 25, mod = 998244353;
struct fenwicktree {
	int arr[N];
	void edt(int p, int v) {
		for(; p < N; p += p & -p)
			arr[p] = (arr[p] + v) % mod;
	}
	int sum(int p) {
		int res = 0;
		for(; p; p -= p & -p)
			res = (res + arr[p]) % mod;
		return res;
	}
	int que(int l, int r) {
		if(r < 0)
			return 0;
		return (sum(r) - (l > 0 ? sum(l - 1) : 0) + mod) % mod;
	}
} tree;

signed main() {
	EmiliaMyWife

	int n, k;
	cin >> n >> k;
	vector<pair<int, int>> seg(k);
	for(int i = 0; i < k; i++)
		cin >> seg[i].first >> seg[i].second;
	tree.edt(1, 1);
	for(int i = 2; i <= n; i++) {
		int res = 0;
		for(auto [a, b] : seg)
			res = (res + tree.que(i - b, i - a)) % mod;
		tree.edt(i, (res + mod) % mod);
	}
	cout << tree.que(n, n) << '\n';

	return 0;
}


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

using namespace std;

#define all(c) ((c).begin()), ((c).end())
#define dump(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define REP(i, a, b) for (int i = a; i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define mp make_pair
#define fst first
#define snd second
#define pb push_back

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int, int> pii;

const int INF = 1 << 29;
const double EPS = 1e-10;

double zero(double d) {
    return d < EPS ? 0.0 : d;
}

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

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &a) {
    os << '[';
    rep(i, a.size()) os << (i ? " " : "") << a[i];
    return os << ']';
}

// to avoid error on mingw
string toString(int i) {
    stringstream ss;
    ss << i;
    return ss.str();
}

const int M = 1000000007;

// a^k
ll fpow(ll a, ll k, int M) {
    ll res = 1ll;
    ll x = a;
    while (k != 0) {
        if ((k & 1) == 1)
            res = (res * x) % M;
        x = (x * x) % M;
        k >>= 1;
    }
    return res;
}

int dr[] = {0, 1, 0, -1};
int dc[] = {1, 0, -1, 0};

map<string, int> ans;

int main() {
    cout.setf(ios::fixed, ios::floatfield);
    cout.precision(8);
    ios_base::sync_with_stdio(false);

    queue< pair<string, int> > que;
    que.push( mp("01234567", 0) );

    while (!que.empty()) {
        pair<string, int> t = que.front(); que.pop();
        int zero = t.first.find_first_of('0');

        ans[t.first] = t.second;

        rep(i, 4) {
            int nr = zero / 4 + dr[i];
            int nc = zero % 4 + dc[i];

            if (nr < 0 || 2 <= nr || nc < 0 || 4 <= nc)
                continue;

            swap(t.first[nr * 4 + nc], t.first[zero]);
            if( ans.find(t.first) == ans.end() )
                que.push(mp(t.first, t.second + 1));
            swap(t.first[nr * 4 + nc], t.first[zero]);
        }
    }

    int a[8];
    while (cin >> a[0]) {
        rep(i,7) cin >> a[i+1];
        stringstream ss;
        rep(i,8) ss << a[i];

        cout << ans[ss.str()] << endl;
    }

    return 0;
}

Measured memory_bytes: 3556
#include<stdio.h>
#define N 100
int main(){
    
    int a,b,f,i,j,A[N],min=0,cnt = 0;

    scanf("%d",&a);
    for(i = 0;i < a;i++){
        scanf("%d",&A[i]);
    }

    for(i = 0;i < a;i++){
        f = 0;
        min = i;
        for(j = i;j < a;j++){
            if(A[j] < A[min]){
                f = 1;
                min = j;
            }
        }
        if(f == 1)cnt++;
            b = A[i];
            A[i] = A[min];
            A[min] = b;
        printf("%d",A[i]);
        if(i != a-1) printf(" ");
    }
    printf("\n");
    printf("%d\n",cnt);
    return 0;
}


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

int main(int argc, char *argv[]) {
  ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

  vector<int> a(3);
  for(int i=0;i<3;i++)cin>>a[i];
  sort(a.begin(), a.end());
  int res=0;

  while(a[0]+2<=a[2]){
    a[0]+=2;res++;
  }
  while(a[1]+2<=a[2]){
    a[1]+=2;res++;
  }
  if(a[0]==a[1]&&a[1]==a[2]){cout<<res<<endl;}
  else if (a[0]==a[1]&&a[1]!=a[2]){cout<<res+1<<endl;}
  else {cout<<res+2<<endl;}

  return 0;
}


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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

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

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3916
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n,k = readline() |> split |> parseMap
	h = readline() |> split |> parseMap
	dp = Array{Int}(n)
	dp[1] = 0
	for i in 2:min(k,n)
		m = 10000000000
		for j in 1:i-1
			m = min(m,dp[j]+abs(h[i]-h[j]))
		end
		dp[i] = m
	end
	for i in k+1:n
		m = 10000000000
		for j in 0:k-1
			m = min(m,dp[i-k+j]+abs(h[i]-h[i-k+j]))
		end
		dp[i] = m
	end
	println(dp[n])
end

main()


Measured memory_bytes: 118200
#include<stdio.h>
#include<string.h>
long long s[100005];
int main(){
	long long n,k,i;
	while(scanf("%lld %lld",&n,&k)!=EOF){
		memset(s,0,sizeof(s));
		long long a,b,max=0;
		for(i=0;i<n;i++){
			scanf("%lld %lld",&a,&b);
			s[a]+=b;
			if(a>max)
				max=a;
		}
		for(i=0;i<=max;i++){
			if(s[i]==0)
				continue;
			if(k<=s[i]){
				printf("%lld\n",i);
				break;
			}
			else{
				k-=s[i];
			}
		}
	}
	return 0;
}

Measured memory_bytes: 896
n,m = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))
mod = 10**9 + 7

uni_x = 0
for i in range(1,n):
    uni_x += i * (n-i) * (x[i]-x[i-1])
    uni_x %= mod

ans = 0
for i in range(1,m):
    ans += i * (m-i) * (y[i]-y[i-1])
    ans %= mod

ans *= uni_x
ans %= mod

print(ans)

Measured memory_bytes: 90416
package main

import "fmt"

const (
	A = 'M'
	B = 'A'
	C = 'R'
	D = 'C'
	E = 'H'
)

var runeMap = [...]int{
	'M': 0,
	'A': 1,
	'R': 2,
	'C': 3,
	'H': 4,
}

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

	m := make([]int, 5)
	var name string
	for i := 0; i < n; i++ {
		fmt.Scan(&name)
		switch name[0] {
		case A:
			fallthrough
		case B:
			fallthrough
		case C:
			fallthrough
		case D:
			fallthrough
		case E:
			m[runeMap[name[0]]]++
		}
	}

	var cnt int
	for i := 0; i < 5; i++ {
		if m[i] > 0 {
			cnt++
		}
	}

	if cnt < 3 {
		fmt.Println(0)
		return
	}

	var sum int
	for i := 0; i < 5; i++ {
		for j := i + 1; j < 5; j++ {
			for k := j + 1; k < 5; k++ {
				sum += m[i] * m[j] * m[k]
			}
		}
	}
	fmt.Println(sum)
}

Measured memory_bytes: 5504
#include <bits/stdc++.h>
#define MOD 1000000007
#define ll long long int
#define db double
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define endl "\n"
#define mp make_pair
#define f first
#define s second
ll power(ll x, ll y){ ll ans = 1;x %= MOD;while(y){if(y&1)ans = (x * ans) % MOD;x = (x * x) % MOD;y >>= 1;}return ans;}
ll modInverse(ll a, ll m){ll m0 = m;ll y = 0, x = 1;if (m == 1) return 0;while (a > 1){ ll q = a / m;ll t = m;m = a % m,a = t;t = y;y = x - q * y;x = t;}if(x < 0) x += m0;return x;}
using namespace std;


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

Measured memory_bytes: 3640
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
  int N;
  cin >> N;
  cout << (1 + N) * N / 2 << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int N = 1e5 + 10;
const int M = 1e5 + 10;
const int INF = 0x3f3f3f3f;
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define endl '\n'
#define ls (i << 1)
#define rs (i << 1 | 1)
#define loop(i, a, b) for (int i = a; i < b; ++i)

inline int read() {
    char ch = getchar();
    int w = 1, c = 0;
    for (; !isdigit(ch); ch = getchar())
        if (ch == '-') w = -1;
    for (; isdigit(ch); ch = getchar()) c = (c << 3) + (c << 1) + (ch ^ 48);
    return w * c;
}
const int mod = 1e9 + 7;
long long fastPower(long long base, long long power) {
    long long result = 1;
    while (power > 0) {
        if (power & 1) {  //此处等价于if(power%2==1)
            result = (result % mod * base % mod) % mod;
        }
        power >>= 1;  //此处等价于power=power/2
        base = (base % mod * base % mod) % mod;
    }
    return result;
}

int main() {
    ll n;
    cin >> n;
    ll ans = ((fastPower(10, n) % mod - 2 * fastPower(9, n) % mod + mod) % mod +
              fastPower(8, n) % mod) %
             mod;
    cout << ans << endl;
    return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(12);
  
  int w, h, x, y;
  cin >> w >> h >> x >> y;
  
  double S = double(h)*w / 2.0;
  int ans = 0;
  if(x+x == w && y+y == h) ans = 1;
  
  cout << S << " " << ans << endl;
  return 0;
}

Measured memory_bytes: 3800
#include <stdio.h>
#include <algorithm>
using namespace std;
bool mp[701][701];
int n,siz[2][701],cnt,clr[701];
bool dfs(int k,int curc)
{
    clr[k]=curc;
    ++siz[curc-1][cnt];
    for (int i=1;i<=n;++i)
        if (mp[k][i])
        {
            if (!clr[i])
            {
                if (!dfs(i,3-curc))
                    return false;
            }
            else if (clr[i]==curc)
                return false;
        }
    return true;
}
bool dp[701][701];
int main()
{
    int m;
    scanf("%d%d",&n,&m);
    for (int i=1;i<n;++i)
        for (int j=i+1;j<=n;++j)
            mp[i][j]=mp[j][i]=true;
    for (int i=1;i<=m;++i)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        mp[a][b]=mp[b][a]=false;
    }
    for (int i=1;i<=n;++i)
        if (!clr[i])
        {
            ++cnt;
            if (!dfs(i,1))
            {
                printf("-1");
                return 0;
            }
        }
    dp[0][0]=1;
    for (int i=0;i<cnt;++i)
        for (int j=0;j<=n;++j)
            if (dp[i][j])
            {
                dp[i+1][j+siz[0][i+1]]=true;
                dp[i+1][j+siz[1][i+1]]=true;
            }
    int ans=1000000000;
    for (int i=0;i<=n;++i)
        if (dp[cnt][i])
            ans=min(ans,i*(i-1)/2+(n-i)*(n-i-1)/2);
    printf("%d\n",ans);
    return 0;
}


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


int main(){
    long long n, m;
    long long c;

    cin >> n >> m;

    if(n<=m) swap(n, m);

    if(m==1){
        if(n==1) c = 1;
        else c = n - 2;
    }else if(m==2){
        c = 0;
    }else{
        c = (n-2) * (m-2);
    }


    cout << c << endl;

	return 0;
}


Measured memory_bytes: 256
while True:
    a, op, b = map(str, input().split())
    
    if op == '+':
        print(int(a) + int(b))
    elif op == '-':
        print(int(a) - int(b))
    elif op == '*':
        print(int(a) * int(b))
    elif op == '/':
        print(int(a) // int(b))
    else:
        exit()



Measured memory_bytes: 5592
// くるさんのコード
#include <iostream>
#include <vector>
#include <bitset>

using namespace std;
typedef long long ll;
const ll MOD = (ll)1e9 + 7; 

int main() {
	ll N; cin >> N;
	bitset<60> bs(N);	//2進に直す
	vector<vector<long long> > dp(61, vector<long long>(3, 0));//dpテーブル
	dp[60][0] = 1;//初期化
		
	//上の桁から見ていく
	for (int i = 59; i >= 0; --i) {
		//i桁目のbitが立ってるとき
		if (bs[i]) {
			dp[i][0] = dp[i + 1][0];
			dp[i][1] = dp[i + 1][0] + dp[i + 1][1];
			dp[i][2] = 2 * dp[i + 1][1] + 3 * dp[i + 1][2];
		}
		//i桁目のbitが立ってないとき
		else {
			dp[i][0] = dp[i + 1][0] + dp[i + 1][1];
			dp[i][1] = dp[i + 1][1];
			dp[i][2] = dp[i + 1][1] + 3 * dp[i + 1][2];
		}
		dp[i][0] %= MOD;
		dp[i][1] %= MOD;
		dp[i][2] %= MOD;
	}
	cout << (((dp[0][0] + dp[0][1]) % MOD) + dp[0][2]) % MOD << endl;
	return 0;
}

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

#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;

const int mod = 1e9 + 7;


int main() {
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

	int n;
	cin >> n;
	vi l(n);
	rep(i, n){
		cin >> l[i];
	}

	ll ans = 0;
	sort(all(l));
	for(int i = n-1; i >= 0; i--){
		for(int j = i - 1; j >= 0; j--){
			auto itr = lower_bound(all(l), l[i] + l[j]);	//l[i]+l[j]以上の値を取得(address)
			ll ng = distance(itr, l.end());	//itrとnの距離(address)
//			cout << ng << endl;
			ans += n - 1 - i - ng;
		}
	}

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



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

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

#define INF 99999999
#define rep(i,n) for(int (i)=0,temp=(int)(n);(i)<temp;++(i)) 
#define repi(i,start,end) for(int (i)=(start),temp=(int)(end);i<(end);++(i))
#define rfor(v,x) for(const auto& (x) : (v)) //xは値を表す
#define all(x) (x).begin(),(x).end()
#define SORT(v, n) sort((v), (v)+(n))
#define vsort(v) sort((v).begin(), (v).end())
#define vfsort(v,lambda) sort(all((v)),(lambda))
#define vint vector<int>
#define vvint vector<vector<int>> //vvint v(n,vint(n))のように宣言できる
#define vin(v) rep(i,(v).size()) {cin >> (v)[i];}
//最終奥義(使うときはINFも書き換えろ!!)
//#define int long long
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 (b<a) { a=b; return 1; } return 0; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int ctoi(char c) {return c-'0';}
//lambda式 -> [&](int x, int y){return x<y;}
//vector内の重複を削除-> v.erase(unique(all(v)),v.end());

signed main(void){
  int a,b;cin >> a >> b;
  if(a+b>9)cout << "error" << endl;
  else cout << a+b<< endl;

}


Measured memory_bytes: 256
// Copyright (C) 2018 Sayutin Dmitry.
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; version 3

// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with this program; If not, see <http://www.gnu.org/licenses/>.

#include <iostream>
#include <vector>
#include <stdint.h>
#include <algorithm>
#include <set>
#include <map>
#include <array>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <string>
#include <assert.h>
#include <iterator>
#include <cstdint>
#include <cinttypes>
#include <string.h>
#include <random>
#include <numeric>
#include <tuple>


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

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;

using std::pair;
using std::make_pair;

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

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

#define pb push_back
#define eb emplace_back


int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    // code here.
    string s = input<string>();
    int k = input<int>();

    vector<string> lst;

    for (int i = 0; i != SZ(s); ++i)
        for (int j = i; j != min(i + 10, SZ(s)); ++j)
            lst.push_back(s.substr(i, j - i +1));

    std::sort(ALL(lst));
    lst.resize(std::unique(ALL(lst)) - lst.begin());

    cout << lst[k - 1] << "\n";
    
    return 0;
}


Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <tuple>
#include <cctype>
#include <ctype.h>
#include <set>
#include <sstream>
#include <time.h>
using namespace std;
//#define int long long
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define l1 list[index]
#define l2 list[index - 1]
#define l3 list[index + 1]
#define iif(i,j) ((i<0 && j<0) || (i>0 && j>0)) ? true : false 
typedef long long ll;
typedef pair<int, int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
int ca[12] = { 31,28,31,30,31,30,31,31,30,31,30,31 };

struct MyStruct
{
	int list[13];
};

void func(int n) {

	int i = 1;

	while (++i<=n)
	{
		int x = i;

		if (x % 3 == 0) {
			cout << " " << i;
		}
		else {

			while (x)
			{
				bool flag = false;

				if (x % 10 == 3) {
					cout << " " << i;
					flag = true;
				}

				if (flag == true) break;
				x /= 10;
			}

		}

	}

	cout << endl;

}


signed main() {
	int i, j, k, n, sum = 0, cnt = 0;
	string s, s1, s2;
	bool flag = false;
	vector<bool>list(100000,false);
	int a, b;
	


	cin >> n;

	func(n);










	getchar();
	getchar();
	return 0;
}


Measured memory_bytes: 3120
#include<stdio.h>
int main(){
	int n,d=1,w=0,a[105];
	scanf("%d",&n);
	for(int x=1;x<=n;x++)
	a[x]=0;
	for(int i=1;i<=n;i++){
		int f=i;
		while(f>=1){
			if(f%2==0)
				{
				a[i]++;
				f=f/2;	
				}
			else
			break;
		}
	}
	for(int j=1;j<=n;j++){
		if(a[j]>w){
				w=a[j];
				d=j;
		}
	}
	printf("%d\n",d);
	return 0;
}

Measured memory_bytes: 128
import bisect
import sys
import math
from collections import deque
from heapq import heappush, heappop

def sRaw():
    return input().rstrip("\r")


def iRaw():
    return int(input())


def ssRaw():
    return input().split()


def isRaw():
    return list(map(int, ssRaw()))


INF = 1 << 29

#DIV = (10**9) + 7
DIV = 998244353

def mod_inv_prime(a, mod=DIV):
    return pow(a, mod-2, mod)


def mod_inv(a, b):
    r = a
    w = b
    u = 1
    v = 0
    while w != 0:
        t = r//w
        r -= t*w
        r, w = w, r
        u -= t*v
        u, v = v, u
    return (u % b+b) % b


def CONV_TBL(max, mod=DIV):
    fac, finv, inv = [0]*max, [0]*max, [0]*max
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    inv[1] = 1
    for i in range(2, max):
        fac[i] = fac[i-1]*i % mod
        inv[i] = mod - inv[mod % i] * (mod//i) % mod
        finv[i] = finv[i-1]*inv[i] % mod

    class CONV:
        def __init__(self):
            self.fac = fac
            self.finv = finv
            pass

        def ncr(self, n, k):
            if(n < k):
                return 0
            if(n < 0 or k < 0):
                return 0
            return fac[n]*(finv[k]*finv[n-k] % DIV) % DIV

    return CONV()


def cumsum(As):
    s = 0
    for a in As:
        s += a
        yield s


sys.setrecursionlimit(200005)


def dijkstra(G,start=0):
    heap = []
    cost = [INF]*len(G)
    heappush(heap,(0,start))
    while len(heap)!=0:
        c,n = heappop(heap)
        if cost[n] !=INF:
            continue
        cost[n]=c
        for e in G[n]:
            ec,v = e
            if cost[v]!=INF:
                continue
            heappush(heap,(ec+c,v))
    return cost


def main():
    N= iRaw()
    d= {}
    ks=["AC", "WA", "TLE", "RE"]
    for k in ks:
        d[k]=0
    for _ in range(N):
        s = sRaw()
        if s not in d:
            d[s]=0
        else:
            d[s]+=1
    for k in ks:
        print(k,"x",d[k])
main()


Measured memory_bytes: 70196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD (int) (1e9+7)
#define INF (int) 2e9

bool seen[50*50];
vector<int> edges[50*50];

void dfs(int s, int p){
    seen[s] = true;
    for (auto v: edges[s]){
        if(v==p) continue;
        if(!seen[v]) dfs(v, s);
    }
}


int main(){
    int w, h;
    int di[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
    int dj[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
    
    while(true){
        cin >> w >> h;
        if(w==0 && h==0) break;
        int c[h][w];
        rep(i, h){
            rep(j, w){
                cin >> c[i][j];
                edges[w*i+j] = {};
            }
        }

        // 隣接リスト構築
        rep(i, h){
            rep(j, w){
                if(c[i][j]==1){
                    rep(k, 8){
                        int i_ = i+di[k];
                        int j_ = j+dj[k];
                        if(i_>=0 && i_<h && j_>=0 && j_<w && c[i_][j_]==1){
                            int idx = w * i_ + j_;
                            edges[w*i+j].emplace_back(idx);
                            // edges[idx].emplace_back(w*i+j);
                        }
                    }
                }
            }
        }

        rep(i, h){
            rep(j, w){
                seen[w*i+j] = false;
            }
        }

        // ここからdfs実行
        int cnt = 0;
        rep(i, h){
            rep(j, w){
                int num = w*i+j;
                if(c[i][j]==1 && !seen[num]){
                    dfs(num, -1);
                    cnt++;
                }
            }
        }
        cout << cnt << endl;
    }

    // printf("%d\n", N);
    return 0;
}


Measured memory_bytes: 3352
import math

N = int(input())
x, y = [], []
for _ in range(N):
	xt, yt = map(int, input().split())
	x.append(xt)
	y.append(yt)

def bfs(flg, cp, tot):
	if flg.count(0) == 0:
		return tot

	ans = 0
	for np in [i for i in range(N) if flg[i] == 0]:
		d = ((x[cp]-x[np])**2 + (y[cp]-y[np])**2) ** (1/2)
		flg[np] = 1
		ans += bfs(flg, np, tot+d)
		flg[np] = 0

	return ans

flg = [0] * N

A = 0

for i in range(N):
	flg[i] = 1
	A += bfs(flg,i,0)
	flg[i] = 0

for i in range(1,N+1):
	A /= i

print(A)
	


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

int main(){
    int N,M;
    cin >> N >> M;

    vector<int> k(M);
    vector<vector<int>> s(M);
    vector<int> p(M);

    for(int i=0; i<M; i++){
        cin >> k.at(i);
        for(int j=0;j<k.at(i); j++){
            int tmp;
            cin >> tmp;
            s.at(i).push_back(tmp);
        }
    }
    for(int i=0; i<M; i++){
        cin >> p.at(i);
    }

    int ans = 0;
    for(int st=0; st < pow(2,N); st++){ // switch status
        for(int i=0; i<M; i++){ // light
            int sum = 0;
            for(int j=0; j<k.at(i); j++){ 
                if(((1 << (s.at(i).at(j)-1)) & st) != 0) sum++; 
            }
            if((sum%2) != p.at(i)){
                break;
            }
            if(i == M-1) ans++;
        }
    }

    cout << ans << endl;
    return 0;

} 


Measured memory_bytes: 4028
#include<bits/stdc++.h>
using namespace std;
long long y,x;
string s;
int main()
{
 cin>>s;
 for(int i=0; i<s.size(); i++)
 {
 	if(s[i]=='C')
 	y=1;
 	if(s[i]=='F' && y==1)
 	{
 		cout<<"Yes"<<endl;
 		return 0;
 	}
 }
 cout<<"No"<<endl;
 return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define sz(v) (int)v.size()
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;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n, q;
    cin >> n >> q;
    while (q--) {
        int v, w;
        cin >> v >> w;
        if (n == 1) {
            cout << min(v, w) << EOL;
            continue;
        }
        while (v != w) {
            if (v > w) swap(v, w);
            w = (w + n - 2) / n;
        }
        cout << v << EOL;
    }
}


Measured memory_bytes: 1280
n,*a=`dd`.split.map &:to_i;b=a.pop n;r=1;n.times{|i|x=i<1||a[i-1]<a[i]?a[i]:0;y=i>n-2||b[i]>b[i+1]?b[i]:0;r=x+y==0?r*[a[i],b[i]].min%(10**9+7):y>a[i]||x>b[i]?0:r};p r

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

using namespace std;



void hawawa()
{
  int a, b, c;
  int x, y;
  cin >> a >> b >> c;
  cin >> x >> y;
  int ans = min(a + b, c * 2) * min(x, y);
  if (x < y) {
    ans += min(c * 2, b) * (y - x);
  } else {
    ans += min(c * 2, a) * (x - y);
  }
  cout << ans << "\n";
}

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

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

constexpr int64_t MOD= 1'000'000'007;
constexpr bool is_FACTORIAL_STORED= false; // 階乗を配列に格納をする前処理をする/しない
constexpr int Nfac= is_FACTORIAL_STORED ? 500'007
                                        : 0;
/* 剰余環 Z/nZ */
struct mint{ // Z/nZ に関する演算(n:素数の場合は除算も)をサポートする構造体
  int64_t rep; // 出力すべき代表元 rep \in {0,1,..,MOD- 1}
  mint(int64_t x=0): rep(((x%MOD)+ MOD)% MOD){}
  mint operator-() const { return mint(-rep);}
  mint& operator+=(const mint& x){
    rep+= x.rep; 
    if(rep>= MOD) rep-= MOD;
    return *this;
  }
  mint& operator-=(const mint& x){
    rep-= x.rep;
    if(rep< 0) rep+= MOD;
    return *this;
  }
  mint& operator*=(const mint& x){
    rep*= x.rep; rep%= MOD;
    return *this;
  }
  mint operator+(const mint x) const {
    mint ans(*this);
    ans+= x;
    return ans;
  }
  mint operator-(const mint x) const {
    mint ans(*this);
    ans-= x;
    return ans;
  }
  mint operator*(const mint x) const {
    mint ans(*this);
    ans*= x;
    return ans;
  }
  bool operator==(const mint x) const {
    return rep==x.rep;
  }
  bool operator!=(const mint x) const {
    return rep!=x.rep;
  }

  mint pow(int64_t d) const{
    assert(d >= 0); // ここで引っかかったら this.pow(d)= 0 or this.pow(-d).inv() のどちらかを選べ
    assert(!(*this==0 && d==0)); //   this.pow(d)= 0 or 1           　     のどちらかを選べ
    mint ans= 1;
    mint x= *this;
    while(d > 0){
      if(d&1){ ans*= x; }
      d >>= 1;
      x*= x;
    }

    return ans;
  }

  friend istream& operator >> (istream &is, mint& x) noexcept{
    int64_t a;
    is >> a;
    x= a;
    return is;
  }
  friend ostream& operator << (ostream &os, const mint& x) noexcept{
      return os << x.rep;
  }
  // MOD が素数(<=> Z/nZ が体)のとき
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint& x){
    *this *= x.inv();
    return *this;
  }
  mint operator/(const mint x) const {
    mint ans(*this);
    ans/= x;
    return ans;
  }
};

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

  vector<mint> data(N);
  for(int i=0; i<N; i++){
    cin >> data.at(i);
  }

  vector<mint> cumsum_tail(N);
  for(int i=1; i <= N; i++){
    cumsum_tail.at(N-i)= (i==1) ? data.at(N-1)
                                : cumsum_tail.at(N-i+1)+ data.at(N-i);
  }

  mint ans= 0;
  for(int i=0; i+1 < N; i++){
    ans+= data.at(i)* cumsum_tail.at(i+1);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 6348
#include <bits/stdc++.h>
using namespace std;
int n, f[2005][2005], ty[4005], id[4005], totb[4005][2005], totw[4005][2005], posb[2005], posw[2005];
char s[5];
int main()
{
#ifdef _noname
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	memset(f, 0x3f3f3f, sizeof f);
	f[0][0] = 0;
	scanf("%d", &n);
	for (int i = 1; i <= n * 2; i++)
	{
		scanf("%s%d", s, id + i);
		for (int j = 0; j <= n; j++) totb[i][j] = totb[i - 1][j], totw[i][j] = totw[i - 1][j];
		if (s[0] == 'B')
		{
			posb[id[i]] = i;
			ty[i] = 1;
			for (int j = 0; j < id[i]; j++) totb[i][j]++;
		}
		else
		{
			posw[id[i]] = i;
			ty[i] = 2;
			for (int j = 0; j < id[i]; j++) totw[i][j]++;
		}
	}
	for (int i = 0; i <= n; i++)
		for (int j = 0; j <= n; j++)
		{
			if (i) f[i][j] = min(f[i][j], f[i - 1][j] + totb[posb[i]][i] + totw[posb[i]][j]);
			if (j) f[i][j] = min(f[i][j], f[i][j - 1] + totb[posw[j]][i] + totw[posw[j]][j]);
		}
	printf("%d\n", f[n][n]);
	return 0;
}


Measured memory_bytes: 78720
#include <iostream>

using namespace std;

int a, b, c, k;

void input() {
    cin >> a >> b >> c >> k;
}

int max() {
    int ans = 0, tmp = 0;
    if(a >= k) ans = k;
    else {
        tmp = a;
        k -= a;
        if(b >= k) ans = tmp;
        else {
            tmp += 0;
            k -= b;
            ans = tmp - k;
        }
    }
    return ans;
}

int main() {
    input();
    cout << max() << endl;
    return 0;
}


Measured memory_bytes: 3636
n,l = map(int,input().split())
A = []
for i in range(1,n+1):
    A.append(l+i-1)

if 0 in A:
    print(sum(A))
else:
    B = [abs(n) for n in A]
    m = min(B)
    if m in A:
        print(sum(A)-m)
    else:
        print(sum(A)+m)

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

using ll = long long;
using ld = long double;

int main()
{
    int n;
    bool four = false;
    cin >> n;
    
    for(int i = 0; i < n; i++)
    {
        char c;
        cin >> c;
        if(c=='Y') four = true;
    }
    

    if(four)
    {
        cout << "Four"<< endl;
    }
    else 
    {
        cout << "Three" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
n=io.read("*n","*l")
s={}
for i=1,n do
    x=io.read()
    if not s[x] then
        s[x]=1
    else
        s[x]=s[x]+1
    end
end
m=io.read("*n","*l")
t={}
for i=1,m do
    x=io.read()
    if not t[x] then
        t[x]=1
    else
        t[x]=t[x]+1
    end
end

yen=0
for k,v in pairs(s) do
    if t[k] then
        x=t[k]
    else
        x=0
    end
    yen=math.max(yen,s[k]-x)
end
print(yen)

Measured memory_bytes: 888
#include <bits/stdc++.h>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

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

ll gcd(ll n, ll m)
{
	ll tmp;
	while (m != 0)
	{
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m)
{
	return abs(n) / gcd(n, m) * abs(m); //gl=xy
}

using namespace std;

template<typename T>
vector<T> sieve(T n){//n以下の整数が素数か判定 エラトステネスの篩
    vector<T>prime(n+1);
		for(int i=0;i<=n;++i)prime[i]=i;
    for(int i=2;i*i<=n;i++){
        if(prime[i]<i)continue;
				for(int j=i*i;j<=n;j+=i){
					if(prime[j]>=i)prime[j]=i;
				}
    }
    return prime;
}

map< int64_t, int > prime_factor(int64_t n,const vector<int64_t>& min_factor){
  map< int64_t, int > ret;
  while(n>1){
		ret[min_factor[n]]++;
		assert(min_factor[n]!=0);
		n/=min_factor[n];
	}
  if(n != 1) ret[n] = 1;
  return ret;
}


void solve()
{
	int64_t n;
	cin>>n;
	vector<int64_t>v=sieve(n);
	// for(auto x:v){
	// 	cout<<x<<"\n";
	// }
	ll ans=1;
	REP(i,2,n+1){
		ll cul=1;
		for(auto x:prime_factor(i,v)){
			cul*=x.second+1;
		}
		ans+=cul*i;
	}
	cout<<ans<<"\n";
}

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


Measured memory_bytes: 81328
from sys import stdin
input = stdin.readline

n = input().rstrip()
a = list(map(int, input().split()))

ans = 0
for i in range(len(a)-1):
    if a[i] > a[i+1]:
        diff = a[i] - a[i+1]
        a[i+1] += diff
        ans += diff

print(ans)

Measured memory_bytes: 31464
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <string>
 
using namespace std;
 
int main() {
	long long N, P;
	cin >> N >> P;
	long long temp;
	bool flg;
	for (long long i = pow(P,1/double(N))+1; i > 0; i--) {
		temp = P;
		flg = true;
		if (i == 1) {
			cout << i;
			break;
		}
		for (long long j = 0; j < N; j++) {
			if (temp%i == 0) {
				temp = temp / i;
			}
			else {
				flg = false;
				break;
			}
		}
		if (flg) {
			cout << i;
			break;
		}
		
	}
	return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
cnt=[1]*n
s=set([1])
for i in range(m):
  x,y=map(int,input().split())
  cnt[y-1]+=1
  cnt[x-1]-=1
  if x in s:
    s.add(y)
  if cnt[x-1]==0:
    if x in s:
      s.remove(x)
print(len(s))

Measured memory_bytes: 12652
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        int[] a = new int[n];
        for(int i=0;i<n;i++)a[i]=sc.nextInt();

        int ans = Integer.MAX_VALUE;
        for(int i=-100;i<101;i++){
            int sum=0;
            for(int j=0;j<n;j++){
                sum+=Math.pow(a[j]-i,2);
            }
            ans = Math.min(ans,sum);

        }

        System.out.println(ans);


    }
}


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

#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define ll long long

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

  vector<unsigned ll> a(n);
  bool zero = false;
  rep(i, 0, n){
    cin >> a[i];
    if(a[i] == 0) zero = true;
  }

  if(zero){
    cout << 0 << endl;
    return 0;
  }

  unsigned ll ans = 1;
  rep(i, 0, n){
    if(ans*a[i] > (ll)1e18 or ans*a[i]/a[i] != ans){
      cout << -1 << endl;
      return 0;
    }
    ans *= a[i];
  }

  cout << ans << endl;

  return 0;
}



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

using namespace std;

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

    set<int> num;
    for (int i = 0; i < 3; ++i) {
        int c;
        cin >> c;
        num.insert(c);
    }

    cout << num.size() << endl;

    return 0;
}


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

using namespace std;

using P = pair<string, string>;

int main()
{
    int N, F, M, cnt = 0;
    map<P, int> comb;
    cin >> N >> F;
    for (int i = 0; i < N; i++) {
        cin >> M;
        vector<string> v(M);
        for (int j = 0; j < M; j++) {
            cin >> v[j];
        }
        for (int j = 0; j < M; j++) {
            for (int k = j + 1; k < M; k++) {
                string a = v[j];
                string b = v[k];
                if (a > b) swap(a, b);
                comb[P(a, b)]++;
            }
        }
    }
    for (auto& it : comb) {
        if (it.second >= F) ++cnt;
    }    
    cout << cnt << endl;
    for (auto& it : comb) {
        if (it.second >= F) {
            cout << it.first.first << " " << it.first.second << endl;
        }
    }
    return 0;
}

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

int main(){
    int n;
    cin>>n;
    ll ans=0;
    for(int i=1; i<=n; ++i)ans+=(ll)i*(n-i+1);
    rep(i,n-1){
        int a,b;
        cin>>a>>b;
        if(a>b)swap(a,b);
        ans-=(ll)a*(n-b+1);
    }
    cout<<ans<<endl;
}

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

enum Direction{SOUTH,EAST};

int main()
{
  int H,W,N;
  int y,x;
  while(cin>>H>>W>>N,H|W|N){
    vector< vector<int> >v(H,vector<int>(W));
    vector< vector<int> >dp(H,vector<int>(W,0));
    for(int i=0;i<H;i++)for(int j=0;j<W;j++)cin>>v[i][j];
    dp[0][0]=N-1;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	if(i-1>=0){
	  if(dp[i-1][j]&1){
	    if(v[i-1][j]==SOUTH)dp[i][j]+=(dp[i-1][j]+1)/2;
	    else dp[i][j]+=(dp[i-1][j]-1)/2;
	  }else{
	    dp[i][j]+=dp[i-1][j]/2;
	  }
	}
	if(j-1>=0){
	  if(dp[i][j-1]&1){
	    if(v[i][j-1]==EAST)dp[i][j]+=(dp[i][j-1]+1)/2;
	    else dp[i][j]+=(dp[i][j-1]-1)/2;
	  }else{
	    dp[i][j]+=dp[i][j-1]/2;
	  }
	}
      }
    }
    y=x=0;
    while(x<W && y<H){
      v[y][x]+=dp[y][x];
      v[y][x]&=1;
      if(v[y][x]==SOUTH)y++;
      else x++;
    }
    cout<<y+1<<" "<<x+1<<endl;
  }
}

Measured memory_bytes: 8760
# code-festival-2017-qualaC - Palindromic Matrix
from collections import defaultdict


def main():
    H, W, *A = open(0).read().split()
    H, W, C = int(H), int(W), defaultdict(int)
    for i in "".join(A):
        C[i] += 1
    single = H & W & 1
    double = (H >> 1 if W & 1 else 0) + (W >> 1 if H & 1 else 0)
    C_mod4 = [i % 4 for i in C.values()]
    flg = C_mod4.count(1) + C_mod4.count(3) <= single and C_mod4.count(2) <= double
    print("Yes" if flg else "No")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef bool boolean;

const int N = 1e5 + 5;

int gcd(int a, int b) {
	return (b) ? (gcd(b, a % b)) : a;
}

int n;
int a[N];

boolean solve() {
	int c[2] = {0, 0};
	boolean aflag = false;
	for (int i = 1; i <= n; i++) {
		c[a[i] & 1]++;
		if (a[i] == 1) {
			aflag = true;
		}
	}
	if (aflag) {
		int sum = 0;
		for (int i = 1; i <= n; i++) {
			sum ^= (a[i] - 1) & 1;
		}
		return sum;
	}
	if ((!(c[0] & 1)) && c[1] >= 2) {
		return false;
	} else if ((c[0] & 1) && c[1] >= 1) {
		return true;
	}
	int x = 1, g = 0;
	while (!(a[x] & 1))
		x++;
	--a[x];
	for (int i = 1; i <= n; i++)
		g = gcd(a[i], g);
	for (int i = 1; i <= n; i++)
		a[i] /= g;
	return !solve();
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", a + i);
	}
	boolean ans = solve();
	puts((ans) ? ("First") : ("Second"));
	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  ll n;
  cin>>n;
  std::vector<ll> a(n);
  std::map<ll, ll> mp;
  for(auto&& e: a) 
  {
    cin>>e;
    mp[e]++;
  }
  map<ll,ll> comb;
  ll sum=0;
  for(const auto& e: mp) 
  {
    comb[e.first]=(e.second)*(e.second-1)/2;
    sum+=comb[e.first];
  }

  for (int k = 0; k < n; ++k)
  {
    cout<<sum-comb[a[k]]+(mp[a[k]]-1)*(mp[a[k]]-2)/2<<endl;
  }

  
}

Measured memory_bytes: 19712
#include<stdio.h>

int main(void)
{
  int k,sum,n,S = 0;

  scanf("%d",&n);

  k = n;

  while(k != 0){
    S += k % 10;
    k /= 10;
  }

  sum = n % S;

  if(sum == 0){
    printf("Yes");
  }
  else{
    printf("No");
  }

  return 0;

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
using namespace std;

inline void vec(vector<int> a){
    rep(i,a.size()-1){
        cout<<a.at(i)<<' ';
    }
    cout<<a.back()<<endl;
}

signed main(){
    int n,x; cin>>n>>x;
    
    if(x==1 or x==n*2-1){
        cout<<"No"<<endl;
        return 0;
    }
    cout<<"Yes"<<endl;
    
    if(n==2){
        cout<<1<<' '<<2<<' '<<3<<endl;
        return 0;
    }
    
    vector<int> ans(n*2-1);
    rep(i,ans.size()){
        ans.at(i)=i+1;
    }
    
    if(x==2){
        swap(ans.at(1),ans.at(ans.size()/2));
        swap(ans.front(),ans.at(ans.size()/2-1));
        vec(ans);
        return 0;
    }else{
        swap(ans.at(x-1),ans.at(ans.size()/2));
        swap(ans.at(ans.size()/2+1),ans.back());
        swap(ans.front(),ans.at(ans.size()/2-1));
        swap(ans.at(1),ans.at(ans.size()/2+2));
        vec(ans);
        return 0;
    }
}

Measured memory_bytes: 4608
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int x,count=1,ma=1;
	cin>>x;
	for(int i=2;i*i<=x;i++){
		while(count*i<=x){
			count*=i;
		}
		if(count>ma)ma=count;
		count=1;
	}
	cout<<ma<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void)
{
    long long N, A[200001], sum=0, i, judge=1, x, y=0, z=0;
    double div;

    cin >> N;

    for(i=1; i<=N; i++){
        cin >> A[i];
        sum += A[i];
    }

    div = (double)sum / 2;

    for(i=1; i<=N; i++){
        div -= A[i];

        if(div == 0){
            judge = 0;
            break;
        }

        else if(div < 0){
            x = i;
            break;
        }
    }

    if(judge == 0){
        cout << 0 << endl;
    }

    else{
        for(i=1; i<=N; i++){
            if(i <= (x-1)){
                y += A[i];
                z -= A[i];
            }
            else if(i == x){
                y += A[i];
                z += A[i];
            }
            else{
                y -= A[i];
                z += A[i];
            }
        }
        if(y<z){
            cout << y << endl;
        }
        else{
            cout << z << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main() {
    int n, m, o;
    cin >> n >> m >> o;
    int ans = 9999999;
    ans = min(abs(n-m)+abs(m-o),ans);
    ans = min(abs(n-o)+abs(m-o),ans);
    ans = min(abs(n-o)+abs(m-n),ans);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
typedef pair<pair<int, int>, int> ppi;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef bitset<60> Bitset;
const ll INFL = 1LL << 60;
const int INF = 1000000005;
const int MAX = 300000;
const int MOD = 1000000007;
struct Graph{int to,coin; ll cost;};
struct Edge{int from,to,coin; ll cost;};
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
//------------------------------------------------------------------------------------------------------------------------------

int main(void) {
    ios::sync_with_stdio(false);cin.tie(nullptr);
    int n;cin>>n;
    vl a(n);
    ll m;cin>>m;
    ll t = 1;
    for(int i = 0; i < n; i++) {
        cin>>a[i];
        a[i] /= 2;
        t = LCM(t,a[i]);
    }
    for(int i = 0; i < n; i++) {
        if((t/a[i])%2==0){
            cout<<0<<endl; return 0;
        }
    }
    cout<<(m/t+1)/2<<endl;
}


Measured memory_bytes: 3964