akhauriyash/Code-Regression huggingface dataset:
import copy
import queue


def read():
    N = int(input().strip())
    edge = [-1 for _ in range(N+1)]
    for i in range(1, N+1):
        edge[i] = list()
    for _ in range(N-1):
        a, b = list(map(int, input().strip().split()))
        edge[a].append(b)
        edge[b].append(a)
    C = list(map(int, input().strip().split()))
    return N, edge, C


def center_of_tree(N, edge):
    # 端点を削除していく。最後に残ったものが中心。
    n = N
    previous_parent = -1
    e = copy.deepcopy(edge)
    while n > 1:
        for child in range(1, N+1):
            if len(e[child]) == 1:
                parent = e[child][0]
                e[parent].remove(child)
                e[child].remove(parent)
                n -= 1
                previous_parent = parent
    return previous_parent


def write_node_weights(N, parent, edge, C):
    C = list(sorted(C))
    node_weight = [-1 for _ in range(N+1)]
    node_weight[parent] = C.pop()
    q = queue.Queue()
    q.put(parent)
    while len(C) > 0:
        parent = q.get()
        for child in edge[parent]:
            if node_weight[child] == -1:
                node_weight[child] = C.pop()
                q.put(child)
    return node_weight


def sum_of_edge_weights(N, node_weight, edge):
    sum_of_edge_weights = 0
    for a in range(1, N+1):
        for b in edge[a]:
            if a < b:
                sum_of_edge_weights += min(node_weight[a], node_weight[b])
    return sum_of_edge_weights


def solve(N, edge, C):
    center = center_of_tree(N, edge)
    node_weight = write_node_weights(N, center, edge, C)
    edge_weights = sum_of_edge_weights(N, node_weight, edge)
    return edge_weights, node_weight[1:]


if __name__ == '__main__':
    inputs = read()
    edge_weights, node_weight = solve(*inputs)
    print(edge_weights)
    print(' '.join(map(str, node_weight)))


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

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

	int ans = 0;
	for( int i = 0; i < S.size() / 2; i++ ) {
		if( i == S.size() - 1 - i ) continue;
		if( S[i] != S[S.size() - 1 - i] ) ans++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
str = input()
S = []
for i in range(N):
    if str[i] == 'R':
        S.append(0)
    elif str[i] == 'G':
        S.append(1)
    else:
        S.append(2)

ans = 0
for i in range(N):
    left = [0, 0, 0]
    cent = [0, 0, 0]
    right = [0, 0, 0]
    for j in range(N):
        if j < i:
            left[S[j]] += 1
        elif i == j:
            cent[S[j]] += 1
        else:
            right[S[j]] += 1
    for a in range(3):
        for b in range(3):
            for c in range(3):
                if a == b or a == c or b == c:
                    continue
                ans += left[a] * cent[b] * right[c]
    for d in range(N):
        left = i - d
        right = i + d
        if left < 0 or right >= N or S[left] == S[i] or S[left] == S[right] or S[i] == S[right]:
            continue
        ans -= 1
print(ans)


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

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

	const int mod = 100000;
	for(int n, m, s; cin >> n >> m >> s, n;) {
		vector<vector<int> > dp(s + 1, vector<int>(n * n + 1, 0));
		dp[0][0] = 1;
		for(int i = 1; i <= m; ++i) {
			for(int j = s - i; j >= 0; --j) {
				for(int k = 0; k < n * n; ++k) {
					if(dp[j][k] == 0)
						continue;

					dp[j + i][k + 1] += dp[j][k];
					dp[j + i][k + 1] %= mod;
				}
			}
		}

		cout << dp[s][n * n] << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1796
#include<iostream>
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	while(a>0 && c>0){
		c-=b;
		if(c<=0) {
			cout<<"Yes";
		}
		else{
			a-=d;	
			if(a<=0) cout<<"No";
		}
	}
	return 0;
}

Measured memory_bytes: 3596
def main():
    s = raw_input().strip()
    t = raw_input().strip()

    ans = []

    def normal():
        m = '?' * len(t)
        pos = s.rfind(m)
        if pos == -1:
            return 
        
        mod = s[:pos] + t + s[pos + len(t): ]
        mod = mod.replace('?', 'a')
        ans.append(mod)

    def solve(pos):

        for i in xrange(len(s)):
            if s[i] == t[pos]:
                ss = (i - pos)
                ee = i + (len(t) - 1 - pos)
                if ss < 0 or ee >= len(s): 
                    continue

                tmp = s[ss: ee+1]
                ok = True
                for j in xrange(len(tmp)):
                    if tmp[j] == '?': 
                        continue 
                    if tmp[j] != t[j]: 
                        ok = False
                        break
                if ok:
                    mod = s[:ss] + t + s[ee+1: ]
                    mod = mod.replace('?', 'a')
                    ans.append(mod)

    for i in xrange(len(t)):
        solve(i)

    normal()
    if ans:
        return min(ans)
    return "UNRESTORABLE"

print main()




Measured memory_bytes: 29420
/*
　　　　　　 ＿＿
　　　　　／＞　　 フ
　　　　　|   _　 _l  
　 　　　／` ミ＿x ノ   Zzz..
　　 　 /　 　 　 |   コード見ちゃだめ！！
　　　 /　 ヽ　　  ﾉ
　 　 │　　|　|  |   
　／￣|　　 |　|  |
　| (￣ヽ＿_ヽ_)_ _)
　＼二つ
*/

#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) reverse((a).begin(),(a).end())
#define REP(i, n) for(int i = 0; i < n; i++)
const int MOD = 1e9+7;
typedef long long ll;

int main() {
    int n;
    cin>>n;
    vector<int>a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    int count=1;
    for(int i=0;i<n;i++){
        if(a[i]==count) count++;
    }
    if(count==1) cout<<"-1"<<endl;
    else cout<<n-count+1<<endl;
    
    
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
int main(){
    int n,chukei;
    cin>>n;
    int a[n];
    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    for(int i=0;i<n;++i){
        cout<<a[i];
        if(i!=n-1){
            cout<<" ";
        }
    }
        cout<<endl;
    for(int i=1;i<n;++i){
        for(int j=i;j>=0;--j){
            if(a[j]<a[j-1]){
                chukei=a[j-1];
                a[j-1]=a[j];
                a[j]=chukei;
            }
        }
        for(int i=0;i<n;++i){
            cout<<a[i];
            if(i!=n-1){
                cout<<" ";
            }
        }
        cout<<endl;
    }
    return 0;
}



Measured memory_bytes: 3100
import java.util.Scanner;

class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        //sc.nextLine();
        //sc.close();
        String[] n  = str.split(" ");
        int a = Integer.parseInt(n[0]);
        int b = Integer.parseInt(n[1]);
        int fee = 0;
        if( a <= 5 ){
            fee = 0;
        } else if ( a >= 6 && a <= 12){
            fee = b / 2;
        } else {
            fee = b;
        }
        System.out.println(fee);
    } 
}  

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

