akhauriyash/Code-Regression huggingface dataset:
import java.io.{BufferedReader, InputStream, InputStreamReader, PrintWriter}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import scala.collection.mutable.{ArrayBuffer, ListBuffer}

object Main {
  val MOD = 1000000007
  val out = new PrintWriter(System.out)
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N = sc.nextInt()
    val A = Array.ofDim[Int](N + 2)
    rep(N)(i => A(i + 1) = sc.nextInt())

    def d(i: Int, j: Int) = abs(A(i) - A(j))

    val S = map(N + 1)(i => d(i, i + 1)).sum

    rep(N) { i =>
      out.println(S + d(i, i + 2) - d(i, i + 1) - d(i + 1, i + 2))
    }
  }


  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }


  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
    def nextLong(): Long = next.toLong
    def nextChar(): Char = next.charAt(0)
  }

  private def rep(n: Int)(f: Int => Unit): Unit = {
    (0 until n) foreach f
  }

  private def map[@specialized(Int, Long) A](n: Int)(f: Int => A): Seq[A] = {
    (0 until n) map f
  }
}


Measured memory_bytes: 42636
public partial class IntroductionToProgramming{
	public static void Main(){
		string[] line = System.Console.ReadLine().Split(' ');
		int w = int.Parse(line[0]);
		int h = int.Parse(line[1]);
		int x = int.Parse(line[2]);
		int y = int.Parse(line[3]);
		int r = int.Parse(line[4]);
		
		System.Console.WriteLine(r <= x && x <= w - r && r <= y && y <= h - r ? "Yes" : "No");
	}
}

