akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x

int main() {

  long long a[200010], N;
  long long min = 1000000001, diff = -1000000000;

  cin >> N;

  REP(i, N){
    cin >> a[i];
  }

  REP(i, N-1){
    if( ( a[i] < min ) ){
      min = a[i];
    }
    if( (a[i+1] - min) > diff ){
      diff = a[i+1] - min;
    }
  }

  cout << diff << endl;

}

/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


Measured memory_bytes: 4676
import fractions

entrada = list(map(int,input().split(" ")))

rangoMenor = entrada[0]
rangoMayor = entrada[1]
divisor1 = entrada[2]
divisor2= entrada[3]

multiplo = divisor2*divisor1// fractions.gcd(divisor1,divisor2)
cantidad = rangoMayor-rangoMenor
repetidos = rangoMayor//multiplo - rangoMenor//multiplo

if rangoMenor%divisor1==0:
	divisibles1 = rangoMayor//divisor1 +1 - rangoMenor//divisor1
else:
	divisibles1 = rangoMayor // divisor1 - rangoMenor//divisor1

divisibles2 = rangoMayor//divisor2 - rangoMenor//divisor2

resultado = cantidad -(divisibles1+divisibles2) +repetidos + 1
print(resultado)

Measured memory_bytes: 5044
import java.util.*;

public class Main {
	int [] vx = {0,1,0,-1};
	int [] vy = {1,0,-1,0};
	int ans,w,h;
	int [][] data;
	private void doit(){
		Scanner sc = new Scanner (System.in);
		while(true){
			w = sc.nextInt();
			h = sc.nextInt();
			int sx=0,sy=0;
			if(w == 0 && h == 0) break;
			data = new int[h][w];
			for(int i=0; i < h; i++){
				for(int j=0; j < w; j++){
					data[i][j] = sc.nextInt();
					if(data[i][j] == 2){
						data[i][j] = 0;
						sx = j;
						sy = i;
					}
				}
			}
			ans = 11;
			dfs(sx,sy,0);
			//System.out.print("ANS= ");
			System.out.println(ans == 11 ? -1: ans);
		}
	}

	private void dfs(int x, int y, int count) {
		if(count == 10) return ;
		//System.out.println("x= " + x + " y= " + y + " count= " + count);
		for(int i=0; i < 4;i++){
			int nextX = x + vx[i];
			int nextY = y + vy[i];
			if(! isOK(nextX, nextY)) continue;
			if(data[nextY][nextX] == 1) continue;
			while(true){
				if( isOK(nextX, nextY) && data[nextY][nextX] == 0){
					nextX += vx[i];
					nextY += vy[i];
				}
				else{
					break;
				}
			}
			if(! isOK(nextX, nextY)) continue;
			if(data[nextY][nextX] == 1){
				data[nextY][nextX] = 0;
				int stopX = nextX - vx[i];
				int stopY = nextY - vy[i];
				dfs(stopX, stopY,count + 1);
				data[nextY][nextX] = 1;
			}
			else if(data[nextY][nextX] == 3){
				ans = Math.min(ans, count+1);
			}
		}
	}
	
	private boolean isOK(int x, int y){
		if(0 <= x && x < w && 0 <= y && y < h){
			return true;
		}
		return false;
	}

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

Measured memory_bytes: 12000
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string str = Console.ReadLine();
		int N = int.Parse(str);
		string[,] S = new string[N,N];
		for(var i=0;i<N;i++){
			string t = Console.ReadLine();
			for(var j=0;j<N;j++){
				S[i,j] = t.Substring(j,1);
			}
		}
		string[,] S2 = new string[N,N];
		int count = 0;
		int A = 0;
		int B = N-1;
		while(A<N){
			int f = 1;
			for(var i=0;i<N;i++){
				for(var j=i;j<N;j++){
					if(S[(i+A)%N,(j+B)%N] != S[(j+A)%N,(i+B)%N]){
						f = 0;
						break;
					}
				}
				if(f==0){
					break;
				}
			}
			if(f==1){
				count += N-Math.Abs(A-B);
			}
			if(B > 0){
				B -= 1;
			} else {
				A += 1;
			}
		}
		Console.WriteLine(count);
	}
}

Measured memory_bytes: 16352
n,T=map(int,input().split())
a=[]
b=[]
d=[]
for i in range(n):
    c,t=map(int,input().split())
    a.append(c)
    b.append(t)
for i in range(n):
    if b[i]<=T:
        d.append(a[i])
if len(d)==0:
    print("TLE")
else:
    print(min(d))

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

int main() {
    string s;
    int w;
    cin >> s >> w;
    for (int i = 0; i < s.size(); i+=w){
        cout << s[i];
    }
    cout << endl;
}

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

const int MOD = (int)1e9+7;

