akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    map<string, int> mp;
    rep(i, N) {
        string s;
        cin >> s;
        mp[s]++;
    }
    int ma = 0;
    for(auto x : mp) {
        ma = max(x.second, ma);
    }
    for(auto x : mp) {
        if(x.second == ma) {
            cout << x.first << endl;
        }
    }
    return 0;
}

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

ll mod = 1e9+7;
ll dp[10001][100][2];

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  string s;
  cin >> s;
  int d;
  cin >> d;
  dp[0][0][0] = 1;
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j < d; j++) {
      for (int k = 0; k < s[i]-'0'; k++)
	(dp[i+1][(j+k)%d][1] += dp[i][j][0]) %= mod;
      for (int k = 0; k < 10; k++)
	(dp[i+1][(j+k)%d][1] += dp[i][j][1]) %= mod;
      (dp[i+1][(j+(s[i]-'0'))%d][0] += dp[i][j][0]) %= mod;
    }
  }
  cout << (dp[s.size()][0][0]+dp[s.size()][0][1]-1+mod)%mod << endl;
}


Measured memory_bytes: 15872
#include<iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
using namespace std;
int main(){
  int n;
  cin >> n;
  long long int a[n];
  for(int i=0;i<n;i++) cin >>a[i];
 sort(a,a+n);
 cout << abs(a[n-1]-a[0])<<endl;
}


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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) (((a)+(b)-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define INF LLONG_MAX/2
#define PI acos(-1.0)
//#define MOD 1000000007

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;
typedef priority_queue<int> PQi;

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;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vout(Vs &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());} //vectorの同じ要素消す
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
int leng(int n){string s=to_string(n); return s.size();} //intの桁数
int digitsum(int n){int ret=0; while(n>0){ret+=n%10;n/=10;}return ret;} //桁和
int lesscount(int x,Vi &a){return lower_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx未満の数の個数
int orlesscount(int x,Vi &a){return upper_bound(a.begin(),a.end(),x)-a.begin();} //vector aにおけるx以下の数の個数
int morecount(int x,Vi &a){return a.size()-orlesscount(x,a);} //vector aにおけるxより大きい数の個数
int ormorecount(int x,Vi &a){return a.size()-lesscount(x,a);} //vector aにおけるx以上の数の個数
int count(int x,Vi &a) {return upper_bound(ALL(a),x)-lower_bound(ALL(a),x);} //vector aにおけるxの個数
Vi accum(Vi &v){Vi ret((v).size()+1);REP(i,0,(v).size()) ret[i+1]=ret[i]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

const string YES = "Yes";
const string NO = "No";
template<class T> void YesNo(T a) {cout<<(a?YES:NO)<<endl;}

void solve(long long A, long long B, long long C, long long D){
    while(1){
        if(A<=0){
            cout<<NO<<endl;
            break;
        }
        if(C<=0){
            cout<<YES<<endl;
            break;
        }
        C-=B;
        if(A<=0){
            cout<<NO<<endl;
            break;
        }
        if(C<=0){
            cout<<YES<<endl;
            break;
        }
        A-=D;
    }
}

signed main(){cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long D;
    scanf("%lld",&D);
    solve(A, B, C, D);
    return 0;
}


Measured memory_bytes: 3712
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,avx2,fma,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(0),cin.tie(0), cout.tie(0)
typedef long long ll;


ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

//#######################################


int main(){
  boost;
  
  ll n;
  cin>>n;
  ll a[n];
  for(int i=0;i<n;i++){
	  cin>>a[i];
  }
  ll ans=0;
  for(int i=1;i<n;i++){
	  if(a[i-1]>a[i]){
	  	ans+=(a[i-1]-a[i]);
		a[i]=a[i-1];
	  }
  }
  cout<<ans;
}



Measured memory_bytes: 5184
local DBG = false
local function dbgpr(...)
    if DBG then
        io.write("[dbg]")
        print(...)
    end
end

-- returns (b^n) % m
local function modpow(b, n, m)
    if n == 0 then
        return 1
    else
        return b * modpow(b, n - 1, m) % m
    end
end

---
local MOD = 998244353
local N = io.read("*n")
local a = {}
local S = 0
for i=1,N do
    a[i] = io.read("*n")
    S = S + a[i]
end


local function fill90000(t, v)
    for i=1,900000 do
        t[i] = v
    end
end

local function default0(t)
    local mt = {
        __index = function(t,k)
            return 0
        end
    }
    setmetatable(t, mt)
end

-- ∑A = S/2 and ∑B = S/2 and ∑C = 0
local function getY()
    if S % 2 == 1 then
        return 0
    end
    local cache = {}
    default0(cache)
    --fill90000(cache, 0)
    cache[0] = 1
    local curmax = 0
    for i=1,N do
        local cur = a[i]
        curmax = curmax + cur
        for s=curmax,cur,-1 do
            cache[s] = (cache[s] + cache[s-cur]) % MOD
        end
    end
    return cache[math.floor(S/2)]
end

-- ∑A >= S/2
local function getX()
    local cache = {}
    default0(cache)
    --fill90000(cache, 0)
    cache[0] = 1
    local curmax = 0
    for i=1,N do
        local cur = a[i]
        curmax = curmax + cur
        for s=curmax,cur,-1 do
            cache[s] = (2 * cache[s] + cache[s-cur]) % MOD
        end
        for s=cur-1,0,-1 do
            cache[s] = 2 * cache[s] % MOD
        end
    end
    local sum = 0
    for s = math.ceil(S/2), curmax, 1 do
        sum = sum + cache[s]
    end
    return sum
end

local X, Y = getX(), getY()
local Total = modpow(3, N, MOD)
--dbgpr(Total, X, Y)
local ans = (Total - (3 * X) % MOD + (3 * Y) % MOD) % MOD
print(ans)


Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second

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

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

template<typename T> T chmax(T& a, const T& b){return a = (a > b ? a : b);}
template<typename T> T chmin(T& a, const T& b){return a = (a < b ? a : b);}

int main(){
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    vector<int> cnt(61);
    auto addCnt = [&](ll k) {
        rep(i, 61) if(k&(1LL<<i)) cnt[i]++;
    };
    addCnt(a[n-1]);
    ll ans = 0LL;
    ll num = 1;
    repr(i, n-1) {
        rep(j, 61) {
            if(a[i]&(1LL<<j)) {
                (ans += (1LL<<j)%MOD*(num-cnt[j])%MOD) %= MOD;
            }
            else {
                (ans += (1LL<<j)%MOD*(cnt[j])%MOD) %= MOD;
            }
        }
        addCnt(a[i]);
        ++num;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
use io::*;
use std::*;
use std::collections::BinaryHeap;

fn solve(N: i64, M: i64, A: Vec<i64>) {
    let mut bin_heap = BinaryHeap::from(A);
    for i in 0..M {
        let a = bin_heap.pop().unwrap() / 2i64;
        bin_heap.push(a);
    }
    let mut vec = Vec::from(bin_heap);
    let sum: i64 = vec.iter().fold(0, |sum, a| sum + a);
    println!("{}", sum);
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
fn main() {
    let con = read_string();
    let mut scanner = Scanner::new(&con);
    let mut N: i64;
    N = scanner.next();
    let mut M: i64;
    M = scanner.next();
    let mut A: Vec<i64> = vec![0i64; (N) as usize];
    for i in 0..(N) as usize {
        A[i] = scanner.next();
    }
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(move || solve(N, M, A)).unwrap().join().unwrap();
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 10620
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    // 1つ目
    int a = sc.nextInt();
    // 2つ目
    int b = sc.nextInt();

    if (a == b) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 24020
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=a;i<=b;i++)
using namespace std;

typedef long long LL;

const int maxn=2e5+5;

int n,a[maxn],cnt[maxn];

struct B{int val,i;} b[maxn];
bool cmpB(const B &a,const B &b) {return a.val<b.val;}
int maxr,ax[maxn];
void discretize()
{
	fo(i,1,n) b[i]=(B){a[i],i};
	sort(b+1,b+1+n,cmpB);
	fo(i,1,n)
	{
		if (i==1 || b[i].val>b[i-1].val) ax[++maxr]=b[i].val-b[i-1].val;
		a[b[i].i]=maxr;
	}
}

bool tr[4*maxn];
void update(int k,int t)
{
	tr[t]|=tr[k], tr[t+1]|=tr[k];
	tr[k]=0;
}
void tr_xg(int k,int l,int r,int x,int y)
{
	if (x>y) return;
	if (x<=l && r<=y) {tr[k]=1; return;}
	int t=k<<1, mid=(l+r)>>1;
	update(k,t);
	if (x<=mid) tr_xg(t,l,mid,x,y);
	if (mid<y) tr_xg(t+1,mid+1,r,x,y);
}
bool tr_cx(int k,int l,int r,int x)
{
	while (l<r)
	{
		int t=k<<1, mid=(l+r)>>1;
		update(k,t);
		if (x<=mid) k=t, r=mid;
			else k=t+1, l=mid+1;
	}
	bool re=tr[k];
	tr[k]=0;
	return re;
}

LL Pow(LL x,LL y)
{
	if (x==1) return 1;
	LL re=1;
	fo(i,1,y)
	{
		re*=x;
		if (re>n) return re;
	}
	return re;
}

LL lim[maxn];
bool check(int mid)
{
	memset(cnt,0,sizeof(cnt));
	memset(tr,0,sizeof(tr));
	fo(i,1,maxr) cnt[i]=0, lim[i]=Pow(mid,ax[i]);
	
	fo(i,2,n) if (a[i]<=a[i-1])
	{
		int j=a[i];
		if (tr_cx(1,1,maxr,j)) cnt[j]=0;
		while (j>0 && cnt[j]+1>=lim[j])
		{
			j--;
			if (tr_cx(1,1,maxr,j)) cnt[j]=0;
		}
		if (j==0) return 0;
		cnt[j]++;
		tr_xg(1,1,maxr,j+1,maxr);
	}
	return 1;
}

int main()
{
	scanf("%d",&n);
	fo(i,1,n) scanf("%d",&a[i]);
	
	discretize();
	
	int l=1, r=n;
	while (l<=r)
	{
		int mid=(l+r)>>1;
		if (check(mid)) r=mid-1; else l=mid+1;
	}
	
	printf("%d\n",r+1);
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
int main(){
  int H,W;
  cin >>H>>W;
  int skyans[H][W];
  char sky[H][W];
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >>sky[i][j];
    }
  }

  for(int i=0;i<H;i++){
    int count=-1;
    for(int j=0;j<W;j++){
      if(count!=-1)count++;
      if(sky[i][j]=='c')count =0;
      skyans[i][j]=count;
    }
  }
  for(int i=0;i<H;i++){
    for(int j=0;j<W-1;j++){
      cout <<skyans[i][j]<<" ";
    }
    cout <<skyans[i][W-1]<<endl;
  }
  return 0;
}

Measured memory_bytes: 3148
#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, W;
    cin >> N >> W;
    vector<int> v(N);
    vector<int> w(N);
    rep(i, N) {
        cin >> v[i] >> w[i];
    }

    vector<int> dp(W + 1, 0);

    for (int i = 0; i < N; i++) {
        for (int j = w[i]; j <= W; j++) {
            dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
        }
    }
    cout << dp[W] << endl;
}


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

using namespace std;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for (int i = 0; i < H; i++) {
        cin >> S[i];
    }

    priority_queue<pii, vector<pii>, greater<pii>> Q;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (S[i][j] == '#') {
                Q.push({0, i * W + j});
            }
        }
    }
    
    const int INF = 1 << 29;
    vector<vector<int>> dist(H, vector<int>(W, INF));
    while(!Q.empty()) {
        pii p = Q.top(); Q.pop();
        int d = p.first;
        int y = p.second / W;
        int x = p.second % W;
        if (d >= dist[y][x]) continue;
        dist[y][x] = d;

        int dx[] = {0, 1, 0, -1};
        int dy[] = {1, 0, -1, 0};
        for (int k = 0; k < 4; k++) {
            int tx = x + dx[k];
            int ty = y + dy[k];
            if (tx < 0 || tx >= W || ty < 0 || ty >= H) continue;
            if (d + 1 >= dist[ty][tx]) continue;
            Q.push({d + 1, ty * W + tx});
        }
    }

    int ma = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            ma = max(ma, dist[i][j]);
        }
    }
    cout << ma << endl;
    
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 22764
#include<bits/stdc++.h>
using namespace std;
int main() {
	long long n,m;
	cin>>n>>m;
	if(n*2>m) {
		cout<<m/2<<endl;
		return 0;
	}
	if(n*2==m) {
		cout<<n<<endl;
		return 0;
	}
	cout<<n+((m-(2*n))/4)<<endl;
}

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

