akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
using lint = long long;
#define low lower_bound
#define upp upper_bound
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define Rep(i, n) for (int i = int(n); i >= 0; --i)
#define all(vec) (vec).begin(), (vec).end()
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

struct edge { lint to, cost; };
using P = pair<lint, lint>;
using D = pair<double, double>;
//const lint mod = 998244353LL;
const lint mod = 1000000007LL;
const lint inf = 3e18;

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;
}

lint modpow(lint x, lint n) {
	lint ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (mod <= ans) ans %= mod;
		}
		x *= x;
		if (mod <= x) x %= mod;
		n >>= 1;
	}
	return ans;
}

lint fact[1000000];
void f_init(lint n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (lint i = 2; i <= n; ++i) {
		fact[i] = i * fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

lint comb(lint n, lint r) {
	if (n < r) return 0;
	if (n == r) return 1;
	lint ans = fact[n] * modpow(fact[n - r], mod - 2) % mod * modpow(fact[r], mod - 2);
	if (ans < 0) return ans + mod;
	return ans;
}

lint nck[1010][1010];
void comb(lint n) {
	rep(i, n + 1) {
		rep(j, i + 1) {
			if (j == 0 || i == j) nck[i][j] = 1;
			else nck[i][j] = nck[i - 1][j - 1] + nck[i - 1][j];
		}
	}
}

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

lint lcm(lint a, lint b) { return a / gcd(a, b) * b; }

bool pri(lint p) {
	for (lint i = 2LL; i * i <= p; ++i) if (p % i == 0) return false;
	return p > 1LL;
}

map<lint, lint> factring(lint n) {
	map<lint, lint>ans;
	for (lint i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

double dis(D a, D b) { return sqrt((a.first - b.first) * (a.first - b.first) + (a.second - b.second) * (a.second - b.second)); }

int n, a, b, c, ans = 100000;
int l[1010];
string quat(int x) {
	string ans;
	int y = (1 << (2 * n - 2));
	while (y != 0) {
		ans += '0' + x / y;
		x %= y;
		y /= 4;
	}
	return ans;
}
int main() {
	cin >> n >> a >> b >> c;
	rep(i, n) {
		cin >> l[i];
	}
	rep(i, (1 << 2 * n)) {
		string s = quat(i);
		int cnt[3] = { 0,0,0 };
		int cnt2 = 0;
		rep(j, n) {
			if (s[j] != '3') {
				if (cnt[s[j] - '0'] != 0) cnt2 += 10;
				cnt[s[j] - '0'] += l[j];
			}
		}
		if (cnt[0] * cnt[1] * cnt[2] == 0) continue;
		ans = min(ans, cnt2 + abs(a - cnt[0]) + abs(b - cnt[1]) + abs(c - cnt[2]));
	}
	cout << ans << endl;
}

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

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

	vector<int> sum(n);
	sum[0] = abs(a[0]);
	for (int i = 1;i < n;i++) {
		sum[i] = sum[i - 1] + abs(a[i] - a[i - 1]);
	}

	cout << abs(a[1]) + sum[n - 1] - sum[1] + abs(a[n - 1]) << endl;
	for (int i = 1;i < n-1;i++) {
		int ans = sum[i - 1] + abs(a[i + 1] - a[i - 1]) + (sum[n - 1] - sum[i + 1]) + abs(a[n-1]);
		cout << ans << endl;
	}
	cout << sum[n - 2] + abs(a[n - 2]) << endl;





	return 0;
}

Measured memory_bytes: 2048
#c
n = int(input())
alpha = [chr(i) for i in range(97, 97+26)]
i = 0
s = 0
while True:
    i  += 1
    if (n-1) //(26**i+s) < 1: #これが文字数
        break
    s = s + 26**i #累積和
t_turn = n-s #これが文字数内の順番
ans =""
for j in range(i,0,-1):
    ans += alpha[((t_turn-1)//(26**(j-1)))]
    t_turn = t_turn-((t_turn-1)//(26**(j-1)))*(26**(j-1))
print(ans)

Measured memory_bytes: 9232
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long int ll;

int main() {
  int A,B;
  cin>>A>>B;
  
  if(A<=9 && B<=9)
    cout<<A*B<<endl;
  else
    cout<<-1<<endl;
  
}


Measured memory_bytes: 256
from itertools import permutations
from scipy.sparse.csgraph import dijkstra as di
N,M,R=map(int,input().split())
r=list(map(int,input().split()))
dp=[[0 for _ in range(N)] for _ in range(N)]
 
for _ in range(M):
  A,B,C=map(int,input().split())
  if dp[A-1][B-1]==0 or dp[A-1][B-1]>C:
    dp[A-1][B-1]=C
    dp[B-1][A-1]=C
distance=di(dp)
'''
def get_target_min_index(min_index, distance, unsearched_nodes):
    start = 0
    while True:
        index = distance.index(min_index, start)
        found = index in unsearched_nodes
        if found:
            return index
        else:
            start = index + 1
 
 
distance = [[100001]*N] * N # ノードごとの距離のリスト
 
 
for i in range(R):
  for j in range(i+1,R):
    dist=[100001]*N
    dist[r[i]]=0
    unsearched_nodes = list(range(N)) # 未探索ノード
    previous_nodes = [-1] * N # 最短経路でそのノードのひとつ前に到達するノードのリスト
    while(len(unsearched_nodes) != 0): #未探索ノードがなくなるまで繰り返す
    # まず未探索ノードのうちdistanceが最小のものを選択する
      posible_min_distance = 100001 # 最小のdistanceを見つけるための一時的なdistance。初期値は inf に設定。
      for node_index in unsearched_nodes: # 未探索のノードのループ
          if posible_min_distance > dist[node_index]: 
              posible_min_distance = dist[node_index] # より小さい値が見つかれば更新
      target_min_index = get_target_min_index(posible_min_distance, dist, unsearched_nodes) # 未探索ノードのうちで最小のindex番号を取得
      unsearched_nodes.remove(target_min_index) # ここで探索するので未探索リストから除去
 
      target_edge = dp[target_min_index] # ターゲットになるノードからのびるエッジのリスト
      for index, route_dis in enumerate(target_edge):
          if route_dis != 0:
              if dist[index] > (dist[ target_min_index] + route_dis):
                  dist[index] = dist[ target_min_index] + route_dis # 過去に設定されたdistanceよりも小さい場合はdistanceを更新
                  previous_nodes[index] =  target_min_index #　ひとつ前に到達するノードのリストも更新
    #print("-----経路-----")
    previous_node = r[j]
    while previous_node != -1:
      if previous_node !=i:
        #print(str(previous_node + 1) + " <- ", end='')
      else:
        #print(str(previous_node + 1))
      previous_node = previous_nodes[previous_node]
 
    #print("-----距離-----")
    #print(dist[j])
    distance[i][j]=dist[j]
    distance[j][i]=dist[j]
'''
 
ans=10**11
for tmp in permutations(r):
  tmpans=0
  for i in range(len(tmp)-1):
    tmpans+=distance[tmp[i]-1][tmp[i+1]-1]
  if ans>tmpans:
    ans=tmpans
print(int(ans))

Measured memory_bytes: 15756
import java.util.*;
public class Main {
 public static void main(String[] args){
  Scanner sc = new Scanner(System.in);
  // 整数の入力
  // int a = sc.nextInt();
  // スペース区切りの整数の入力
  long n = sc.nextLong();
  long a = sc.nextLong();
  long b = sc.nextLong();

  // 文字列の入力
 long amari =  n %  (a + b);
 long syo = n/(a+b);
 	
 	
 		if(amari>=a){
  	 System.out.println(a+syo*a);

 		}else{
 			  	 System.out.println(amari+syo*a);
 		}
 	
 	
 // String s = sc.next();
// 	if(s.matches(".*A.*") & s.matches(".*B.*")){
 //	}else{
 //		 	 System.out.println("No");
 //	}
 }
}


Measured memory_bytes: 23892
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const ll INFTY = (1LL << 60);

class Edge{
public:
	int from, to;
	ll cost;
	Edge(int from = 0, int to = 0, ll cost = 0) :
			from(from), to(to), cost(cost){}

	bool operator < (const Edge &e) const{
		return cost < e.cost;
	}
	bool operator >(const Edge &e) const{
		return cost > e.cost;
	}

};

class Node{
public:
	vector<Edge> edges;
	ll dist;

	Node(){
		dist = INFTY;
	}
};

class Graph{
public:
	vector<Node> nodes;
	Graph(int n) {
		rep(i, n) { Node n;  nodes.push_back(n); }
	}
	Node& operator[](int i){
		return nodes[i];
	}
};

class Data{

public:
	ll dist;
	Edge *edge;
	Data(ll dist, Edge *edge) {
		this->dist = dist;
		this->edge = edge;
	}

	bool operator < (const Data &d) const{
		return dist < d.dist;
	}
	bool operator >(const Data &d) const{
		return dist > d.dist;
	}
};

int N, E;
Graph G(0);
ll A[100][100];

int main() {
	cin >> N >> E;
	G = Graph(N);

	rep(i, E){
		int x, y;
		ll d;
		cin >> x >> y >> d;
		G[x].edges.push_back(Edge(x, y, d));
	}

	// warshallFloyd
	rep(i, N) rep(j, N) A[i][j] = INFTY;
	rep(i, N) A[i][i] = 0;
	rep(i, N){
		for(auto &ee : G[i].edges) A[ee.from][ee.to] = min(ee.cost, A[ee.from][ee.to]);
	}

	rep(k, N)
	rep(i, N)
		rep(j, N){
            if (A[i][k] != INFTY && A[k][j] != INFTY){
                A[i][j] = min(A[i][j], A[i][k]+A[k][j]);
            }
        }

	// negative cycle
	rep(i, N){
		if(A[i][i] < 0){
			cout << "NEGATIVE CYCLE" << endl;
			return 0;
		}
	}

	// normal case
	rep(i, N){
		rep(j, N){
			if(A[i][j] == INFTY) cout << "INF";
			else cout << A[i][j];
			if(j < N-1){
				cout << " ";
			}
			else{
				cout << endl;
			}
		}
	}
}

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

int main()
{
	ll N,A,B;
	cin >> N >> A >> B;
	ll s = A+B;
	ll ans = N / s * A;
	ans += min((N%s),A);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3672
#include <iostream>
#include <string>
#include <vector>


using namespace std;

int main()
{
    unsigned long long int n,atai,hozi1,hozi2;
    std::cin >>n;
    for(int a = 0;a < n + 1;a++){
        if(a == 0){
            atai = 2;
            hozi1 = atai;
        }
        if(a == 1){
            atai = 1;
            hozi2;
        }
        if(a >= 2){
            atai = hozi1 + hozi2;
        }
        if((a % 2) == 0){
            hozi1 = atai;
        }else{
            hozi2 = atai;
        }
    }
    std::cout <<atai<<endl;
    return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    string S; cin >> S;
    string ans = "Yes";
    if (S.size() % 2 == 1){ans = "No";}
    else {
        rep(i, S.size()){
            if (i % 2 == 0){if (S[i] != 'h'){ans = "No"; break;}}
            else {if (S[i] != 'i'){ans = "No"; break;}}
        }
    }
    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

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

  if (s[0] != s[1] && s[0] != s[2] && s[1] != s[2]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

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

    string S; cin >> S;
    set<char> st;
  
    rep(i, 0, S.size()) {
      if (st.find(S[i]) == st.end()) st.insert(S[i]);
      else {
        cout << "no" << endl;
        return 0;
      }
    }
  
    cout << "yes" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repq(i,a,n) for(int i=a; i<=n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

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

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    string s; getline(cin,s);
    char c = s[8];
    printf("A%cC\n", c);
    return 0;
}

Measured memory_bytes: 256
import math
import copy

def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l

n=nCast(input())
a=nCast(inputArr1(n))

def akey(a):
    return a[0]+a[1]
list.sort(a,key=akey,reverse=True)


def func(a):
    pa,pb=0,0
    tag=True
    for idx in range(0,len(a)):
        if tag:
            pa+=a[idx][0]
        else:
            pb+=a[idx][1]
        tag=not tag
    return pa-pb
    
print(func(a)) 







Measured memory_bytes: 45480
import java.util.Collections;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	private static int n;

	public static void main(String[] args) {

		Main main = new Main();

		Set<Integer> set = new HashSet<>();
		int[][] arr = main.scan();
		int candies = 0;

		int f = 0;
		for (int i = 0; i < n; i++) {
			f += arr[0][i];
			for (int j = i; j < n; j++) {
				candies += arr[1][j];
			}
			set.add(f + candies);
			candies = 0;
		}

		System.out.println(Collections.max(set));
	}

	private int[][] scan() {

		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		int[][] arr = new int[2][n];
		for (int i = 0; i < 2; i++) {
			for (int j = 0; j < n; j++) {
				arr[i][j] = sc.nextInt();
			}
		}
		sc.close();
		return arr;
	}
}

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

int main(){
  int N, A;
  cin >> N >> A;
  bool flag = 0;
  for (int i = 0; i <= N; i++){
    for (int j = 0; j <= A; j++){
      if ((N - ((500 * i) + j)) == 0){
        cout << "Yes";
        flag = 1;
        break;
      }
    }
    if (flag == 1) break;
  }
  if (flag == 0) cout << "No";
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

cc = 1  # current_count
nuke_count = 0 # nuke no count

for a in A:
    if a == cc:
        cc += 1
    else:
        nuke_count += 1
        
if nuke_count == N:
    print('-1')
else:
    print(nuke_count)

Measured memory_bytes: 26140
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)

using namespace std;
typedef long long ll;
const int maxn=100000+10;

int x[maxn],xx[maxn],w[maxn];
int i,j,k,l,r,s,t,n,m;
ll c; 
int main(){
    scanf("%d%d%d",&n,&l,&t);
    fo(i,1,n) scanf("%d%d",&x[i],&w[i]);
    fo(i,1,n){
        if (w[i]==2) w[i]=-1;
        r=x[i]+w[i]*t;

        if (r>0) (c+=r/l)%=n;
        else if (r<0) (c+=(r+1)/l-1)%=n;
        xx[i]=(r%l+l)%l;
    }
    sort(xx+1,xx+n+1);
    c=(c+n)%n;
    fo(i,c+1,n) printf("%d\n",xx[i]);
    fo(i,1,c) printf("%d\n",xx[i]);

}

Measured memory_bytes: 2304
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = input.trim().split('\n');

var line;
var rectangles = 0;
var lozenges = 0;
while (line = lines.shift()) {
	var l = line.split(',').map(function(n){return +n;});
	var a = l[0];
	var b = l[1];
	var c = l[2];

	if (a * a + b * b == c * c)
		rectangles++;
	else if (a == b)
		lozenges++;
}
console.log(rectangles);
console.log(lozenges);

Measured memory_bytes: 7640
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define eb          emplace_back
#define c(P)        cout<<P<<"\n"
#define pii         pair<ll,ll>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define F           first
#define S           second
#define mp(x,y)     make_pair(x,y) 
#define mem(a,val)  memset(a,val,sizeof(a))
#define fr(i,a,n)   for(ll i=a;i<n;i++)
#define frr(i,a,n)  for(ll i=n-1;i>=a;i--)


const ll N   =  500005;
const ll mod = 1e9 + 7;

using namespace std;


void solve()
{
ll a,b,c,d;
string s;

cin>>s;
a = s[0] - '0';
b = s[1] - '0';
c = s[2] - '0';
d = s[3] - '0';
for (int i = 0; i < 8; ++i)
{  ll sum =a;
  std::vector<ll> v(3);
    for (int j = 0; j < 3; ++j)
    { 
     if(i&(1<<(j)))
     {
        v[j] = 1;
     }

    }
    if(v[0]==0)
      sum -=b;
    else sum+=b;
     if(v[1]==0)
      sum -=c;
    else sum+=c;
     if(v[2]==0)
      sum -=d;
    else sum+=d;
    if(sum==7)
    {
      cout<<a;
      if(v[0]==0)
        cout<<"-";
      else cout<<"+";
      cout<<b;
       if(v[1]==0)
        cout<<"-";
      else cout<<"+";
      cout<<c;
       if(v[2]==0)
        cout<<"-";
      else cout<<"+";
      cout<<d;
      cout<<"=7";
      return;

    }
    





}
}

signed main(){
  
      ios_base::sync_with_stdio(false);   
      cin.tie(NULL);
      ll T=1;
      //cin>>T;
      while(T--)
      {
      solve();
      }
      return 0;
    }


Measured memory_bytes: 256
<?php
fscanf(STDIN, "%d", $N);
$T = explode(" ", trim(fgets(STDIN)));
$M = fgets(STDIN);
$sum = array_sum($T);
for ($i = 0; $i < $M; $i++) {
 $_sum = $sum;
 fscanf(STDIN, "%d %d", $P, $X);
 $_sum -= $T[$P - 1];
 $_sum += $X;
 echo $_sum . "\n";
}


Measured memory_bytes: 4732
#![allow(unused_imports)]
use proconio::{
   fastout, input,
   marker::{Bytes, Isize1, Usize1},
};

fn mag_dif((x1, y1): (i32, i32), (x2, y2): (i32, i32)) -> i32 { (x1 - x2).abs() + (y1 - y2).abs() }

#[fastout]
fn main() {
   input! {
      h: usize,
      w: usize,
      d: usize,
      a: [[Usize1; w]; h],
      q: usize,
      lr: [(Usize1, Usize1); q]
   }
   let mut dir = vec![(0, 0); h * w];
   for i in 0..h {
      for j in 0..w {
         dir[a[i][j]] = (i as i32, j as i32);
      }
   }
   let mut mag = vec![0; h * w];
   for i in d..h * w {
      mag[i] = mag[i - d] + mag_dif(dir[i], dir[i - d]);
   }
   for (l, r) in lr {
      println!("{}", mag[r] - mag[l]);
   }
}


Measured memory_bytes: 7108
#include <stdio.h>
#include <stdlib.h>
#define N 100000

int CanLay(int, int, int, int *);

int main()
{
	int i;
	int n, k;
	int l, m, r;
	int weight[N];
	int maxWeight;
	
	scanf("%d %d", &n, &k);
	for(i = 0; i < n; i++)
	{
		scanf("%d", &weight[i]);
	}
	
	l = 0;
	r = 10000 * n / k;
	while(1)
	{
		m = (l + r) / 2;
		if(l == m) break;
		if(CanLay(n, k, m, weight))
		{
			r = m;		
		}
		else
		{
			l = m;
		}
	}
	printf("%d\n", r);
	
	return 0;
}

int CanLay(int n, int k, int m, int *weight)
{
	int i;
	int stack = 0;
	int numTracks = 1;

	for(i = 0; i < n; i++)
	{
		if(weight[i] > m) return 0;
		stack += weight[i];
		if(stack > m)
		{
			stack = weight[i];
			numTracks++;
		}
	}
	if(numTracks <= k) return 1;
	else return 0;
}

Measured memory_bytes: 988
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define all(c) begin(c), end(c)
#define dump(x) cerr << __LINE__ << ":\t" #x " = " << x << endl

const int INF = 1e9;

int N;
int P[100010];
int A[100010], B[100010];

int main(){
    while(cin >> N){
        memset(A, 0, sizeof A);
        memset(B, 0, sizeof B);
        rep(i,N){
            A[i] += 30000*(i+1);
            B[i] += 30000*(N-i);
            int p;
            cin >> p;
            --p;
            A[p] += i;
        }

        rep(i,N){
            cout << A[i] << (i == N-1 ? "\n" : " ");
        }
        rep(i,N){
            cout << B[i] << (i == N-1 ? "\n" : " ");
        }
    }
}


Measured memory_bytes: 1408
import java.util.Scanner;

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

        if (n%10 == 3) {
            System.out.println("bon");
        } else if (n%10 == 0 || n%10 == 1||n%10 == 6||n%10 == 8 ) {
            System.out.println("pon");
        } else {
            System.out.println("hon");
        }

    }
}


Measured memory_bytes: 35740
import sys
from collections import defaultdict

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())
    S = [0] * N
    for i in range(N):
        S[i] = readline().strip()

    d = defaultdict(int)
    for s in S:
        c = [0] * 26
        for l in s:
            c[ord(l) - 97] += 1
        d[tuple(c)] += 1

    ans = 0
    for n in d.values():
        if n > 1:
            ans += n * (n - 1) // 2

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 162316
#include <cstdio>
#include <algorithm>
using namespace std;

int main() {
    int array[3];
    for(int i = 0; i < 3; i++) {
        scanf("%d", &array[i]);
    }
    sort(array, array + 3);

    printf("%d\n", array[2] * 10 + array[1] + array[0]);

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <deque>

using namespace std;

#define FOR(i, start, end) for(ll i = (start); i < (end); i++)
#define rep(i, n) FOR(i, 0, n)
#define all(x) (x).begin(),(x).end()
#define ctoi(c) c - '0'
#define tos(s) to_string(s)

typedef long long ll;

int main() {
    ll n;
    cin >> n;
    ll mx = 0;
    ll sum = 0;
    rep (i, n) {
        ll a;
        cin >> a;
        mx = max(mx,a);
        if (mx > a) {
            sum += mx-a;
        }
    }
    cout << sum << endl;
    return 0;
}

/*
ACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACACAC                                                                              
                                   ******,  .,, .,, ,,,    ****.**              
                                   ** . .,,,,,,,,,,,,,,,,,,,,,. .,*             
                                   **,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.            
                                .,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.        
                                .,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.        
                    ****      ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,      
              ***************,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,    
         ********************,,,,,,,,,,,,,,@@@,,,,,,,,,,,/@@@,,,,,,,,,,,,,,,    
        ******************,,,,,,,,,,,,,,,,,,(,,.         ,,,,,,,,,,,,,,,,,,,    
       ********************,,,,,,,,,,,*,,,,,.     %&&&     .,,,,*,,,,,,,,,,,,.  
       ***,,,,,,,,,,,,,,*,,,,,,,,,,,,,,,,,,,,               ,,,,,,,,,,,,,,,,,   
       ,,,,,,,,,,,,,,,,,,,**,,,,,,,,,,.......      ##(     ........,,,,,,,,,,.  
     .,,,,,,,,,,,,,,,,,,**,,,,,,,,,,..............    ..............,,,,,,,,    
    .,,,,,,,,,,,,,,,,,,,**,,,,,,,,,.................................,,,,,,,,,   
   ,,,,,,,,,,,,,,,,,,,,***,,,,,,,....................................,,,,,,,,,  
   ,,,,,,,,,,,,,,,,,,,,**,,,,,,,,.....................................,,,,,,,   
   ,,,,,,,,,,,,,,,,,,,,,**,,,,,,,,....................................,,,,,,,   
   ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,.....................................,,,,,     
   ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,...................................,.,,,,,     
    ,,,,,,,,,,,,,,,,,,,,,,,,,,,,.....................................,,,        
     ,,,,,,,,,,,,,,,,,,,,,,,,,,,,....................................,,,        
      ,,,,,,,,,,,,,,,,,,,,,,,,,,,,...................................,          
       ..,,,,,,,,,,,,,,,,,,,,,,,,,,.................................,           
       .........**.....       ,,,,,..............................               
        .......*......                  ****,**,       ,..****                  
        .......*,....                   .......        ......                   
          .......*....                   .....          .....                   
                                         ......          .....                  
*/

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll A,B;
const ll M=10000000000LL+19;

ll hoge2(ll p,ll C) {
	ll q=M-p;
	
	ll X=C/p;
	ll Y=C/q;
	
	if(X==0) return Y+1;
	if(Y==0) return X+1;
	
	if(X>=1<<30 || Y>=1<<30 || (X-1)*(Y-1)/2>=1LL<<30) return 1LL<<30;
	if(p<q) swap(p,q);
	
	ll ret=0;
	for(int i=0;p*i<=C;i++) {
		ll v=(C-p*i)/q;
		ret+=v+1;
		if(ret>1LL<<25) break;
	}
	return ret;
	
}

pair<ll,ll> hoge(ll p,ll K) {
	
	ll C=1LL<<61;
	for(int i=60;i>=0;i--) if(hoge2(p,C-(1LL<<i))>=K) C-=1LL<<i;
	ll q=M-p;
	ll a=0,b=0;
	if(p>q) {
		for(int i=0;p*i<=C;i++) {
			ll v=(C-p*i)/q;
			a+=(v+1)*i;
			b+=v*(v+1)/2;
		}
	}
	else {
		for(int i=0;q*i<=C;i++) {
			ll v=(C-q*i)/p;
			b+=(v+1)*i;
			a+=v*(v+1)/2;
		}
	}
	
	return {a,b};
	
}


int ok(int K) {
	ll p=1;
	
	auto r=hoge(p,K);
	if(r.first>A&&r.second>B) return 0;
	if(r.first<=A&&r.second<=B) return 1;
	int i;
	for(i=40;i>=0;i--) if(p+(1LL<<i)<M) {
		auto r=hoge(p+(1LL<<i),K);
		if(r.first>A&&r.second>B) return 0;
		if(r.first<=A&&r.second<=B) return 1;
		if(r.first>A) p+=1LL<<i;
		
	}
	r=hoge(p,K);
	if(r.first>A&&r.second>B) return 0;
	if(r.first<=A&&r.second<=B) return 1;
	auto r2=hoge(p+1,K);
	if(r2.first>A&&r2.second>B) return 0;
	if(r2.first<=A&&r2.second<=B) return 1;
	
	assert(r.first>=A&&r.second<=B&&r2.first<=A&&r2.second>=B);
	ll ax=r2.first-r.first;
	ll ay=r2.second-r.second;
	ll bx=A-r.first;
	ll by=B-r.second;
	if(ax*by-bx*ay<=0) return 1;
	
	return 0;
	
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>A>>B;
	
	int K=0;
	for(i=20;i>=0;i--) if(ok(K+(1<<i))) K+=1<<i;
	cout<<K-1<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 3672
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <map>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  int A, B;
  cin >> A >> B;

  if (A <= 5) {
    cout << 0 << endl;
  } else if (A <= 12) {
    cout << B / 2 << endl;
  } else {
    cout << B << endl;
  }

  return 0;
}


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

void solve () {
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    vector<int> a(n);
    int sum = 0;
    for (int i = 1; i < n; i++) {
        if (s[i - 1] == 'A' && s[i] == 'C') {
            sum++;
        }
        a[i] = sum;
    }
    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        cout << a[r - 1] - a[l - 1] << "\n";
    }

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


Measured memory_bytes: 3800
#include <bits/stdc++.h>
#define ll long long int
#define pr pair<ll, ll>
#define tp tuple<ll, ll, ll>
using namespace std;
long long int mod = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    char s[7];
    cin >> s;
    if (s[3] == s[2] && s[5] == s[4])
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys

def main():
    n, y = map(int, sys.stdin.readline().split())

    for i in range(y // 10000, -1, -1):
        z = y - 10000 * i
        for j in range(z // 5000, -1, -1):
            k = n - i - j
            if z == 5000 * j + 1000 * k:
                print(i, j, k)
                sys.exit()
    else:
        print('-1 -1 -1')

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
//
// Created by watemus on 07.05.2020.
//

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>

using namespace std;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff first
#define ss second

using ll = long long;
using ld = long double;
#define int ll

constexpr ll INFL = 1'000'000'000'000'000'228;
constexpr int INFI = 1'000'000'228;

#ifdef LOCAL
#else
#endif


void run() {
    int n, L;
    cin >> n >> L;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n - 1; i++) {
        if (a[i] + a[i + 1] >= L) {
            cout << "Possible\n";
            for (int j = 0; j < i; j++) {
                cout << j + 1 << '\n';
            }
            for (int j = n - 2; j > i; j--) {
                cout << j + 1 << '\n';
            }
            cout << i + 1 << '\n';
            return;
        }
    }
    cout << "Impossible\n";
}

signed main() {
#ifdef LOCAL
    std::freopen("input.txt", "r", stdin);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif
    int t = 1;
//    cin >> t;
    while (t--) {
        run();
    }
    return 0;
}

Measured memory_bytes: 1664
import java.util.*; 

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

		String s = sc.next();
		int cnt = 0;
		int ans = 0;

		char [] a = s.toCharArray();

		for(int i=0;i<a.length;i++){
		  if(a[i]=='A' ||a[i]=='C' ||a[i]=='G'||a[i]=='T') {
				 cnt++;
		  	} else {
		//連続が終わった時の長さをansに入れる		  
				  if(ans<cnt){
					ans=cnt;
					cnt = 0;
				  }
			  }
		}
		if(ans<cnt){
			ans=cnt;
		}
		System.out.println(ans);
	  }
	}
	

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

using namespace std;

#define to first
#define ind second

const int N = 55;
vector<pair<int , int> > adj[N];

bool find_path (int node , int par , int target , vector<int> &path) {
    if (node == target)
        return 1;

    for (auto &e : adj[node]) {
        if (e.to == par) continue;
        path.push_back(e.ind);
        if (find_path(e.to , node , target , path))
            return 1;
        path.pop_back();
    }

    return 0;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.in" , "r" , stdin);
#endif
    int n;
    cin >> n;

    for (int i = 0 ;i < n - 1 ;i++) {
        int u , v;
        cin >> u >> v;
        adj[u].push_back({v , i});
        adj[v].push_back({u , i});
    }

    int m;
    cin >> m;

    vector<vector<int> > edges(m);
    for (int i = 0 ;i < m ;i++) {
        int a , b;
        cin >> a >> b;
        find_path(a , a , b , edges[i]);
    }


    vector<long long> p(n);
    p[0] = 1;
    for (int i = 1 ;i < n ;i++)
        p[i] = p[i - 1] * 2;

    long long bad = 0;
    for (int msk = 1 ;msk < (1 << m) ; msk++) {
        set<int> uni;
        int ones = 0;
        for (int i = 0 ;i < m ;i++) {
            if (msk & (1 << i)) {
                ones++;
                for (int x : edges[i])
                    uni.insert(x);
            }
        }

        if (ones&1)
            bad += p[n - 1 - uni.size()];
        else
            bad -= p[n - 1 - uni.size()];
    }

    cout << p[n - 1] - bad;
}

Measured memory_bytes: 3616
#include<stdio.h>
#include<iostream>
using namespace std;
char mine[55][55]={'\0'};
char output[55][55];
int h,w;
int main()
{
	cin>>h>>w;
	int i,j;
	for(i=1;i<=h;++i)
	{
		for(j=1;j<=w;++j)
		 cin>>mine[i][j];
	}
	for(i=1;i<=h;++i)
	{
		for(j=1;j<=w;++j)
		{    int flag=0;
		     if(mine[i][j]=='#')
			 {   output[i][j]='#';
			 	continue;
			  } 
			  else 
			  {
			  	if(mine[i-1][j-1]=='#')flag++;
			  	if(mine[i-1][j]=='#')flag++;
			  	if(mine[i-1][j+1]=='#')flag++;
			  	if(mine[i][j-1]=='#')flag++;
			  	if(mine[i][j+1]=='#')flag++;
			  	if(mine[i+1][j-1]=='#')flag++;
			  	if(mine[i+1][j]=='#')flag++;
			  	if(mine[i+1][j+1]=='#')flag++;
			  }
			  output[i][j]=48+flag;
			 
		}
	}
         for(i=1;i<=h;++i)
		  {
		  	for(j=1;j<=w;++j)
		    cout<<output[i][j];
		    cout<<endl;
		  }
		  return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(), A.end());
    ll ans = 0;
    if (N % 2 == 0) {
        for (int i = N-1; i >= N/2+1; i--) ans += 2*A[i];
        ans += A[N/2];
        ans -= A[N/2-1];
        for (int i = N/2-2; i >= 0 ; i--) ans -= 2*A[i];
    }
    else if (N % 2 == 1) {
        int t = (N-1)/2;
        for (int i = N-1; i >= t+2; i--) ans += 2*A[i];
        ans += max(2*A[t+1]-A[t]-A[t-1], A[t+1]+A[t]-2*A[t-1]);
        for (int i = t-2; i >= 0 ; i--) ans -= 2*A[i];
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  int N, K, X, Y;
  cin >> N >> K >> X >> Y;
  
  if (N <= K) {
    cout << N * X << endl;
  } else {
    cout << K * X + (N - K) * Y << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mod=1e9+7,N=5005;
int f[N][N];
signed main(){
	int n,m;
	cin>>n>>m;
	for(int i=1;i<=m;++i)
		f[0][i]=1;
	for(int i=1;i<=n;++i){
		for(int j=2;j<=m;++j)
			f[i][j]=(f[i][j-1]*2ll+f[i-1][j-1]*(j-1)%mod)%mod;
		for(int j=1;j<=m;++j)
			f[i][j]=(f[i][j]+f[i-1][j]*(j+1)%mod)%mod;
	}
	cout<<f[n][m];
	return 0;
}

Measured memory_bytes: 199124
n = gets.to_i
a = gets.split.map(&:to_i)
x=[]
y=[]
n.times do |i|
    if i.even?
        x<< a[i]
    else
        y<< a[i]
    end
end
if n.odd?
    b=x.reverse+y
else
    b=y.reverse+x
end
puts b.join(' ')

Measured memory_bytes: 38776
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;


    void calc()
    {
        cin = new Scanner();
        int[] HW = cin.ArrayInt(2,0);
        char[,] map=new char[HW[0],HW[1]];
        string[] s=new string[HW[0]];
        int[] dx={1,1,1,-1,-1,-1,0,0};
        int[] dy={1,-1,0,1,-1,0,1,-1};
        for(int i=0;i<HW[0];i++)
        {
          s[i]=cin.next();
        }
        for(int i=0;i<HW[0];i++)
        {
          for(int j=0;j<HW[1];j++)
          {
            if(s[i][j]=='#')map[i,j]='#';
            else 
            {
              int count=0;
              for(int z=0;z<8;z++)
              {
                if(i+dx[z]>=0&&i+dx[z]<HW[0]&&j+dy[z]>=0&&j+dy[z]<HW[1]&&s[i+dx[z]][j+dy[z]]=='#')
                {
                  count++;
                }
                map[i,j]=count.ToString()[0];
              }
            }
          }
        }
        
        for(int i=0;i<HW[0];i++)
        {
          for(int j=0;j<HW[1]-1;j++)
          {
            Console.Write(map[i,j]);
          }
          Console.WriteLine(map[i,HW[1]-1]);
        }
        
    }


}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}

Measured memory_bytes: 13140
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val aList = readLine()!!.split(" ").map { it.toLong() }
    val vaList = aList.asReversed()

    var rightSum = 0L
    var leftSum = 0L
    var right = 0
    var left = 0
    while (right + left < aList.size) {
        if (rightSum <= leftSum) {
            rightSum += vaList[right++]
        } else {
            leftSum += aList[left++]
        }
    }

    println(Math.abs(rightSum - leftSum))
}

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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b + c > 21)
        print("bust");
    else
        print("win");

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(long long i=0;i<(long long)(n);i++)
#define N 200010






int main() {
	long long n, m, k;
	long long ss;
	vector<long long>d;
	vector<long long>ans;
	vector<long long>a;
	vector<long long>b;
	vector<bool>used;
	long long x, y;
	scanf("%lld", &n);
	f(i, n) {
		scanf("%lld", &x);
		d.push_back(x);
	}
	ss = d[0];
	f(i, n - 1)d[i] = d[i + 1] - d[i];
	f(i, n - 1)a.push_back(i);
	scanf("%lld %lld", &m, &k);
	f(i, m) {
		scanf("%lld", &x);
		swap(a[x - 2], a[x - 1]);
	}
	f(i, n - 1) {
		ans.push_back(0);
		used.push_back(false);
	}
	f(i, n - 1) {
		if (!used[i]) {
			b.clear();
			b.push_back(i);
			used[i] = true;
			y = 1;
			x = a[i];
			while (x != i) {
				b.push_back(x);
				used[x] = true;
				y++;
				x = a[x];
			}
			f(j, y) {
				x = (j + k) % y;
				ans[b[j]] = d[b[x]];
			}
		}
	}
	x = ss;
	printf("%lld\n", x);
	f(i, n - 1) {
		x += ans[i];
		printf("%lld\n", x);
	}

	return 0;
}


Measured memory_bytes: 4516
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main() {
	int a, b, h, m;
	long double the,l;
	scanf("%d %d %d %d", &a, &b, &h, &m);
	the = fabsl(3.1415926535897932384*(30*h-5.5*m)/180);
	l = sqrtl(a*a+b*b-2*a*b*cosl(the));
	printf("%.20Lf",l);
}

Measured memory_bytes: 2580
#include <stdio.h>
#include <vector>

using namespace std;

#define MOD 1000000007

struct mint {
    int n;
    mint(int n_ = 0) : n(n_) {}
};

mint operator+(mint a, mint b) { a.n += b.n; if (a.n >= MOD) a.n -= MOD; return a; }
mint operator-(mint a, mint b) { a.n -= b.n; if (a.n < 0) a.n += MOD; return a; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }

mint dp0[100000];
mint dp1[100000];
int N;
vector<int> G[100000];

void dfs(int u, int p) {
    dp0[u] = 1;
    dp1[u] = 1;
    for (int v : G[u]) if (v != p) {
        dfs(v, u);
        dp0[u] *= dp0[v] + dp1[v];
        dp1[u] *= dp0[v];
    }
}

int main() {
    scanf("%d", &N);
    for (int i = 0; i < N - 1; i++) {
        int u, v;
        scanf("%d %d", &u, &v);
        u--; v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs(0, -1);
    printf("%d\n", (dp0[0] + dp1[0]).n);
    return 0;
}



Measured memory_bytes: 13440
#include<iostream>
using namespace std;
#include<math.h>
int main(void)
{
long n;
cin>>n;
long min = 1e18;
for(long i=1;i*i<=n;i++)
{
  
    if(n%i!=0) continue;

    long shou = n/i;

  min =(min,i+shou-2);
}
cout<<min<<endl;


}

Measured memory_bytes: 256
N,K=map(int,input().split())

kaijo=[0]*(N+2)
kaijo[0]=1
kaijo[1]=1
s=0
rui=[0]*(N+2)
rui[0]=0
rev=[0]*(N+2)
rev[0]=N
for i in range(N+1):
    kaijo[i+1] *= (i+1)*kaijo[i]
    rui[i+1] += rui[i] + i+1
    rev[i+1] += rev[i] + (N-i-1)
    

for k in range(K,N+2):
    s += rev[k-1]-rui[k-1]+1

print(s%1000000007)

Measured memory_bytes: 31788
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan=new Scanner(System.in);
		int a=scan.nextInt();
		int b=scan.nextInt();
		int c=0;
		if(a%2==0) {
			c=a/2;
		}
		else {
			c=a/2+1;
		}
		if(c>=b) {
			System.out.println("YES");
		}
		else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
#include <deque>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using itn = int;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;

int main() {

    int  n;
    cin >> n;

    cout << 3*n*n << endl;
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
 
#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------
 
ll dp[505050];
int N,M;
const ll mo=1000000007;
const int NUM_=600001;
static ll fact[NUM_+1],factr[NUM_+1],inv[NUM_+1];
 
ll comb(ll N_, ll C_) {
	if(C_<0 || C_>N_) return 0;
	return factr[C_]*fact[N_]%mo*factr[N_-C_]%mo;
}
 
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	inv[1]=fact[0]=factr[0]=1;
	for (int i=2;i<=NUM_;++i) inv[i] = inv[mo % i] * (mo - mo / i) % mo;
	for (int i=1;i<=NUM_;++i) fact[i]=fact[i-1]*i%mo, factr[i]=factr[i-1]*inv[i]%mo;
	
	cin>>N>>M;
	ll ret=0;
	FOR(i,N+1) {
		dp[i]=comb(M,i)*comb(N,i)%mo*fact[i]%mo*fact[M-i]%mo*fact[M-i]%mo*factr[M-N]%mo*factr[M-N]%mo;
		if(i%2) {
			ret-=dp[i];
		}
		else {
			ret+=dp[i];
		}
	}
	
	cout<<(ret%mo+mo)%mo<<endl;
}
 
 
int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}

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

vector<string> visited;
vector<int> num;

int main(){
  int N,M;
  string s;
  cin >> N;

  cin >> s;
  visited.push_back(s);
  num.push_back(1);
  for (int i = 0; i < N-1; i++){
      int flag = 0;
    cin >> s;
    for (int j = 0; j < (int)visited.size(); j++){
      if (s == visited[j]){
        num[j]++;
        flag = 1;
      }
    }
    if(flag == 0){
        visited.push_back(s);
        num.push_back(1);
    }
  }


  cin >> M;
  for (int i = 0; i < M ; i++){
    cin >>s;
    for (int j = 0; j < (int)visited.size(); j++) if (s == visited[j]) num[j]--;
  }

  int ma = 0;
  for (int i = 0; i <(int)num.size(); i++) ma = max(ma, num[i]);

  cout << ma << endl;
  return 0;
}


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

int main(){
    int D; cin >> D;
    vector<int> c(26);
    rep(i,26) cin >> c[i];
    vector<vector<int>> s(D,vector<int>(26));
    rep(i,D){
        rep(j,26){
            cin >> s[i][j];
        }
    }
    vector<int> t(D);
    rep(i,D) cin >> t[i];

    vector<int> day(26,0);

    ll score=0;
    int tuday=1;
    rep(z,D){
        score += s[z][t[z]-1];
        day[t[z]-1] = z+1;
        rep(i,26){
            score -= c[i] * ((z+1) - day[i]);
        }
        cout << score << endl;
    }

}


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

int main() {
	int N,ans = 0;
	cin >> N;
	vector<int> data(N);
	rep(i,N-1){
		cin >> data.at(i);
	}
    ans += data.at(0);
    rep(i,N-2){
        if(data.at(i) > data.at(i+1)){
            ans += data.at(i+1);
        }else{
            ans += data.at(i);
        }
    }
    ans += max(data.at(N-2),data.at(N-1));
    cout << ans << endl;
}


Measured memory_bytes: 256