akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const int di[] = {-1, 1, 0, 0}, dj[] = {0, 0, -1, 1};

int main(void){
    int n;
    cin >> n;
    int n2 = n * n;
    VI p(n2);
    REP(i,n2) p[i] = in() - 1;

    VVI dist(n, VI(n));
    REP(i,n) REP(j,n){
        dist[i][j] = min({i + 1, j + 1, n - i, n - j});
    }

    VVI wall(n, VI(n, 1));
    int ans = 0;
    REP(i,n2){
        // cout << p[i] << endl;
        int x = p[i] / n, y = p[i] % n;
        wall[x][y] = 0;
        int mi = dist[x][y];
        REP(k,4){
            int i = x + di[k], j = y + dj[k];
            if (i < 0 || i >= n || j < 0 || j >= n) chmin(mi, 0);
            else chmin(mi, dist[i][j]);
        }
        ans += mi;
        queue<P> que;
        que.push(P(x, y));
        dist[x][y] = mi;
        while (!que.empty()){
            P p = que.front();
            que.pop();
            int i = p.first, j = p.second;
            REP(k,4){
                int ii = i + di[k], jj = j + dj[k];
                if (ii < 0 || ii >= n || jj < 0 || jj >= n) continue;
                if (dist[ii][jj] <= dist[i][j] + wall[ii][jj]) continue;
                dist[ii][jj] = dist[i][j] + wall[ii][jj];
                que.push(P(ii, jj));
            }
        }
        // REP(i,n){
        //     REP(j,n) cout << dist[i][j] << " ";
        //     cout << endl;
        // }
    }
    cout << ans << endl;

    return 0;
}


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

int N;
int T[64];
int estimated;

int dp[53][2500][2500];

int estimated_answer() {
  int count[3] = {};

  for(int i = 0; i < N; ++i) {
    int t = 0;
    if( count[0] < count[1] ) {
      t = 0;
    }
    else {
      t = 1;
    }
    if( count[t] > count[2] ) {
      t = 2;
    }

    count[t] += T[i];
  }
  return std::max(std::max(count[0], count[1]), count[2]);
}

int dfs(int i, int count[3]) {
  std::sort(count, count + 3);
  assert(count[0] < 2500 );
  assert(count[1] < 2500 );
  assert( i <= 51 );
  if( dp[i][count[0]][count[1]] != 0 ) return dp[i][count[0]][count[1]] - 1;
  int max = std::max(std::max(count[0], count[1]), count[2]);
  if( i >= N ) {
    dp[i][count[0]][count[1]] = max + 1;
    return max;
  }
  if( max > estimated ) {
    dp[i][count[0]][count[1]] = max + 1;
    return max;
  }
  int res = 1000000;
  int count2[3] = {};
  for(int k = 0; k < 3; ++k) count2[k] = count[k];
  for(int k = 0; k < 3; ++k) {
    count[k] += T[i];
    res = std::min(res, dfs(i + 1, count));
    for(int k = 0; k < 3; ++k) count[k] = count2[k];
  }
  estimated = std::min(estimated, res);
  dp[i][count[0]][count[1]] = estimated + 1;
  return res;
}

int main(int argc, char *argv[]) {


  std::cin >> N;
  for(int i = 0; i < N; ++i) {
    std::cin >> T[i];
  }

  std::sort(T, T + N);
  std::reverse(T, T + N);

  estimated = estimated_answer();

  int count[3] = {};
  std::cout << dfs(0, count) << std::endl;
  
  return 0;
}

Measured memory_bytes: 35100
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

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

        while (true) {
            int y = scanner.nextInt(), x = scanner.nextInt();

            if (x == 0 && y == 0) break;

            for (int i = 0; i < y; ++i) {
                for (int j = 0; j < x; ++j) {
                    if (i == 0 || i == y - 1 || j == 0 || j == x - 1) System.out.print("#");
                    else System.out.print(".");
                }
                System.out.println();
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 32724
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		int a=Integer.parseInt(sc.next());
		int b=Integer.parseInt(sc.next());
		int c=Integer.parseInt(sc.next());
		
		int num=0;
		for(int i=a;i<=b;i++){
			if(c%i==0) num++;
		}
		System.out.println(num);

	}

}

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
using ll = long long;


int main() {
    int n; cin >> n;
    V<P<int, int> > od(100010), ev(100010);
    for(int i = 0; i < n; i++){
        int v; cin >> v;
        if(i & 1){
            od[v].first++;
            od[v].second = v;
        }else{
            ev[v].first++;
            ev[v].second = v;
        }
    }

    sort(ALL(od), greater<P<int, int>>());
    sort(ALL(ev), greater<P<int, int>>());

    int t = 0;
    if(od[0].second == ev[0].second){
        t = max(od[0].first + ev[1].first, od[1].first + ev[0].first);
    }else{
        t = od[0].first + ev[0].first;
    }
    cout << n - t << endl;

    return 0;
}


Measured memory_bytes: 4832
import heapq
K = int(input())


def fun(h, n):
    tmp = n % 10
    if tmp != 0:
        heapq.heappush(h, 10 * n + tmp - 1)
    heapq.heappush(h, 10 * n + tmp)
    if tmp != 9:
        heapq.heappush(h, 10 * n + tmp + 1)


h = list(range(1, 10))
while K > 0:
    n = heapq.heappop(h)
    fun(h, n)
    K -= 1
else:
    print(n)

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

public class Main {


    private static void solver(InputReader sc, PrintWriter out) throws Exception {
       int a = sc.nextInt();
       int b = sc.nextInt();
       int c = sc.nextInt();
       int k = sc.nextInt();
       int count=0;
       while(b <= a && count < k){
            b *= 2;
            count++;
       }
       while(c <= b && count < k){
           c *= 2;
           count++;
       }
       if(b > a && c > b){
           out.println("Yes");
       }else out.println("No");
    }

    private static int lcm(int a, int b) {

        return (a * b) / gcd(a, b);
    }

