akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::{stderr, stdin, stdout, BufRead, BufWriter, Read, StdoutLock, Write};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::{i64, u64, usize};
#[allow(unused_macros)]
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;($($r :tt ) *) =>{let mut s ={use std ::io ::Read ;let mut s =String ::new () ;std ::io ::stdin () .read_to_string (&mut s ) .unwrap () ;s } ;let mut iter =s .split_whitespace () ;input_inner !{iter ,$($r ) *} } ;}
#[allow(unused_macros)]
macro_rules !input_inner {($iter :expr ) =>{} ;($iter :expr ,) =>{} ;($iter :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($iter ,$t ) ;input_inner !{$iter $($r ) *} } ;}
#[allow(unused_macros)]
macro_rules !read_value {($iter :expr ,($($t :tt ) ,*) ) =>{($(read_value !($iter ,$t ) ) ,*) } ;($iter :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($iter ,$t ) ) .collect ::<Vec <_ >>() } ;($iter :expr ,chars ) =>{read_value !($iter ,String ) .chars () .collect ::<Vec <char >>() } ;($iter :expr ,usize1 ) =>{read_value !($iter ,usize ) -1 } ;($iter :expr ,$t :ty ) =>{$iter .next () .unwrap () .parse ::<$t >() .expect ("Parse error" ) } ;}
#[allow(unused_macros)]
macro_rules !dbg {($($a :expr ) ,*) =>{writeln !(&mut stderr () ,concat !($(stringify !($a ) ," = {:?}, " ) ,*) ,$($a ) ,*) .unwrap () ;} }
#[allow(non_snake_case)]
#[allow(dead_code)]
fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }
    let mut i = 1;
    for ai in a {
        if ai == i {
            i += 1;
        }
    }
    if i == 1 {
        println!("-1");
    } else {
        println!("{}", n - (i - 1));
    }
}

Measured memory_bytes: 8444
#pragma GCC optimize ("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse4")
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
#define all(x) x.begin(), x.end()
#define trav(i,a) for(auto &i:a) 
inline int in(){int x;scanf("%lld",&x);return x;}
int dp[60][2];
const int mxd=50;
//dp[i][0] answer for ms i bits if ith is 0
int32_t main()
{
	int n=in();int k=in();
	vector<int> a(n);
	for(int &i:a)i=in();
	memset(dp,-1,sizeof dp);
	dp[0][0]=0;
	for(int d=0;d<mxd;d++)
	{
		int mask=1LL<<(mxd-d-1);
		int ct=0;//ct of ones at this bit
		for(int i:a)if(i&mask)ct++;
		int x1=mask*(n-ct);int x0=mask*ct;
		if(dp[d][1]!=-1)
		dp[d+1][1]=max(dp[d+1][1],dp[d][1]+max(x0,x1));
		
		if(dp[d][0]!=-1)
		{
			if(k&mask)
			{
				dp[d+1][1]=max(dp[d][0]+x0,dp[d+1][1]);
				dp[d+1][0]=max(dp[d+1][0],dp[d][0]+x1);
			}
			else dp[d+1][0]=max(dp[d+1][0],dp[d][0]+x0);
		}
	}
	cout<<max(dp[mxd][0],dp[mxd][1]);
	
	
	
}


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

#define fi first
#define se second
#define pb push_back
#define mod(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,a,b) for(int i = a; i < b; i++)
#define forr(i,a,b) for(int i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int maxn = 100000+10;
const ll oo  = numeric_limits<ll>::max();
ll dp[maxn],A[maxn];
int N;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> N;
	forn(i,0,N)cin >> A[i];
	dp[0] = 0;
	forn(i,1,N){
		dp[i] = oo;
		if(i-1 >= 0){
			dp[i] = dp[i-1]+abs(A[i-1]-A[i]); 
		}
		if(i-2 >= 0){
			dp[i] = min(dp[i],dp[i-2]+abs(A[i-2]-A[i]));
		}
	}
	cout << dp[N-1] << '\n';
	return 0;
}
/*
__builtin_mul_overflow(x,y,&x)
-fsplit-stack
*/


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


int main(){
  int h,w,n;
  cin >> h >> w;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a.at(i);
  //
  vector<vector<int>> b(h,vector<int>(w));
  int revolver = 0;
  rep(i,h){
    rep(j,w){
      if(a.at(revolver) == 0){
        revolver++;
      }
      if(i % 2 == 0){
        b.at(i).at(j) = revolver+1;
        a.at(revolver)--;
      }else{
        b.at(i).at(w-1-j) = revolver+1;
        a.at(revolver)--;
      }
    }
  }
  rep(i,h){
    rep(j,w){
      cout << b.at(i).at(j) << " ";
    }
    cout << endl;
  }
}
        

        

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

using namespace std;

long long INF = 1000000000000000000;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<long long> a(n);
    long long ans = 1;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
        if (a[i] == 0) {
            cout << 0 << '\n';
            return 0;
        }
    }
    for (int i = 0; i < n; i++) {
        if (a[i] > (INF / ans)) {
            cout << -1 << '\n';
            return 0;
        }
        ans *= a[i];
    }
    cout << ans << '\n';
    return 0;
}

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

ch_list=[]
for i in range(1,N):
  if S[i-1]!=S[i]:
    ch_list.append(i)
#print(ch_list)
len_ch=len(ch_list)

if len_ch>2*K:
  print(N-1-len_ch+2*K)
else:
  print(N-1)

Measured memory_bytes: 7108
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)

ll N, M;

void solve() {
    if (N == 2 || M == 2) {
        cout << 0 << endl;
        return;
    }
    if (N == 1 && M == 1) {
        cout << 1 << endl;
        return;
    }
    if (N == 1) {
        cout << M - 2 << endl;
        return;
    } else if (M == 1) {
        cout << N - 2 << endl;
        return;
    } else {
        cout << N * M - (2 * M + 2 * (N - 2)) << endl;
        return;
    }
}

int main() {
    cin >> N >> M;
    solve();
    return 0;
}

Measured memory_bytes: 256
D=int(input())
clist=list(map(int,input().split()))
smat=[[int(x) for x in input().split()] for _ in range(D)]
#print(clist)
#print(smat)

