akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#include <atcoder/all>
//using namespace atcoder;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
typedef pair<int,int> P;
typedef long long ll;



int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    
    ll ans = max(a*c, a*d);
    ans = max(ans, b*c);
    ans = max(ans, b*d);
    
    cout << ans << endl;
    
    
    return 0;
}




Measured memory_bytes: 3620
package main

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

var sc = bufio.NewScanner(os.Stdin)
var a [15][15]int

func main() {
	scanInit()

	n := nextInt()
	m := nextInt()
	x := nextInt()
	c := make([]int, n)
	for i := 0; i < n; i++ {
		c[i] = nextInt()
		for j := 0; j < m; j++ {
			a[i][j] = nextInt()
		}
	}

	costmin := 1 << 30
	for bit := 0; bit < (1 << n); bit++ {
		nowcost := 0
		nowskill := make([]int, m)
		for j := 0; j < n; j++ {
			if bit&(1<<j) != 0 { // 今回ヒットした場合
				nowcost += c[j]
				for k := 0; k < m; k++ {
					nowskill[k] += a[j][k]
				}
			}
		}
		skilled := true
		for i := 0; i < m; i++ {
			if nowskill[i] < x {
				skilled = false
			}
		}
		if skilled == true {
			costmin = min(costmin, nowcost)
		}
	}

	if costmin == 1<<30 {
		fmt.Println(-1)
	} else {
		fmt.Println(costmin)
	}
}
func min(a, b int) int {
	if a > b {
		return b
	}
	return a
}

