akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

//Adaptive Time Slicing Quantization
public class Main{

	int n, M, L, INF = 1<<29;
	double res;
	double[] a;
	double[][] dp;
	
	double bs(double min, double max, double x){
		int l = 1, r = 1<<L;
		while(r-l>1){
			int m = (l+r)/2;
			double v = min+(m-1)*(max-min)/((1<<L)-1);
			if(v<x)l=m;
			else r=m;
		}
		double lv = min+(l-1)*(max-min)/((1<<L)-1), rv = min+(r-1)*(max-min)/((1<<L)-1);
		return Math.abs(x-lv)<Math.abs(x-rv)?lv:rv;
	}
	
	double get(int k, int m){
		if(n==k){
			return m==0?0:INF;
		}
		if(m<0)return INF;
		if(dp[k][m]!=-1)return dp[k][m];
		if(n<=k+1)return INF;
		double min = a[k], max = a[k], res = INF;
		for(int i=k+1;i<n;i++){
			min = Math.min(min, a[i]); max = Math.max(max, a[i]);
			if(n<i+1+2*(m-1))break;
			double e = 0;
			for(int j=k;j<=i;j++){
				double s = bs(min, max, a[j]);
				e += (s-a[j])*(s-a[j]);
			}
			res = Math.min(res, e+get(i+1, m-1));
		}
		return dp[k][m] = res;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			n = sc.nextInt(); M = sc.nextInt(); L = sc.nextInt();
			if((n|M|L)==0)break;
			a = new double[n];
			for(int i=0;i<n;i++)a[i]=sc.nextDouble();
			dp = new double[n][M+1];
			for(double[]d:dp)Arrays.fill(d, -1);
			System.out.printf("%.8f\n", get(0, M));
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 14000
n=int(input());y=[list(map(int,input().split())) for i in range(n-1)]
for s in range(n):
  x=0
  for k,g in enumerate(y[s:]):
    a,b,c=g[0],g[1],g[2]
    if k==0:x=b+a
    elif x>b:
      if (x-b)%c==0:x=x+a
      else:x=(x//c+1)*c+a
    elif x<b:x=b+a
  print(x)

Measured memory_bytes: 3188
import scala.io.Source

object Main extends App {
  case class State[S, A](run: S => (S, A)) {
    def map[B](f: A => B): State[S, B] = flatMap(a => State.pure(f(a)))
    def flatMap[B](f: A => State[S, B]): State[S, B] = State { s =>
      val (s2, a) = run(s)
      f(a).run(s2)
    }
  }
  object State {
    def pure[S, A](a: A): State[S, A] = State[S, A](s => (s, a))
  }

  def fact(a: Int): State[(Int, Int), Int] = State { s =>
    val next = (Math.max(s._1, a - s._2), Math.min(s._2, a))
    (next, a)
  }

  implicit class StreamOps[S, A](stream: Stream[State[S, A]]) {
    def sequence: State[S, Stream[A]] =
      stream.foldRight(State.pure[S, Stream[A]](Stream.empty[A])) { (a: State[S, A], acc: State[S, Stream[A]]) =>
        a.flatMap(sa => acc.map(sa #:: _))
      }
  }

  val lines = Source.stdin.getLines()
  val n     = lines.next().toInt

  val list: State[(Int, Int), Stream[Int]] =
    lines.toStream
      .take(n)
      .map(_.toInt)
      .map(fact)
      .sequence

  println(list.run((Integer.MIN_VALUE, Integer.MAX_VALUE))._1._1)
}



Measured memory_bytes: 235208
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,k;
cin >> n >> k;
int a[n];
for(int i=0;i<n;i++)
{
cin >> a[i];
}
sort(a,a+n);
int sum=0;
for(int i=0;i<k;i++)
{
sum+=a[i];
}
cout << sum;
return 0;
}

Measured memory_bytes: 3636
import java.util.*;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
		int n = sc.nextInt();
		int a[] = new int[n];
		int d[] = new int[n];
		int ans = 0;
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		for(int i = 0; i < n-1; i++) {
			d[i] = a[i+1]-a[i];
		}
		d[n-1] = k-a[n-1]+a[0];
		Arrays.sort(d);
		for(int i = 0; i < n-1; i++) {
			ans+=d[i];
		}
		System.out.println(ans);
	}
}

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

#define int long long

const int N = 5e2 + 10;
int n, m, mark[N][N];

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> m;
	for (int i = 0; i < n; i++)
		for (int j = 0; j < m; j++) {
			char c;
			cin >> c;
			if (c == '#')
				mark[i][j] = 2;
		}
	
	for (int j = 1; j < m - 1; j++)
		mark[n - 1][j] = 1;
	for (int j = 1; j < m - 1; j += 2)
		for (int i = 1; i < n; i++)
			if (!mark[i][j])
				mark[i][j] = 1;
	
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++)
			if (mark[i][j])
				cout << '#';
			else
				cout << '.';
		cout << '\n';
	}
	cout << '\n';
	
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++)
			if (!mark[i][j] || mark[i][j] == 2)
				cout << '#';
			else
				cout << '.';
		cout << '\n';
	}
	cout << endl;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
typedef pair<int,int> P;
typedef vector<int> vi;

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

ll gcd(ll a , ll b){
	if(b == 0) return a;
	return gcd(b , a % b);	
}
ll lcm(ll a , ll b){
	ll g = gcd(a , b);
	ll lc = (a/g) * b;
	return lc;
}


