akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
	static final int MAX = 2_147_483_646; // intMax 
	static final int INF = 1_000_000_000; // 10^9  
	public static void main(String[] args) throws Exception{
		hayami saori = new hayami();
		int n = saori.saori_hayami();
		int a = saori.saori_hayami();
		int b = saori.saori_hayami();
		int[] p = new int[n];
		for(int i = 0;i < n;i++){
			p[i] = saori.saori_hayami();
		} 
		int num1 = 0;
        int num2 = 0;
        int num3 = 0;
        for(int i = 0; i < n; i++){
            if(p[i] <= a){
				num1++;
			} else if(p[i] <= b){
				num2++;
			} else{
				num3++;
			}

        }
        System.out.println(Math.min(Math.min(num1, num2), num3));
		saori.close();
	}
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}


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

#define   ll    long long int

ll n, k;
ll ara[300005];
ll pw[66];
ll mod = 1000000007;
ll cnt[66];

int main( )
{
    ll i, j, k, s = 0;
    pw[0]= 1;
    for (i = 1; i <= 62; i++)
        pw[i] = (pw[i - 1] * 2) % mod;
    cin >> n;
    for (i = 1; i <= n; i++)
        cin >> ara[i];
    for (j = 0; j <= 61; j++)
        if ( (ara[1] & (1LL << j)) != 0 )
            cnt[j]++;
    for (i = 2; i <= n; i++)
    {
        for (j = 0; j <= 61; j++)
        {
            if ( (ara[i] & (1LL << j)) != 0 )
            {
                s = (s + pw[j] * (i - 1 - cnt[j])) % mod;
                cnt[j]++;
            }
            else
                s = (s + pw[j] * cnt[j]) % mod;
        }

    }
    cout << s << '\n';
    return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
 
int main() {
  unsigned long long n;
  cin >> n;
  
  if(n==2){cout << 1 << endl;
          return 0;}
  
  /////////////////
  int k=0;
  for(int i=0;i<n/2+1;i++){
    if(-k+n%(k+1)>k)k=-k+n%(k+1);
  }
  /////////////////
  
  unsigned long long ans=n*(n-1)/2;
  
  ans -= k;
  ans -= n/(n+1);
  ans += n%(k+1);
  
  /////////////////////
  
  cout << ans << endl;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i ,n) for(int i = 0 ; i < (n) ; i ++ )
#define all(x) (x).begin(),(x).end()
using ll = long long;
using namespace std;

int main() {
  ll a,b,c,d;
  cin>>a>>b>>c>>d;
  ll ans=0;
  /////////////////
  ll x,y,z,g;
  x=(b/c-a/c);
  y=b/d-a/d;
  g=c*d/__gcd(c,d);
 // gは最小公倍数
  z=b/g-a/g;
  ans=b-a+1-(x+y-z);
  
  
  
  if(a%c==0  ){
    ans--;
  }
  if(a%d==0) ans--;
  if(a%g==0){
    ans++;
  }
  
  
  
  
  cout<<ans<<endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
A = []
for _ in range(n):
    A.append(int(input()))
A.sort()
ans = 100000000000
for i in range(n - k + 1):
    min_ = A[i]
    max_ = A[i + k - 1]
    if max_ - min_ < ans:
        ans = max_ - min_
print(ans)

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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define mp make_pair
#define ll long long
#define all(x) x.begin(), x.end()
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 2010
#define inf 1e14
#define MOD 1000000007

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

int main()

{

    ll a, b, k;
    set<ll > v;
    cin >> a >> b >> k;
    for(ll i = 0; i < k; i++)
    {

        ll z = a+i;
        if(z >= a && z <= b) v.insert(z);
    }
    for(ll i = 0; i < k; i++)
    {

        ll z = b-i;
        if(z >= a && z <= b) v.insert(z);
    }
    set<ll> :: iterator it;
    for(it = v.begin(); it != v.end(); it++) cout << *it << endl;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
A = []
for i in range(N):
    a, b = map(int, input().split())
    A.append((a, b))

A = sorted(A, key=lambda x: x[0])
money = 0
i = 0
while M > 0 and i < len(A):
    if M >= A[i][1]:
        M -= A[i][1]
        money += A[i][1] * A[i][0]
        i += 1
    else:
        money += M * A[i][0]
        i += 1
        M -= M
print(money)

Measured memory_bytes: 18948
import java.io.*;
public class Main{
	public static void main(String[]args)throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String str=br.readLine();
		String[]scoreAstr=str.split(" ");
		str=br.readLine();
		String[]scoreBstr=str.split(" ");
		int[]scoreA=new int[4];
		int[]scoreB=new int[4];
		for(int i=0;i<4;i++){
			scoreA[i]=Integer.parseInt(scoreAstr[i]);
			scoreB[i]=Integer.parseInt(scoreBstr[i]);
		}
		int tscoreA=0;
		int tscoreB=0;
		for(int score:scoreA)
			tscoreA+=score;
		for(int score:scoreB)
			tscoreB+=score;
		if(tscoreA<tscoreB)
			System.out.println(tscoreB);
		else
			System.out.println(tscoreA);
	}
}

Measured memory_bytes: 24220
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int N = 0;
		int X = 0;
		int Y = 0;
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		X = sc.nextInt()-1;
		Y = sc.nextInt()-1;
		int i, j;
		int A[] = new int[N - 1];
		for (i = 0; i < N - 1; i++) {
			for (j = i + 1; j < N; j++) {
				int a = j - i;
				int b = Math.abs(X - i) + 1 + Math.abs(Y - j);
				A[Math.min(a, b)-1]++;
			}
		}
		for (i = 0; i < N - 1; i++) {
			System.out.println(A[i]);
		}
		sc.close();

	}

}