using namespace std;

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

long long dis1[210][210];
long long dis2[210][210];
long long dp[2][210];

int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0) break;
    rep (i, n) rep (j, n) dis1[i][j] = 1e18;
    rep (i, n) rep (j, n) dis2[i][j] = 1e18;
    rep (i, n) dis1[i][i] = 0;
    rep (i, n) dis2[i][i] = 0;
    rep (i, m) {
      long long x, y, t;
      string sl;
      cin >> x >> y >> t >> sl;
      --x, --y;
      if (sl == "L") dis1[x][y] = dis1[y][x] = min(dis1[y][x], t);
      else dis2[x][y] = dis2[y][x] = min(dis2[y][x], t);
    }
    rep (k, n) rep (i, n) rep (j, n) dis1[i][j] = min(dis1[i][j], dis1[i][k] + dis1[k][j]);
    rep (k, n) rep (i, n) rep (j, n) dis2[i][j] = min(dis2[i][j], dis2[i][k] + dis2[k][j]);
    int r, p;
    cin >> r >> p;
    --p;
    rep (i, 2) rep (j, n) dp[i][j] = 1e18;
    dp[0][p] = 0;
    rep (_, r - 1) {
      int q;
      cin >> q;
      --q;
      rep (i, n) rep (j, n) dp[1][j] = min(dp[1][j], dp[0][i] + dis1[p][i] + dis2[i][j] + dis1[j][q]);
      rep (i, n) dp[1][i] = min(dp[1][i], dp[0][i] + dis1[p][q]);
      rep (i, n) dp[0][i] = dp[1][i];
      rep (i, n) dp[1][i] = 1e18;
      p = q;
    }
    long long res = 1e18;
    rep (i, n) res = min(res, dp[0][i]);
    cout << res << endl;
  }
}