int main(){
    ios::sync_with_stdio(false);
    ll k,n;
    ll p[1100];
    cin >> n >> k;
    rep(i,n){
      cin >> p[i];
    }
    sort(p,p+n);
    ll ans =0;
    rep(i,k){
      ans += p[i];
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int N, T, A;
    cin >> N >> T >> A;
    vector<int> H(N);
    for (int i = 0; i < N; i++) cin >> H.at(i);
    int min = 1001001;
    int ans;
    for (int i = 0; i < N; i++) {
        int tmp = T*1000 - H.at(i)*6 - A*1000;
        if (tmp < 0) tmp = -tmp;
        if (tmp < min) {
            min = tmp;
            ans = i+1;
        }
    }
    cout << ans << endl;
}

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

int main() {
	int n, m, ind = 0;
	long long sum = 0;
	cin >> n >> m;
	vector<long long> cards(n);
	vector<pair<long long, long long>> repl(m);
	for(int i = 0; i < n; i++) {
		cin >> cards[i];
	} sort(cards.begin(), cards.end());
	for(int i = 0; i < m; i++) {
		cin >> repl[i].second >> repl[i].first;
	} sort(repl.begin(), repl.end(), greater<pair<long long, long long>>());
	for(int i = 0; i < m && cards[ind] < repl[i].first && ind < n; i++) {
		for(int j = 0; j < repl[i].second && cards[ind] < repl[i].first && ind < n; j++) {
			cards[ind] = repl[i].first;
			ind++;
		}
	} for(int i = 0; i < n; i++) {
		sum += cards[i];
	} cout << sum << endl;
    return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int PAIR[6050];
string dp[6050];

int main() {
    //cout.precision(10);
    int N;
    string S;
    cin >> N >> S;
    S = "#" + S;
    queue<int> a, b;
    for(int i = 1; i <= 2*N; i++) {
        if(S[i] == 'a') a.push(i);
        else b.push(i);
    }
    for(int i = 1; i <= N; i++) {
        int A = a.front();
        int B = b.front();
        a.pop();
        b.pop();
        PAIR[A] = B;
        PAIR[B] = A;
    }
    for(int i = 1; i <= 2*N; i++) {
        //cerr << PAIR[i] << endl;
    }
    for(int index = 2*N; index >= 1; index--) {
        dp[index] = dp[index + 1];
        if(PAIR[index] < index) continue;
        if(S[index] == 'a') {
            string sub = "ab" + dp[PAIR[index] + 1];
            dp[index] = max(dp[index], sub);
            continue;
        }
        if(S[index] == 'b') {
            string sub = "b";
            int plus = 1;
            int sub_index = index + 1;
            for(; plus > 0; sub_index++) {
                if(S[sub_index] == 'b') {
                    sub.push_back('b');
                    plus++;
                    continue;
                }
                if(sub_index < PAIR[index]) continue;
                sub.push_back('a');
                plus--;
            }
            sub = sub + dp[sub_index];
            dp[index] = max(dp[index], sub);
        }
    }
    cout << dp[1] << endl;
    return 0;
}


Measured memory_bytes: 14592
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <utility>
#include <algorithm>
#include <map>
#include <cassert>
using namespace std;


const int maxn = 1e5 + 5;
const int inf = 0x3f3f3f3f;
int n, k, h[maxn], cost[maxn];

void solve() {
    memset(cost, inf, sizeof(cost));
    cost[0] = 0;
    for (int i = 1; i < n; i++) {
        for (int j = 1; j <= k; j++) {
            if (i >= j) cost[i] = min(cost[i], cost[i - j] + abs(h[i] - h[i - j]));
        }
    }
    cout << cost[n - 1] << endl;
}

int main() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) cin >> h[i];
	solve();
	return 0;
}

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

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if ((a + b) == (c + d))
    {
        cout << "Balanced" << endl;
    }
    else if ((a + b) > (c + d))
    {
        cout << "Left" << endl;
    }
    else
    {
        cout << "Right" << endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

class Main{
    public static void main(String args[]){
 int a;
        int b;
 String c;
 Scanner scan = new Scanner(System.in);
 a = scan.nextInt();
 c = scan.next();
 b = scan.nextInt();
 if(c.equals("+")){
     System.out.println(a+b);
 }else if(c.equals("-")){
     System.out.println(a-b);
 }
    }
}

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

int main(){
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  int min = 10000000;
  for(int i=0;i<3;i++){
    int sum = abs(a[0]-a[i])+abs(a[1]-a[i])+abs(a[2]-a[i]);
    if(min>sum) min = sum;
  }
  cout << min << endl;
 }


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

int gcd(int x, int y)
{
    int r;
    while((r = x % y) != 0) 
    {
        x = y;
        y = r;
    }
    return y;
}

int main(){
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    int b=gcd(a[0],a[1]);
    for(int i=2;i<n;i++){
        b=gcd(b,a[i]);
    }
    cout<<b<<endl;
}

Measured memory_bytes: 640
from itertools import permutations
import math

N = int(input())
xy = [tuple(map(int, input().split())) for _ in range(N)]

total = 0


for path in permutations(range(N)):
    dist = 0
    for a,b in zip(path, path[1:]):
        dist += math.sqrt((xy[a][0] - xy[b][0])**2 + (xy[a][1] - xy[b][1])**2)
    total += dist

print(total / math.factorial(N))

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

int main() {
    string s;
    cin >> s;
    int len = (int)s.size();
	
  	if (len == 2) {
    	if (s.at(0) == s.at(1)) printf("%d %d\n", 1, 2);
      	else printf("%d %d\n", -1, -1);
      	return 0;
    }
  
    for (int i = 0; i < len - 2; i++) {
        if (s.at(i) == s.at(i + 1) || s.at(i) == s.at(i + 2) || s.at(i + 1) == s.at(i + 2)) {
            printf("%d %d\n", i + 1, i + 3);
            return 0;
        }
    }
    printf("%d %d\n", -1, -1);
}   

Measured memory_bytes: 512
/*input
1 100
*/
#include <bits/stdc++.h>
using namespace std;

int main() {
    int a, b, ans;

    cin >> a >> b;
    if (b == 100) b++;
    
    if (a == 0) {
        cout << b << '\n';
        return 0;
    }

    cout << b;
    for (int i = 1; i <= a; i++) {
        cout << "00";
    }
    cout << '\n';
    return 0;
}

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

#define deb(x) cout << #x << " " << x << endl;
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define ll long long
#define pb push_back
#define endl "\n"
#define mp map<int,int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007

void c_p_c()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

}


