akhauriyash/Code-Regression huggingface dataset:
import qualified Data.ByteString.Char8 as BS
import           Data.List
import           Data.Maybe

readInt = fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words

getIntList = readIntList <$> BS.getLine
getIntMatrix = map readIntList . BS.lines <$> BS.getContents

toTable :: [[Integer]] -> [(Integer,[Integer])]
toTable = map (\book -> (head book, tail book))

solve :: Integer -> [(Integer,[Integer])] -> Integer
solve target table = if null allcosts then -1 else minimum allcosts
  where
    allcases = filter (not . null) $ subsequences table
    allcosts = map fst . filter (\(_, xs) -> all (>= target) xs) . map calc $ allcases

calc :: [(Integer,[Integer])] -> (Integer,[Integer])
calc []          = (0, repeat 0)
calc ((t, c):cs) = (t + tt, zipWith (+) c cc)
  where
    (tt, cc) = calc cs

main = do
  [_, _, target] <- getIntList
  contents <- getIntMatrix
  print $ solve target $ toTable contents


Measured memory_bytes: 4868
#include<bits/stdc++.h>
using namespace std;
int main()
{
     ios_base::sync_with_stdio(0);
     cin.tie(0);
     long long a,b,c,i,ans=1;
     cin>>a>>b;
	 c=__gcd(a,b);
	 for(i=2;i*i<=c;i++)
	 {
		 if(c%i==0)ans++;
		 while(c%i==0)
			 c/=i;
	 }
	 if(c!=1)ans++;
	 cout<<ans<<'\n';
}


Measured memory_bytes: 256
#include<cstdio>
int main(){
	char a[100][101];
	bool b[100];
	bool c[100];
	int n, m;
	scanf("%d %d", &n,&m);
	for (int i = 0; i < n; i++)b[i] = false;
	for (int i = 0; i < m; i++)c[i] = false;
	for (int i = 0; i < n; i++){
		scanf("%s", a[i]);
		for (int j = 0; j < m; j++){
			if (a[i][j] == '#'){
				b[i] = true;
				c[j] = true;
			}
		}
	}
	for (int i = 0; i < n; i++){
		if (b[i]){
			for (int j = 0; j < m; j++){
				if (c[j])printf("%c", a[i][j]);
			}
			printf("\n");
		}
	}
	return 0;
}

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


int main() {

  int n;
  cin>>n;

  long min1=2000000000;
  long min2=2000000000;
  long max1=-2000000000;
  long max2=-2000000000;


  rep(i,n){
    long x,y;
    cin>>x>>y;
    if(x+y>max1)max1=x+y;
    if(x-y>max2)max2=x-y;
    if(x+y<min1)min1=x+y;
    if(x-y<min2)min2=x-y;
  }

  long ans=max(max1-min1,max2-min2);

  
  cout<<ans<<endl;
  return 0;

}


Measured memory_bytes: 3584
import scala.io.StdIn.readLine

class Dice(var d:Array[Int]) {
  val s = Array(4,0,2,3,5,1)
  val n = Array(1,5,2,3,0,4)
  val w = Array(2,1,5,0,4,3)
  val e = Array(3,1,0,5,4,2)

  def roll(dir:Char)  =
    d = dir match {
      case 'S' => s.map(d)
      case 'N' => n.map(d)
      case 'W' => w.map(d)
      case 'E' => e.map(d)
    }

  def getTopFace() = d(0)
}

object Main extends App {
  val faces = readLine.split(" ").map(_.toInt)
  val dice = new Dice(faces)

  readLine.foreach { dice.roll _ }
  println(dice.getTopFace)
}

Measured memory_bytes: 44160
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s,d[100][100],f,g=0,h,i,j,k[100][100],l=0,q,w=2100000000;
	char z[100][100];
	scanf("%d %d",&a,&s);
	for(i=0;i<a;i++)
		scanf("%s",z[i]);
		for(i=0;i<a;i++){
			k[1][i]=0;
			k[2][i]=0;
			k[3][i]=0;
			d[1][i]=0;
			d[2][i]=0;
			d[3][i]=0;
		}
	for(i=0;i<a;i++){
		for(j=0;j<s;j++){
			if(z[i][j]!='W')
				d[1][i]++;
			if(z[i][j]!='B')
				d[2][i]++;
			if(z[i][j]!='R')
				d[3][i]++;
		}
	}
	for(i=1;i<a-1;i++){
		for(j=a-1;j>1;j--){
			q=0;
			if(i<j){
				for(h=0;h<i;h++)
					q+=d[1][h];
			//	printf("%d %d  %d",i,j,q);
				for(h=i;h<j;h++)
					q+=d[2][h];
			//	printf("  %d",q);
				for(h=j;h<a;h++)
					q+=d[3][h];
			//	printf("  %d\n",q);
				if(w>q)
					w=q;
				//printf("%d %d %d\n",i,j,q);
			}
		}
	}
	printf("%d\n",w);
		return 0;
}

Measured memory_bytes: 2684
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