int main(){
  int A,B,Q;
  cin >> A >> B >> Q;
  vector<long long> s(A);
  vector<long long> t(B);
  vector<long long> x(Q);
  for(int i=0;i<A;i++)  cin >> s.at(i);
  for(int i=0;i<B;i++)  cin >> t.at(i);
  for(int i=0;i<Q;i++)  cin >> x.at(i);

  for(int i=0;i<Q;i++){
    long long ans=1e18;
    long long q=x.at(i);
    auto sl=lower_bound(s.begin(),s.end(),q);
    auto su=upper_bound(s.begin(),s.end(),q);
    auto tl=lower_bound(t.begin(),t.end(),q);
    auto tu=upper_bound(t.begin(),t.end(),q);
    long long al=1e18;
    long long au=1e18;
    long long bl=1e18;
    long long bu=1e18;
    if(sl-s.begin()-1>=0) al=s.at(sl-s.begin()-1);
    if(su-s.begin()<s.size()) au=s.at(su-s.begin());
    if(tl-t.begin()-1>=0) bl=t.at(tl-t.begin()-1);
    if(tu-t.begin()<t.size()) bu=t.at(tu-t.begin());
    //cout << al << "," << au << "," << bl << "," << bu << endl;
    ans=min({max(abs(al-q),abs(bl-q)),max(abs(au-q),abs(bu-q)),abs(al-bu)+min(abs(al-q),abs(bu-q)),abs(au-bl)+min(abs(au-q),abs(bl-q))});
    cout << ans << endl;
  }
  
  return 0;
}


Measured memory_bytes: 3712
#include <stdio.h>

int main(){
  int X;
  scanf("%d",&X);
  if(X<=3) {
    printf("1");
    return 0;
  }
  for(int l=X;l>0;l--){
    for(int i=2;i*i<=X;i++){
      if(l%i==0){
        int k=l;
        while(k!=1){
          if(k%i==0) k/=i;
          else break;
        }
        if(k==1&&l!=i) {printf("%d",l); return 0;}
      }
    }
  }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt,ans,a,b,c,d[ohara],tmp,tmpp,m,h,w,x[ohara],y[ohara],sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

void solve1(){
    //sample1
    Cout(34);
    d[0]=1;
    d[1]=1;
    cnt=1;
    rrep(i,2,34){
        d[i]=cnt;
        cnt*=2;
    }
    sort(d,d+34);
    reverse(d,d+34);
    rep(i,34){
        if(i==33)Cout(d[i]);
        else cout<<d[i]<<" ";
    }
    rep(i,n){
        string s;
        rep(j,34){
            if(abs(x[i])<abs(y[i])){
                if(y[i]<0){
                    y[i]+=d[j];
                    s+='D';
                }
                else{
                    y[i]-=d[j];
                    s+='U';
                }
            }
            else{
                if(x[i]<0){
                    x[i]+=d[j];
                    s+='L';
                }
                else{
                    x[i]-=d[j];
                    s+='R';
                }
            }
        }
        cout<<s<<"\n";
        //cout<<x[i]<<" "<<y[i]<<"\n";
    }
}

void solve2(){
    Cout(35);
    d[0]=1;
    d[1]=1;
    d[2]=1;
    cnt=1;
    rrep(i,3,35){
        d[i]=cnt;
        cnt*=2;
    }
    sort(d,d+35);
    reverse(d,d+35);
    rep(i,35){
        if(i==34)Cout(d[i]);
        else cout<<d[i]<<" ";
    }
    rep(i,n){
        string s;
        rep(j,35){
            if(abs(x[i])<abs(y[i])){
                if(y[i]<0){
                    y[i]+=d[j];
                    s+='D';
                }
                else{
                    y[i]-=d[j];
                    s+='U';
                }
            }
            else{
                if(x[i]<0){
                    x[i]+=d[j];
                    s+='L';
                }
                else{
                    x[i]-=d[j];
                    s+='R';
                }
            }
        }
        cout<<s<<"\n";
        //cout<<x[i]<<" "<<y[i]<<"\n";
    }
}

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

    cin>>n;
    rep(i,n)cin>>x[i]>>y[i];
    rep(i,n){
        if((abs(x[i])+abs(y[i]))%2!=(abs(x[0])+abs(y[0]))%2){
            Cout(-1);
            return 0;
        }
        if((abs(x[i])+abs(y[i]))%2==1)b=1;
    }
    if(b)solve1();
    else solve2();
    return 0;
}


Measured memory_bytes: 4352
h, n = map(int, input().split())

h_map = [-1 for _ in range(h+1)]
h_map[h] = 0

ab = []
for _ in range(n):
  a,b = map(int, input().split())
  ab.append([a, b])

for i in range(1, h+1):
  h_i = h+1 - i
  
  if h_map[h_i] == -1:
    continue
   
  for a, b in ab:
    next_h = h_i - a
    if next_h <= 0:
      if h_map[0] == -1:
        h_map[0] = h_map[h_i] + b
      else:
        h_map[0] = min(h_map[0], h_map[h_i] + b)
        
    else:
      if h_map[next_h] == -1:
        h_map[next_h] = h_map[h_i] + b
      else:
        h_map[next_h] = min(h_map[next_h], h_map[h_i] + b)
        
print(h_map[0])

Measured memory_bytes: 43516
import java.util.Scanner;

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

        if (N >= 10) {
            System.out.println(R);
            return;
        }

        System.out.println(R + (100 * (10 - N)));
    }
}

Measured memory_bytes: 22228
use proconio::*;

#[fastout]

fn dfs(x: i64, ans: &mut Vec<i64>) {
    if x <= 3234566667 {
        ans.push(x);
        let k = x % 10;
        if k + 1 < 10 {
            dfs(x * 10 + k + 1, ans);
        }
        if k - 1 >= 0 {
            dfs(x * 10 + k - 1, ans);
        }
        dfs(x * 10 + k, ans);
    }
}

fn main() {
    input! {
        k: i64,
    }
    let mut ans = vec![];
    for i in 1..=9 {
        dfs(i, &mut ans);
    }
    ans.sort();
    println!("{}", ans[k as usize - 1]);
}


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

typedef unsigned long long ull;