//int a[mxn];

int main(){
	c_p_c();

	queue<ll> q;
	fo(i,9) q.push(i+1);
	int n; cin >> n;

	fo(i,n){
		ll temp = q.front();
		if(i+1==n){
			cout << temp << endl;
			break;
		}
		q.pop();
		if(temp%10!=0){
			q.push((temp*10)+(temp%10)-1);
		}
		q.push((temp*10)+(temp%10));
		if(temp%10!=9){
			q.push((temp*10)+(temp%10)+1);
		}
	}


	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main()
{
  int n,s,i,j,total,x,max,min;

  while(1){
    
    scanf("%d",&n);
    if(n==0) break;
    
    for(i=0; i<n; i++){
      total=0;
      
      for(j=0; j<5; j++){
	scanf("%d",&s);
	total+=s;
      }

      if(i==0){
	max=total;
	min=total;
      }
      if(max<total){
	x=max;
	max=total;
	total=x;
      }
      if(total<min){
	x=min;
	min=total;
	total=x;
      }
    }
  
    printf("%d %d\n",max,min);

  }
  
  return 0;
}

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

#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define ui unsigned int
//#define ld long double
#define mod 998244353
#define inf 100000000000010
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF LONG_MAX
#define PI 3.1415926535897932384626
#define mpp make_pair
#define fi first
#define se second
#define pb push_back
#define rep(x,j,n)for(int x=j;x<n;x++)
#define repr(x,n,j)for(ll x=n;x>j;x--)
#define all(x) (x).begin(), (x).end()

typedef vector<pair<ll,ll>> vpi;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> pi;
typedef long double ld;
bool isprime(ll n)
{
    if(n<=1)return false;
    if(n<=3)return true;
    if(n%2==0||n%3==0)return false;
    for(ll i=5;i*i<=n;i+=6)
    {
        if(n%i==0||n%(i+2)==0)return false;
    }
    return true;
}

ll modexp(ll a,ll b,ll m)
{
    ll r=1;
    a=a%m;
    while(b>0)
    {
        if(b&1)r=(r*a)%m;
        b = b>>1;
        a=(a*a)%m;
    }
    return r%m;
}




ll builtin_popcount(ll x)
{
    ll cnt = 0;
    for(ll i=60;i>=0;i--)
    {
        if((1LL<<i)&x)cnt++;
    }
    return cnt;
}

ll addmod(ll a,ll b)
{
    a%=mod;
    b%=mod;
    return (a+b)%mod;
}
ll mulmod(ll a,ll b)
{
    a%=mod;
    b%=mod;
    return (a*b)%mod;
}
ll submod(ll a,ll b)
{
    a%=mod;
    b%=mod;
    a-=b;
    if(a<0)a+=mod;
    return a%mod;
}
struct CustomCompare
{
    bool operator()(ll a,ll b)
    {
        return a>b;
    }
};
/*
const int mxn = 5*(1e6) +10;
vi spf(mxn);
void sieve()
{
    for(ll i =0;i<mxn;i++)spf[i]  = i;
    for(ll i=2;i<mxn;i+=2)spf[i] = 2;
    for(ll i = 3;i*i<mxn;i++)
    {
        if(spf[i]==i)
        {
            for(ll j = i*i;j<mxn;j+=i)
            {
                if(spf[j]==j)spf[j] = i;
            }
        }
    }
}
*/

const int mxn = 2e5 + 10;
ll tree[mxn];

void update(ll i,ll val)
{
    while(i<mxn)
    {
        tree[i]=addmod(tree[i],val);
        i+=i&-i;
    }
}
ll query(ll i)
{
    ll ans = 0;
    while(i>0)
    {
        ans = addmod(tree[i],ans);
        i-=i&-i;
    }
    return ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);

ll n; cin>>n;
ll k; cin>>k;
vpi arr(k);
rep(i,0,k)cin>>arr[i].fi>>arr[i].se;

update(1,1);
ll res;
rep(i,2,n+1)
{
    rep(j,0,k)
    {
        ll l= max(0LL,i-arr[j].se) ,r = max(0LL,i-arr[j].fi);
        res = submod(query(r),query(l-1));
        update(i,res);
    }
    //cout<<res<<"\n";
}

cout<<submod(query(n),query(n-1))<<"\n";
return 0;
}
/*
4
1
1 2 1

*/


