akhauriyash/Code-Regression huggingface dataset:
/*
Author : Chandan Agrawal
College : Poornima College of Engg. jaipur, Raj
Mail : chandanagrawal23@gmail.com


" when you are not practicing someone else is ,
 and the day u meet them u will lose "

*/
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define MAX 200050

#define ll long long
#define ld long double
#define lli long long int

#define pb push_back
#define INF 1000000000000
#define mod 1000000007

// trignometric function always give value in Radians only
#define PI acos(-1) //3.1415926535897932384626433832795028
#define dsin(degree) sin(degree*(PI/180.0))
#define dcos(degree) cos(degree*(PI/180.0))
#define dtan(degree) tan(degree*(PI/180.0))

#define rsin(radian) sin(radian)
#define rcos(radian) cos(radian)
#define rtan(radian) tan(radian)

#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))

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

#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define makeuniq(v) v.resize(unique(all(v)) - v.begin()); //only uniq element in vector after this
#define sz(x) int(x.size())
#define F first
#define S second

#define mii map<lli,lli>

#define pii pair<lli,lli>

#define vi vector<lli>
#define vvi vector<vi>
#define vpi vector<pii>
#define vbool vector<bool>

#define seti set<lli>

#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) (a/gcd(a,b))*b
#define abs(x) ((x < 0)?-(x):x)

#define endl '\n'

template <typename T>
void print(T x){cout<<x<<endl;}
template <typename T1, typename T2>
void print2(T1 x,T2 y){cout<<x<<" "<<y<<endl;}
template <typename T1, typename T2,typename T3>
void print3(T1 x, T2 y,T3 z){cout<<x<<" "<<y<<" "<<z<<endl;}

#define scanarr(a,n) for(lli i=0;i<n;i++)    cin>>a[i];
#define scanvec(a,n) for(lli i=0;i<n;i++){ lli x ; cin>>x; a.pb(x);}

#define printarr(a,n) for(lli i=0;i<n;i++)   cout<<a[i]<<" "; cout<<endl;
#define printvec(vec) for(auto xt : vec) cout<<xt<<" ";    cout<<"\n";

#define FD(N) fixed<<setprecision(N)

#define deb(x) cout<<#x<<" "<<x<<endl;

/*
1D vector -  vi dp(n,value);
2D vector -  vvi dp(n,vi(n,value));
*/

// chandan1,2
void chandan1(){int y=1;return;}
void chandan2(){
        loop(i,10){
        lli x=1;
    }
    return(chandan1());
}


int main(){
fastio
lli t=1;
//cin>>t;
chandan2();
while(t--) {
    lli n;
    cin>>n;
    lli a[n];
    scanarr(a,n);
    if(n==1)
        print(0);
    else
    {
        lli sum = 0;
        for(lli i=1;i<n;i++)
        {
            if(a[i]<a[i-1])
            {
                sum+=(a[i-1]-a[i]);
                a[i] = a[i-1];
            }
        }
    print(sum);
    }
  }
return 0;
}


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

public class Main {

	public static void main(String[] args)
	{
		Scanner stdIn = new Scanner(System.in);

		List<Integer> list = new ArrayList<Integer>();

		for (int i = 0; i < 10; i++)
		{
			list.add(stdIn.nextInt());
		}

		Collections.sort(list);
		Collections.reverse(list);

		for (int i = 0; i < 3; i++)
		{
			System.out.println(list.get(i));
		}
	}
}

Measured memory_bytes: 17212
#include <bits/stdc++.h>
 
typedef unsigned long long int ull;
typedef long double ldb;
typedef long long int ll;
 
#define for01(k,n)  for (ll i=k; i<n; i++)
#define for02(k,n)  for (ll j=k; j<n; j++)
#define for03(k,n)  for (ll k=k; k<n; k++)
#define for11(k,n)  for (ll i=k; i<=n; i++)
#define for12(k,n)  for (ll j=k; j<=n; j++)
#define for13(k,n)  for (ll k=k; k<=n; k++)

#define pb push_back
#define mp make_pair
#define pf push_front
#define popf pop_front
#define popb pop_back
#define vll vector<ll>
#define F first
#define S second
#define pp pair <ll, ll>
#define lb lower_bound
#define ub upper_bound
#define emp empty()
#define beg begin()
#define en end()
#define si size()
#define bk back()
#define deci(n)  fixed<<setprecision(n)

#define p0(a) cout << a << " "
#define p1(a) cout << a << "\n"

#define mem(a,n) memset(a, n, sizeof(a)); // n = 0 OR -1 only

#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define MOD 1000000007
#define MOD2 998244353

using namespace std;