Measured memory_bytes: 5300
main(){double a,b,c,d,e,f,g;for(scanf("%*d");~scanf("%lf%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e,&f);puts(d>c+f?"0":c>d+f?"2":f>c+d?"-2":"1"))d=hypot(a-d,b-e);exit(0);}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.Generic;
namespace AtCoder
{
    class Abc162F
    {

        public static void Main()
        {
            var input = Console.ReadLine().Split(' ');
            //long MOD = 10000000007;
            var n = int.Parse(input[0]);
            var k = int.Parse(input[1]);

            //var mm = Console.ReadLine().Split(' ').Select(y => long.Parse(y)).ToArray();
            //var nn = Console.ReadLine().Split(' ').Select(y => long.Parse(y)).ToArray();

           
            double prob = 0.0;
            for (int i = 1; i <=n; i++)
            {
                var nProb = 1.0 / n;
                var f = i;
                int count = 0;
                while (f < k)
                {
                    count++;
                    f = 2 * f;
                    nProb = nProb / 2;  
                }

                prob += nProb;
            }
            Console.Write(prob);
            Console.WriteLine();

        }


    }
}


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

int main(){
    string s;
    int k;
    set<string> S;

    cin>>s>>k;

    int size = s.length();

    for(int i=0; i<size; i++){
        string tmp;
        for(int j=0; j<k; j++){
            tmp = s.substr(i,j+1);
            S.insert(tmp);           
        }
    }

    set<string> ::iterator itr = S.begin();

    for(int i=1; i<k; i++) itr++;

    cout<<*itr<<endl;

    return 0;
}

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

using namespace std;

int main(){
    int N;

    cin >> N;

    int a[N];

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

    sort(a, a+N, greater<>());

    int bob = 0;
    int alice = 0;
    for(int i = 0; i < N; i++){
        if( i%2 == 0) alice += a[i];
        else bob += a[i];
    }

    printf("%d\n", alice-bob);

    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
MOD = 10**9+7
if abs(N-M) > 1:
    print(0)
    exit()

if N > M:
    N, M = M, N
ans = 1
for i in range(1, N+1):
    ans = ans*i%MOD
ans = ans*ans%MOD
if M > N:
    ans = ans*M%MOD
else:
    ans = ans*2%MOD
print(ans)



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

int main( void ) {
    
    long long x, ans;
    cin >> x; ans = ( x / 11 ) * 2;
    
    x %= 11;
    if( x >= 1 && x <= 6 )
        ans += 1;
    if( x >= 7 && x <= 10 )
        ans += 2;
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL endl
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
#define deb(x) cout << #x": " << (x) << endl;
const lli N = 1e7;
const lli INF = 1e18;
const lli mod = 1e9+7;

// ---- コーディングはここから！ ('-')7



int main(){_
	int n; cin>>n;
	vl v(n);
	fore(i,0,n)cin>>v[i];
	lli d=1000, a = 0, mx = 1000;
	fore(i,0,n-1){
		if(v[i]<=v[i+1]){
			lli x = d/v[i];
			d-=x*v[i];
			a+=x;
		}
		if(v[i]>v[i+1]){
			lli x = a*v[i];
			d+=x;
			a=0;
		}
		mx = max(d,mx);
	}
	if(v[n-1]>=v[n-2]){
		lli x = a*v[n-1];
		d+=x;
		a=0;
		mx = max(d,mx);
	}
	cout<<mx<<ENDL;

}


Measured memory_bytes: 3640
#include <iostream>

#define SIZE 100

int N, M;
long T[SIZE];
long total, ans;

int main() {
    std::cin >> N;
    for (int i=0; i<N; ++i) {
        std::cin >> T[i];
        total += T[i];
    }
    std::cin >> M;
    for (int i=0; i<M; ++i) {
        int  p;
        long x;
        std::cin >> p >> x;
        ans = total - T[p-1] + x;
        std::cout << ans << std::endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
typedef long long ll;
int main()
{
    ll a,b;
    cin>>a>>b;
    ll z=b/2;
    if(a>=z)
    {
        cout<<z<<endl;
    }
    else
    {
        cout<<a+(b-a*2)/4<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] dif = new int[n];
		int max = 0;
		for(int i = 0; i < n; i++){
			dif[i] = sc.nextInt();
		}
		Arrays.sort(dif);
		
		int res= dif[dif.length/2] - dif[dif.length/2 - 1];
		System.out.println(res);
	}
}

Measured memory_bytes: 59720
n = int(input())

times_ls = [0] * (n+1)
for base in range(1,n+1):
    for j in range(1,n+1):
        if base * j <= n:
            times_ls[base * j] += 1
        else:
            break
ans = 0
for i in range(1,n+1):
    ans += i * times_ls[i]
print(ans)
    




Measured memory_bytes: 151708
#include <iostream>
#include <vector>
#include <algorithm>
const int MAX=100010;
using namespace std;
int cntc[MAX],dp[MAX],index[MAX][2];
vector <vector<int>> a;
int n,m,a1,a2,ans=0;

bool compare(const vector<int> &x,const vector<int> &y){
  return x[0]<y[0];
}

int fmax(int i){
  if (dp[i]){
    return dp[i];
  } else if (!cntc[i]){
    dp[i]=1;
    return 1;
  } else {
    int maxv=-1;
    for (int j=index[i][0];j<=index[i][1];j++){
      maxv=max(maxv,fmax(a[j][1]));
    }
    dp[i]=maxv+1;
    return dp[i];
  }
}

int main(){
  cin >>n>>m;
  for (int i=1;i<=n;i++){
    index[i][0]=-1;
    cntc[i]=0;
  }
  for (int i=0;i<m;i++){
    cin >>a1>>a2;
    vector<int> tmp={a1,a2};
    a.push_back(tmp);
    cntc[a1]++;
  }

  sort(a.begin(),a.end(),compare);
  for (int i=0;i<m;i++){
    if (index[a[i][0]][0]==-1)
      index[a[i][0]][0]=i;
    index[a[i][0]][1]=i;
  }

  for (int i=1;i<=n;i++){
    ans=max(fmax(i),ans);
  }
cout << ans-1<<endl;
return 0;

}


Measured memory_bytes: 9264
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int n, a, b, m, d[100100];
vector<int> e[100100];
priority_queue<pair<int,int>, vector<pair<int,int> >, greater<pair<int,int> > > q;

signed main() {
	cin >> n;
	rep(i,n-1) {
		cin >> a >> b;
		a--, b--;
		e[a].push_back(b), e[b].push_back(a);
	}
	rep(i,n) d[i] = -1;
	cin >> m;
	rep(i,m) {
		cin >> a >> b;
		a--;
		d[a] = b;
		q.push({b,a});
	}
	while (!q.empty()) {
		int v = q.top().second, dis = q.top().first; q.pop();
		each(i,e[v]) {
			if (d[i]==-1) {
				d[i] = dis+1;
				q.push({d[i],i});
			} else if (d[i]!=dis+1 && d[i]!=dis-1) return cout << "No" << endl, 0;
		}
	}
	cout << "Yes" << endl;
	rep(i,n) cout << d[i] << endl;
}


Measured memory_bytes: 8576
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,x;
    cin>>a>>b>>x;
    if(a+b>=x&&x>=a)
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
    return 0;
}


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

public class Main {
	
	public int getMax(int[][] map){
		int[][] len = new int[map.length+1][map.length];
		int max = 0;
		for(int i = 0; i < map.length; i++){
			int[] wid = new int[map.length+1];
			for(int j = 0; j < map.length; j++){
				if( map[i][j] == 1 ){
					wid[j+1] = wid[j] + 1;
					len[i+1][j] = len[i][j] + 1;
					max = Math.max(wid[j+1], max);
					max = Math.max(len[i+1][j], max);
				}
			}
		}
		if( max == map.length ){
			return max;
		}
		for(int i = max; i < map.length; i++){
			int count = 0;
			for(int j = 0; j <= i; j++){
				if( map[j][i-j] == 1 ){
					count++;
					max = Math.max(max, count);
				} else {
					count = 0;
				}
			}			
		} 
		for(int i = max; i < map.length; i++){
			int count = 0;
			for(int j = 0; j <= i; j++){
				if( map[map.length-1-i+j][map.length-1-j] == 1 ){
					count++;
					max = Math.max(max, count);
				} else {					
					count = 0;
				}
			}
		} 
		for(int i = max; i < map.length; i++){
			int count = 0;
			for(int j = 0; j <= i; j++){
				if( map[j][map.length-1-i+j] == 1 ){
					count++;
					max = Math.max(max, count);
				} else {					
					count = 0;
				}
			}			
		}
		for(int i = max; i < map.length; i++){
			int count = 0;
			for(int j = 0; j <= i; j++){
				if( map[map.length-1-j][i-j] == 1 ){
					count++;
					max = Math.max(max, count);
				} else {					
					count = 0;
				}
			}			
		}  
		return max;
	}
	public  void solve() throws IOException{
		int n;
		while( (n = nextInt() ) != 0 ){
			String[] s = new String[n];
			int[][] map = new int[n][n];
			for(int i = 0; i < n; i++){
				s[i] = nextToken();
				for(int j = 0; j < n; j++){
					map[i][j] = s[i].charAt(j)-'0';
				}
			}
			writer.println(getMax(map));			
		}
		writer.flush();
	}
	public static void main (String args[]) throws IOException{
		new Main().run();
	}
	
	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;
	
	public void run() throws IOException{
		try{
			reader = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			writer = new PrintWriter(System.out);
			solve();
			reader.close();
			writer.close();
		} catch (Exception e){
			e.printStackTrace();
			System.exit(1);
		}
	}
	public int nextInt() throws IOException{
		return Integer.parseInt(nextToken());
	}		
	public String nextToken() throws IOException{
		while( tokenizer == null || !tokenizer.hasMoreTokens() ){
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}
}

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

int main()
{
  int a,b;
  char op;

  scanf("%d %c %d",&a,&op,&b);

  if (op=='+') {
    printf("%d\n",a+b);
  } else {
    printf("%d\n",a-b);
  }
  
  return 0;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
int main(){
    ll n;
    cin>>n;
    map<ll,ll>m;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
        m[a[i]]++;
    }
    map<ll,ll>::iterator it;
    it=m.begin();
    ll ans=0;
    while(it!=m.end()){
        if(it->second>=it->first)ans+=it->second-it->first;
        else ans+=it->second;
        it++;
    }
    cout<<ans;
}

Measured memory_bytes: 7040
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a,b,c;
    cin>>a>>b>>c;
    if((a*100+b*10+c)%4 ==0){
        cout<<"YES"<<endl;
    }
    else{
        cout<<"NO"<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>

using namespace std;


int main(){
    char temp;
    int zero=0,one=0;
    while(scanf("%c",&temp)!=EOF){
        if(temp=='0')
            zero++;
        else if(temp=='1')
            one++;
    }
    printf("%d",min(zero,one)*2);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int n,i;
	int a[1005];
	
	scanf("%d",&n);
	for(i=0; i<n; i++){
		scanf("%d",&a[i]);
	}
	for(i=n; i>1; i--){
		printf("%d",a[i-1]);
		printf(" ");
	}
	printf("%d\n",a[0]);
	
	return 0;
}


Measured memory_bytes: 2108
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
	
	void run() {
		
		int m = sc.nextInt();
		int k = sc.nextInt();
		
		if(k >= 1<<m) {
			System.out.println(-1);
			return;
		}
		
		if(m == 1 && k == 1) {
			System.out.println(-1);
			return;
		}
		
		if(m == 0) {
			if(k == 0) {
				System.out.print("0 0");
				return;
			}else {
				System.out.println(-1);
			}
			return ;
		}
		
		if(k == 0) {
			System.out.print("0 0");
			
			for(int i = 1; i < 1 <<m;i++) {
				System.out.print(" ");
				System.out.print(i);
				System.out.print(" ");
				System.out.print(i);
			}
		}else {
			
			System.out.print(k);
			
			for(int i = 1; i < 1 <<m;i++) {
				if(i == k) continue;
				System.out.print(" ");
				System.out.print(i);
			}
			
			System.out.print(" ");
			System.out.print(k);

			System.out.print(" ");
			System.out.print(0);

			for(int i = (1<<m)-1 ; i > 0; i--) {
				if(i == k) continue;
				System.out.print(" ");
				System.out.print(i);
			}
			
			System.out.print(" ");
			System.out.print(0);
		}
		
	}
}


Measured memory_bytes: 46656
#include<iostream>
#include<vector>
using namespace std;
int map[1000][1000];
int main(){
  int h,w,a,b;
  cin>>h>>w>>a>>b;
  for(int i=0;i<b;i++){
    for(int j=0;j<a;j++){
      map[i][j]=0;
    }
    for(int j=a;j<w;j++){
      map[i][j]=1;
    }
  }
  for(int i=b;i<h;i++){
  for(int j=0;j<a;j++){
    map[i][j]=1;
  }
  for(int j=a;j<w;j++){
    map[i][j]=0;
  }
}
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cout<<map[i][j];
    }
    cout<<endl;
  }
  return 0;
}


Measured memory_bytes: 5120
N = int(input())
V = list(map(int, input().split()))
max_value = 0
for i in range(N-1):

    temp = min(V)
    V.remove(temp)
    temp2 = min(V)
    V.remove(temp2)

    V.append((temp+temp2)/2)

print(V[0])


Measured memory_bytes: 2940
#include<iostream>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;
#include<algorithm>
#include<math.h>
#include<map>
#include<queue>
#include<set>

int main() {
	int n;
	cin >> n;
	vector<int>a(n+1);
	vector<int>b(n + 1);
	rep(i, n) {
		cin >> a[i+1];
	}
	int ans;
	for (int i = n; i > 0; --i) {
		int cnt(0);
		for (int j = i * 2; j <= n;j+=i) {
			cnt += b[j];
			
		}
		//cout << cnt << " ";
		if (cnt % 2 != a[i]) {
			b[i]++;
		}
		
	}
	ans = 0;
	rep(i, n+1) {
		ans += b[i];
	}
	
	cout << ans << endl;
	for (int i = 1; i <= n; ++i) {
		if (!b[i])continue;
		cout << i << " ";
	}
	return 0;
}

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

const int N = 2e5 + 100;

int h[N], a[N];

int main() {
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i=0; i<n; i++) cin >> h[i];
    for (int i=0; i<n; i++) cin >> a[i];
    map<int, ll> dp;
    dp[0] = 0;
    dp[1e9] = 1e18;
    for (int i=0; i<n; i++) {
        ll x = prev(dp.lower_bound(h[i]))->second + a[i];
        dp[h[i]] = x;
        auto it = next(dp.find(h[i]));
        while (it->second <= x) {
            it = dp.erase(it);
        }
    }
    cout << next(dp.rbegin())->second << '\n';
}


Measured memory_bytes: 14464
import numpy as np

N, D = [int(x) for x in input().split()]

X = np.zeros((N, D))
for i in range(N):
	t = [int(x) for x in input().split()]
	X[i,:] = np.array(t)

counter = 0
for i in range(N-1):
	for j in range(i+1, N):
		if np.sqrt(np.sum((X[i,:]-X[j,:])**2))%1 == 0:
			counter += 1
print(counter)


Measured memory_bytes: 12452
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	static int[][] F=new int[100][100];
	static int[][] P=new int[100][100];

	void run() {
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < 10; j++) {
				F[i][j]=sc.nextInt();
			}
		}

		for (int i = 0; i < N; i++) {
			for (int j = 0; j < 11; j++) {
				P[i][j]=sc.nextInt();
			}
		}

		int res = Integer.MIN_VALUE;

		for (int b = 1; b < (1<<10); b++) {

			int cc = 0;

			for (int i = 0; i < N; i++) {

				int c = 0;

				for (int j = 0; j < 10; j++) {
					if((b>>j&1)==1 && F[i][j]==1) {
						c++;
					}
				}

				cc+=P[i][c];


			}

			res=Math.max(res,cc);

		}

		System.out.println(res);

	}



	//以下テンプレート

	public static int[] extgcd(int a, int b) {

		int x0 = 1;
		int x1 = 0;

		int y0 = 0;
		int y1 = 1;

		while (b != 0) {
			int q = a / b;
			int r = a % b;

			int x2 = x0 - q * x1;
			int y2 = y0 - q * y1;

			a = b;
			b = r;

			x0 = x1;
			x1 = x2;

			y0 = y1;
			y1 = y2;
		}

		return new int[] { a, x0, y0 };

	}

	static int gcd(int a, int b) {

		if (b == 0)
			return a;

		if (a < b) {
			int t = a;
			a = b;
			b = t;
		}

		return gcd(b, a % b);

	}

	static int lcm(int a, int b) {
		return a * b / gcd(a, b);
	}

	static void swap(int[] a) {
		int t;

		t = a[0];
		a[0] = a[1];
		a[1] = t;

		return;
	}

	static <T> void output(List<T> list) {

		for (int i = 0; i < list.size(); i++) {
			System.out.print(list.get(i));

			if (i != list.size() - 1) {
				System.out.print(" ");
			} else {
				nl();
			}
		}

	}

	static void output(String[][] str) {

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				print(str[i][j]);
			}

			nl();
		}

	}

	static void output(boolean flg, String Yes, String No) {

		if (flg) {
			pln(Yes);
		} else {
			pln(No);
		}

	}

	static void output(String[][] str, int digit) {

		String dig = "%" + String.valueOf(digit) + "s";

		for (int i = 0; i < str.length; i++) {
			for (int j = 0; j < str[i].length; j++) {
				System.out.printf(dig, str[i][j]);
			}
			nl();
		}

	}

	static void pln(String str) {
		System.out.println(str);
	}

	static void pln(int x) {
		System.out.println(x);
	}

	static void print(String str) {
		System.out.print(str);
	}

	static void print(int x) {
		System.out.print(x);
	}

	static void print(String str, int times) {
		for (int i = 0; i < times; i++) {
			print(str);
		}
	}

	static void print(int x, int times) {
		for (int i = 0; i < times; i++) {
			print(x);
		}
	}

	static void nl() {
		System.out.println();
	}

}