template<class U, class V>
istream& operator >>(istream& in, pair<U, V>& pr) {
    return in >> pr.first >> pr.second;
}

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    string S;
    int N;
    cin >> N >> S;

    for(char& c : S) {
        int i = N + c - 'A';
        c = char('A' + i % 26);
    }

    cout << S << endl;
    return 0;
};

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    long a = 1;
    long b = 1;
    
    for(int i = 0; i < N; i++){
      String[] S = sc.nextLine().split(" ");
      int x = Integer.parseInt(S[0]);
      int y = Integer.parseInt(S[1]);
      
      
      
      long n = Math.max(((a + x - 1)/x), ((b + y - 1)/y));
      
      a = x * n;
      b = y * n;
      
    }
    
    long ans = a + b;
    System.out.println(ans);
  }
}

Measured memory_bytes: 25044
#include <iostream>
using namespace std;
int main(){
  long long a,b;
  cin >> a >> b;
  long long kotae = 0;
  long long bai = 0;
  while(1){
    bai++;
    if(a * bai % b == 0){
      kotae = a * bai;
      break;
    }
  }
  cout << kotae << endl;
}

Measured memory_bytes: 256
def main():
    import fractions
    a,b,c,d=map(int, input().split())
    def lcm(c,d):
        return c*d//fractions.gcd(c,d)
    e=lcm(c,d)
    ans=(b-a+1)-((b//c-(a-1)//c)+(b//d-(a-1)//d))+(b//e-(a-1)//e)
    print(ans)
    
if __name__=='__main__':
    main()

Measured memory_bytes: 5432
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	vector<ll>ch;
	for(ll i=0;i<n;i++){
		ll now;
		cin>>now;
		ch.push_back(now);
	}
	sort(ch.begin(),ch.end());
	long double ans=ch[0];
	for(ll i=1;i<n;i++){
		ans+=ch[i];
		ans/=2;
	}
	cout <<ans;
	return 0;
}

Measured memory_bytes: 3824
#[allow(unused_macros)]
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 ) * } } ; }
#[allow(unused_macros)]
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 ) * } } ; }
#[allow(unused_macros)]
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! {
        s: chars
    }

    let c = count(&s);
    println!("{}", 700 + 100 * c.get(&'o').unwrap_or(&0));
}

#[allow(dead_code)]
fn count<T: Eq + std::hash::Hash + Clone>(slice: &[T]) -> std::collections::HashMap<T, usize> {
    let mut hmap = std::collections::HashMap::new();
    for item in slice {
        *hmap.entry(item.clone()).or_insert(0) += 1;
    }
    hmap
}

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

int main() {
    int N;
    while (cin >> N, N) {
        string process;
        cin >> process;
        vector<int> locked(N);
        vector<set<int>> next(1<<12);
        vector<int> is(1<<12);
        bool ans = true;

        for (int i = 0, now = 0; i < N; i++) {
            is[now] = true;
            if (process[i] == 'u') {
                now = 0;
                continue;
            }
            int s = process[i] - '0';
            if (now & (1 << s)) ans = false;

            next[now].insert(s);
            now += (1 << s);
        }

        for (int i = 0; ans && i < (1 << 11); i++) {
            for (int j = 0; j < (1 << 11); j++) {
                if ((i & j) != j) continue;
                int nj = i ^ j;
                bool flag = false;

                if (j == nj) continue;
                if (!is[j] || !is[nj]) continue;
                if (next[j].size() == 0 || next[nj].size() == 0) continue;
                is[i] = true;

                for (auto k : next[j]) {
                    if (!(nj & (1 << k))) flag = true;
                    if (!(j & (1 << k)) && !(nj & (1 << k)))
                        next[i].insert(k);
                }
                for (auto k : next[nj]) {
                    if (!(j & (1 << k))) flag = true;
                    if (!(j & (1 << k)) && !(nj & (1 << k)))
                        next[i].insert(k);
                }

                if (!flag) {
                    ans = false;
                }
            }
        }

        if (ans) cout << "SAFE" << endl;
        else cout << "UNSAFE" << endl;
    }

    return 0;
}

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

typedef long long ll;
#define REP(i,n) for(ll i=0; i<(ll)(n); i++)
#define REPM(i,n) for(ll i=(n-1); 0=<i; i--)
#define VI vector<int>
#define VL vector<ll>
#define VD vector<double>
#define VS vector<string>
#define V_SORT_U(x) sort(x.begin(), x.end());
#define V_SORT_D(x) sort(x.begin(), x.end(),greater<int>());
#define V_SUM(x) accumulate(x.begin(), x.end(), 0)
#define STR_TRANS_UP(x) transform(x.begin(), x.end(), x.begin(), ::toupper);
#define STR_TRANS_LOW(x) transform(x.begin(), x.end(), x.begin(), ::tolower);