int main()
{
  ll w,h;
  cin >> h >> w;
  
  while(h--)
  {
    string s;
    cin >> s;
    p1(s);
    p1(s);
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int Maxn=100005;
int n,m;
struct opt
{
	int cnt,val;
	bool operator < (const opt &tmp) const
	{
		return val>tmp.val;
	}
}op[Maxn];
long long ans;
priority_queue <int,vector<int>,greater<int> > Pr;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		Pr.push(x);
	}
	for(int i=1;i<=m;i++)
		scanf("%d%d",&op[i].cnt,&op[i].val);
	sort(op+1,op+1+m);
	for(int i=1;i<=m;i++)
		while(op[i].cnt&&Pr.top()<op[i].val)
		{
			Pr.pop();
			Pr.push(op[i].val);
			op[i].cnt--;
		}
	while(!Pr.empty())
		ans+=Pr.top(),Pr.pop();
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1528
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>

#define MAX_V 100
#define INF 10000000

using namespace std;

typedef pair<int, int> P;

struct edge {
	int to, info;
	edge(int _to, int _info) { to = _to, info = _info; };
};

vector<edge> Gc[MAX_V];
vector<edge> Gt[MAX_V];
int V, E;
int c[MAX_V];
int t[MAX_V];
int cm[MAX_V][MAX_V];
int tm[MAX_V][MAX_V];

void solve();
void dijkstra(int s, int g, int r);

int main()
{
	while (cin>>E>>V, E != 0 && V != 0) {
		for (int i = 0; i < V; i++) {
			fill(cm[i], cm[i] + V, INF);
			fill(tm[i], tm[i] + V, INF);
			cm[i][i] = 0, tm[i][i] = 0;
			Gc[i].clear(), Gt[i].clear();
		}
		for (int i = 0; i < E; i++) {
			int fr, to, co, ti;
			cin>>fr>>to>>co>>ti;
			Gc[fr - 1].push_back(edge(to - 1, co));
			Gc[to - 1].push_back(edge(fr - 1, co));
			Gt[fr - 1].push_back(edge(to - 1, ti));
			Gt[to - 1].push_back(edge(fr - 1, ti));
		}
		solve();
	}
}

void solve()
{
	int k,p,q,r;
	cin>>k;
	for (int i = 0; i < k; i++) {
		cin>>p>>q>>r;
		if (r == 0 && cm[p-1][q-1] != INF) {
			cout<<cm[p-1][q-1]<<endl;
		} else if (r == 0 && cm[q-1][p-1] != INF) {
				cout<<cm[q-1][p-1]<<endl;
		} else if (r == 1 && tm[p-1][q-1] != INF) {
			cout<<tm[p-1][q-1]<<endl;
		} else if (r == 1 && tm[q-1][p-1] != INF) {
			cout<<tm[q-1][p-1]<<endl;
		} else {
			dijkstra(p - 1, q - 1, r);
		}
	}
}

void dijkstra(int s, int g, int r)
{
	priority_queue<P, vector<P>, greater<P> > que;
	switch (r) {
			case 0:
			que.push(P(0,s));
			fill(c, c + V, INF);
			c[s] = 0;
			while (!que.empty()) {
				P p = que.top();
				que.pop();
				int v = p.second;
	
				if (c[v] < p.first) continue;
				for (int i = 0; i < Gc[v].size(); i++) {
					edge e = Gc[v][i];
					if (c[e.to] > c[v] + e.info) {
						c[e.to] = c[v] + e.info;
						que.push(P(c[e.to], e.to));
					}
				}
			}
			
			for (int i = 0; i < V; i++) {
				cm[s][i] = c[i];
			}
			cout<<c[g]<<endl;
			
			break;
			
			case 1:
			que.push(P(0,s));
			fill(t, t + V, INF);
			t[s] = 0;
			while (!que.empty()) {
				P p = que.top();
				que.pop();
				int v = p.second;
				
				if (t[v] < p.first) continue;
				for (int i = 0; i < Gt[v].size(); i++) {
					edge e = Gt[v][i];
					if (t[e.to] > t[v] + e.info) {
						t[e.to] = t[v] + e.info;
						que.push(P(t[e.to], e.to));
					}
				}
			}
			
			for (int i = 0; i < V; i++) {
				tm[s][i] = t[i];
			}
			
			cout<<t[g]<<endl;
			
			break;
	}
}

Measured memory_bytes: 1404
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      long[] x = new long[n];
      long[] y = new long[n];
      long[] h = new long[n];
      long X = 0;
      long Y = 0;
      long H = 0;
      for(int i = 0;i < n;i++){
      	x[i]=sc.nextLong();
        y[i]=sc.nextLong();
        h[i]=sc.nextLong();
      }
      for(int i = 0;i < n;i++)
        if(h[i]!=0){
          X = x[i];
          Y = y[i];
          H = h[i];
          break;
        }
      for(long cx = 0;cx <= 100;cx++){
      	for(long cy = 0;cy <= 100;cy++){
          boolean cnt = true;
          long H0 = H+Math.abs(cx-X)+Math.abs(cy-Y);
          for(int i = 0;i < n;i++){
          	if(h[i]!=Math.max(0,H0-Math.abs(x[i]-cx)-Math.abs(y[i]-cy)))cnt = false;
          }
          if(cnt){
          	System.out.println(cx+" "+cy+" "+H0);
            return;
          }
        }
      }
    }
}


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

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

    int mcount = 0;

    while(a >= b){
        b *= 2;
        mcount++;
    }

    while(b >= c){
        c *= 2;
        mcount++;
    }

    if(mcount <= k){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

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

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 10000000000 + 7;
// modint
const ll mod = 1e9+7;
template< int mod >
struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int) (1LL * x * p.x % mod);
      return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inv();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }
    
  ModInt inv() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while(b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  
  ModInt pow(int64_t n) const {
    ModInt ret(1), mul(x);
    while(n > 0) {
      if(n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }
  
  friend ostream &operator<<(ostream &os, const ModInt &p) {
    return os << p.x;
  }
  
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt< mod >(t);
    return (is);
  }
  
  static int get_mod() { return mod; }
};
 
using mint = ModInt<mod>;


int main(){
  cout << setprecision(10);
  int N,K; cin >> N >> K;
  map<ll,int> m;

  for(int i = 0; i < N; i++){
    ll tmp; cin >> tmp;
    m[tmp]++;
  }

  vector<mint> fact(N+1,1);
  for(int i = 1; i <= N; i++){
    fact[i] = fact[i-1] * (mint)i;
  }

  auto C = [&fact](int a, int b){
    if(a < b) return (mint)0;

    mint ret = 1;
    ret *= fact[a];
    ret *= fact[b].inv();
    ret *= fact[a-b].inv();
    return ret;
  };

  // maxの話を求める...
  int sum = 0;
  mint max_sum = 0;
  for(auto x: m){
    // sum: xより小さい者の数
    mint tmp = C(sum + x.second, K);
    tmp -= C(sum, K);
    max_sum += tmp * (mint)x.first;

    sum += x.second;
  }

  // maxの話を求める...
  sum = N;
  mint min_sum = 0;
  for(auto x: m){
    // sum: x以上の数の個数
    mint tmp = C(sum, K);
    tmp -= C(sum - x.second, K);
    min_sum += tmp * (mint)x.first;

    sum -= x.second;
  }

  mint ans = max_sum - min_sum;
  cout << ans << endl;

}


Measured memory_bytes: 9412
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <map>
#include <cctype>
using namespace std;

int main()
{
  cout << setprecision(6);
  cout << setiosflags(ios::scientific);
  cout.flags(ios::fixed);

  while(true){
    string str;
    cin >> str;

    if(str.size()==1 && str == "0")
      break;

    int sum =0;
    for(int i=0; i<str.size(); i++){
      sum += str[i] - '0';
    }
      cout << sum << endl;
  }
}

Measured memory_bytes: 1192
import sys
n, k = map(int, input().split())
a = list(map(int, input().split()))

a.sort()
if a[-1] < k:
    print('IMPOSSIBLE')
    sys.exit(0)

seta = set(a)
if k in seta:
    print('POSSIBLE')
    sys.exit(0)
lena = len(seta)
sorteda = sorted(seta)
mini = sorteda[0] if sorteda[0] != 0 else sorteda[1]
for i in range(1, len(sorteda)):
    seta.add(sorteda[i] % mini)

sorteda = sorted(seta)

mini = sorteda[0] if sorteda[0] != 0 else sorteda[1]

if k % mini == 0:
    print('POSSIBLE')
    sys.exit(0)
print('IMPOSSIBLE')

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

int main()
{
 int n;
  string s;
  cin>>n>>s;
  int ans=0;
  for(int i=1;i<n-1;i++)
  {
    set<char> pre,suf;
    for(int j=0;j<=i;j++)
      pre.insert(s[j]);
    for(int j=i+1;j<n;j++)
      suf.insert(s[j]);
    vector<char> v(103);
    auto it = set_intersection(pre.begin(),pre.end(),suf.begin(),suf.end(),v.begin());
    v.resize(it-v.begin());
    ans = max(ans,(int)v.size());
  }
  cout<<ans<<"\n";
  
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int ma[10008];
int main(){
	int n,x;
	while(~scanf("%d%d",&n,&x)){
		for(int i=0;i<n;i++)
		scanf("%d",ma+i);
		int s=1,sum=0;
		for(int i=0;i<n;i++){
			sum+=ma[i];
			if(sum<=x)
			s++;
			else
			break;
		}
		printf("%d\n",s);
	}
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
 	string s, t; cin >> s >> t;
  	int ans = 0;
  	for (int i = 0; i < 3; i++) {
    	ans += (s[i] == t[i]);
    }
  	cout << ans << endl;
	return 0;
}	

Measured memory_bytes: 256
#define DEBUG 1
#include <bits/stdc++.h>
using namespace std;
typedef          char      s8;
typedef unsigned char      u8;
typedef          short    s16;
typedef unsigned short    u16;
typedef          int      s32;
typedef unsigned int      u32;
typedef          long int s64;
typedef unsigned long int u64;
typedef float             f32;
typedef double            f64;
#define rep(_i, _n) for (int _i = 0; _i < (int)(_n); _i++)
#if DEBUG
#define PHERE()			{ cerr << "L" << setw(3) << __LINE__ << ": PHERE" << clock() << endl; }
#define PVAL( _var )	{ cerr << "L" << setw(3) << __LINE__ << ":" << #_var "=" << (_var) << endl; }
#else
#define PHERE()
#define PVAL( _var )
#endif


int main()
{
	//////// 入力 ////////
	string IN;
	cin >> IN;
	/////////////////////
	
	//////// 出力 ////////
	cout << (('A'<=IN[0] && IN[0] <= 'Z') ? 'A' : 'a');
	/////////////////////
	
	return 0;
}


Measured memory_bytes: 3624
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy


if __name__ == "__main__":
    n = int(input())
    a = list(map(int,input().split()))
    b = a[0]
    for i in range(1,n):
        b = b^a[i]
    for i in range(n):
        print(a[i]^b)

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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

#define	MOD 998244353

long	P(long A, long B) {
	long S=1;
	for (long i=0; i<B; i++) {
		S *=A;
		S %=MOD;
	}
	return S;
}

int	main() {
	int N;
	cin >>N;
	vector<int> A(N, 0);
	for (int i=0; i<N; i++)
		cin >>A.at(i);
	if (0!=A.at(0)) {
		cout <<0 <<endl;
		return 0;
	}
	sort(A.begin(), A.end());
	if ((N>1)&&(1!=A.at(1))) {
		cout <<0 <<endl;
		return 0;
	}
	long C=1;
	long C0=1;
	long S=1;
	for (int i=1; i<N; i++) {
		if (A.at(i)==A.at(i-1)) {
			C++;
		} else if (A.at(i)==A.at(i-1)+1) {
			S *=P(C0, C);
			S %=MOD;
			C0=C;
			C=1;
		} else {
			cout <<0 <<endl;
			return 0;
		}
	}
	S *=P(C0, C);
	S %=MOD;
	cout <<S <<endl;
	return 0;
}



Measured memory_bytes: 640
// ---------- begin chmin, chmax ----------
trait ChangeMinMax {
    fn chmin(&mut self, x: Self) -> bool;
    fn chmax(&mut self, x: Self) -> bool;
}

impl<T: PartialOrd> ChangeMinMax for T {
    fn chmin(&mut self, x: Self) -> bool {
        *self > x && {
            *self = x;
            true
        }
    }
    fn chmax(&mut self, x: Self) -> bool {
        *self < x && {
            *self = x;
            true
        }
    }
}
// ---------- end chmin, chmax ----------

use proconio::*;
use proconio::marker::*;

fn run() {
    input! {
        n: usize,
        k: usize,
        p: [Usize1; n],
        c: [i64; n],
    }
    let mut ans = *c.iter().max().unwrap();
    let mut used = vec![false; n];
    for i in 0..n {
        if used[i] {
            continue;
        }
        used[i] = true;
        let mut a = vec![c[i]];
        let mut sum = c[i];
        let mut pos = p[i];
        while !used[pos] {
            used[pos] = true;
            sum += c[pos];
            a.push(c[pos]);
            pos = p[pos];
        }
        for i in 0..a.len() {
            let mut s = 0;
            for (j, b) in a.iter().cycle().skip(i).take(a.len()).enumerate() {
                if j + 1 > k {
                    break;
                }
                s += *b;
                let q = ((k - j - 1) / a.len()) as i64;
                ans.chmax(s);
                ans.chmax(s + q * sum);
            }
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 2384
package main

import (
	"fmt"
	"io"
	"os"
	"strconv"
)

var pri = fmt.Println
var scan = fmt.Fscanln
var scanone = fmt.Fscan

func main() {
	solve(os.Stdin)
}

func min(a ...int) int {
	res := a[0]
	for i := 1; i < len(a); i++ {
		if res > a[i] {
			res = a[i]
		}
	}
	return res
}

func max(a ...int) int {
	res := a[0]
	for i := 1; i < len(a); i++ {
		if res < a[i] {
			res = a[i]
		}
	}
	return res
}

func mustint(a string) int {
	i, _ := strconv.Atoi(a)
	return int(i)
}

type P struct {
	x, y int
}

func (p *P) add(q *P) *P {
	return &P{p.x + q.x, p.y + q.y}
}

const huge = 1e10

func solve(rd io.Reader) {
	var n int
	scan(rd, &n)
	if n%2 == 1 {
		pri(n / 2)
	} else {
		pri(n/2 - 1)
	}
}


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

typedef long long ll;
#define mp make_pair
#define f first
#define s second
#define pb push_back

const int inf = 1e7;
const int N  = 1e5 + 5;

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

int n,k,h[N],dp[N];

int solve(int idx) {

  if(idx==n-1) return 0;

  int &ret = dp[idx];

  if(ret!=-1) return ret;

  ret = solve(idx+1) + abs(h[idx]-h[idx+1]);

  for(int t=2;t<=k;++t) {
    if(idx+t<n)
      ret = min(ret,solve(idx+t) + abs(h[idx]-h[idx+t]));
  }

  return ret;

}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> k;

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

      cin >> h[i];

    }

    memset(dp,-1,sizeof(dp));

    cout << solve(0) << endl;

    return 0;
}


Measured memory_bytes: 5760
import heapq
from collections import defaultdict, deque
from math import ceil, factorial
from fractions import gcd
import sys

sys.setrecursionlimit(10 ** 7)
INF = float("inf")
MOD = 10 ** 9 + 7

si = lambda: input().strip()
ii = lambda: int(input())
mii = lambda: map(int, input().split())
lmii = lambda: list(map(int, input().split()))
smii = lambda: sorted(map(int, input().split()))


Q, H, S, D = mii()
N = ii()

tea = [
    (Q, 0.25),
    (H, 0.5),
    (S, 1),
    (D, 2),
]
tea.sort(key=lambda x: x[0] / x[1])

ans = 0
remaining = N
for i in range(4):
    p, q = tea[i]
    d, m = map(int, divmod(remaining, q))
    if d == 0:
        continue
    ans += d * p
    remaining = m

print(int(ans))


Measured memory_bytes: 5076
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
        //MyDebugger.Test(process, "../TextFile2.txt");
        //MyDebugger.MakeTestCase("../TextFile2.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var spl = input.ReadLine().Split(' ');
        var n = int.Parse(spl[0]);
        var m = int.Parse(spl[1]);

        var maxL = 0;
        var minR = int.MaxValue;

        for (int i = 0; i < m; i++) {
            spl = input.ReadLine().Split(' ');
            var l = int.Parse(spl[0]);
            var r = int.Parse(spl[1]);

            maxL = Math.Max(l, maxL);
            minR = Math.Min(r, minR);
        }

        var ret = minR - maxL;
        if (ret < 0) return 0;
        return ret + 1;
    }
}

Measured memory_bytes: 17340
#include<bits/stdc++.h>
using namespace std;
int main(){
long long b;
cin>>b;int flag=1;long long mini=1000000000000;int in;
//if(b<=1e9){
for(long long i=1;i<=sqrt(b);i++)
{//cout<<"hi"<<endl;
    if(b%i==0)
    {if(i-1+(b/i)-1<mini)
        mini=i-1+(b/i)-1;
    in=i;//cout<<i<<" "<<(b/i)<<endl;
    }
}
if(in!=1)
cout<<mini<<endl;
else
    cout<<(b/in)*in-1<<endl;//}
//else
  //  cout<<b-1<<endl;
}


Measured memory_bytes: 256
// Aizu Vol-10 1003: Extraordinary Girl II
// 2017.8.18 bal4u@uu

#include <stdio.h>
char *gets();

char tbl[10][8] = { { 0 },
{ '\'', ',', '.', '!', '?' },
{ 'a', 'b', 'c', 'A', 'B', 'C' },
{ 'd', 'e', 'f', 'D', 'E', 'F' },
{ 'g', 'h', 'i', 'G', 'H', 'I' },
{ 'j', 'k', 'l', 'J', 'K', 'L' },
{ 'm', 'n', 'o', 'M', 'N', 'O' },
{ 'p', 'q', 'r', 's', 'P', 'Q', 'R', 'S' },
{ 't', 'u', 'v', 'T', 'U', 'V' },
{ 'w', 'x', 'y', 'z', 'W', 'X', 'Y', 'Z' } };
int len[10] = { 0,5,6,6,6,6,6,8,6,8 };

char buf[10010], *p;

int main()
{
	int d, w;
	char c;

	while (gets(p = buf) != NULL) {
		while (*p) {
			c = *p++, d = c - '0';
			w = 0;  while (*p == c) w++, p++;
			if (d == 0) while (w-- > 0) putchar(' ');
			else putchar(tbl[d][w % len[d]]);
		}
		putchar('\n');
	}
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

const ll SIZE = 1e5+10;
ll n;
ll a[SIZE];
pair<ll,ll> aa[SIZE];

int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> aa[i].first;
        aa[i].second = i+1;
    }
    sort(aa, aa+n);
    for(int i = 0; i < n; i++){
        cout << aa[i].second << ' ';
    }
    cout << endl;

}