using ll = long long;
using ull = unsigned long long;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int s,w;cin >> s >> w;
    if(w >= s)cout << "unsafe" << endl;
    else cout << "safe" << endl;
    return 0;
}

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

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;






void one_case() {
    int n;
    cin >> n;
    cout << 24 + (24 - n) << "\n";
}


int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);


    int t = 1;
//    cin >> t;
    while (t--) {
        one_case();
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//debug
#ifdef grief
#define debug(...) do{\
	fprintf(stderr , "%s - %d : (%s) = " , __PRETTY_FUNCTION__ , __LINE__ , #__VA_ARGS__ );\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> 				void _DO(I&&x){	cerr<<x<<endl;	}
template<typename I,typename...T>	void _DO(I&&x,T&&...tail){	cerr<<x<<" , ";	_DO(tail...);	}
template<typename _a,typename _b> 	ostream& operator << (ostream &_s,const pair<_a,_b> &_p)
{	return _s<<'('<<_p.first<<','<<_p.second<<')';	}
#define IOS
#else
#define debug(...)
#define IOS do{ios_base::sync_with_stdio(0); cin.tie(0);}while(0);
#endif
//type
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef priority_queue<pll,vector<pll>,greater<pll> > heap;
//macro
#define SZ(x) ((ll)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define stp setprecision(30)<<fixed
const ll INF=0x3f3f3f3f3f3f3f3f;
const int NF=0x3f3f3f3f;
const ll MAX=1e5+5,Mlg=__lg(MAX)+2;
const ll MOD=1e9+7;
// ready~ go!
// let's coding and have fun!
// I can't solve this problem
int n,x;
int main(){
	IOS
	cin>>n>>x;
	int mi=NF;
	for(int i=0;i<n;i++){
		int m;	cin>>m;
		mi=min(mi,m);
		x-=m;
	}
	cout<<(n+x/mi)<< '\n';
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
import itertools
#sys.setrecursionlimit(150000)

def chkA(A, Q, a, b, c, d):
    ret=0
    for i in range(Q):
        ret += d[i] if A[b[i]-1] - A[a[i]-1] == c[i] else 0
    return ret
            

def solve(N: int, M: int, Q: int, a: "List[int]", b: "List[int]", c: "List[int]", d: "List[int]"):
    P=[i+1 for i in range(M+N-1)]
    B=[0]*N
    ans=0
    for A in itertools.combinations(P, N):
        for i in range(N):
            B[i]=A[i]-i
        ans = max(ans, chkA(B, Q, a, b, c, d))
    print(ans)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    Q = int(next(tokens))  # type: int
    a = [int()] * (Q)  # type: "List[int]"
    b = [int()] * (Q)  # type: "List[int]"
    c = [int()] * (Q)  # type: "List[int]"
    d = [int()] * (Q)  # type: "List[int]"
    for i in range(Q):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
        c[i] = int(next(tokens))
        d[i] = int(next(tokens))
    solve(N, M, Q, a, b, c, d)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9300
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] h = new int[n];
        for(int i = 0 ; i < n ; i++ ){
            h[i] = sc.nextInt();
        }
        int s = 0 ;
        for(int i = 0 ; i < n ; i++ ){
            boolean ip = true;
            for(int j = 0 ; j < i && ip == true ; j++ ){
                if(h[i] < h[j]){
                    ip = false;
                }
            }
            if(ip == true){
                s++;
            }
        }
        System.out.println(s);
        sc.close();
    }
}

Measured memory_bytes: 35592
#include<bits/stdc++.h>
using namespace std;
int main() {
	string a;
	string b;
	cin >> a >> b;
	a = a + a;
	int n,m;
	m = b.length();
	n = a.length();
	int ans=0;
	for (int i = 0;i < n;i++) {
		if (b[0] == a[i]) {
			for (int j = 0;j < m;j++) {
				if (b[j] != a[i + j])break;
				if (j == m - 1) { ans = 1;break; }
			}
		}
	}
	if (ans == 1) { cout << "Yes" << endl; }
	else { cout << "No" << endl; }
	return 0;
}


