akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

//#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

/*
   cin.tie(0);
   ios::sync_with_stdio(false);
*/

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;


using type = long long;
using P = pair<type, type>;

struct Edge{
    int to, cost;
    Edge(int a, long long b){
        to = a;
        cost = b;
    }
};

class Dijkstra{
private:
    const type _INF = 1000000000000000;
    int V; // 頂点数
    vector<type> d;
    vector<int> prev;
    vector<vector<Edge> > G;
public:
    Dijkstra(int v){
        V = v + 1;
        d.resize(V);
        G.resize(V);
        prev.resize(V);
    }

    void shortest_path(int s){
        priority_queue<P, vector<P>, greater<P>> que;
        d.assign(V, _INF);
        prev.assign(V, -1);
        d[s] = 0;
        que.push(P(0, s));
        while(que.size()){
            P p = que.top(); que.pop();
            int v = p.second;
            if(d[v] < p.first) continue;
            for(auto e : G[v]){
                if(d[v] + e.cost < d[e.to]){
                    d[e.to] = d[v] + e.cost;
                    prev[e.to] = v;
                    que.push(P(d[e.to], e.to));
                }
            }
        }
    }

    bool is_path(int t){
        return d[t] != _INF;
    }
  
    void add_path(int from, int to, type cost){
        G[from].push_back(Edge(to, cost));
    }

    type get_cost(int t){
        return d[t];
    }

    vector<int> get_path(int t){
        vector<int> path;
        for(; t != -1; t = prev[t])
            path.push_back(t);
        reverse(path.begin(), path.end());
        return path;
    }
};

int main(){
  int v,e,r;
  cin>>v>>e>>r;
  Dijkstra dij(v);
  rep(i,e){
    int s,t,d;
    cin>>s>>t>>d;
    dij.add_path(s,t,d);
  }
  dij.shortest_path(r);
  rep(i,v){
    if(dij.is_path(i))cout<<dij.get_cost(i)<<endl;
    else cout<<"INF"<<endl;
  }
  return 0;
}



Measured memory_bytes: 14748
n,y = map(int,input().split())
for i in range(n+1):
    for l in range((n+1)-i):
        if i*10+l*5+(n-i-l) == y//1000:
            print("{} {} {}".format(i,l,n-i-l))
            exit()
print("-1 -1 -1")

Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
using namespace std;
string a[200];
int main()
{
    int n,l;
    cin >> n >> l;
    for(int i=0;i<n;i++)
        cin >> a[i];
    sort(a,a+n);
    for(int i=0;i<n;i++)
        cout << a[i];
    return 0;
}

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

int main(){
  string S, T;
  cin >> S >> T;

  int A, B;
  cin >> A >> B;

  string U;
  cin >> U;
  if(U == S){
    A--;
  }else{
    B--;
  }

  cout << A << ' ' << B << endl;
}


Measured memory_bytes: 888
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int sx = Integer.parseInt(scn.next());
		int sy = Integer.parseInt(scn.next());
		int tx = Integer.parseInt(scn.next());
		int ty = Integer.parseInt(scn.next());

		for (int i = sy; i < ty; i++) {
			System.out.print("U");
		}
		for (int i = sx; i < tx; i++) {
			System.out.print("R");
		}
		for (int i = ty; i > sy; i--) {
			System.out.print("D");
		}
		for (int i = tx; i > sx; i--) {
			System.out.print("L");
		}
		System.out.print("L");
		for (int i = sy; i < ty + 1; i++) {
			System.out.print("U");
		}
		for (int i = sx; i < tx + 1; i++) {
			System.out.print("R");
		}
		System.out.print("D");
		System.out.print("R");
		for (int i = ty; i > sy - 1; i--) {
			System.out.print("D");
		}
		for (int i = tx; i > sx - 1; i--) {
			System.out.print("L");
		}
		System.out.print("U");
		System.out.println();

	}
}

Measured memory_bytes: 24260
#include <stdio.h>
int main(void)

{
	int m,f,r;
	while(1){
		scanf("%d %d %d",&m,&f,&r);
		if(m==-1&&f==-1&&r==-1){
			break;
		}
		if(m==-1||f==-1||m+f<-30){
			printf("F\n");
		}
		else if(m+f>=80){
			printf("A\n");
		}
		else if(m+f>=65){
			printf("B\n");
		}
		else if(m+f>=50||r>=50){
			printf("C\n");
		}
		else if(m+f>=30){
			printf("D\n");
		}
		else{
			printf("F\n");
		}
	}
	return 0;
}
	


Measured memory_bytes: 2052
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<cstdio>
#include<queue>
#include<deque>
#include<map>
#include<stack>
#include<set>
#include<utility>
using namespace std;
typedef pair<int,int> ii;
typedef long long ll;
typedef pair<ll,ll> P;
typedef unsigned long long int ull;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
const int MAXN=100000;
const int MAXE=100000;
const int MAXV=10000;
const ll INF=2e18;
const ll MOD=1e9+7;


int main(){
    int H,W,D;cin>>H>>W>>D;
    int A[H][W];
    vector<int> X(H*W+1,0),Y(H*W+1,0); 
    for(int i=0;i<H;++i){
        for(int j=0;j<W;++j){
            cin>>A[i][j];
            X[A[i][j]]=i;
            Y[A[i][j]]=j;
        }
    }
    vector<int> SX(H*W+1,0),SY(H*W+1,0);
    for(int i=D+1;i<=H*W;++i){
        SX[i]=SX[i-D]+abs(X[i]-X[i-D]);
        SY[i]=SY[i-D]+abs(Y[i]-Y[i-D]);
    }
    int Q;cin>>Q;
    while(Q--){
        int L,R;cin>>L>>R;
        cout<<(SX[R]-SX[L])+(SY[R]-SY[L])<<endl;
    }
    return 0;
}