Measured memory_bytes: 2432
N = int(input())
A = []

for i in range(N):
    s = input()
    if '.' in s:
        a,b = map(int,s.split('.'))
        if(int(b)==0):
            c = a
            d = 1
        else:
            c = a*pow(10,len(s)-s.find('.')-1)+b
            d = pow(10,len(s)-s.find('.')-1)
    else:
        c = int(s)
        d = 1
    e = 0
    f = 0
    while(c != 0 and c%2==0):
        e += 1
        c //= 2
    while(c != 0 and c%5==0):
        f += 1
        c //= 5
    while(d%2==0):
        e -= 1
        d //=2
    while(d%5==0):
        f -= 1
        d //=5
    A.append([e,f])

tm = max(max([a[0] for a in A]), -1 * min([a[0] for a in A])) + 1
fm = max(max([a[1] for a in A]), -1 * min([a[1] for a in A])) + 1

B = [[0] * (tm * 2 ) for _ in range(fm * 2)]

for a in A:
    B[a[1]+fm][a[0]+tm] += 1

for i in range(fm*2):
    for j in range(tm*2):
        if(i>0):
            B[i][j] += B[i-1][j]
        if(j>0):
            B[i][j] += B[i][j-1]
        if(i>0 and j>0):
            B[i][j] -= B[i-1][j-1]