// ---- readfunc
func scanInit() {
	const cap = 200 * 1024 // default=64*1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 2184
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;
#define ll long long

signed main() {
  int d;
  cin >> d;
  vector<pair<int,int>> c(26);
  vector<int> cc(26);
  vector<int> dd(26);
  vector<int> t;
  rep(i,26) {
    int x;
    cin >> x;
    c[i] = {-x,i};
    cc[i]=x;
  }
  sort(c.begin(),c.end());
  
  vector<vector<int>> s(d);
  int ans = 0;
  rep(i,d) {
    int ma = 0;
    rep(j,26) {
      int num;
      cin >> num;
      ma = max(ma,num+cc[j]);
      if(ma==num+cc[j]) ans = j+1;
      s[i].push_back(num);
    }
    rep(j,26) {
      if(ans-1!=j) cc[j]+=dd[j];
      else cc[j]=dd[j];
    }
    //sort(s.begin(),s.end());
    //cout << ans << endl;
  }
  
  int cnt = 0;
  rep(i,d) {
    t.push_back(c[cnt].second+1);
    cnt++;
    cnt%=26;
  }

  cnt=0;
  while(cnt<3000) {
  rep(i,d/13) {
    FOR(j,i*13+1,i*13+12) {
      if(j+13+cnt>=360) break;

      if(s[j][t[j]-1]<s[j+13+cnt][t[j]-1]+1000) {
        swap(t[j],t[j+1]);
      }
    }
  }
  cnt++;
  }

  rep(i,d) {
    cout << t[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 3704
#include<bits/stdc++.h>
#define int long long
#define rep1(i,a,b) for(int i=a;i<b;i++)
#define rep2(i,a,b) for(int i=a;i>=b;i--)
#define mod 1000000009
#define garou99 ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
signed main() {
  string s,t;
  cin>>s>>t;
  int m=s.length();
  int n=t.length();
  if(n>m){
	  cout<<0;
	  return 0;
  }
  int mn=INT_MAX,j=0;
  for(int i=0;i<=m-n;i++){
	  int x=i,z=0;
	for(int j=0;j<n;j++){
   if(s[i+j]!=t[j])
   z++;
   x++;
	} 
	mn=min(mn,z);
  }
//   if(mn==INT_MAX)
//   mn=n;
  cout<<mn;
	}

Measured memory_bytes: 3580
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
using namespace std;

void b_bitter_alchemy(void) {
	int n,x;
	int m[100];
	int sum = 0;

	cin >> n >> x;
	for (int i = 0; i < n; i++) {
		cin >> m[i];
		sum += m[i];
	}
	sort(m, m + n);
	
	int amari = x - sum;
	int hasu = amari / m[0];

	cout << n + hasu << endl;
}

int main()
{
	b_bitter_alchemy();
    return 0;
}

Measured memory_bytes: 3540
h,w =map(int,input().split())
s = [input() for i in range(h)]
dx = [ 1,-1, 0, 0]
dy = [ 0, 0, 1,-1]
Bool = True

for i in range(h):
    for j in range(w):
        if s[i][j]=="#":
            count = 0
            for k in range(4):
                x = i + dx[k]
                y = j + dy[k]
                if x >= 0 and x <= h-1 and y >= 0 and y <= w-1 and s[x][y] == "#":
                    count += 1
            if count == 0:
                Bool = False
                
if Bool == True:
    print("Yes")
else:
    print("No")
                
            

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

int main() {
  int n; //入力する数値の初期化
  
  cin >> n;
  
  int a, b, c, d;
  a = n / 1000;
  b = n / 100 - a * 10;
  c = n / 10 - a * 100 - b * 10;
  d = n - a * 1000 - b * 100 - c * 10;

  if ((a == b && b == c) || (b == c && c ==d)){
  	cout << "Yes" << endl;
  }else{
  	cout << "No" << endl;
  }
}


Measured memory_bytes: 3592
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <algorithm>
using namespace std;
namespace mp = boost::multiprecision;
using llll = mp::cpp_int;
// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
using Real = mp::number<mp::cpp_dec_float<1024>>;
using ll = long long;
const double EPS = 1e-10;
const ll MOD = 7+(1e+9);

int main(){
  ll r,d,x;
  cin>>r>>d>>x;
  for(ll i=0;i<10;i++){
    x=x*r-d;
    cout<<x<<endl;
  }
}


Measured memory_bytes: 888
a11, a12, a13 = map(int, input().split())
a21, a22, a23 = map(int, input().split())
a31, a32, a33 = map(int, input().split())
N = int(input())
B = [int(input()) for _ in range(N)]

A = [a11, a12, a13, a21, a22, a23, a31, a32, a33]


for k in range(N):
    for p in range(9):
        if B[k] == A[p]:
            A[p] = 0

if (A[0]==0 and A[1]==0 and A[2]==0) or (A[3]==0 and A[4]==0 and A[5]==0) or(A[6]==0 and A[7]==0 and A[8]==0) or (A[0]==0 and A[3]==0 and A[6]==0) or (A[1]==0 and A[4]==0 and A[7]==0)or(A[2]==0 and A[5]==0 and A[8]==0)or(A[0]==0 and A[4]==0 and A[8]==0)or(A[2]==0 and A[4]==0 and A[6]==0):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include<cstdio>
using namespace std;
int main(){
	long long n,A,B;
	scanf("%lld%lld%lld",&n,&A,&B);
	if(B<A){
		printf("0");
		return 0;
	}
	if(n==1){
		if(A==B) printf("1");
		else printf("0");
		return 0;
	}
	printf("%lld\n",(B-A)*(n-2)+1);
	return 0;
}

Measured memory_bytes: 128
K=int(input())
if K<10:
    n=2
    i=1
else:
    n=10
    i=9
while i<K:
    S=str(n)
    cond=True
    for j in range(len(S)-1):
        if abs(int(S[j])-int(S[j+1]))>1:
            cond=False
            break
    if cond:
        i+=1
#        print(n)
        n+=1
    else:
        n+=10**(len(S)-j-2)
#        print(n,10**(len(S)-j-2))
print(n-1)

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

int main(){
    int n;
    cin >> n;
    if(n%10==3){
        cout << "bon" << endl;
    }else if(n%10==0||n%10==1||n%10==6||n%10==8){
        cout << "pon" << endl;
    }else{
        cout << "hon" << endl;
    }
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

struct UnionFind {
  const int n;
  V<> t; // root ? -sz : par
  UnionFind(int n) : n(n), t(n, -1) {}
  int find(int v) { return t[v] < 0 ? v : t[v] = find(t[v]); }
  void unite(int u, int v) {
    if ((u = find(u)) == (v = find(v))) return;
    if (-t[u] < -t[v]) swap(u, v);
    t[u] += t[v];
    t[v] = u;
  }
  bool same(int u, int v) { return find(u) == find(v); }
  int size(int v) { return -t[find(v)]; }
};

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  UnionFind uf(2 * n);
  for (int i = 0; i < n - 1; ++i) {
    int u, v, w; cin >> u >> v >> w, --u, --v;
    if (w & 1) {
      uf.unite(u, n + v);
      uf.unite(n + u, v);
    } else {
      uf.unite(u, v);
      uf.unite(n + u, n + v);
    }
  }
  for (int i = 0; i < n; ++i) {
    cout << uf.same(0, i) << '\n';
  }
}

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

Measured memory_bytes: 256
x = ['+++', '++-', '+-+', '+--', '-++', '-+-', '--+', '---']
a = input()
for i in range(8):
    ans = a[0] + x[i][0] + a[1] + x[i][1] + a[2] + x[i][2] + a[3]
    if eval(ans) == 7:
        print(ans + '=7')
        break


Measured memory_bytes: 3060
import java.util.*;

/**
 * C
 */
public class Main {
    public static void main(String[] args) {
        
        int prime = 0;
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int array[] = new int[n];

        for(int i=0; i<n; i++) {
            array[i] = sc.nextInt();
        }

        sc.close();

        for(int num : array) {
            if(isPrime(num) == true) {
                prime++;
            }
        }

        /*IN : for (int num : array) {
            for (int j = 2; j<num; j++) {
                if (num % j == 0) {
                    continue IN;
                }
            }
            prime++;
        }
        
        これでだめだったから悲しいよなぁ。。。
        巨大な数が来た時に計算速度がバカ落ちる。

        */

        System.out.println(prime);

    }


    // 判定メソッドを作ったほうがいい
    public static boolean isPrime(int num) {

        if (num < 2) {
            return false;
        } else if (num == 2) {
            return true;
        } else if (num % 2 == 0) {
            return false; // 偶数はあらかじめ除く
        }

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

        // 素数である
        return true;
    }
}


Measured memory_bytes: 42896
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using P=pair<int,int>;
using lint=long long;
using ll=long long;
const lint inf=1e18+7;
const int MOD=1000000007;
signed main(){
  int n,k;cin>>n>>k;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  sort(a.begin(),a.end());
  int hu=0;
  bool zero=false;
  rep(i,n){
    if(a[i]==0)zero=true;
  }
  rep(i,n){
    if(a[i]<0)++hu;
    else break;
  }
  int num=0;
  int cur=n-k;
  int res=1;
  while(num<=hu){
    if(cur+1>=n)break;
    if(a[num]*a[num+1]<a[cur]*a[cur+1]){
      break;
    }
    num+=2;
    cur+=2;
  }
  rep(i,num){
    res*=a[i];res%=MOD;
  }
  for(int i=cur;i<n;++i){
    res*=a[i];res%=MOD;
  }
  if(a[n-1]<0&&k%2==1){
    if(zero)res=MOD-1;
    else{
      res=1;
      rep1(i,k){
        res*=-a[n-i];res%=MOD;
      }
      res=MOD-res;
    }
  }
  res+=MOD;
  res%=MOD;
  cout<<res<<"\n";
  return 0;
}


Measured memory_bytes: 4760
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    int A, B;
    cin >> A >> B;
    if(A <= 8 && B <= 8) {
        cout << "Yay!" << endl;
    } else {
        cout << ":(" << endl;
    }
    return 0;
}

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

const int maxn = 1005;
int N, A[maxn][maxn];

vector<pair<int,int>> dir[maxn][maxn];
int in[maxn][maxn];

pair<int,int> mn(pair<int,int> p) {
    if (p.first > p.second) swap(p.first,p.second);
    return p;
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> N;
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N-1; j++) {
            cin >> A[i][j];
        }
    }
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N-2; j++) {
            dir[min(i,A[i][j])][max(i,A[i][j])].push_back(mn({i,A[i][j+1]}));
            in[min(i,A[i][j+1])][max(i,A[i][j+1])]++;
        }
    }
    queue<pair<int,int>> q;
    for (int i = 1; i <= N; i++) {
        for (int j = i+1; j <= N; j++) {
            if (in[i][j] == 0) {
                q.push({i,j});
            }
        }
    }
    queue<pair<int,int>> batch;
    int steps = 0;
    int cnt = 0;
    while (true) {
        steps++;
        while (!q.empty()) {
            auto p = q.front(); q.pop();
            cnt++;
            for (auto j: dir[p.first][p.second]) {
                if (--in[j.first][j.second] == 0) {
                    batch.push(j);
                }
            }
        }
        while (!batch.empty()) {
            auto p = batch.front(); batch.pop();
            q.push(p);
        }

        if (q.empty()) break;
    }
    if (cnt < (N*(N-1))/2) {
        cout << -1 << '\n';
    }
    else {
        cout << steps << '\n';
    }
}