Measured memory_bytes: 3212
uses math;
const fi='CAITUI2.INP';
      fo='CAITUI2.OUT';
      maxn=100;
      maxj=trunc(1e5);
      oo=trunc(1e9)+7;

var n,mw:longint;
    w,v:array[1..maxn] of longint;

    f:array[0..maxn,0..maxj] of longint;
//============================
procedure doc;
var i:longint;
begin
  readln(n,mw);

  for i:=1 to n do readln(w[i],v[i]);
end;
//============================
procedure xuli;
var i,j:longint;
begin

  for i:=0 to n do
    for j:=0 to n*1000 do f[i,j]:=oo;

  f[0,0]:=0;

  for i:=0 to n-1 do
    for j:=0 to n*1000 do
      if f[i,j]<>oo then
        begin

          //if f[i,j]+w[i+1]>mw then

          f[i+1,j]:=min(f[i+1,j],f[i,j]);

          //writeln(i,' ',j,' ',f[i,j],' ',i+1,' ',f[i+1,j]);

          if f[i,j]+w[i+1]<=mw then
            f[i+1,j+v[i+1]]:=min(f[i+1,j+v[i+1]],f[i,j]+w[i+1]);

        end;

  for j:=n*1000 downto 1 do
    if f[n,j]<=mw then break;

  {for i:=0 to n do
    for j:=0 to n+1000 do
      writeln(i,' ',j,' ',f[i,j]);}

  write(j);
end;
//============================
BEGIN
  //assign(input,fi); reset(input);
  //assign(output,fo); rewrite(output);
  doc;
  xuli;
  //close(input); close(output);
END.


Measured memory_bytes: 39680
#include<iostream>
using namespace std;
int main(){
int N, H1, H2, H3,i,flg,max,min;
cin >> N;
if(N ==1) cout << "Yes" << endl;
if(N==2){
  cin >> H1 >> H2;
  if((H1 - H2) <= 1) cout << "Yes" << endl;
  else cout << "No" << endl;
}
if(N > 2){
  cin >> H1;
  if(H1 > 0) H1--;
  flg = 0;
  for(i=0;i<(N-1);i++){
    cin >> H2;
    if(H1 > H2) flg = 1;
    if((H2 - H1) > 0) H2--;
    H1 = H2;
  }
  if(flg == 0) cout << "Yes" << endl;
  if(flg == 1) cout << "No" << endl;
}
return 0;
}

Measured memory_bytes: 256
'use strict'
function otoshidama(stdin) {
  const inputs = stdin.split(' ')
  const n = inputs[0]
  const y = inputs[1]
  for (let i = 0;i <= n;i++) {
    const remain = y - 10000 * i
    if (remain === 0 && n === i) {
      return console.log(n, 0, 0)
    } else if (remain < 0) {
      break
    }
    for (let j = 0;j <= n - i;j++) {
      const sen = n - i - j
      const result = remain - 5000 * j - 1000 * sen
      if (result === 0) {
        return console.log(i, j, sen)
      } else if (result < 1000) {
        break
      }
    }
  }
  return console.log(-1, -1, -1)
}
otoshidama(require('fs').readFileSync(0, 'utf8'))


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