ans = 0
for a in A:
    i = -1 * a[1] + fm
    j = -1 * a[0] + tm
    ans += B[fm*2-1][tm*2-1] - B[fm*2-1][j-1] - B[i-1][tm*2-1] + B[i-1][j-1]
    if a[1]>=0 and a[0]>=0:
        ans -= 1

print(ans//2)

Measured memory_bytes: 31768
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<ll,double> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl; 有効桁数指定
// *min_element(c + l, c + r) *max_element(c + l, c + r) 配列の中のmin-max
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// ~ は、-1の時だけfalse

int b_search(vector<int> &v,int n) {
    int l=-1,r=v.size(),mid=(r+l)/2;
    while(r-l>1) {
        if(v[mid] >= n) r = mid;
        else l = mid;
    }
    return r;
}

int main() {
    string s,t;cin>>s>>t;
    vector<int> dic[26];
    rep(i,s.size()) {
        dic[s[i]-'a'].push_back(i);
    }
    ll cnt=0,pos=0;
    rep(i,t.size()) {
        if(dic[t[i]-'a'].size()==0) {
            cout<<-1<<endl;
            return 0;
        }
        if(pos > dic[t[i]-'a'][(dic[t[i]-'a'].size()-1)]) {
            cnt++;
            pos = dic[t[i]-'a'][0] + 1;
        } else {
            // cout<<t[i]<<" "<<b_search(dic[t[i]-'a'],pos)<<endl;
            // pos = dic[t[i]-'a'][b_search(dic[t[i]-'a'],pos)] + 1;
            // pos = dic[t[i]-'a'][int(lower_bound(dic[t[i]-'a'].begin(),dic[t[i]-'a'].end(),pos))] + 1;
            auto it = lower_bound(dic[t[i]-'a'].begin(),dic[t[i]-'a'].end(),pos);
            pos = *it + 1;
        }
        // cout<<"pos "<<pos<<endl;
    }
    ll ans = cnt * s.size() + pos;
    cout<<ans<<endl;
}

Measured memory_bytes: 4236
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
#define FAST  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int 
#define ar array

const int mxn=1e5+1;
int n;
vector<int> adj[mxn];
bool vis[mxn+1];
const int mod=1e9+7;

pair<ll,ll> dfs(int node)
{
	ll all_white=1;
	ll is_black=0;
	vis[node]=true;
	for(auto i:adj[node])
	{
		if(!vis[i])
		{
			pair<ll,ll> p=dfs(i);
			ll prev_all_white=all_white;
			all_white=((ll)all_white*p.second)%mod;
			is_black=((prev_all_white*p.first)%mod+(is_black*(p.first+p.second))%mod)%mod;
		}
	}
	return make_pair(all_white,(all_white+is_black));
}
int main()
{
	FAST;
	//#ifndef ONLINE_JUDGE
	//	freopen("input.txt","r",stdin);
	//	freopen("output.txt","w",stdout);
	//#endif
	//ll testcase;
	//cin>>testcase;
	//for(ll t=0;t<testcase;t++)
	{
		cin>>n;
		for(int i=0;i<n-1;i++)
		{
			int x,y;
			cin>>x>>y;
			adj[x].push_back(y);
			adj[y].push_back(x);
		}
		pair<ll,ll> p=dfs(1);
		cout<<(p.first+p.second)%mod<<'\n';
		
	}
		
	return 0;
}




























Measured memory_bytes: 14668
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <iterator>
#include <algorithm>
#include <queue>
#include <set>
#include <bitset>
#include <vector>
#include <map>



#define IOS                    ios::sync_with_stdio();cin.tie(0);
#define tc()                int tc;scanf("%d",&tc);while(tc--)
#define endl                "\n"
#define FLOAT_COM(a,b)      if(abs(a-b)==1e-9)
#define VI                  vector<int>
#define VLL                 vector<long long>
#define PB                  push_back
#define MP                  make_pair



using namespace std;

// int i,j,k,l,temp;

void shomoy(){
    #ifndef ONLINE_JUDGE
        cerr<<"\nTime  :"<<1.0*clock()/CLOCKS_PER_SEC<<"  s\n";
    #endif

}

bool isprime(int n){
    int f;
    for(f=2;f*f<=n;f++){
        if(n%f==0)
            return false;
    }
    return true;
}


                      /*Driver Code Startes Here*/
int main(){IOS

    
    long long tc,d,count =0;
    scanf("%lld%lld",&tc,&d);
    for(int i=0;i<tc;i++){
        long long x,y;
        scanf("%lld%lld",&x,&y);
        if(x*x + y*y <=d*d){
            count++;
        }
    }
    
    cout<<count<<endl;
    

shomoy();
return 0;
}

Measured memory_bytes: 3772
N, K = map(int, input().split())
moves = [0] + list(map(int, input().split()))
points = [0] + list(map(int, input().split()))
INF = 10**10

answer = -INF
for start in range(1, N+1):
  circle = [start]
  next = moves[start]
  c_score = points[start]
  while(next != start):
    circle.append(next)
    c_score += points[next]
    next = moves[next]
  m_score = 0
  for i in range(min(len(circle), K)):
    m_score += points[circle[i]]
    loop_cnt = (K-i-1)//len(circle)
    answer = max(answer, m_score + max(0, loop_cnt * c_score))
print(answer)

Measured memory_bytes: 80784
#include <stdio.h>
#include <string.h>

static const char * e;
static int p, q, r;

static int expr ( void );

static int
term (
  void
  )
{
  int res;

  switch ( *( e++ ) )
  {
    case '-':
      res = expr ( );
      switch ( res )
      {
        case 0: res = 2; break ;
        case 2: res = 0; break ;
      }
      break ;
    case 'P': res = p; break ;
    case 'Q': res = q; break ;
    case 'R': res = r; break ;
    case '0': res = 0; break ;
    case '1': res = 1; break ;
    case '2': res = 2; break ;
  }

  return ( res );
}

static int
nanikaka (
  void
  )
{
  int lt, rt;
  char opr;
  int res;

  lt = expr ( );
  opr = *( e++ );
  rt = expr ( );

  switch ( opr )
  {
    case '*':
      res = 1;
      if ( lt == 0 || rt == 0 ) res = 0;
      if ( lt == 2 && rt == 2 ) res = 2;
      break ;
    case '+':
      res = 0;
      if ( lt == 1 || rt == 1 ) res = 1;
      if ( lt == 2 || rt == 2 ) res = 2;
      break ;
  }

  return ( res );
}

static int
expr (
  void
  )
{
  int lt, rt, res;

  switch ( *e )
  {
    case '(':
      ++e;
      res = nanikaka ( );
      ++e;
      break ;
    default:
      res = term ( );
      break ;
  }

  return ( res );
}

/** Application main entry point. */
int
main (
  int     argc,
  char  * argv[ ]
  )
{
  char s[ 128 ];

  for ( ; ; )
  {
    int res = 0;

    scanf ( " %s", s );
    if ( !strcmp ( s, "." ) ) break ;

    for ( p = 0; p <= 2; ++p )
    for ( q = 0; q <= 2; ++q )
    for ( r = 0; r <= 2; ++r )
    {
      e = s;
      res += !!( expr ( ) == 2 );
    }

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

  return ( 0 );
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define dfor(i,a,b) for(ll i=(a);i>=(b);i--)
#define mem(u, vis) memset(u, vis, sizeof(u))
#define ll long long
#define ull unsigned long long
#define MOD  1000000007
#define MAX  1e9
#define pb   push_back
#define F    first
#define S    second


int main() {
	ll t=1;
	//cin>>t;
	while(t--){
		ll n,m;
		cin>>n>>m;
		ll sum=0;
		rep(i,m){
			ll a;
			cin>>a;
			sum += a;
		}		
		if(sum>n){
			cout<<-1;
		}
		else{
			cout<<n-sum;
		}
	}
	
}

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

int main () {
  int H, W;
  cin >> H >> W;
  
  for (int i = 0; i < W+2; i++) {
    cout << "#";
  }
  cout << endl;
  
  for (int i = 0; i < H; i++) {
    string s;
    cin >> s;
    cout << "#" << s << "#" << endl;
  }
  
  for (int i = 0; i < W+2; i++) {
    cout << "#";
  }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define HAIRETU(N,A) for(int i=0;i<N;i++) cin >>A[i]
using namespace std;

int main(){
    string S,moji = "";
    cin >> S;
    for (int i = 0; i < S.size(); i++) {
        if (i % 2 == 0) {
            moji += S[i];
        }
    }
    cout << moji << endl;
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a.at(i);
  }
  
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  
  long long int ans = 0;
  for(int i=1;i<n;i++){
    ans += a.at(i/2);
  }
  cout << ans << endl;
}


Measured memory_bytes: 4044
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    long ans = 0;
    long sum = 0;
    long[] a = new long[n];
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextLong();
    }
    sum = Math.abs(a[0]) + Math.abs(a[n - 1]);
    for(int i = 0; i < (n - 1); i++) {
      sum += Math.abs(a[i] - a[i + 1]);
    }
    System.out.println(sum - Math.abs(a[0]) - Math.abs(a[0] - a[1]) + Math.abs(a[1]));
    for(int i = 1; i < (n - 1); i++) {
      System.out.println(sum - Math.abs(a[i - 1] - a[i]) - Math.abs(a[i] - a[i + 1]) + Math.abs(a[i - 1] - a[i + 1]));
    }
    System.out.println(sum - Math.abs(a[n - 1]) - Math.abs(a[n - 1] - a[n - 2]) + Math.abs(a[n - 2]));
  }
}