int main(void){
    ll N;
    cin >> N;

    ll sum=0;

    REP(i,N)
    {
        ll chk = i+1;
        if ( chk % 3 == 0)
        {
            continue;
        }
        if ( chk % 5 == 0)
        {
            continue;
        }

        //cout << chk << endl;
        sum += chk;
    }

    cout << sum << endl;
    return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vch = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
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;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;

int main(){
	st s;
	ll k, n;
	cin >> s >> k;
	n = s.size();
	vvll dp1(n + 1, vll(k + 1, 0)), dp2(n + 1, vll(k + 1, 0));
	dp2.at(0).at(0) = 1;
	rep(i, 0, n)rep(j, 0, k + 1){
		if(s.at(i) == '0'){
			dp1.at(i + 1).at(j) += dp1.at(i).at(j);
			dp2.at(i + 1).at(j) += dp2.at(i).at(j); 
			if(j < k) dp1.at(i + 1).at(j + 1) += dp1.at(i).at(j) * 9;
		}
		else{
			dp1.at(i + 1).at(j) += dp1.at(i).at(j) + dp2.at(i).at(j);
			if(j < k){
				dp1.at(i + 1).at(j + 1) += dp1.at(i).at(j) * 9 + dp2.at(i).at(j) * (s.at(i) - '1');
				dp2.at(i + 1).at(j + 1) += dp2.at(i).at(j);
			}
		}
	}

	cout << dp1.at(n).at(k) + dp2.at(n).at(k) << endl;
}

Measured memory_bytes: 256
# coding: utf-8

n, m = map(int, input().split())
v = list(map(int, input().split()))

sum = 0
for i in range(n):
    sum += v[i]
count = 0

for i in range(m):
    if max(v) < (sum/4/m):
        break
    count += 1
    v.remove(max(v))

if count == m:
    print("Yes")
else:
    print("No")


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

int a[100007];

int gcb(int x,int y)
{
	while (x != y)
	{
		if (x > y)x = x = y;
		else y = y - x;
	}
	return x;
}

int main()
{
	int n, k;
	scanf("%d %d", &n, &k);
	for (int i = 0; i < n; i++)scanf("%d", a + i);
	sort(a, a + n);
	if (n == 1)
	{
		if (k != a[0])printf("IMPOSSIBLE\n");
		else printf("POSSIBLE\n");
		return 0;
	}
	if (a[n - 1] < k)
	{
		printf("IMPOSSIBLE\n");
		return 0;
	}
	int ans = gcb(a[0], a[1]);
	for (int i = 2; i < n; i++)
	{
		int ans1 = gcb(a[i-1], a[i]);
		ans = gcb(ans, ans1);
		if (ans == 1)break;
	}
	if (k%ans != 0)
	{
		printf("IMPOSSIBLE\n");
	}
	else
	{
		printf("POSSIBLE\n");
	}
	return 0;
}

Measured memory_bytes: 640
//#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++){for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<typename T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << p.first << " " << p.second;}
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){for(auto &z:v)os << z << " ";cout<<"|"; return os;}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n,x,m;cin>>n>>x>>m;
  vector<bool>t(m);
  vector<ll>a;
  ll now=x;
  ll sum=0;
  while(!t[now]){
    t[now]=true;
    a.PB(now);
    sum+=now;
    now=(now*now)%m;
  }
  ll idx=0;
  rep(i,0,a.size()){
    if(a[i]==now){
      idx=i;
      break;
    }
    sum-=a[i];
  }
  ll len=(ll)a.size()-idx;
  rep(i,0,min(idx,n))res+=a[i];
  ll rem=max(0LL,n-idx);
  //debug(a,a.size());
  //cout<<idx spa len spa rem spa sum<<endl;
  res+=(rem/len)*sum;
  rep(i,idx,idx+rem%len)res+=a[i];
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 3872
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++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(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
 
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int X,Y,Z;
  cin>>X>>Y>>Z;
  cout<<(X-Z)/(Y+Z)<<endl;
    
 
}
  







Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using Graph = vector<vector<LL>>;

long long gcd(long long a, long long b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
long long chmax(long long a,long long b){
  a = max(a,b);
}
long long chmin(long long a, long long b){
  a = min(a,b);
}
vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true;

    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue;
        dfs(G, next_v);
    }
}



int main() {
  LL n,k=-1,sum=0,a=0,b=0,c=0,d=0,ans=0;
  long double L=0,E=0;
  LL MOD = 1000000007;
  LL INF = 1LL << 60;
  string S="";
  cin >> L;
  E = L/3.0;
  cout <<setprecision(20)<< E*E*E << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int i, j, x, y, n, data[15][15];

  while(1){
    scanf("%d", &n);
    if(n == 0) break;

    for(i=0; i<n; i++){
      for(j=0; j<n; j++)
        data[i][j] = 0;
    }

    for(i=0, x=n/2+1, y=n/2; i<n*n; i++, x++, y++){
      if(x == n && y == n){
        x = 0;
        y = 0;
      }else if(x == n){
        x = 0;
      }else if(y == n){
        y = 0;
      }

      while(data[x][y] != 0){
        x++;
        y--;

        if(x == n && y == -1){
          x = 0;
          y = n-1;
        }else if(x == n){
          x = 0;
        }else if(y == -1){
          y = n-1;
        }
      }

      data[x][y] = i+1;
    }

    for(i=0; i<n; i++){
      for(j=0; j<n-1; j++)
        printf("%4d", data[i][j]);
      printf("%4d\n", data[i][n-1]);
    }
  }

  return 0;
}

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

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