Measured memory_bytes: 5208
#include <bits/stdc++.h>
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int MX = 100005;
int n, res[MX];
multiset<int> st;

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n;
	forn (i, n) {
		int a;
		cin >> a;
		st.insert(a);
	}

	res[0] = *st.begin();
	st.erase(st.find(res[0]));

	res[1] = *st.rbegin();
	st.erase(st.find(res[1]));

	for (int i = 2; i < n; i++) {
		auto it = st.find(res[i - 1] ^ res[i - 2]);
		if (it == st.end()) {
			cout << "No" << endl;
			return 0;
		}
		res[i] = *it;
		st.erase(it);
	}

	forn (i, n)
		if ((res[i] ^ res[(i + 2) % n]) != res[(i + 1) % n]) {
			cout << "No" << endl;
			return 0;
		}

	cout << "Yes" << endl;

	return 0;
}


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

int main(){
  int A,B;
  cin >> A >> B;
  if((A%2 ==0 && B%2 ==0)||(A%2 == 1 && B%2 ==1)) {
    cout << B-((B-A)/2) << endl;
  
  }
  else{
    cout << "IMPOSSIBLE" << endl;
  }
  }


Measured memory_bytes: 256
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue> 
 
using namespace std;
 
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

    long long A, B, K;
    cin >> A >> B >> K;

    if(A >= K) {
        cout << A - K << " " << B << endl;
    } else if(A + B > K) {
        cout << 0 << " " << A + B - K << endl;
    } else {
        cout << 0 << " " << 0 << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma warning(disable:4996)
using namespace std;
using ll = long long;
int main() {
	string S;
	cin >> S;
	int N = S.size(), MOD = 1000000007;
	ll dp[100010][4] = {};
	for (int i = N; i >= 0; --i) {
		for (int j = 3; j >= 0; --j) {
			if (i == N) {
				dp[i][j] = (j == 3 ? 1 : 0);
			}
			else {
				dp[i][j] = dp[i + 1][j] * (S[i] == '?' ? 3LL : 1LL);
				if (j < 3 && (S[i] == '?' || S[i] == "ABC"[j])) {
					dp[i][j] += dp[i + 1][j + 1];
				}
				dp[i][j] %= MOD;
			}
		}
	}
	cout << dp[0][0] << endl;
}




Measured memory_bytes: 3584
n, m = map(int, input().split())
ans = [-1]*n

for i in range(m):
    s, c = map(int, input().split())
    if s == 1 and c == 0 and n != 1:
        print(-1)
        exit()
    if ans[s-1] == -1 or ans[s-1] == c:
        ans[s-1] = c
    else:
        print(-1)
        exit()

if ans[0] == -1 and n != 1:
    ans[0] = 1

for i in range(n):
    if ans[i] == -1:
        ans[i] = 0

print(*ans, sep="")


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

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

  int ans= 0;
  for(int i=0; i+3 <= N; i++){
    if(S.substr(i,3)=="ABC"){
      ans++;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3600
a = 0
b = 0
c = 0

for i in range(10):
  x=int(input())
  if x>=a:
    c = b
    b = a
    a = x
  elif x>=b:
    c = b
    b = x
  elif x >=c:
    c = x

print(a)
print(b)
print(c)


Measured memory_bytes: 5588
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll MOD=1000000007LL;
char s[100004];
ll f[100004][15];
int main(){
    memset(f,0,sizeof(f));
	scanf("%s",s+1);
	int l=strlen(s+1);
	for(int i=0;i<13;i++)f[l+1][i]=0;
	f[l+1][0]=1;
	ll tin=1;
	for(int i=l;i>=1;i--){
        if(s[i]=='?'){
            for(int j=0;j<13;j++){
                for(int k=0;k<=9;k++){
                    f[i][(j+k*tin)%13]+=f[i+1][j];
                    f[i][(j+k*tin)%13]%=MOD;
                }
            }
        }
        else{
            ll df=(s[i]-'0')*tin;
            df%=13;
            for(int j=0;j<13;j++){
                f[i][(j+df)%13]=f[i+1][j];
            }
        }
        tin*=10;tin%=13;
	}
	printf("%lld\n",f[1][5]);
	return 0;
}


Measured memory_bytes: 12032
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define at(x,i) get<i>(x);
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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(){
  ll n;cin >> n;
  vl r(50),l(50);
  ll left=0,right=0;
  ll cnt=1;
  rep(i,50){
    if(cnt>0)right+=cnt;
    else left+=cnt;
    r[i]=right;
    l[i]=left;
    cnt*=-2;
  }
  cnt=-cnt/2;
  string ans;
  bool check=false;
  for(int i=49;i>=1;i--){
    if(l[i-1]<=n&&r[i-1]>=n){
      if(check)ans+='0';
    }
    else {
      n-=cnt;
      ans+='1';
      check=true;
    }
    cnt=-cnt/2;
  }
  if(n==1)ans+='1';
  if(n==0)ans+='0';
  cout << ans <<endl;
}


Measured memory_bytes: 256
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// Nの桁数
ll dig(ll N) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= 10;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

int main() {
	ll N, M, X; cin >> N >> M >> X;
	vector<ll> A(N); rep(i, M)cin >> A[i];

	ll l=0, r=0;
	rep(i, M) {
		if (A[i] < X) l++;
		else if (A[i] > X) r++;
	}

	cout << min(l, r) << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#define lld long long int
#define DBG1(vari1) cerr<<#vari1<<" = "<<(vari1)<<endl;
#define DBG2(vari1,vari2) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<endl;
#define DBG3(vari1,vari2,vari3) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<" "<<#vari3<<" = "<<(vari3)<<endl;
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	// freopen("input.txt", "r", stdin);  
	int k,s;
	cin >> k >> s;
	int c=0;
	for(int i=0;i<=k;i++)
		for(int j=0;j<=k;j++)
		{
			int q = s-i-j;
			if(q>=0 && q<=k)
				c++;
		}
	cout << c;
}

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

int n;
long dp[290][18];

long rec(int a, int b){ //今の合計a,前に足した数b
	if(dp[a][b]>=0) return dp[a][b];
	
	long ret=0;	
	
	if(a==n) ret=1;
	else{
		for(int i=b; a+i*i<=n; ++i)	ret+=rec(a+i*i, i);
	}
	
	return dp[a][b]=ret;
}

int main(){
	while(1){
		scanf(" %d", &n);
		if(n==0) break;	
		
		memset(dp, -1, sizeof(dp));
		printf("%ld\n", rec(0,1));
	}
}

Measured memory_bytes: 1244
mod =  998244353
n, s = map(int, input().split())
a = list(map(int, input().split()))
dp = [[0 for j in range(s+1)] for i in range(n+1)]
dp[0][0] = 1
for i in range(n):
    for j in range(s+1):
        dp[i+1][j] += 2*dp[i][j]
        dp[i+1][j] %= mod
        if j+a[i] <= s:
            dp[i+1][j+a[i]] += dp[i][j]
            dp[i+1][j+a[i]] %= mod
print(dp[n][s])

Measured memory_bytes: 147408
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
#include<map>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll p, ll n, ll m) {
	if (n == 0) return 1;
	else if (n == 1) return p % m;
	else if (n % 2 == 1) return p * pow_mod(p, n - 1, m) % m;
	else {
		ll tmp = pow_mod(p, n / 2, m);
		return (tmp * tmp) % m;
	}
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

ll com_mod(ll n, ll k, ll m) {
	if (k == 0) return 1;
	else {
		ll x = 1;
		ll y = 1;
		for (ll i = 0; i < k; i++) {
			x = (x * (n - i)) % m;
			y = (y * (i + 1)) % m;
		}
		ll res = (x * pow_mod(y, m - 2, m)) % m;
		return res;
	}
}

int keta(int n) {
	int res = 0;
	while (n > 0) {
		res++;
		n /= 10;
	}
	return res;
}

int main() {
	int a, b; cin >> a >> b;
	if (a < 2 * b) cout << 0 << endl;
	else cout << a - 2 * b << endl;
	return 0;
}

Measured memory_bytes: 3604
import math
import sys
input = sys.stdin.readline


def main():
    sc = Scan()
    a = sc.intarr()[0]
    d = sc.intarr()

    sum = 0
    for i in range(a):
        for j in range(i+1, a):
            sum += d[i]*d[j]

    print(sum)


class Scan():

    def intarr(self):
        line = input()
        array = line.split(' ')
        num_array = [int(n) for n in array]
        return num_array

    def strarr(self):
        line = input()
        array = line.split(' ')
        array[-1] = array[-1].strip('\n')
        return array


main()


Measured memory_bytes: 3064
#pragma region

#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (register int i = (begin); i < (end); i++)
#define IFOR(i, begin, end) for (register int i = (end)-1; i >= (begin); i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define MOD 1000000007
#define debug(x) cerr << #x << " = " << (x) << " (line: " << __LINE__ << ") " << endl;
typedef long long ll;
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "vec[ ";
  REP(i, vec.size())
  i == 0 ? os << vec[i] : os << ", " << vec[i];
  os << " ]";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const deque<T> &deq) {
  os << "deq[ ";
  REP(i, deq.size())
  i == 0 ? os << deq[i] : os << ", " << deq[i];
  os << " ]";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &set) {
  os << "{ ";
  for (auto &&s : set) &s == &(*set.begin()) ? os << s : os << ", " << s;
  os << " }";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &set) {
  os << "{ ";
  for (auto &&s : set) &s == &(*set.begin()) ? os << s : os << ", " << s;
  os << " }";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &set) {
  os << "{ ";
  for (auto &&s : set) &s == &(*set.begin()) ? os << s : os << ", " << s;
  os << " }";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_multiset<T> &set) {
  os << "{ ";
  for (auto &&s : set) &s == &(*set.begin()) ? os << s : os << ", " << s;
  os << " }";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << "(" << p.first << ", " << p.second << ")";
  return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const map<TK, TV> &m) {
  os << "{ ";
  for (auto &&k : m) &k == &(*m.begin()) ? os << k.first << " => " << k.second : os << ", " << k.first << " => " << k.second;
  os << " }";
  return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const unordered_map<TK, TV> &m) {
  os << "{ ";
  for (auto &&k : m) &k == &(*m.begin()) ? os << k.first << " => " << k.second : os << ", " << k.first << " => " << k.second;
  os << " }";
  return os;
}

#pragma endregion
#pragma region

#define out(x) cout << (x) << '\n';

ll gcd(ll a, ll b) {
  if (a < b) swap(a, b);
  if (b == 0) return a;
  return gcd(a - b, b);
}

bool isPrime(ll a) {
  if (a == 2) return true;
  if (a < 2 || a % 2 == 0) return false;
  int b = sqrt(a);
  for (register int i = 3; i <= b; i += 2)
    if (b % i == 0) return false;
  return true;
}

#pragma endregion
#define INF 2147483647

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(16);

  ll N;
  cin >> N;
  vector<ll> V(N), C(N);
  cin >> V >> C;
  ll ans = 0;
  REP(i, N)
  ans += max(V[i] - C[i], 0ll);
  out(ans);
}


Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
using namespace std;


int calc(int x) {
	int ret = 0;
	while (x % 100 == 0) {
		x /= 100;
		++ret;
	}
	return ret;
}

int main() {
	int d, n;
	cin >> d >> n;
	int cnt = 0, val = 0;
	while (cnt < n) {
		++val;
		if (calc(val) == d) ++cnt;
	}
	cout << val << endl;
	return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        h_vec: [usize; n],
    }
    let mut h_vec = h_vec;
    for i in 0..h_vec.len() {
        if i == 0 {
            h_vec[0] -= 1;
            continue;
        }
        if h_vec[i-1] > h_vec[i] {
            println!("No");
            return;
        } else if h_vec[i-1] == h_vec[i] {
            // noop
        } else {
            h_vec[i] -= 1;
        }
    }
    println!("Yes");
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(a) a.begin(),a.end()
int main()
{
    int H,W,N;
    cin >> H >> W >> N;
    int mini = min(H,W);
    FOR(i,0,H){
        FOR(j,0,W){
            int S = W*i + H*j - i*j;
            if(S >= N && i+j < mini){
                mini = i+j;
            }
        }
    }
    cout << mini << endl;
    return 0;
}

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

long long C[2005][2005];

int main()
{
    long mod = 1E9 + 7;
    int N, K;
    cin >> N >> K;

    C[0][0] = 1;
    C[1][0] = 1;
    C[1][1] = 1;
    for (int i = 2; i < 2005; i++) {
        C[i][0] = 1;
        for (int j = 1; j <= i; j++) {
            C[i][j] = (C[i-1][j] + C[i-1][j-1]) % mod;
        }
    }
    int R = N - K;
    for (int i = 1; i <= K; i++) {
        long a = C[R+1][i] % mod;
        long b = C[K-1][i-1] % mod;
        cout << (a * b)%mod << endl;
    }
    return 0;
}


Measured memory_bytes: 30208
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t n,k;
  cin >> n >> k;
  int64_t m=0;
  for(int i=k;i<=n+1;i++){
	m+=((2*n-i+1)*i/2-i*(i-1ull)/2+1);
    m%=1000000007;
  }
  cout<<m<<endl;
}