Measured memory_bytes: 65680
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class ABC
{
    public static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        Queue<String> B_start = new Queue<String>();
        Queue<String> A_end = new Queue<String>();
        string both = "";
        string s = "";
        for (int i = 0; i < N; i++)
        {
            string temp = Console.ReadLine();
            if (temp.EndsWith("A") && temp.StartsWith("B"))
            {
                both += temp;
            }
            else if (temp.EndsWith("A"))
            {
                A_end.Enqueue(temp);
            }
            else if (temp.StartsWith("B"))
            {
                B_start.Enqueue(temp);
            }
            else
            {
                s += temp;
            }



        }
        if (A_end.Count > 0) both = A_end.Dequeue() + both;
        if (B_start.Count > 0) both = both + B_start.Dequeue();
        while (A_end.Count != 0 && B_start.Count != 0)
        {
            both = both + A_end.Dequeue() + B_start.Dequeue();
        }
        while (A_end.Count > 0)
        {
            both = both + A_end.Dequeue();
        }
        while (B_start.Count > 0)
        {
            both = both + B_start.Dequeue();
        }
        s = s + both;
        int moto_length = s.Length;
        long output = 0;
        for (int i = 0; i < s.Length-1; i++)
        {
            if (s[i] == 'A' && s[i + 1] == 'B')
            {
                output++;
                i++;
            }

        }
        Console.WriteLine(output);

    }
}