Measured memory_bytes: 47488
import Control.Applicative
solveRPN :: [String] -> Int
solveRPN expression = head (foldl foldingFunction [] expression)
  where foldingFunction (x:y:ys) "*" = (y * x) : ys
        foldingFunction (x:y:ys) "+" = (y + x) : ys
        foldingFunction (x:y:ys) "-" = (y - x) : ys
        foldingFunction xs numberString = read numberString : xs


main :: IO()
main = do
  line <- words <$> getLine
  print $ solveRPN line

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-9;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    ll N,M; cin >> N >> M;
    vector<ll> dp(N+3,0), dest(N+1,0);
    REP(i,M){
        int a; cin >> a;
        dest[a] = 1;
    }
    dp[0] = 1;
    REP(i,N){
        if(dest[i]) continue;
        dp[i+1] = (dp[i+1]+dp[i])%MOD;
        dp[i+2] = (dp[i+2]+dp[i])%MOD;
    }
    cout << dp[N] << endl;
    return 0;
}

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

int main(){
    string s,t;
    cin>>t;
    int ans=0;
    while(1){
        cin>>s;
        if(s=="END_OF_TEXT")break;
        rep(i,s.length()){
            if(s[i]>='A'&&s[i]<='Z')s[i]=s[i]-'A'+'a';
        }
        if(s==t)ans++;
    }
    out(ans);
}


Measured memory_bytes: 3284
import sys
input = sys.stdin.readline

n = int(input())
a = [int(x) for x in input().split()]

key_1, key_4 = 0, 0
for value in a:
  if value%4 == 0:
    key_4 += 1
  elif value%2 == 1:
    key_1 += 1

if key_4+key_1 == n and key_1 <= key_4+1:
  print("Yes")
elif key_1 <= key_4:
  print("Yes")
else:
  print("No")

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

int main() {
	// your code goes here
	ios::sync_with_stdio(false);
    cin.tie(0);
	vector<int>g[601];
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		
	}
	long double dp[601];
	long double ans=1e18;
	for(int i=1;i<=n-1;i++)
	{
		dp[n]=0;
		for(int j=n-1;j>=1;j--)
		{
			int num=g[j].size();
			long double sum=0.0;
			long double maxi=0.0;
			for(auto t:g[j])
			{
				sum+=dp[t];
				maxi=max(maxi,dp[t]);
			}
			if(j==i&&num>=2)
			{
				num--;
				sum-=maxi;
			}
			dp[j]=sum/num+1;
			
		}
		ans=min(ans,dp[1]);
	}
	 cout << fixed << setprecision(10) << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1408
# https://abc113.contest.atcoder.jp/tasks/abc113_c
def pad(n):
    return '{:0>6}'.format(n)


N, M = map(int, input().split())
P, Y = [0 for _ in range(M)], [0 for _ in range(M)]
for i in range(M):
    P[i], Y[i] = map(int, input().split())

data = [[P[i], Y[i], 1, i] for i in range(M)]
data.sort(key=lambda x: x[1])  # sort by year
data.sort(key=lambda x: x[0])  # sort by prefectures