Measured memory_bytes: 3640
#include <iostream>

int main()
{
    int num;
    std::cin >> num;
    std::string a, b;
    while (std::cin >> a >> b) 
    {
        int m, n;
        m = a.size();
        n = b.size();
        a = ' ' + a;
        b = ' ' + b;
        int maxl = 0;
        long c[m + 1][n + 1];
        for (int i = 0; i <= m; i++) c[i][0] = 0;
        for (int i = 1; i <= n; i++) c[0][i] = 0;
        for (int i = 1;  i <= m; i++) 
        {
            for (int  j = 1; j <= n; j++)
            {
                if (a[i] == b[j])
                    c[i][j] = c[i - 1][j - 1] + 1;
                else if (c[i - 1][j] >= c[i][j - 1])
                    c[i][j] = c[i - 1][j];
                else 
                    c[i][j] = c[i][j - 1];
                maxl = (maxl >= c[i][j]) ? maxl : c[i][j];
            }
        }
        std::cout << maxl << '\n';
    }
}




Measured memory_bytes: 10940
#![allow(unused_imports)]
#![allow(unused_variables)]

use itertools::Itertools;
use proconio::marker::*;
use proconio::*;

#[fastout]
fn main() {
    input! {
        n: i32, m: i32,
        a: [i32; n],
    }
    // annotate for rust-analyzer
    let n: i32 = n;
    let m: i32 = m;
    let a: Vec<i32> = a;

    let mut cnt = 0;
    let sum = a.iter().sum::<i32>();
    let th = sum as f32 / (4_f32 * m as f32);
    for i in 0..n {
        if a[i as usize] as f32 >= th {
            cnt += 1;
        }
    }

    println!("{}", if cnt >= m { "Yes" } else { "No" });
}