Measured memory_bytes: 1872
<?php
define('MOD', pow(10, 9) + 7);
define('BIT', 60);
$x[0] = 1;
for ($i = 1; $i < BIT; $i++) {
    $x[$i] = $x[$i - 1] * 2;
    $x[$i] %= MOD;
}

fscanf(STDIN, "%d", $N);
$a = array_map('intval', explode(' ', trim(fgets(STDIN))));

$k[0] = array_pad(array(), BIT, 0);
$k[1] = array_pad(array(), BIT, 0);
$ans = 0;
for ($i = 0; $i < $N; $i++) {
    $s = strrev(str_pad(decbin($a[$i]), BIT, '0', STR_PAD_LEFT));
    for ($j = 0; $j < BIT; $j++) {
        $k[$s[$j]][$j]++;
    }
}
for ($i = 0; $i < BIT; $i++) {
    $tmp = $k[0][$i] * $k[1][$i];
    $tmp %= MOD;
    $tmp *= $x[$i];
    $tmp %= MOD;
    $ans += $tmp;
}
$ans %= MOD;
printf("%d", $ans);


Measured memory_bytes: 40936
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(998244353);
const ll HLF = (MOD+1)>>1;
const int M = (int)(1e6);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll rwpw(ll a, ll p){
	ll ret = 1ll;
	while(p){
		if(p&1){
			mul_mod(ret,a);
		}
		mul_mod(a,a);
		p >>= 1;
	}
	return ret;
}

ll a[1001001],w[1001001];

int main(void){
	int n,x,i,j;
	ll p,q,nv,ans=0ll;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> x;
		++a[x];
	}
	for(i=1; i<=M; ++i){
		nv = rwpw(i,MOD-2);
		add_mod(w[i],nv);
		p = a[i]*i%MOD;
		q = (a[i]*i%MOD)*i%MOD;
		for(j=i*2; j<=M; j+=i){
			add_mod(w[j],MOD-w[i]);
			add_mod(p,a[j]*j%MOD);
			add_mod(q,(a[j]*j%MOD)*j%MOD);
		}
		mul_mod(p,p);
		add_mod(p,MOD-q);
		mul_mod(p,HLF);
		mul_mod(p,w[i]);
		add_mod(ans,p);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	
	//cout<<pow(200,5);
	for(ll i=-200;i<=200;i++)
	{
		ll b = n - pow(i,5);
		//cout<<b<<" ";
		bool flg = false;
		ll j;
		for(ll i=0;i<=200;i++)
		{
			if (pow(i,5)==abs(b))
			{
				if (b>0)
				j = -i;
				else
				j = i;
				flg = true;
				break;
			}
		}
		if (flg)
		{
			cout<<i<<" "<<j;
			break;
		}
	}

}