Measured memory_bytes: 5024
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define initdp(a, b)  for (int i = 0; i <= a; i++)   for (int j = 0; j <= b; j++) dp[i][j] = -1;
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define ll long long
#define pll pair<ll, ll>
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repd(i, n) for (int i = n - 1; i >= 0; i--)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
// #define N 1000005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll,ll>
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define endl "\n"
using namespace std;




void solve(){
  
  int a[3],N,ans[100010];


  char s[100010][3];

  cin>>N>>a[0]>>a[1]>>a[2];



  fo(i,1,N) {
    cin>>s[i];
  }


  int flag = 1;


  fo(i,1,N) {


    int x = s[i][0]-'A';
    int  y = s[i][1]-'A';

    if (!a[x] && !a[y]){
      flag = 0;
      break;
    }


    if (a[x] > a[y])  {
      ans[i] = y;
      a[x]--;
      a[y]++;
    }
    else if (a[x] < a[y])  {
      ans[i] = x;
      a[x]++;
      a[y]--;
    }


    else {
      int x2 = s[i+1][0] - 'A'; 
      int y2 = s[i+1][1] - 'A';

      if (x == x2 || x == y2) 
         ans[i] = x, a[x]++, a[y]--;
      else ans[i] = y, a[y]++, a[x]--;
    }



  }


  if (!flag)   {
    cout<<"No"<<endl;
  }
  else {
    cout<<"Yes"<<endl;
    for (int i=1; i<=N; i++)  {
      char x = ans[i] + 'A';
        cout<<x<<endl;
    }
  }




}
 
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<fixed<<setprecision(20);
    int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}

Measured memory_bytes: 4344
#!/usr/bin/env python3
import sys


def solve(N: int, h: "List[int]"):
    INF = 1000000000
    dp = [INF] * (N+1)
    dp[0] = 0
    dp[1] = abs(h[1] - h[0])
    for i in range(2, N):
        dp[i] = min(dp[i-1] + abs(h[i]-h[i-1]), dp[i-2] + abs(h[i] - h[i-2]))

    print(dp[N-1])
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    h = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, h)

if __name__ == '__main__':
    main()


Measured memory_bytes: 18064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.Arrays;
import java.util.Random;
public class Main 
{
    public static void main(String[] args) 
    {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(2, in, out);
        out.close();
    }

    static class TaskC 
    {
        static boolean prime(int n)
        {
            for(int i=2;i<=Math.sqrt(n);i++)
            {
                if(n%i==0)
                {
                    return false;
                }
            }
            return true;
        }

        static void reverse(long[] a,long start,long end)
        {
            long temp = 0;
            while(start<end)
            {
                temp = a[(int)start];
                a[(int)start] = a[(int)end];
                a[(int)end] = temp;
                start++;
                end--;
            }
        }


   
        
        public void solve(int testNumber, Scanner in, PrintWriter out) 
        {
            long t = in.nextLong();
            char[] s = in.next().toCharArray();
            long r=0;
            long b =0;
            for(int i=0;i<s.length;i++)
            {
                if(s[i]=='R')
                {
                    r++;
                }
                else
                {
                    b++;
                }
            }

            if(r>b)
            {
                System.out.println("Yes");
            }
            else{
                System.out.println("No");
            }
        }


      
        
        
        static long maxdiff(long[] arr,long size)
        {
            long max = arr[1]-arr[0];
            long min = arr[0];
            for(int i=1;i<(int)size;i++)
            {
                if(arr[i]-min>max)
                {
                    max = arr[i]-min;
                }
                if(arr[i]<min)
                {
                    min = arr[i];
                }

            }
            return max;
        }

                
    }

}

Measured memory_bytes: 23124
var
    n,i,x,y: Integer;
    a: array[0..100] of Integer;

procedure qsort(l,r:Longint;data:PInteger);
var
    i,j,mid,t: Integer;
begin
    if l>=r then
    begin
        exit;
    end;
    i:=l;
    j:=r;
    mid:=data[(l+r) div 2];
    repeat
        while data[i]<mid do
        begin
            inc(i);
        end;
        while data[j]>mid do
        begin
            dec(j);
        end;
        if i<=j then
        begin
            t:=data[i];
            data[i]:=data[j];
            data[j]:=t;
            inc(i);
            dec(j);
        end;
    until i>j;
    qsort(l,j,data);
    qsort(i,r,data);
end;
begin
    readln(n);
    for i := 0 to n-1 do
    begin
        read(a[i]);
    end;
    qsort(0,n-1,@a[0]);
    x:=0;
    y:=0;
    i:=n-1;
    while i>=0 do
    begin
        inc(x,a[i]);
        dec(i,2);
    end;
    i:=n-2;
    while i>=0 do
    begin
        inc(y,a[i]);
        dec(i,2);
    end;
    writeln(x-y);
    readln;
    readln;
end.

Measured memory_bytes: 128
#include<stdio.h>

int main(void){
    int rows, columns;
    scanf("%d %d",&rows,&columns);

    int a[rows][columns];
    int b[columns];
    int i,n;
    for(i=0;i<rows;i++){
        for(n=0;n<columns;n++) scanf("%d",&a[i][n]);                  
    }        
    for(i=0;i<columns;i++) scanf("%d",&b[i]);
     
    int z;
    for(i=0;i<rows;i++){
        z = 0;
        for(n=0;n<columns;n++){
            z += a[i][n]*b[n];
        }
        printf("%d\n",z);
    }
    return 0;
}