    private static int gcd(int a, int b) {

        if (b == 0)
            return a;

        return gcd(b, a % b);
    }

    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        solver(in, out);
        out.close();
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

class Pair {
    int x, y;

    Pair(int x, int y) {
        this.x = x;
        this.y = y;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Pair pair = (Pair) o;
        return x == pair.x &&
                y == pair.y;
    }

    @Override
    public int hashCode() {
        return Objects.hash(x, y);
    }
}

class Tuple implements Comparable<Tuple> {
    int x, y, z;

    public Tuple(int x, int y, int z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }

    public int compareTo(Tuple t) {
        if (this.z == t.z) {
            if (this.y == t.y) {
                return t.x - this.x;
            } else return t.y - this.y;
        } else
            return this.z - t.z;
    }


}

Measured memory_bytes: 32924
#include<iostream>
#include<cstdlib>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
using ll = long long int;
const int mod = 1e9 + 7;
#define rep(i, a, b) for(int i = a;i < b; i++)

int main() {

	int n;
	cin >> n;

	int k = n - 1;
	vector<int> b(k);
	rep(i, 0, n - 1) cin >> b[i];

	int sum = 0;

	sum += b[0];

	rep(i, 1, k) {
		if (b[i - 1] <= b[i]) sum = sum + b[i - 1];
		else sum = sum + b[i];
	}

	sum += b[n - 2];

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>
#include <cmath>
using namespace std;
int main(){
    int n;
    cin>>n;
    double bk1[n],bk2[n];
    
    double min1=0,min2=0,min3=0,minm=0;
    double che[n];
    
    for(int i=0;i<n;i++){
        cin>>bk1[i];
    }
    int ci=0;
    for(int i=0;i<n;i++){
        cin>>bk2[i];
        min1+=abs(bk1[i]-bk2[i]);
        min2+=pow(abs(bk1[i]-bk2[i]),2);
        min3+=pow(abs(bk1[i]-bk2[i]),3);
        che[ci]=abs(bk1[i]-bk2[i]);
        ci++;
    }
    min2=sqrt(min2);
    min3=cbrt(min3);
    minm=che[0];
    for(int i=1;i<ci;i++){
        if(minm<che[i]){
            minm=che[i];
            
        }
    }
    printf("%f\n%f\n%f\n%f\n",min1,min2,min3,minm);
    
    
    
    
return 0;
}


Measured memory_bytes: 3412
X[]={0,1,0,-1},Y[]={-1,0,1,0},f[109][109],g[109][109][4];char s[109],*D="NESW";
main(h,w,z,x,y,c,i,j,k){long long l;for(;scanf("%d%d%lld",&h,&w,&l),h;printf("%d %d %c\n",y,x,D[z])){
	memset(f,1,sizeof(f)),memset(g,0,sizeof(g));
	for(i=0;i<h;i++)for(scanf("%s",s),j=0;j<w;j++){
		for(k=0;k<4;k++)if(s[j]==D[k])x=j+1,y=i+1,z=k;
		if(s[j]!='#')f[i+1][j+1]=0;
	}
	for(c=0;l;l--,c++){
		if(g[y][x][z]&&(l%=c-g[y][x][z])==0)break;
		for(g[y][x][z]=c;;z=(z+1)%4)if(!f[y+Y[z]][x+X[z]]){x+=X[z];y+=Y[z];break;}
	}
}exit(0);}

Measured memory_bytes: 844
#include <iostream>
using namespace std;
int main()
{
    int x;
    cin>>x;
    if (x>=1800 && x<=1999) {cout<<1;return 0;}
    if (x>=1600 && x<=1799) {cout<<2;return 0;}
    if (x>=1400 && x<=1599) {cout<<3;return 0;}
    if (x>=1200 && x<=1399) {cout<<4;return 0;}
    if (x>=1000 && x<=1199) {cout<<5;return 0;}
    if (x>=800 && x<=999) {cout<<6;return 0;}
    if (x>=600 && x<=799) {cout<<7;return 0;}
    if (x>=400 && x<=599) {cout<<8;return 0;}
}

Measured memory_bytes: 3628
#include<iostream>
#include<cstdio>
#define N 100005
using namespace std;

typedef long long ll;
ll n,c,s,ans,x[N],cal[N],mx[N]={0},mx2[N]={0};
int main(){
  ll i;
  cin>>n>>c;
  for(i=0;i<N;i++){
    scanf("%lld %lld",&x[i],&cal[i]);
  }  
  //clockwise
  for(i=n-1;i>=0;i--){
    s+=cal[i];//consumed calories
    mx[i] = max(mx[i+1],s-(c-x[i]));//c-x[i]: used calories
    mx2[i] = max(mx2[i+1],s-(c-x[i])*2);//return first point
  }
  
  ans = max(mx[0],mx2[0]);
  s=0;//initialize calories
  
  //anticlockwise
  for(i=0;i<n;i++){
    s+=cal[i];
    ans = max(ans, s-x[i]*2 + mx[i+1]);//return first point 
    ans = max(ans, s-x[i] + mx2[i+1]);
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 3328
N, A, B = map(int, input().split())
S = list(input())

x = 0 # 予選の通過人数
b = 1 # 海外勢の予選の通過人数

for S in S:
    if S == "a" and x < A + B:
        x += 1
        print("Yes")
    elif S == "b" and x < A + B and b <= B:
        b += 1
        x += 1
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 9876
n = int(input())
wa = 0.5*n*(n+1)
Fizz_num = n//3
Fizz_sum = sum([3*i for i in range(1,Fizz_num+1)])
Buzz_num = n//5
Buzz_sum = sum([5*i for i in range(1,Buzz_num+1)])
FizzBuzz_num = n//15
FizzBuzz_sum = sum([15*i for i in range(1,FizzBuzz_num+1)])

ans = wa - (Fizz_sum+Buzz_sum) + FizzBuzz_sum

print(int(ans))

Measured memory_bytes: 22108
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin >> n;
	int g=0,ans=1;
	for(int i=1;i<=n;++i){
		int x=0;
		int t=i;
		while(t%2==0){
			x++;
			t/=2;
		}
		if(x>g){
			g=x;
			ans=i;
		}
	}
	cout << ans << endl;
}

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

int main(void){
	int n, jum, cou=1, pre;
	int a[100000];

	cin >> n;
	for(int i=0; i<n; i++)
		cin >> a[i];

	jum = a[0];
	pre = a[0];
	a[0] = -1;
	while(1){
		if(jum==-1){
			cout << -1 << endl;
			return 0;
		}else if(jum==2){
			cout << cou << endl;
			return 0;
		}
		jum = a[pre-1];
		a[pre-1] = -1;
		pre = jum;
		cou++;
	}
}


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

using namespace std;

int main() {
  int N, s = 0; cin >> N;
  vector<int> A(N, 0), C(N, 0);
  for(int i = 0; i < N; i++) cin >> A[i];
  for(int i = 0; i < N; i++) {
    int B; cin >> B; s += B;
  }
  for(int i = 0; i < N; i++) cin >> C[i];
  for(int i = 0; i < N - 1; i++) {
    if(A[i] == A[i + 1] - 1) s += C[A[i] - 1];
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N,D;
    cin>>N>>D;
    D = (D * 2) + 1;
    if(N%D==0)
        cout<<N/D<<endl;
    else
        cout<<(N/D)+1<<endl;
    return 0;
}


Measured memory_bytes: 256
// Goods things are coming, just keep believing 
 
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
 
#define FOR(i, x, n) for(ll i = x; i < n; i++) 
#define pb push_back
#define pf push_front
#define ll long long
#define hii cout << "hii" << endl
#define okay cout << "okay" << endl
// #define hey cout << "hey" << endl
#define pii pair<int, int>
#define pll pair<ll, ll>
#define mp make_pair
#define endl '\n'
#define ff first 
#define int long long
#define ss second
#define vi vector<int>
#define all(s) s.begin(), s.end()
#define si size()
 #define ld long double
#define INF 1000000000;
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; } 
 
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE
 
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
 
 
 
const int N = 2e5 + 5;
const int LG = 20;
const int mod = 1e9 + 7;

int arr[N];
int n, m;

int f(int n)
{
	if(n == 1)
	{
		return 1;
	}
	int ans1 = f(n / 2);
	return 2 * ans1 + 1;
}

void solve()
{
	vector<int> v;
	int n;
	cin >> n;
	cout << f(n) << endl;
}

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

	int t = 1;
	// cin >> t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main (){
    double w,h,x,y;
    cin >> w >> h >> x >> y;
    bool jud=0;
    double s=(double)w*h/2;
    if(x==w/2&&y==h/2) jud=1;
    cout << (double)s << " " << jud << "\n";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
const long long MOD = 1000000007;
const int INF = 1<<29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef pair<int,int> P;
typedef long long ll;

ll N, M;
ll memo[301][301][301];

ll dfs(int pos, int got, int next){
    if(pos == M){
        if(got == N) return 1;
        else return 0;
    }
    if(memo[pos][got][next] != -1) return memo[pos][got][next];

    if(got == N) {
        return (N * dfs(pos+1, N, 0)) % MOD;
    }

    ll ret = 0;
    
    // go to nodes that has a path to node 1.
    // number of such nodes is `got`
    ret = (ret + got * dfs(pos+1, got+next, 0)) % MOD;
    
    // go to visited nodes that doesn't have a path to node 1.
    // number of such nodes is `next`
    ret = (ret + next * dfs(pos+1, got, next)) % MOD;

    // go to non visited nodes if it exists.
    // number of such nodes is `N - (got + next)`
    if (N - (got + next) > 0){
        ret = (ret + (N - (got + next)) * dfs(pos+1, got, next+1)) % MOD;
    }

    memo[pos][got][next] = ret;
    return ret;
}

int main(){
    cin >> N >> M;
    memset(memo, -1, sizeof(memo));
    cout << dfs(0, 1, 0) << endl; 
    return 0;
}


Measured memory_bytes: 213376
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rel register ll
#define rec register char
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) pc('-'),x=-x;
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
const int z=105;
char c[z][z];int vish[z],visl[z];
int main(){
int i,j,n=read(),m=read();
for (i=1;i<=n;++i) scanf("%s",c[i]+1);
for (i=1;i<=n;++i){
  int bo=0;
  for (j=1;j<=m;++j) if (c[i][j]=='#') bo=1;
  if (!bo) vish[i]=1; 
  }  
for (i=1;i<=m;++i){
  int bo=0;
  for (j=1;j<=n;++j) if (c[j][i]=='#') bo=1;
  if (!bo) visl[i]=1;
  }
int bo;
for (i=1;i<=n;++i,bo?pl:0)
  for (bo=0,j=1;j<=m;++j) if (!vish[i]&&!visl[j]) pc(c[i][j]),bo=1;
}

Measured memory_bytes: 256
#include <cmath>
#include<iostream>
#include <functional>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <iomanip>
using namespace std;
 
int main(){    
  int N,a=1;
  string S;
  cin >> N >> S;
  
  while(a != 0){
    a=0;
    for(int i=0;i<S.length();i++){
      if(S[i] == S[i+1]){
	a++;
      }
    }
    
    for(int i=0;i<S.length();i++){
      if(S[i] == S[i+1]){
	S.erase(i+1,1);
      }
    }
  }
  
  cout << S.length() << endl;
}


Measured memory_bytes: 512
S = input()
T = input()
ans = 0
cnt = 0
for i in range(0, len(S) - len(T)+1):
    cnt = 0
    S_sub = S[i:i+len(T)]
    for j in range(len(T)):
        if S_sub[j] == T[j]:
            cnt += 1
    ans = max(ans, cnt)
print(len(T) - ans)



Measured memory_bytes: 9052
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 14

N, Q = map(int, raw_input().split())
A = map(int, raw_input().split())
X = [(input(), i) for i in range(Q)]
X.sort()

ALT = [0] * N
if N % 2:
    ALT[0] = A[0]
    for i in range(2, N, 2):
        ALT[i - 1] = ALT[i - 2]
        ALT[i] = ALT[i - 2] + A[i]
else:
    ALT[1] = A[1]
    for i in range(3, N, 2):
        ALT[i - 1] = ALT[i - 2]
        ALT[i] = ALT[i - 2] + A[i]

ALT = [0] + ALT

S = [0] * N + [0]
for i in range(N):
    S[i + 1] = S[i] + A[i]

A = [-INF] + A + [INF]
pos1 = pos2 = 0
x, index = X[0]
for i in range(N + 2):
    if x <= A[i]:
        if A[i] - x < x - A[i - 1]:
            pos1 = pos2 = i
        else:
            pos1 = pos2 = i - 1
        break

ans = [0] * Q
for x, index in X:
    while True:
        cnt1 = pos2 - pos1
        cnt2 = N - pos2 + 1
        if cnt2 - cnt1 >= 2:
            if A[pos2] - x < x - A[pos1 - 1]:
                pos2 += 1
            else:
                pos1 -= 1
        elif cnt1 > cnt2:
            if A[pos2 - 1] - x < x - A[pos1]:
                pos1 += 1
            else:
                pos2 -= 1
        elif A[pos2] - x < x - A[pos1]:
            pos1 += 1
            pos2 += 1
        elif A[pos2 - 1] - x >= x - A[pos1 - 1]:
            pos1 -= 1
            pos2 -= 1
        else:
            break
    ans[index] = S[N] - S[pos2 - 1] + ALT[pos1 - 1]

for a in ans:
    print a


Measured memory_bytes: 30132
n = int(input())
arr = list(map(int, input().split()))
idx = {}
for i, a in enumerate(sorted(arr)):
    idx[a] = i
visit = [False]*n
Min = min(arr)
ans = 0
for i in range(n):
    if visit[i]:
        continue
    visit[i] = True
    now = idx[arr[i]]
    tmp_min = arr[i]
    tot = tmp_min
    cnt = 1
    while now != i:
        visit[now] = True
        tot += arr[now]
        cnt += 1
        if tmp_min > arr[now]:
            tmp_min = arr[now]
        now = idx[arr[now]]
    ans += min(tot + (cnt - 2)*tmp_min, tot + tmp_min + (cnt + 1)*Min)
print(ans)


Measured memory_bytes: 5720
import java.util.*;

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

    int prevA = -10;
    long cost = 0;
    for (int i = 0; i < n; i++) {
      int a = s.nextInt();
      if (a <= prevA) {
        cost += a;
      } else if (a == prevA + 1) {
        cost++;
      } else if (a == 0) {
        // Do nothing.
      } else {
        System.out.println(-1);
        return;
      }
      prevA = a;
    }

    System.out.println(cost);
  }
}


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