Measured memory_bytes: 26152
n,x = map(int,input().split())

piece = [1]
meet  = [1]
for _ in range(n):
  piece.append(piece[-1]*2 +3)
  meet.append(meet[-1]*2+1)
  
ans = 0
i = n
while x:
  if x > (piece[i]+1)//2:
    ans += meet[i]//2+1
    x -= piece[i]//2+1
    i -= 1
  elif x== (piece[i]+1) //2:
    ans += meet[i]//2+1
    x = 0
  else:
    i -= 1
    x -= 1
print(ans)

Measured memory_bytes: 38384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n = 0;
  cin >> n;
  ll k = 0;
  cin >> k;
  vector<ll> a(n);
  for(int i = 0;i < n;i++)cin >> a[i];
  sort(a.begin(),a.end());
  ll res = 0;
  for(int i = 0;i < k;i++)res += a[i];
  cout << res << endl;
}

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

int main(){
    ll n,p,ans=0;
    cin>>n>>p;
    string mo;
    cin>>mo;
    if(p==2 || p==5){
        for (ll i = n-1; i >=0; --i) {
            int now=stoi(mo.substr(i,1));
            if(now%p==0){
                ans+=i+1;
            }
        }
    }
    else{
        ll count[p],amari[10];
        ll now=0;
        for (int l = 0; l < 10; ++l) {
            amari[l]=l;
        }
        for (int j = 0; j < p; ++j) {
            count[j]=0;
        }
        count[0]++;
        for (ll i = n-1; i >=0; --i) {
            now+=amari[stoi(mo.substr(i,1))];
            now%=p;
            count[now]++;
            for (int j = 0; j < 10; ++j) {
                amari[j]=amari[j]*10%p;
            }
        }
        for (int k = 0; k < p; ++k) {
            ans+=count[k]*(count[k]-1)/2;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 644
from scipy.sparse import csr_matrix #pypyだとエラーになるので、pythonを使うこと
from scipy.sparse.csgraph import shortest_path, floyd_warshall
import numpy as np

import sys
def input():
	return sys.stdin.readline().strip()

N, M, L = list(map(int, input().split()))

graph = np.full((N, N), np.inf)
for i in range(M):
	A, B, C = list(map(int, input().split()))
	graph[A - 1, B - 1] = C
	graph[B - 1, A - 1] = C


dist = floyd_warshall(graph, directed=False)
graph2 = np.full((N, N), np.inf)
for i in range(N):
	for j in range(N):
		if dist[i, j] <= L:
			graph2[i, j] = 1
graph2 = csr_matrix(graph2)
num = shortest_path(graph2, directed=False)


Q = int(input())
for q in range(Q):
	s, t = list(map(int, input().split()))
	if num[s - 1][t - 1] < 10000000:
		print(int(num[s - 1][t - 1] - 1))
	else:
		print(-1)

Measured memory_bytes: 18896
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};



int main(){
    LL n,m,k;cin >> n >> m >> k;
    vector<LL> a(n),b(m);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> b[i];
    }
    vector<LL> as(n + 1, 0), bs(m + 1, 0);
    for (int i = 0; i < n; i++) {
        as[i + 1] = as[i] + a[i];
    }
    for (int i = 0; i < m; i++) {
        bs[i + 1] = bs[i] + b[i];
    }
    LL ans = 0;
    for (int i = 0; i <= n; i++) {
        LL t = i;
        if(as[i] > k) break;
        t += upper_bound(ALL(bs), k - as[i]) - bs.begin();
        chmax(ans, t - 1);
    }
    cout << ans << endl;
    return 0;
}


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

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

// #define int long long
#define YES "YES"
#define NO  "NO"

using namespace std;

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

  int num;
  bool flag;

  num = 0;
  // num = numeric_limits<int>::max();
  // num = numeric_limits<int>::min();
  flag = true;
  // flag = false;

  string s[3];
  for (int i = 0; i < 3; ++i) cin >> s[i];

  flag = (s[0][s[0].length() - 1] == s[1][0]) && (s[1][s[1].length() - 1] == s[2][0]);

  // cout << num << endl;
  cout << (flag ? YES : NO) << endl;
  
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string line;
            while ((line = Console.ReadLine()) != null)
            {
                string[] ps = line.Split(' ');
                decimal ax = decimal.Parse(ps[0]);
                decimal ay = decimal.Parse(ps[1]);
                decimal bx = decimal.Parse(ps[2]);
                decimal by = decimal.Parse(ps[3]);
                decimal cx = decimal.Parse(ps[4]);
                decimal cy = decimal.Parse(ps[5]);
                decimal dx = decimal.Parse(ps[6]);
                decimal dy = decimal.Parse(ps[7]);

                decimal x1 = bx - ax;
                decimal y1 = by - ay;
                decimal x2 = dx - cx;
                decimal y2 = dy - cy;
                if ((x1 * x2 + y1 * y2) == 0) Console.WriteLine("YES");
                else Console.WriteLine("NO");
            }
        }
    }
}