int main(){
  int z;
  while(cin >> z, z){
    ull ans = 1e+9;

    for(ull x = 1 ; x*x*x < z*z*z ; x++){
      for(ull y = 1 ; x*x*x + y*y*y < z*z*z ; y++){
	ull tmp = z*z*z - x*x*x - y*y*y;
	ans = min(ans, tmp);
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 868
#include <iostream>
#include <numeric>
#include <set>
using namespace std;
using ll = long long;

// 入出力
void print() { std::cout << '\n'; }
template <class T>void print(const T &x) {std::cout << x <<'\n';}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}

int main(){
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    long long N;
    scanf("%lld",&N);
    std::set<long long> d;
    for(int i = 0 ; i < N ; i++){
        ll tmp;
        cin >> tmp;
        d.insert(tmp);
    }
    // cout << d.size() << '\n';
    print(d.size());
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int bingo[4][4][3]={0};
    int b[11]={0};
    int n;
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            scanf("%d",&bingo[i][j][1]);
        }
    }
    scanf("%d",&n);
    for(int k=0;k<n;k++){
        scanf("%d",&b[k]);
    }

    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<n;k++){
                if(bingo[i][j][1]==b[k]){
                    bingo[i][j][2]=1;
                }
            }
        }
    }

    if(bingo[0][0][2]==1){
        if(bingo[1][0][2]==1){
            if(bingo[2][0][2]==1){
                printf("Yes");
                return 0;
            }
        }
        if(bingo[0][1][2]==1){
            if(bingo[0][2][2]==1){
                printf("Yes");
                return 0;
            }
        }
        if(bingo[1][1][2]==1){
            if(bingo[2][2][2]==1)
            printf("Yes");
            return 0;
        }
    }
    if(bingo[0][1][2]==1){
        if(bingo[1][1][2]==1){
            if(bingo[2][1][2]==1){
                printf("Yes");
                return 0;
            }
        }
    }
    if(bingo[0][2][2]==1){
        if(bingo[1][1][2]==1){
            if(bingo[2][0][2]==1){
                printf("Yes");
                return 0;
            }
        }
        if(bingo[1][2][2]==1){
            if(bingo[2][2][2]==1){
                printf("Yes");
                return 0;
            }
        }
    }
    if(bingo[1][0][2]==1){
        if(bingo[1][1][2]==1){
            if(bingo[1][2][2]==1){
                printf("Yes");
                return 0;
            }
        }
    }
    if(bingo[2][0][2]==1){
        if(bingo[2][1][2]==1){
            if(bingo[2][2][2]==1){
                printf("Yes");
                return 0;
            }
        }
    }
    printf("No");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <climits>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#define MAX 1000000007


using namespace std;
#define ll long long
#define dbg if(0)
#define ISRANGE(val,lo,hi) ((lo<=val)&&(val<hi))

//ダブり→一緒に抜き出せば確実に1,2枚は減らせる
//→ダブっているものを選んで減らすという行為を繰り返せばいい

int main(){
    ll ans=0,n,n2;
    cin >>n>>n2;
    cout <<n-n2+1<<endl;

    return 0;

}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 500010

int heap[MAX];

void swap(int i, int j) {
	int buf = heap[i];
	heap[i] = heap[j];
	heap[j] = buf;
}

void maxHeap(int H, int i) {
	int l = 2 * i, r = 2 * i + 1;
	int largest = i;
	if (l <= H && heap[l] > heap[i])largest = l;
	if (r <= H && heap[r] > heap[largest])largest = r;
	if (largest != i) {
		swap(i, largest);
		maxHeap(H, largest);
	}
}

void buildMaxHeap(int H) {
	for (int i = H / 2; i >= 1; i--) {
		maxHeap(H, i);
	}
}

int main() {
	int H;

	scanf("%d", &H);
	for (int i = 1; i <= H; i++) {
		scanf("%d", &heap[i]);
	}
	buildMaxHeap(H);
	for (int i = 1; i <= H; i++) {
		printf(" %d", heap[i]);
	}
	printf("\n");

	return 0;
}


Measured memory_bytes: 3808
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}

int main(){
    int a,b,c,d;
    in(a,b,c,d);
    out(a+b+c+d);
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)

typedef long long ll;

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

void solve(long long K)
{
    ll ans = 0;
    rep1(i, K + 1)
    {
        rep1(j, K + 1)
        {
            rep1(k, K + 1) { ans += gcd(i, gcd(j, k)); }
        }
    }
    cout << ans << endl;
}

int main()
{
    long long K;
    scanf("%lld", &K);
    solve(K);
    return 0;
}


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