#define ll long long
#define d long double

#define scf(n) scanf("%d",&n)
#define lscf(n) scanf("%lld",&n)
#define dscf(n) scanf("%Lf",&n)
#define pri(n) printf("%d ",(int)n)
#define lpri(n) printf("%lld ",n)
#define dpri(n) printf("%Lf ",n)
#define prin(n) printf("%d\n",(int)n)
#define lprin(n) printf("%lld\n",n)
#define dprin(n) printf("%Lf\n",n)

#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define rep(i,ini,n) for(ll i=ini;i<(int)n;i++)
#define all(x) x.begin(),x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define bitcount(n) __builtin_popcount(n)
#define tc   int tt; scf(tt); while(tt--)
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN

#define pb push_back
#define mp make_pair
#define F first
#define S second
#define PI 3.14159265358979323846264

const ll M =1e9+7;
const int N = 1e6+7;



int main()
{
    int x,n;
    cin>>x>>n;
    set<int>s;
    rep(i,0,n)
    {
        int a;
        cin>>a;
        s.insert(a);
    }
    int mi1=0;
    for(int i=x;i>x-200;i--)
    {
        if(s.find(i)==s.end())
        {
            mi1=i;
            break;
        }
    }
    int mi2=0;
    for(int i=x;i<x+200;i++)
    {
        if(s.find(i)==s.end())
        {
            mi2=i;
            break;
        }
    }

    if(abs(mi1-x)<abs(mi2-x))
    {
        cout<<mi1;
        return 0;
    }
    if(abs(mi1-x)>abs(mi2-x))
    {
        cout<<mi2;
        return 0;
    }
    else
    {
        cout<<mi1;
    }
    
return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define pii pair<ll,ll>

using namespace :: std;

const ll mod=1e9+7;
const ll inf=1e17+500;
const ll maxn=1e6+500;
ll fac[maxn];
ll rfac[maxn];

ll poww(ll a,ll b){
    ll ans=1;
    while(b){
        if(b&1){
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b>>=1;
    }
    return ans;
}
ll ent(ll n,ll k){
    if(k<0 || k>n)return 0;
    return (((fac[n]*rfac[k])%mod)*rfac[n-k])%mod;
}

set<pii> st[maxn];
set<pii> :: iterator it;

pii find_near(ll n,ll r){
    pii ans=mp(0,1);
    it=st[n].lower_bound(mp(r,0));
    if(it!=st[n].end()){
        if(abs((*it).F-r)<abs(r-ans.F)){
            ans=*it;
        }
    }
    if(it!=st[n].begin()){
        it--;
        if(abs((*it).F-r)<abs(r-ans.F)){
            ans=*it;
        }
    }
    return ans;
}
ll find_pre(ll n,ll r){
    if(r==n){
        ll res=poww(2,n);
        st[n].insert(mp(r,res));
        return res;
    }
    pii e=find_near(n,r);
    if(abs(e.F-r)<5){
        while(e.F<r){
            e.F++;
            e.S=(e.S+ent(n,e.F))%mod;
        }
        while(e.F>r){
            e.S=(e.S-ent(n,e.F)+mod)%mod;
            e.F--;
        }
        st[n].insert(e);
        return e.S;
    }
    ll res=(find_pre(n-1,r)*2-ent(n-1,r)+mod)%mod;
    st[n].insert(mp(r,res));
    return res;
}
ll find_sum(ll s,ll l,ll r){
    if(l==0)return find_pre(s,r);
    return (find_pre(s,r)-find_pre(s,l-1)+mod)%mod;
}
int main(){
    fac[0]=1;
    rfac[0]=1;
    for(ll i=1;i<maxn;i++){
        fac[i]=(fac[i-1]*i)%mod;
        rfac[i]=poww(fac[i],mod-2);
    }

   ll ans=0;
   ll n,m,k;
   cin>>n>>m>>k;
   n--;
   for(ll s=0;s<=m+k;s++){
        ll res=find_sum(s,max(0LL,s-m),min(k,s));
        res%=mod;
        res*=ent(n+s,s);
        res%=mod;
        res*=poww(3,m+k-s);
        res%=mod;
        ans+=res;
   }
   cout<<ans%mod;
}




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

long long n,a,b,s=0;
vector<long long> c, d, ans;
vector<vector<long long>> G;

long long ret(long long a){
    return a*(a+1)/2;
}

void dfs(long long u, long long prev) {
    long long t = s + d[c[u]];
    for(auto v: G[u]) {
        if (v == prev) {
            continue;
        }
        // cout<<"v: " << v<<endl;
        d[c[u]] = -s;
        dfs(v, u);
        ans[c[u]] -= ret(s + d[c[u]]);
    }
    s++;
    d[c[u]] = t-s;
}

int main() {
    cin>>n;
    
    G.assign(n, vector<long long>());
    c.assign(n, 0);
    d.assign(n, 0);
    ans.assign(n, ret(n));

    for(int i=0;i<n;i++) {
        long long cc;
        cin >>cc;
        c[i] = cc-1;
    }
    for(int i=0;i<n - 1;i++) {
        cin >>a>>b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    dfs(0, -1);
    for(int k=0;k<n;k++) {
        ans[k] = ans[k] - ret(s+d[k]);
    }
    for(int i=0;i<n;i++){
        cout<<ans[i]<<"\n";
    }
    return 0;
}

Measured memory_bytes: 31384
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main(){
    int n,b,c;
    scanf("%d",&n);
    scanf("%d",&b);
    scanf("%d",&c);
    if(n<b&&b<c){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 2040
n,m = map(int,input().split())
l = [0 for i in range(n)]
pena = 0
for i in range(m):
    q,res = input().split()
    if res == "AC":
        if l[int(q)-1] != 1:
            pena += l[int(q)-1]//2
            l[int(q)-1] = 1
    elif l[int(q)-1]%2 == 0:
        l[int(q)-1] +=2

print(l.count(1),pena)

Measured memory_bytes: 3888
from decimal import Decimal, ROUND_HALF_UP, ROUND_HALF_EVEN
while True:
    try:
        z = list(map(int,input().split()))
    except:
        break
    a = z[:3]
    b = z[3:]
    c = a[:]
    d = b[:]
    s = [a[0],b[0]]
    a = list(map(lambda x:x*s[1],a))
    b = list(map(lambda x:x*s[0],b))
    y = (b[2]-a[2])/(b[1]-a[1])
    try:
        x = (c[2]-c[1]*y)/c[0]
    except:
        x = (d[2]-d[1]*y)/d[0]
    print(Decimal(str(x)).quantize(Decimal('0.001'), rounding=ROUND_HALF_UP),Decimal(str(y)).quantize(Decimal('0.001'), rounding=ROUND_HALF_UP))


Measured memory_bytes: 6396
//headers
#include <bits/stdc++.h>
#define ll long long
using namespace std;

void solve() 
{
    char c;cin>>c;
    if(islower(c)){cout << 'a' << endl;}
    else{cout << 'A' << endl;}
} 

//driver
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    ll test = 1;
    // cin>>test;
    for(ll i = 0;i<test;i++)
    {
        solve();
    }
}    

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

using namespace std;


#define ff				first
#define ss				second
#define int				long long
#define pb				push_back
#define mp				make_pair
#define pii				pair<int,int>
#define vi				vector<int>
#define mii 			map<int,int>
#define	pqb				priority_queue<int>
#define pqs				priority_queue<int,vi,greater<int> >
#define setbits(x)		__builtin_popcountll(x)
#define zrobits(x)		__builtin_ctzll(x)
#define mod				1000000007
#define inf 			1e18
#define ps(x,y)			fixed<<setprecision(y)<<x
#define mk(arr,n,type)	type *arr = new type[n]
#define w(x)			int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl			'\n'
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl

const int maxn = 1e5 + 5;
void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

}


bool isPrime(int n)
{
	if (n <= 1)
		return false;
	if (n <= 3)
		return true;
	if (n % 2 == 0 || n % 3 == 0)
		return false;
	for (int i = 5; i * i <= n; i += 6)
	{
		if (n % i == 0 || n % (i + 2) == 0)
			return false;

	}
	return true;
}

vector<int> Sieve(int n)
{
	bool prime[n + 1];
	memset(prime, true, sizeof(prime));
	for (int i = 2; i * i <= n; i++)
	{
		if (prime[i])
		{
			for (int j = i * i; j <= n; j += i)
			{
				prime[j] = false;
			}
		}
	}
	vector<int> primes;

	for (int i = 2; i <= n; i++)
	{
		if (prime[i])
			primes.pb(i);
	}
	return primes;
}
set<int> primeFactors(int  n)
{
	set<int> factors;
	while (n % 2 == 0)
	{
		n /= 2;
		factors.insert(2);

	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		// int count = 0;
		while (n % i == 0)
		{
			factors.insert(i);
			n /= i;
		}
	}
	if (n > 2)
		factors.insert(n);
	return factors;
}

int power(int x, unsigned int y, int p)
{
	int res = 1;

	x = x % p;

	if (x == 0) return 0;
	;
	while (y > 0)
	{

		if (y & 1)
			res = (res * x) % p;

		y = y >> 1; // y = y/2
		x = (x * x) % p;
	}
	return res;

}

// Graph------------------------------------------------------------------------


int32_t main()
{
	 FIO;
//	c_p_c();
	// --------------------------------------------------
	// Never GIVE UP !!!!

	int n;
	cin >> n;
	mk(arr, n, int);
	for (int i = 0; i < n; i++)
	{
		cin >> arr[i];
	}

	vi dp(n, 1e9 + 5);
	dp[0] = 0;

	for (int i = 0; i < n; i++)
	{
		for (int j = i + 1; j <= i + 2; j++)
		{
			dp[j] = min(dp[j], dp[i] + abs(arr[j] - arr[i]));
		}
	}

	cout << dp[n - 1] << endl;







}


Measured memory_bytes: 4792
package main

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

var sc = bufio.NewScanner(os.Stdin)
var buff []byte

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buff, bufio.MaxScanTokenSize*1024)
	log.SetFlags(log.Lshortfile)
}

func main() {
	input := nextString()
	remSumArray := make([]int, 2019)
	remSumArray[0] = 1
	var num int
	digit := 1
	for i := len(input) - 1; i >= 0; i-- {
		num += int(input[i]-48) * digit
		digit *= 10
		digit %= 2019
		remSumArray[num%2019]++
	}
	var result int
	for _, num := range remSumArray {
		result += num * (num - 1) / 2
	}
	fmt.Println(result)
}

func nextString() string {
	sc.Scan()
	return sc.Text()
}

func nextFloat64() float64 {
	sc.Scan()
	f, err := strconv.ParseFloat(sc.Text(), 64)
	if err != nil {
		panic(err)
	}
	return f
}

func nextInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextInts(n int) (r []int) {
	r = make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

var dy = []int{0, 1, 0, -1}
var dx = []int{1, 0, -1, 0}
var MAX = math.MaxInt32

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type Pair struct {
	a, b int
}

type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return p[i].a < p[j].a
}


Measured memory_bytes: 2524
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
 
int main() {
  int N;
  int C = 0, a = 0;
  cin >> N;
  int p[N];

  for(int i = 0; i < N; ++i){
    cin >> p[i];
    C += p[i];
    a = max(a,p[i]);
  }

 
  cout << C - a/2 << endl;    
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
using namespace std;

int main(){
	int i,n,x=100000;
	cin >> n;
	for(i=0;i<n;i++){
		x*=1.05;
		if(x%1000!=0) x=(x/1000+1)*1000;
	}
	cout << x << endl;
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

const int MAXN = 2001;

std::vector<std::pair<int, int>> a;
int64_t f[MAXN][MAXN];

int64_t solve(int n) {
  std::sort(a.begin(), a.end(), [](const auto& x, const auto& y) {
    return x > y; 
  });
  for (int i = 0; i < n; ++i) {
    int64_t val = a[i].first;
    int pos = a[i].second;
    for (int l = 0; l <= i + 1; ++l) {
      int r = i + 1 - l;
      int64_t temp = 0;
      if (l > 0) f[l][r] = f[l - 1][r] + val * std::abs(l - 1 - pos);
      if (r > 0) temp = f[l][r - 1] + val * std::abs(n - r - pos);
      if (temp > f[l][r]) f[l][r] = temp;
    }
  }
  int64_t ans = 0;
  for (int i = 0; i <= n; ++i) {
    if (f[i][n - i] > ans) ans = f[i][n - i];
  }
  return ans;
}

int main() {
  int n;
  std::cin >> n;
  for (int i = 0, u; i < n; ++i) {
    std::cin >> u;
    a.emplace_back(u, i);
  }
  std::cout << solve(n) << std::endl;
  return 0;
}


Measured memory_bytes: 26168
#include <bits/stdc++.h>
using namespace std;
 
#define froop1(a,n) for(int i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)
int main(){
	int N,M,th = 0;  //N:スイッチ M:電球
  cin >> N >> M;
  vector<vector<int>> sw(N); //それぞれの電球に対応したスイッチ
  vector<int> check(M); //電球点灯確認
  
  froop1(0,M){
    int s;
    cin >> s;
    for(int j = 0;j < s;j++){
      int t;
      cin >> t;
      sw.at(t - 1).push_back(i);
    }
  }
  
    froop1(0,M) cin >> check.at(i);
  	int all = 1 << N;
  for(int bit = 0;bit < all;bit++){
      int c = 1;
      vector<int> count(M,0);
      	froop1(0,N){
    		if((bit >> i) & 1){
         	 for(int j = 0;j < sw.at(i).size();j++){
               count.at(sw.at(i).at(j))++;
             }
        	}
     	 }
      for(int j = 0;j < M;j++){
        if(count.at(j) % 2 != check.at(j)) c = 0;
      }
      if(c == 1) th++;
    }
  cout << th << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
	
	int x[10000];
	int i = 1, j = 1;

	while (1) {
		scanf("%d\n", &x[i]);
		if (1 <= x[i] && x[i] <= 10000) {
			if (x[i] == 0) break;
			i++;
		}
		else break;
	}

	while (1) {
		printf("Case %d: %d\n", j, x[j]);
		j++;
		if (j == i) break;
	}
	
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <deque>
using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
typedef long long ll;
typedef map<int,int> mint;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef deque<pair<ll,ll>> dep;
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int inf=1e9+1000;
ll infi=1e18+100;

//x=10111;
//x<<2 = 1011100 (右シフト),x>>2 = 101 (左シフト)
//(x>>2)&1 = 101 & 001 = 1
//iビット目は、(x>>i) & 1 でわかる(x>>i)%2 でもよい

ll N,C;


int main(){
	cin>>N>>C;
	ll x[N+2],v[N+2];
	x[0]=0;
	x[N+1]=C;
	v[0]=0;
	v[N+1]=0;
	rep(i,N) cin>>x[i]>>v[i];
	ll y[N+2],w[N+2];
	Rep(i,N+2){
		y[N+1-i]=C-x[i];
		w[N+1-i]=v[i];
	}
	
	ll tokei[N+2];
	tokei[0]=0;
	rep(i,N){
		tokei[i]=tokei[i-1]+v[i]-x[i]+x[i-1];
	}
	ll hantai[N+2];
	hantai[0]=0;
	rep(i,N){
		hantai[i]=hantai[i-1]+w[i]-y[i]+y[i-1];
	}
	
	ll ans;
	ans = 0;
	rep(i,N) ans=max(ans,tokei[i]);
	rep(i,N) ans=max(ans,hantai[i]);
	
	ll maxhantai[N+2];
	maxhantai[0]=0;
	rep(i,N) maxhantai[i]=max(maxhantai[i-1],hantai[i]);
	rep(k,N) ans=max(ans,tokei[k]-x[k]+maxhantai[N-k]);
	
	ll maxtokei[N+2];
	maxtokei[0]=0;
	rep(i,N) maxtokei[i]=max(maxtokei[i-1],tokei[i]);
	rep(k,N) ans=max(ans,hantai[k]-y[k]+maxtokei[N-k]);
	
	cout<<ans<<endl;
	  return 0;
  }

Measured memory_bytes: 6528
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define in read()
#define re register
#define fur(i,a,b) for(re int i=a;i<=b;++i)
#define fdr(i,a,b) for(re int i=a;i>=b;--i)
#define cl(a,b) memset(a,b,sizeof(a))
#define jinitaimei signed
#define int long long
inline int read()
{
	int x=0;
	char ch=getchar();
	for(;!isalnum(ch);ch=getchar());
	for(;isalnum(ch);ch=getchar()) x=x*10+ch-'0';
	return x;
}
const int xx=1e5+1;
struct point
{
	int x,y;
}tmp[xx],check[xx*9];
int w,h,n;
inline int num(point a){return (a.x-1)*w+a.y;}
inline bool cmp(point a,point b){return num(a)<num(b);}
inline bool cmpp(point a,point b){return a.x<b.x;}
inline int look_up(int k)
{
	int hd=1,tl=n,ans=n+1;
	while(hd<=tl)
	{
		int mid=hd+tl>>1;
		if(num(tmp[mid])>=k) ans=mid,tl=mid-1;
		else hd=mid+1;
	}
	return ans;
}
inline int look_down(int k)
{
	int hd=1,tl=n,ans=0;
	while(hd<=tl)
	{
		int mid=hd+tl>>1;
		if(num(tmp[mid])<=k) ans=mid,hd=mid+1;
		else tl=mid-1;
	}
	return ans;
}
int res[10],all=0;
jinitaimei main()
{
	h=in;w=in;n=in;
	fur(i,1,n) tmp[i]=(point){in,in};
	sort(tmp+1,tmp+n+1,cmp);
	res[0]=(w-2)*(h-2);
	fur(i,1,n) fur(x,tmp[i].x-2,tmp[i].x) fur(y,tmp[i].y-2,tmp[i].y) if(x>0&&y>0)
	{
		int ch=num((point){x,y});
		int chh=num(tmp[i]);
		int delta=chh-ch;
		if(delta/w>2||delta%w>2) continue;
		if(x+2>h||y+2>w) continue;
		int cnt=0;
		fur(k,0,2)
		{
			int l=look_up(ch+k*w),r=look_down(ch+k*w+2);
			cnt+=(r-l+1);
		}
		if(cnt>0) check[++all]=(point){ch,cnt};
	}
	sort(check+1,check+all+1,cmpp);
	fur(i,1,all)
	{
		while(check[i].x==check[i+1].x) ++i;
		++res[check[i].y];
		--res[0];
	}
	fur(i,0,9) printf("%lld\n",res[i]);
	return 0;
}


Measured memory_bytes: 15872
r,c=map(int,input().split())
a=[0]*c
for i in range(r):
    x=list(map(int,input().split()))
    for j in range(c):
        a[j]+=x[j]
    print(*x, end=' ')
    print(sum(x))
print(*a, end=' ')
print(sum(a))


Measured memory_bytes: 5632
import bisect

INF=10**18
A,B,Q=map(int,input().split())
S=[0]*(A+2)
T=[0]*(B+2)
S[0],T[0]=-INF,-INF
S[A+1],T[B+1]=INF,INF

for i in range(1,A+1):
    S[i]=int(input())

for i in range(1,B+1):
    T[i]=int(input())

for i in range(Q):
    x=int(input())
    b,d=bisect.bisect_right(S,x), bisect.bisect_right(T,x)
    ans=INF
    for s in [S[b-1],S[b]]:
        for t in [T[d-1],T[d]]:
            d1,d2=abs(s-x)+abs(t-s),abs(t-x)+abs(s-t)
            ans=min(ans,d1,d2)
    print(ans)

Measured memory_bytes: 13940
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <limits>
#include <string>
#include <bitset>
#include <functional>
#include <iomanip>
#include <cassert>

using namespace std;
using lint = long long;
using vb = vector<bool>;
using vi = vector<int>;
using vl = vector<int>;
using pii = pair<int, int>;
using pll = pair<lint, lint>;
using pqi = priority_queue<int>;
using pql = priority_queue<lint>;
using si = set<int>;
#define mii = map<int, int>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define repf(i, f, n) for (int i = (f); i < (n); i++)
#define mp(x, y) make_pair((x), (y))
#define pb(x) push_back((x))
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()
#define foreach(it, x) for (auto it = (x).begin(); it != (x).end(); it++)
#define space (char)0x20
#define yes "Yes"
#define no "No"

constexpr lint MOD = 1e9 + 7;
const double PI = acos(-1);
lint A, B, C, D, E, F, G, H, I, J, K, L, M, N;
lint O, P, Q, R, S, T, U, V, W, X, Y, Z;
string s;
lint ans;
lint r = 0, g = 0, b = 0;
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
 
	cin >> N >> s;

	rep(i, N) {
		switch(s[i]) {
			case 'R':
				r++;
				break;
			case 'G':
				g++;
				break;
			case 'B':
				b++;
				break;
			default:
				assert(false);
		}
	}

	ans = r * g * b;
	if (ans == 0) {
		cout << ans << endl;
		return 0;
	}
    
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			int k = j + j - i;
			if (k < N) {
				if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) {
					ans--;
				}
			} else {
				break;
			}
		}
	}

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

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

int main(void){

    const int limitNum = 3000;
    int dataSetX[limitNum];
    int dataSetY[limitNum];
    
    for(int i = 0; i < limitNum; i++) {
        std::cin >> dataSetX[i] >> dataSetY[i];
        if(dataSetX[i] == 0 && dataSetY[i] == 0) {
            break;
        }
    }
    
    for(int i = 0; i < limitNum; i++) {
        if(dataSetX[i] == 0 && dataSetY[i] == 0) {
            break;
        }
        
        if(dataSetX[i] < dataSetY[i]) {
            std::cout << dataSetX[i] << " " << dataSetY[i] << std::endl;    
        } else {
            std::cout << dataSetY[i] << " " << dataSetX[i] << std::endl;
        }
        
    }
    

    
    return 0;
}

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

int n;
int A[20];

bool solve(int i,int m){
    if(m==0){
        return true;
    }
    if(i>=n){
        return false;
    }
    bool res = solve(i+1,m) || solve(i+1,m-A[i]);
    return res;
}

int main(){
    int q, m;
    cin >> n;
    for(int j=0 ; j<n ; j++){
        cin >> A[j];
    }
    cin >> q;
    for(int k=0 ; k<q ; k++){
        cin >> m;
        if(solve(0,m)){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }
    return 0;
}


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

bool solve(const int N, const vector<int>& eccentricities)
{
    const auto diameter = *max_element(begin(eccentricities), end(eccentricities));
    const auto radius = (diameter+1) / 2;

    auto counts = vector<int>(N);
    for (const auto x : eccentricities)
        counts[x]++;

    for (auto d = diameter; d >= radius; d--)
    {
        counts[d] -= 2;
        if (2*d == diameter) counts[d]++;
        if (counts[d] < 0) return false;
    }

    for (auto x = 0; x <= radius; x++)
        if (counts[x] > 0) return false;
    return true;
}

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

    auto eccentricities = vector<int>(N);
    for (auto& x : eccentricities) cin >> x;

    cout << (solve(N, eccentricities) ? "Possible" : "Impossible") << endl;
}


Measured memory_bytes: 384
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws FileNotFoundException {

//    	File file = new File("src/in.txt");

        //コード
//    	Scanner sc = new Scanner(file);
    	Scanner sc = new Scanner(System.in);

    	String T = sc.next();

    	T = T.replace("?", "D");

    	System.out.println(T);

    }
}