int main(){
    string s;
    cin >> s;
    for(int i = 0; i < 4; i++) cout << s[i];
    cout << " ";
    for(int i = 4; i < s.size(); i++) cout << s[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<set>
#include<ctime>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
inline void write(long long a){
	if(a>=10)write(a/10);
	putchar('0'+a%10);
}
inline void writeln(long long a){
	write(a); puts("");
}
inline long long read()//不管是正负数，都可以 
{
	long long x = 0; char ch = getchar(); bool positive = 1;
	for (; !isdigit(ch); ch = getchar())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = getchar())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
long long n,a,b,c,d;
int main(){
	n=read(); n--; a=read(); b=read(); c=read(); d=read();
	for(long long i=0;i<=n;i++){
		if(a+d*i-c*(n-i)>=b&&a+c*i-d*(n-i)<=b){
			puts("YES"); return 0;
		}
	}
	puts("NO"); return 0;
}

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

int main(){
  long A, B, count=0;
  cin >> A >> B;
  for(long i=A; i<=B; i++){
    if(i/10000==i%10 && (i/1000)%10==(i/10)%10) count++;
  }
  cout << count << endl;
  return 0;
}

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

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;

template<class T> using v2d = vector <vector <T> >;
template<class T> bool uin(T &a, T b)
{
    return a > b ? (a = b, true) : false;
}
template<class T> bool uax(T &a, T b)
{
    return a < b ? (a = b, true) : false;
}

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int maxN = 2e5 + 10;
const ll inf = 1e18;

int n;
ll k;
vector <ll> pos, neg;
ll zeros = 0;

ll cal(ll lim)
{
    //Count number of pairs which have product less than or equal to lim
    if (lim > 0)
    {
        ll res = 0;
        //positive * positive
        int l = 0, r = pos.size() - 1;
        while (l < r)
        {
            if (pos[l] * pos[r] <= lim)
            {
                res += r - l;
                ++l;
            }
            else
            {
                --r;
            }
        }
        //zero
        res += zeros * (n - zeros) + zeros * (zeros - 1) / 2;
        //negative * negative
        l = 0, r = neg.size() - 1;
        while (l < r)
        {
            if (neg[l] * neg[r] <= lim)
            {
                res += r - l;
                --r;
            }
            else
            {
                ++l;
            }
        }
        //positive * negative
        res += (ll)pos.size() * neg.size();
        return res;
    }
    else
    {
        ll res = 0;
        //positive * negative
        int l = 0, r = 0;
        while (l < (int)neg.size() && r < (int)pos.size())
        {
            if (neg[l] * pos[r] <= lim)
            {
                res += pos.size() - r;
                ++l;
            }
            else
            {
                ++r;
            }
        }
        if (lim == 0)
        {
            //zero
            res += zeros * (n - zeros) + zeros * (zeros - 1) / 2;
        }
        return res;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> k;
    for1(i, n)
    {
        ll a;
        cin >> a;
        if (a == 0)
        {
            ++zeros;
        }
        else if (a < 0)
        {
            neg.eb(a);
        }
        else
        {
            pos.eb(a);
        }
    }
    sort(all(pos));
    sort(all(neg));
    ll l = -inf, r = inf;
    //binary searck the maximum x which number of pairs smaller or equal than x to be strictly smaller tham k
    while (r - l > 1)
    {
        ll mid = (l + r) / 2;
        if (cal(mid) < k)
        {
            l = mid;
        }
        else
        {
            r = mid;
        }
    }
    cout << l + 1;
    return 0;
}


Measured memory_bytes: 2420
function Main(input) {
  i = input.trim();
  var weather = ['Sunny', 'Cloudy', 'Rainy'];
  var n = weather.indexOf(i);
  if(n == 2) {
    n = 0;
  } else {
    n++;
  }
  console.log(weather[n]);

}
Main(require('fs').readFileSync('/dev/stdin', 'utf-8'));


Measured memory_bytes: 7372
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int n; cin >> n;
    map<string, int> m;
    int M = 0;
    rep(i,n) {
        string str; cin >> str;
        ++m[str];
        M = max(m[str], M);
    }
    cout << endl;
    for (auto itr = m.begin(); itr != m.end(); itr++)
    {
        if (itr->second == M) {
            cout << itr->first << endl;
        }
    }
    return 0;
}

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

int dp[100010];
const int INF = 1 << 30;
int h[100010];

int main(){
    int N=0;
    cin >>N;
    for(int i=0; i<N; ++i){
        cin >> h[i];
    }

    for(int i=0; i<100010; ++i){
        dp[i] = INF;
    }

    dp[0] = 0;

    for(int i=1; i<N; ++i){
        if(dp[i] > dp[i-1]+ abs(h[i]-h[i-1])){
            dp[i] = dp[i-1] + abs(h[i]-h[i-1]);
        }
        if(i>1){
            if(dp[i] > dp[i-2] + abs(h[i] - h[i-2])){
                dp[i] = dp[i-2] + abs(h[i] - h[i-2]);
            }
        }
    }

    cout << dp[N-1] << endl;

    return 0;
}

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


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

  int ans
    = c - ( a - b ) > 0
    ? c - ( a - b )
    : 0 ;
  cout << ans << endl ;
 
  return 0 ;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include<random>
#include<ctime>
#include<cstdlib>
#include<complex>
#include<fstream>
using namespace std;

int main(){

  int n, a[200], cnt=0;
  cin >> n;
  for(int i=0; i<n; i++){
    cin >> a[i];
  }

  while(n>0){
    for(int i=0; i<n; i++){
      if(a[i]%2!=0){
        cout << cnt << endl;
        return 0;
      }
      a[i]/=2;
    }
    cnt++;
  }

  return 0;
}

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

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using mii = map<int, int>;
using msi = map<string, int>;
using pii = pair<int, int>;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << std::fixed << std::setprecision(10);
    
    int n; cin >> n;
    cout << n * n * n << endl;
    

    return 0;
}


Measured memory_bytes: 3160
#include<stdio.h>

int main(){ int i, aa, bb, cc, dd, ee, count[4][3][10];
	for (aa=0; aa<4; aa++) for (bb=0; bb<3; bb++) for (cc=0; cc<10; cc++) count[aa][bb][cc] = 0;
	scanf ("%d", &aa);
	for (i=0; i<aa; i++) {
		scanf ("%d %d %d %d", &bb, &cc, &dd, &ee);
		count[bb-1][cc-1][dd-1] += ee;
		if (count[bb-1][cc-1][dd-1] < 0) count[bb-1][cc-1][dd-1] = 0;
		if (count[bb-1][cc-1][dd-1] > 9) count[bb-1][cc-1][dd-1] = 9;
	}
	for (aa=0; aa<4; aa++) {
		for (bb=0; bb<3; bb++) {
			for (cc=0; cc<10; cc++) printf (" %d", count[aa][bb][cc]);
			printf ("\n");
		}
		if ( aa != 3) printf ("####################\n");
	}
	return 0;
}

Measured memory_bytes: 612
// JOI 2012-2013 予選2
#include<iostream>
#include<string>

int N;
std::string shop;
std::string s[100];
int ans;

int main()
{
	std::cin >> N >> shop;
	for( int i = 0; i != N; ++i )
	{
		std::cin >> s[i];

		std::string::size_type p;
		while( ( p = s[i].find( shop[0] ) ) != std::string::npos )
		{
			for( int j = 0; j <= s[i].size(); ++j )
			{
				bool f = true;

				int c = 0;
				for( int k = p; k < s[i].size() && c < shop.size(); k += j + 1 )
					f &= s[i][k] == shop[c++];

				if( f && c == shop.size() )
				{
					++ans;

					goto end;
				}
			}

			s[i] = s[i].substr( p + 1 );
		}

end:;
	}

	std::cout << ans << std::endl;

	return 0;
}

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

int main(){
    vector<int> A(3);
    for(int i=0; i<3; i++){
        cin >> A[i];
    }
    sort(A.begin(), A.end());
    if(A[0] == A[1]){
        if(A[2] != A[1]){
            cout << "Yes" << endl;
            return 0;
        }
    }else if(A[1] == A[2]){
        if(A[0] != A[1]){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include <string.h>
using namespace std;
int bd[3][3];
int a[3], b[3];
int main() {
	for (int i = 0; i < 9; i++) {
		cin >> bd[i / 3][i % 3];
	}
	for (int i = 0; i < 3; i++) {
		b[i] = bd[0][i];
	}
	a[1] = bd[1][0] - b[0];
	a[2] = bd[2][0] - b[0];
	for (int i = 0; i < 9; i++) {
		if (a[i / 3] + b[i % 3] != bd[i / 3][i % 3]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e9;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200005;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<tuple<string,ll,ll>> res;
    ll n;
    cin >> n;
    string s;
    ll p;
    rep(i,n){
        cin >> s >> p;
        res.push_back(make_tuple(s,-p,i+1));
    }
    SORT(res);
    rep(i,n){
        ll a;
        tie(s,p,a) = res[i];
        PRINT(a);
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(), (c).end());
const long long MOD = 1e9 + 7;
typedef long long ll;

int main(){
	int N, K;
	cin >> N >> K;
	int ans = 1;
	if(N % K == 0)ans = 0;
	cout << ans << endl;
}

Measured memory_bytes: 256
fun main() {
    val (n, k) = readLine()!!.split(' ').let { it[0].toInt() to it[1].toLong() }
    val a = readLine()!!.split(' ').map { it.toInt() - 1 }
    val b = IntArray(n) { -1 }
    b[0] = 0

    var cur = 0
    var flag = false
    var x = k

    while (x > 0) {
        x--
        val next = a[cur]

        if (flag) {
            cur = next
            continue
        }

        if (b[next] == -1) {
            b[next] = b[cur] + 1
            cur = next
            continue
        }

        flag = true
        x %= (b[cur] + 1 - b[next])
        cur = next
    }

    println(cur + 1)
}


Measured memory_bytes: 64564
#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)

//cerrはコメントアウトしなくても通る

int m,a,r,c,h;
ll k[5];

int main(){
    int n;
    cin >> n;
    rep(i,n){
        string s;
        cin >> s;
        if(s[0]=='M'){
            m++;
            k[0]++;
        }else if(s[0]=='A'){
            a++;
            k[1]++;
        }else if(s[0]=='R'){
            r++;
            k[2]++;
        }else if(s[0]=='C'){
            c++;
            k[3]++;
        }else if(s[0]=='H'){
            h++;
            k[4]++;
        }
    }
    ll ans=0;
    for(int i=0;i<=2;i++){
        for(int j=i+1;j<=3;j++){
            for(int l=j+1;l<=4;l++){
                ans+=k[i]*k[j]*k[l];
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	
	
	
	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		
		while(true) {
			int n=cin.nextInt(),x=cin.nextInt();
			int res=0;
			if(n==0 && x==0)break;
			
			for(int i=1;i<=n-2;i++) {
				for(int j=i+1;j<=n-1;j++) {
					for(int k=j+1;k<=n;k++) {
						if(i+j+k==x)res++;
					}
				}
			}
			
			System.out.println(res);
			
		}
	}
	
}


Measured memory_bytes: 26748
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")
MOD = 1000000007


class Edge:
    def __init__(self, to, cost):
        self.to = to
        self.cost = cost


visited = []
vertex = []
def dfs(G, v, d):
    visited[v] = True
    if d % 2 == 0:
        vertex[v] = 0
    else:
        vertex[v] = 1

    for edge in G[v]:
        nv = edge.to
        if visited[nv]:
            continue
        nd = d + edge.cost
        dfs(G, nv, nd)


def main():
    N = int(input())
    G = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b, cost = map(int, input().split())
        a -= 1; b -= 1
        G[a].append(Edge(b, cost))
        G[b].append(Edge(a, cost))

    for _ in range(N):
        visited.append(False)
        vertex.append(0)
    
    dfs(G, 0, 0)

    for v in vertex:
        print(v)


if __name__ == '__main__':
    main()

Measured memory_bytes: 103160
#include <bits/stdc++.h>
#define for1(a,b,i) for(int i=a;i<=b;++i)
#define FOR2(a,b,i) for(int i=a;i>=b;--i)
using namespace std;
typedef long long ll;
inline int read() {
	int f=1,sum=0;
	char x=getchar();
	for(;(x<'0'||x>'9');x=getchar()) if(x=='-') f=-1;
	for(;x>='0'&&x<='9';x=getchar()) sum=sum*10+x-'0';
	return f*sum;
}

#define M 1000005
int n;
int vis[M];
int a[M],f[M][2],Max[M*4][2];

inline pair<int,int> query(int g,int l,int r,int lx,int rx) {
	if(lx>rx) return make_pair(0,0);
	if(lx<=l&&rx>=r) return make_pair(Max[g][0],Max[g][1]);
	pair<int,int> ans=make_pair(0,0);
	int mid=l+r>>1;
	if(lx<=mid) ans=query(g<<1,l,mid,lx,rx);
	if(rx>mid) {
		pair<int,int> y=query(g<<1|1,mid+1,r,lx,rx);
		ans.first=max(ans.first,y.first);
		ans.second=max(ans.second,y.second);
	}
	return ans;
}

inline void T_add(int g,int l,int r,int x,int id) {
	if(l==r) return Max[g][0]=f[id][0],Max[g][1]=f[id][1],void();
	int mid=l+r>>1;
	if(x<=mid) T_add(g<<1,l,mid,x,id);
	else       T_add(g<<1|1,mid+1,r,x,id);
	Max[g][0]=max(Max[g<<1][0],Max[g<<1|1][0]);
	Max[g][1]=max(Max[g<<1][1],Max[g<<1|1][1]);
}

inline bool check(int val,int to) {
	if(to<0) return 0;
	pair<int,int> y=query(1,1,n,val+1,n);
	if(!(y.first-to&1)) return y.first>=to;
	else return y.second>=to;
}

int main () {
	//freopen("a.in","r",stdin);
	n=read();
	for1(1,n,i) a[i]=read();
	
	for(int x=0,i=1;i<=n;++i) {
		x=max(x,a[i]);
		if(x==a[i]) ++vis[i];
	}
	FOR2(n,1,i) vis[i]+=vis[i+1];
	
	FOR2(n,1,i) {
		int t=1+(vis[i]!=vis[i+1]);
		pair<int,int> y=query(1,1,n,a[i]+1,n);
		f[i][y.first+t&1]=max(f[i][y.first+t&1],y.first+t);
		f[i][y.second+t&1]=max(f[i][y.second+t&1],y.second+t);
		T_add(1,1,n,a[i],i);
	}
	
	if(!check(0,vis[1])) return puts("-1"),0;
	
	for(int i=1,len[2]={0},pos[2]={0};i<=n;++i) {
		f[i][0]=f[i][1]=0;
		T_add(1,1,n,a[i],i);
		int x=a[i]>a[pos[0]]?i:pos[0],y=len[0]+(x==i);
		if(check(a[x],len[1]+vis[i+1]-y)||check(a[pos[1]],y+vis[i+1]-len[1])) {
			pos[0]=x,len[0]=y,putchar('0');
		}
		else {
			pos[1]=a[i]>a[pos[1]]?i:pos[1];
			len[1]+=pos[1]==i;
			putchar('1');
		}
	}
	puts("");
}

Measured memory_bytes: 16896
#include <iostream>

using namespace std;

int main(void) {
    int N;
    cin >> N;
    int ans = 0;
    int t;
    for (int i = 0; i < N; i++) {
        cin >> t;
        while (t % 2 == 0) {
            t /= 2;
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
    init();
    ll N;
    cin >> N;
    vvc<pair<ll, ll>> G(N);
    rep(i, N - 1) {
        ll a, b;
        cin >> a >> b;
        a--, b--;
        G[a].eb(b, i), G[b].eb(a, i);
    }

    vl C(N - 1);
    auto dfs = [&](auto&& dfs, ll now, ll par, ll id) -> ll {
        ll ret = 1;
        for (auto [to, tid] : G[now]) {
            if (to == par) continue;
            ret += dfs(dfs, to, now, tid);
        }
        if(id!=-1) C[id] = ret;
        return ret;
    };

    dfs(dfs, 0, -1, -1);

    vl p2(N + 1, 1);
    ll inv2N;
    rep(i, N) p2[i + 1] = p2[i] * 2 % MOD;
    inv2N = modpow(p2[N], MOD - 2, MOD);

    ll ans = 0;
    rep(i, N - 1)(ans += (p2[C[i]] - 1) * (p2[N - C[i]] - 1) % MOD) %= MOD;
    (ans += p2[N] - 1);
    (ans *= inv2N) %= MOD;


    (ans += MOD - N * modpow(2, MOD - 2, MOD) % MOD) %= MOD;

    cout << ans << endl;
}

Measured memory_bytes: 35084
#include <iostream>
#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#define decimal(x) cout<<fixed<<setprecision(x);
#define hackercup(x) cout<<"Case #"<<x<<": ";
void solve()
{
    int n;
    cin>>n;
    map<int,int>mp;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int count=0;
    for (int i = 0; i < n; i++) { 
        for (int j = i + 1; j < n; j++) { 
            for (int k = j + 1; k < n; k++) 
                if ( arr[i] + arr[j] > arr[k] && arr[i] + arr[k] > arr[j] && arr[k] + arr[j] > arr[i] && arr[i]!=arr[j] && arr[j]!=arr[k] && arr[k]!=arr[i]) 
                    count++; 
        } 
    } 
    cout<<count;
}
int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
     //  cin>>t;
    while(t--)
    {
        solve();
    }
}

Measured memory_bytes: 3652
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
using ll = long long;

const long double PI = acos(-1.0);
const int MOD = 1e9 + 7;

int main() {
    int n;
    string c;
    cin >> n >> c;
    int r = 0;
    int w = 0;
    for(int i = 0; i < n; i++) {
        if(c[i] == 'R') r++;
        else w++;
    }

    int ans = 0;
    for(int i = 0; i < r; i++) {
        if(c[i] == 'W') ans++;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3720
#include<stdio.h>

int main()
{
    int a,b,sum,sub,mul;
    scanf("%d %d",&a,&b);

    sum=a+b;
    sub=a-b;
    mul=a*b;

    if(sum>=sub && sum>=mul)
        printf("%d\n",sum);
    else if(sub>=sum && sub>=mul)
        printf("%d\n",sub);
    else if(mul>=sum && mul>=sub)
        printf("%d\n",mul);


    return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define vii vector<int>
#define vll vector<long long>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
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;}

int n;
ll ans;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
    cin >> n;
    vll a(n);
    rep(i, 0, n) {
        int p; cin >> p;
        a[i] = p - (i + 1);
    }
    sort(all(a));
    int b;
    b = a[n/2];
    rep(i, 0, n) {
        ans += abs(a[i] - b);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int ans = 0;
  cin >> n;
  std::vector<int> v(n);
  for(int i = 0; i < n; i++){
    cin >> v[i];
      v[i]--;
    ans += v[i];
  }
  cout << ans << endl;
  return 0;
}
    


Measured memory_bytes: 256
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

#約数列挙
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

n = ni()
ans = 0
for i in range(1,n+1,2):
    if len(make_divisors(i)) == 8:
        ans += 1

print(ans)

Measured memory_bytes: 3064
from __future__ import print_function

import sys
sys.setrecursionlimit(500000)

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return

# from fractions import gcd
# from math import gcd

# def lcm(n, m):
#     return int(n * m / gcd(n, m))


# def coprimize(p, q):
#     common = gcd(p, q)
#     return (p // common, q // common)


# def find_gcd(list_l):
#     x = reduce(gcd, list_l)
#     return x


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    x,y = map(int,input().strip().split())
    i=1
    while True:
        x*=2
        if x<=y:
            i+=1
        else:
            break
    print(i)
    

if __name__ == '__main__':
    main()

Measured memory_bytes: 62572
#include <bits/stdc++.h>
#define F(i,N) for(int i=0;i<(int)N;i++)
using namespace std;
int main(){
    int n,j,a[11],q,b,c,d,e;
    while(cin>>q>>b){
        if(q==0&&b==0)break;
        int sum=0;
        F(i,11)a[i]=0;
        F(i,q){cin>>c>>d;a[d]+=c;}
        for(int i=10;i>=0;i--){
            e=a[i];
            a[i]=a[i]-b;
            b=b-e;
            if(b<0)b=0;
            if(a[i]<0)a[i]=0;
        }
        F(i,11)sum+=a[i]*i;
        cout<<sum<<endl;
    }
}
 

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

using namespace std;

int main() {

  int N, T, A;
  cin >> N >> T >> A;
  vector<int> H(N);
  for (int i = 0; i < N; ++i) {
    cin >> H[i];
  }

  double min = 1e9;
  double ans = 0;
  for (int i = 0; i < N; ++i) {
    double d = abs(A - (T - H[i] * 0.006));
    if (d < min) {
      min = d;
      ans = i + 1;
    }
  }

  cout << ans << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x1f3f3f3f3f3f3f3f;
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)

const int MX = 200005;

int A[MX];

int main()
{
	int N;
	scanf("%d", &N);
	for(int i = 1; i <= N; i++) scanf("%d", A+i);
	sort(A+1, A+N+1);

	auto it = lower_bound(A+1, A+N, A[N] / 2);
	int v = A[1], w = A[N-1];
	if(it != A+N) w = *it;
	if(it != A+1) v = *(--it);
	if(A[N]/2 - v > w - A[N]/2-1) printf("%d %d\n", A[N], w);
	else printf("%d %d\n", A[N], v);
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repb(i, n) for (int i = n - 1; i >= 0; i--)
#define MODE 0
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
int ceil2(int a,int b){if(a%b){return a/b+1;}else{return a/b;}}
using namespace std;

int n,ans,k;

signed main(){
	cin>>n;
	for(int i=1;;i++){
		for(int j=-200;j<=i;j++){
			int A=(int)pow(i,5);
			int B=(int)pow(j,5);
			if(A-B==n){
				cout<<i<<" "<<j<<endl;
				return 0;
			}
		}
	}
}


Measured memory_bytes: 4028
#include<bits/stdc++.h>
#define MAXN 100000
#define pii pair<int,int>
#define lowbit(x) ((x)&(-(x)))

using namespace std;
void get(int &v)
{
	char c;
	while((c=getchar())!=EOF&&isdigit(c)==0);
	v=c-'0';
	while((c=getchar())!=EOF&&isdigit(c))
		v=(v<<1)+(v<<3)+c-'0';
	return ;
}
int get()
{
    int v;
	char c;
	while((c=getchar())!=EOF&&isdigit(c)==0);
	v=c-'0';
	while((c=getchar())!=EOF&&isdigit(c))
		v=(v<<1)+(v<<3)+c-'0';
	return v;
}
int a[MAXN+80];
set<int>s;
int main()
{
	int n,i,tot=0,x;
	get(n);
	for(i=1;i<=n;i++)
	{
		get(x);
		if(s.count(x))
		{
			a[++tot]=x;
			a[++tot]=x;
			s.erase(x);
		}
		else
			s.insert(x);
	}
	if(tot<4)
		puts("0");
	else
	{
		sort(a+1,a+tot+1);
		cout<<1LL*a[tot-1]*a[tot-3];
	}
    return 0;    
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

void print_aiko()
{
	rep(i, 5) cout << 3 << endl;
}

int main()
{
	int hand[5];
	map<int, int> num;

	while (cin >> hand[0])
	{
		num.clear();
		if (hand[0] == 0) break;
		num[hand[0]]++;

		for (int i = 1; i < 5; i++)
		{
			cin >> hand[i];
			num[hand[i]]++;
		}

		if ((num[1] > 0 && num[2] > 0 && num[3] > 0)
			|| num[1] == 5 || num[2] == 5 || num[3] == 5)
		{
			print_aiko();
			continue;
		}

		//??°??????0???
		if (num[1] == 0)
		{
			num[2] = 1;
			num[3] = 2;
		}
		//?????§??????0???
		else if (num[2] == 0)
		{
			num[1] = 2;
			num[3] = 1;
		}
		else if (num[3] == 0)
		{
			num[1] = 1;
			num[2] = 2;
		}

		rep(i, 5)
		{
			cout << num[hand[i]] << endl;
		}
	}
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    int n,m;
    cin >> n >> m;
    cout << n*(n-1)/2+m*(m-1)/2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>
#include<list>

/*
　　　　　　　　　　　　　　　　　　　　　__,.二ﾆ==-　　ﾆ．、_.　　　　　　　　　　　　　　　　　　　　　
　　　　　　　　　　　　　　　　.,.．‐　⌒　　　　　　　　　　　　｀`'ァ-ﾆ、.　　　　　　　　　　　　　　　
　　　　　　　　　　　　　　ィ'´.　　　　　　　　　　　　　　　　　　　　　　´丶.、　　　　　　　　　　　　
　　　　　　　　　　　.,ィ'´　　　　　　　　　　　　　　　　　　　　　　　　　　　　`.ｘ、..　　　　　　　　　
　..　　　　　　　　／.　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　､＼.　　　　　　　　
　　　　　　　　.ﾝ′.　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　￢`""冖ｰミト．
　　　　　　　,ｒ′.　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　.ﾍ、　　　　`
　　　　　　ﾂ　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　`、....　　　
　　　　　./´　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　ﾍ　　　　
　.....　　/.　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　.〉.　　　
　　　´/..　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　.ｌ　　　
　　　ｨ　　　　　　　　　　　　　　　　　　　　　　　　　．　　　　　　　　　　　　　　　　　　　　　ｆ..　　
　..　.ｆ　,d.　　　　　　　　　　　　　　　　　l　　　′　」　　,.　　　　　　　　　　　　　ﾄ　　　　　！　　
　.　〕../.ｆ..　　　　　　　　　　　　　　　　　′　．.　　|　　.｝　　　　　　　　　　　　　|　　　　　　|.　　
　　.!./..f..　　　　　　　　　　　　　　　　　/　　!－　ナ丶п冖т　　　　ﾉｰ-　．　〕　　　　　　|.　　
　　|ﾒ　|　　　　　　　　　　　　　　　｜　j　　　　　　,　　┌．　|〈.　　　л`.　　　/|..　　　　　┤,..　
　...「...｜.　　　　　　|　　´　　　　　　l.　|　　j.Ｌ......ｭ.Ｌ＿└ヽ_｜Y.　　ﾒムｗ　ょ　|　　j.:　　　|　￣
　.　　｜.　　　　　　　　　　　　　　　т〕＜.ィ冖T冖..　г‐　`､　`,　/┴￢..г￣|..　.′　　｜　　
　...　　|　　　　　　　　．..　　　　　　　),|..　｀　　ﾘ　「_ﾉ.||　　　　`　V　　|!｛,｢ll　´.」.　　　　　卜　　
　.　　｜.」　　　　　　′　　　　　　　　ヽ　　　　└++〃..　　　　　　　　ﾙｗｆ　　ｶz′.　　　｜.　　
　　　　|..〕　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　｢　　　　　．|　　　
　　　　.ｌ.|.　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　′.　　　　　|　　　
　.　　　.〕..　　　　　　　　　　　　　　　`!　　　　　　　　_...．.ｰ：''　　　　　　　　　｣　´　　　　λ.　　
　　　　_｢.　　　　,　　　　　　　　　　　　┐_,、｀~‐''"´　　　　　　　　　　　　　　　　ィ　　　.､　ﾍ、　
　　　　ｆ　　　　　　:_＿..,二ュ．-i―'''^~´　　　　　　　　　　　　　　　　　　　　　　　､＼イ　ヘ．`ｘ
　.　　/　　　　　　｛　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　j　　　　.~^
　　､/　　　　　　　'ｔ..　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　丿..　　　　　
　.../.　　　　　　　,x┐..　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　∠∫　　　　　
　:^.　　　　　　　/　　￣冖ー=zzｭ┌ｰ―--　　　∟,二...＿.　　　　　　　_,､．-ｰ.'l+~.　.l｀．　　　　
　.　　　　　　　У.　　　　　　　　　⌒冖‐-=．_..　l｢.｢　　　　　　´￣｣了　　.,､-''＾　　　〉　ヽ_　　　
　　　　　　　_/.　　　　　　　　　　　　　　　　　　￣~'.ー-=．、＿,..usｧ.ｰ''"　　　　　　｛　　　＼´　
　　　　　　_ヰl'￢―-　､_　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　（　　　　.＼
*/

using namespace std;

using ll = long long int;
using ull = unsigned long long int;

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

ll mypow(ll x,ll n,ll mod = MOD){
    ll ret = 1;
    while(n > 0){
        if(n&1){
            ret = (ret*x)%mod;
        }
        x = (x*x)%mod;
        n >>= 1;
    }
    return ret;
}

ll mygcd(ll a,ll b){
    if(b == 0)return a;
    return mygcd(b,a%b);
}

ll twoPow(ll shiftNum){
    return (1LL << (shiftNum - 1));
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
 
    ll s,w;
    cin >> s >> w;

    if(w >= s){
        cout << "unsafe" << endl;;
    }else{
        cout << "safe" << endl;
    }

    return 0;
}

Measured memory_bytes: 3640