Measured memory_bytes: 38492
#include<iostream>
using namespace std;
int n;
main()
{
	cin>>n;
	int k,m=0;
	cin>>k;
	for(;k--;)
	{
		int b;cin>>b;m|=1<<b;
	}
	for(int i=m;i<1<<n;i=(i+1)|m)
	{
		cout<<i<<":";
		for(int j=0;j<n;j++)if(i>>j&1)cout<<" "<<j;
		cout<<endl;
	}
}


Measured memory_bytes: 3112
N,K = input().split(" ")
N = int(N)
K = int(K)
p = input().split(" ")
expected_list = []
max_list = []
for i in range(N):
  expected_list.append((int(p[i])+1)/2)
anan = 0
for j in range(K):
  anan += expected_list[j]
max_list.append(anan)
for i in range(N):
  if i == 0:
    continue
  anan = 0
  try:
    anan = max_list[i-1]-expected_list[i-1]+expected_list[i+K-1]
  except:
    pass
  max_list.append(anan)
  
print(max(max_list))

Measured memory_bytes: 76552
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<sstream>
#include<numeric>
#include<cassert>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define rep(i,s,n) for(int i=(s); i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))
#define print(x) printf("%d\n",x)

using namespace std;

typedef unsigned int uint;
typedef long long ll;