Measured memory_bytes: 47916
#include <stdio.h>
#include <stdlib.h>

#define NIL -1

typedef struct _node {
	int value;
	int depth;
	int chldNum;
	int *chldHead;
} node;

typedef struct _queue {
	int top;
	int tail;
	int *ary;
} queue;

void enqueu(queue *qp, int u) {
	qp->ary[(qp->tail)++] = u;
}

int dequeu(queue *qp) {
	return qp->ary[(qp->top)++];
}

node *allocNode(int u, int k) {
	node *p = (node *)malloc(sizeof(node));
	p->value = u;
	p->depth = NIL;
	p->chldNum = k;
	p->chldHead = k > 0 ? (int *)malloc(sizeof(int) * k) : NULL;
	return p;
}

void terminate(node **top, int n) {
	int i;
	for (i = 0; i < n; i++)
		free(top[i]->chldHead);
	free(top);
}

void bfs(queue *qp, node **top) {
	int i, u, v;
	enqueu(qp, 0);
	top[0]->depth = 0;
	while (qp->top != qp->tail) {
		u = dequeu(qp);
		for (i = 0; i < top[u]->chldNum; i++) {
			v = top[u]->chldHead[i];
			if (top[v]->depth != NIL) continue;
			top[v]->depth = top[u]->depth + 1;
			enqueu(qp, v);			
		}
	}
}