Measured memory_bytes: 4092
#include <stdio.h>

#include<stdlib.h>

#include<string.h>



int main(void){

char num_str[1002];

int num;

long sum=0;

int i;

char tmp;



while(1){

fgets(num_str, sizeof(num_str), stdin);



if (num_str[0]=='0') break;



for (i=0; i<strlen(num_str)-1;i++){

tmp=num_str[i];

num =atoi(&tmp);

sum=sum+num;

};

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



sum=0;

memset(num_str,1002,0);

};

return 0;

};

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

#define int long long

using namespace std;

const int MAXN = 2e5 + 100;

#ifdef LOCAL 
#include "/media/brayand/BrayanD/debugger.h"
#else
#define db(...) false
#define dbl(...) false
#define dbg(...) false
#endif

int mp1[MAXN];
int mp2[MAXN];

vector<int> arr[MAXN];

int mp3[MAXN];

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

    int N;
    cin >> N;

    vector<int> v1, v2;

    for(int i = 0 ; i < N ; i++)
    {
    	int n;
    	cin >> n;
    	v1.push_back(n);

    	arr[n].push_back(i);

    	mp1[n]++;
    }

    for(int i = 0 ; i < N ; i++)
    {
    	int n;
    	cin >> n;
    	v2.push_back(n);

    	mp2[n]++;
    }

    bool flag = false;

    for(int i = 1 ; i <= N ; i++)
    {
    	if(mp1[i] + mp2[i] > N)flag = true;
    }

    if(flag)
    {
    	cout << "No" << '\n';
    	return 0;
    }

    vector<pair<int,int>> vect;

    vector<int> temp;

    for(int i = 0 ; i < N ; i++)
    {
    	if(arr[v2[i]].size())
    	{
    		vect.push_back({v2[i], arr[v2[i]].back()});
    		arr[v2[i]].pop_back();
    	}
    	else
    	{
    		temp.push_back(v2[i]);
    	}
    }

    int may = -1;
    int val = -1;

    for(auto x : vect)
    {
    	mp3[x.first]++;

    	if(mp3[x.first] > may)
    	{
    		may = mp3[x.first];
    		val = x.first;
    	}
    }

    if(val == -1)
    {
    	cout << "Yes" << '\n';
    	for(auto x : v2)
    	{
    		cout << x << " ";
    	}
    	return 0;
    }

    int del = 0;

    int tam = vect.size();

    while(may*2 > tam)
    {
    	may--;
    	del++;
    	tam--;
    }

    int cont = 0;

    vector<pair<int,int>> good;

    vector<pair<int,int>> otro;

    for(auto x : vect)
    {
    	if(del && x.first == val)
    	{
    		otro.push_back(x);
    		del--;
    		cont++;
    		continue;
    	}
    	good.push_back(x);
    }

    vector<int> res(N);

    for(int i = 0 ; i < good.size() ; i++)
    {
    	res[good[(i+may)%good.size()].second] = good[i].first;
    }

    vector<pair<int,int>> nw;

    vector<pair<int,int>> tipo;

    for(int i = 1 ; i <= N ; i++)
    {
    	while(arr[i].size())
    	{
    		if(i == val || temp.back() == val)tipo.push_back({temp.back(), arr[i].back()});
    		else nw.push_back({temp.back(), arr[i].back()});

    		temp.pop_back();
    		arr[i].pop_back();
    	}
    }

    for(auto x : tipo)nw.push_back(x);
    for(auto x : otro)nw.push_back(x);

    	db(nw);

    db(cont);
    db(good);

    for(int i = 0 ; i < nw.size() ; i++)
    {
    	res[nw[(i+cont)%nw.size()].second] = nw[i].first;
    }

    cout << "Yes" << '\n';

    for(auto x : res)
    {
    	cout << x << " ";
    }
    cout << '\n';

    return 0;
}

Measured memory_bytes: 31164
#include<stdio.h>
int main(void){
 
    int i,n,a[100];
 
    scanf("%d",&n);
 
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
 
	for(i=n-1;i>0;i--){
		printf("%d ",a[i]);
	}
 
    printf("%d\n",a[0]);
 
    return 0;
 
}

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

using namespace std;

typedef long long int ll;
typedef pair<int, int> P;
#define INF 10000000000000
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i < (int)(n); i++)
#define repN_1(i, n) for(int i = 0; i < (int)(n - 1); i++)
#define repM(i, n) for(int i = (int)(n - 1); i >= 0; i--)
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 main()
{
	int n;
	string s;
	
	cin >> n;
	cin >> s;

	rep(i, s.size()) {
		s[i] = (s[i] + n);
		if (s[i] > 'Z')
			s[i] -= 26;
	}
	cout << s << endl;

	return 0;
}

Measured memory_bytes: 256
#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;
    vector<int> h(n);
    bool ok = true;
    rep(i, n) {
        cin >> h[i];
        if (i == 0) {
            h[i]--;
            continue;
        }
        if (h[i-1] < h[i]) h[i]--;
        if (h[i] < h[i-1]) {
            ok = false;
            break;
        }
    }
    if (ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3740
#include <iostream>

using namespace std;

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

    if(M==1){
        int ans=1;
        for(int i=0;i<N;i++){
            ans*=2;
            ans%=1000000;
        }
        cout << ans << endl;
    }else{
        int dp[N][5];
        // 0 |-- <- 0 1 2   4
        // 1 -|- <- 0 1 2 3 4
        // 2 --| <- 0 1 2 3  
        // 3 ||\ <- 0     3  
        // 4 /|| <-     2   4

        dp[0][0]=dp[0][1]=dp[0][2]=dp[0][3]=1;
        dp[0][4]=0;

        for(int i=1;i<N;i++){
            dp[i][0]=dp[i-1][0]+dp[i-1][1]+dp[i-1][2]           +dp[i-1][4];
            dp[i][1]=dp[i-1][0]+dp[i-1][1]+dp[i-1][2];
            dp[i][2]=dp[i-1][0]+dp[i-1][1]+dp[i-1][2]+dp[i-1][3];
            dp[i][3]=dp[i-1][0]                      +dp[i-1][3];
            dp[i][4]=                      dp[i-1][2]           +dp[i-1][4];
            dp[i][0]%=1000000;
            dp[i][1]%=1000000;
            dp[i][2]%=1000000;
            dp[i][3]%=1000000;
            dp[i][4]%=1000000;
        }
        int ans=dp[N-1][0]+dp[N-1][1]+dp[N-1][2]+dp[N-1][3];
        ans%=1000000;
        cout << ans << endl;
    }

}