int main(){
  string s;
  cin >> s;
  string mm;
 
  if(s.at(5) == '1' || s.at(6) == '5' || s.at(6) == '6' ||s.at(6) == '7' || s.at(6) == '8' || s.at(6) == '9'){
    cout << "TBD" << endl;
  }
  else {
    cout << "Heisei" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    in_arr(int, a, n);
    int mi, ma;
    mi = accumulate(a.begin(), a.end(), INT_MAX, [](int a, int b){ return min(a, b); });
    ma = accumulate(a.begin(), a.end(), INT_MIN, [](int a, int b){ return max(a, b); });
    int ans = INT_MAX;
    for(int i = mi; i <= ma; ++i){
        int cost = 0;
        repi(j, a){
            cost += (*j - i) * (*j - i);
        }
        ans = min(cost, ans);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define OUT(a) cout<<(a)<<endl
#define VECIN(type, c, n) vector<type> c(n);for(auto& i:c) cin>>i;


int main(){
	int a,b;
	cin>>a>>b;
	int ans=-1;
	for(int i=1;i<=1250;i++){
		if(((int)(0.08*i)==a)&&((int)(0.1*i)==b)){
			ans=i;
			break;
		}
	}
	OUT(ans);
	return 0;
}

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++)
int in(){int x; scanf("%d",&x); return x;}
static const int MAX = 10000;


int main(){
  int A = in(), B = in(), ans;
  
  ans = A-2*B;
  if(ans <= 0) cout << 0 << endl;
  else cout << ans << endl;
}


Measured memory_bytes: 256
N, K = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)

if K == 1
  puts 0
  exit
end

RUI = [0]

A.map { |a| a - 1 }.each do |a|
  RUI << (RUI.last + a) % K
end

counter = Hash.new(0)
counter[0] += 1

ans = 0

1.upto(N) do |i|
  r = RUI[i]
  ans += counter[r]
  counter[r] += 1

  j = i - K + 1
  counter[RUI[j]] -= 1 if j >= 0
end

puts ans


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

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	string s;
	cin>>s;
	int n=s.size();
	int i=0,j=n-1;
	while(i<n&&s[i]!='A') ++i;
	while(~j&&s[j]!='Z') --j;
	cout<<(i>j?0:j-i+1)<<'\n';
}




Measured memory_bytes: 3708
def input_int():
    return map(int, input().split())

def one_int():
    return int(input())

def one_str():
    return input()

def many_int():
    return list(map(int, input().split()))

N=one_int()

A=many_int()
A=sorted(A)

out = 10**18
output = 1
for a in A:
    output *= a
    if output>out:
        output=-1
        break
print(output)

Measured memory_bytes: 21612
#include<stdio.h>
#include<iostream>
using namespace std;
int p[100][100];
int main(){
int w,h,i,j;
char c[201];
cin>>h>>w;
for(i=0;i<h;i++){
scanf("%s",c);
for(j=0;j<w;j++){
if(c[j]=='c')p[i][j]=0;
else p[i][j]=-1;
}
}
for(i=0;i<h;i++){
for(j=1;j<w;j++){
if(p[i][j-1]>=0&&p[i][j]<0)p[i][j]=p[i][j-1]+1;
}
}
for(i=0;i<h;i++){
for(j=0;j<w;j++){
cout<<p[i][j];
if(j!=w-1)cout<<' ';
}
cout<<endl;
}
return 0;
}

Measured memory_bytes: 3244
take3s [x1,x2,x3] = [[x1,x2,x3]]
take3s (x1:x2:x3:xs) = [x1,x2,x3] : take3s (x2:x3:xs)
sub = (-)

main = minimum . map (abs.(`sub`753).read) . take3s <$> getLine >>= print


Measured memory_bytes: 508
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;

int main(){
    int k,x;
    cin>>k>>x;
    cout<<(500*k>=x ? "Yes":"No")<<endl;
    return 0;
}

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

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

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

using namespace std;

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

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

template <class T, class U>
std::ostream& operator<<(std::ostream &os, const std::pair<T, U> &p) {
	os << "(" << p.first << ", " << p.second << ")";
	return os;
}
 
template <class T>
std::ostream& operator<<(std::ostream &os, const std::vector<T> &v) {
    os << "[";
	for (int i = 0; i < v.size(); ++i) {
        if (i) {
            if (i % 5 == 0) {
                os << ",\n ";
            } else {
                os << ", ";
            }
        }
		os << v[i];
	}
	os << "]";
	return os;
}

template <class T>
using vec2 = vector<vector<T>>;

template <class T>
using vec3 = vector<vector<vector<T>>>;

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

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

    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    ll money = 1000;
    ll stock = 0;

    REP(i, N - 1) {
        if (A[i] < A[i + 1]) {
            stock += money / A[i];
            money %= A[i];
        } else {
            money += stock * A[i];
            stock = 0;
        }
    }

    money += stock * A[N - 1];

    cout << money << endl;

    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

int main()
{
    string s;
    cin >> s;
    int a = -1, z;
    rep(i, 0, s.size())
    {
        if (a == -1 && s[i] == 'A')
            a = i;
        if (s[i] == 'Z')
            z = i;
    }
    cout << z-a+1;
    return 0;
}

Measured memory_bytes: 640
from collections import defaultdict


def factorize(n: int) -> dict:
    f = defaultdict(int)
    while n % 2 == 0:
        f[2] += 1
        n //= 2
    p = 3
    while p * p <= n:
        while n % p == 0:
            f[p] += 1
            n //= p
        p += 2
    if n != 1:
        f[n] += 1
    return f


n, p = map(int, input().split())
fact = factorize(p)
ans = 1
for k, v in fact.items():
    ans *= k**(v // n)
print(ans)


Measured memory_bytes: 9396
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0);
#define endl '\n'
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    int a, b;
    cin >> a >> b;
    int cnt = 0;
    for (int i = a; i <= b; i++) {
        string cur = to_string(i);
        bool ok = 1;
        forn(i, sz(cur) / 2) {
            if (cur[i] != cur[sz(cur) - i - 1]) {
                ok = 0;
                break;
            }
        }
        if (ok) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
void solve()
{
   cin>>s;
   ll sum=0;
   ll N=s.length();
   for(ll i=0;i<N;i++)
   {
       sum+=s[i]-'0';
   }
   if(sum%9==0)
   cout<<"Yes"<<"\n";
   else
   {
       cout<<"No\n";
   }
   
}
signed main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    solve();
}