int main() {
	int i, j, u, k, n, v;
	queue q;
	node **top;

	scanf("%d", &n);
	q.ary = n > 0 ? (int *)malloc(sizeof(int) * n) : NULL;
	q.top = q.tail = 0;

	top = (node **)malloc(sizeof(node *) * n);
	for (i = 0; i < n; i++) {
		scanf("%d %d", &u, &k);
		top[i] = allocNode(u, k);
		for (j = 0; j < k; j++) {
			scanf("%d", &v);
			top[i]->chldHead[j] = v - 1;
		}
	}

	bfs(&q, top);

	for (i = 0; i < n; i++)
		printf("%d %d\n", top[i]->value, top[i]->depth);

	terminate(top, n);
	free(q.ary);

	return 0;
}


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

using namespace std;
using ll = long long;

const ll MOD = 1e9 + 7;

inline void normal(ll &a) { if (a >= MOD) a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) {normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) {normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) {normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; } //if MOD is prime, modPow(b, p % (MOD-1))
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }


const int mx = 1e6 + 9;

ll f[mx];

ll ncr(ll n, ll r) {
    return modDiv(f[n], modMul(f[r], f[n - r]));
}

ll total_path(ll r, ll c) {
    return ncr(r + c - 2, r - 1);
}

int main() {
    f[0] = 1;
    for (int i = 1; i < mx; i++) f[i] = modMul(i, f[i - 1]);
    ll h, w, a, b; cin >> h >> w >> a >> b;
    ll ttl = 0;

    for (ll i = 1; i <= h - a; i++) {
        ll temp = modMul(total_path(i, b), total_path(h - i + 1, w - b));
        ttl = modAdd(ttl, temp);
    }

    cout << ttl << endl;
}


Measured memory_bytes: 11460