Measured memory_bytes: 24276
from collections import deque


def solve(N, UVWs):
    vertexes = {}

    for u, v, w in UVWs:
        vertexes.setdefault(u, []).append((v, w % 2))
        vertexes.setdefault(v, []).append((u, w % 2))

    colors = [-1 for _ in range(N + 1)]
    colors[1] = 0
    que = deque()
    que.append((1, colors[1]))
    while que:
        u, c = que.popleft()
        for v, w in vertexes[u]:
            if colors[v] == -1:
                colors[v] = (c + w) % 2
                que.append((v, colors[v]))
    return "\n".join(str(c) for c in colors[1:])


if __name__ == "__main__":
    N = int(input())
    UVWs = [tuple(map(int, input().split(" "))) for _ in range(N - 1)]
    print(solve(N, UVWs))


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

int main(){
  ll i,j,cnt;
  ll n,m;
  cin>>n>>m;
  ll prod=1;
  if(max(n-m,m-n)>=2){
    cout<<0;
    return 0;
  }
  for(i=1;i<=min(n,m);i++){
    prod=(((prod*i)%1000000007)*i)%1000000007;
  }
  if(n==m){
    cout<<(2*prod)%1000000007;
  }else if(n>m)cout<<(n*prod)%1000000007;
  else cout<<(m*prod)%1000000007;
}

Measured memory_bytes: 256
#include <cstring>
#include <algorithm>
#include <cstdio>

const int N = 200010;
const int M = 1000010;
const int K = M/2;
int _w;

int n, k, p, st;
char s[M];

void solve() {
	if( s[p] - st == 'A' ) {
		s[p] = 131 - s[p];
	} else {
		st ^= 1;
		s[p+n] = st ? 'B' : 'A';
		++p;
	}
}

int main() {
	_w = scanf( "%d%d%s", &n, &k, s );
	if( k <= K ) {
		while( k-- ) solve();
		for( int i = 0; i < n; ++i )
			putchar( st ? 131 - s[p+i] : s[p+i] );
		puts("");
	} else {
		for( int i = 0; i < K; ++i ) solve();
		k -= K;
		if( n % 2 && k % 2 ) s[p] = 131 - s[p];
		for( int i = 0; i < n; ++i )
			putchar( st ? 131 - s[p+i] : s[p+i] );
		puts("");
	}
	return 0;
}


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

struct Node{
  int key;
  struct Node *right;
  struct Node *left;
  struct Node *parent;
};
typedef struct Node * node;
#define NIL NULL

node root;

node find(node u,int k){
  while(u!=NIL && k!=u->key){
    if(k<u->key) u = u->left;
    else u=u->right;
  }
  return u;
}

void insert(int k){
  node y = NIL;
  node x = root;
  node z;

  z = malloc(sizeof(struct Node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key){
      x=x->left;
    }else {
      x = x->right;
    }
  }
  z->parent = y;
  if(y == NIL){
    root = z;
  }else if(z->key<y->key){
    y->left=z;
  }else(y->right = z);
}

void inorder(node u){
  if(u==NIL) return;

  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}