Measured memory_bytes: 3748
try:
    from math import gcd
except:
    from fractions import gcd
import operator
from collections import deque


class Segtree:
    """
    st = Segtree(4, f=operator.add, e=0)
    st[1:] = [4, 9, 16]
    st[0] = -99
    assert st[-1] == 16
    assert st[:] == [-99, 4, 9, 16]
    assert st.grasp(1, 3) == 13
    """

    def __init__(self, n, f=operator.add, e=0):
        """all(f(v, e) == f(e, v) == v for v in data)"""
        self.r = range(n)
        self.size = 2 ** ((n - 1).bit_length())
        self.tree = [e] * (2 * self.size)
        self.f = f
        self.iden = e

    def __len__(self):
        return len(self.r)

    def __list__(self):
        return self.tree[self.size-1:self.size-1+len(self.r)]

    def __repr__(self):
        return repr(list(self))

    def grasp(self, i=0, j=None):
        """reduce(f, data[i:j], e)"""
        if j is None:
            j = len(self)
        i = self.size - 1 + max(i, 0)
        j = self.size - 1 + min(j, len(self))
        ans = self.iden
        while j - i > 0:
            if i & 1 is 0:
                ans = self.f(self.tree[i], ans)
            if j & 1 is 0:
                ans = self.f(ans, self.tree[j-1])
            i = i >> 1
            j = (j - 1) >> 1
        return ans

    def __getitem__(self, i):
        r = self.r[i]
        if isinstance(r, int):
            return self.tree[self.size - 1 + r]
        else:
            return [self.tree[self.size - 1 + ri] for ri in r]

    def __setitem__(self, i, v):
        """Extra elements will be ignored when i is a slice."""
        r = self.r[i]
        if isinstance(r, int):
            r = [r]
            v = [v]
        q = deque()
        s = set()

        def addnext(j):
            k = (j - 1) // 2
            if k >= 0 and k not in s:
                q.append(k)
                s.add(k)

        for ri, vi in zip(r, v):
            j = self.size - 1 + ri
            self.tree[j] = vi
            addnext(j)
        while len(q):
            j = q.popleft()
            # s.remove(j)
            vl = self.tree[2 * j + 1]
            vr = self.tree[2 * j + 2]
            self.tree[j] = self.f(vl, vr)
            addnext(j)


N = int(input())
A = [int(s) for s in input().split()]
st = Segtree(N, f=gcd, e=0)
st[:] = A
ans = max([gcd(st.grasp(0, i), st.grasp(i+1)) for i in range(N)])
print(ans)


Measured memory_bytes: 109536
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int P,Q,M; cin >> P >> Q >> M;
    vector<int> A(P),B(Q),x(M),y(M),c(M);
    rep(i,P) cin >> A[i];
    rep(i,Q) cin >> B[i];
    rep(i,M) cin >> x[i] >> y[i] >> c[i];
    int ans = *min_element(all(A)) + *min_element(all(B));
    rep(i,M) {
        --x[i]; --y[i];
        chmin(ans,A[x[i]]+B[y[i]]-c[i]);
    }

    cout << ans << ln;

}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
const int maxn = 1e5+5;
ll f[maxn],sum[maxn];
int a[maxn];
ll qpow(ll a,ll b){
	ll res = 1;
	while(b){
		if(b & 1) res = (res*a)%mod;
		a = (a*a)%mod;
		b >>= 1;
	}
	return res%mod;
}
ll inv(ll a){return qpow(a,mod-2);}

void table(int n,int k){
	if(k == 0) for(int i = 0;i <= n;i++) f[i] = 1;
	else{
		for(int i = 0;i <= k;i++) f[i] = 1;
		for(int i = k+1;i <= n;i++) f[i] = ((f[i-1]*i)%mod)*inv(i-k)%mod;
	}
	return ;
}

int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    table(n,k-2);  
	for(int i = 1;i <= n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);	
	sum[0] = 0;
	for(int i = 1;i <= n;i++) sum[i] = sum[i-1]+a[i];
	if(k == 1){
		printf("0\n");
		return 0;
	}
	else if(k == n){printf("%d\n",a[n]-a[1]);return 0;}
	else{
		ll ans = 0;
		for(int i = k-2;i <= n-2;i++){
			ll t1 = (sum[n]-sum[i+1])%mod;
			ll t2 = (sum[n-i-1])%mod;
			ans = (((t1-t2)%mod*f[i]%mod)+ans)%mod;
		}
		printf("%lld\n",(ans+mod)%mod);
	}
    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e5)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
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; }
typedef pair <ll,ll> P;