Measured memory_bytes: 5704
// C - Peaks
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(int)(n); i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main(){
    int n, m;
    cin >> n >> m;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];
    vector<bool> ok(n, true);
    vector<int> cnt(n, 0);
    rep(i, m){
        int a, b;
        cin >> a >> b;
        a -= 1, b -=1;
        if(h[a] < h[b]){
            ok[a] = false, ok[b] = true;
            cnt[a]++;
        }else if(h[a] > h[b]){
            ok[a] = true, ok[b] = false;
            cnt[b]++;
        }else{
            ok[a] = ok[b] = false;
            cnt[a]++; cnt[b]++;
        } 
    }
    int ans = 0;
    rep(i, n) if(ok[i] && cnt[i]==0) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4564
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main() {
    string s;
    cin >> s;
    int n = s.length();
    string target = "keyence";
    rep(i,n){
        rep(j,n){
            //i=>jまでを切り取る
            string t = s.substr(0,i) + s.substr(j);
            if(t == target){
                cout << "YES\n";
                return 0;
            }
        }
    }
    cout << "NO\n";
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int num_of_divisor(int n) {
    int count = 0;
    for (int i = 1; i <= n; ++i) {
        if (n % i == 0)
            ++count;
    }
    return count;
}

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

    int result = 0;
    for (int i = 1; i <= n; i += 2) {
        if (num_of_divisor(i) == 8)
            ++result;
    }
    cout << result << '\n';
}