index_set=set(range(26))
for d in range(D):
  max_index=-1
  max_sd=-1
  for i in index_set:
    if max_sd<smat[d][i]:
      max_index=i
      max_sd=smat[d][i]
      
  max_index2=-1
  max_sd2=-1
  for i in range(26):
    if max_sd<smat[d][i]:
      max_index2=i
      max_sd2=smat[d][i]
      
  if max_index==max_index2:
    print(max_index+1)
    index_set.remove(max_index)
  else:
    if max_sd2>4*max_sd:
      print(max_index2+1)
    else:
      print(max_index+1)
      index_set.remove(max_index)      
      
  if not index_set:
    index_set=set(range(26))

Measured memory_bytes: 69376
w=gets.chomp
t=""
while true
    str=gets.chomp
    if str=="END_OF_TEXT"
        break
    end
    t+=" "+str
end

tsplit=t.split(" ")
cnt=0
tsplit.each { |item|
    if item.casecmp(w)==0
        cnt+=1
    end
}
puts cnt

Measured memory_bytes: 8612
import heapq
n = int(input())
a = list(map(int, input().split()))

a1 = a[:n]
heapq.heapify(a1)
a1_sum = sum(a1)
a1_sums = [a1_sum]
for i in range(n, 2*n):
    a1_min = heapq.heappop(a1) # pop the smallest value from a1
    if a[i] > a1_min:
        heapq.heappush(a1, a[i])
        a1_sum = a1_sum - a1_min + a[i]
    else:
        heapq.heappush(a1, a1_min)
    a1_sums.append(a1_sum)

a2 = a[-n:]
a2_sum = sum(a2)
a2_sums = [a2_sum]
a2_inv = [-aa for aa in a2]
heapq.heapify(a2_inv)
for i in range(2*n-1, n-1, -1):
    a2_max = -heapq.heappop(a2_inv) # pop the largest value from a2
    if a[i] < a2_max:
        heapq.heappush(a2_inv, -a[i])
        a2_sum = a2_sum - a2_max + a[i]
    else:
        heapq.heappush(a2_inv, -a2_max)
    a2_sums.append(a2_sum)
a2_sums = a2_sums[::-1] # reverse order

ans = a1_sums[0] - a2_sums[0]
for a1_s, a2_s in zip(a1_sums, a2_sums):
    ans = max(ans, a1_s-a2_s)
print(ans)


Measured memory_bytes: 38292
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N = i()
a = l()
b = l()
num = sum(b)-sum(a)
cnt1 = 0
cnt2 = 0
for i in range(N):
    if a[i] > b[i]:
        cnt1 += a[i]-b[i]
    if a[i] < b[i]:
        cnt2 += (b[i]-a[i]-1)//2+1
if cnt1 > num or cnt2 > num:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 77804
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String str = sc.next();
    char start = str.charAt(0);
    char end = str.charAt(str.length()-1);
    System.out.print(start);
    System.out.print(str.length()-2);
    System.out.println(end);
  }
}


Measured memory_bytes: 22612
#include <iostream>

using namespace std;

int main()
{
    int a = 0;
    int b = 0;
    int c = 0;
    int total = 0;
    
    cin >> a >> b >> c;
    total = a + b + c;
    
    if (total>=22){
        cout << "bust";
    }
    else{
        cout << "win";
    }
    
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.BitSet;
import java.util.HashSet;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(bf.readLine());
        StringBuilder sb = new StringBuilder();
        BitSet bitSet = new BitSet(33554432);
        HashSet<Integer> hashSet = new HashSet<>();
        final char[] key = new char[128];
        key['A'] = 0;
        key['C'] = 1;
        key['G'] = 2;
        key['T'] = 3;
        for (int i = 0; i < n; i++) {
            String sp = bf.readLine();
            if (sp.charAt(0) == 'i') {
                int hash = 1;
                for (int j = 7; j < sp.length(); j++) {
                    hash <<= 2;
                    hash+=key[sp.charAt(j)];
                }
                bitSet.set(hash);
            } else {
                int hash = 1;
                for (int j = 5; j < sp.length(); j++) {
                    hash <<= 2;
                    hash+=key[sp.charAt(j)];
                }
                sb.append(bitSet.get(hash) ? "yes\n" : "no\n");
            }
        }
        bf.close();
        System.out.print(sb.toString());
    }
}


Measured memory_bytes: 69756
#include<stdio.h>

int main(){
  int H, W, N;
  
  scanf( "%d %d %d", &H, &W, &N);
  int sum = 0;
  int cnt = 0;
  while (sum < N)
  {
    if( H >= W){
      sum += H;
      W--;
    } else {
      sum += W;
      H--;
    }
    cnt++;
  }
  
  printf("%d", cnt);
  return 0;
}

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

typedef long long int llint;

int main()
{
  int n, k;
  cin>> n >> k;

  llint x[100001];
  for(int i = 0; i < n; i++) cin>> x[i];

  llint s = 0, mn;
  for(int i = 0; i < k - 1; i++) s += abs(x[i] - x[i + 1]);
  mn = s + min(abs(x[0]), abs(x[k - 1]));
  
  for(int i = 1; i < n - k + 1; i++) {
    s -= abs(x[i] - x[i - 1]);
    s += abs(x[i + k - 2] - x[i + k - 1]);
    mn = min(mn, s + min(abs(x[i]), abs(x[i + k - 1])));
  }

  cout<< mn <<endl;

  return 0;
}


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

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

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
  ll n, a[10001], b[10001], as = 0, bs = 0;
  cin >> n;
  rep(i, 0, n) cin >> a[i], as += a[i];
  rep(i, 0, n) cin >> b[i], bs += b[i];
  if(as > bs) {
    cout << "No" << endl;
    return 0;
  }

  ll c = 0, d = 0;
  rep(i, 0, n) {
    if(a[i] > b[i]) c += a[i] - b[i];
    else if(a[i] < b[i]) {
      d += b[i] - a[i];
      d -= (b[i] - a[i]) % 2;
    }
  }
  if(c * 2 <= d) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <sstream>
#include <stdio.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <set>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <bitset>
#include <stack>
#include <queue>
#include <ctype.h>
#include <list>

typedef long long int lli;
#define rep(i,s,N) for(int i=s;i<N;i++)
#define MOD 1000000007
#define more(a,b) (((a)>(b))?(a):(b))
#define less(a,b) (((a)<(b))?(a):(b))
template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;