def solve(N: int, X: int, x: "List[int]"):
    dis = []
    for a in x:
        dis.append(abs(X - a))
    ret = dis[0]
    for i in range(1, len(dis)):
        ret = gcd(ret, dis[i])
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    x = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, X, x)

if __name__ == '__main__':
    main()


Measured memory_bytes: 19236
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<ll, ll>;
using iii = pair<ii, ll>;
#define vt vector
#define pb push_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second
#define __lcm(a, b) a * b / __gcd(a, b)x
const ll MOD = 1e9 + 7;
const ll INF = 2e9;
const ll N = 1e2 + 5;
const ll M = 1e3 + 5;

ll n, cap, sum, temp, ans;
ll w[N], v[N];
ll dp[N][N * M];

ll f(ll idx, ll val) {
    if(idx > n) return val == 0 ? 0 : INF;
    ll &sol = dp[idx][val];
    if(sol != -1) return sol;
    return sol = min(f(idx + 1, val - v[idx]) + w[idx], f(idx + 1, val));
}

void solve() {
    cin >> n >> cap;
    for(ll i = 1; i <= n; i++) {
        cin >> w[i] >> v[i];
        sum += v[i];
    }
    memset(dp, -1, sizeof(dp));
    for(ll i = 1; i <= sum; i++) {
        temp = f(1, i);
        if(temp == INF) continue;
        if(temp <= cap) ans = i;
    }
    cout << ans << "\n";
}

int main() {
 
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    solve();
    
}

Measured memory_bytes: 90224
from operator import itemgetter
n,k = map(int,input().split())
li=[]
s=[]
t=[]
g=0
ans=[]
retu=[0]*n
p=0
q=0
for _ in range(n):
    a,b=map(int,input().split())
    li.append([a,b])
li=sorted(li,key=itemgetter(1),reverse=True)
for i in range(k):
    g+=li[i][1]
    if retu[li[i][0]-1]==0:
        retu[li[i][0]-1]+=1
        p+=1
    else:
        t.append(li[i][1])
        q+=1
g+=p**2
ans.append(g)
for i in range(k,n):
    if q==0:
        break
    if retu[li[i][0]-1]==0:
        g=g-t[q-1]+li[i][1]+2*p+1
        p+=1
        q-=1
        ans.append(g)
        retu[li[i][0]-1]+=1
print(max(ans))

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

int dp[222][111];

int Grundy(int h,int w){
  int &g=dp[h][w];
  
  if(g!=-1)return g;
  if(h==0&&w==0)return g=0;

  set<int>V;

  if(h)V.insert(Grundy(h-1,w));
  for(int i=1;i<=min(h,w);i++)V.insert(Grundy(h,w-i));
  if(w)V.insert(Grundy(h+1,w-1));

  g=0;
  while(V.count(g))++g;
  return g;
}

int main(){
  memset(dp,-1,sizeof(dp));
  int n,ans=0;
  cin>>n;
  r(i,n){
    int a,b;
    cin>>a>>b;
    ans^=Grundy(a,b);
  }
  cout<< (ans? 0:1) <<endl;
}


Measured memory_bytes: 3464
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
#define int long long
using namespace std;
const int mod(1e9 + 7);
int n, k, smin, smax, res;
int32_t main() {
    DAU
    cin >> n >> k;
    for (int i = k; i <= n + 1; ++i) {
        smin = i * (i - 1) / 2LL;
        smax = (n * (n + 1) - (n - i) * (n - i + 1)) / 2;
        res = (res + smax - smin + 1) % mod;
    }
    cout << res;
    PLEC
}


Measured memory_bytes: 3660
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <math.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define printA(arr) for(int i = 0; i < SZ(arr); i++){cout << arr[i];if (i==SZ(arr)-1){cout<<endl;}else{cout << " ";}}
typedef long long ll;