Measured memory_bytes: 1164
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
using namespace std;
int main(){
	int H,N,x=0,y=0;
	cin>>H>>N;
	for(int i=1;i<=N;i++){
	cin>>x;
	y+=x;
	}
	if(y>=H)cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <stdio.h>

int main(int argc, char const *argv[]) {
  int H = 0,W = 0;
  std::cin >> H >> W;
  while(H != 0 && W != 0) {
    for(int i = 0; i < H; i++) {
      for(int j = 0; j < W; j++) {
        printf("#");
      }
      printf("\n");
    }
    printf("\n");
    std::cin >> H >> W;
  } 
  return 0;
}

Measured memory_bytes: 2984
Var s,x:ansistring;
    n,i:longint;
Begin
        readln(s);
        for i:=1 to length(s) do //遍历字符串s
        Begin
                if s[i] in ['C','F'] then //当s串的第i个位置是C或F就存入x串。
                Begin
                        x:=x+s[i];
                end;

                if pos('CF',x)<>0 then //判断是否出现过CF，如果有，就输出Yes并跳出
                Begin
                        write('Yes');
                        halt;
                end;
        end;
        write('No'); //因为如果有前面就跳出程序了，所以如果执行到这一步肯定是找不到
end.

Measured memory_bytes: 256
N = int(input())
S = []
for _ in range(N):
    S.append(input())
    
ac = 0
wa = 0
tle = 0
re = 0
for s in S:
    if s == "AC":
        ac += 1
    if s == "WA":
        wa += 1
    if s == "TLE":
        tle += 1
    if s == "RE":
        re += 1

print("AC x ",ac)
print("WA x ",wa)
print("TLE x ",tle)
print("RE x ",re)

Measured memory_bytes: 16276
int main()
{
  int S, h, m, s;

  scanf("%d", &S);

  s = S;
  m = 0;
  h = 0;

  if(s >= 60){
    m = s / 60;
    s = s - 60 * m;

    if(m >= 60){
      h = m / 60;
      m = m - 60 * h;

    }
  }

  printf("%d:%d:%d\n", h, m ,s);

  return 0;
}

Measured memory_bytes: 1816
#pragma region header
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rev(i, n) for(int i = (int)(n - 1); i >= 0; i--)
#define rev1(i, n) for(int i = (int)(n); i > 0; i--)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define resort(v) sort((v).rbegin(), (v).rend())
#define vi vector<int>
#define vvi vector<vector<int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
using ll = long long;
using P = pair<int, int>;
/* ----------------よく使う数字や配列----------------- */
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};
constexpr ll mod = 1e9+7;
constexpr int inf = INT32_MAX/2;
constexpr ll INF = LLONG_MAX/2;
constexpr long double eps = DBL_EPSILON;
constexpr long double pi = 3.141592653589793238462643383279;
/* ----------------------end----------------------- */

/* --------------------テンプレート------------------ */
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;
}
/* ----------------------end----------------------- */