int main(void)
{
	lli N; cin >> N;
	lli ans = N * (N - 1) / 2;

	cout << ans << endl;

	return 0;
}


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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int

int main(){
  int r;
  cin>>r;
  if(r<1200)
    cout<<"ABC"<<endl;
  else if(r<2800)
    cout<<"ARC"<<endl;
  else
    cout<<"AGC"<<endl;



  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;
const int MAX_N = 1e3+10;

int main(int argc, char const *argv[])
{
	int n;
	double t, a, h[MAX_N];
	cin >> n;
	cin >> t >> a;
	for (int i = 0; i < n; ++i) cin >> h[i];

	int ans = 0;
	double temp = t-h[0]*0.006;
    for (int i = 0; i < n; ++i)
    {
    	if (abs(a-(t-h[i]*0.006))<abs(a-temp))
    	{
    		temp = t-h[i]*0.006;
    		ans = i;
    	}
    }
    cout << ans + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque
S = deque(list(input()))
Q = int(input())

flag = False
for _ in range(Q):
    q = list(input().split())
    if q[0] == '1':
        flag = True if flag is False else False
    else:
        if flag is False:
            if q[1] == '1':
                S.appendleft(q[2])
            else:
                S.append(q[2])
        else:
            if q[1] == '1':
                S.append(q[2])
            else:
                S.appendleft(q[2])

if flag is True:
    S.reverse()
print(''.join(S))


Measured memory_bytes: 8548
n = int(input())
a = list(map(int,input().split()))
num_a = [0 for i in range(10 ** 5)]
for i in range(n):
    num_a[a[i]-1] += 1

q = int(input())
sum_a = sum(a)
#print(num_a)
for i in range(q):
    b,c = map(int,input().split())
    sum_a = sum_a + (c-b)*num_a[b-1]
    print(sum_a)
    num_a[c-1] += num_a[b-1]
    num_a[b-1] = 0
    
    


Measured memory_bytes: 90832
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;

class Node{
	public:
		int location;
		int p,l,r;
		Node(){
		}
};


class Point{
	public:
		int id,x,y;
		Point(){
		}
		Point(int id,int x,int y):id(id),x(x),y(y){
		}
		
		bool operator < (const Point &p) const{
		return id<p.id;
		}
		
		void print(){
			printf("%d\n",id);
		}
};

static const int MAX = 1000000;
static const int NIL = -1;

int N;
Point P[MAX];
Node T[MAX];

int np=0;

bool lessX(const Point &p1, const Point &p2){
	return p1.x<p2.x;
}

bool lessY(const Point &p1,const Point &p2){
	return p1.y<p2.y;
}

int makeTree(int l,int r,int depth){
	if(!(l<r)) return NIL;
	int mid = (l+r)/2;
	
	int t = np++;
	if(depth%2==0){
		sort(P+l,P+r,lessX);
	}else {
		sort(P+l,P+r,lessY);
	}
	
	T[t].location = mid;
	T[t].l = makeTree(l,mid,depth+1);
	T[t].r = makeTree(mid+1,r,depth+1);
	return t;
}


void find(int v,int sx,int tx, int sy,int ty,int depth,vector<Point> &ans){
	int x = P[T[v].location].x;
	int y = P[T[v].location].y;
	
	if(sx<=x&&x<=tx&&sy<=y&&y<=ty){
		ans.push_back(P[T[v].location]) ;
	}
	
	if(depth%2==0){
		if(T[v].l!=NIL){
			if(sx<=x) find(T[v].l,sx,tx,sy,ty,depth+1,ans);
	}
		if(T[v].r!=NIL){
			if(x<=tx) find(T[v].r,sx,tx,sy,ty,depth+1,ans);
	}
}

	else{
		if(T[v].l!=NIL){
			if(sy<=y) find(T[v].l,sx,tx,sy,ty,depth+1,ans);
	}
		if(T[v].r!=NIL){
			if(y<=ty) find(T[v].r,sx,tx,sy,ty,depth+1,ans);
		}
	}
}

int main(){
	int x,y;
	scanf("%d",&N);
	
	
	for(int i=0;i<N;i++){
		scanf("%d %d",&x,&y);
		P[i] = Point(i,x,y);
		T[i].l = T[i].r = T[i].p = NIL;	
	}
	
	np=0;
	
	int root = makeTree(0,N,0);
	
	int q;
	scanf("%d",&q);
	int sx,tx,sy,ty;
	vector<Point> ans;
	for(int i=0;i<q;i++){
		scanf("%d %d %d %d",&sx,&tx,&sy,&ty);
		ans.clear();
		find(root,sx,tx,sy,ty,0,ans);
		sort(ans.begin(),ans.end());
		for(int j=0;j<ans.size();j++){
			ans[j].print();
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 16456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, m, d[5003][5003] = {1};
    string s;
    cin >> n >> s; m = (int)s.length();
    for (int i = 1; i <= n; i++) for (int j = 0; j <= n; j++) d[i][j] = ((d[i - 1][max(0, j - 1)] + d[i - 1][j + 1]) % mod + d[i - 1][j + 1]) % mod;
    cout << d[n][m];
}


Measured memory_bytes: 98048
#include <iostream>    // cin, cout
#include <string>    // string, stoi, to_string
#include <algorithm>    // sort, lower_bound, heap, min, next_permutation 
#include <functional>    // greater, less
#include <vector>    // vector
#include <stack>    // stack
#include <queue>    // queue
#include <list>    // list
#include <map>    // map
#include <set>    // set
#include <tuple>    // tuple
#include <bitset>    // bitset
#include <cstdio>  // fopen, printf, scanf, puts
#include <cmath>    // sin, exp, log, pow, sqrt
#include <iomanip>    // setfill, setbase

using namespace std;
using pii = pair<int, int>;
using ti = tuple<int, int, int>;

const double eps=1e-14;
const int mod = 1e9 + 7;
const int inf = ((1<<30));
const long long linf = (1LL<<60);

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m, k;
    cin >> n >> m >> k;
    bool ok = false;
    for(int i=0; i<=n; i++)
    {
        for(int j=0; j<=m; j++)
        {
            int tmp;
            tmp = i*m + j*n - 2*i*j;
            if(tmp == k)
            {
                ok = true;
                break;
            }
        }
    }
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=(int)a; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define FI first
#define SE second
#define MP make_pair
#define PB push_back
#define SZ(x)  (int)x.size()
#define SP(x)  setprecision((int)x)


using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<string> vstr;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll LINF = 1e18;
const double EPS = 1e-9;
ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;} //最小公倍数


int main()
{
  double a, b, x ;
  cin >> a >> b >> x ;
  double c = (2*a*a*b-2*x)/(a*a*a) ;
  
  double ans1 = atan(c) ;
  
  ans1 = ans1/M_PI*180 ;
  
  double d = (a*b*b)/(x*2) ;
  
  double ans2 = atan(d) ;
  
  ans2 = ans2/M_PI*180 ;
  
  double e = b/a ;
  
  double tmp = atan(e) ;
  
  tmp = tmp/M_PI*180 ;
  

  
  if(ans1<=tmp){
    cout << SP(10) << ans1 <<endl ;
  }
  else{
    cout << SP(10) << ans2 <<endl ;
  }
  


  return 0 ;
}




Measured memory_bytes: 256
//
//  main.cpp
//  앳코
//
//  Created by 김도훈 on 2020/09/13.
//  Copyright © 2020 김도훈. All rights reserved.
//

#include <iostream>
using namespace std;

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


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

ordered = [i for i in range(1,n+1)]
i = 0
count = 0

for i in range(n):
  if i == 0:
    if a[i] == ordered[i]:
      tmp = a[i]
      a[i] = a[i+1]
      a[i+1] = tmp
      count += 1
  elif i == n-1:
    if a[i] == ordered[i]:
      tmp = a[i]
      a[i] = a[i-1]
      a[i-1] = tmp
      count += 1  
  else:
    if a[i] == ordered[i]:
      tmp = a[i]
      a[i] = a[i+1]
      a[i+1] = tmp
      count += 1
print(count)

Measured memory_bytes: 14008
#include <bits/stdc++.h>
using namespace std;
using ll = long long;using vll = vector<ll>;
int main(){
  ll n, sum = 0;
  cin >> n;
  vll a(n), x(n, 0);
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
    if (i % 2 == 0) x[0] += a[i];
    else x[0] -= a[i];
  }
  
  cout << x[0] << ' ';
  
  for (ll i = 1; i < n; i++) {
    x[i] = 2*a[i-1]-x[i-1];
    if (i < n-1) cout << x[i] << ' ';
    else cout << x[i] << endl;
    
  }
}


Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    int n;
    cin>>n;
    if(n%10==3) cout<<"bon";
    else if(n%10==0||n%10==1||n%10==6||n%10==8) cout<<"pon";
    else cout<<"hon";
}

Measured memory_bytes: 3604
N, M = map(int, input().split())

l = []
for i in range(1, int(M**0.5)+1):
    if M%i==0:
        l += [M//i]
        if M//i != i:
            l += [i]
l.sort()

for i in l:
    if i >= N:
        print(M//i)
        break

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

int main() {
  int N;
  cin >> N;
  int X[N];
  int MAX = 0;
  unsigned int MIN = -1;
  int SUM = 0;
  int i;
  int n;
  
  for (i = 1; i <= N; i++){
    cin >> X[i];
    
    if (MAX < X[i]) MAX = X[i];
  }
  
  for (i = 0; i <= MAX; i++){ 
    for (n = 1; n <= N; n++){
      SUM = SUM + ((i - X[n]) * (i - X[n]));
      
    }
    
    if (MIN > SUM) MIN = SUM;
    SUM = 0;
  }
  cout << MIN << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define less Less
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define KK 500
#define MXN 200005
vector<int> v[100005];
int dp[100005][20];
int ans;
void dfs(int x,int f){
    for(auto it:v[x]){
        if(it!=f){
            dfs(it,x);
            for(int i = 0;i<20;i++){
                dp[x][i]+=dp[it][i];
            }
        }    
    }
    int st=0;
    for(int  i = 19;i>=0;i--){
        if(dp[x][i]>=2){
            st=i;
            break;
        }
    }
    for(int i = st;;i++){
        if(dp[x][i]==0){
            dp[x][i]=1;
            ans=max(ans,i);
            for(int j=i-1;j>=0;j--)
                dp[x][j]=0;
            return;
        }
    }
}
int main(){
    int n;
    scanf("%d",&n);
    for(int i = 1;i<n;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        v[x].pb(y);
        v[y].pb(x);
    }
    dfs(1,0);
    printf("%d\n",ans);
}

Measured memory_bytes: 19200
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    char ar[1000];
    ar['a']=0;ar['b']=0;ar['c']=0;ar['d']=0;ar['e']=0;ar['f']=0;ar['g']=0;ar['h']=0;ar['i']=0;
    ar['j']=0;ar['k']=0;ar['l']=0;ar['m']=0;ar['n']=0;ar['o']=0;ar['p']=0;ar['q']=0;ar['r']=0;
    ar['s']=0;ar['t']=0;ar['u']=0;ar['v']=0;ar['w']=0;ar['x']=0;ar['y']=0;ar['z']=0;

    string a;
    cin>>a;

    int length,i;
    length=a.length();

    for(i=0;i<length;i++)
    {
       ar[a[i]]++;
    }

if((ar['a']==0||ar['a']%2==0)&&(ar['b']==0||ar['b']%2==0)&&(ar['c']==0||ar['c']%2==0)&&(ar['d']==0||ar['d']%2==0)
&&(ar['e']==0||ar['e']%2==0)&&(ar['f']==0||ar['f']%2==0)&&(ar['g']==0||ar['g']%2==0)&&(ar['h']==0||ar['h']%2==0)
&&(ar['i']==0||ar['i']%2==0)&&(ar['j']==0||ar['j']%2==0)&&(ar['k']==0||ar['k']%2==0)&&(ar['l']==0||ar['l']%2==0)
&&(ar['m']==0||ar['m']%2==0)&&(ar['n']==0||ar['n']%2==0)&&(ar['o']==0||ar['o']%2==0)&&(ar['p']==0||ar['p']%2==0)
&&(ar['q']==0||ar['q']%2==0)&&(ar['r']==0||ar['r']%2==0)&&(ar['s']==0||ar['s']%2==0)&&(ar['t']==0||ar['t']%2==0)
&&(ar['u']==0||ar['u']%2==0)&&(ar['v']==0||ar['v']%2==0)&&(ar['w']==0||ar['w']%2==0)&&(ar['x']==0||ar['x']%2==0)
&&(ar['y']==0||ar['y']%2==0)&&(ar['z']==0||ar['z']%2==0))
{
    cout<<"Yes"<<endl;
}
else
{
    cout<<"No"<<endl;
}






return 0;
}


Measured memory_bytes: 3564
#include<iostream>
#include<string>

using namespace std;

int main()
{
    int N;
    string s;
    cin >> N;
    cin >> s;
    if(N % 2 != 0)
    {
        cout << "No" << endl;
    }
    else
    {
        string t = s.substr(0, N / 2);
        string g = s.substr(N/2, N/2);
        if(t == g)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
}

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

const int N = 1e2 + 5;
int n, b[N], a[N], vis[N];


int main(){
#ifdef LOCAL
    freopen("./input.txt", "r", stdin);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    
    cin>>n;
    for (int i = 1; i <= n; i++)cin>>b[i];
    
    int cnt = 0;
    int last;
    for (int i = 1; i <= n; i++){
        int used = 0;
        bool found = false;
        for (int j = 1; j <= n; j++){
            if(!vis[j]){
                if(b[j] == j-used)last = j, found = true;
            }else used++;
        }
        if(found){
            a[n-cnt] = last;
            cnt++;
            vis[last] = 1;
        }else{
            cout<<-1<<endl;
            return 0;
        }
    }
    for (int i = 1; i <= n; i++)cout<<b[a[i]]<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <string>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <functional>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <list>
#include <tuple>
#include <bitset>
#include <ciso646>
#include <cassert>

using namespace std;

#define int long long
#define double long double

typedef pair<int, int> P;
typedef tuple<int, int, int> T;

template<class T> string tostr(T x) { stringstream o; o << x; return o.str(); }
template<class T> T sqr(T x) { return x*x; }
template<class T> T mypow(T x, int n) { T r = 1; while (n > 0) { if (n & 1)r = r*x; x = x*x; n >>= 1; }return r; }

int toint(string s) { int v; stringstream i(s); i >> v; return v; }
bool check(int x, int y, int w, int h) { return x >= 0 && y >= 0 && w > x && h > y; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

#define REP(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	REP(i,0,n)
#define PER(i,a,b)	for(int (i) = (a-1);i >= (b);(i)--)
#define per(i,n)	PER(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define dump(val) 	cerr << #val " = " << val << endl;
#define dum(val)	cerr << #val " = " << val;
#define FILL(a,v)	fill(a,a+sizeof(a)/sizeof(*a),v)

const int dx[8] = { +1,+0,-1,+0,+1,+1,-1,-1 };
const int dy[8] = { +0,-1,+0,+1,-1,+1,-1,+1 };
const int mod = 1e9 + 7;
const int INF = 1e17 + 9;

signed main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int n, m;
	cin >> n >> m;

	int ans = 0;
	m = m / 2;
	
	if (n >= m) {
		cout << m << endl;
	}
	else {
		cout << n + (m - n) / 2 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
#define INF 1000000007
#define LINF 1000000000000000007
 
typedef long long i64;
typedef pair<i64,i64> P;


int a,b,c;

int main(){
	cin >> a >> b>>c;
	
	cout << min(a,b)+min(max(a,b),c) << endl;
	
	return 0;
}

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

int main()
{
	int N, M;
	cin >> N >> M;
	int H[N+1], A[M+1], B[M+1];
	vector<int> R[N+1];
	
	for(int i=1; i<=N; i++)
	{
		cin >> H[i];
	}
	
	for(int i=1; i<=M; i++)
	{
		cin >> A[i] >> B[i];
	}
	
	for(int i=1; i<=M; i++)
	{
		R[A[i]].push_back(B[i]);
		R[B[i]].push_back(A[i]);
	}
	
	int G = 0;
	for(int i=1; i<=N; i++)
	{
		G = G + 1;
		for(int j=0; j<R[i].size(); j++)
		{
			if(H[i] <= H[R[i][j]])
			{
				G = G - 1;
				break;
			}
		}
		
	}
	
	cout << G;
	
	//for(int i=0; i<=N; i++)
	//{
	//	cout << R[i].size();
	//}
	
	//for(int i=1; i<=N; i++)
	//{
	//	for(int j=0; j<R[i].size(); j++)
	//	{
	//		cout << i << " " << R[i][j];
	//	}
	//	cout << endl;
	//}
	
	return 0;

}

Measured memory_bytes: 9476
N = int(input())
# = str(input())
# = map(int, input().split())
A = list(map(int, input().split()))
# = [int(input()) for i in range(N)]
# = [list(map(int, input().split())) for i in range(N)]
wallet = 1000

for i in range(N-1):
    if A[i] < A[i+1]:
        chicket, money = divmod(wallet, A[i])
        wallet = money
        wallet += chicket*A[i+1]

print(wallet)


Measured memory_bytes: 8824
package main

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

const mod int = 1e9 + 7

func main() {
	sc.Split(bufio.ScanWords)

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

	ans := 0
	for i := uint(0); i <= 60; i++ {
		k := 0
		for j := 0; j < n; j++ {
			if (a[j]>>i)&1 == 0 {
				k++
			}
		}

		x := (k * (n - k) % mod) * ((1 << i) % mod)
		ans = (ans + x) % mod
	}

	fmt.Println(ans)
}

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 6912
# coding: utf-8
# Your code here!
k=int(input())
if k==1:
    print(1)
elif k%2==0 or k%5==0:
    print(-1)
else:
    a=[7%k for i in range(k+1)]
    for i in range(1,k+1):
        a[i]=(a[i-1]*10+7)%k
    for i in a:
        if i==0:
            print(a.index(i)+1)
            break


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

using std::cerr;
using std::endl;

inline int get_val(int x, int y) {
  return x / y + !!(x % y);
}

inline int check(int A, int B, int K, int M) {
  int seg = M / (K + 1);
  long long a = 1ll * seg * K, b = seg;
  if (M % (K + 1))
    a += M - seg * (K + 1);
  if (a > A || b > B)
    return 0;
  a = A - a, b = B - b;
  if (a * K >= b)
    return 1;
  return 0;
}

inline char get(int K, int M, int W, int x) {
  if (x <= M) {
    if (!(x % (K + 1)))
      return 'B';
    return 'A';
  } else {
    x -= W;
    if (!(x % (K + 1)))
      return 'A';
    return 'B';
  }
}

inline void solve() {
  int A, B, C, D, K;
  std::cin >> A >> B >> C >> D;
  K = std::max(get_val(A, B + 1), get_val(B, A + 1));
  int l = 0, r = A + B, pos = -1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(A, B, K, mid))
      pos = mid, l = mid + 1;
    else
      r = mid - 1;
  }
  ++pos;
  int seg = pos / (K + 1), a = A - seg * K, b = B - seg;
  if (pos % (K + 1)) a -= pos - seg * (K + 1);
  int tmp = pos + 1 - a * K + b;
  for (int i = C; i <= D; ++i)
    std::cout << get(K, pos, tmp, i);
  std::cout << '\n';
}

int main() {
  // freopen("data", "r", stdin);
  std::ios::sync_with_stdio(0);
  std::cin.tie(0);
  int T; std::cin >> T;
  while (T--) solve();
  return 0;
}


Measured memory_bytes: 384
package main

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

var sc = bufio.NewScanner(os.Stdin)

func next() int {
	sc.Scan()

	val, err := strconv.Atoi(sc.Text())
	if err != nil {
		fmt.Println(err)
	}
	return val
}

func scanSlice(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = next()
	}
	return a
}

func main() {
	sc.Split(bufio.ScanWords)

	vals := scanSlice(3)
	L, R, d := vals[0], vals[1], vals[2]
	count := 0

	for i := L; i < R+1; i++ {
		if i%d == 0 {
			count++
		}
	}
	fmt.Println(count)
}

Measured memory_bytes: 1768
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(x) (x).begin(), (x).end()
const ld pi = 3.14159265358979323846;
 
int main() {
    ll n,x,t;
    cin>>n>>x>>t;
    if (n%x==0){
        cout<<(n/x)*t<<endl;
    }
    else{
        cout<<(n/x+1)*t<<endl;
    }
}

Measured memory_bytes: 3560
import numpy as np
i8 = np.int64


def solve(N, X, M):
    memo_val = np.zeros(M, i8)
    memo_i = np.zeros(M, i8)
    ret = 0
    a = X
    for i in range(1, N):
        ret += a
        if memo_i[a] > 0:
            u = (N - memo_i[a]) // (i - memo_i[a])
            v = (N - memo_i[a]) % (i - memo_i[a])
            ret = u * (ret - memo_val[a])
            nokori = v + memo_i[a]
            for j in range(M):
                if memo_i[j] == nokori:
                    ret += memo_val[j]
            return ret
        memo_i[a] = i
        memo_val[a] = ret
        a = a ** 2 % M
    ret += a
    return ret

def main():
    f = open(0)
    N, X, M = [int(x) for x in f.readline().split()]
    ans = solve(N, X, M)
    print(ans)

main()

Measured memory_bytes: 28260
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
			Scanner sc = new Scanner(System.in);
			int N = sc.nextInt();
			long[] lucas =new long[87] ;
			lucas[0]=2;lucas[1]=1;
			for(int i=2;i<=86;i++) 
				lucas[i]=lucas[i-2] + lucas[i-1];
			System.out.println(lucas[N]);
	}

}


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

int main()
{
    int x, a, b, des1, des2;
    cin  >> x >> a >> b;
    des1 = x - a;
    des2 = x - b;
    if(des1 < 0)
        des1 = des1 * -1;
    if(des2 < 0)
        des2 = des2 * -1;
    if(des1 < des2)
        cout << "A" << endl;
    if(des1 > des2)
        cout << "B" << endl;


    return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        char paste[][] = new char[H+2][W+2];
        String line = "";
        for(int i = 0; i < H + 2; i++){
            for(int j = 0; j < W + 2; j++){
                paste[i][j] = ('#'); 
            }
        }
        for(int i = 1; i < H + 1; i++){
            line = sc.next();
            for(int j = 1; j < W + 1; j++){
                paste[i][j] = line.charAt(j-1); 
            }
        }
        for(int i = 0; i < H + 2; i++){
            for(int j = 0; j < W + 2; j++){
                System.out.print(paste[i][j]);
            }
            System.out.println("");
        }
	}
}

Measured memory_bytes: 24276
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;
	double EPS=1e-12;

	int n, m, p;
	int[] xs, ks;
	int[][] ls;
	int[] ys;
	int[] js1, js2, ds;

	void run(){
		n=sc.nextInt();
		m=sc.nextInt();
		p=sc.nextInt();
		xs=new int[n];
		ks=new int[n];
		ls=new int[n][];
		for(int j=0; j<n; j++){
			xs[j]=sc.nextInt();
			ks[j]=sc.nextInt();
			ls[j]=new int[ks[j]];
			for(int i=0; i<ks[j]; i++){
				ls[j][i]=sc.nextInt()-1;
			}
		}
		ys=new int[m];
		for(int i=0; i<m; i++){
			ys[i]=sc.nextInt();
		}
		js1=new int[p];
		js2=new int[p];
		ds=new int[p];
		for(int i=0; i<p; i++){
			js1[i]=sc.nextInt()-1;
			js2[i]=sc.nextInt()-1;
			ds[i]=sc.nextInt();
		}
		solve();
	}

	void solve(){
		int sum=0;
		V source=new V(), sink=new V();
		V[] cs=new V[n];
		V[] ts=new V[m];
		V[] ps=new V[p];
		for(int i=0; i<n; i++){
			cs[i]=new V();
		}
		for(int i=0; i<m; i++){
			ts[i]=new V();
		}
		for(int i=0; i<p; i++){
			ps[i]=new V();
		}
		for(int j=0; j<n; j++){
			sum+=xs[j];
			source.add(cs[j], xs[j]);
			for(int i=0; i<ks[j]; i++){
				cs[j].add(ts[ls[j][i]], INF);
			}
		}
		boolean[] used=new boolean[m];
		for(int i=0; i<p; i++){
			used[js1[i]]=used[js2[i]]=true;
			// ts[js1[i]].add(ps[i], INF);
			// ts[js2[i]].add(ps[i], INF);
			ts[js1[i]].add(ps[i], ys[js1[i]]);
			ts[js2[i]].add(ps[i], ys[js2[i]]);
			// debug(ys[js1[i]], ys[js2[i]]);
			ps[i].add(sink, ds[i]);
		}
		for(int i=0; i<m; i++){
			if(!used[i]){
				ts[i].add(sink, ys[i]);
			}
		}
		ArrayList<V> list=new ArrayList<V>();
		list.addAll(asList(source, sink));
		list.addAll(asList(cs));
		list.addAll(asList(ts));
		list.addAll(asList(ps));
//		debug(sum);
//		debug(fordFulkerson(list.toArray(new V[0]), source, sink));
		println(sum-fordFulkerson(list.toArray(new V[0]), source, sink)+"");
	}

	int fordFulkerson(V[] vs, V s, V t){
		for(int flow=0;;){
			for(V v : vs)
				v.used=false;
			int f=dfs(s, t, INF);
			if(f==0)
				return flow;
			flow+=f;
		}
	}

	int dfs(V v, V t, int f){
		if(v==t)
			return f;
		v.used=true;
		for(E e : v.es){
			if(!e.to.used&&e.cap>0){
				int d=dfs(e.to, t, min(f, e.cap));
				if(d>0){
					e.cap-=d;
					e.rev.cap+=d;
					return d;
				}
			}
		}
		return 0;
	}

	class V{
		ArrayList<E> es=new ArrayList<E>();
		boolean used;

		void add(V to, int cap){
			E e=new E(to, cap), rev=new E(this, 0);
			e.rev=rev;
			rev.rev=e;
			es.add(e);
			to.es.add(rev);
		}
	}

	class E{
		V to;
		E rev;
		int cap;

		E(V to, int cap){
			this.to=to;
			this.cap=cap;
		}
	}

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 13000
# ALDS1_5_C
import math

n = int(input())
def koch(d, p1, p2):
    if d == 0:
        return
    s = [(2 * p1[0] + p2[0]) / 3, (2 * p1[1] + p2[1]) / 3]
    t = [(p1[0] + 2 * p2[0]) / 3, (p1[1] + 2 * p2[1]) / 3]
    u = [(t[0] - s[0]) * 0.5 - (t[1] - s[1]) * 0.866025403 + s[0],
        (t[0] - s[0]) * 0.866025403 + (t[1] - s[1]) * 0.5 + s[1]]

    koch(d-1, p1, s)
    print(*s)
    koch(d-1, s, u)
    print(*u)
    koch(d-1, u, t)
    print(*t)
    koch(d-1, t, p2)

print(0.0, 0.0)
koch(n, [0, 0], [100, 0])
print(100.0, 0.0)


Measured memory_bytes: 5760
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n) 
{ v = vector<T>(n); for (lli i=0; i<n; ++i) cin >> v[i]; }
template<class T, class U> void read_n(vector<pair<T, U>>& v, size_t n)
{ v = vector<pair<T, U>>(n); 
  for (lli i=0; i<n; ++i) cin >> v[i].first >> v[i].second; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n;
lli h[101];
int main() {
  cin >> n;
  for (lli i=0; i<n; ++i) cin >> h[i];
  lli cnt = 0;
  while (true) {
    bool f = false, g = false;
    for (lli i=0; i<n; ++i) {
      if (h[i] > 0) { --h[i]; f = g = true; }
      else if (f) {
	++cnt;
	f = false;
      }
    }
    if (f) ++cnt;
    if (!g) break;
  }
  cout << cnt << endl;
  return 0;
}



Measured memory_bytes: 256
import sys, math

def calcN(x, y, z):
    if(x==y and y == z):
        return 1
    elif(x==y or y==z):
        return 3
    else:
        return 6

def calcf(N):
    f_values = [0] * (N+1)
    root = math.floor(math.sqrt(N) )
    for x in range(1, root+1, 1):

        for y in range(x, root+1, 1):
            sum = x**2+y**2+x*y
            if(sum > N):
                break
            for z in range(y, root+1, 1):
                sum2 = z**2+y*z+z*x+ sum
                if(sum2 > N):
                    break
                else:
                    f_values[sum2] += calcN(x, y, z)
    return f_values

if(__name__ == "__main__"):

    N = int(input().strip())

    f_values = calcf(N)
    for i in range(1, N+1):
        print(f_values[i])


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

using namespace std;

u_int seed = 3;
u_int xor_shift()
{
    seed ^= seed << 1;
    seed ^= seed >> 3;
    seed ^= seed << 10;
    return seed;
}

chrono::system_clock::time_point start_time;
int elapsed()
{
    auto cur = chrono::system_clock::now();
    return chrono::duration_cast<chrono::milliseconds>(cur - start_time).count();
}

// セグ木を使えば二分探索で一点をlog(n)で更新できる これ嘘で，後ろのスコアも変更する必要があるため
// 前からA*とかビームサーチもできそう
// とりあえず焼きなます
// 最初はCを考慮せずに焼きなます(いや，貪欲でいいだろ)
int score = 0;
int d;
vector<int> T, C;
vector<vector<int>> S, last;

// i日目をj番目に
int calc(int i, int to){
    int res = 0;
    int from = T[i];
    res -= S[i][from];
    int l = i == 0 ? -1 : last[i - 1][from];
    for (int j = i; j < d; j++){
        if (last[j][from] != i)
            break;
        res += C[from] * (j - last[j][from]);
        res -= C[from] * (j - l);
    }

    res += S[i][to];
    for (int j = i; j < d; j++){
        if (last[j][to] > i)
            break;
        res += C[to] * (j - last[j][to]);
        res -= C[to] * (j - i);
    }

    return res;
}

void change(int i, int to){
    int from = T[i];
    T[i] = to;
    int l = i == 0 ? -1 : last[i - 1][from];
    for (int j = i; j < d; j++){
        if (last[j][from] != i)
            break;
        last[j][from] = l;
    }

    for (int j = i; j < d; j++){
        if (last[j][to] > i)
            break;
        last[j][to] = i;
    }
}

int calc_overall(){
    int res = 0;
    for (int i = 0; i < d; i++){
        res += S[i][T[i]];
        for (int j = 0; j < 26; j++){
            res -= C[j] * (i - last[i][j]);
        }
    }

    return res;
}


int main(){
    cin >> d;
    start_time = chrono::system_clock::now();
    C.resize(26);
    copy_n(istream_iterator<int>(cin), 26, C.begin());
    S.assign(d, vector<int>(26));
    last.assign(d, vector<int>(26, -1));
    for (auto &s: S)
        copy_n(istream_iterator<int>(cin), 26, s.begin());

    T.resize(d);

    for (int i = 0; i < d; i++){
        // int to = max_element(S[i].begin(), S[i].end()) - S[i].begin();
        int to = xor_shift() % 26;
        T[i] = to;
        for (int j = i; j < d; j++){
            last[j][to] = i;
        }
    }

    auto ans = T;
    score = calc_overall();
    cerr << score << endl;
    int max_score = score;
    const double s_temp = 20000, e_temp = 1;
    const constexpr int L = 5e6;
    double delta = (s_temp - e_temp) / L;
    double temp = s_temp;
    const double sup = pow(2, 32) - 1;

    while (elapsed() < 1950){
        auto i = xor_shift() % d;
        auto to = xor_shift() % 26;
        if (T[i] == to)
            continue;
        auto cost = calc(i, to);
        if (cost > 0 or exp(cost / temp) > xor_shift() / sup){
            change(i, to);
            // cerr << "change: " << i << " " << to << " " << cost << " " << temp << endl;
            score += cost;
        }
        if (score > max_score){
            ans = T;
            max_score = score;
        }
        if (temp > e_temp)
            temp -= delta;
    }

    cerr << temp << endl;
    for (const auto &t: ans)
        cout << t + 1 << endl;

    cerr << max_score << endl;

}

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

using namespace std;
#define _for(i,j,N) for(int i = (j);i < (N);i++)
#define _rep(i,j,N) for(int i = (j);i <= (N);i++)
#define _dec(i,N,j) for(int i = (N-1);i >= (j);i--)
#define _rec(i,N,j) for(int i = (N);i >=(j);i--)
#define ALL(x) x.begin(),x.end()
#define MEM(a,n) memset(a,n,sizeof(a))
#define fst first
#define scd second
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

int get_int(){int x;scanf("%d",&x);return x;}
LL get_ll(){LL x;scanf("%lld",&x);return x;}
double get_db(){double x;scanf("%lf",&x);return x;}

template<typename T> int chmin(T &a,T b){if(a > b){a = b;return 1;}else return 0;}
template<typename T> int chmax(T &a,T b){if(a < b){a = b;return 1;}else return 0;}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v) {_for(i,0,v.size()) os << v[i] << " ";return os;}
template<typename T>
ostream& operator<<(ostream& os,const set<T>& v){for(auto a:v) os << a <<" ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& v){os << v.fst <<" "<<v.scd << " ";return os;}
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const map<T1,T2>& v){for(auto a:v) cout << a << endl;return os;}