int main()
{
    ll N;
    cin >> N;
    ll cnt = 0;
    rep(i, N) {
        ll tmp = i+1;
        ll d = 0;
        while(tmp > 0) {
            d++;
            tmp /= 10;
        }
        if (d % 2 == 1) cnt++;
    }
    print(cnt);
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <limits>
#include <iomanip>

using namespace std;
double dp[301][301][301];
int N;
double rec(int one, int two, int three){
//   cout << one << ", " << two <<", "<< three <<", "<< endl;
   if(one==0&&two==0&&three==0) return 0;
   if(one<0 || two < 0 || three < 0 ) return 0;
   if(dp[one][two][three]>=0) return dp[one][two][three];
   double ans = N;
   ans += one * rec(one-1, two, three);
   ans += two * rec(one+1, two-1, three);
   ans += three * rec(one, two+1, three-1);
   return dp[one][two][three] = ans / (one+two+three); 
}

int main(){
  cin >> N;
  for(int i = 0 ; i < 301; i++){
     for(int j = 0 ; j < 301; j++){
        for(int k = 0 ; k < 301; k++){
           dp[i][j][k] = -1;
        }
     }
  }
  int cnt[3];
  memset(cnt,0,sizeof(cnt));
  for(int i = 0 ; i < N; i++){
     int a;
     cin >> a;
     a--;
     cnt[a]++;
  }
  cout << fixed << setprecision(15) << rec(cnt[0], cnt[1], cnt[2]) << endl;
  return 0;
}


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

typedef unsigned uint;
typedef long long INT;
typedef unsigned long long UINT;
const int INF = 1001001001;
const INT INFLL = 1001001001001001001LL;

 int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
INT lin() { INT x; scanf("%lld", &x); return x; }

int main(){
    int a, b, c;
    double fa, fb, fc;
    char S[128], sa[128], sb[128], sc[128];
    // int N = in();
    // int K = in();
    // scanf("%s", S);

    int N = in();

    vector<string> vecStr;
    for (int i = 0; i < N; ++i) {
        scanf("%s", S);
        vecStr.push_back(string(S));
    }
    sort(vecStr.begin(), vecStr.end());
    vecStr.erase(unique(vecStr.begin(), vecStr.end()), vecStr.end());

    printf("%d", vecStr.size());

    return 0;
}







Measured memory_bytes: 11664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, int(n) + 1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
const int MOD = 1000000007;

template <typename T>
void __dump__(std::ostream &os, const T &first) {
    os << first;
}
template <typename First, typename... Rest>
void __dump__(std::ostream &os, const First &first, const Rest &... rest) {
    os << first << ", ";
    __dump__(os, rest...);
}
#define dump(...)                                         \
    do {                                                  \
        std::ostringstream os;                            \
        os << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; \
        __dump__(os, __VA_ARGS__);                        \
        std::cerr << os.str() << std::endl;               \
    } while (0)

int h, w, k;
char g[1010][1010];
int d[1010][1010];

const int INF = 1e9;
using pii = pair<int, int>;

void bfs(int si, int sj) {
    auto is_valid = [&](int i, int j) {
        if (i < 0 || i >= h || j < 0 || j >= w) return false;
        if (g[i][j] == '#') return false;
        return true;
    };

    auto get_next = [&](int ci, int cj) {
        static const pii dir[] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
        vector<pii> res;
        for (auto &d : dir) {
            int ni = ci + d.first;
            int nj = cj + d.second;
            if (is_valid(ni, nj)) res.emplace_back(ni, nj);
        }
        return res;
    };

    queue<pii> q;
    rep(i, h) rep(j, w) d[i][j] = INF;
    d[si][sj] = 0;
    q.emplace(si, sj);
    while (q.size()) {
        int ci, cj;
        tie(ci, cj) = q.front();
        q.pop();
        const vector<pii> next = get_next(ci, cj);
        for (auto &nx : next) {
            int ni, nj;
            tie(ni, nj) = nx;
            int nd = d[ci][cj] + 1;
            if (d[ni][nj] > nd) {
                d[ni][nj] = nd;
                q.emplace(ni, nj);
            }
        }
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    while (cin >> h >> w >> k) {
        rep(i, h) cin >> g[i];
        int si = -1, sj = -1;
        rep(i, h) rep(j, w) if (g[i][j] == 'S') {
            si = i, sj = j;
        }
        bfs(si, sj);
        int ans = INF;
        rep(i, h) rep(j, w) {
            if (d[i][j] <= k) {
                int cd = INF;
                cd = min(cd, i);
                cd = min(cd, w - j - 1);
                cd = min(cd, j);
                cd = min(cd, h - i - 1);
                ans = min(ans, (cd + k - 1) / k);
            }
        }
        cout << ans + 1 << endl;
    }
}


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

using namespace std;

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

  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int count = 0;
  for(int i = 0; i < n; i++) {
    if (!(a[i] % 2)) count++;
  }

  cout << count << endl;
}



Measured memory_bytes: 3100
#include<bits/stdc++.h>
#define fo(i,a,b) for(register int (i)=(a);(i)<=(b);++(i))
#define rd read()
#define maxn 200001
#define gc getchar()
#define mem(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define pb push_back
#define db double
#define pu puts(" ")
using namespace std;
const int p=998244353;
int read()
{
	int x=0,f=1;
	char ch=gc;
	while(!isdigit(ch))
	{
		if(ch=='-')f=-1;
		ch=gc;
	}
	while(isdigit(ch))x=x*10+ch-48,ch=gc;
	return x*f;
}
void print(int x)
{
	if(x<0)putchar('-'),x=-x;
	if(x>9)print(x/10);
	putchar(x%10+48);
}
int qp(int a,int b)
{
	int ans=1;
	while(b)
	{
		if(b&1)ans=(ll)ans*a%p;
		a=(ll)a*a%p;
		b>>=1;
	}
	return ans;
}

int main()
{
   int a=rd,b=rd;
   printf("%d\n",a-b+1);
	return 0;
}

Measured memory_bytes: 256
/**
 * 3 ????????°?????´???

???????????´??°?????????????????????????????????????°??????????????????????????????????????????°?????????????????????????????????

Input
???????????´??°???????????§????????????????????????????????????

Output
?°???????????????????????????????????????´??°??????????????????????????????????????´??°?????????????????????????????\??????????????????

Constraints
1 ??? ???????????´??° ??? 10,000
Sample Input
3 8 1
Sample Output
1 3 8
 */

#include <algorithm>
#include <iostream>
#include <sstream>
#include <vector>
#include <iterator>

int main(int argc, char const *argv[]) {
  unsigned int a, b, c;
  a = b = c = 1;

  while (true) {
    std::string param;

    getline(std::cin, param);
    std::istringstream iss(param);
    iss >> a >> b >> c;

    if ((a < 1 || a > 10000) || (b < 1 || b > 10000) || (c < 1 || c > 10000)) {
      std::cout << "Error: 1 <= a, b, c <= 10000" << std::endl;
    } else {
      break;
    }
  }

  std::vector<unsigned int> v = {a, b, c};
  std::sort(v.begin(), v.end());

  std::ostringstream oss;
  std::copy(v.begin(), v.end() - 1,
            std::ostream_iterator<unsigned int>(oss, " "));
  oss << v.back();
  std::cout << oss.str() << std::endl;
  return 0;
}

Measured memory_bytes: 3160
#include <iostream>
#include <set>

using namespace std;

int main(void)
{
	multiset<int> s;
	int i1;
	int h;

	for(i1=0;i1<10;i1++){
		cin>>h;
		s.insert(h);
	}

	multiset<int>::reverse_iterator rit=s.rbegin();
	for(i1=0;i1<3;i1++){
		cout<<(*rit)<<endl;
		rit++;
	}

	return 0;
}

Measured memory_bytes: 1196
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	static int[][] map;
	static int[][] directions8= {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
	static int[][] directions4= {{-1,0},{1,0},{0,-1},{0,1}};
	static int ans;
	static int[] A;
	static int K;//union-find用

	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		 K = sc.nextInt();

		A = new int[N];
//		PriorityQueue<Wood> q = new PriorityQueue<>(Collections.reverseOrder());
//
		for(int i = 0;i<N ; i++) {
			A[i] = sc.nextInt();
		}

		ans = 0;

		double ub =Integer.MAX_VALUE;
		double lb = 0;
		int idx = 0;
		while(ub - lb > 0.000001) {
			double mid = (ub + lb)/2;
			if(hantei(mid)) {
				lb = mid;
				}else {
					ub = mid;
				}
			}


		System.out.println((int)Math.ceil(lb));
	}




	static boolean hantei(double length) {
		int num = 0;
		for(int i = 0;i<A.length ; i++) {
			num+=(int)(A[i]/length);
		}
		return num >= K+1;
	}

	//素数判定
	public static boolean isPrime(long num) {
		if (num < 2) return false;
		else if (num == 2) return true;
		else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

		double sqrtNum = Math.sqrt(num);
		for (int i = 3; i <= sqrtNum; i += 2)
		{
			if (num % i == 0)
			{
				// 素数ではない
				return false;
			}
		}

		// 素数である
		return true;
	}

	//BFS用に二つの配列を足し算する
	static int[] addArrayElms(int[] a, int[] b) {
		int[] c = new int[a.length];
		for(int i = 0; i < a.length; i++) {
			c[i] = a[i] + b[i];
		}
		return c;
	}

	//	//二分探索
	//k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, int[] a){
		int lowerBorder = -1;
		int upperBorder = a.length;
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(a[mid]<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//二分探索
	//k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList){
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedList.get(mid)<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
		return b == 0 ? a: gcd(b, a % b);
	}
	public static long gcd(long a, long b) {
		return b == 0 ? a: gcd(b, a % b);
	}

	//Union-Find用の配列を要素数nで初期化
//	static void ufInit(int n){
//		parent = new int[n];
//		rank = new int[n];
//	}
//
//	//Union-Findの要素の最上位の親（グループ名）を返す
//	static int ufFind(int a) {
//		if(parent[a]==a) {
//			return a;
//		}else {
//			return ufFind(parent[a]);
//		}
//	}
//
//	//Union-Find木を連結する
//	static void ufUnite(int a, int b) {
//		a = parent[a];
//		b = parent[b];
//
//		if(a==b) {
//			return;
//		}
//		if(rank[a] > rank[b]){
//			parent[b]=a;
//		}else {
//			parent[a]=b;
//			if(rank[a]==rank[b]) {
//				rank[b]++;
//			}
//		}
////	}
//
//	static boolean ufSame(int a, int b) {
//		return ufFind(a)==ufFind(b);
//	}
//}

}