Measured memory_bytes: 2124
import java.util.Scanner;

public class Main {
    public static int N = 0;
    public static int[] A;
    public static int[] B;

    public static void main(String[] args) {

        String[] aStrArray;
        String[] bStrArray;

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

        aStrArray = sc.nextLine().split(" ");
        A = new int[N + 1];
        for (int i = 0; i < N + 1; i++) {
            A[i] = Integer.parseInt(aStrArray[i]);
        }
        bStrArray = sc.nextLine().split(" ");
        B = new int[N];
        for (int i = 0; i < N; i++) {
            B[i] = Integer.parseInt(bStrArray[i]);
        }

        long tmp = 0;
        long remainingA = A[N];
        long totalEnemy;
        for (int i = N - 1; i >= 0; i--) {
            totalEnemy = A[i] + remainingA;
            if (B[i] >= totalEnemy) {
                tmp += totalEnemy;
                remainingA = 0;
            } else {
                tmp += B[i];
                if (remainingA - B[i] > 0) {
                    remainingA = A[i];
                } else {
                    remainingA = A[i] - (B[i] - remainingA);
                }
            }
        }
        System.out.println(tmp);
    }
}

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

using namespace std;

#define MAX_N 100005
int N;
int A[MAX_N];

void input()
{
  cin >> N;
  for (size_t i = 0; i < N; i++) {
    cin >> A[i];
    A[i]--;
  }
}