int main()
{
  int x;
  cin >> x;
  int best = 1;
  /*
  input 10
  p=2
  b=2 -> 4
  b=3 -> 9
  b=4 -> 16 x
  p=3
  b=2 -> 8
  b=3 -> 27 x
  p=4
  b=2 -> 16 x
  */
  for(int p=2;pow(2,p)<=x;p++){
    int bp=1;
    for(int b=2;1;b++){
      bp = pow(b,p);
      if(bp>x){
        break;
      }
      best = max(bp,best);
      //cout << b << " " << p << endl;
    }
  }

  cout << best << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
import numpy as np
import math  # gcdもあるよ
from collections import deque
from collections import defaultdict
from copy import deepcopy
from itertools import accumulate #リストを与えると累積和を返す
def input(): return sys.stdin.readline().rstrip()
from functools import lru_cache #メモ化

def main():
    INF = 10**9
    n = int(input())
    A = list(map(int,input().split()))
    B = [0] * n
    for i in range(len(A) - 1):
        B[i + 1] = A[i + 1] - A[i]
    #print(B)
    B.append(-INF)
    C = ['D'] * (n + 1)
    for i in range(1, len(B)):
        if B[i] > 0:
            C[i] = 'U'
        if B[i] == 0:
            C[i] = C[i - 1]
    #print(C)

    money = 1000
    stock = 0

    for i in range(n):
        if C[i] == 'D' and C[i + 1] == 'U':
            stock = money // A[i]
            money = money - (stock * A[i])
        if C[i] == 'U' and C[i + 1] == 'D':
            #売る
            money += stock * A[i]
            stock = 0
    print(money)
    return 0

if __name__ == "__main__":
    main()

Measured memory_bytes: 27204
import numpy as np

def solve(stdin):
    n = stdin[0]
    dp = np.zeros(n+1,dtype=np.int64)
    for i in range(1,n+1):
        for j in range(i,n+1,i):
            dp[j]+=1
    dp*=np.arange(n+1)
    return dp.sum()

def main():
    stdin = np.fromstring(open(0).read(), dtype=np.int64, sep=' ')
    print(solve(stdin))

def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', '(i8[:],)')(solve)
    cc.compile()

if __name__ == '__main__':
    import sys
    if sys.argv[-1] == 'ONLINE_JUDGE':
        cc_export()
        exit(0)
    from my_module import solve
    main()

Measured memory_bytes: 183236
#include<iostream>
using namespace std;
int solve(int p1, int p2, int p3, int p4) {
	if (p1 >= 5)p1 = 0; if (p2 >= 5)p2 = 0; if (p3 >= 5)p3 = 0; if (p4 >= 5)p4 = 0;
	if (p1 == 0 && p2 == 0)return 0;
	if (p3 == 0 && p4 == 0)return 0;
	int G[6] = { 0,0,0,0,0,0 };
	if (p1 != 0 && p3 != 0) { G[solve(p3 + p1, p4, p1, p2)] = 1; }
	if (p1 != 0 && p4 != 0) { G[solve(p3, p4 + p1, p1, p2)] = 1; }
	if (p2 != 0 && p3 != 0) { G[solve(p3 + p2, p4, p1, p2)] = 1; }
	if (p2 != 0 && p4 != 0) { G[solve(p3, p4 + p2, p1, p2)] = 1; }
	for (int i = 0; i < 6; i++) {
		if (G[i] == 0) { return i; }
	}
}
int main() {
	int v1, v2, v3, v4; cin >> v1 >> v2 >> v3 >> v4;
	int res = solve(v1, v2, v3, v4);
	if (res == 0)cout << "NAKAJIMA" << endl;
	else cout << "ISONO" << endl;
	return 0;
}

Measured memory_bytes: 3088
A, B, C, X = gets.to_i, gets.to_i, gets.to_i, gets.to_i
ans=0
for a in 0..A do
    for b in 0..B do
        for c in 0..C do
            if a*500+b*100+c*50==X then
                ans+=1
            end
        end
    end
end
puts ans

Measured memory_bytes: 1788
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    static class CAttackSurvival
    {
        static void Main(string[] args)
        {
            var nkq = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
            long n = nkq[0];
            long k = nkq[1];
            long q = nkq[2];
            var aList = new List<long>();
            for (int i = 0; i < q; i++)
            {
                aList.Add(long.Parse(Console.ReadLine()));
            }

            var notDecreaseCounts = new long[n].ToList();
            foreach (var a in aList)
            {
                notDecreaseCounts[(int)a - 1]++;
            }

            for (int i = 0; i < n; i++)
            {
                Console.WriteLine(k - aList.Count + notDecreaseCounts[i] > 0 ? "Yes" : "No");
            }            
            Console.ReadLine();
        }
    }
}

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