int main(){
  int n,i,x;
  node t;
  char com[30];

  scanf("%d", &n);

  for(i=0;i<n;i++){
    scanf("%s",com);
    if(com[0] =='f'){
      scanf("%d",&x);
      node t = find(root, x);
      if(t != NIL)printf("yes\n");
      else printf("no\n");
    }

    if(com[0] == 'i'){
      scanf("%d",&x);
      insert(x);
    }
    else if(com[0] == 'p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}



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

int mas[300];
int memo[300];
int isGorl[300];

int Max;
int n;

void dfs(int i){
  if(i < 0) i = 0;
  if(i >= n) i = n-1;
  if(memo[i] != 0) return;
  memo[i] = 1;
  for(int j = 1;j <= Max;j++){
    int tmp = i+j;
    if(i+j < n) tmp += mas[i+j];
    dfs(tmp);
  }

  return;
}

bool flag;

void gorldfs(int i){
  if(i < 0) i = 0;
  if(i >= n) i = n-1;
  if(memo[i] != 0) return;
  if(isGorl[i] == 0){
    flag = true;
  }
  memo[i] = 1;
  for(int j = 1;j <= Max;j++){
    int tmp = i+j;
    if(tmp < n) tmp += mas[tmp];
    gorldfs(tmp);
  }

  return;
}

int main(){
  while(1){
    flag = false;

    cin >> Max;
    if(Max == 0) break;
    cin >> n;
    for(int i = 0;i < n;i++) scanf("%d",&mas[i+1]);
    n += 2;

    int i;
    for(i = n-1;i >= 0;i--){
      for(int x = 0;x < 300;x++) memo[x] = 0;
      dfs(i);
      if(memo[n-1] == 1){
        isGorl[i] = 1;
      }else{
        isGorl[i] = 0;
      }
    }

    for(int x = 0;x < 300;x++) memo[x] = 0;
    gorldfs(0);
    if(flag) cout << "NG" << endl; else cout << "OK" << endl;
  }



  return 0;
}



Measured memory_bytes: 3144
fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let n: usize = s.trim().parse().unwrap();
    let mut x: usize = 1;
    let c = 10usize.pow(9)+7;
    for i in 1..n+1 {
        x *= i;
        if x > c {x = x % c;}
    }
    println!("{}", x);
}



Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
class Program
{

    static void Main()
    {
        string[] ABC = Console.ReadLine().Split(' ');
        int A = int.Parse(ABC[0]);
        int B = int.Parse(ABC[1]);
        int C = int.Parse(ABC[2]);

        int K = int.Parse(Console.ReadLine());

        for(int i=0;i<K;i++)
        {
            if (A < B && B < C)
            {
                
            }
            else
            {
                if (C <= B || C <= A)
                {
                    C = C * 2;
                }
                else if (C > B && B <= A)
                {
                    B = B * 2;
                }
                else if (C > A && B > A)
                {
                    A = A * 2;
                }
            }
        }

        //Console.WriteLine(A);
        //Console.WriteLine(B);
        //Console.WriteLine(C);

        if (A<B&&B<C)
        {
            Console.WriteLine("Yes");
        }
        else
        {
            Console.WriteLine("No");
        }

    }

}



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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    vector<int> x(5);
    for (int i = 0; i < 5; ++i) {
        cin >> x[i];

        if (x[i] == 0) {
            cout << i + 1 << endl;
            return 0;
        }
    }
}

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

using namespace std;

#define int long long




void solve() {
    int h, w,n;
    cin >> h >> w >> n;
    int ans;
    map<pair<int,int>, int> grid;
    vector<int> mnused(h + 1, 1e9);
    mnused[h] = 0;
    for (int i = 0; i < n; ++ i) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        grid[{x, y}] = 1;
        mnused[x] = min (mnused[x], y);
    }
    int  y = 0;
    for (int i = 0; i < h; ++ i) {
        if (mnused[i+ 1] <= y) {
            cout << i + 1;
            return;
        }
        else if (grid.count({i + 1, y + 1}) == 0) {
            y++;
        }
    }
}

signed main() {
    //freopen
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
}

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

int main() {
  long int A, V, B, W, T;
  cin >> A >> V;
  cin >> B >> W;
  cin >> T;

  long int dis, ido, ans;

  dis = A - B;
  dis = abs(dis);

  ido = V - W;

  if (ido <= 0){
    cout << "NO" << endl;
    //cout << "---" << endl;
    return 0;
  }

  ans = dis - (ido * T);

  //cout << ans << endl;
  
  if (ans <= 0){
    cout << "YES" << endl;
    return 0;
  }

  cout << "NO" << endl;

}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;

vector<int> fact;
vector<int> ifact;
vector<int> inv;
vector<int> pow2;
const int MOD = (1e9 + 7);
int add(int a, int b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
	return a;
}
int mult(int a, int b)
{
	return (a*1LL*b)%MOD;
}
int modpow(int a, int b)
{
	int r=1;
	while(b)
	{
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}
int choose(int a, int b)
{
	if(a<b) return 0;
	if(b==0) return 1;
	if(a==b) return 1;
	return mult(fact[a],mult(ifact[b],ifact[a-b]));
}
int inverse(int a)
{
	return modpow(a,MOD-2);
}
void init(int _n)
{
	fact.clear(); ifact.clear(); inv.clear(); pow2.clear();
	fact.resize(_n+1);
	ifact.resize(_n+1);
	inv.resize(_n+1);
	pow2.resize(_n+1);
	pow2[0]=1;
	ifact[0]=1;
	fact[0]=1;
	for(int i=1;i<=_n;i++)
	{
		pow2[i]=add(pow2[i-1],pow2[i-1]);
		fact[i]=mult(fact[i-1],i);
		//ifact[i]=mult(ifact[i-1],inv[i]);
	}
	ifact[_n] = inverse(fact[_n]);
	for(int i=_n-1;i>=1;i--)
	{
		ifact[i] = mult(ifact[i + 1], i + 1);
	}
	for(int i=1;i<=_n;i++)
	{
		inv[i] = mult(fact[i-1],ifact[i]);
	}
}
	
int a[33];
int dp[17][(1<<16)+14];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	init((1<<17)+111);
	int n,m; cin>>n>>m;
	for(int i=0;i<m;i++) 
	{
		cin>>a[i]; a[i]--;
	}
	sort(a,a+m); reverse(a,a+m);
	int ans = 0;
	dp[0][0]=1;
	for(int i=0;i<m;i++)
	{
		for(int j=0;j<(1<<n);j++)
		{
			int v=dp[i][j]; if(v==0) continue;
			int rem = (1<<n) - a[i] - j; //# of remaining ones including a[i]
			//cerr<<i<<' '<<j<<' '<<v<<' '<<rem<<'\n';
			if(rem<0) continue;
			dp[i+1][j]=add(dp[i+1][j],v);
			for(int k=0;k<n;k++)
			{
				if(!(j&(1<<k)))
				{
					dp[i+1][j^(1<<k)] = add(dp[i+1][j^(1<<k)], mult(mult(choose(rem-1,(1<<(k))-1),fact[(1<<(k))]),v));
				}
			}
		}
	}
	for(int i=0;i<(1<<(n));i++)
	{
		int v=1;
		int lef=(1<<n)-1;
		lef-=i;
		if(lef<0) continue;
		//cerr<<i<<' '<<dp[m][i]<<' '<<lef<<'\n';
		v=mult(v,fact[lef]);
		v=mult(v,dp[m][i]);
		if(__builtin_popcount(i)&1) ans=add(ans,MOD-v);
		else ans=add(ans,v);
	}
	ans=mult(ans,pow2[n]);
	cout<<ans<<'\n';
}