int main()
{

  input();

  int ans = 0;
  for (size_t i = 0; i < N; i++) {
    if(A[A[i]] == i){
      ans++;
    }
  }

  cout << ans/2 << endl;

  return 0;
}


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

int main()
{
	string S;
	cin >> S;
	for (int i = 0; i < S.size(); i += 2)
	{
		if (S[i] == 'L')
		{
			cout << "No\n";
			return 0;
		}
	}
	for (int i = 1; i < S.size(); i+= 2)
	{
		if (S[i] == 'R')
		{
			cout << "No\n";
			return 0;
		}
	}
	cout << "Yes\n";
}


Measured memory_bytes: 256
def resolve():
    S = input()
    if S == "RRR":
        print(3)
    elif S == "RRS" or S == "SRR":
        print(2)
    elif S == "RSS" or S == "SRS" or S == "SSR" or S == "RSR":
        print(1)
    else:
        print(0)
resolve()

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

int main()
{
    string s;
    cin >> s;
    string ans;

    ll n = s.size();
    rep(i, n){
        if (s[i] == '0'){
            ans.push_back('0');
        }else if(s[i] == '1'){
            ans.push_back('1');
        }else if(s[i] == 'B'){
            if (ans.size() > 0){
                ans.pop_back();
            }
        }
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    // Your code here!
    
    long long int N, K, ans;
    
    cin >> N >> K;
    
    ans = N % K;

    ans = (abs(ans - K) < ans) ? abs(ans - K) : ans;
    
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    H, W = map(int, input().split())
    grid = [list(input().rstrip()) for _ in range(H)]

    cnt_w = [[0] * W for _ in range(H)]
    for h in range(H):
        cnt = 0
        for w in range(W):
            if grid[h][w] == "#":
                cnt = 0
            else:
                cnt += 1
            cnt_w[h][w] = cnt

    for h in range(H):
        cnt = 0
        for w in reversed(range(W)):
            if grid[h][w] == "#":
                cnt = 0
            else:
                cnt = max(cnt, cnt_w[h][w])
            cnt_w[h][w] = cnt

    cnt_h = [[0] * W for _ in range(H)]
    for w in range(W):
        cnt = 0
        for h in range(H):
            if grid[h][w] == "#":
                cnt = 0
            else:
                cnt += 1
            cnt_h[h][w] = cnt

    for w in range(W):
        cnt = 0
        for h in reversed(range(H)):
            if grid[h][w] == "#":
                cnt = 0
            else:
                cnt = max(cnt, cnt_h[h][w])
            cnt_h[h][w] = cnt

    res = 0
    for h in range(H):
        for w in range(W):
            res = max(res, cnt_w[h][w] + cnt_h[h][w] - 1)
    print(res)


if __name__ == '__main__':
    resolve()


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

int main()
{
	int x,y;
	cin>>x>>y;
	for(int i=0;i<=x;i++){
		int j=x-i;
		if(i*2+j*4==y){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = numeric_limits<ll>::max()/3;
const ll mod = 1e9 + 7;

int main(void){
  ll n;
  cin >> n;
  vector< ll > v(n);
  ll m1 = -1,m2 = -1;
  for(int i = 0;i < n;++i){
    scanf("%lld", &v[i]);
    if(v[i] > m1){
      m1 = v[i];
    }else if(v[i] > m2){
      m2 = v[i];
    }
  }
  for(int i = 0;i < n;++i){
    if(v[i] == m1){
      printf("%lld\n", m2);
    }else{
      printf("%lld\n", m1);
    }
  }
  return 0;
}


Measured memory_bytes: 3200
a, b = map(int, input().split())

ans = -1
for x in range(1, 1250+1):
  _a = int(x * 0.08)
  _b = int(x * 0.1)
  # print(x, _a, _b)
  if _a == a and _b == b:
    ans = x
    break
print(ans)

Measured memory_bytes: 3060
using System;
using System.Linq;
using System.Collections.Generic;
using static C.LCMGCD;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(long.Parse).ToList();


            var gcdL = new List<long>();
            var gcdR = new List<long>();


            gcdL.Add(0);
            foreach (var x in a)
            {
                gcdL.Add(GCD(gcdL.Last(), x));
            }

            a.Reverse();
            gcdR.Add(0);
            foreach (var x in a)
            {
                gcdR.Add(GCD(gcdR.Last(), x));
            }
            gcdR.Reverse();

            var M = new List<long>();
            
            for(int i=0;i<gcdR.Count()-1;i++)
            {
                M.Add(GCD(gcdL[i], gcdR[i+1]));
            }

            Console.WriteLine(M.Max());

        }
    }

    public class LCMGCD
    {
        public static long GCD(long a, long b)
        {
            // Greatest Common Divisor
            var v = new[] { a, b };
            while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
            return v[0];
        }

        public static long LCM(long a, long b)
        {
            // Least Common Multiple
            return a / GCD(a, b) * b;
        }
    }
}






Measured memory_bytes: 32832
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include <fstream>
#include <time.h>
#include <iterator>
#include<random>



#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
#define all(x) (x).begin(), (x).end()
using namespace std;
int MOD = (ll)1000000000 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 500050;


vector<P>v;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N; cin >> N;
	REP(i, N) {
		int a, b; cin >> a >> b;;
		v.push_back({ b,a });
	}
	VSORT(v);
	int t = 0;
	REP(i, N) {
		t += v[i].second;
		if (t > v[i].first) {
			print("No"); return 0;
		}
	}
	print("Yes");
}


Measured memory_bytes: 6512
#include <stdio.h>



int main(void)
{
	//変数の宣言
	int n;
	int array[110];
	int min,max;
	int i;
	
	//データの読み込み
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&array[i]);
	}
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	
	
	//実際の処理
	
	min=array[0];
	max=array[0];
	
	for(i=0;i<n;i++){
		if(min>array[i]){
			min=array[i];
		}else if(max<array[i]){
			max=array[i];
		}
	}
	
	