const int _dx[] = {0,1,0,-1};
const int _dy[] = {-1,0,1,0};

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

int main(){
  int n;
  while(n = getInt()){
    map<int,int> m;
    REP(i,n){
      int t = getInt();
      m[getInt() + getInt()] = t;
    }
    map<int,int>::iterator it = m.end();
    it--;
    printf("%d %d\n",it->second,it->first);
  }
  return 0;
}

Measured memory_bytes: 1188
n=int(input())
a=[int(i) for i in input().split()]
MAX=a.index(max(a))
half=-1
for i in range(n):
    if abs(a[MAX]//2-a[half])>abs(a[MAX]//2-a[i]) and MAX!=i:
        half=i
print("{} {}".format(a[MAX],a[half]))

Measured memory_bytes: 62832
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define ALL(obj) (obj).begin(),(obj).end()
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef priority_queue<int> p_que;
typedef priority_queue<int, vector<int>, greater<int>()> p_que_rev;
// const int INF = INT_MAX;
const lint LINF = LLONG_MAX;
// const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};


int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    string c;
    cin >> c;
    if(c[0] == 'a' || c[0] == 'i' || c[0] == 'u' || c[0] == 'e' || c[0] == 'o'){
        cout << "vowel" << endl;
    }
    else {
        cout << "consonant" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ford(i,a,b) for(int i=(a);i>=b;i--)
#define rep(i,a,b) for(int i=(a);(i)<=(b);(i)++)
#define ll long long
#define re return
#define mp map<int,int>
#define N 200005
#define pq priority_queue<ll>
using namespace std;
int a[N],l[N],r[N];
int main() {
	int n; int ans=0;
	cin>>n;
	rep(i,1,n)cin>>a[i];
	l[1]=a[1],r[n]=a[n];
	rep(i,2,n) l[i]=__gcd(l[i-1],a[i]);
	ford(i,n-1,1) r[i]=__gcd(r[i+1],a[i]);
	rep(i,1,n) 
		ans=max(ans,__gcd(l[i-1],r[i+1]));
	cout<<ans;
	re 0;
}


Measured memory_bytes: 1408
n, k = list(map(int,input().split()))
a = list(map(int,input().split()))
for i in range(n):
    a[i] -= 1
b = [0]
flags = [-1]*n
flags[0] = 0
i = 0
while i <= n:
    c = a[b[i]]
    if flags[c] > -1:
        i += 1
        break
    else:
        i += 1
        b.append(c)
        flags[c] = i
if k <= i-1:
    for j in range(len(b)):
        b[j] += 1
    print(b[k])
else:
    #print(b)
    #print(c)
    #print(i)
    #print(flags)
    sb = i - flags[c]
    md = (k - flags[c]) % sb
    for j in range(len(b)):
        b[j] += 1
    print(b[flags[c]+md])

Measured memory_bytes: 32480
# 入力が10**5とかになったときに100ms程度早い
import sys
read = sys.stdin.readline


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_matrix(H):
    '''
    H is number of rows
    '''
    return [list(map(int, read().split())) for _ in range(H)]


def read_map(H):
    '''
    H is number of rows
    文字列で与えられた盤面を読み取る用
    '''
    return [read()[:-1] for _ in range(H)]


def read_col(H, n_cols):
    '''
    H is number of rows
    n_cols is number of cols

    A列、B列が与えられるようなとき
    '''
    ret = [[] for _ in range(n_cols)]
    for _ in range(H):
        tmp = list(map(int, read().split()))
        for col in range(n_cols):
            ret[col].append(tmp[col])

    return ret


r = read_a_int()
print(r**2)


Measured memory_bytes: 3064
#include <stdio.h>
 
int main(void) {
	int a,b;

	scanf("%d %d",&a,&b);
	do{
		if(a > b){
			printf("%d %d\n",b,a);
		}else{
			printf("%d %d\n",a,b);
		}
		scanf("%d %d",&a,&b);
	}while(a != 0 || b != 0);
	return 0;
}
 

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define pb push_back 
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin >> n;
	long long ans = 0;
	for(int i = 1; i <= n; i++){
		if(i % 5 && i % 3){
			ans += i;
		}
	}
	cout << ans << '\n';

}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  ll X, Y; scanf("%lld %lld", &X, &Y);
  bool alice = abs(X - Y) > 1;
  printf("%s\n", alice ? "Alice" : "Brown");
  return 0;
}


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