for i in range(1, M):
    if data[i][0] == data[i - 1][0]:
        data[i][2] = data[i - 1][2] + 1

data.sort(key=lambda x: x[-1])  # original order
for di in data:
    print(pad(di[0]) + pad(di[2]))


Measured memory_bytes: 30568
#B
while True:
    import bisect
    L = int(input()) #length
    if L == 0:
        break
    N = int(input())
    M = int(input())

    D = [int(input()) for i in range(N-1)]
    K = [int(input()) for i in range(M)]

    Md = max(D)
    D.append(0)
    D.append(L)
    D.sort()
    #print(D)
    ans = 0
    for k in K:
        ind = bisect.bisect_left(D,k)
        #print(ind)
        ans+=min(abs(k-D[ind]),abs(k-D[ind-1]))

    print(ans)



Measured memory_bytes: 10744
/*
	author: Ibrahim-Elsayed (Codeforces Handle)
	date: 9/18/2020
*/
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int64_t INF = (int64_t)1e18;
const int mxN = 1e5+20;

int n;
int64_t arr[mxN+1][3];

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

	cin >> n;
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j < 3; j++) {
			cin >> arr[i][j];
		}
	}
	// dp[i][j] max happ points can get ending at day i with last used j;
	vector<vector<int64_t>> dp(n+1, vector<int64_t>(3));
	dp[0][0] = dp[0][1] = dp[0][2] = 0; // empty set of activities, max we can get here is 0;
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j < 3; j++) {
			dp[i][j] = -INF;
			if(j != 0) {
				dp[i][j] = max(dp[i][j], dp[i-1][0] + arr[i][0]);
			}
			if(j != 1) {
				dp[i][j] = max(dp[i][j], dp[i-1][1] + arr[i][1]);
			}
			if(j != 2) {
				dp[i][j] = max(dp[i][j], dp[i-1][2] + arr[i][2]);
			}
		}
	}
	cout << max({dp[n][0], dp[n][1], dp[n][2]}) << "\n";

	return 0;
}


Measured memory_bytes: 11140
#include<bits/stdc++.h>
#define ll long long

using namespace std;

const int N = 1e6+1, M = 5e5, F = 4*N, mod = 998244353;

ll binpow(ll a, ll s){
    ll ans = 1;
    while(s){
        if(s&1)
            ans = ans*a%mod;
        a = a*a%mod;
        s >>= 1;
    }
    return ans;
}

ll inv(ll a){
    return binpow(a, mod-2);
}

int n, m;
ll f[F], invf[F];
void init(){
    f[0] = 1;
    invf[0] = 1;
    for(int i = 1; i < F; ++i){
        f[i] = f[i-1]*i%mod;
        invf[i] = inv(f[i]);
    }
}

ll C(int n, int k){
    if(n < k || k < 0)
        return 0ll;
    return f[n]*invf[n-k]%mod*invf[k]%mod;
}

ll C_(int n, int k){
    return C(n+k-1, k);
}

int main(){
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    init();
    cin >> n >> m;
    ll ans = 0;
    for(int odd = m; odd >= 0; odd -= 2){
        if(odd > n)
            continue;
        ll cnt2 = m+(m-odd)/2;
        ll res = C(n, odd)*C_(n, cnt2)%mod;
        res = (res - (C_(n, cnt2-m-1)*C(n-1, odd)%mod + C_(n, cnt2-m)*C(n-1, odd-1)%mod)*n%mod)%mod;
        ans = (ans+res)%mod;
    }
    if(ans < 0) ans += mod;
    cout << ans << '\n';
}


Measured memory_bytes: 62848
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int n,m; cin>>n>>m; 
    priority_queue<int> pq;
    for (int i=0;i<n;i++){
        int a; cin>>a; 
        pq.push(a);
    }
    while (m--){
        int helper=pq.top();
        pq.pop();
        helper /= 2;
        pq.push(helper);
    }
    int sum=0;
    while (pq.size()){
        sum += pq.top();
        pq.pop();
    }
    cout << sum << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 4328
#include <bits/stdc++.h>
#define lg2 std::__lg

const int N = 1054;

int n, L;
int X[N], Y[N];

inline void up(int &x, const int y) {x < y ? x = y : 0;}

int main() {
	int i, j, x, y, parity = 0;
	scanf("%d", &n);
	for (i = 0; i < n; ++i) scanf("%d%d", X + i, Y + i), parity += (X[i] ^ Y[i]) & 1;
	if (parity && parity != n) return puts("-1"), 0;
	if (!parity) for (i = 0; i < n; --X[i++]);
	for (i = 0; i < n; ++i) up(L, abs(X[i]) + abs(Y[i]));
	L = (L ? lg2(L) + 1 : 0), printf("%d\n", L + !parity);
	for (i = L - 1; i >= 0; --i) printf("%d%c", 1 << i, !i && parity ? 10 : 32);
	if (!parity) putchar(49), putchar(10);
	for (i = 0; i < n; ++i, putchar(10)) {
		x = X[i], y = Y[i];
		for (j = L - 1; j >= 0; --j)
			putchar(abs(x) < abs(y)
				? (y >> 31 ? (y += 1 << j, 68) : (y -= 1 << j, 85))
				: (x >> 31 ? (x += 1 << j, 76) : (x -= 1 << j, 82))
			);
		if (!parity) putchar(82);
	}
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;

long long int gcd(long long int a,long long int b){

    if (a % b==0)return b;
    return gcd(b,a%b);

}


int main()
{
    
    int n;
    cin >> n;
    long long int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            for (int k = 1; k <= n; k++) {
                ans += gcd(i, gcd(j, k));
            }
        }
    }


    cout << ans << endl;
   

    return 0;

}

