akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
int a, b;

int main() {
	scanf("%d %d", &a, &b);
	int cnt = 0;
	bool flag = 0;
	int t = b;
	while(t) {
		t /= 10;
		cnt++;
	}
	int s;
	if(cnt == 1) s = a * 10 + b;
	else if(cnt == 2) s = a * 100 + b;
	else if(cnt == 3) s = a * 1000 + b;
	//printf("%d\n", s);
	for(int i = 1; i <= sqrt(s); i++) {
		if(i * i == s) {
			flag = 1;
			break;
		}
	}
	if(flag) puts("Yes");
	else puts("No");
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS

/* include ***********************/
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

/* define *************************/
//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define FOR(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)
#define RFOR(i,s,n) for(int i=(int)(n)-1,i##_len=(int)(s);i>=i##_len;i--)

//printf
#define PRINTD(d) printf("%d\n",(d))
#define PRINTL(d) printf("%lld\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9
#define MOD 1000000007

typedef long long ll;
typedef unsigned long long ull;

int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};
//今回の変数

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int  a, int  b) {
	return (a) > (b) ? (a) : (b);
}
ll Minl(ll a, ll b) {
	return (a)<(b) ? (a) : (b);
}
ll Maxl(ll a, ll b) {
	return (a)>(b) ? (a) : (b);
}

int main() {
	int a, p;
	scanf("%d%d", &a, &p);

	p += a * 3;
	PRINTD(p / 2);

}


Measured memory_bytes: 128
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations
import math

def main():
    N = int(input())
    result = math.floor(N / 500) * 1000
    result += math.floor((N % 500)/5)*5
    print(result)


if __name__ == "__main__":
    main()

Measured memory_bytes: 5048
#[allow(unused_imports)]
use proconio::{input, marker::*};

#[allow(unused_imports)]
use std::io::Write;
#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

const INF: usize = 1_000_000_000_000_000;

fn lower_bound<F>(l: isize, r: isize, criterion: F) -> isize
where
    F: Fn(isize) -> bool,
{
    let mut l = l;
    let mut r = r;
    while r - l > 1 {
        let mid = l + (r - l) / 2;
        if criterion(mid) {
            r = mid;
        } else {
            l = mid;
        }
    }
    r
}

fn dfs(
    node: usize,
    parent: usize,
    nodes: &Vec<Vec<usize>>,
    dp: &mut Vec<usize>,
    res: &mut Vec<usize>,
    a: &Vec<usize>,
    mut val: usize,
) {
    let crit = |i: isize| {
        let i = i as usize;
        a[node - 1] <= dp[i]
    };
    let i = lower_bound(-1, a.len() as isize, crit) as usize;
    if dp[i] == INF {
        val += 1;
    }
    let before = dp[i];
    dp[i] = a[node - 1];
    for &next in &nodes[node] {
        if next == parent {
            continue;
        }
        dfs(next, node, nodes, dp, res, a, val);
    }
    dp[i] = before;
    res[node - 1] = val;
}

fn main() {
    input! {
        n: usize,
        a: [usize; n],
        uv: [(usize,usize); n-1],
    }
    debug!(n, a, uv);

    let mut nodes = vec![Vec::new(); n + 1];
    for (u, v) in uv {
        nodes[u].push(v);
        nodes[v].push(u);
    }

    let mut res = vec![0; n];
    dfs(1, 0, &nodes, &mut vec![INF; n], &mut res, &a, 0);
    for i in 0..n {
        println!("{}", res[i]);
    }
}


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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}


constexpr int N_MAX = 200000;

ll solve(int L, int N, int *X, int *Y) {
    ll result = 0;
    
    ll accl[N_MAX + 1];
    ll accr[N_MAX + 1];
    accl[0] = 0;
    accr[0] = 0;
    REP(i, N) {
        accl[i + 1] = accl[i] + X[i];
        accr[i + 1] = accr[i] + Y[i];
    }
    PRINTA(X, 0, N);
    PRINTA(Y, 0, N);
    PRINTA(accl, 0, N + 1);
    PRINTA(accr, 0, N + 1);

    REP(i, N) {
        PRINT(i);
        if ((N - i - 1) % 2 == 0) {
            PRINT("left end");
            int left = i + (N - i - 1) / 2;
            int right = (N - i - 1) / 2 - 1;
            PRINT(left);
            PRINT(right);
            ll left_sum = X[left] + 2 * (accl[left] - accl[i]);
            ll right_sum; 
            if (right  + 1 >= 0) {
                right_sum = 2 * accr[right + 1];
            } else {
                assert(0);
            }
            PRINT(left_sum);
            PRINT(right_sum);
            ll dist = left_sum + right_sum;
            amax(result, left_sum + right_sum);
        } else {
            PRINT("right end");
            int left = i + (N - i - 2) / 2;
            int right = (N - i) / 2 - 1;
            PRINT(left);
            PRINT(right);
            ll left_sum = 2 * (accl[left + 1] - accl[i]);
            ll right_sum;
            if (right >= 0) {
                right_sum = Y[right] + 2 * accr[right];
            } else {
                assert(0);
            }
            PRINT(left_sum);
            PRINT(right_sum);
            ll dist = left_sum + right_sum;
            amax(result, left_sum + right_sum);
        }
    }
    return result;
}