/* --------------------ライブラリ-------------------- */
ll fact(int i) {       //階乗
    if (i == 0) return 1;
    return (fact(i - 1)) * i % mod;
}
ll gcd(ll a, ll b) {        //最大公約数
    if(b == 0) return a;
    return gcd(b, a % b); 
}
ll lcm(ll a, ll b) {      //最小公倍数
    return a * b / gcd(a, b);
}
int keta(ll n) {        //桁数を求める
    if(n == 0) return 1;
    int count = 0;
    while(n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
ll ketasum(ll n) {    //各桁の和
    ll sum = 0;
    while(n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
/* ----------------------end----------------------- */
#pragma endregion
signed main() {
    int h,w;cin >> h >> w;
    int count = 0;
    rep(i, h) {
        rep(j, w) {
            char c;cin >> c;
            if(c=='#') count++;
        }
    }
    if(count==h+w-1) puts("Possible");
    else puts("Impossible");
    return 0;
}

Measured memory_bytes: 3620
def generate357(num_str,n):  
  if len(num_str) < 3:
    pass
  elif int(num_str) > n:    
    return 0
  
  count = sum([generate357(str(i) + num_str, n) for i in '357'])      
  
  if all((s in num_str)  for s in '357'):
    count +=1
  return count   

n = int(input())
print(generate357('',n))

Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	int x, a, b;
	cin >> x >> a >> b;
	if (abs(x - a) < abs(x - b)) {
		cout << "A\n";
	}
	else {
		cout << "B\n";
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const double Pi=acos(-1);
int main(){
	double k,m,n,a,b;
	scanf("%lf%lf%lf",&a,&b,&n);
	n/=1.*a;
	if(a*b/2<=n){
		m=atan(2*(a*b-n)/a/a)/Pi*180;
	}
	else {
		m=atan(b*b/2/n)/Pi*180;
	}
	printf("%.8lf\n",m);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<l_l> vpl;
typedef vector<string> vs;
typedef pair<l_l,ll> lll;
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=1;i<=(n);i++)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=10100100100100100;
const ll dx[4]={1,-1,0,0};
const ll dy[4]={0,0,1,-1};
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 n;
ll a[20][20];
ll dp[1<<16];
ll cost[1<<16];
int main(){
    cin>>n;
    rep(i,n)rep(j,n)cin>>a[i][j];
    for(int Q=1;Q<(1<<n);Q++){
        rep(i,n){
            if(Q>>i&1){
                for(int j=i+1;j<n;j++){
                    if(Q>>j&1){
                        cost[Q]+=a[i][j];
                    }
                }
            }
        }
    }
    for(int Q1=1;Q1<(1<<n);Q1++){
        for(int Q2=Q1;Q2>0;Q2=(Q2-1)&Q1){
            dp[Q1]=max(dp[Q1],dp[Q1-Q2]+cost[Q2]);
        }
    }
    cout<<dp[(1<<n)-1]<<endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
ll MAX_N = 200005;

int main() {
  ll n;
  ll x[MAX_N], y[MAX_N];
  scanf("%lld", &n);
  for (ll i=0; i<n; i++) {
    scanf("%lld", &x[i]);
    y[i] = x[i];
  }
  sort(y, y+n);
  
  ll m = n/2 - 1;
  for (ll i=0; i<n; i++) {
    if (y[m] < x[i]) {
      printf("%lld\n", y[m]);
    } else {
      printf("%lld\n", y[m+1]);
    }
  }
  
  return 0;
}


Measured memory_bytes: 5376
#include<iostream>
#include<algorithm>
 using namespace std;
 int a[4];
 int main()
 {
 	int n,m,x,y,flag=0;
 	cin>>n>>m;
	a[1]=a[2]=a[3]=-1;
	for(int i=1;i<=m;i++){
		cin>>x>>y;
		if(a[x]!=-1&&a[x]!=y){
			flag=1;
			break;
		} 
		a[x]=y;
	}
	if(flag==1){
		cout<<-1<<endl;
		return 0;
	}
	if(a[1]==0&&n!=1){
		cout<<-1<<endl;
		return 0;
	}
	if(n==1&&a[1]==-1){
		cout<<0<<endl;
		return 0;
	}
	for(int i=1;i<=n;i++){
		if(a[i]==-1&&i==1){
			cout<<"1";
			continue;
		} 
		if(a[i]==-1) cout<<"0";
		else cout<<a[i];
	}
 }

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <set>
#include <map>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>
 
using namespace std;
typedef long long ll;
 
 
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする
 
vector<int> G[100005];
 
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
 
std::vector<P> tree[100010];
struct edge{int to,cost;};
 
ll i,j,k;
ll a[305][305];
ll n,ans=0;

 
int main(){
	cin>>n;
	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			cin>>a[i][j];
		}
	}

	bool dame=false;

	for(i=1;i<=n;i++){
		for(j=1;j<=n;j++){
			bool check=false;
			if(i==j)continue;
			for(k=1;k<=n;k++){
				if(i==k || j==k)continue;
				if(a[i][k]+a[k][j]<a[i][j]){
					dame= true;
					break;
				}else if(a[i][k]+a[k][j]==a[i][j]){
					check = true;
				}
			}
			if(!check)ans += a[i][j];
			check=false;
		}
	}
	if(dame)cout<<-1;
	else cout<<ans/2;

	cout<<endl;
	return 0;
}

Measured memory_bytes: 5632
use std::collections::HashSet;
use std::fmt::Debug;
use std::str::FromStr;

pub struct TokenReader {
    reader: std::io::Stdin,
    tokens: Vec<String>,
    index: usize,
}

impl TokenReader {
    pub fn new() -> Self {
        Self {
            reader: std::io::stdin(),
            tokens: Vec::new(),
            index: 0,
        }
    }

    pub fn next<T>(&mut self) -> T
    where
        T: FromStr,
        T::Err: Debug,
    {
        if self.index >= self.tokens.len() {
            self.load_next_line();
        }
        self.index += 1;
        self.tokens[self.index - 1].parse().unwrap()
    }

    pub fn vector<T>(&mut self) -> Vec<T>
    where
        T: FromStr,
        T::Err: Debug,
    {
        if self.index >= self.tokens.len() {
            self.load_next_line();
        }
        self.index = self.tokens.len();
        self.tokens.iter().map(|tok| tok.parse().unwrap()).collect()
    }

    pub fn load_next_line(&mut self) {
        let mut line = String::new();
        self.reader.read_line(&mut line).unwrap();

        self.tokens = line
            .split_whitespace()
            .map(String::from)
            .collect();
        self.index = 0;
    }
}

fn solve(bombs: &HashSet<(usize, usize)>, cr: &Vec<usize>, cc: &Vec<usize>) -> usize {
    let mut rows = (0..cr.len()).collect::<Vec<usize>>();
    rows.sort_by_key(|&i| -(cr[i] as i32));

    let mut cols = (0..cc.len()).collect::<Vec<usize>>();
    cols.sort_by_key(|&i| -(cc[i] as i32));

    let res = cr[rows[0]] + cc[cols[0]] - 1;
    let mut extra = 0;

    for i in 0..rows.len() {
        if cr[rows[i]] != cr[rows[0]] {
            break;
        }
        for j in 0..cols.len() {
            if cc[cols[j]] != cc[cols[0]] {
                break;
            }
            if !bombs.contains(&(rows[i], cols[j])) {
                extra = 1;
                break;
            }
        }
        if extra > 0 {
            break;
        }
    }
    res + extra
}

fn main() {
    let mut reader = TokenReader::new();
    let rows = reader.next::<usize>();
    let cols = reader.next::<usize>();

    let mut cr = vec![0; rows + 1];
    let mut cc = vec![0; cols + 1];

    let b = reader.next();
    let mut bombs = HashSet::new();
    for _ in 0..b {
        let r = reader.next();
        let c = reader.next();
        cr[r] += 1;
        cc[c] += 1;
        bombs.insert((r, c));
    }

    let res = solve(&bombs, &cr, &cc);
    println!("{}", res);
}


Measured memory_bytes: 21896
program main
    implicit none
    integer a, b, m
    integer, allocatable, dimension(:) :: ai, bi, x, y, c
    integer i, value
    integer a_min, b_min, value_min

    read(*,*) a, b, m

    allocate(ai(a))
    allocate(bi(b))
    allocate(x(m))
    allocate(y(m))
    allocate(c(m))

    read(*,*) ai
    read(*,*) bi
    do i = 1,m
        read(*,*) x(i),y(i),c(i)
    end do

    a_min = ai(1)
    b_min = bi(1)
    
    do i = 1,a
        if(ai(i) <= a_min) then
            a_min = ai(i)
        end if
    end do

    do i = 1,b
        if(bi(i) <= b_min) then
            b_min = bi(i)
        end if
    end do

    value_min = a_min + b_min

    do i = 1,m
        value = ai(x(i)) + bi(y(i)) - c(i)
        if(value <= value_min) then
            value_min = value
        end if
    end do

    write(*,*) value_min


end program

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

struct state{
	ll i,j,col,d;
};

bool operator<(const state& a,const state& b){
	return a.d > b.d;
}

ll dp[101][101][2];
ll di[]={+1,0};
ll dj[]={0,+1};

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

  ll H,W;
  cin>>H>>W;
  vector<string> S(H);
  rep(i,H)cin>>S[i];

  rep(i,H)rep(j,W)rep(c,2)dp[i][j][c]=INF;

  priority_queue<state> que;
  que.push((state){0,0,0,0});
  while(que.size()){
  	state s=que.top(); que.pop();
  	if(dp[s.i][s.j][s.col]!=INF)continue;
  	dp[s.i][s.j][s.col]=s.d;
  	if(s.col==0&&S[s.i][s.j]=='#'){
  		que.push((state){s.i,s.j,1,s.d+1});
  		continue;
  	}
  	if(s.col==1&&S[s.i][s.j]=='.'){
  		que.push((state){s.i,s.j,0,s.d});
  		continue;
  	}
  	rep(dir,2){
  		ll ni=s.i+di[dir],nj=s.j+dj[dir];
  		if(ni<0||ni>=H||nj<0||nj>=W)continue;
  		que.push((state){ni,nj,s.col,s.d});
  	}
  }
  if(S[H-1][W-1]=='#') cout<<dp[H-1][W-1][1]<<endl;
  else cout<<dp[H-1][W-1][0]<<endl;

  return 0;
}


Measured memory_bytes: 512
#include<iostream>
using namespace std;
const int inf=1e8;
int memo[20000+1][256];

void hoge(int N, int M){

   int c[M];
   for(int i=0; i<M; i++) cin>> c[i];
   int x[N];
   for(int i=0; i<N; i++) cin>> x[i];
   for(int i=0; i<N+1; i++){
      for(int j=0; j<256; j++){
         memo[i][j]=inf;
      }
   }

   memo[0][128]=0;
   for(int i=0; i<N; i++){
      for(int j=0; j<256; j++){
         //if(memo[i][j]==inf) continue;
         for(int k=0; k<M; k++){
            int p=max(0, min(255, j+c[k]));
            memo[i+1][p]=min(memo[i][j]+(p-x[i])*(p-x[i]), memo[i+1][p]);
         }
      }
   }
   int mi=1e8;
   for(int j=0; j<256; j++) mi=min(mi, memo[N][j]);
   cout<< mi<< endl;

}


int main(){

   while(1){
      int N, M;
      cin>> N>> M;
      if(!(N||M)) break;
      hoge(N, M);
   }
   return 0;
}

Measured memory_bytes: 23124
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>
using namespace std;
int a,b,c,x,d;

int main()
{
    cin>>a>>b>>c>>x;
    for(int i = 0;i <= a;i ++)
    {
        for(int j = 0;j <= b;j ++)
        {
            for(int k = 0;k <= c;k ++)
                if(i * 500 + j * 100 + k * 50 == x)d ++;
        }
    }
    cout<<d<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int M=100001;
char a[M];
int n,Q[M],tot,Ans[M];
int main(){
	scanf("%s",a+1);
	n=strlen(a+1);
	for(int i=1;i<n;i++)if(a[i]=='R'&&a[i+1]=='L')Q[++tot]=i;
	sort(Q+1,Q+tot+1);
	int l=1;
	for(int i=1;i<=n;i++){
		if(i>Q[l]&&l<=tot)l++;
		if(a[i]=='R'){
			int t=Q[l]-i;
			if(t&1)Ans[Q[l]+1]++;
			else Ans[Q[l]]++;
		}
		if(a[i]=='L'){
			int t=i-Q[l-1];
			if(t&1)Ans[Q[l-1]+1]++;
			else Ans[Q[l-1]]++;
		}
	}
	for(int i=1;i<n;i++)printf("%d ",Ans[i]);
	printf("%d\n",Ans[n]);
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
using ll = long long;
using ld = long double;
#define vpl vector<pair<long long,long long>>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using pll = pair<long long,long long>;
#define cY cout<<"Yes"<<endl
#define cN cout<<"No"<<endl
const long long INF = 1LL << 60;
long long MOD = 1000000007;
const long double pi = 3.1415926535897932;
#define pb push_back
#define mp make_pair
#define mt make_tuple
//(mod m)でのaの逆元を計算する
//a/b(mod m)=a(mod m)*modinv(b,m)
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

//最大最小の入れ替え
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;
}

//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
//コンビネーション
ll nCr(ll n, ll r) {
    ll ans = 1;
    for (ll i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (ll i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}
//素因数分解
map< ll, ll > prime_factor(ll n) {
  map< ll, ll > ret;
  for(ll i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

//切り上げの割り算は(a + b - 1) / bでできる

//ここから
int main(){
    ll N;
    cin>>N;
    map<string,ll> m;
    rep(i,N){
        string S;
        cin>>S;
        m[S]++;
    }
    queue<string> q;
    ll max=0;
    for(auto p:m){
        ll x=p.second;
        if(x>max){
            queue<string> emp;
            swap(emp,q);
            q.push(p.first);
            max=x;
        }else if(x==max){
            q.push(p.first);
        }
    }
    while(!q.empty()){
        cout<<q.front()<<endl;
        q.pop();
    }
}

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

using namespace std;
#define MOD 1e9
typedef long long ll;

int a, b, c, k;

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

  cin>>a>>b>>c>>k;

  if(k <= a) cout<<k;
  else if(k <= a + b) cout<<a;
  else cout<<(2*a + b - k);

  return 0;
}


Measured memory_bytes: 3652
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int h,w,i,j;
        while(true){
        h = s.nextInt();
        w = s.nextInt();
        if(h==0&&w==0)break;
        for(i=1;i<=h;i++){
            for(j=1;j<=w;j++){
                if(i==1||i==h||j==1||j==w)System.out.print("#");
                else System.out.print(".");
            }
            System.out.println();
        }
        System.out.println();
    }
    }
}


Measured memory_bytes: 36308
/*
    Only way to go is UP 
    H1s3nb3rg's Here !!
*/
#define _USE_MATH_DEFINES
#include <bits/stdc++.h> 
#include <cmath>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef long double ld;
typedef pair<int,int> pi;
typedef uint64_t i64;
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef vector<vector<ll>> v2ll;
const int MOD = 1e9+7;
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MAIN int main(){FAST_IO;ll tc;cin>>tc;while(tc--){solver();}ret0;}
#define MAIN1 int main(){FAST_IO;solver();ret0;}
#define rep(i,b,e) for(__typeof(e)i=(b)-((b)>(e));i!=(e)-((b)>(e));i+=1-2*((b)>(e)))
#define repa(i,x)  for(auto i:x)
#define vin(x) for(auto &i:x){cin>>i;}
#define vin2(x) for(auto &i:x){for(auto &j:i){cin>>j;}}
#define vin1(x) for(ll i=1;i<x.size();i++){cin>>x[i];}
#define dbg(x) for(auto i:x){cout<<i<<" ";}cout<<ENDL;
#define dbg2(x) for(auto &i:x){for(auto j:i){cout<<j<<" ";}cout<<endl;}
#define dbgp(x) for(auto i:x){cout<<i.ff<<" "<<i.ss<<endl;}
#define ENDL "\n"
#define VALL(a) a.begin(),a.end()
#define ff first
#define ss second
#define sz(x) (int)x.size()
#define MP(a,b) make_pair(a,b)
#define ff first
#define ss second
#define ret0 return 0;
#define ret return;
#define pb(x) push_back(x)
/*----------------------------*/

void solver(){
    int x,y;
    cin>>x>>y;
    vector<vector<char>> ar(x,vector<char>(y,' '));
    vin2(ar);
    int dp[x][y];
    for(int i=0;i<x;i++)
        for(int j=0;j<y;j++)
            if(ar[i][j]!='#')
                dp[i][j]=0;
            else
                dp[i][j]=-1;
    bool set=0;
    for(int i=0;i<y;i++)
        if(dp[0][i]!=-1 && !set)
            dp[0][i]=1;
        else
            dp[0][i]=-1,set=1;
    set=0;
    for(int i=0;i<x;i++)
        if(dp[i][0]!=-1 && !set)
            dp[i][0]=1;
        else
            dp[i][0]=-1,set=1;
    
    // solve DP
    for(int i=1;i<x;i++){
        for(int j=1;j<y;j++){
            if(dp[i][j]==-1)
                continue;
            dp[i][j]=((max(0,dp[i-1][j])%MOD)+(max(0,dp[i][j-1])%MOD))%MOD;
        }
    }
    cout<<dp[x-1][y-1]<<ENDL;
    ret;
}

MAIN1


Measured memory_bytes: 8216
n, m=map(int, input().split())
gate=[]

for i in range(m):
    L, R=map(int, input().split())
    gate.append((L, R))

L_max=0
R_min=10**6
for i in range(m):
    if gate[i][0]>L_max:
        L_max=gate[i][0]

for i in range(m):
    if gate[i][1]<R_min:
        R_min=gate[i][1]


ans=0

for i in range(1, n+1):
    if L_max<=i<=R_min:
        ans+=1

print(ans)

Measured memory_bytes: 22552
/*
 * src.cpp
 *
 *  Created on: 2016/08/04
 *      Author: joi
 */

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

const int MAX_N=1e7;

bool prime[MAX_N+1];

void sieve(){
	memset(prime,1,sizeof(prime));
	prime[0]=prime[1]=false;
	for (int i=2;i*i<=MAX_N;i++){
		if (prime[i]){
			for (int j=i*2;j<=MAX_N;j+=i){
				prime[j]=false;
			}
		}
	}
}

int n;

int main(){
	sieve();
	do{
		scanf("%d",&n);
		if (n){
			for (int x=n;;x--){
				if (prime[x] && prime[x-2] && prime[x-6] && prime[x-8]){
					printf("%d\n",x);
					break;
				}
			}
		}
	}while(n);
	return 0;
}

Measured memory_bytes: 10960
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
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; }
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;
    vector<int> d(n);
    rep(i,n) cin>>d[i];
    ll res=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            res+=d[i]*d[j];
        }
    }
    cout<<res<<endl;
}

Measured memory_bytes: 256