static const int dx[8] = { 1,  0, -1,  0,  1, -1,  1, -1};
static const int dy[8] = { 0,  1,  0, -1,  1, -1, -1,  1};
const double pi  = acos(-1.0);
const double eps = 1e-8;
const LL  INF  = 0x3f3f3f3f3f3f3f3f;
const int inf  = 0x3f3f3f3f;
const int mod = 1e9+7;

const int maxn = 1e5+5;

int num[maxn];


map<int,int> num2index;
set<int> pos;

int main()
{
    int N;
    cin >> N;
    _for(i,0,N){
        int k;
        scanf("%d",&k);
        num2index[k] = i;
        num[i] = k;
    }
    sort(num,num+N,greater<int>());

    pos.insert(num2index[num[0]]);
    LL ans = 0;
    _for(i,1,N){
        int k = num[i];
        int index = num2index[k];
        pos.insert(index);
        auto it = pos.lower_bound(index);
        auto it2 = it;
        int w,x,z,y;
        it++;
        if(it != pos.end()){
            z = *it;
            it++;
            if(it != pos.end()){
                y = *it;
            }else{
                y = N;
            }

        }else{
            z = N;
            y = N;

        }

        if(it2  !=  pos.begin()){
            it2--;
            x = *it2;
            if(it2 != pos.begin()){
                it2--;
                w = *it2;
            }else{
                w = -1;
            }

        }else{
            x = -1;
            w = -1;
        }

        //cout << w <<" "<< x <<" "<<z <<" "<<y<<endl;
        ans += ((x-w)*(LL)(z-index) + (y-z)*(LL)(index-x)) * k;
        //cout << ans << endl;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9984
def solve():
    S = input()
    T = input()
    ls = len(S)
    lt = len(T)
    lst = []
    w_lst = []
    if ls < lt:
        return 'UNRESTORABLE'
    if ls == lt:
        for i in range(ls):
            if S[i] == '?': continue
            elif not S[i] == T[i]: return 'UNRESTORABLE'
        return T
    for d in range(ls - lt + 1):
        eq = True
        for i in range(lt):
            if S[i + d] == '?':
                continue
            elif not S[i + d] == T[i]:
                eq = False
                break
        if eq:
            lst.append(d)
    if len(lst) == 0:
        return 'UNRESTORABLE'
    for d in lst:
        w = S[0:d] + T + S[d + lt:]
        for i in range(ls):
            if w[i] == '?':
                w = w[0:i] + 'a' + w[i + 1:]
        w_lst.append(w)
    return min(w_lst)
if __name__ == '__main__':
    print(solve())


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

long MOD=1e9+7;
long MAX=200000;

long sigma(long n){
  return (n*(n+1)/2);
}

int main() {

long N,K;
cin>>N>>K;

//COMinit();
long ans=0;
for(int i=K;i<=N+1;i++){
  long tmp =sigma(N+1)-sigma(N+1-i)-sigma(i)+1;

  tmp %=MOD;
  ans+= tmp;
  ans%=MOD;
}
cout<<ans<<endl;
}


Measured memory_bytes: 3636
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
    var count = 0;
    for(i= 0; i<3; i++){
      if(input[0][i] == 1){
        count += 1;
      }
    }
	//出力
   console.log(count);
}

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

Measured memory_bytes: 7372