Measured memory_bytes: 3176
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  int fin = 0;
  for (int i=0;i<=25;i++) {
    for (int j=0;j<=14;j++) {
      if (N == 4*i + 7*j) {
        cout << "Yes" << endl;
        fin = 1;
        break;
      }
    }
    if (fin==1) {
      break;
    }
  }
  
  if (fin==0) {
    cout << "No" << endl;
  }
}

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

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    const real PI = acos(-1);

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os;
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    struct Point {
        real x, y;
        Point(real x, real y) : x(x), y(y) {}
    };
    real dist(const Point& p, const Point& q) {
        real dx = p.x - q.x;
        real dy = p.y - q.y;
        return sqrt(dx*dx + dy*dy);
    }
    ostream& operator<<(ostream& os, const Point& p) {
        return os << "(" << p.x << "," << p.y << ")";
    }

    real heron(real a, real b, real c) {
        real s = (a + b + c) / 2.0;
        return sqrt(s * (s - a) * (s - b) * (s - c));
    }

    real R, X, Y;
    int  N;
    vector<real> P;
    void input() {
        cin >> R >> X >> Y >> N;
        P.clear(); P.resize(N);
        cin >> P;
    }

    void solve() {
        real theta = 0;
        const Point O(0, 0);
        const Point Z(X, Y);
        vector<int> ans;
        for (int i = 0; i < N; i++) {
            real diff_area = 0;
            for (int j = 1; j <= P[i]; j++) {
                Point s(R * sin(theta), R * cos(theta));
                theta += 1.0 / 100 * 2 * PI;
                Point t(R * sin(theta), R * cos(theta));
                diff_area += - heron(dist(O, s), dist(s, t), dist(t, O)) + heron(dist(Z, s), dist(s, t), dist(t, Z));
            }
            real org_area = R * R * PI * (P[i] / 100);
            real mod_area = org_area + diff_area;
            ans.push_back(int(100 * mod_area / org_area));
        }
        cout << ans << endl;
    }
}

int main() {
    input(); solve();
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <stdio.h>
#include <string>

using namespace std;
#define MAXN 88000

string s;
long long f[MAXN][12], g[MAXN][12];
int a[MAXN];

int num(char x)
{
    return x - '0';
}

int mm(int x)
{
    while (x < 0) x += 11;
    return x % 11;
}

int main()
{
    //freopen("test.txt", "r", stdin);
    cin >> s;
    while (s != "0")
    {
        int n = s.length();

        for (int i = 0; i < n; ++i)
            for (int j = 0; j < 11; ++j)
                f[i][j] = g[i][j] = 0;
        for (int i = 0; i < n; ++i)
            a[i] = num(s[i]);

        int start = n;
        for (int i = 0; i < n; ++i)
            if (s[i] != '0')
            {
                start = i;
                break;
            }

        long long res = 0;
        if (start < n)
        {
            f[start][a[start]] = 1;
            if (start < n - 1 && s[start + 1] != '0')
                f[start + 1][a[start + 1]] = 1;

            for (int i = start; i < n; ++i)
            {
                if (i >= start + 2)
                {
                    if (a[i] != 0)
                        f[i][a[i]]++;
                    for (int j = 0; j < 11; ++j)
                        f[i][mm(j + a[i] - a[i - 1])] += f[i - 2][j];
                }
                res += f[i][0];
            }

            start++;
            if (start < n)
            {

                g[start][mm(a[start] - a[start - 1])] = 1;
                if (start < n - 1 && s[start] != '0')
                    g[start + 1][mm(a[start + 1] - a[start])] = 1;

                for (int i = start; i < n; ++i)
                {
                    if (i >= start + 2)
                    {
                        if (a[i - 1] != 0)
                            g[i][mm(a[i] - a[i - 1])]++;
                        for (int j = 0; j < 11; ++j)
                            g[i][mm(j + a[i] - a[i - 1])] += g[i - 2][j];
                    }
                    res += g[i][0];
                }
            }
        }

        cout << res << endl;
        cin >> s;
    }
    return 0;
}

Measured memory_bytes: 17688
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a)-1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a)-1; (i) >= (b); (i)--)
#define PI acos(-1.0)
#define DEBUG(C) cout<< C <<endl;
#define VI vector <int>
#define VII vector <VI>
#define VL vector <LL>
#define VLL vector <VL>
#define VD vector <double>
#define VDD vector <VD>
#define PII pair <int, int>
#define PDD pair <double, double>
#define PLL pair <LL, LL>
#define VPII vector <PII>
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define REVERSE(a) reverse(ALL(a))
#define MP make_pair
#define FORE(a, b) for (auto &&a:b)
#define FIND(s, e) (s.find(e) != s.end())
#define EB emplace_back

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9;
const int MOD = INF+7;
const LL LLINF = 1e18;

int N;
VI a, dis;