Measured memory_bytes: 2100
#include<stdio.h>
int main(){
	int i,j,ans=0;
	int combination(int n, int r); 
    scanf("%d %d",&i,&j);
	if(i>=2){
      	ans+=combination(i,2);
    }
  	if(j>=2){
      ans+=combination(j,2);
    }
  printf("%d\n",ans);
}
int combination(int n, int r)
{
    if (r == 0 || r == n)
        return (1);
    else if (r == 1)
        return (n);
    return (combination(n - 1, r - 1) + combination(n - 1, r));
} 

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    int s[102], t[102], v[102];
    int r = 0;
    for (int i = 0; i < n; i++) {
        cin >> t[i];
        s[i] = r;
        r += t[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    s[n] = 0; t[n] = 0; v[n] = 0;
    s[n + 1] = r; t[n + 1] = 0; v[n + 1] = 0;

    double u[40001];
    double a = 0;
    for (int i = 0; i <= r * 2; i++) {
        u[i] = 1e+100;
    }
    for (int i = 0; i <= r * 2; i++) {
        double c = i * 0.5;
        for (int j = 0; j < n + 2; j++) {
            double x;
            if (s[j] <= c && c <= s[j] + t[j]) x = v[j];
            else if (s[j] > c) x = (c - s[j]) * -1.0 + v[j];
            else if (c > s[j] + t[j]) x = (c - (s[j] + t[j])) * 1.0 + v[j];
            else throw;
            u[i] = min(u[i], x);
        }
    }
    for (int i = 0; i < r * 2; i++) {
        a += 0.25 * (u[i] + u[i + 1]);
        //cout << i * 0.5 << ' ' << u[i] << endl;
    }

    cout << fixed << setprecision(9) << a << endl;

    return 0;
}

Measured memory_bytes: 512
#!/usr/bin/env python3
import sys
 
 
def solve(K: int, S: int):
    cnt = 0
    for a in range(K + 1):
        for b in range(K + 1):
            tmp = S - (a + b)
            if 0 <= tmp and tmp <= K:
                cnt += 1 
    print(cnt)
    return
 
 
# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    S = int(next(tokens))  # type: int
    solve(K, S)
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import collections
n = int(input())
d = list(map(int,input().split()))
ma = max(d)
mod = 998244353

if d[0] != 0:
    print(0)
    exit()

p = [0 for i in range(ma+1)]

for i in range(n):
    p[d[i]] += 1

if p[0] != 1:
    print(0)
    exit()
else:
    ans = 1
    for i in range(1,ma+1):
        ans *= (p[i-1]**p[i])%mod
        ans %= mod
    
    print(ans)

Measured memory_bytes: 14780
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

int main() {
    int QQQ;
    cin >> QQQ;
    while(QQQ--){
        vector<u32> v(9);
        for (auto &&i : v) scanf("%x", &i);
        u32 ans = 0;
        for (int i = 0; i < 32; ++i) {
            u32 mask = (1U<<(i+1))-1;
            if(!mask) mask--;
            u32 sum = 0;
            for (int j = 0; j < 8; ++j) {
                sum += (ans^v[j]);
            }
            if((sum&mask) != ((v[8]^ans)&mask)) ans ^= (1<<i);
        }
        printf("%x\n", ans);
    }
    return 0;
}


Measured memory_bytes: 3172
h,n=map(int,input().split())
a=sorted(list(map(int,input().split())),reverse=True)
x=len(a)

if x<=n:
    if sum(a)>=h:
        print('Yes')
    else:
        print('No')
else:
    a=a[:x-n+1]
    if sum(a)>=h:
        print('Yes')
    else:
        print('No')

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

int main() {
	string S, T;
	cin >> S >> T;

	int A, B;
	cin >> A >> B;

	string U;
	cin >> U;

	if (U == S) cout << (A - 1) << " " << B;
	if (U == T) cout << A << " " << (B - 1);

	return 0;

}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2
void dfs(void);
void dfs_v(int);
int n,M[N][N];
int color[N],d[N],f[N],time;


int main(){
  int u,k,v;
  int i,j;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=0;
    }
  }

  for(i=0;i<n;i++){
    scanf(" %d%d",&u,&k);
    u-=1;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }

  dfs();
  return 0;
}

void dfs(){
  int u;
  for(u=0;u<n;u++){
    color[u]=WHITE;
  }

  time=0;


  for(u=0;u<n;u++){
    if(color[u]==WHITE)dfs_v(u);
  }


  for(u=0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}


void dfs_v(int u){
  int v;
  color[u]=GRAY;
  time+=1;
  d[u]=time;
  for(v=0;v<n;v++){
    if(M[u][v]==0)continue;
    if(color[v]==WHITE){
      dfs_v(v);
    }
  }
  color[u]=BLACK;
  time+=1;
  f[u]=time;
}

Measured memory_bytes: 636
from heapq import*
n=int(input())
a=[-int(e)for e in input().split()]
r=0
heapify(a)
while 1:
	x=heappop(a)
	if x>-n:break
	c=-x//n
	x+=c*n
	for i in range(n-1):a[i]-=c
	heappush(a,x)
	r+=c
print(r)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
using namespace std;
  
int main () {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i,n) cin >> h.at(i);
  sort(h.begin(),h.end());
  int ans=1e9;
  for(int i=0;i<n-k+1;i++) {
    int p = h.at(k+i-1) - h.at(i);
    ans = min(ans,p);
  }
  cout << ans;
}

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

/*
dp.
株は安いときにたくさん買って, 高いときにたくさん売れば利益が最大化される.
買うときは全財産をつぎ込み, 売るときは持ち株を全て売る.
dp[x]はx日目に株の売却が終了した時点での所持金の最大値.
*/