Measured memory_bytes: 60180
#include<bits/stdc++.h>
#define maxn 1010
#define inf 1000000007
using namespace std;
typedef long long ll;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,p1,p2,p3,p4,s,t;
int head[maxn*2],nxt[maxn*20],to[maxn*20],c[maxn*20],v[maxn*20],tot=1;
void add(int x,int y,int z,int u)
{
    ++tot;
    nxt[tot]=head[x];
    head[x]=tot;
    to[tot]=y;
    c[tot]=z;
    v[tot]=u;
}
void addx(int x,int y,int z,int u)
{
    add(x,y,z,u);
    add(y,x,0,-u);
}
ll ans;
ll dis[maxn*2];
int pre[maxn*2],pre_num[maxn*2],vis[maxn*2];
queue<int>q;
int spfa()
{
    for(int i=1;i<=t;i++)  dis[i]=-1e16;
    q.push(s);dis[s]=0;vis[s]=1;
    while(q.size())
    {
        int now=q.front();q.pop();vis[now]=0;
        for(int i=head[now];i;i=nxt[i])
        {
            if(dis[to[i]]<dis[now]+v[i]&&c[i])
            {
                dis[to[i]]=dis[now]+v[i];
                pre[to[i]]=now;
                pre_num[to[i]]=i;
                if(!vis[to[i]])  q.push(to[i]),vis[to[i]]=1;
            }
        }
    }
    if(dis[t]==-1e16)  return 0;
    int di=inf;
    for(int i=t;i!=s;i=pre[i])  di=min(di,c[pre_num[i]]);
    for(int i=t;i!=s;i=pre[i])  c[pre_num[i]]-=di,c[pre_num[i]^1]+=di;
    ans+=dis[t]*di;
    return di;
}
int main()
{
    n=read();p1=2*n+1;p2=p1+1;p3=p2+1;p4=p3+1;s=p4+1;t=s+1;
    for(int i=1;i<=n;i++)
    {
        int x=read(),y=read(),z=read();
        addx(s,i,z,0);
        addx(i,p1,inf,x+y);
        addx(i,p2,inf,x-y);
        addx(i,p3,inf,-x+y);
        addx(i,p4,inf,-x-y);
    }
    for(int i=1;i<=n;i++)
    {
        int x=read(),y=read(),z=read();
        addx(i+n,t,z,0);
        addx(p1,i+n,inf,-x-y);
        addx(p2,i+n,inf,-x+y);
        addx(p3,i+n,inf,x-y);
        addx(p4,i+n,inf,x+y);
    }
    while(spfa()){};
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 4088
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>

// ===============================================================
//using系

using namespace std;
using ll = long long;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using vs = vector<string>;
using vc = vector<char>;
using vcc = vector<vector<char>>;
using vm = vector<short>;
using vmm = vector<vector<short>>;
using pii = pair<int, int>;
using psi = pair<string, int>;
using ld = long double;
using ull = unsigned long long;
using ld = long double;
using qul = queue<ll>;
using pql = priority_queue<ll>;

// ========================================================================
//define系

//#define int long long;
#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i <= n; i++)

// ========================================================================


ll gcd(ll a, ll b)
{
	if (a % b == 0)
	{
		return(b);
	}
	else
	{
		return(gcd(b, a % b));
	}
}
//最大公約数
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
//最小公倍数
ll box(double a)
{
	ll b = a;
	return b;
}
//切り捨て
ll fff(double a)
{
	ll b = a + 0.5;
	return b;
}
//四捨五入
ll mch(ll n) {
	if (n == 1) return 1;
	else return n * mch(n - 1);
}
//1から整数nまでの階乗を出す(INFで割っていない)
bool prime(ll a)//素数判定、primeならtrue,違うならfalse
{
	if (a < 2) return false;
	else if (a == 2) return true;
	else if (a % 2 == 0) return false;
	double m = sqrt(a);
	for (int i = 3; i <= m; i += 2)
	{
		if (a % i == 0)
		{
			return false;
		}
	}

	// 素数である
	return true;
}
//素数判定
ll modpow(ll a, ll n, ll mod) {
	ll hi = 1;
	while (n > 0) {
		if (n & 1) hi = hi * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return hi;
}
//いろいろやります（ただの前座）
ll mg(ll a, ll mod) {
	return modpow(a, mod - 2, mod);
}
//割り算の10^9+7等対策で逆元を出します 




// ========================================================================


/*signed*/int main() {
	ll n; cin >> n;
	vl a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	vl dp(n);
	dp[0] = 0;
	dp[1] = abs(a[1] - a[0]);
	for (int i = 2; i < n; i++) {
		dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
	}
	cout << dp[n - 1] << endl;

	return 0;
}

Measured memory_bytes: 4840
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define PI 3.14159265358979323846
using namespace std;

int main() {
    long double a, b, h, m;
    cin >> a >> b >> h >> m;

    long double rad = (30 * h + m / 2 - 6 * m) * PI / 180;

    long double d = (a * a + b * b) - 2 * a * b * cos(rad);

    cout << fixed << setprecision(20) << sqrt(d) << endl;


}

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

using namespace std;

typedef long long ll;

const long long MOD = 1000000007;

vector< vector<ll> > product(vector< vector<ll> > A, vector< vector<ll> > B){
	int height = A.size(), width = B[0].size(), n = B.size();
	
	vector< vector<ll> > C(height, vector<ll>(width, 0));
	
	for(int i=0;i<height;++i){
		for(int j=0;j<width;++j){
			for(int k=0;k<n;++k){
				C[i][j] += (A[i][k] * B[k][j]) % MOD;
                C[i][j] %= MOD;
			}
		}
	}
	
	return C;
}

vector< vector<ll> > matrix_pow(vector< vector<ll> > A, ll t) {
    int n = A.size();
    vector< vector<ll> > B(n, vector<ll>(n, 0));
    for(int i=0;i<n;++i) B[i][i] = 1;
    while(t){
        if(t & 1){
            B = product(B, A);
        }
        A = product(A, A);
        t >>= 1;
    }
    return B;
}

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

    vector< vector<ll> > A(n, vector<ll>(n));
    for(int i=0;i<n;++i) for(int j=0;j<n;++j) cin >> A[i][j];

    vector< vector<ll> > B = matrix_pow(A, k);
    ll ans = 0LL;
    for(int i=0;i<n;++i) for(int j=0;j<n;++j) {
        ans += B[i][j];
        ans %= MOD;
    }

    cout << ans << "\n";
}

Measured memory_bytes: 384