int main(void)
{
    int L, N;
    int X[N_MAX];
    int Y[N_MAX];
    cin >> L >> N;
    REP(i, N) cin >> X[i];
    REP(i, N) Y[i] = L - X[N - 1 - i];

    cout << max(solve(L, N, X, Y), solve(L, N, Y, X)) << endl;


    return 0;
}



Measured memory_bytes: 4992
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	p := scanInt()
	MOD = p
	combInit(p)
	a := scanInts(p)
	b := make([]int, p)

	for i := 0; i < p; i++ {
		if a[i] == 0 {
			continue
		}
		b[0]++
		b[0] %= MOD
		c := 1
		for j := 0; j < p; j++ {
			b[p-1-j] -= comb(p-1, j) * c % MOD
			b[p-1-j] %= MOD
			c *= -i
			c %= MOD
		}
	}

	for i := 0; i < p; i++ {
		fmt.Fprint(wr, (MOD+b[i])%MOD, " ")
	}
	fmt.Fprintln(wr)

}

// MOD constant
var MOD = 1000000007

var fac, ifac, inv []int

func combInit(n int) {
	fac = make([]int, n+1)
	ifac = make([]int, n+1)
	inv = make([]int, n+1)

	fac[0], fac[1] = 1, 1
	ifac[0], ifac[1] = 1, 1
	inv[1] = 1

	for i := 1; i < n; i++ {
		fac[i+1] = fac[i] * (i + 1) % MOD
		inv[i+1] = MOD - inv[MOD%(i+1)]*(MOD/(i+1))%MOD
		ifac[i+1] = ifac[i] * inv[i+1] % MOD
	}
}

func comb(a, b int) int { return (fac[a] * ifac[b] % MOD) * ifac[a-b] % MOD }
func perm(a, b int) int { return fac[a] * ifac[a-b] % MOD }