//	printf("計算部分終了\n");
	
	//出力
	
	printf("%d",max-min);
	
	
//	printf("結果の出力終了\n");
	
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch IntervalRunning | diff IntervalRunning.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address IntervalRunning.cpp && ./a.out

/*
 
 12/1/2019
 
 5:07-5:40 give up
 10:20-11:30 read editorial and got AC
 
 */

LL T[2],A[2],B[2];

string solve() {
  LL P=(A[0]-B[0])*T[0],Q=(A[1]-B[1])*T[1];
  if(P>0) P*=-1,Q*=-1;
  if(P+Q<0) return "0";
  if(P+Q==0) return "infinity";
  dump(P,Q,P+Q);
  LL k=-P/(P+Q);
  LL res=2LL*k;
//  if((__int128)(P+Q)*k!=(__int128)P) ++res;
  
  bool x=(__int128)(P+Q)*k!=(__int128)-P,y=-P%(P+Q)!=0;
  dump(x,y);
  assert(x==y);
  
  if(-P%(P+Q)!=0) ++res;
  return to_string(res);
}

void solve_wrong() {
  int res=0;
  LL a=0,b=0;
  int sign=-100;
  FOR(i,0,1e6) {
    a+=T[i%2]*A[i%2];
    b+=T[i%2]*B[i%2];
    LL x=min(a,b);
    a-=x,b-=x;
    int sign2=a==b?0:a>b;
    if(sign2==0||sign2!=sign) ++res;
    sign=sign2;
  }
  if(res>1e5) cout<<"infinity"<<endl;
  else cout<<res-1<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>T[0]>>T[1]>>A[0]>>A[1]>>B[0]>>B[1];
  cout<<solve()<<endl;
  
  return 0;
}


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

int main() {
  int N, C, K;
  scanf("%d %d %d", &N, &C, &K);

  std::vector<int> T(N);
  for (int i=0; i<N; ++i)
    scanf("%d", &T[i]);

  std::sort(T.begin(), T.end());

  int res=0, lasttime=0, lastnum=0;
  for (int i=0; i<N; ++i) {
    if (lastnum == 0 || lasttime + K < T[i]) {
      lasttime = T[i];
      lastnum = 1;
      ++res;
    } else {
      ++lastnum;
    }

    if (lastnum == C) {
      lasttime = 0;
      lastnum = 0;
    }
  }

  printf("%d\n", res);
  return 0;
}


Measured memory_bytes: 640
import math


n, d = map(int, input().split())
x = [list(map(int, list(input().split()))) for _ in range(n)]
c = 0

for i in range(n):
    for j in range(i + 1, n):
        sum = 0
        for k in range(d):
            sum += pow(x[i][k] - x[j][k], 2)
        if math.sqrt(sum).is_integer():
            c += 1

print(c)


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

using namespace std;

int main(int argc, char *argv[]) {
    int N, M;
    cin >> N >> M;

    vector<vector<int>> g(N, vector<int>());
    for (int i = 0; i < M; i++) {
        int from, to;
        cin >> from >> to;
        g[from - 1].push_back(to - 1);
        g[to - 1].push_back(from - 1);
    }

    deque<pair<int, int>> q;
    q.push_back(make_pair(0, 0));
    vector<int> ans(N);
    vector<int> visited(N, 0);
    while (!q.empty()) {
        auto p = q.front();
        q.pop_front();
        if (visited[p.first] == 1) continue;
        visited[p.first] = 1;
        ans[p.first] = p.second;

        for (int j = 0; j < g[p.first].size(); j++) {
            if (visited[g[p.first][j]] != 1) {
                q.push_back(make_pair(g[p.first][j], p.first));
            }
        }
    }

    cout << "Yes" << endl;
    for (int k = 1; k < N; k++) {
        cout << ans[k] + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 11244
# -*- coding: utf-8 -*-
from sys import stdin
import math
# import numpy as np

s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()

N = d_in()
max_people = []
for i in range(5):
    max_people.append(d_in())

min_p = min(max_people)
min_idx = 5
for i in range(5):
    if max_people[i] == min_p:
        min_idx = i
        break

cost = 0
cost += 4
cost += math.ceil(N / min_p)

print(cost)


Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int h = sc.nextInt();
		int m = sc.nextInt();
		sc.close();
		double shortHand = m * 6;
		double longHand = h * 30 + m * 0.5;
		double angle = Math.max(longHand, shortHand) -
				Math.min(longHand, shortHand);
		double distance = Math.sqrt(
				b * b + a * a - 2 * a * b * Math.cos(Math.toRadians(angle)));
		System.out.println(distance);
	}

}


Measured memory_bytes: 35884