int main() {
  long long N, A[85], dp[85];
  cin >> N;
  for (int i = 1; i <= N; i++) cin >> A[i];

  dp[1] = 1000;
  for (int i = 2; i <= N; i++) {
    dp[i] = dp[i - 1];  // 今日のbase caseは昨日から何もしない場合
    for (int j = 1; j <= i - 1; j++) {
      long long stock = dp[j] / A[j];
      long long money = dp[j] + (A[i] - A[j]) * stock;  // 今日株を買って明日売った時点での所持金
      dp[i] = max(dp[i], money);  // 昨日から何もしない場合と, 株の売買をした場合を比較. 大きい方を選択
    }
  }
  cout << dp[N] << endl;
}

Measured memory_bytes: 3580
#include <cstdio>
#include <cstring>
using namespace std;

typedef int INT;
const int SIZE = 10777216;
bool HA[SIZE];

inline INT get( char c ) {
    char T[5] = "ACGT";
    for ( INT i = 0; i < 4; ++ i ) {
        if ( c == T[i] ) return i + 1;
    }
    return 0;
}

int main() {
    INT n, sum, t, c;
    while ( scanf("%d", &n) != EOF ) {
        memset( HA, false, sizeof(HA) );
        while ( getchar() != '\n' );
        for ( register INT i = 0; i < n; ++ i ) {
            sum = 0;
            t = 1;
            bool flag = getchar() == 'i';
            while ( ( c = getchar() ) != ' ' );
            while ( ( c = get( getchar() ) ) != 0 ) {
                sum += c * t;
                t *= 4;
            }
            if ( flag ) {
                HA[sum] = true;
            } else {
                puts( HA[sum] ? "yes" : "no" );
            }
        }
    }
    return 0;
}

Measured memory_bytes: 10000
n, k = map(int, input().split())
ans = 0

for i in range(k, n + 2):
    maxsum = (i*(n + (n - i + 1)))//2
    minsum = (i - 1)*i//2
    ans += (maxsum - minsum + 1)%(10**9 + 7)

print(ans%(10**9 + 7))

Measured memory_bytes: 9180
from sys import stdin