Measured memory_bytes: 256
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() (int, error) {
	return strconv.Atoi(nextString())
}

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

func printArr(arr []string) {
	fmt.Println(strings.TrimRight(fmt.Sprintf("%+v", arr)[1:], "]"))
}

func main() {
	scanner.Split(bufio.ScanWords)

	n, _ := nextInt()
	x := make([]int, 2019+1)
	for i := range x {
		x[i] = -1
	}
	for i := 0; i < n; i++ {
		p, _ := nextInt()
		x[p] = i + 1
	}
	m, _ := nextInt()
	a := make([]int, m)
	for i := 0; i < m; i++ {
		a[i], _ = nextInt()
	}

	for i := 0; i < m; i++ {
		ai := a[i]
		//		fmt.Println(a, ai, x[0:10])
		for j := 1; j < 2019; j++ {
			if (x[j] == ai) && (x[j+1] == -1) {
				x[j] = -1
				x[j+1] = ai
				break
			}
		}
	}

	for i := 1; i <= 2019; i++ {
		for j := 1; j <= 2019; j++ {
			if x[j] == i {
				fmt.Println(j)
				break
			}
		}
	}
}



Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define _GLIBCXX_DEBUG
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  ll n,T;
  cin>>n>>T;
  vlong t(n);
  rep(i,n){
    cin>>t[i];
  }
  ll sum=0;
  REP(i,1,n){
    if(t[i]-t[i-1]>T){
      sum+=T;
    }
    else{
      sum+=t[i]-t[i-1];
    }
  }
  cout<<sum+T<<'\n';
  return(0);
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main(){

	int A,B,m;
	cin>>A>>B>>m;
	int a[A];
	int b[B];
	int c[m];
	int x[m];
	int y[m];
	int sa=1000000;
	int sb=1000000;
	int ans;
	for(int i=0;i<A;i++){
	
		cin>>a[i];
		if(a[i]<sa){
		
			sa=a[i];
		}
	}
	for(int i=0;i<B;i++){

		cin>>b[i];
		if(b[i]<sb){
		
			sb=b[i];
		}
		
	}
	ans=sa+sb;
	for(int i=0;i<m;i++){
	
		cin>>x[i]>>y[i]>>c[i];
		if(a[x[i]-1]+b[y[i]-1]-c[i]<ans){
		
			ans=a[x[i]-1]+b[y[i]-1]-c[i];
		}
	}

	cout<<ans;
	return 0;

}