int main() {
  string N;
  cin >> N;
  if ((N[0]==N[1] && N[1]==N[2]) || N[1]==N[2] && N[2]==N[3]) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 3628
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"


struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

struct edge {
	int id;
	int to;
	int from;
	long long int time;
};
vector<edge>es;

int N, M;
pair<set<int>, long long int > getans(int banid) {
	UnionFind uf(N);
	long long int  cost = 0;
	set<int>aset;
	for (auto e : es) {
		if (uf.root(e.from) == uf.root(e.to))continue;
		if (e.id == banid)continue;
		else {
			uf.unionSet(e.from, e.to);
			cost += e.time;
			aset.emplace(e.id);
		}
	}
	if (uf.size(0) == N) {
		return make_pair(aset, cost);
	}
	else {
		return make_pair(aset, 2e12);
	}
}
int main() {cin >> N >> M;
	for (int i = 0; i < M; ++i) {
		int s, d, c; cin >> s >> d >> c; s--; d--;
		es.push_back(edge{ i,s,d,c });
	}
	sort(es.begin(), es.end(), [](const edge&l, const edge&r) {return l.time < r.time; });
	for (int i = 0; i < M; ++i) {
		es[i].id = i;
	}
	auto p(getans(-1));
	long long int mincost = p.second;
	vector<int>ans;
	long long int sum = 0;
	for (auto e : p.first) {
		if (getans(e).second != mincost) {
			ans.emplace_back(e); 
			sum += es[e].time;
		}
	}
	cout << ans.size() << " " << sum << endl;
	return 0;
}

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

int main() {
	int n,flag=0,a,b,c;
	long y;
	cin >> n >> y;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n-i;j++){
			int k = n-i-j;
			if(10000*i+5000*j+1000*k == y){
				flag = 1;
				a=i;					b=j;
				c=k;
				break;
			}
		}
		if(flag==1)break;
	}
	if(flag != 1){
		a = -1;
		b = -1;
		c = -1;
	}
	cout << a << " "<< b  << " " << c << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  cin >> s;
  string ans = "Yes";
  for(int i = 0;i < s.size();i++){
    for(int j = i+1;j < s.size();j++){
      if(s[i] == s[j]){
        ans = "No";
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
/**
 *    Coded by : lucky_21
 *               --------Lokesh Singh
**/

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

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

#define     F           first
#define     S           second
#define     pb          push_back
#define     lb          lower_bound
#define     ub          upper_bound
#define     pii         pair<int,int>
#define     all(x)      x.begin(),x.end()
#define     fix         fixed<<setprecision(10)
#define     rep(i,a,b)  for(int i=int(a);i<=int(b);i++)
#define     repb(i,b,a) for(int i=int(b);i>=int(a);i--)
#define     FastIO      ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)

typedef double db;
typedef long long ll;

const int N=2e5+5;
const int mod=1e9+7;

signed main(){
    FastIO;
    int l,r,d;
    cin>>l>>r>>d;
    cout<<r/d-(l-1)/d;
    return 0;
}



Measured memory_bytes: 3648
// Code by H~$~C
#include <bits/stdc++.h>
using namespace std;

static const int Maxn = 55;
static const double EPS = 1e-9;

int n;

struct point {
  double x, y;
} a[Maxn];
inline double get_dist(double x, double y) {
  double mx = 0;
  for (int i = 1; i <= n; ++i) {
    double now = sqrt((x - a[i].x) * (x - a[i].x) + (y - a[i].y) * (y - a[i].y));
    mx = max(mx, now);
  }
  return mx;
}

double f(double x) {
  double l = 0, r = 1000;
  while (r - l > EPS) {
    double lmid = l + (r - l) / 3.0;
    double rmid = r - (r - l) / 3.0;
    if (get_dist(x, lmid) > get_dist(x, rmid)) l = lmid;
    else r = rmid;
  }
  return get_dist(x, l);
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%lf%lf", &a[i].x, &a[i].y);
  double l = 0, r = 1000;
  while (r - l > EPS) {
    double lmid = l + (r - l) / 3.0;
    double rmid = r - (r - l) / 3.0;
    if (f(lmid) > f(rmid)) l = lmid;
    else r = rmid;
  }
  printf("%.7lf\n", f(l));
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1e9+100;
const ll MOD = 1e9;
const double EPS = 1e-10;
const bool debug = 1;
//------------------------------//

int n;
vector<pii> g[112345]; // to, cost
int dp[112345];

int dfs1(int u, int pre) {
	int res = 0;
	REP(i, g[u].size()) if (g[u][i].fi != pre)
		chmax(res, dfs1(g[u][i].fi, u) + g[u][i].se);
	return dp[u] = res;
}

int dfs2(int u, int pre, int par) {
	vector<pii> child;
	child.push_back(pii(0, -1));
	child.push_back(pii(0, -1));
	
	REP(i, g[u].size()) {
		int to = g[u][i].fi, cost = g[u][i].se;
		if (to == pre) child.push_back(pii(par + cost, to));
		else child.push_back(pii(dp[to] + cost, to));
	}
	sort(ALL(child), greater<pii>());
	
	int res = child[0].fi + child[1].fi;
	
	REP(i, g[u].size()) {
		int to = g[u][i].fi;
		if (to == pre) continue;
		
		if (child[0].se == to) chmax(res, dfs2(to, u, child[1].fi));
		else chmax(res, dfs2(to, u, child[0].fi));
	}
	
	return res;
}

int main() {
	cin >> n;
	REP(i, n - 1) {
		int s, t, w;
		scanf("%d %d %d", &s, &t, &w);
		g[s].push_back(pii(t, w));
		g[t].push_back(pii(s, w));
	}
	
	dfs1(0, -1);
	cout << dfs2(0, -1, 0) << endl;
	return 0;
}

Measured memory_bytes: 26436
#define	_USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
using namespace std;
int main(){
	
	int n,m;
	
	while(cin>>n>>m,n!=0&&m!=0){
	int a;
	vector<int>	w(m+1);
	
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
		cin>>a;
			if(a==1){
				w[j]++;
			}
		}
	}
	
	bool f=false;
	for(int i=0;i<m;i++){
		int max=-1;
		int id=0;
		for(int j=0;j<m;j++){
			if(max<w[j]){
				max=w[j];
				id=j;
			}
		}
		if(!f){
			cout<<id+1;
			f=true;
		}
		else
			cout<<" "<<id+1;
		
		w[id]=-999999;
	}
	cout<<endl;
	}
	
}

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

int main(){
  ll n, a, b;
    cin >> n >> a >> b;
  ll ans=0;
  if(b<a){
    ans = 0;
  }else if(n==1){
    ans = 1;
    if(a!=b) ans=0;
  }else if(n==2){
    ans = 1;
  }else{
    ans = (n-2)*(b-a) + 1;
  }
    cout << ans << endl;
}


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

using namespace std;

int main()
{
    int a, b, c, d;
    cin>>a>>b>>c>>d;
    int e=a/d, f=c/b;
    if(c%b!=0){
       f++;
    }
    if(a%d!=0){
        e++;
    }
    if(f<=e){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define INF 1e9
#define all(v) v.begin(), v.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
using namespace std;

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

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

    int n, y;
    cin>>n>>y;
    int x[n];
    rep(i, n)
        cin>>x[i];
    int tmp = abs(y-x[0]);
    rep(i, n){
        tmp = gcd(tmp, abs(y-x[i]));
    }
    cout<<tmp<<endl;
    return 0;
} 


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
    int M = 0;
    int D = 0;
    
    cin >> M;
    cin >> D;
    
    int d10 = D/10;
    int d1 = D%10;
    int count = 0;
    for(int i = 1; i <= M; ++i){
        for(int j = 11; j <= D; ++j){
            int d10 = j/10;
            int d1 = j%10;
            if(d1 >=2 && d10 >=2){
                if(i == d10*d1){
                    //cout << i<<d10<<d1<<endl;
                    
                    count++;
                }
            }
        }
    }
    cout << count;
    return 0;
}





Measured memory_bytes: 256
# -*- coding: utf-8 -*-
#
#すぬけ君は、犬を N 匹と猿を M 匹飼っています。
#すぬけ君は、この N+M 匹を一列に並べようと思っています。
#文字通り犬猿の仲の犬たちと猿たちを仲直りさせたいすぬけ君は、
#犬同士、または猿同士が隣り合うところができないように並べようと思っています。
#このような並べ方は何通りあるでしょうか。
#犬と猿は 109+7 以上の数を理解できないので、
#並べ方の個数を 109+7 で割ったあまりを求めてください。 
#ただし、犬同士、また猿同士は互いに区別します。また、左右が反転しただけの列も異なる列とみなします。

import math

Data = input().split()
N = int(Data[0])
M = int(Data[1])

if abs(N - M) >= 2:
    print(0)
    
else:
    
    A = math.factorial(N)
    B = math.factorial(M)

    if N == M:
        ans1 = A * B * 2
    else:
        ans1 = A * B
    
    ans2 = ans1 % (1000000000 + 7)
    
    print(ans2)




Measured memory_bytes: 5184
// AOJ 1262: Atomic Car Race
// 2017.12.4 bal4u@uu

#include <stdio.h>
#include <string.h>

#define MAX 10000
typedef struct { double t; int node; } QUE;
QUE que[MAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
	que[0] = que[--qsize];
	min_heapify(0);
}

void enq(int n, double t)
{
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].node = n, que[i].t = t;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

int n;
int a[101];
double s[10005], dist[101], b;

double dijkstra()
{
	int i, k;
	double d;

	memset(dist, 0x53, sizeof(dist));
	qsize = 0;
	dist[0] = 0;
	enq(0, 0);
	while (qsize) {
		k = que[0].node; deq();
		if (k == n) break;
		for (i = k+1; i <= n; i++) {
			d = 0;
			if (k > 0) d = b;
			d += dist[k] + s[a[i]-a[k]];
			if (d < dist[i]) dist[i] = d, enq(i, d);
		}
	}
	return dist[n];
}

int main()
{
	int r, i, j;
	double v, e, f, t;

	while (scanf("%d", &n) && n > 0) {
		for (i = 1; i <= n; i++) scanf("%d", a+i);
		scanf("%lf%d%lf%lf%lf", &b, &r, &v, &e, &f);

		for (s[0] = 0, j = 0; j < a[n]; j++) {
			t = (r <= j) ? 1.0/(v-e*(j-r)) : 1.0/(v-f*(r-j));
			s[j+1] = s[j] + t;
		}
		printf("%.8lf\n", dijkstra());
	}
	return 0;
}

Measured memory_bytes: 1828
#include<stdio.h>
int main() {
	int N;
	scanf("%d", &N);
	int *A = (int *)malloc(sizeof(int)*N);
	for (int i = 0; i < N; i++)
	{
		scanf("%d", &A[i]);
	}
	if (N % 2 == 0)
	{
		for (int i = N - 1; i > 0; i -= 2)
		{
			printf("%d ", A[i]);
		}
		for (int i = 0; i < N; i += 2)
		{
			printf("%d ", A[i]);
		}
	}
	if (N % 2 == 1)
	{
		for (int i = N - 1; i >= 0; i -= 2)
		{
			printf("%d ", A[i]);
		}
		for (int i = 1; i < N; i += 2)
		{
			printf("%d ", A[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(int i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll k, n;
  cin >> k >> n;
  vl a(n);
  rep(i, n) cin >> a[i];
  vl d(n);
  d[n - 1] = a[0] + k - a[n - 1];
  rep(i, n - 1) d[i] = a[i + 1] - a[i];
  cout << accumulate(all(d), 0) - *max_element(all(d)) << endl;
}

Measured memory_bytes: 3328
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 10;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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

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

    string ans = "NO";
    ll sum = A;
    for(int i=2; i<100000000; i++) {
        if (sum%B==C) {
            ans = "YES";
            break;
        }
        sum += A;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val abcd = sc.next()
  val a = abcd.head.toString.toInt
  val bcd = abcd.tail.map(_.toString.toInt)

  def product[A](l: List[A], n: Int): List[List[A]] = {
    def product(n: Int, res: List[List[A]] = List(Nil)): List[List[A]] = {
      if (n == 0) res else product(n - 1, for (x <- l; r <- res) yield x :: r)
    }
    product(n)
  }

  val fs = product(List(1, -1), 3).find(l =>
    l.zip(bcd).map{case (f, v) => f * v}.sum + a == 7
  ).get
  print(a)
  for ((f, v) <- fs.zip(bcd)) {
    print(if (f == 1) "+" else "-")
    print(v)
  }
  println("=7")
}


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

using namespace std;

int main(void) {
  int n;
  cin >> n;
  vector<int> a = vector<int>(n, 0);

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

  int ans = 0;
  for (int i = 0; i < n; i++) {
    bool canDivide = true;

    while(canDivide) {
      if (a[i] % 2 == 0 && a[i] != 0) {
        // canDivide
        a[i] /= 2;
        ans++;
      }
      else {
        // cannot divide
        canDivide = false;
      }
    }
  }

  cout << ans << endl;

  return 0;
}

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

int main() {
    long long n, k, a, b, count=0, ans;
    cin >> n >> k;
    vector<long long> vec(100000,0);
    for(int i=0; i<n; i++) {
        cin >> a >> b;
        vec.at(a-1)+=b;
    }
    for(int i=0; i<100000; i++) {
        count += vec[i];
        if(count>=k) {
            ans=i+1;
            break;
        }
    }
    cout << ans;
}

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

using namespace std;

using ll = long long;
template <class T>
struct BIT {
    int n;
    vector<T> data;
    BIT(int n) : n(n), data(n) {}
    T sum(int i) {
        T res(26);
        for (; i >= 0; i = (i & (i + 1)) - 1)
            res += data[i];
        return res;
    }
    void add(int i, T val) {
        for (; i < n; i |= i + 1)
            data[i] += val;
    }
};

int main() {
    int N, Q;
    cin >> N;
    string S;
    cin >> S;
    BIT<valarray<int>> bit(N + 1);
    fill(bit.data.begin(), bit.data.end(), valarray<int>(26));
    for (int i = 0; i < N; i++) {
        valarray<int> cnt(26);
        cnt[S[i] - 'a'] = 1;
        bit.add(i + 1, cnt);
    }
    cin >> Q;
    for (int i = 0; i < Q; i++) {
        int q;
        cin >> q;
        if (q == 1) {
            int ind;
            char c;
            cin >> ind >> c;
            valarray<int> cnt(26);
            auto& x = S[ind - 1];
            cnt[x - 'a'] -= 1;
            cnt[(x = c) - 'a'] += 1;
            bit.add(ind, cnt);
        } else {
            int l, r;
            cin >> l >> r;
            valarray<int> cnt = bit.sum(r) - bit.sum(l - 1);
            int z = count(begin(cnt), end(cnt), 0);
            cout << 26 - z << endl;
        }
    }
}


Measured memory_bytes: 63236
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	string s; cin >> s;
	int ans = s.size();
	REP(i, 26)
	{
		string t = s;
		char c = 'a' + i;
		if (find(ALL(s), c) == s.end()) continue;
		int cnt = -1;
		while (1)
		{
			cnt++;
			if (count(ALL(t), c) == t.size()) break;
			string tt;
			REP(i, t.size() - 1)
			{
				if (t[i] == c || t[i + 1] == c) tt.push_back(c);
				else tt.push_back(t[i]);
			}
			t = tt;
		}
		chmin(ans, cnt);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	In := readLine()
	Result := 700
	for _, v := range strings.Split(In, "") {
		if v == "o" {
			Result += 100
		}
	}
	fmt.Println(Result)
}

/////////////////////////////////////////

//func readLineInt() []int {
//	result := make([]int, 0)
//	for _, v := range strings.Split(readLine(), " ") {
//		i, _ := strconv.Atoi(v)
//		result = append(result, i)
//	}
//	return result
//}

var reader = bufio.NewReaderSize(os.Stdin, 1e6)

func readLine() string {
	result := make([]byte, 0, 1e6)
	for {
		line, remains, e := reader.ReadLine()
		if e != nil {
			panic(e)
		}
		result = append(result, line...)
		if !remains {
			break
		}
	}
	return string(result)
}

Measured memory_bytes: 640
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
#![macro_use]

use std::cmp::*;
use std::collections::*;
use std::io::*;
use std::mem::*;
use std::num::*;
use std::ops::*;
use std::slice::*;
use std::*;

const MOD: isize = 1000000007;
fn main() {
    let l: usize = read();

    let t: f64 = l as f64 / 3.0f64;
    println!("{}", t * t * t);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace() // iter
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 4352