int main(void) {
    cin >> N;
    a.resize(N);
    dis.resize(N + 1, 0);
    int maxlen = 0;
    REP(i, N) {
        cin >> a[i];
        dis[a[i]]++;
        maxlen = max(maxlen, a[i]);
    }
    int minlen = (maxlen + 1) / 2;
    //if (maxlen == 1) minlen = 0;
    REP(i, minlen) {
        if (dis[i]) {
            cout << "Impossible" << endl;
            return 0;
        }
    }
    FOR(i, minlen, maxlen + 1) {
        if (i == minlen) dis[i] -= 1 + (maxlen % 2);
        else dis[i] -= 2;
        if (dis[i] < 0) {
            cout << "Impossible" << endl;
            return 0;
        }
    }
    REP(i ,minlen) if (dis[i + 1]) {
        cout << "Impossible" << endl;
        return 0;
    }
    //REP(i, N) cerr << i + 1 << " " << dis[i + 1] << endl;
    cout << "Possible" << endl;
    return 0;
}


Measured memory_bytes: 384
/** omgursocute **/
#include <bits/stdc++.h>
 
using namespace std;
typedef int64_t ll;
typedef uint64_t ull;
typedef long double ld;
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);
 
	int n;
	cin >> n;
	int a[n];
	for(int i = 0; i < n; i++) cin >> a[i];
	sort(a, a+n);
 
	ld res = a[0];
	for(int i = 1; i < n; i++)
		res = (res+a[i])/2;
 
	cout << res;
 
	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << " ms.\n";
}
 
// g++ o .cpp -O2 -std=c++11 -D cute -Wall -Wno-unused-result

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String s = in.next().trim();
        String t = in.next().trim();
        int sCount = in.nextInt();
        int tCount = in.nextInt();
        String u = in.next();
        if (s.equals(u)) {
            sCount -= 1;
        } else {
            tCount -= 1;
        }
        System.out.println(sCount + " " + tCount);
    }
}


Measured memory_bytes: 21844
#include <stdio.h>

int main() {
  int n,k;
  int angka = 1;
  scanf("%d %d", &n, &k);
  for(int i = 0; i < n; i++) {
    (angka+k>angka*2) ? angka *= 2 : angka += k;
  } //misal k itu 3,jadi 1+3 atau 1*2 ....
  printf("%d\n", angka);
  return 0;
}

Measured memory_bytes: 1656
#include <bits/stdc++.h>
using namespace std;
#define debug(args...) fprintf(stderr, args)

bool sortByA(pair<int,int> i, pair<int,int> j) {
    return i.first < j.first;
}

int main() {
    int n, a, b;
    unsigned long long int k, acm;
    vector<pair<int,int>> vector;
    acm = 0;

    cin >> n >> k;


    for (int i = 0; i < n; i++) {
        cin >> a >> b;
        vector.push_back(make_pair(a,b));    
    }
    sort(vector.begin(), vector.end(), sortByA);
    
    for (int i = 0; i < vector.size(); i++) {
        acm += vector[i].second;

        if (acm >= k) {
            cout << vector[i].first << endl;
            break;
        }
    }
    


    return 0;
}

Measured memory_bytes: 1400
function main(input: string): void {
  const nums: number[] = input.split('\n')[1].split(' ').map(n => parseInt(n, 10))

  const sort = (a: number, b: number) => {
    return b - a
  } 

  const sum = (array: number[]) => {
    return array.reduce((acc, arg) => {return acc + arg}, 0)
  }

  const sortNums: number[] = nums.sort(sort)
  const allice: number[] = []
  const bob: number[] = []

  for (let i: number = 0; i < sortNums.length; i ++) {
    i % 2 === 0 ? allice.push(sortNums[i]) : bob.push(sortNums[i])
  }

  const diff: number = sum(allice) - sum(bob)

  console.log(diff)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))

Measured memory_bytes: 7500
import scala.io.{ StdIn => in}

object Main extends App {
  val s = StringBuilder.newBuilder
  s.append(in.readLine)

  val res = s.reverse.toString
    .replaceAll("eraser".reverse,"")
    .replaceAll("erase".reverse,"")
    .replaceAll("dreamer".reverse,"")
    .replaceAll("dream".reverse,"")

  val ans = if(res.isEmpty) "YES" else "NO"
  println(ans)
}

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