Measured memory_bytes: 5480
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {
    int r;
    cin >> r;
    cout << r * r << endl;
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long int ll;
int main(){
	int n;
	ll a,b;
	ll x[100000];
	scanf("%d%lld%lld",&n,&a,&b);
	for(int i=0;i<n;i++){
		scanf("%lld",x+i);
	}
	ll ans = 0;
	for(int i=0;i<n-1;i++){
		ans += min(a*(x[i+1]-x[i]),b);
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits.h>

using namespace std;

int main()
{
	int n;
	int cx,cy;
	long ch;
	

	cin >> n;

	int *x = new int[n];
	int *y = new int[n];
	long *h = new long[n];

	for (int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> h[i];
	}

	bool find;
	for (int i = 0; i <= 100; i++) {
		for (int j = 0; j <= 100; j++) {
			cx = i;
			cy = j;
			int delta_x;
			int delta_y;
			long delta_h;
			find = false;
			ch = LONG_MAX;

			int k;
			for (k = 0; k < n; k++) {
				delta_x = abs(x[k] - i);
				delta_y = abs(y[k] - j);
				long temp_ch = h[k] + delta_x + delta_y;
				if (temp_ch <= ch) {
					ch = temp_ch;
				}
				else if (h[k] == 0) {
					continue;
				}
				else {
					break;
				}
			}
			for (k = 0; k < n; k++) {
				delta_x = abs(x[k] - i);
				delta_y = abs(y[k] - j);
				long temp_ch = h[k] + delta_x + delta_y;
				if (temp_ch <= ch) {
					ch = temp_ch;
				}
				else if (h[k] == 0) {
					continue;
				}
				else {
					break;
				}
			}
			if (k == n && ch < LONG_MAX) {
				find = true;
				break;
			}
		}
		if (find) {
			break;
		}
	}
	cout << cx << " " << cy << " " << ch << endl;
}



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

int main (){
    ll N;
    cin >> N;
    string ans;
    while(N > 26){
        int mod = N % 26;
        if(mod != 0){
            ans = (char)('a' + mod - 1) + ans;
            N = N / 26;
        }else{
            ans = 'z' + ans;
            N = N / 26 - 1;
        }
    }
    if(N != 0) ans = (char)('a' + N - 1) + ans;
    cout << ans << endl;
}

Measured memory_bytes: 3616
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int m = sc.nextInt();
		
		for(int i = 0; i < m; i++){
			String str = sc.next();
			HashSet<String> set = new HashSet<String>();
			
			for(int j = 1; j < str.length(); j++){
				
				String forward = str.substring(0, j);
				String backward = str.substring(j);
				StringBuilder forward_r = new StringBuilder();
				forward_r.append(forward);
				forward_r.reverse();
				StringBuilder backward_r = new StringBuilder();
				backward_r.append(backward);
				backward_r.reverse();
				
				set.add(forward + backward);
				set.add(forward + backward_r);
				set.add(forward_r + backward);
				set.add(forward_r + "" + backward_r);
				set.add(backward + forward);
				set.add(backward + forward_r);
				set.add(backward_r + forward);
				set.add(backward_r + "" + forward_r);
				
			}
			
			System.out.println(set.size());
		}
		
	}

}

Measured memory_bytes: 13000
s = int(input())
MOD = 1000000007
dp = [0] * (s+1)
dp[0] = 1
for i in range(1, s+1):
    for j in range(0, (i-3)+1):
        dp[i] += dp[j]
        dp[i] %= MOD

print(dp[s])

Measured memory_bytes: 9220
def gcd(a,b)
  return a if b == 0
  gcd(b,a%b)
end

N=gets.to_i
a=gets.chomp.split.map(&:to_i)
l=[0]
r=[0]
a.each_with_index do |v|
  l << gcd(v,l[-1])
end

a.reverse.each_with_index do |v|
  r << gcd(v,r[-1])
end

ans=0
0.upto(N) do |i|
  tmp = gcd(l[i],r[N-1-i])
  ans = tmp if ans < tmp
end
puts ans


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

using namespace std;

int main()
{
	string S, T;
	cin >> S >> T;
	int ans = 0;
	for (int i = 0; (size_t)i < S.size(); i++) {
		if (S[i] == T[i]) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    
    
    int a, b, c;
    int A, B, C;
    
    do{
        scanf("%d", &A);
      
    }while(A<1 || A>10);
    
    do{
        scanf("%d", &B);
        
    }while(B<1 || B>10);
    
    do{
        scanf("%d", &C);
        
    }while(C<1 || C>10);
    
    
    if(A==B){
        if(B==C)
            printf("No \n");
        else
            printf("Yes \n");
    }
    else{
        if(B==C || A==C)
            printf("Yes \n");
        else
            printf("No \n");
        
    }
    
	return 0;
}



Measured memory_bytes: 128
using System;

namespace AtCoderBeginnerContest178
{
	class Program
	{
		static void Main(string[] args)
		{
			var input = int.Parse(Console.ReadLine());
			if(input == 1)
			{
				Console.WriteLine("0");
			}
			else
			{
				Console.WriteLine("1");
			}
		}
	}
}


Measured memory_bytes: 27500
#include<cstdio>
#include<map>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<set>

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

using namespace std;

int main(){
	int n,m;cin>>n>>m;
	int a = n-1,b = m-1;
	cout << a*b << endl;
	return 0;
}


Measured memory_bytes: 256
##C
a,b = map(int,input().split())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

aa = (prime_factorize(a))
bb = (prime_factorize(b))

def f(a1, b1):
  result = []
  for i in sorted(set(a1 + b1)):
    aa1 = [x for x in a1 if x == i]
    bb1 = [x for x in b1 if x == i]
    result += aa1 if len(aa1) < len(bb1) else bb1
  return result

from operator import mul
from functools import reduce

aabb1 = f(aa,bb)

if aabb1 == []:
    aabb1 = [1,1]

aabb = reduce(mul,aabb1)

print(int(a*b/aabb))

Measured memory_bytes: 3572
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

a, b, c, d = ri(), ri(), ri(), ri()
print(min(a, b) + min(c, d))















Measured memory_bytes: 27220
import heapq
n, k = map(int, input().split())
sushi = []
for _ in range(n):
    t, d = map(int, input().split())
    sushi.append((d, t-1))

sushi.sort(reverse=True)
used = [False] * n
choose = []
rest = []
cost = 0
kind = 0
for i in range(n):
    d, t = sushi[i]
    if i < k:
        cost += d
        if used[t]:
            heapq.heappush(choose, d)
        else:
            used[t] = True
            kind += 1

    else:
        if not used[t]:
            heapq.heappush(rest, -d)
        used[t] = True


cost += kind ** 2
ans = cost

cnt = min(len(choose), len(rest))
for i in range(cnt):
    cost -= heapq.heappop(choose)
    cost += -heapq.heappop(rest)
    cost += 2 * kind + 1
    kind += 1
    ans = max(ans, cost)

print(ans)


Measured memory_bytes: 63704
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Math;

class program{
    public static void Main(){
        Console.ReadLine();
        var x = Console.ReadLine().Split(' ').Select(_ => double.Parse(_)).ToList();
        var y = Console.ReadLine().Split(' ').Select(_ => double.Parse(_)).ToList();

        var d1 = x.Zip(y, (X,Y) => Abs(X-Y)).Sum();
        var d2 = Sqrt(x.Zip(y, (X,Y) => (X-Y) * (X-Y)).Sum());
        var d3 = Pow(x.Zip(y, (X,Y) => Abs(X-Y) * Abs(X-Y) * Abs(X-Y)).Sum(),1.0/3);
        var dinf = x.Zip(y, (X,Y) => Abs(X-Y)).Max();
        Console.WriteLine(d1);
        Console.WriteLine(d2);
        Console.WriteLine(d3);
        Console.WriteLine(dinf);


    }
}



Measured memory_bytes: 18528
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        final int N = sc.nextInt();
        int[] H = new int[N];
        for(int i = 0;i < N;i++)    H[i] = sc.nextInt();
        int id = 0;
        int ans = 0;
        boolean f = false;
        while(true){
            f = false;
            for(int i = 0;i < N;i++){
                if(H[i] > 0){
                    f = true;
                    ans++;
                    while(H[i] > 0){
                        H[i]--;
                        i++;
                        if(i == N)    break;
                    }
                }
            }
            if(!f)  break;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 21844
n, m = [int(x) for x in input().split(' ')]
 
edges = set([tuple(input().split(' ')) for _ in range(m)])
edges.update([(x[1], x[0]) for x in list(edges)])
 
 
def dfs(node, history):
    ans = 0
    if len(history) == n - 1:
        return 1
 
    nextnodes = [
        x[1] for x in edges if x[1] not in history and x[0] == node and x[1] != node
    ]
    history.add(node)
    for next in nextnodes:
        ans += dfs(next, history)
    history.remove(node)
    return ans
 
 
print(dfs('1', set()))

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
//#define int long long

signed main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << 9 * max({a,b,c}) + a + b + c << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void debug(String str) {
        boolean debug = false;
        if (debug != false) {
            return;
        }
        System.out.println(str);
    }

    public static void main(String[] args) {

        int N;
        String[] Sn;

        try (Scanner sc = new Scanner(System.in)) {
            N = sc.nextInt();
            Sn = new String[N];
            for (int i = 0; i < N; i++) {
                Sn[i] = sc.next();
            }
        }
        String[] sortedChar = new String[N];
        for (int i = 0; i < N; i++) {
            sortedChar[i] = sortStr(Sn[i]);
        }
        String[] sortedStr = sortStrArr(sortedChar);
        long count = 1;
        long result = 0;
        for (int i = 1; i < N; i++) {
            if (sortedStr[i].equals(sortedStr[i - 1])) {
                count++;
            } else {
                if (count == 1) {
                    continue;
                }
                result += combi2(count);
                count =1;
            }
        }
        if (count > 1) {
            result += combi2(count);
        }
        System.out.println(result);
        return;
    }

    private static String sortStr(String str) {
        char[] arr = str.toCharArray();
        Arrays.sort(arr);
        return new String(arr);
    }

    private static String[] sortStrArr(String[] strArr) {
        Arrays.sort(strArr);
        return strArr;
    }

    private static long combi2(long count) {
        return count * (count - 1) / 2;
    }
}


Measured memory_bytes: 51032
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    int d = a-b;
    if(c>d)
    {
        cout << c-d << endl;
    }
    else
    {
        cout << 0 << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 1000000007
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

const int N = 500 * 1000 + 5;
vector <int> rv[N];
set <int> st[N]; 
vector <int> par(N);
vector <bool> vis(N, false);
int even = 0, odd = 0;
bool ok = true;
void dfs(int s, int c) {
	vis[s] = true;
	par[s] = c % 2;
	even += (par[s] == 0);
	odd += (par[s] == 1);
	for (auto g : rv[s]) {
		if(!vis[g]) {
			dfs(g, c + 1);
		}
		else {
			if(par[s] == par[g])
				ok = false;
		}
	}
}
vector <pair<int, int>> A;
map <int, int> dp[705];
int func(int i, int d) {
	if(i == (int) A.size())
		return d;
	if(dp[i].find(d) != dp[i].end())
		return dp[i][d];
	int a = func(i + 1, d + (A[i].ff - A[i].ss));
	int b = func(i + 1, d + (A[i].ss - A[i].ff));
	return dp[i][d] = min(abs(a), abs(b));
}
int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		st[x].insert(y);
		st[y].insert(x);
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			if(i == j)	continue;
			if(st[i].find(j) == st[i].end()) {
				rv[i].push_back(j);
			}
		}
	}
	int total = 0;
	for (int i = 1; i <= n; i++) {
		if(!vis[i]) {
			even = 0, odd = 0;
			dfs(i, 0);			
			if(!ok) {
				cout << -1;
				return 0;
			}
			A.push_back({even, odd});
			total += (even + odd);
		}
	}
	int d = func(0, 0);
	int x = (total + d) / 2;
	int y = total - x;
	cout << x * (x - 1) / 2 + y * (y - 1) / 2;
}