def calc(init):
    ans = 0
    sum = 0
    prev = init
    for i in range(n):
        sum += a[i]
        if sum == 0:
            ans += 1
            if prev < 0:
                sum = 1
            else:
                sum = -1
        else:
            if sum > 0 and prev > 0:
                ans += sum + 1
                sum = -1
            elif sum < 0 and prev < 0:
                ans += 1 - sum
                sum = 1
        prev = sum
    return ans


print(min(calc(1), calc(-1)))


Measured memory_bytes: 63472
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,a[15],x[15][15],y[15][15];
int f(int arr){
    bool h[15];
    for(int i=0;i<n;i++){
		h[i]=arr&1;
		arr>>=1;
    }
    for(int i=0;i<n;i++){
        if(h[i]==0){
            continue;
        }
        for(int j=0;j<a[i];j++){
            if(y[i][j]==0&&h[x[i][j]-1]==1)return 0;
            if(y[i][j]==1&&h[x[i][j]-1]==0)return 0;
        }
    }
    int res=0;
    for(int i=0;i<n;i++){
		res+=h[i];
    }
    return res;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        for(int j=0;j<a[i];j++){
            cin>>x[i][j]>>y[i][j];
        }
    }
    int ans=0;
    for(int i=0;i<(1<<n);i++){
		ans=max(ans,f(i));
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 256
import queue
H, W = map(int, input().split())
S = [input() for _ in range(H)]
white = sum(map(lambda x: x.count("."), S))
dxs = (0,1,0,-1)
dys = (1,0,-1,0)

goal = False
reached = [[None for _ in range(W)] for _ in range(H)]
reached[0][0] = 0

q = queue.Queue()
q.put((0,0))
while not q.empty():
    now = q.get()
    now_val = reached[now[1]][now[0]]
    
    for dx,dy in zip(dxs,dys):
        x = now[0] + dx
        y = now[1] + dy
        # 範囲外
        if x < 0 or y < 0 or x >= W or y >= H: continue
        # 到達済    
        if reached[y][x] is not None: continue
        # マスが黒の場合
        if S[y][x] == "#":
            reached[y][x] = -1
            continue
        # マスが城の場合
        else:
            if x == W-1 and y == H-1: goal = True
            reached[y][x] = now_val + 1
            q.put((x, y))

print((white - reached[H-1][W-1] -1) if goal else -1)

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

int N, A, B, C;
vector<int> L;

int dfs(int i, int a, int b, int c) {
  if (i == N) {
    if (a == 0 || b == 0 || c == 0) return 1e9;
    return abs(A - a) + abs(B - b) + abs(C - c);
  }
  int ans = 1e9;
  ans = min(ans, dfs(i + 1, a + L.at(i), b, c) + (a > 0 ? 10 : 0));
  ans = min(ans, dfs(i + 1, a, b + L.at(i), c) + (b > 0 ? 10 : 0));
  ans = min(ans, dfs(i + 1, a, b, c + L.at(i)) + (c > 0 ? 10 : 0));
  ans = min(ans, dfs(i + 1, a, b, c));
  return ans;
}

int main() {
  cin >> N >> A >> B >> C;
  L.resize(N);
  for (int i = 0; i < N; i++) cin >> L.at(i);

  cout << dfs(0, 0, 0, 0) << endl;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split(" ");
	//tmp = input[1].split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var a = parseInt(input[0], 10);
	var b = parseInt(input[1], 10);
    var c = parseInt(input[2], 10);
    
    if((a==b & b==c) || (a!=b & b!=c &a!=c)){
        console.log('No');

    }else{
        console.log('Yes');

    }

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

int main(){
    int d,t,s;
    cin>>d>>s>>t;
    if(s*t>=d)cout<<"Yes\n";
    else cout<<"No\n";
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define repp(i, n) rep(i, n)
#define reppp(i, n) repp(i, n)
#define rrepp(i, n) rrep(i, n)
#define repss(i, n) reps(i, n)
#define repcc(i, n) repc(i, n)
#define repii(i, a, b) repi(i, a, b)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  int n; cin >> n;
  vi32 a(n); cin >> a;
  {
    vi32 b = a;
    vi32 d(n);
    reps(i, n - 1) {
      d[i] = b[i - 1] * 2;
      b[i] -= d[i] / 2;
    }
    int diff = b[n - 1];
    d = vi32(n, 0);
    b = a;
    d[0] = diff;
    b[0] -= diff / 2;
    b[n - 1] -= diff / 2;
    reps(i, n - 1) {
      d[i] = b[i - 1] * 2;
      b[i] -= d[i] / 2;
    }
    cout << d << '\n';
  }
}


Measured memory_bytes: 2552