func mpow(a, n int) int {
	res := 1
	for n > 0 {
		if n&1 == 1 {
			res = res * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return res
}


Measured memory_bytes: 896
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//do {
//    print(v);
//  } while (std::next_permutation(v.begin(), v.end()));

const int limit = 100010;
using edge = struct { int to; int cost; };
vector<edge> tree[limit];
int depth[limit];

void dfs(int v, int p, int d) {
	depth[v] = d;
	for (auto &e : tree[v]) {
		if (e.to == p)continue;
		dfs(e.to, v, d + e.cost);
	}
}



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

	int N;
	cin >> N;

	REP(i, N - 1) {
		int A, B, C;
		cin >> A >> B >> C;
		A--;
		B--;
		tree[A].push_back({ B,C });
		tree[B].push_back({ A,C });
	}

	int Q, K;
	cin >> Q >> K;
	K--;
	dfs(K, -1, 0);
	REP(i, Q) {
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		cout << depth[x] + depth[y] << endl;
	}

	return 0;
}



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

using namespace std;

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

  char str[600000];
  int left = 250000;
  for (int i = 0; i < S.size(); i++) {
    str[left + i] = S[i];
  }
  int right = left + S.size();
  left--;

  bool reverse = false;
  for (int i = 0; i < Q; i++) {
    int T;
    cin >> T;
    if (T == 1) {
      reverse = !reverse;
    } else {
      int F;
      cin >> F;
      char c;
      cin >> c;
      if (!reverse) {
        if (F == 1) {
          //   S = c + S;
          str[left] = c;
          left--;
        } else {
          //   S = S + c;
          str[right] = c;
          right++;
        }
      } else {
        if (F == 1) {
          //   S = S + c;
          str[right] = c;
          right++;
        } else {
          //   S = c + S;
          str[left] = c;
          left--;
        }
      }
    }
  }

  if (!reverse) {
    // for (int i = 0; i < S.size(); i++) {
    //   cout << S[i];
    // }
    for (int i = left + 1; i < right; i++) {
      cout << str[i];
    }
  } else {
    // for (int i = S.size() - 1; 0 <= i; i--) {
    //   cout << S[i];
    // }
    for (int i = right - 1; left < i; i--) {
      cout << str[i];
    }
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 1088
//Template Matching

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, string>;
using garph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int n,m;cin>>n>>m;
    vecrep(n,a,string);
    vecrep(m,b,string);
    rep(i,0,n-m+1){
        rep(j,0,n-m+1){
            vector<string>t(m);
            rep(k,0,m){
                t[k]=a[i+k].substr(j,m);
            }
            if(t==b){
                cout<<"Yes"<<nnn;
                return 0;
            }
        }
    }
    cout<<"No"<<nnn;
    return 0;
}

Measured memory_bytes: 3580
n,k,q = (int(i) for i in input().split())
a0 = [int(input()) for i in range(q)]
a = sorted(a0)
l = 0
for i in range(1,n+1):
    s = 0
    for j in range(l,q):
        if a[j] > i:
            break
        elif a[j] == i:
            s += 1
            l += 1
        else:
            l += 1
    if k+s-q > 0:
        print("Yes")
    else:
        print("No")

    

Measured memory_bytes: 8628
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
 	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N,p[MAXN],deg[MAXN],val[MAXN];
int id[MAXN][2],tot,cir;
vector<int> t[MAXN],to[MAXN * 2];
vector<int> son[MAXN];
queue<int> q;
int dfn[MAXN * 2],low[MAXN * 2],sta[MAXN * 2],instack[MAXN * 2],idx,top;
bool flag = 0;
void Tarjan(int u) {
    dfn[u] = low[u] = ++idx;
    sta[++top] = u;instack[u] = 1;
    for(auto v : to[u]) {
	if(!dfn[v]) {Tarjan(v);low[u] = min(low[v],low[u]);}
	else if(instack[u] == 1){
	    low[u] = min(low[u],dfn[v]);
	}
    }
    if(low[u] == dfn[u]) {
	int k = 0;
	while(1) {
	    int x = sta[top--];
	    ++k;
	    instack[x] = 2;
	    if(x == u) break;
	}
	if(k == cir) flag = 1;
    }
}
void Solve() {
    read(N);
    for(int i = 1 ; i <= N ; ++i) {
	read(p[i]);
	deg[p[i]]++;
    }
    for(int i = 1 ; i <= N ; ++i) {
	if(!deg[i]) q.push(i);
    }
    while(!q.empty()) {
	int u = q.front();q.pop();
	sort(son[u].begin(),son[u].end());
	son[u].erase(unique(son[u].begin(),son[u].end()),son[u].end());
	int m = 0;
	while(m < son[u].size()) {
	    if(son[u][m] != m) break;
	    ++m;
	}
	son[p[u]].pb(m);
	if(!--deg[p[u]]) {
	    q.push(p[u]);
	}
    }
    for(int i = 1 ; i <= N ; ++i) {
	if(deg[i]) {
	    sort(son[i].begin(),son[i].end());
	    son[i].erase(unique(son[i].begin(),son[i].end()),son[i].end());
	    int m = 0,pos = 0;
	    
	    while(1) {
		if(pos >= son[i].size() || son[i][pos] != m) {
		    t[i].pb(m);
		    if(t[i].size() < 2) {++m;}
		    else break;
		}
		else {pos++;++m;}
	    }
	    id[i][0] = ++tot;id[i][1] = ++tot;
	    ++cir;
	}
    }
    for(int i = 1 ; i <= N ; ++i) {
	if(deg[i]) {
	    int f = p[i];
	    to[id[f][0]].pb(id[i][t[f][0] == t[i][0]]);
	    to[id[f][1]].pb(id[i][t[f][1] == t[i][0]]);
	}
    }
    for(int i = 1 ; i <= tot ; ++i) {
	if(!dfn[i]) Tarjan(i);
    }
    if(flag) puts("POSSIBLE");
    else puts("IMPOSSIBLE");
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


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

#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

using namespace std;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	//#endif
	ll a,rb;
	string b;
	cin>>a>>b;
	rb=((b[0]-'0')*100)+((b[2]-'0')*10)+(b[3]-'0');
	cout<<a*rb/100<<endl;
	return 0;
}

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

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

	for (int i = 0; i < 50000; i++) {
		if ((int)(i * 1.08) == n) {
			cout << i << endl;
			return 0;
		}
	}

	cout << ":(" << endl;

 	return 0;
 }

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { rep(i,v.size())os<<v[i]<<(i==v.size()-1?"\n":" "); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
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 inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n,m;
    cin >> n >> m;
    vvi dist(n,vi(n,inf));
    rep(i,n) dist[i][i] = 0;
    vector<tuple<int,int,int>> v;
    rep(_,m) {
        int a,b,c;
        cin >> a >> b >> c;
        a--; b--;
        dist[a][b] = c;
        dist[b][a] = c;
        v.eb(a,b,c);
    }
    rep(k,n) rep(i,n) rep(j,n) {
        chmin(dist[i][j],dist[i][k]+dist[k][j]);
    }
    int ans = 0;
    for(auto t : v) {
        int a,b,c;
        tie(a,b,c) = t;
        bool ok = true;
        rep(i,n) rep(j,n) {
            if(dist[i][j] == dist[i][a]+c+dist[b][j]) ok = false;
            if(dist[i][j] == dist[i][b]+c+dist[a][j]) ok = false;
        }
        if(ok) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
import java.util.Scanner;

class Main{
	public static void main( String[] args ) {
		try(Scanner sc = new Scanner(System.in)){
			int n = sc.nextInt();
			while(n != 0) {
				double[] data = new double[n];
				double sum = 0;
				double vars = 0;
				for(int i = 0;i <n;i++) {
					int num = sc.nextInt();
					data[i] =  num;
					sum += data[i];
				}
				double ave = ( (double)sum )/data.length;
				for (int i=0; i<data.length; i++) {
					vars += ((data[i] - ave)*(data[i] - ave));
				}
				double std = Math.sqrt(vars/data.length);
				System.out.println(std);
				n = sc.nextInt();
			}
		}
	}
}


Measured memory_bytes: 31004
n = int(input())
C = list(map(int, input().split()))

mod = 10**9 + 7

if n == 1:
    ans = 2 * C[0]
    ans %= mod
    print(ans)
    exit()


ans = 0
pattern = 2 ** (n-1) % mod
d = 2 ** (n-2) % mod
C.sort(reverse=True)
for c in C:
    ans += (c * pattern) % mod
    pattern += d
    pattern %= mod
    ans %= mod

print(ans*(2**n) % mod)

Measured memory_bytes: 25508
#include<bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
ll n,i,a[1010],has,j;
int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n;
	for(i=1;i<=n;i++)
		cin>>a[i];
	for(i=1;i<=n;i++)
		for(j=i+1;j<=n;j++)
			has+=(a[i]*a[j]);
	cout<<has<<"\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define eb emplace_back
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 233;
bool vis[maxn];
int sum[maxn];
char s[maxn];
int main()
{
	int m,n;cin>>m>>n;
	int cnt = 0,sa =0 ;
	for(int i=1;i<=n;i++){
		int p;
		scanf("%d %s",&p,s);
		if(s[0]=='A'){
			vis[p] = 1;
		}
		else{
			if(!vis[p])sum[p]++;
		}
	}
	for(int i=1;i<=m;i++)
		if(vis[i]){
			cnt++;
			sa += sum[i];
		}
	cout << cnt <<" " << sa << endl;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x ,n) for(int i = x; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    ll ans=0;
    
    rep2(i,1,n+1)if(i%3!=0 and i%5!=0)ans+=i;
    
    cout << ans;
}

Measured memory_bytes: 3576
#include<stdio.h>
long long int res[55][5003];
int h[10000007],l;
void swap_h(int a, int b)
{
	long long int f = h[a];
	h[a] = h[b];
	h[b] = f;
	return;
}
int comp_h(int a, int b)
{
	if (res[h[a] / 100000][h[a] % 100000] > res[h[b] / 100000][h[b] % 100000])
		return 1;
	return -1;
}
void f1(int n)
{
	h[l] = n;
	int p = l;
	l++;
	while (p > 0)
	{
		if (comp_h((p - 1) / 2, p) > 0)
			swap_h((p - 1) / 2, p);
		p = (p - 1) / 2;
	}
	return;
}
long long int f2()
{
	l--;
	swap_h(0, l);
	int p = 0;
	for (;;)
	{
		if (2 * p + 2 < l)
		{
			if (comp_h(2 * p + 1, 2 * p + 2) > 0)
			{
				if (comp_h(p, 2 * p + 2) > 0)
					swap_h(p, 2 * p + 2);
				p = 2 * p + 2;
			}
			else
			{
				if (comp_h(p, 2 * p + 1) > 0)
					swap_h(p, 2 * p + 1);
				p = 2 * p + 1;
			}
		}
		else if (2 * p + 1 < l)
		{
			if (comp_h(p, 2 * p + 1) > 0)
				swap_h(p, 2 * p + 1);
			p = 2 * p + 1;
		}
		else
			break;
	}
	return h[l];
}
int main()
{
	int n, m, s;
	scanf("%d %d %d", &n, &m, &s);
	int u[202], v[202];
	long long int a[202], b[202];
	int i, j;
	for (i = 0; i < m; i++)
	{
		i *= 2;
		scanf("%d %d %lld %lld", &u[i], &v[i], &a[i], &b[i]);
		u[i]--;
		v[i]--;
		v[i + 1] = u[i];
		u[i + 1] = v[i];
		a[i + 1] = a[i];
		b[i + 1] = b[i];
		i /= 2;
	}
	int hoge;
	long long int hogehoge;
	for (i = 0; i < 2 * m - 1; i++)
	{
		if (u[i] > u[i + 1])
		{
			hoge = u[i];
			u[i] = u[i + 1];
			u[i + 1] = hoge;
			hoge = v[i];
			v[i] = v[i + 1];
			v[i + 1] = hoge;
			hogehoge = a[i];
			a[i] = a[i + 1];
			a[i + 1] = hogehoge;
			hogehoge = b[i];
			b[i] = b[i + 1];
			b[i + 1] = hogehoge;
			if (i > 0)
				i -= 2;
		}
	}
	long long int c[55], d[55];
	for (i = 0; i < n; i++)
		scanf("%lld %lld", &c[i], &d[i]);
	for (i = 0; i < n; i++)
		for (j = 0; j < 5003; j++)
			res[i][j] = 2000000000000000018;
	l = 0;
	if (s < 5003)
	{
		res[0][s] = 0;
		f1(s);
	}
	else
	{
		res[0][5002] = 0;
		f1(5002);
	}
	int min, mid, max;
	while (l > 0)
	{
		i = f2();
		j = i % 100000;
		i /= 100000;
		if (j + c[i] < 5002)
		{
			if (res[i][j + c[i]] > res[i][j] + d[i])
			{
				res[i][j + c[i]] = res[i][j] + d[i];
				f1(100000 * i + j + c[i]);
			}
		}
		else if (res[i][5002] > res[i][j] + d[i])
		{
			res[i][5002] = res[i][j] + d[i];
			f1(100000 * i + 5002);
		}
		min = -1;
		max = 2 * m;
		while (max - min > 1)
		{
			mid = (max + min) / 2;
			if (u[mid] < i)
				min = mid;
			else
				max = mid;
		}
		if (max < 2 * m)
		{
			while (u[max] == i)
			{
				if (a[max] <= j)
				{
					if (res[v[max]][j - a[max]] > res[i][j] + b[max])
					{
						res[v[max]][j - a[max]] = res[i][j] + b[max];
						f1(100000 * v[max] + j - a[max]);
					}
				}
				max++;
				if (max == 2 * m)
					break;
			}
		}
	}
	long long int ans[55];
	for (i = 0; i < n; i++)
	{
		ans[i] = res[i][0];
		for (j = 0; j < 5003; j++)
			if (ans[i] > res[i][j])
				ans[i] = res[i][j];
	}
	for (i = 1; i < n; i++)
		printf("%lld\n", ans[i]);
	return 0;
}

Measured memory_bytes: 4136
#include<bits/stdc++.h>
#include <cstdio>
using namespace std;
#define ll  long long
#define PB push_back
#define ld long double
#define ff first
#define ss second
# define st(v) (v).begin(),(v).end()
#define   pr pair<int,int>
using namespace std::chrono;
const int N = 1e5+4 , M=N,inf=(int)1e9;
const ll mod=1e9+7;
int fastAbs(int n) { return (n ^ (n >> 31)) - (n >> 31); }
ll multiply(ll a, ll b){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
int ans ;
map< pair<int,int> , int > mp;
const int dx[4] = {1,0,0,-1};
const int dy[4] = {0,-1,1,0};
void solve(){
    int n ;
    cin >> n ;
    vector < int > gem(n) , cost(n);
    for( int i = 0 ; i < n ; i++)   cin >> gem[i] ;
    for( int i = 0 ; i < n ; i++) cin >> cost[i] ;
    int answer = 0 ;
    for( int i = 0 ; i < n ; i++){
        if(gem[i]>cost[i]){
            answer+=gem[i]-cost[i];
        }
    }
    cout << answer ;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int q=1;
    //cin >> q;
    while(q--)
        solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = 105;
P r[MAX_N],b[MAX_N];
bool used[MAX_N];

int main()
{
	int N;
	cin >> N;
	int x,y;
	for (int i = 0; i < N; ++i)
	{
		cin >> x >> y;
		r[i] = P(x,y);
	}
	for (int i = 0; i < N; ++i)
	{
		cin >> x >> y;
		b[i] = P(x,y);
	}

	sort(b,b+N);
	int ans = 0;

	for (int i = 0; i < N; ++i)
	{
		used[i] = false;
	}

	rep(i,N)
	{
		bool ok = false;
		int idx;
		rep(j,N)
		{
			if (!used[j] && r[j].first < b[i].first && r[j].second < b[i].second)
			{
				if (ok && r[j].second > r[idx].second)
				{
					idx = j;
				}
				else if (!ok)
				{
					idx = j;
				}
				ok = true;
			}
		}

		if (ok)
		{
			ans++;
			used[idx] = true;	
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
typedef long long i64;
typedef char str255[256];

#define BIG_PRIME 1000000007
#define remainder(x) ((x) % BIG_PRIME)

int N;
int *a;

void Solve()
{
  int searching_number = 1;
  bool isFound = false;
  int i;
  for (i = 0; i < N; ++i){
    if (a[i] == searching_number){
      isFound = true;
      ++searching_number;
    }
  }
//cout << "i = " << i << ", searching_number = " << searching_number << endl;
  if (isFound) cout << N - (searching_number - 1) << endl;
  else puts("-1");
}

void Init()
{
  cin >> N;
  a = new int[N + 10];
  for (int i = 0; i < N; ++i)
    cin >> a[i];
}

void Clean()
{
  delete[] a;
}

int main(){ Init(); Solve(); Clean(); return 0; }


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

using namespace std;

using ll= long long;

#define sz(x) (int)x.size()
#define all(x) (x).begin(),(x).end()
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define _set(x) __builtin_popcount(x)
#define dpv(...) cerr<< "["#__VA_ARGS__ " : ";for(int i: (__VA_ARGS__)){cerr<<i<<" ";}cerr<<"]\n"


void solve(){
	int n;
	cin>>n;
	vector<ll> a,b;
	for(int i=0;i<n;i++){
		ll x,y;
		cin>>x>>y;
		a.push_back(x+y);
		b.push_back(x-y);
	}
	ll mx =0;
	sort(all(a));
	sort(all(b));
	mx = max(mx, a.back()-a[0]);
	mx = max(mx, b.back()- b[0]);
	cout<<mx<<"\n";
}

int32_t main(){
	IOS
	// freopen("input.txt","r",stdin);
	int _;
	// cin>>_;
	_=1;
    // int tt=1;
	while(_--){
		// cout<<"Case #"<<tt++<<": ";
		solve();
    }
	return 0;
}

/*
   check for overflows int long long
   correct size of array
*/

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

int MOD=1000000007;
struct edge {
    int to, cost;
};

int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}

int gyaku(int n){
    return modpow(n,MOD-2);
}

auto factor(int n){
  map<int,int>res;
  for(int i=2;i*i<=n;i++){
      for(; n%i==0;n/=i) res[i]++;
  }
  if(n>1)res[n]++;
  return res;
}
////////////////////////////////////////////////////////////
signed main() {
  int h,w;
  cin>>h>>w;
  int c[10][10];
  rep(i,10)rep(j,10){cin>>c[i][j];}
  vector<int>d(10);
  rep(i,10)d[i]=c[i][1];
  rep(i,10){
    if(i!=1){
      vector<int>v(0);
      rep(j,10){
        if(j!=i)v.push_back(j);
      }

      do{
        int t=0;
        for(int k=0;k<9;k++){
          if(k==0) {
            t+=c[i][v[k]];
            if(v[0]==1)continue;
          }
          if(k!=0){
            t+=c[v[k-1]][v[k]];
            if(v[k]==1){
              d[i]=min(d[i],t);
            }
          }
          if(t>d[i])break;
        }
      }while(next_permutation(v.begin(),v.end()));
    }
  }
  int ans=0;
    rep(i,h){
      rep(j,w){
        int a;
        cin>>a;
        if(a!=1&&a!=-1){
          ans+=d[a];
        }
      }
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 3552
n = int(input())
s = [input() for _ in range(n)]
s = [t[0] for t in s if t[0] in 'MARCH']
d = {}
for t in s:
  if t in d:
    d[t] += 1
  else:
    d[t] = 1
l = list(d.keys())
result = 0
for i in range(len(l) - 2):
  for j in range(i + 1, len(l) - 1):
    for k in range(j + 1, len(l)):
      result += d[l[i]] * d[l[j]] * d[l[k]]
print(result)


Measured memory_bytes: 10528
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n; cin >> n;
	vi c(n), w(n), s(n + 1);
	rep(i, n) cin >> c[i] >> w[i], s[i + 1] = s[i] + w[i];
	
	vector<vector<bool>> can(n, vector<bool>(n));
	for(int len = 1; len <= n; len++) rep(l, n - len + 1){
		int r = l + len - 1;
		if(len == 1){
			can[l][r] = 1;
			continue;
		}
		if(can[l][r - 1] && c[r] >= s[r] - s[l]) can[l][r] = 1;
		if(can[l + 1][r] && c[l] >= s[r + 1] - s[l + 1]) can[l][r] = 1;
	}
	//dbg(can);
	vi dp(n + 1, inf);
	dp[0] = 0;
	rep(i, n) rep(j, i+1) if(dp[j] < inf && can[j][i]) dp[i+1] = min(dp[i+1], dp[j] + 1);
	cout << dp[n] << endl;
	
	return 0;
}


Measured memory_bytes: 3284
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int x = Integer.parseInt(sc.next());
        int primeNum;
        while (true) {
            if (isPrimeNumber(x)) {
                primeNum = x;
                break;
            }
            x++;
        }
        out.println(primeNum);
        
        out.flush();
    }
  
    static boolean isPrimeNumber(int target) {
        int sqrt = (int)Math.sqrt(target);
        boolean result = true;
        for (int i = 2; i <= sqrt; i++) {
            if (target % i == 0) {
                result = false;
                break;
            }
        }
        return result;
    }
  
}

Measured memory_bytes: 23636
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#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 equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];
  int m;
  cin >> m;
  vector<string> t(m);
  rep(i, m) cin >> t[i];

  map<string, int> a;
  rep(i, n) a[s[i]]++;
  rep(i, m) a[t[i]]--;

  int ans = 0;
  rep(i, n) {
    ans = max(ans, a[s[i]]);
  }
  cout << ans << endl;


  
  return 0;
}

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

using namespace std;

int main() {
	string s;
	int count = 0;//文字数カウント用
	int index_min_A = 0;//Aの最小インデックス
	int index_max_Z = 0;//Zの最大インデックス

	//入力
	cin >> s;

	//Aではじまり、Zでおわる最大の文字列を取得
	for (int i = 0; i < s.length(); i++) {
		if (s[i] == 'A') {
			index_min_A = i;
			break;
		}
	}
	for (int i = s.length(); i >= 0; i--) {
		if (s[i] == 'Z') {
			index_max_Z = i;
			break;
		}
	}
	
  	//出力
	cout << index_max_Z - index_min_A + 1 << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>

using namespace std;

long long int modinv(long long int a, long long int m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

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

	vector<long long int> A(N);
	for (long long int i = 0; i < N; ++i)
	{
		cin >> A[i];
	}

	long long int ans = 0;
	long long int tmp1 = 0;
	long long int tmp2 = 0;

	for (long long int i = 0; i < N; ++i)
	{
		tmp1 += A[i];
		tmp2 += (A[i] * A[i]) % 1000000007;
		tmp1 %= 1000000007;
		tmp2 %= 1000000007;
	}
	tmp1 *= tmp1;
	tmp1 %= 1000000007;

	long long int tmp3 = 0;
	if (tmp1 - tmp2 < 0) {
		tmp3 = tmp1 - tmp2 + 1000000007;
	}
	else tmp3 = tmp1 - tmp2;

	ans = tmp3 * modinv(2, 1000000007);
	ans %= 1000000007;

	cout << ans;

	return 0;
}

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

#define INF 1e18
#define REP(i, n) for (int i=0; i<n; i++)
#define print(x) cout << x << endl
#define debug(x) cout << #x << " = "<< x << endl

const double PI=3.141592653589793238462643383279502884197169399375105820974944;

typedef long long ll;

using namespace std;

void solve() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (abs(a-b) <= d && abs(c-b) <= d || abs(a-c) <= d) {
        print("Yes");
    } else {
        print("No");
    }
}

signed main() {
    solve();
}


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


int main()
{
	int A, B, C;
	cin >> A >> B >> C;
	if ((A>C && C>B)||(A<C && C<B)){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
	
	return 0;
}

Measured memory_bytes: 256
#pragma region _head

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>

#pragma region _define

#define int LL
#define f(i,a,b) for(LL i=a;i<b;i++)
#define rep(i,n) for(LL i=0;i<n;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n,option) f(i,0,n)cout<<v[i]<<option;
#define all(a) a.begin(),a.end()
#define size(s) ((int)s.size())
#define check() cout<<"! ! !"
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl
#define INT_INF 1<<29
#define LL_INF 1LL<<60
#define MOD 10000007

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vc = vector<char>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using qi = queue<int>;
using qc = queue<char>;
using qs = queue<st>;
using si = stack<LL>;
using sc = stack<char>;
using ss = stack<st>;
using pi = pair<LL, LL>;
using mll = map<LL, LL>;
using vpi = vector<pi>;

#pragma endregion


//素数判定
bool is_prime(int n) {
	for (int i = 2; i*i <= n; i++) {
		if (n%i == 0) {
			return false;
		}
	}
	return true;
}

void y_n(bool p) {
	if (p)_y();
	else _n();
}

void Y_N(bool p) {
	if (p) _Y();
	else _N();
}

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b)*b);
}

//階乗計算
LL factorial(LL n) {
	LL a = 1, ret = 1;
	while (a < n) {
		a++;
		ret *= a;
		//ret %= 1000000007;
	}
	return ret;
}

#pragma endregion


/************************************************************************/
signed main(void) {
	cin.tie(0); ios::sync_with_stdio(false);

	while (1) {
		int n, m, p;
		cin >> n >> m >> p;
		if (n == 0 && m == 0 && p == 0)break;
		vi x(n);
		f_vI(x, n);
		int sum = 0;
		rep(i, n) {
			sum += x[i] * 100;
		}
		sum *= (100 - p);
		sum /= 100;
		if (x[m - 1] == 0) {
			sum = 0;
		}
		else {
			sum /= x[m - 1];
		}
		cout << sum << endl;
	}
	return 0;
}


Measured memory_bytes: 3204
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
from collections import deque


def bfs(xg,yg):
    queue = deque([(xs,ys,0)])
    while queue:
        x,y,dep = queue.popleft()
        l = []
        for xx,yy in [(1,0),(0,1),(-1,0),(0,-1)]:
            for i in range(1,k+1):
                nx,ny = x+xx*i,y+yy*i
                if cord[ny][nx] == '.':
                    l.append((nx,ny))
                elif cord[ny][nx] == dep+1:
                    continue
                else:
                    break
        for nx, ny in l:
            if cord[ny][nx] == '.':
                cord[ny][nx] = dep+1
                if (nx,ny) == (xg,yg):
                    return dep+1
                else:
                    queue.append((nx,ny,dep+1))
    return -1

h,w,k = iim()
ys,xs,yg,xg = iim()

cord = [['@']*(w+2)]
for i in range(h):
    cord.append(['@']+list(input())+['@'])
cord.append(['@']*(w+2))
cord[ys][xs] = '#'
#for i in cord:
#    print(*i)
#print(len(cord),len(cord[0]))

print(bfs(xg,yg))


Measured memory_bytes: 51208
#include <bits/stdc++.h>
#define INF 114514810
using namespace std;

int main(void){
    int w, a, b;
    cin >> w >> a >> b;
    if (b + w < a) cout << a - b - w << endl;
    if (b + w >= a && b <= a + w) cout << 0 << endl;
    if (b > a + w) cout << b - a - w << endl;
}


Measured memory_bytes: 256
#include <iostream> 
#include <vector>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <queue>
#include <stack>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <cctype>
#include <climits>

using namespace std;

using ll = long long int;
using ii = pair<int, int>;
using vi = vector<ll>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;



#define mp(a,b) make_pair(a,b)

const int MOD = 1000 * 1000 * 1000 + 7;

ll dp(int x, int y, int it, vvi const& mat, vvvi & marcaje) {
	if (y >= mat.size()) return 0;
	else if (x >= mat[0].size()) return 0;
	else if (marcaje[y][x][it] != -1) return marcaje[y][x][it];
	else {
		//No hay item, vamos para la derecha o para abajo
		if (mat[y][x] == 0) {
			ll s1 = dp(x + 1, y, it, mat, marcaje);
			ll s2 = dp(x, y + 1, 0, mat, marcaje);
			marcaje[y][x][it] = max(s1, s2);
			return marcaje[y][x][it];
		}
		else {
			//Podemos o coger el ítem o no cogerlo

			//Cogemos el item
			//Vamos hacia la derecha si podemos
			ll s1 = 0;
			if(it < 2) s1 = dp(x + 1, y, it + 1, mat, marcaje) + mat[y][x];

			//Vamos hacia abajo
			ll s2 = dp(x, y + 1, 0, mat, marcaje) + mat[y][x];

			//No lo cogemos
			ll s3 = dp(x + 1, y, it, mat, marcaje);
			ll s4 = dp(x, y + 1, 0, mat, marcaje);

			marcaje[y][x][it] = max({ s1, s2,s3, s4 });
			return marcaje[y][x][it];
		}
	}
}

int main() {
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	int r, c, k;
	cin >> r >> c >> k;

	vvi mat(r, vi(c));

	for (int i = 0; i < k; ++i) {
		int fil, col, val;
		cin >> fil >> col >> val;
		mat[fil - 1][col - 1] = val;
	}

	vvvi marcaje(r, vvi(c, vi(4, -1)));
	cout << dp(0, 0, 0, mat, marcaje) << '\n';
	return 0;
}

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

int main(){
	int N, A;
	cin >> N >> A;
	int n = 0;
	while(true){
		if(N >= 500){
			N -= 500;
		}else if(A >= N){
			cout << "Yes" << endl;
			break;
		}else{
			cout << "No" << endl;
			break;
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
        a[i]--;
    }
    int ans = 0;
    rep(i,n){
        if (i == a[a[i]]) ans++; 
    }
    cout << ans/2 << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;

int main() {
  string S;
  int flag = 0, c_flag = 0;
  int length;

  cin >> S;

  if(S[0] != 'A') flag = 1;
  length = S.length();

  for(int i=1; i<length; ++i) {
    if(flag) break;
    if(S[i] != 'C') {
      if(!('a' <= S[i] && S[i] <= 'z'))
        flag = 1;
    }
    else {
      if(c_flag) flag = 1;
      if(2<=i && i<=length-2) c_flag = 1;
      else flag = 1;
    }
  }

  if(!(flag) && c_flag) cout << "AC" << "\n";
  else cout << "WA" << "\n";

  return 0;
}

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

using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,n,m) for(ll i=n; i>(ll)m; i--)
#define cinv(v,n,m) FOR(i,n,m) cin>>v.at(i)
#define coutv(v,n,m) FOR(i,n,m) cout<<v.at(i) <<" "
#define cout(n) cout<<fixed<<setprecision(n)
int main(){
  int N;
  cin>>N;
  vector<ll> v(N+2,0);
  cinv(v,1,N+1);
  ll sum=0;
  FOR(i,1,N+2){
    sum += abs(v[i]-v[i-1]);
  }
  int a,b;
  FOR(i,1,N+1){
    if((v[i-1]<=v[i]&&v[i]<=v[i+1])||(v[i-1]>=v[i]&&v[i]>=v[i+1])) cout<<sum<<endl;
    else {
      a=abs(v[i-1]-v[i]);
      b=abs(v[i+1]-v[i]);
      if(a<b) cout<<sum-2*a<<endl;
      else cout<<sum-2*b<<endl;
    }
  }
}


Measured memory_bytes: 2048
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int H = sc.nextInt();
	int W = sc.nextInt();
	int N = sc.nextInt();
	int count=0;
        while(N > 0){
	    if(H < W){
		N -= W;
	    }else{
		N -= H;
	    }
	    count++;
	}
	System.out.print(count);
    }
}


Measured memory_bytes: 21844
from operator import itemgetter
N = int(input())
ab = [list(map(int,input().split())) for _ in range(N)]
cd = [list(map(int,input().split())) for _ in range(N)]
ab.sort(key=itemgetter(0),reverse=True)
ab.sort(key=itemgetter(1),reverse=True)
cd.sort(key=itemgetter(1))
cd.sort(key=itemgetter(0))
count = 0
for c,d in cd[:]:
    for a,b in ab:
        if a < c and b < d:
            count += 1
            ab.remove([a,b])
            cd.remove([c,d])
            break
print(count)


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

using namespace std;
using ll=long long;

// when range [l, r), has property notP~P, want first P.
// when return r, means not found.
template <typename T>
T bs_first(T l, T r, function<bool (T)> f) {
    assert(l < r);
    T mid;
    while (l != r) {
        mid = l + (r-l)/2;
        if (f(mid)) {
            r = mid;
        }else {
            l = mid + 1;
        }
    }
    return r;
}

void solve() {
    int n; ll K;
    cin >> n >> K;
    vector<int> a(n), b(n);
    for (auto& x: a) {
        cin >> x;
    }
    for (auto& x: b) {
        cin >> x;
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end(), greater<int>());
    ll res = bs_first<ll>(0, 1e12+10, [&](ll t){
            ll need = 0;
            for (int i = 0; i < n; i++) {
                need += max(0ll, a[i] - t/b[i]);
            }
            return need <= K;
            });
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

int main() {
  int K;
  std::cin >> K;
  int ans = 0;
  for (int i: range(1, K + 1)) {
    for (int j: range(1, K + 1)) {
      for (int k: range(1, K + 1)) {
        ans += std::gcd(std::gcd(i, j), k);
      }
    }
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3628
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	as := make([]int, n)
	for i := range as {
		fmt.Scan(&as[i])
	}
	cnt := 0
	for _, a := range as {
		for a%2 == 0 {
			cnt++
			a /= 2
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 1280
#include<iostream>

using namespace::std;

int main(){
  string s,t;
  cin>>s>>t;
  int l,r;
  cin>>l>>r;
  string u;
  cin>>u;
  if(s==u)
    cout<<l-1<<' '<<r<<'\n';
  else cout<<l<<' '<<r-1<<'\n';
}

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

using namespace std;

int main(){
    int n,x,count=0;
    cin>>n>>x;
    vector<int>D(n+1);
    D[0]=0;
    for(int i=0;i<n;i++){
        int a;cin>>a;
        D[i+1]=D[i]+a;
    }
    for(int i=0;i<=n;i++){
        if(D[i]<=x) count++;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

using namespace std;

int main() {
    int N, M;
    
  //青のカード
    cin >> N;
    map <string, int> s;
    for (int i = 0; i < N; i++) {
        string input;
        cin >> input;
        s[input]++;               //keyのvalueが1増加
    }
  
  //赤のカード
    cin >> M;
    map <string, int> t;
    for (int i = 0; i < M; i++) {
        string input;
        cin >> input;
        t[input]++;
    }

    int ans = 0;
    for (auto&& str : s) {
        ans = max(ans, str.second - t[str.first]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256