Measured memory_bytes: 71808
from collections import Counter
N = int(input())
blue = [input() for _ in range(N)]
M = int(input())
red = [input() for _ in range(M)]
Cb = Counter(blue)
Cr = Counter(red)
ans = 0
for b in Cb.most_common():
    x = b[0]
    y = b[1]
    if Cr.get(x):
        ans = max(ans, y - Cr[x])
    else:
        ans = max(ans, y)
print(ans)

Measured memory_bytes: 9300
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int a,b,n;
	cin >> a >> b >> n;
	for(int i=0; i<n; i++){
		int s,f;
		cin >> s >> f;

		if(b>s && a<f){
			cout << 1 << endl;
			return 0;
		}
/*		if(b>s && b<=f){
			cout << 1 << endl;
			return 0;
	*/	
		
	}
	cout << 0 << endl;
	return 0;
}



Measured memory_bytes: 3104
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()

a = [0]*k
for i in range(k):
	a[i] = t[i::k]

ans = 0

for i in range(k):
	dp = [[0]*3 for l in range(len(a[i])+1)]
	for j in range(len(a[i])):
		if a[i][j] == 'r':
			dp[j+1][0] = max(dp[j+1][0], max(dp[j][1], dp[j][2]))
			dp[j+1][1] = max(dp[j+1][1], max(dp[j][0], dp[j][2]))
			dp[j+1][2] = max(dp[j+1][2], max(dp[j][0], dp[j][1])+p)
		elif a[i][j] == 's':
			dp[j+1][0] = max(dp[j+1][0], max(dp[j][1], dp[j][2])+r)
			dp[j+1][1] = max(dp[j+1][1], max(dp[j][0], dp[j][2]))
			dp[j+1][2] = max(dp[j+1][2], max(dp[j][0], dp[j][1]))
		else:
			dp[j+1][0] = max(dp[j+1][0], max(dp[j][1], dp[j][2]))
			dp[j+1][1] = max(dp[j+1][1], max(dp[j][0], dp[j][2])+s)
			dp[j+1][2] = max(dp[j+1][2], max(dp[j][0], dp[j][1]))
	ans += max(dp[-1][0], max(dp[-1][1], dp[-1][2]))

print(ans)

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


int main(){
  string S;
  cin>>S;
  if(S=="Sunny")
    cout<<"Cloudy"<<endl;
    else if(S=="Cloudy")
      cout<<"Rainy"<<endl;
    else
      cout<<"Sunny"<<endl;


  return 0;
}


Measured memory_bytes: 256