Measured memory_bytes: 5888
#include<bits/stdc++.h>
#include<utility>
using namespace std;
int main () {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>>wa(M);
  for (int i = 0; i < M; i ++) {
    int a, b;
    cin >> a >> b;
    wa[i] = make_pair(b, a);
  }
  int ans = 0;
  sort(wa.begin(), wa.end());
  int min = -1;
  for (int i = 0; i < M; i ++) {
    if (min <= wa[i].second) {
      ans ++;
      min = wa[i].first;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<utility>
#include<tuple>
 
// North, west, south, east
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
 
int main(void){
    int h, w;
    std::cin >> h >> w;
 
    int countAll = h * w;
    int countOriginalBlack = 0;
 
    std::vector<std::vector<char>> board(h, std::vector<char>(w));
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            std::cin >> board[i][j];
            if(board[i][j] == '#') countOriginalBlack++;
        }
    }
 
    int sx = 0;
    int sy = 0;
    int gx = h - 1;
    int gy = w - 1;
 
    std::queue<std::pair<int,int>> que;
 
    // //11/08/2019 added: to record the distance from the start 
    std::vector<std::vector<int>> distance(h, std::vector<int>(w));
 
    // //11/08/2019 added: not to  check the position already visited 
    std::vector<std::vector<int>> dualcheck(h, std::vector<int>(w));
 
    //the distance from the start to the start must be 0
    distance[sx][sy] = 0;
    dualcheck[sx][sy]++;
 
    //push the Coordinate 
    que.push({sx, sy});
 
    while(que.size()){
        int x, y;
        std::tie(x,y) = que.front();
 
        //after completing addition to the tie, que.front must be deleted
        que.pop();
        for(int i = 0; i < 4; i++){
 
            //neighborhood of the maze[y][x]
            int nx = x + dx[i];
            int ny = y + dy[i];
 
            //Outside of the maze, or the wall is inappropriate
            if(nx < 0 || nx >= h || ny < 0 || ny >= w || board[nx][ny] == '#'){
                continue;
            }
 
            //11/08/2019 added: not to count the place already visited
            if(dualcheck[nx][ny] != 0) continue;
            
            //the coordinate can be plus 1
            distance[nx][ny] = distance[x][y] + 1;
 
            //11/08/2019 added: not to count the place already visited
            dualcheck[nx][ny]++;
            que.push({nx, ny});
        }
    }
 
    int minRouteLength = distance[gx][gy];
    int ans = countAll - countOriginalBlack - minRouteLength - 1;
 
    if(!distance[gx][gy]) ans = -1;
 
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
char s[999];int cnt[26];
int main(){
    scanf("%s",s);
    for(int i=0; s[i]; i++)
    	cnt[s[i]-'a']++;
    bool flag=true;
    for(int i=0; i<26; i++){
    	if(cnt[i]%2)
    		flag=false;
    }
    puts(flag?"Yes":"No");
    
    return 0;
}


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

using namespace std;

void solve() {
    long double N, K;
    cin >> N >> K;

    long double ans;
    ans = 0;
    for (int i = 1; i <= N; i++)
    {   
        if (i < K)
        {
            ans += pow(2, 17- ceil(log2(K/i)));
        }
        else
        {
            ans += 131072;
        }
        
    }
    ans = ans / N / 131072;
    cout << fixed << setprecision(15) << ans << endl;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 3852
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n;
    cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    sort(ALL(a));
    a.erase(unique(ALL(a)), a.end());

    if((ll)a.size() == n) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;

bool compare_by_b(pair<int,string> a, pair<int,string> b) {
	if (a.first != b.first) {
		return a.first > b.first;
	}
	else {
		return a.second < b.second;
	}
}

int main()
{
	ll N;
	vector<ll> vec;
	cin >> N;
	fore(i,0,N){
		vec.push_back(0);
	}
	fore(i,0,N-1){
		ll t;
		cin >> t;
		vec[t-1]++;
	}
	fore(i,0,N){
		cout << vec[i] << endl;
	}

}

Measured memory_bytes: 4828
#include<iostream>
#include<algorithm>
#include<cstdio>
using namespace std;
long long n,a;
int main()
{
	cin>>n>>a;
	if(a>=n%500)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return(0);
}

Measured memory_bytes: 256
import collections
n = int(input())
a = list(map(int, input().split()))

counter = collections.Counter(a)
ans = 1
for k, v in counter.items():
    if k != 0:
        if v == 2:
            ans *= 2
        if v == 1:
            ans = 0
            break
print(ans % (10**9 + 7))

Measured memory_bytes: 14820
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <string>
#include <stack>
#include <set>
#include <sstream>
#include <iomanip>
#include <limits>
using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, pair<ll, ll>> PP;

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define fr first
#define sc second


int main() {
	ll n, a[200010], r[200010] = { 0 }, ans = INF2;
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
		r[i + 1] = r[i] + a[i];
	}
	for (int i = 2;i < n;i++) {
		int ng = 1, ok = i-1, mid;
		ll P, Q, R, S, pp, qq, rr, ss;
		while (ok - ng > 1) {
			mid = (ok + ng) / 2;
			if (r[i] - r[mid] >= r[mid])ng= mid;
			else ok = mid;
		}
		P = r[ok], Q = r[i] - r[ok], pp = r[ng], qq = r[i] - r[ng];
		ng = i+1, ok = n;
		while (ok - ng > 1) {
			mid = (ok + ng) / 2;
			if (r[n] - r[mid] >= r[mid] - r[i])ng = mid;
			else ok = mid;
		}
		R = r[ok] - r[i], S = r[n] - r[ok], rr = r[ng] - r[i], ss = r[n] - r[ng];
		ans = min(ans, abs(max({ P,Q,R,S }) - min({ P,Q,R,S })));
		ans = min(ans, abs(max({pp,qq,R,S }) - min({pp,qq,R,S })));
		ans = min(ans, abs(max({ P,Q,rr,ss }) - min({ P,Q,rr,ss })));
		ans = min(ans, abs(max({ pp,qq,rr,ss }) - min({ pp,qq,rr,ss })));
		//cout << P << ' ' << Q << ' ' << R << ' ' << S << endl;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int main(){
    int H,W,N; cin >> H >> W >> N;
    int sr,sc; cin >> sr >> sc;
    sr--;
    sc--;
    string S,T; cin >> S >> T;
    bool ok = true;
    rep(i,4){
        int nowh = sr;
        int noww = sc;
        rep(j,N){
            if(i == 0){
                if(S[j] == 'D'){
                    nowh++;
                    if(nowh >= H) ok = false;
                }
                if(T[j] == 'U' && nowh-1 >= 0){
                    nowh--;
                }
            }
            else if(i == 1){
                if(S[j] == 'U'){
                    nowh--;
                    if(nowh < 0) ok = false;
                }
                if(T[j] == 'D' && nowh+1 < H){
                    nowh++;
                }
            }
            else if(i == 2){
                if(S[j] == 'R'){
                    noww++;
                    if(noww >= W) ok = false;
                }
                if(T[j] == 'L' && noww-1 >= 0){
                    noww--;
                }
            }
            else{
                if(S[j] == 'L'){
                    noww--;
                    if(noww < 0) ok = false;
                }
                if(T[j] == 'R' && noww+1 < W){
                    noww++;
                }
            }
        }
    }
    cout << (ok ? "YES" : "NO") << endl;
}


Measured memory_bytes: 776
N = gets.to_i

a = N.times.map{gets.to_i}
a.unshift(0) #1-indexed

i = 1
count = 0

N.times do |n|
  if a[i] == 2
    count += 1
    puts count
    exit
  else
    count += 1
    i = a[i]
  end
end

puts -1


Measured memory_bytes: 3252
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
typedef long long int ll;
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//B
	ll K;
	string s;
	cin>>K>>s;
	if(s.size()<=K){
		cout<<s;
	}
	else{
		s=s.substr(0,K);
		cout<<s<<"...";
	}
	return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;

int main(){
  
  int n,m;
  cin>>n>>m;
  
  vector<string>s(n);
  
  for(int i=0;i<n;i++)
    cin>>s[i];
  
  vector<vector<long long>>dp(n);
  
  for(int i = 0;i<n;i++)
    dp[i] = vector<long long>(m,0);
    
  dp[0][0] = 1;
  
  for(int i=0;i<n;i++){
      for(int j=0;j<m;j++){
          if(s[i][j] == '#'){
              continue;
          }
          if(i-1>=0)
            dp[i][j] += dp[i-1][j];
          if(j-1>=0)
            dp[i][j] += dp[i][j-1];
          dp[i][j]%=mod;
      }
  }
  cout<<dp[n-1][m-1];
}

Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
int a[200005];
int tag[200005];
bool incircle[200005];
bool vis[200005];
int val[200005];
struct edge
{
    int y;
    edge * next;
};
edge * li[200005];
edge * new_edge()
{
    static edge a[200005];
    static int top=0;
    return &a[top++];
}
void insert_edge(int x,int y)
{
    edge * t=new_edge();
    t->y=y;
    t->next=li[x];
    li[x]=t;
}
bool tags[200005];
void dfs(int x)
{
    if (vis[x]) return;
    vis[x]=true;
    edge * t;
    for (t=li[x];t!=0;t=t->next)
    {
        if (incircle[t->y]) continue;
        dfs(t->y);
    }
    if (incircle[x]) return;
    for (t=li[x];t!=0;t=t->next)
    {
        if (incircle[t->y]) continue;
        tags[val[t->y]]=true;
    }
    int i;
    for (i=0;;i++)
    {
        if (tags[i]) continue;
        break;
    }
    val[x]=i;
    for (t=li[x];t!=0;t=t->next)
    {
        if (incircle[t->y]) continue;
        tags[val[t->y]]=false;
    }
}
int main()
{
    int n;
    scanf("%d",&n);
    int i;
    for (i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        a[i]--;
        insert_edge(a[i],i);
    }
    int now=0;
    for (i=0;i<n;i++)
    {
        now=a[now];
    }
    for (i=0;i<n;i++)
    {
        incircle[now]=true;
        now=a[now];
    }
    for (i=0;i<n;i++)
    {
        if (vis[now]) break;
        dfs(now);
        now=a[now];
    }
    int j;
    for (j=0;j<=25;j++)
    {
        edge * t;
        for (t=li[now];t!=0;t=t->next)
        {
            if (incircle[t->y])
            {
                continue;
            }
            if (val[t->y]==j)
            {
                //Error!
                break;
            }
        }
        if (t!=0) continue;
        val[now]=j;
        int x;
        for (x=a[now];x!=now;x=a[x])
        {
            for (t=li[x];t!=0;t=t->next)
            {
                tags[val[t->y]]=true;
            }
            int i;
            for (i=0;;i++)
            {
                if (tags[i]) continue;
                break;
            }
            val[x]=i;
            for (t=li[x];t!=0;t=t->next)
            {
                tags[val[t->y]]=false;
            }
        }
        for (t=li[x];t!=0;t=t->next)
        {
            tags[val[t->y]]=true;
        }
        int i;
        for (i=0;;i++)
        {
            if (tags[i]) continue;
            break;
        }
        if (i==val[now])
        {
            puts("POSSIBLE");
            return 0;
        }
        for (t=li[x];t!=0;t=t->next)
        {
            tags[val[t->y]]=false;
        }
    }
    puts("IMPOSSIBLE");
    return 0;
} 

Measured memory_bytes: 7552
import sys
import itertools
import math

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

while 1:
    H, W = map(int, readline().split())
    if H == 0 and W == 0:
        break
    else:
        for _ in range(H):
            Y = '#' * W
            print(Y)
    print()



Measured memory_bytes: 5712
INF = 10 ** 9
H, W = map(int, input().split())
s = [list(input()) for _ in range(H)]
dp = [[INF for _ in range(W)] for _ in range(H)]
if s[0][0] == '#':
    dp[0][0] = 1
else:
    dp[0][0] = 0

for i in range(H):
    for j in range(W):
        if j != 0:
            cnt = 0
            if s[i][j] == '#' and s[i][j - 1] == '.':
                cnt += 1
            dp[i][j] = min(dp[i][j], dp[i][j - 1] + cnt)

        if i != 0:
            cnt = 0
            if s[i][j] == '#' and s[i - 1][j] == '.':
                cnt += 1
            dp[i][j] = min(dp[i][j], dp[i - 1][j] + cnt)

print(dp[-1][-1])

Measured memory_bytes: 3316
N,M,Q = map(int,input().split())
A = [list(map(int,input().split())) for _ in range(Q)]
def dfs(s):
    if len(s) == N:
        return[s]
    result = []
    if s == '':
        num = 0
    else:
        num = int(s[-1])
    for i in range(num,M):
        result.extend(dfs(s+str(i)))
    return result
ans = 0
S = dfs('')
for s in S:
    C = [int(i)+1 for i in s]
    B = 0
    for a,b,c,d in A:
        if C[b-1] - C[a-1] == c:
            B += d
    ans = max(ans,B)
print(ans)

Measured memory_bytes: 82448
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    X=int(input())
    s=0
    for i in range(10**7):
        s+=i
        if s>=X:
            print(i)
            exit()

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
S, T = read().decode('utf-8').rstrip().split()

A = [None] * (N+N)
A[::2] = S
A[1::2] = T

ans = ''.join(A)
print(ans)

Measured memory_bytes: 9084
n = int(input())
num = [[0]*10 for _ in range(10)]
ans = 0
for i in range(1,n+1):
  c = list(str(i))
  t,b = int(c[0]),int(c[-1])
  num[t][b] += 1
for i in range(1,10):
  for j in range(1,10):
    ans += num[i][j]*num[j][i]
print(ans)
  
  

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

vector<int> prim;
bool p[1001]={0};
void prim_func(){
  for(int i=0;i<1001;i++)
    p[i]=true;
  p[0]=p[1]=false;
  for(int i=2;i*i<=1000;i++){
    for(int j=i*2;j<=1000;j+=i){
      p[j]=false;
    }
  }
  for(int i=0;i<=1000;i++){
    if(p[i])
      prim.push_back(i);
  }
}
int main (){
  int n;
  cin >> n;
  int num[1001]={0};
  prim_func();
  for(int i=1;i<=n;i++){
    int t=i;
    for(int j=0;j<prim.size();j++){
      while(1){
        if(t%prim[j]==0){
          t/=prim[j];
          num[prim[j]]++;
        }else{
          break;
        }
      }
    }
  }
  long long ans=1;
  for(int i=0;i<=1000;i++){
    ans*=(num[i]+1);
    ans%=1000000007;
  }
  cout<<ans<<endl;
  return 0;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------



int main()
{
    int x,y;
    scanf("%d%d\n",&x,&y);
    printf("%d\n",x+y/2 );

}


Measured memory_bytes: 256
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll>P;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll cmp(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------
long long modpow(long long a, long long n) {//a^n(MOD)を求める
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;//次の準備
        n >>= 1;
    }
    return res;
}
//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    ll n;cin>>n;
    vector<ll>a(n);
    for(int i=0;i<n;i++)cin>>a[i];
    vector<ll> zero(60,0);
    vector<ll> one(60,0);
    for(int i=0;i<n;i++){
        ll cnt=0;
        while(a[i]){
            if(a[i]%2==1)one[cnt]++;
            cnt++;
            a[i]/=2;
        }
    }
    for(int i=0;i<60;i++)
        zero[i]=n-one[i];
    ll ans=0;
    for(int i=0;i<60;i++){
        ll c=zero[i]*one[i];
        c%=MOD;
        ans+=modpow(2,i)*c%MOD;
        ans%=MOD;
    }
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

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

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

namespace detail {
template <typename T, std::size_t NDIMS>
struct vector_builder {
  using type = std::vector<typename vector_builder<T, NDIMS - 1>::type>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    const auto vec = std::vector<T>(dims.empty() ? 0 : dims.back(), v);
    if (!dims.empty()) dims.pop_back();
    return vector_builder<std::vector<T>, NDIMS - 1>::make(dims, vec);
  }
};

template <typename T>
struct vector_builder<T, 1> {
  using type = std::vector<T>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    return type(dims.empty() ? 0 : dims.back(), v);
  }
};
}  // namespace detail

template <typename T, typename... SIZE_T>
auto exvector(const T& v, SIZE_T... dims) {
  static_assert(sizeof...(dims) != 0, "invalid dimension");
  std::vector<std::size_t> vec_dims{dims...};
  return detail::vector_builder<T, sizeof...(dims)>::make(vec_dims, v);
}

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T& data, vector<int>& iter) {
  cout << data << " ";
}
template <typename T>
void dump(const vector<T>& data, vector<int>& iter) {
  for (auto elem : data) dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>>& data, vector<int>& iter) {
  for (auto elem : iter) {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++) {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T>& data, int dummy) {
  for (int i = 0; i < data.size(); i++) {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T& data) {  // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

void solve(long long N, long long M, std::vector<long long> X) {
  sort(X.begin(), X.end());
  vector<LL> diff;
  adjacent_difference(X.begin(), X.end(), back_inserter(diff));
  sort(diff.begin() + 1, diff.end());
  LL ans =

      accumulate(diff.begin() + 1, diff.begin() + max(0LL, M - N) + 1, 0LL);
  cout << ans << endl;
}

int main() {
  cout << setprecision(10);
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> X(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &X[i]);
  }
  solve(N, M, std::move(X));
  return 0;
}


Measured memory_bytes: 2168
[l,r] = [int(i) for i in input().split()]

ans = 2019


for i in range(l,r):
	for j in range(i+1,r+1):
		rem = i*j%2019
		if rem < ans:
			ans = rem
		if ans == 0:
			break
			
	if ans == 0:
		break
				
print(ans)	

Measured memory_bytes: 3060
#pragma GCC optimize ("Ofast")
#include <iostream>
#include <cmath>
 
inline void fastscan(int &num) {
    bool neg = false;
    int c;
    num = 0;
    c = getchar_unlocked();
    if (c == '-') {
        neg = true;
        c = getchar_unlocked();
    }
    for (; (c > 47 && c < 58); c = getchar_unlocked()) num = num * 10 + c - 48;
    if (neg) num *= -1;
}
 
inline void fastout(int n) {
    int N = n, rev, count = 0;
    rev = N;
    if (N == 0) { putchar_unlocked('0'); putchar_unlocked('\n'); return ;}
    while ((rev % 10) == 0) { ++count; rev /= 10;}
    rev = 0;
    while (N != 0) { rev = (rev<<3) + (rev<<1) + N % 10; N /= 10;}
    while (rev != 0) { putchar_unlocked(rev % 10 + '0'); rev /= 10;}
    while (count--) putchar_unlocked('0');
}
 
int main(){
    
    int N; fastscan(N);
    int v[N];
    for (int i = 0; i < N; ++i) fastscan(v[i]);
    int sum = 0;
 
    for (int i = 1; i < N; ++i) sum += abs(v[i - 1] - v[i]);
    sum += abs(0 - v[0]) + abs(v[N - 1]);
    int diff[N]; 
    diff[0] = abs(0 - v[0]) + abs(v[0] - v[1]) - abs(0 - v[1]);
    for (int i = 1; i < N - 1; ++i){
        diff[i] = abs(v[i - 1] - v[i]) + abs(v[i] - v[i + 1]) - abs(v[i - 1] - v[i + 1]);
    }
    diff[N - 1] = abs(v[N - 2] - v[N - 1]) + abs(v[N - 1]) - abs(v[N - 2]);
 
    for (int i = 0; i < N; ++i){
        fastout(sum - diff[i]); putchar_unlocked('\n');
    }
    return 0;
}

Measured memory_bytes: 2048
#include <iostream>

using namespace std;

int main() {
  int N, T;
  cin >> N >> T;
  int cost = 10001;
  for (int n = 0; n < N; ++n) {
    int c, t;
    cin >> c >> t;
    if (t <= T) {
      cost = min(cost, c);
    }
  }
  if (cost <= 1000) {
    cout << cost << endl;
  } else {
    cout << "TLE" << endl;
  }

  return 0;
}


Measured memory_bytes: 3664
#include <cstdio>
#include <vector>

const int MOD=1e9+7;

std::vector<int> edges[100005];
int dp[100005][2];

void mulmod(int& x,int y){
  x=1LL*x*y%MOD;
}

void dfs(int node,int parent){
  dp[node][0]=1;
  dp[node][1]=1;
  for(int child:edges[node]){
    if(child==parent) continue;
    dfs(child,node);
    mulmod(dp[node][0],dp[child][0]+dp[child][1]);
    mulmod(dp[node][1],dp[child][0]);
  }
}


int main(){
  int N;
  scanf("%d",&N);
  for(int i=0;i<N-1;i++){
    int X,Y;
    scanf("%d %d",&X,&Y);
    X--,Y--;
    edges[X].push_back(Y);
    edges[Y].push_back(X);
  }
  dfs(0,0);
  printf("%d\n",(dp[0][0]+dp[0][1])%MOD);
  return 0;
}


Measured memory_bytes: 13440
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    public static void exec(InputStream in, PrintStream out){
        Scanner sc = new Scanner(in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int n = Math.max(a,b);
        int m = Math.min(a,b);
        StringBuffer sb = new StringBuffer();
        for (int i = 0; i < n; i++) {
            sb.append(m);
        }
        out.println(sb.toString());
    }

    public static void main(String[] args) {
        exec(System.in, System.out);
    }
}

Measured memory_bytes: 21588
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <cstring>
#include <cctype>
#include <sstream>
#include <set>
#include <map>
#include <queue>
#include <complex>
using namespace std;

int main() {
	int n, y, m, d;
	int mil=0;
	mil += 200 * 333;
	mil += 390/2 * 666;
	cin >> n;
	for(int i=0; i<n; i++) {
		cin >> y >> m >> d;
		int cnt = 0;
		cnt += (y-1)/3 * 200;
		cnt += (y-(y-1)/3-1) * 390/2;
		for(int j=1; j<=m; j++) {
			if(j==m) cnt += d-1;
			else if(y%3==0)
				cnt += 20;
			else {
				if(j%2==1) cnt += 20;
				else cnt += 19;
			}
		}
	cout << mil - cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>
using std::cout;
using std::cin;
using std::endl;

void Cube(int x) {
    int res = 1;
    for (int i = 0; i < 3; i++) {
        res *= x;
    }
    cout << res << endl;
}

int main() {
    int x = 0;
    cin >> x;
    Cube(x);
    return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(0); 
    cin.tie(0);   
	ll n,a[200009],m,k,ans=0,fl=0;
	string s;
	cin>>n>>m>>k;
	if(m*k>=n)
		cout<<"Yes\n";
	else
		cout<<"No\n";
	return 0;
}

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

int main(){
  ll n, a, b;
  cin >> n >> a >> b;
  if((b-a)%2 == 0){
    cout << (b-a)/2 << endl;
    return 0;
  }
  else if(b-a == 1){
    cout << min(n-a,b-1) << endl;
    return 0;
  }
  else{
    cout << min((n-b+n-a+1)/2,(b-1+a-1+1)/2) << endl;
  }
}

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

int main() {
    int n,k;
    cin>>n>>k;
    vector <int> vec (n,0);
    vector <int> dp(k+1,0);
    for(int i=0;i<n;i++)cin>>vec[i];
    for(int i=1;i<=k;i++){
        int key=0;
     for(int j=0;j<n;j++){
         int ind=i-vec[j];
         if(ind>=0&&dp[ind]==0){key=1;break;}
     }
        if(key==1)dp[i]=1;
    }
    if(dp[k]==0)cout<<"Second"<<endl;
    else cout<<"First"<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define itn int
#define REP(i,n) for(int i=0;i<(n);i++)
#define IREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(n);i++)
#define REPEACH(itr,k) for(auto&& itr : k)
#define MOD 1000000007

using namespace std;
typedef long long ll;

const ll INF = 1LL<<60;

int main(){
  int n;
  cin >> n;
  vector<vector<char>> vv(n,vector<char>(10));
  vector<string> s(n,"");
  REP(i,n){
    REP(j,10){
      cin >> vv[i][j];
    }
    sort(vv[i].begin(),vv[i].end());
    REP(j,10){
      s[i]+=vv[i][j];
    }
  }
  sort(s.begin(),s.end());
  ll tmp=1;
  string a="";
  ll ans=0;
  REP(i,n){
    if(a==s[i]){
      tmp++;
    }
    else{
      a=s[i];
      ans+=tmp*(tmp-1)/2;
      tmp=1;
    }
  }
  ans+=tmp*(tmp-1)/2;
  cout << ans << endl;
}


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

int main(){
	int N;
  	int a=0,b=0,c=0,d=0;
  cin >> N;
  rep(i, N+1){
    string test;
    getline(cin, test);
    if(test == "AC")
      a++;
    if(test == "WA")
      b++;
    if(test == "TLE")
      c++;
    if(test == "RE")
      d++;
  }
 	cout << "AC x " << a << endl; 
    cout << "WA x " << b << endl; 
    cout << "TLE x " << c << endl; 
    cout << "RE x " << d << endl; 
}


Measured memory_bytes: 3628
#include<iostream>
#include <iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<string.h>
#include<math.h>
#include<unordered_map>
#include <deque>
using namespace std;


typedef long long ll;



int main()
{
	int n;
	vector<ll> ar;

	cin >> n;
	for (int i = 0; i < n; i++) {
		ll a;
		cin >> a;
		ar.push_back(a);
	}
	sort(ar.begin(), ar.end());

	ll ai = ar[n-1], aj;
	double ha = (double)ai / 2.,t=(double)ai;
	for (int i = 0; i < n; i++) {
		double  tt = (double)ar[i] - ha;
		if (tt < 0) tt = -tt;
//		cout << tt << endl;
		if (t > tt ){
			t = tt;
			aj = ar[i];
		}
	}

	cout << ai << " " << aj << endl;


	return 0;
}

Measured memory_bytes: 1400