int main(){
  int k;
  string str, ans = "";
  cin >> k >> str;
  if(str.length() > k) {
    for(int i = 0; i < k; i++){
      ans.push_back(str.at(i));
    }
    ans.push_back('.');
    ans.push_back('.');
    ans.push_back('.');
  }
  else {
    ans = str;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3644
//
//  main.cpp
//  ABC172C しゃくとり法
#include <iostream>
#include <vector>
#include <algorithm> // max
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
int main(int argc, const char * argv[]) {
    int n,m;
    ll k;
    cin>>n>>m>>k;
    vector<int>a(n+1);
    vector<int>b(m+1);
    ll total=0;
    a.at(0)=0;
    b.at(0)=0;
    for(int i=1;i<=n;i++){
        cin >> a.at(i);
    }
    for(int i=1;i<=m;i++){
        cin >> b.at(i);
        total+=b.at(i);
    }
    int j=m;
    ll now=0;
    ll ans=0;
    rep(i,n+1){
        total+=a.at(i);
        while(total>k&&j>0){
            total-=b.at(j);
            j--;
        }
        if(total>k) break; // jが0になり、Aの方だけが加算される状態でtotal>kなら終了
        now=i+j;
        ans=max(ans,now);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4324
a=input().strip().split(" ")

b=[int(i) for i in a]

if(b[0]==5 and b[1]==5 and b[2]==7):
    print("YES")
elif(b[1]==5 and b[2]==5 and b[0]==7):
    print("YES")
elif(b[2]==5 and b[0]==5 and b[1]==7):
    print("YES")
else:
    print("NO")









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

using namespace std;

int a[100050];
int dp[100050];

int ghadr(int a, int b) {
	return max((a - b) , (b - a));
}

int main() {
	long long int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	dp[0] = 0;
	dp[1] = ghadr(a[0] , a[1]);
	for (int i = 2; i < n; i++) {
		int mini = dp[i - 1] + ghadr(a[i] , a[i - 1]);
		for (int j = 2; j <= k ; j++) {
			if (i - j < 0)
				break;
			mini = min (mini , dp[i - j] + ghadr(a[i] , a[i - j]));
		}
		dp[i] = mini;
	}
	cout << dp[n - 1];
	return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    if(N % 2 == 0){
        cout << N << endl;
    }else{
        cout << N * 2 << endl;
    }

    return 0;
}

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

int main() {
  string a, b;
  cin >> a >> b;

  if (a.at(0) == b.at(2) && a.at(1) == b.at(1) && a.at(2) == b.at(0)) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
}


Measured memory_bytes: 764
import sys
input = sys.stdin.readline
N, X, Y = list(map(int, input().split()))

def f(i, j, X, Y):
  return min(j-i, abs(j - Y) + 1 + abs(i-X))
  
cnts = [0] * N
for i in range(1, N+1):
  for j in range(i+1, N+1):
    k = f(i, j, X, Y)
    cnts[k] += 1
for k in range(1, N):
  print(cnts[k])

Measured memory_bytes: 48220
#include <bits/stdc++.h>
using namespace std;
# define M_PI 3.14159265358979323846

int main() {
  int a, b, x;
  cin >> a >> b >> x;

  double s = (2 * x)/((double)a * b);

  double theta;
  if (s > a) {
    theta = atan(((double)b - (double)x/a/a)*2/a);
  }
  else {
    theta = atan((double)a*b*b/2/x);
  }

  double deg = theta * 180 / M_PI;

  cout << fixed << setprecision(7);
  cout << deg << endl;
  return 0;
}


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

int main(){
    string s;
    cin >> s;
    string ans = "NO";
    for(int i = 0; i < s.length(); i++){
        if(s[i] == 'k'){
            if(s.substr(i, 7) == "keyence"){
                ans = "YES";
            }
        }
    }

    for(int i = 1; i < 7; i++){
        if(s.substr(0, i)+s.substr(s.size()-(7-i)) == "keyence"){
            ans = "YES";
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
n = gets.to_i
name = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
ans = ""
while n != 0
  n -= 1
  rest = n%26
  ans += name[rest]
  n = n/26
end
puts ans.reverse

Measured memory_bytes: 14372
import scala.io.StdIn._

object Main {
  def main(args: Array[String]): Unit = {
    while (true) {
      val sum = readInt
      if (sum == 0) return
      val result = sum - readIntList(9).sum
      println(result)
    }
  }
  def readIntList(n:Int) : List[Int] = {
    var list: Array[Int] = Array.empty
    for (i <- 0 until n) {
      list :+= readInt
    }
    list.toList
  }
}



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

struct node{
    node(ll _val = 0,node *_pre = NULL,node *_nx = NULL):value(_val),pre(_pre),nx(_nx){}
    ll value;
    node *pre,*nx;
};

struct link{
    node *head = new node();
    node *tail = head;
    void add(ll val)
    {
        node *p = new node(val,tail);
        tail->nx = p;
        tail = p;
    }
    node *del(node *p)
    {
        node * tmp = p->pre;
        if (p == tail)
        {
            tail = p->pre;
            tail->nx = NULL;
            delete p;
        }
        else
        {
            node *pre = p->pre,*nx = p->nx;
            pre->nx = nx;
            nx->pre = pre;
            delete p;
        }
        return tmp;
    }
    void write()
    {
        node *j = head;
        while (j->nx != NULL)
        {
            j = j->nx;
            cout<<j->value<<' ';
        }
        cout<<'\n';
    }
}L;

const int N = 1e3+10;
ll n,k,a[N],sum[N],tot,num[50];
int main()
{
    int st;
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=n;i++)
    sum[i]=sum[i-1]+a[i];
    ll maxn = 0;
    for(int i=1;i<=n;i++)
        for(int j=i;j<=n;j++)
        {
            L.add(sum[j]-sum[i-1]);
            maxn = max(maxn,sum[j]-sum[i-1]);
            tot++;
        }
    st = log(maxn) / log(2);
    node *j;
    // L.write();
    for (int i = st;i>=0;i--)    
    {
        j = L.head;
        int tmp = 0;
        while (j->nx != NULL)
        {
            j = j->nx;
            if (((j->value) & (1LL<<i)) == (1LL<<i)) tmp++;
        }
        if (tmp >= k)
        {
            j = L.head;
            while (j->nx != NULL)
            {
                j = j->nx;
                if (((j->value) & (1LL<<i)) == 0) j = L.del(j);
            }   
            tot = tmp;
        }
        // L.write();
    }
    ll ans = (1LL<<40) - 1;
    j = L.head;
    while (j->nx)
    {
        j = j->nx;
        ans &= j->value;
    }
    cout<<ans;
}

Measured memory_bytes: 15872
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int ans = 800*n;
    ans -= 200*(n/15);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;


int main(){

    int N,A[110]={};

    cin >> N;
    for(int i=1;i<=N;i++){
        cin >> A[i];
        if(A[i]%2==0)
        {
            if(!(A[i]%3==0||A[i]%5==0)){
                cout << "DENIED";
                return 0;
            }
        }
    }

    cout << "APPROVED";
    return 0;

}

Measured memory_bytes: 384
import std.stdio,
       std.string,
       std.conv;

void main() {
  int N = to!int(readln.chomp);
  int[char] hash;

  for (int i = 0; i < N; i++) {
    string s = readln.chomp;
    if ("MARCH".count(s[0])) {
      hash[s[0]]++;
    }
  }

  int[] a = hash.values ~ [0, 0, 0, 0, 0];
  long ans = 0;
  for (int i = 0; i < 5; i++) {
    for (int j = i + 1; j < 5; j++) {
      for (int k = j + 1; k < 5; k++) {
        ans += 1L * a[i] * a[j] * a[k];
      }
    }
  }

  writeln(ans);
}


Measured memory_bytes: 1276
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace AtCoder
{
	public class ABC
	{
		static public void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
			Solve(args);
			Console.Out.Flush();
		}

		private const int mod = 1000000007;  // 10^9+7

		static public void Solve(string[] args)
		{
			//string s = Console.ReadLine();
			//int n = int.Parse(Console.ReadLine());
			//long x = long.Parse(Console.ReadLine());
			int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] vs = Console.ReadLine().Split().Select(long.Parse).ToArray();
			int a = vs[0];
			int b = vs[1];
			int c = vs[2];
			int k = vs[3];
			int ans = 0;

			ans = Math.Min(a, k);
			k = Math.Max(0, k - a);
			k = Math.Max(0, k - b);
			ans -= Math.Min(c, k);
			k = Math.Max(0, k - c);

			Console.WriteLine(ans);
		}

	}
}


Measured memory_bytes: 28264
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll n , x;
ll solve(ll base , ll hei)
{
        if(hei == base) return base;
        if(hei > base) {
                if(hei%base == 0) {
                        return (hei/base  -  1)*2*base + base;
                }else {
                        return (hei/base)*2*base + solve(base , hei%base);
                }
        }
        ll smol = hei;
        if(base%smol == 0) {
                return (base/smol  -  1)*2*smol + smol;
        }else {
                return (base/smol)*2*smol + solve(base%smol , hei);
        }
}
int main()
{
        cin >> n >> x;
        ll ans = x + n - x;
        ans += solve(x , n - x);
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 256
#https://atcoder.jp/contests/abc097/tasks/arc097_b

class UnionFindTree():

    def __init__(self, n):
        #木全体の要素数
        self.n  = n
        #root[x]<0ならそのノードが根でありその値が木の要素数
        self.root = [-1] * (n+1)
        #ランク
        self.rank = [1] * (n+1)

    def find_root(self,x):
        if self.root[x] < 0:
            return x
        else:
            self.root[x] = self.find_root(self.root[x])
            return self.root[x]

    def unite(self,x,y):
        x = self.find_root(x)
        y = self.find_root(y)
        if x == y:
            return
        elif self.rank[x] > self.rank[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def is_same(self,x,y):
        return self.find_root(x) == self.find_root(y)

    def count_node(self,x):
        return -1 * self.root[self.find_root(x)]


n, m = map(int, input().split())
uft = UnionFindTree(n)

p_arr = list(map(int, input().split()))

for _ in range(m):
    x, y = map(int, input().split())
    uft.unite(x, y)

ans = 0
for index, num in enumerate(p_arr):
    if uft.is_same(index+1, num):
        ans += 1
print(ans)



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

#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)
 
using namespace std;

typedef long long ll;
const ll MOD=1e9+7;
using pear = pair<int,int>; 

int main(){
    int sum = 0;
    rep(i,3){
        int a; cin>>a;
        sum += a;
    }
    if(sum<22) cout<<"win"<<endl;
    else cout<<"bust"<<endl;
}

Measured memory_bytes: 256
'''
	We can show that if u and v belong to the same connected component, then they are friends w/ each other
	So everyone in a given connected component is friends with one another
	So everyone in a given connected component must be separated into different groups

	If we have a CC of with sz nodes in it, then we need at least sz different groups

	So, the minimum number of groups needed is max sz(CC)
'''
import sys
sys.setrecursionlimit(2*10**5+5)

n, m = map(int,input().split())
adj = [[] for u in range(n+1)]
for i in range(m):
	u, v = map(int,input().split())
	adj[u].append(v)
	adj[v].append(u)

vis = [False for u in range(n+1)]
def dfs(u):
	if vis[u]:
		return 0
	vis[u] = True

	sz = 1
	for v in adj[u]:
		sz += dfs(v)
	return sz

CCs = []
for u in range(1,n+1):
	if not vis[u]:
		CCs.append(dfs(u))

print(max(CCs))

Measured memory_bytes: 210860
import math
result = 0
k = int(input())
for a in range(1, k+1) :
    for b in range(1, k+1) :
        if math.gcd(a ,b) == 1 :
            result += k
        else :
            for c in range(1, k+1) :
                result += math.gcd(math.gcd(a ,b), c)
print(result)

Measured memory_bytes: 9184