def main():
    _in = [_.rstrip() for _ in stdin.readlines()]
    X, Y = list(map(int, _in[0].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    ans = 'No'
    for x in range(0,101):
        for y in range(0,101):
            if x+y==X and 2*x+4*y==Y:
                ans = 'Yes'
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 62948
#include <cstdio>
#include <algorithm>
typedef long long ll;
using namespace std;

int main() {
	ll n; scanf("%lld", &n);
	ll A[n]; for (ll i = 0; i < n; ++i) scanf("%lld", &A[i]);

	ll first_sum = A[0], first_idx = 0;
	ll second_sum = A[n - 1], second_idx = n - 1;

	while (second_idx - first_idx != 1) {
		if (first_sum <= second_sum) {
			++first_idx;
			first_sum += A[first_idx];
		}
		else {
			--second_idx;
			second_sum += A[second_idx];
		}
	}

	printf("%lld\n", abs(first_sum - second_sum));
	return 0;
}

Measured memory_bytes: 1664
#include<stdio.h>

main(){
  int x=0, y=0, z=0;
  scanf("%d%d",&x ,&y);
  while(1){
    if(x % y == 0){
      break;
    }
     if(x >= y){
       z = x % y;
       x = y;
       y = z;
       continue;
     }
     if(x < y){
      z = x;
      x = y;
      y = z;
      continue;
     }
  }
  printf("%d\n",y);
  return 0;
}

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


int main(){
   int n;cin>>n;
   string s,t;cin>>s>>t;
   string ans;
   rep(i,n)cout<<s[i]<<t[i];
   cout<<endl;
}


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

int main() {
    int N, K;
    cin >> N >> K;
    if (N % K == 0) {
        cout << 0 << endl;
    }
    else {
        cout << 1 << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>

using namespace std;

double Sqrt(double x1, double y1, double x2, double y2)
{
    double x3, y3;
    double d;
    
    x3 = x1 - x2;
    y3 = y1 - y2;
  
    d = sqrt(x3 * x3 + y3 * y3);
    
    return d;
}

int main()
{
  double x1, y1, x2, y2;
  
  cin >> x1 >> y1 >> x2 >> y2;
  
  cout << setprecision(15) << Sqrt(x1, y1, x2, y2) << endl;
   
   return 0;
}


Measured memory_bytes: 3196
N,M=map(int,input().split())
A=[input() for _ in range(N)]
B=[input() for _ in range(M)]
flag=False
for y in range(1+N-M):
    if flag==True:break
    for x in range(1+N-M):
        if flag==True:break
        check=True
        for i in range(M):
            if check==False:break
            for j in range(M):
                if check==False:break
                if A[y+j][x+i]!=B[j][i]:
                    check=False
                    break
        if check==True:
            flag=True
            break
if flag==True:print('Yes')
else:print('No')

Measured memory_bytes: 3064
#include <stdio.h>
int main()
{
	int a,b,sum,i,j;
	scanf("%d",&a);
	sum=0;
	scanf("%d\n",&i);
	for(j=1;j<=a;j++)
	{scanf("%d",&b);
		if(b>=i){
		sum=sum+1;}
		}
	printf("%d",sum);
	return 0;
	}


Measured memory_bytes: 128
#include <bits/stdc++.h>  // include all standard C++ libraries

using namespace std;

// Loops
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define _rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a)-1;i>=int(b);--i)

#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(xi, x) for (auto&& xi : x)
// Note: we can use rep(i,N) or rep(i,from,to)


// typedef
using ll = long long;
template <class T> using vec = vector<T>;
using vi   = vector<int>;
using vvi  = vector<vi>;
using vvvi = vector<vvi>;
using pii  = pair<int, int>;


// Constants

// Shorter repr for frequently used terms
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second


// Algorithms
#define all(x) (x).begin(), (x).end()
#define uniq(v) v.erase( unique(all(v)), v.end() )
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

template<class T> pair<T, size_t> max(vector<T> &x){ auto it = max_element(all(x)); return mp(*it, it-x.begin()); }
template<class T> pair<T, size_t> min(vector<T> &x){ auto it = min_element(all(x)); return mp(*it, it-x.begin()); }

template<class T> inline bool chmax(T &maxval, const T &newval) { if (maxval<newval) { maxval=newval; return 1; } return 0; }
template<class T> inline bool chmin(T &minval, const T &newval) { if (minval>newval) { minval=newval; return 1; } return 0; }

// Utilities
// Grid world utilities
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
#define inside(H,W,y,x) 0<=(x) && (x)<(W) && 0<=(y) && (y)<(H)

inline int in() {int x; cin >> x; return x;} // read int from cin
inline  ll IN() {ll x; cin >> x; return x;}  // read ll from cin



// Debug
#ifdef LOCAL
  #include "dump.hpp"
  #define debug(x) cerr << #x << ": " << x << '\n'
#else
  #define dump(...)
  #define debug(x)
#endif

// Paste snippets here!!

// 

int main(){
  cin.tie(0); ios::sync_with_stdio(false);    // Magic for faster cin
  int n, d;
  cin >> n >> d;
  int r = 2*d + 1;
  if(n%r) cout << n/r + 1 << endl;
  else cout << n/r << endl;
  return 0;
}


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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  // std::cout << std::fixed << std::setprecision(10);
  vector<ll> list;
  for (ll i = 0; i < 3; i++) {
    ll v;
    scanf("%lld", &v);
    list.emplace_back(v);
  }
  sort(list.begin(), list.end());

  ll ans = list[2] * 10 + list[1] + list[0];
  cout << ans << endl;
}


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

using namespace std;

const int N = 2E5 + 5;
long long a[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    for(int i = 0; i < n; i ++)
        cin >> a[i];
    int l, r;
    l = r = 0;
    long long sum = 0;
    long long ans = 0;
    while(r < n) {
        while((sum + a[r]) != (sum ^ a[r])) {
            sum -= a[l];
            l ++;
        }
        ans += r - l + 1;
        sum += a[r];
        r ++;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 1792
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextFloat64() float64 {
	sc.Scan()
	f, _ := strconv.ParseFloat(sc.Text(), 64)
	return f
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func expectedValue(x float64) float64 {
	var e float64
	for i := 1; i <= int(x); i++ {
		e += float64(i) / x
	}
	return e
}

func main() {
	sc.Split(bufio.ScanWords)
	n, k := nextInt(), nextInt()
	evs := make([]float64, n)
	for i := 0; i < n; i++ {
		p := nextFloat64()
		evs[i] = expectedValue(p)
	}

	// initialize
	var ev float64
	for i := 0; i < k; i++ {
		ev += evs[i]
	}

	maxEv := ev
	left := 0
	for i := k; i < n; i++ {
		ev = ev - evs[left] + evs[i]
		left++
		if ev > maxEv {
			maxEv = ev
		}
	}
	fmt.Printf("%0.7f\n", maxEv)
}


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
using namespace __gnu_pbds; 
#define mod 1000000007
#define int long long
#define pb push_back
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define inp(n) for(i=0;i<n;i++) cin>>A[i];
#define inz(A) memset(A,0,sizeof(A))
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(),v.end()
#define T 1000000
#define F first
#define S second
#define pi pair<int,int>
#define vi vector<int>
#define mii map<int,int>
#define vp vector<pair< int,int> >
#define mpi map<pair<int,int> ,int>
#define lower(s) transform(all(s),s.begin(),::tolower)
#define endl "\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, 
         tree_order_statistics_node_update> pbds;
int add(int a, int b) {a=(a%mod + b%mod)%mod;return a;}
int sub(int a, int b) {a =(a%mod - b%mod + mod)%mod ;return a;}
int mul(int a, int b) {return (a%mod * b%mod) % mod;}
 
/* brownsands :Arpit */			

void solve()
{ 
  int n,k,a,b;
  cin >> n >> k;
  a=n%k;b=k-a;
  cout << min(a,b);
}
signed main()
{ 
  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int test=0,t;
  //cin>>t;
    t=1;
   while(test++ <t){         
   	//cout<<"Case# "<<test<<": ";
        solve();}
  //cerr << "\nTime : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
} 
               
			
 

				
		
		




Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<setprecision(20)
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000007LL;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
llint LBI(vector<int>&ar,int in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
llint UBI(vector<int>&ar,int in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;cin>>n;
	if(n<1000){cout<<"ABC"<<endl;}else{cout<<"ABD"<<endl;}
	
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int i = 0;
        int j = 0;
        boolean[][] card = new boolean[4][13];
        int myhand = sc.nextInt();
        for(i = 0; i < myhand; i++){
            String type = sc.next();
            int number = sc.nextInt();
            switch(type){
                case "S" :
                    card[0][number-1] = true;
                    break;
                case "H" :
                    card[1][number-1] = true;
                    break;
                case "C" :
                    card[2][number-1] = true;
                    break;
                case "D" :
                    card[3][number-1] = true;
                    break;
            }
        }
        
        for(i=0;i<4;i++){
            for(j=0;j<13;j++){
                if(card[i][j]==false){
                    switch(i){
                    case 0 :
                        System.out.println("S " + (j+1));
                        break;
                    case 1 :
                        System.out.println("H " + (j+1));
                        break;
                    case 2 :
                        System.out.println("C " + (j+1));
                        break;
                    case 3 :
                        System.out.println("D " + (j+1));
                        break;
                        
                    }
                }
            }
        }
        
        
        
        
        
        
    }
}



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

const int INF = 1e9 + 5;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0; i < n; i++){
    cin >> a[i];
  }
  
  vector<int> dp(n, INF);
  
  dp[0] = 0; // donde el costo de ir al mismo lugar actual, no tiene costo ( logico )
  
  for(int i=0; i < n; i++){  // iteramos para tomar el costo minimo para cada 'roca'
    for(int j : {i+1, i+2}){ // dado un roca 'i' solo puede ir a roca 'i+1' o roca 'i+2'
      if(j < n){
        dp[j] = min(dp[j], dp[i] + abs(a[i] - a[j]));
      }
    }
  }
  cout<< dp[n-1];
  cout<< endl;
}

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

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define ALL(v) v.begin(),v.end()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cout<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct Edge{ll from, to, cost;};
struct node{ll cost, to;
  bool friend operator>(node a, node b){
    return a.cost>b.cost;
  }
};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}
ll N, M, Q;
llvec a, b, c, d;
/*
struct cond{
  ll a, b, c, d;
};
*/

ll ans=0;
void dfs(string s){
  if(s.size()==N){
    ll tmp=0;
    rep(i, Q){
      if((ll)(s[b[i]] - s[a[i]])==c[i])tmp+=d[i];
    }
    ans = max(tmp, ans);
    return;
  }else{
    for(ll i = (ll)(s[s.size()-1]-'0');i<M;i++){
      dfs(s+to_string(i));
    }
  }
  return;
}

/**************************************
** A main function starts from here  **
***************************************/
int main(){
  cin >> N >> M >> Q;
  a = llvec(Q);
  b = llvec(Q);
  c = llvec(Q);
  d = llvec(Q);
  rep(i, Q){
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--;b[i]--;
  }

  dfs("0");
  cout << ans ;
  return 0;
}


Measured memory_bytes: 3700
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const ll MOD = 1000000007;
// const int INF = 2000000000;

string N;

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

  for (int i = 0; i < N.size(); i++) {
    if (N[i] == '1') {
      cout << '9';
    } else {
      cout << '1';
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	long long int n;
	long long int a[100000];
	long long int count = 0;
	long long int count2 = 0;
	cin >> n;
	for(int i = 0;i < n;i++){
		cin >> a[i];
		count+=a[i];
	}
	if(count % ((n + 1) * n / 2)){
		cout << "NO" << endl;
		return 0;
	}
	count/=((n + 1) * n / 2);
	for(int i = 0;i < n - 1;i++){
		if((a[i] - a[i + 1] + count) < 0){
			cout << "NO" << endl;
			return 0;
		}
		count2 += ((a[i] - a[i + 1] + count) / n);
	}
	if((a[n - 1] - a[0] + count) < 0){
		cout << "NO" << endl;
		return 0;
	}
	count2 += ((a[n - 1] - a[0] + count) / n);
	if(count == count2){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 1024
fun main(args: Array<String>) {

    var (n ,a, b, c, d) = readLine()!!.split(" ").map { it.toInt() }
    a -= 1
    b -= 1
    c -= 1
    d -= 1
    val inputs = readLine()!!.toString()

    // 岩が連続してる場合 かつ一番遠いゴールがそれよりも先の場合
    // 間違いない  -> ## が開始点よりも左側にあれば問題ないのでは？？ 
    if (inputs.indexOf("##") != -1 && inputs.indexOf("##") in a..Math.max(c, d) ) {
        println("No")
        return
    }

    // 岩が存在するが，すべてゴールより先にある場合 or 岩が存在しない場合
    // 間違いない
    if (inputs.indexOf("#") == -1 || inputs.indexOf("#") >= Math.max(c, d)) {
        println("Yes")
        return
    }

    // C ＜ D の場合 で B が先に D へ行ってしまえば良いので可能
    // 上記２条件を除いた後では間違いない
    if (c < d) {
        println("Yes")
        return
    }

    /**
     * C > D でかつ，Dが岩の隣りにあって かつ 抜かせない場合
     */

    // C>D でかつ岩の隣に D がある(左右） かつ， A が Bを抜かせる場所がゴールよりも前にないとき
    // AをBより先に行かせられないとき

    fun isDNextToStone(): Boolean{
        if (d == inputs.lastIndex) {
            return inputs[d-1] == '#'
        }

        if (d == 0) {
            return inputs[d+1] == '#'
        }

        return inputs[d-1] == '#' || inputs[d+1] == '#'
    }

    fun canAovertakeB(): Boolean {
        // ... が　B~Dの 間に存在しない
        if (inputs.subSequence(b-1, d+2).indexOf("...") != -1){
            return true
        }

        return false
    }

    // C>D でかつ岩の隣に D がある(左右） かつ，A が B を抜かせる場所が B, D 内に無い
    // 間違いなさそう？？
    if (!canAovertakeB()) {
        println("No")
        return
    }



    // D が岩の隣にない
    // 間違いなさそう？？ 特にだめな条件はない
    println("Yes")
}

Measured memory_bytes: 41492
#define MAX 100

#include <stdio.h>

int main(void) {
    int n,m,i,j,judge,n_sum,m_sum,n_ans,m_ans;
    int n_card[MAX] = {};
    int m_card[MAX] = {};
    
    while(1){
        n_sum = 0;
        m_sum = 0;
        n_ans = 100;
        m_ans = 100;
        judge = 0;
    
        scanf("%d %d",&n,&m);
        if(n==0 && m==0)
            break;
    
        for(i=0;i<n;i++){
            scanf("%d",&n_card[i]);
            n_sum += n_card[i];
        }
        for(i=0;i<m;i++){
            scanf("%d",&m_card[i]);
            m_sum += m_card[i];
        }
    
        for(i=0;i<n;i++){
            for(j=0;j<m;j++){
                if(n_sum-n_card[i]+m_card[j] == m_sum-m_card[j]+n_card[i]
                        && n_card[i]+m_card[j] < n_ans+m_ans){
                    n_ans = n_card[i];
                    m_ans = m_card[j];
                    judge = 1;
                }
            }
        }
        if(judge==1)
            printf("%d %d\n",n_ans,m_ans);
        else
            printf("-1\n");
        }
    
    return 0;
}

Measured memory_bytes: 612
#include <iostream>
#include <vector>
#include <algorithm>
#include <complex>
#include <cmath>
#include <cstring>

using namespace std;

const double EPS=(1e-10);
bool EQ(double a,double b){
    return abs(a-b)<EPS;
}

typedef complex<double> P;
typedef pair<double,double> pdd;

double calc(double a1,double b1,double a2,double b2,double x,double r){
    return (a2*a1*x*x*x)/3.0+(x*x*(a1*a2*r+b2*a1+a2*b1))/2.0+(a2*b1*r+b1*b2)*x;
}

int main(){
    int n;
    double r;
    while(cin>>n>>r&&!(n==0&&EQ(r,0))){
        vector<P> dots;
        vector<pdd> co;
        dots.push_back(P(-1000,0));
        for(int i=0;i<n;i++){
            double x,y;
            cin>>x>>y;
            dots.push_back(P(x,y));
        }
        dots.push_back(P(1000,0));
        double sum=0;
        for(int i=1;i<=n+1;i++){
            double a=(dots[i-1].imag()-dots[i].imag())/(dots[i-1].real()-dots[i].real());
            double b=dots[i-1].imag()-a*dots[i-1].real();
            co.push_back(pdd(a,b));
        }
        double ax=dots[1].real();
        double bx=ax+r;
        int nxtApos=n+2;
        int nxtBpos=n+2;
        // rツづ個値ツつェツづづ個凝ヲツ甘板づ可甘慊づ慊づェツづつ「ツづゥツつゥツづーツ探ツ催オ
        for(int i=0;i<=n+1;i++){
            if(dots[i].real()>bx&&!EQ(dots[i].real(),bx)){
                nxtBpos=i;
                break;
            }
        }
        for(int i=0;i<=n+1;i++){
            if(dots[i].real()>ax&&!EQ(dots[i].real(),ax)){
                nxtApos=i;
                break;
            }
        }
        //bool rev=false;
        //if(ax>bx){
        //    swap(ax,bx);
        //    swap(nxtApos,nxtBpos);
        //    rev=true;
        //}
        // nxtBposツつェnツづ可づ按づゥツづ慊づ堕アツつッツづゥ
        while(nxtBpos!=n+2&&nxtApos!=n+2){
            // ツ篠淞づ個湘ェツ渉環づ鳴づ個仰猟猟」ツつェツ渉ャツつウツつ「ツづ個づ債づつソツづァツつゥ
            double adis=dots[nxtApos].real()-ax;
            double bdis=dots[nxtBpos].real()-bx;
            double dis=min(adis,bdis);
            double t=ax+dis;
            double s=ax;
            sum+=calc(co[nxtApos-1].first,co[nxtApos-1].second,co[nxtBpos-1].first,co[nxtBpos-1].second,t,r);
            sum-=calc(co[nxtApos-1].first,co[nxtApos-1].second,co[nxtBpos-1].first,co[nxtBpos-1].second,s,r);
            //if(rev){
            //    t=bx+dis;
            //    s=bx;
            //    sum+=calc(co[nxtBpos-1].first,co[nxtBpos-1].second,co[nxtApos-1].first,co[nxtApos-1].second,t,r);
            //    sum-=calc(co[nxtBpos-1].first,co[nxtBpos-1].second,co[nxtApos-1].first,co[nxtApos-1].second,s,r);
            //}
            //else{
            //    sum+=calc(co[nxtApos-1].first,co[nxtApos-1].second,co[nxtBpos-1].first,co[nxtBpos-1].second,t,r);
            //    sum-=calc(co[nxtApos-1].first,co[nxtApos-1].second,co[nxtBpos-1].first,co[nxtBpos-1].second,s,r);
            //}
            ax+=dis;bx+=dis;
            if(EQ(adis,bdis)){
                nxtApos++;
                nxtBpos++;
            }
            else if(adis<bdis)nxtApos++;
            else nxtBpos++;
        }
        printf("%.10f\n",sum);
    }
    return 0;
}

Measured memory_bytes: 992
def main():
    n = int(input())
    def factorization(n):
        arr = []
        tmp = n
        # √nまでを調べればいい
        for i in range(2, int(-(-tmp**0.5//1))+1):
            if tmp%i == 0:
                cnt = 0
                # 割れる場合は割れなくなるまで同じ数でわる
                while tmp%i == 0:
                    cnt += 1
                    tmp //= i
                    arr.append(i)
        # 最後1になるか素数が余るので素数ならリストに追加
        if tmp != 1:
            arr.append(tmp)
        # そもそも
        if arr == []:
            arr.append(n)
        return arr
    res = factorization(n)
    print(str(n)+': ', end='')
    for i in range(len(res)-1):
        print(res[i], end=' ')
    print(res[len(res)-1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 5648
#include<cstdio>
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#define RG register
using namespace std;
const int N=5e5+10;
struct dabt{
	int next,to;
}e[N<<2];
int head[N],k,n,m,tree[N<<2],ru[N],pos[N],p[N],cnt,ans[N];
priority_queue<int, vector<int> ,greater<int> > pn;
inline void add(int from,int to){e[++k]=(dabt){head[from],to}; head[from]=k; ru[to]++;}
inline int read(){
	char ch=getchar(); int x=0, f=1;
	while(ch<'0' || ch>'9') {if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();}
	return x*f;}
inline int mi(int a,int b){return a<b ? a : b;}
inline int mx(int a,int b){return a>b ? a : b;}
int sum(int l,int r,int st,int ed,int o)
{
	if(st<=l && r<=ed) return tree[o];
//	printf("%d %d %d %d %d\n",l,r,st,ed,o);
	if(l==r) return 2e9;
	int mid=l+(r-l)/2, ans=2e9;
	if(mid>=st) ans=mi(ans,sum(l,mid,st,ed,o<<1));
	if(mid<ed) ans=mi(ans,sum(mid+1,r,st,ed,o<<1|1));
	return ans;
}
void upd(int l,int r,int pos,int kk,int o)
{
	if(l==r) 
	{
		tree[o]=kk;
		return ;
	}
	int mid=l+(r-l)/2;
	if(pos<=mid) upd(l,mid,pos,kk,o<<1);
	else upd(mid+1,r,pos,kk,o<<1|1);
	tree[o]=mi(tree[o<<1],tree[o<<1|1]);
}
inline void topo()
{
	for(int i=1;i<=n;i++) if(!ru[i]) pn.push(i);
	while(!pn.empty())
	{
		int x=pn.top(); pn.pop(); ans[x]=++cnt;
		for(int i=head[x];i;i=e[i].next)
		{
			int v=e[i].to;
			if(--ru[v]==0) pn.push(v);
		}
	}
}
int main()
{
//	freopen("Wide Swap.in","r",stdin);
//	freopen("Wide Swap.out","w",stdout);
	n=read(); m=read();
	for(int i=1;i<=(n<<2);i++) tree[i]=2e9;
	for(int i=1;i<=n;i++)
	{
		pos[p[i]=read()]=i;
	}
	for(int i=n,x;i;i--)
	{
		x=sum(1,n,pos[i]+1,mi(pos[i]+m-1,n),1);
		if(x<2e9) add(pos[i],pos[x]);
		x=sum(1,n,mx(pos[i]-m+1,1),pos[i]-1,1);
		if(x<2e9) add(pos[i],pos[x]);
		upd(1,n,pos[i],i,1);
	}
	topo();
	for(int i=1;i<=n;i++) printf("%d\n",ans[i]);
	//fclose(stdin); fclose(stdout);
	return 0;
}

Measured memory_bytes: 30336
N = int(input())
H = list(map(int, input().split()))[::-1]

ans = True
for i in range(N-1):
    if H[i] < H[i+1]:
        if H[i+1] - H[i] > 1:
            ans = False
        else:
            H[i+1] -= 1
print("Yes" if ans else "No")


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

using namespace std;

int main(){
    int n;
    long long int x;
    cin >> n >> x;
    vector<long long int> a(n), adj(n-1);

    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    long long int ans = 0;
    for(int i = 1; i < n; i++){
        long long int adj = a[i] + a[i-1];
        if(adj > x){
            long long int sub = adj - x;
            ans += sub;
            a[i] = a[i] < sub ? 0 : a[i] - sub;
        }
    }
    cout << ans << endl;




	return 0;
}



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

int main(void) {
	string s;

	cin >> s;
	int n[28] = {};
	
	for (int i = 0; i < s.length(); i++) {
		for (int j = 0; j < 26; j++) {
			if (s[i] == 'a' + j) {
				n[j] ++;
				if (n[j] == 2) {
					cout << "no" << endl;
					return 0;
				}
			}
		}
	}
	cout << "yes" << endl;



	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

//最大フロー
const int MAX_N = 510, MAX_K = 510;
const int MAX_V = 510 * 510;

struct edge{
    int to, cap, rev;
};

//vector<edge> G[MAX_N];
vector<edge> G[MAX_V];
bool used[MAX_V];

void add_edge(int from, int to, int cap){
    G[from].push_back((edge){to, cap, (int)G[to].size()});
    G[to].push_back((edge){from, 0, (int)G[from].size() - 1});
}

int dfs(int v, int t, int f){
    if(v == t) return f;
    used[v] = true;
    for(int i = 0; i < G[v].size(); i++){
        edge &e = G[v][i];
        if(!used[e.to] && e.cap > 0){
            int d = dfs(e.to, t, min(f, e.cap));
            if(d > 0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s, int t){
    int flow = 0;
    for(;;){
        memset(used, 0, sizeof(used));
        int f = dfs(s, t, INF);
        if(f == 0) return flow;
        flow += f;
    }
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, a[110], sum = 0;
    cin >> n;
    rep(i, 1, n + 1){
        cin >> a[i];
        if(a[i] >= 0){
            sum += a[i];
            add_edge(i, n + 1, a[i]);
            add_edge(0, i, 0);
        }else{
            add_edge(i, n + 1, 0);
            add_edge(0, i, -a[i]);
        }
        for(int j = 2 * i; j <= n; j += i) add_edge(i, j, INF);
    }
    cout << sum - max_flow(0, n + 1) << endl;
}

Measured memory_bytes: 6656
#include<bits/stdc++.h>
#include<algorithm>
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;
int main()
{
    fast_io
    ll t,i,j,n,m,p,x,sum=0;
    string a,b,c;
    cin>>a>>b>>c;
    if(a[a.length()-1]==b[0]&&b[b.length()-1]==c[0])
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;

    return 0;
}





Measured memory_bytes: 3588