akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

// 少し多めに確保すること
// ぴったりだと正しく動かないので注意
const long long MAX_V = 1010101;

struct edge {
  long long to, cost;
};

using Pll = pair<long long, long long>;

long long V;
vector<edge> Graph[MAX_V];
long long dist[MAX_V];

void dijkstra(long long s) {
  priority_queue<Pll, vector<Pll>, greater<Pll>> que;

  // 0-indexedと1-indexedの両方に対応
  fill(dist, dist + MAX_V, INF);

  dist[s] = 0;
  que.push(Pll(0, s));

  while (!que.empty()) {
    auto elem = que.top();
    que.pop();

    auto cv = elem.second;

    if (elem.first > dist[cv]) {
      continue;
    }

    for (auto e : Graph[cv]) {
      if (dist[e.to] > dist[cv] + e.cost) {
        dist[e.to] = dist[cv] + e.cost;
        que.push(Pll(dist[e.to], e.to));
      }
    }
  }
}

ll N;
ll Q, K;

int main() {
  cin >> N;
  V = N;

  rep(i, 1, N) {
    ll a, b, c;
    cin >> a >> b >> c;
    Graph[a].push_back(edge{b, c});
    Graph[b].push_back(edge{a, c});
  }

  cin >> Q >> K;
  dijkstra(K);
  vector<ll> ans;
  rep(i, 0, Q) {
    ll x, y;
    cin >> x >> y;
    ans.push_back(dist[x] + dist[y]);
  }

  for (auto e : ans) {
    cout << e << "\n";
  }
}


Measured memory_bytes: 42488
#!/usr/bin/env python
# conding: utf

from logging import getLogger, StreamHandler, NullHandler, DEBUG, INFO
logger = getLogger(__name__)
#handler = StreamHandler()
handler = NullHandler()
logger.setLevel(DEBUG)
handler.setLevel(DEBUG)
logger.addHandler(handler)
logger.propagate = False

g_field = []
g_count = 0
g_W = -1
g_H = -1

OFFSETS = [(1,0), (-1,0), (0,1), (0,-1)]

def dfs(x, y):
    global g_field
    global g_count
    global g_W
    global g_H


    g_count += 1

    g_field[y][x] = "-"

    for dx, dy in OFFSETS:
        logger.debug("diff: {} {}".format(dx, dy))
        new_x = x + dx
        new_y = y + dy

        if new_x < 0 or new_x >= g_W:
            continue
        if new_y < 0 or new_y >= g_H:
            continue
        new_tile = g_field[new_y][new_x]
        if new_tile == "#" or new_tile == "-":
            continue

        logger.debug("{}, {}".format(new_x, new_y))
        dfs(new_x, new_y)


if __name__ == "__main__":
    while True:
        g_W, g_H = [int(s) for s in input().strip().split()]

        if g_W == 0 and g_H == 0:
            break
        
        g_field = []
        for _ in range(g_H):
            row = list(input().strip())
            g_field.append(row)
        g_count = 0

        for y in range(g_H):
            for x in range(g_W):
                if g_field[y][x] == "@":
                    start_x = x
                    start_y = y
                    break

        dfs(start_x, start_y)

        print(g_count)



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

int main(void) {
  int N;
  cin>>N;
  vector<int> V(N);
  int sum=0;
  
  for (int i=0;i<N;i++) {
    cin>>V[i];
  }
  
  for (int i=1;i<N-1;i++) {
    if (V[i-1]<V[i] && V[i]<V[i+1]) {
      sum++;
    }
    else if (V[i-1]>V[i] && V[i]>V[i+1]) {
      sum++;
    }
    else continue;
  }
  
  cout<<sum<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#define REP(i,n) for(int i=0;i<n;i++)

using namespace std;

int main() {
    string s;
    cin >> s;
    int cnt = 0;
    REP(i, s.length()){
        if(s[i] == 'o') cnt++;
    }
    if (cnt + 15 - s.length() >= 8) cout << "YES"<<endl;
    else cout << "NO" <<endl;
}

Measured memory_bytes: 256
def resolve():
    n = int(input())
    dl = list()
    for i in range(n):
        d = int(input())
        dl.append(d)
    dl = sorted(dl, reverse=True)
    pre = 110
    ans = 0
    for d in dl:
        if d < pre:
            ans += 1
        pre = d
    print(ans)
resolve()

Measured memory_bytes: 9004
def around_nums(x):
    i = 1

    while(True):
        yield x
        yield x - i
        yield x + i
        i += 1

x, n = tuple(map(int, input().split()))
temp = input()

nums = list(map(int, temp.split()))
for n in around_nums(x):
    if not n in nums:
        print(n)
        break


Measured memory_bytes: 9180
//B
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
char a[200010],b[200010];
int len,ans;
int main()
{
	cin>>a>>b;
	len=strlen(a);
	for(int i=0;i<len;i++)
		{
		if(a[i]!=b[i])
			ans++;
		}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4016
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<numeric>
#include<utility>

using namespace std;

typedef long long int ll;
const int INF = 1<<30;
const long long LINF = 1LL<<60;

bool dp[1000001] = {};

int main(){
    int x;
    cin >> x;
    dp[0] = true;
    for(int i = 100; i <= 105; i++){
        for(int j = 0; j <= x - i; j++){
            dp[j + i] |= dp[j];
        }
    }
    cout << (dp[x]? "1" : "0") << endl;
    return 0;
}


Measured memory_bytes: 384
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    ab = [list(map(int, input().split())) for _ in range(n)]
    min_arr = sorted(ab, key=lambda x: x[0])
    max_arr = sorted(ab, key=lambda x: x[1])
    if n % 2 != 0:
        a = min_arr[n // 2][0]
        b = max_arr[n // 2][1]
        print(b - a + 1)
    else:
        a1 = min_arr[(n - 1) // 2][0]
        b1 = max_arr[(n - 1) // 2][1]
        a2 = min_arr[(n + 1) // 2][0]
        b2 = max_arr[(n + 1) // 2][1]
        print(b1 + b2 - a1 - a2 + 1)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


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

int main()
{
	for(string s;cin>>s;){
		int res=0;
		for(int i=0;i<s.size();i++){
			int c="gp"[i&1];
			if(c!=s[i])
				res+=c=='p'?1:-1;
		}
		cout<<res<<endl;
	}
}


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

int main() {
	long long n;
	cin >> n;
	long long ans = (n*(n+1)*(2*n+1)/6 + n*(n+1)/2) / 2;
	for (int i = 0; i < n-1; i++) {
		long long u, v;
		cin >> u >> v;
		if (u > v) swap(u, v);
		ans -= u * (n-v+1);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3596
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func scanNums(len int) (nums []int) {
	var num int
	for i := 0; i < len; i++ {
		num = nextInt()
		nums = append(nums, num)
	}
	return
}

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	p := scanNums(n)
	count := 0
	for i := 0; i < n-2; i++ {
		if p[i] < p[i+1] {
			if p[i+1] <= p[i+2] {
				count += 1
			} else if p[i+2] == p[i] {
				count += 1
			}
		} else {
			if p[i+1] > p[i+2] {
				count += 1
			}
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define per(i, a, b) for(int i=(a-1); i>=(b); i--)
#define qrep(i, q) for(auto i : q)
#define sz(a) (int)a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
#define lowbit(x) x&(-x)
#define all(x) x.begin(),x.end()
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int maxn = 100005;
const int logn = (log(maxn)/log(2))+5;
const int inf = 0x3f3f3f3f;
const ld eps = 1e-9;
int main()
{
	std::ios::sync_with_stdio(false);
    std::cin.tie(0);
	ll a, b;
	cin >> a >> b;
	if((a+b)&1) return cout << "IMPOSSIBLE" << endl, 0;
	else cout << (a+b)/2 << endl;
	return 0;
}


Measured memory_bytes: 256
use std::io::BufRead;
fn main() {
    let stdin = std::io::stdin();
    let mut lines: Vec<Vec<i64>> = stdin
        .lock()
        .lines()
        .map(|l| {
            l.unwrap()
                .split_whitespace()
                .map(|w| w.parse().unwrap())
                .collect()
        })
        .collect();
    let (_n, k, mut al, mut fl) = (lines[0][0], lines[0][1], lines.remove(1), lines.remove(1));
    if al.iter().sum::<i64>() <= k {
        println!("0");
        return;
    } else {
        al.sort();
        al.reverse();
        fl.sort();
        let list: Vec<_> = al.iter().zip(fl.iter()).collect();
        let mut lp: i64 = 1;
        let mut rp: i64 = 1 << 60;
        let mut mp: i64 = (lp + rp) / 2;
        while (lp != mp) || (mp != rp) {
            let cnt: i64 = list
                .iter()
                .filter(|x| (x.0 * x.1) > mp)
                .map(|x| x.0 - (mp / x.1))
                .sum();
            if k < cnt {
                lp = mp + 1;
            } else {
                rp = mp;
            }
            mp = (lp + rp) / 2;
        }
        println!("{}", mp);
    }
}


Measured memory_bytes: 13420
import java.io.IOException;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws IOException{
		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();
		int y = sc.nextInt();

		int ans1 = x * y;
		int ans2 = (2 * x)+(2 * y);

		System.out.println(ans1 + " " + ans2);

		sc.close();
	}
}


Measured memory_bytes: 26076
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORA(i, n) for (auto &&i : n)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define DEBUG(x) cerr << #x << ": " << x << "\n"
#define ALL(v) v.begin(), v.end()
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define epb emplace_back
#define int long long
using namespace std;
template < class T > using vec = std::vector< T >;
template < class T > void print(T &x) { cout << x << "\n"; }
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
  cin.tie(0), ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  int ans = 0;
  REPS(i, N) {
    if (i % 2 == 0)
      continue;
    int sqI = floor(sqrt(i));
    int count = 0;
    REPS(j, sqI) {
      if (i % j == 0) {
        count++;
        if (j != i / j) {
          count++;
        }
      }
    }
    if (count == 8) {
      ans++;
    }
  }
  print(ans);

  // print();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define COUT(x) cout<<(x)<<"\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define REP(i, n) for(int i=0;i<n;i++)
#define YES(x) cout<<(x?"YES":"NO")<<"\n"
#define Yes(x) cout<<(x?"Yes":"No")<<"\n"
#define dump(x) cout<<#x<<" = "<<(x)<<"\n"
#define endl "\n"
using G = vector<vector<int>>;
using M = map<int,int>;
using P = pair<int,int>;
using PQ = priority_queue<int>;
using PQG = priority_queue<int,vector<int>,greater<int>>;
using V = vector<int>;
using ll = long long;
using edge = struct { int to; int cost; };
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; }
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

int main() {
  IOS;
  int h,w; cin >> h >> w;
  vector<string> s(h);
  REP(i,h) cin >> s[i];

  vector<vector<int>> ver(h+1,vector<int>(w+1)), hor(h+1,vector<int>(w+1));

  REP(i,h) REP(j,w) {
    if (s[i][j] == '#') continue;
    ver[i+1][j+1] = ver[i][j+1]+1;
    hor[i+1][j+1] = hor[i+1][j]+1;
  }

  for (int i = h; i > 0; i--) {
    for (int j = w; j > 0; j--) {
      if (ver[i-1][j-1] == 0) continue;
      chmax(ver[i-1][j-1], ver[i][j-1]);
      chmax(hor[i-1][j-1], hor[i-1][j]);
    }
  }

  int ans = 1;
  REP(i,h) REP(j,w) {
    chmax(ans, ver[i+1][j+1]+hor[i+1][j+1]-1);
  }
  COUT(ans);
  return 0;
}

Measured memory_bytes: 38768
# -*- coding: utf-8 -*-
# get a integer
# get two integers separated with half-width break
n, m = map(int, raw_input().split())
# get a string
nn = range(2*n)
mm = range(2*m)
for i in range(n):
    nn[i*2], nn[i*2 + 1] = map(int, raw_input().split())
for i in range(m):
    mm[i*2], mm[i*2 + 1] = map(int, raw_input().split())
#print nn,mm
for i in range(n):
    for j in range(m):
        s = abs(mm[j*2]-nn[i*2]) + abs(mm[j*2+1]-nn[i*2+1])
        if j == 0:
            ma = s
            p = j + 1
        elif s < ma:
            ma = s
            p = j + 1
    print p


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

int main() {
  int cnt = 0, res[10000] = {0};
  while (true) {
    string s;
    cin >> s;
    if (s == "0")
      break;
    else {
      for (int i=0;i<s.size();i++)
        res[cnt] += (int)(s[i] - '0');
      cnt++;
    }
  }
  for (int i=0;i<cnt;i++)
    cout << res[i] << endl;
}



Measured memory_bytes: 3180
#!/usr/bin/env python3



# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    r, D, x = map(int, input().split())
    for i in range(10):
        x = x * r - D
        print(x)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define pb push_back
#define endl "\n"
#define pii tuple<ll,ll,ll>
#define ordered_set tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>
using namespace std;
using namespace __gnu_pbds;
const ll N=1005;
const ll INF=LLONG_MAX;
void amfetamin()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cerr.tie(0);
}
int main()
{
amfetamin();
int sol=0;
string a;
string b;
cin>>a;
cin>>b;
for (int i=0; i<a.size(); i++)
    if (a[i]!=b[i])
    sol++;
cout<<sol;
}


Measured memory_bytes: 3832
input = STDIN.gets
a_b = input.split(" ")
a = a_b[0].to_i
b = a_b[1].to_i
d = a / b
r = a % b
f = a.fdiv(b)
print d.to_s + " " + r.to_s + " " + format("%.5f", f) + "\n"

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

#define ST_ARR_LEN(array) (sizeof(array)/sizeof(*array))

using namespace std;

using ll = long long;
const ll MAX = LLONG_MAX;
const ll MIN = LLONG_MIN;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;
typedef vector<int> IntVector;
typedef list<int> IntList;

typedef struct S{
  int a;
  int b;
} Object;

int main(){
  ll N;
  cin >> N;
  
  ll sum = 0;
  ll count[10][10];
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      count[i][j] = 0;
    }
  }
  string str;
  for(int i=1;i<=N;i++){
    str = to_string(i);
    count[str[0]-'0'][i%10]++;
  }
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      sum += count[i][j]*count[j][i];
    }
  }
  
  cout << sum << endl;
}

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

int main(){
    long double a;
    long double b;
    long double c;

    cin >> setprecision(4) >> a;
    cin >> setprecision(4) >> b;

    c = a*b;
    cout << ll(c) << endl;;
}

Measured memory_bytes: 3732
import math

n = int(input())
A = list(map(int,input().split()))
count = 0

def merge(A, left, mid, right):

  global  count

  L = A[left:mid]
  L.append(math.inf)
  R = A[mid:right]
  R.append(math.inf)
  i = 0
  j = 0
  for k in range(left,right):
    count += 1
    if L[i] <= R[j]:
      A[k] = L[i]
      i = i + 1
    else:
      A[k] = R[j]
      j = j + 1


def mergeSort(A,left,right):
    if left +1 < right:
        mid = (left+right) // 2
        mergeSort(A,left,mid)
        mergeSort(A,mid,right)
        merge(A,left,mid,right)


mergeSort(A,0,n)
x = list(map(str,A))
print(" ".join(x))
print(count)


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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if((abs(a - b) <= d && abs(b -c) <= d) || abs(a - c) <= d)cout << "Yes" <<endl;
  else cout << "No" << endl;
}

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

long long N, L;
long long A[100005];

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

	long long idx = -1;
	long long maxi = -1;
	for(long long i = 0; i < N-1; i++){
		if(A[i] + A[i + 1] > maxi){
			idx = i;
			maxi = A[i] + A[i+1];
		}
	}

	if(maxi >= L){
		cout << "Possible" << endl;
		for(long long i = 1; i <= idx; i++){
			cout << i << endl;
		}

		for(long long i = N - 1; i >= idx + 2; i--){
			cout << i << endl;
		}
		cout << idx + 1 << endl;
	} else {
		cout << "Impossible" << endl;
	}
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define ll long long int
#define nl cout << endl
#define pb push_back
#define ff first
#define ss second
#define all(ar) ar.begin(), ar.end()
#define hang while (1)
//debugger
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

int main() {
	fast;
	int n,m,l;
	cin >> n >> m >> l;
	vector <vector <ll> > a(n+1,vector <ll> (n+1,(ll)(1e18))),pi(n+1,vector <ll> (n+1,-1));
	for (int i=0; i<m; i++) {
		int x,y,z;
		cin >> x >> y >> z;
		if (z>l) {
			continue;
		}
		a[x][y]=z;
		a[y][x]=z;
		pi[x][y]=x;
		pi[y][x]=y;
	}
	for (int k=1; k<=n; k++) {
		for (int i=1; i<=n; i++) {
			for (int j=1; j<=n; j++) {
				if (a[i][j]>a[i][k]+a[k][j] and a[i][k]+a[k][j]<(ll)(1e18)) {
					a[i][j]=a[i][k]+a[k][j];
					pi[i][j]=k;
				}
			}
		}
	}
	for (int i=1; i<=n; i++) {
		for (int j=1; j<=n; j++) {
			if (a[i][j]<=l) {
				a[i][j]=1;
			} else {
				a[i][j]=1e18;
			}
		}
	}
	for (int k=1; k<=n; k++) {
		for (int i=1; i<=n; i++) {
			for (int j=1; j<=n; j++) {
				if (a[i][j]>a[i][k]+a[k][j] and a[i][k]+a[k][j]<(ll)(1e18)) {
					a[i][j]=a[i][k]+a[k][j];
					pi[i][j]=k;
				}
			}
		}
	}
	int q;
	cin >> q;
	while (q--) {
		int s,t;
		cin >> s >> t;
		cout << (a[s][t]<(ll)(1e18)?a[s][t]-1:-1);nl;
	}
	return 0;
}

//notes
/*
 use these format of input when number of inputs not provided
 *while(scanf("%lld",&n)!=EOF)
 *while using getline(cin,s) for taking input of a string which is 
 having white space characters just write cin>>ws; before geline(cin,s)
 to make it work properly
*/

/*
 use 2-D vector for representing the pair<int,pair<int,int> > kind of things
*/

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VV = vector<VI>;
using VS = vector<string>;

// tourist set
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << '\n'; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// tourist set end

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<'\n'
#define p2(s, t) cout << (s) << " " << (t) << '\n'
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << '\n'
#define p_yes() p("YES")
#define p_no() p("NO")
#define SZ(x) ((int)(x).size())
#define SORT(A) sort(ALL(A))
#define RSORT(A) sort(ALL(A), greater<ll>())

void no(){p_no(); exit(0);}
void yes(){p_yes(); exit(0);}

const ll mod = 1e9 + 7;
const ll inf = 1e18;
const double PI = acos(-1);

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

    // input
    ll N; 
    cin >> N;
    
    p(N*N);
    
    return 0;
}

Measured memory_bytes: 764
#ifdef LOCAL_BUILD
#include "pch.h"
#define DLOG(msg) cout << "#" << __LINE__ << ":" << msg << endl;
#define DLOG_V(var) \
  cout << "#" << __LINE__ << ":" << #var << " : " << var << endl;
#else
#include <bits/stdc++.h>
#define DLOG(msg)
#define DLOG_V(var)
#endif
using namespace std;

int main() {
  int n, q;
  cin >> n;
  unordered_set<int> nums;
  for (int i = 0; i < n; ++i) {
    int num;
    cin >> num;
    nums.insert(num);
  }
  cin >> q;
  int count = 0;
  for (int i = 0; i < q; ++i) {
    int num;
    cin >> num;
    if (nums.find(num) != nums.end()) {
      ++count;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 4584
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int M = 82;
ll m,sum = 1000;
ll a[M];
priority_queue <int,vector <int>, greater <int> > q;

template<typename T>
inline void read(T &x){
    x = 0; char ch = getchar(); int f = 1;
    for(;ch < '0' || ch > '9'; ch = getchar()) if(ch == '-') f = -1;
    for(;ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
    x *= f;
}

int main(){
    read(m);
    for(int i = 1;i <= m; i++) read(a[i]);
    for(ll i = 1,x;i <= m - 1; i++){
        x = 0;
        if(a[i] < a[i + 1]) x = sum / a[i];
        sum += (a[i + 1] - a[i]) * x;
    }
    printf("%lld\n",sum);
    return 0;
}
/*
7
100 130 130 130 115 115 150

1685
*/

Measured memory_bytes: 3160
# 2020年6月17日

# 修行という概念がない場合、消化コストを大から小に並べて食べにくさを小から大に並べて順にマッチングさせれば良い。
# そうでない状態から2つを交換したときに最大値が下がる方向にしか行かないため。

# 修行をするなら最大値を引き下げるところに修行をするのが最適なので、
# 無修行状態の結果を優先度付きキューに入れる→K回最大値を取り出してコストを引いて再投入→を繰り返す。
# 本当か? やってるうちに最適な組み合わせが変わらないか? →変わらない。食べにくさを昇順に並べたときに消化コストが降順になるのが最善手なので。
# あとKが大きいのでこれだと間に合わない。

# 決め打ち二分探索か?
# あ、それだわ。

# Python TLE 2秒以上
# PyPy 287ms

n, k = list(map(int, input().split()))

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


def is_valid(unit):
    # k回以下の切断で実現可能か

    n_cut = sum(map(lambda p: (p+unit-1) // unit - 1, lengths))
    # print(unit, n_cut)
    
    return n_cut <= k


unit_ok = 10 ** 9 + 1
unit_ng = 0

# めぐる式二分探索
while abs(unit_ok - unit_ng) > 1:
    mid = (unit_ok + unit_ng) // 2
    if is_valid(mid):
        unit_ok = mid
    else:
        unit_ng = mid

print(unit_ok)


Measured memory_bytes: 31032
#include <bits/stdc++.h>
using namespace std;
int main(){
    int h,n;
    cin >> h >> n;
    int sm = 0, a;
    for(int i=0;i<n;i++){
        cin >> a;
        sm += a;
    }
    cout << (h<=sm?"Yes":"No") << endl;
}

Measured memory_bytes: 256
#include "iostream"
#include "vector"
#include "algorithm"


using namespace std;

int H, W;
char a[15][15], pc[15], pr[15];
bool mp_r(int x);
bool mp_c(int x);

bool mp_c(int x) {
    if (x > W) {
        return mp_r(1);
    } else if (pc[x]) {
        return mp_c(x + 1);
    }

    int t = 0;
    for (int i = x; i <= W; i++) {
        if (!pc[i]) t++;
    }
    for (int i = x; i <= W; i++) {
        if (pc[i]) continue;
        pc[x] = i;
        pc[i] = x;
        if (((t & 1) || (i != x)) && mp_c(x + 1)) {
            return true;
        }
        pc[x] = 0;
        pc[i] = 0;
    }

    return false;
}

bool mp_r(int x) {
    if (x > H) {
        return true;
    } else if (pr[x]) {
        return mp_r(x + 1);
    }

    int t = 0;
    for (int i = x; i <= H; i++) {
        if (!pr[i]) t++;
    }
    for (int i = x; i <= H; i++) {
        if (pr[i]) continue;
        bool ok = true;

        for (int j = 1; j <= W; j++) {
            ok &= (a[x][j] == a[i][pc[j]]);
        }

        if (((t & 1) || (i != x)) && ok) {
            pr[x] = i;
            pr[i] = x;
            if (mp_r(x + 1)) return true;
            pr[x] = 0;
            pr[i] = 0;
        }
    }

    return false;
}

int main() {

    cin >> H >> W;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            cin >> a[i][j];
        }
    }
   
   if (mp_c(1)) {
       cout << "YES" << endl;
   } else {
       cout << "NO" << endl;
   }
}

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

int main(){
    int N;
    cin >> N;
    int both_open, profit, max_profit;
    bitset<10> combination;
    vector<vector<int>> F(N, vector<int>(10));
    vector<vector<int>> P(N, vector<int>(11));
    for (int i = 0; i < N; i++){
        for (int j = 0; j < 10; j++){
            cin >> F[i][j];
        }
    }
    for (int i = 0; i < N; i++){
        for (int j = 0; j < 11; j++){
            cin >> P[i][j];
        }
    }

    for (int i = 1; i < (1 << 10); i++){
        profit = 0;
        combination = i;
        for (int j = 0; j < N; j++){
            both_open = 0;
            for (int k = 0; k < 10; k++){
                if (combination[k] == 1 && F[j][k] == 1) both_open++;
            }
            profit += P[j][both_open];
        }
        if (i == 1) max_profit = profit;
        else{
            if (max_profit < profit) max_profit = profit;
        }
    }

    cout << max_profit << endl;
}


Measured memory_bytes: 256
s=str(input())
l=len(s)
t=str(input())
n=len(t)
ans=n
sum=0
for i in range(l+1-n):
    cutted=s[i:i+n]
    for j in range(n):
        if cutted[j]==t[j]:
            continue
        else:
            sum+=1
    ans=min(ans,sum)
    sum=0
print(ans)

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

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, W: "List[str]"):
    if len(W) != len(set(W)):
        print(NO)
        return

    for i in range(1,N):
        if W[i-1][-1] != W[i][0]:
            print(NO)
            return

    print(YES)

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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
    W = [ next(tokens) for _ in range(N) ]  # type: "List[str]"
    solve(N, W)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
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.*;

/** @see http://d.hatena.ne.jp/komiyam/20120402/1333373895 */
public class Main {
	Scanner sc = new Scanner(System.in);

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

	int n, q;
	int[] ps;
	int[] queryType, queryNode;

	void run() {
		for (;;) {
			n = sc.nextInt();
			q = sc.nextInt();
			if ((n | q) == 0) {
				break;
			}
			ps = new int[n];
			for (int i = 1; i < n; i++) {
				ps[i] = sc.nextInt() - 1;
			}
			queryType = new int[q];
			queryNode = new int[q];
			for (int i = 0; i < q; i++) {
				queryType[i] = sc.next().charAt(0) == 'M' ? 0 : 1;
				queryNode[i] = sc.nextInt() - 1;
			}
			solve();
		}
	}

	class Heap {
		Heap l, r;
		int val;

		Heap(int _val) {
			val = _val;
		}

		int top() {
			return val;
		}

		Heap push(int val) {
			return meld(this, new Heap(val));
		}

		Heap pop() {
			return meld(l, r);
		}
	}

	Heap meld(Heap a, Heap b) {
		if (a == null)
			return b;
		if (b == null)
			return a;
		// if (a.val > b.val)
		if (-a.val > -b.val)
			return meld(b, a);
		a.r = meld(a.r, b);
		Heap t = a.l;
		a.l = a.r;
		a.r = t;
		// swap(a.l, a.r);
		return a;
	}

	class V extends ArrayList<V> {
		Heap h;
		int id,state;
		int markedTime;
		ArrayList<Integer> askedTimes = new ArrayList<Integer>();

		V(int _id) {
			id = _id;
		}
	}

	long ans;

	Heap rec(V v) {
		// vが答えになる
		Heap h = null;
		for (int t : v.askedTimes) {
			h = meld(h, new Heap(t));
		}
		for (V u : v) {
			h = meld(h, rec(u));
		}
		for (; h != null && h.top() > v.markedTime; h = h.pop()) {
			ans += v.id;
			// debug("vid",v.id);
		}
		return h;
	}

	void solve() {
		ans = 0;
		V[] vs = new V[n];
		for (int i = 0; i < n; i++) {
			vs[i] = new V(i + 1);
			vs[i].markedTime = INF;
		}
		// root = 1(0)
		for (int i = 1; i < n; i++) {
			// ps[i]
			vs[ps[i]].add(vs[i]);
		}
		vs[0].markedTime = -1;
		for (int i = 0; i < q; i++) {
			int v = queryNode[i], tick = i + 1;
			if (queryType[i] == 0) {
				// mark
				vs[v].markedTime = min(vs[v].markedTime, tick);
			} else {
				// query
				vs[v].askedTimes.add(tick);
			}
		}

		ps = null;
		queryNode = null;
		queryType = null;

		System.gc();

		Stack<V> stackV = new Stack<V>();

		stackV.push(vs[0]);

		for (; !stackV.isEmpty();) {
			V v = stackV.pop();
			if (v.state == 0) {
				// 最初
				for (int t : v.askedTimes) {
					v.h = meld(v.h, new Heap(t));
				}
				stackV.push(v);
				v.state=1;
				for (V u : v) {
					stackV.push(u);
				}
			} else {
				// さいき＼(^o^)／
				for (V u : v) {
					v.h = meld(v.h, u.h);
				}
				for (; v.h != null && v.h.top() > v.markedTime; v.h = v.h.pop()) {
					ans += v.id;
				}
			}
		}
		
		System.gc();

		println(ans + "");
	}

	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: 249048
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <map>
#include <set>
#include <vector>
#include <deque>
#include <queue>

#define pb push_back
#define mp make_pair
#define x first
#define y second
#define FOR(i, a, b) for(int i=a, loop=b; i<=loop; ++i)
#define REV(i, a, b) for(int i=a, loop=b; i>=loop; --i)
#define mize(a, b) a = min(a, b)
#define maxi(a, b) a = max(a, b)
#define shl(k) ((k) << 1)
using namespace std;

const int N = 1e6+5, mod = 1e9+7;
int n;
int64_t a[N], s[N], f[N];

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

    cin >> n;
    s[0] = a[0] = 1;
    s[1] = a[1] = 2;
    f[0] = f[1] = 1;
    FOR(i, 2, n) {
        f[i] = s[i-2];
        a[i] = (a[i-1] + f[i]) % mod;
        s[i] = (s[i-1] + a[i-1]) % mod;
    }

    int64_t ans;
    if (n == 1) ans = 1; else {
        ans = (a[n-2]*(n-1)%mod*(n-1)%mod + f[n-1]*(n-1)%mod + f[n]) % mod;
        FOR(i, 1, n-1) ans = (ans + f[i-1]*i%mod) % mod;
    }
    cout << ans;
}


Measured memory_bytes: 23680
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
      Scanner sc = new Scanner(System.in);
      int N1 = sc.nextInt();
      int N2 = sc.nextInt();      
		for(int i = -N1 +1;  i <  N1  ; i++){
          	if( N2 + i < -1000001 || N2 + i > 1000001){
            continue;
            }
			System.out.println(N2 + i);
          }
    }
}


Measured memory_bytes: 22100
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const  ll INF = 1e9;
const  ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i,n,init) for(ll i=init;i<(n);i++)
#define repd(i,n,init) for(ll i=(n);i>=init;i--)
#define repm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define repb(bit,n,init) for(ll bit=init;bit<(1<<n);++bit)

int main()
{
    int s,w;
    cin >> s >> w;
    cout << (w >= s?"unsafe":"safe") << endl;
    return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    int a, b;
    cin >> a >> b;
    double a1 = a, b1 = b;
    printf ("%d %d %.5lf\n", a / b, a % b, a1 / b1 );
    return 0;
}


Measured memory_bytes: 3196
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int ans = 0;
    while (N != 0) {
      if (Integer.toString(N).length() % 2 != 0) ans++;
      N--;
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 28500
#include "bits/stdc++.h"
using namespace std;
int a[100004];
int main(){
    int n;
    cin>>n;
    for (int i = 1; i <= n; ++i) {
        cin>>a[i];
    }
    int cnt = 0;
    int ans = 0;
    for (int i = 2; i <= n; ++i) {
        if(a[i]<=a[i-1])cnt++;
        else cnt = 0;
        ans = max(ans , cnt);
    }
    cout<<ans<<endl;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  
  int ans_a = 0, ans_b = 0;
  for (int i = 0; i < b; i++) {
    ans_a += a * pow(10, i);
  }
  for (int i = 0; i < a; i++) {
    ans_b += b * pow(10, i);
  }
  
  if (ans_a >= ans_b) {
    cout << ans_a << endl;
  } else {
    cout << ans_b << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
MOD = 10 ** 9 + 7  # prime number
 
def cmb(n, r, mod=MOD):
    if r < 0 or n < r:
        return 0
    r = min(r, n-r)
    numerator, denominator = 1, 1
    for i in range(1, r + 1):
        numerator = (numerator * (n + 1 - i)) % mod
        denominator = (denominator * i) % mod
    return numerator * pow(denominator, mod - 2, mod) % mod
 
X, Y = map(int, input().split())
if (X + Y) % 3 != 0:
    print(0)
else:
    n = int((X + Y) / 3)
    a = Y - n
    b = X - n
    if not (a >= 0 and b >= 0):
        print(0)
    else:
        ans = cmb(a + b, a)
        print(ans)

Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define _USE_MATH_DEFINES
#include <math.h>
#define rep(i,n) for(int i = 0;i < n;i++)
#define NIL = -1;
#define all(x) x.begin(),x.end()
const ll INF = 1e9;
const ll mod = 1e9 + 7;

int digit(ll x) {
    if (x / 10 == 0) return 1;
    return digit(x / 10) + 1;
}

ll gcd(long long a,long long b) {
    if (a < b) swap(a,b);
    if (b == 0) return a;
    
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    return ((a * b == 0)) ? 0 : (a / gcd(a,b) * b);
}

int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};


////////////////////////////////////////////////////////////////////////////////////////
int main(){
    
    char c;
    cin >> c;
    char ans = c + 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;

int main(){
  int n;
  cin >> n;
  if (n == 3 || n == 7 || n == 5) {
    puts("YES");
  } else {
    puts("NO");
  }
  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
 
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
 

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

int a[200001];
int b[200001];

int main(){
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for(int i=0;i<n;++i)
  {
    cin >> a[i] >> b[i];
  }
  int lower = 0;
  int upper = 0;
  int ret = 0;
  sort(a, a+n);
  sort(b, b+n);
  if(n%2 == 0)
  { 
    lower = a[n/2] + a[n/2-1];
    upper = b[n/2] + b[n/2-1];
    ret = upper - lower + 1;
  }else{
    lower = a[n/2];
    upper = b[n/2];
    ret = upper - lower + 1;
  }
  cout << ret << endl;
}

Measured memory_bytes: 5148
(defmacro defsolver (name vars &body body)
  `(defun ,name ()
     (let (,@(mapcar #'list
            vars
            (mapcar (constantly '(read))
                vars)))
       ,@body)))

(defsolver solution-c (n)
  (let* ((l (loop repeat n collect (read)))
	 (ll (sort l #'<)))
    (princ (- (nth (floor n 2) ll)
	      (nth (1- (floor n 2)) ll)))))

(solution-c)

Measured memory_bytes: 59880
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    int aa[b];
    int sum=0;
    for(int i=0;i<b;i++)
    {
        cin>>aa[i];
        sum+=aa[i];
    }

    if(sum>=a)
    {
        cout<<"Yes"<<endl;
    }
    else
        cout<<"No"<<endl;
}



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

using namespace std;
int sqr(int a){return a*a;}
int main(){
    
    while (1)
    {
       int n;
        cin>>n;
        if(n == 0)break;
        int s[n];

        double ss[n];
        for (int i = 0; i < n; i++)
        {
            scanf("%d",&s[i]);
        }
        double cnt = 0;
        for (int i = 0; i < n; i++)
        {
            cnt += s[i];
        }
        double mean = cnt/n;
       // cout<<'*'<<mean;
        double flag = 0;
        
        for (int i = 0; i < n; i++)
        {
            ss[i] = pow((s[i] - mean),2);
            flag+=ss[i];
            
        }
       // cout<<'*'<<flag<<endl;
        double v = 1/((double)n)*flag;
        double res = sqrt(v);
        
        printf("%lf\n",res);
       // cout<<mean;
       // 9 2 5 4 12 7
        
    }
   

    return 0;
    
}
//4 3 90
 // 
//c2 = a2 + b2 − 2ab cos(C)


Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
// -----------------------------------------------------------------------------

const int N = 30;
const int MOD = 1E9 + 7;
LL cnt[N];

int main() {
    int n; cin >> n;
    string s; cin >> s;
    FOR (i, 0, s.length())
        cnt[s[i] - 'a']++;
    LL ans = 1;
    FOR (i, 0, 26) ans = ans * (cnt[i] + 1) % MOD;
    ans = (ans - 1 + MOD) % MOD;
    cout << ans << endl;
}

Measured memory_bytes: 512
#include<stdio.h>

int main(){
  int A, B, C, D, E, F;
  scanf("%d %d %d %d %d %d", &A, &B, &C, &D, &E, &F);
  
  int w = 100 * A;
  int s = 0;
  for(int a = 0; 100 * A * a <= F; a++){
    for(int b = 0; 100 * (A * a + B * b) <= F; b++){
      if(a == 0 && b == 0) continue;
      for(int c = 0; 100 * (A * a + B * b) + C * c <= F; c++){
        for(int d = 0; 100 * (A * a + B * b) + C * c + D * d <= F; d++){
          if((A * a + B * b) * E < C * c + D * d) continue;
          if((100 * (A * a + B * b) + C * c + D * d) * s < (w + s) * (C * c + D * d)){
            w = 100 * (A * a + B * b);
            s = C * c + D * d;
          }
        }
      }
    }
  }
  
  printf("%d %d\n", w + s, s);
  
  return 0;
}

Measured memory_bytes: 128
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val a = List.fill(n)(sc.nextInt())

  val aOdd = a.zipWithIndex.filter(_._2 % 2 == 0).map(_._1)
  val aEven = a.zipWithIndex.filter(_._2 % 2 == 1).map(_._1)
  if (n == 1) {
    println(a.head)
  } else if (n % 2 == 0) {
    println(s"${aEven.reverse.mkString(" ")} ${aOdd.mkString(" ")}")
  } else {
    println(s"${aOdd.reverse.mkString(" ")} ${aEven.mkString(" ")}")
  }
}


Measured memory_bytes: 97472
n, l = map(int, input().split())

t_sum = 0
t_min = 1000
t_min_index = 1000
for i in range(1, n+1):
    if t_min != min(t_min, abs(l+i-1)):
        t_min = min(t_min, abs(l+i-1))
        t_min_index = i
    t_sum += l+i-1

t_min = l + t_min_index - 1
print(t_sum - t_min)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, X, D=0, count=1;
  cin >> N >> X;
  vector<int> L(N);
  for (int i=0; i < N; i++)
    cin >> L.at(i);
  for (int i=0; i<N; i++){
    D += L.at(i);
    if (D <= X)
      count++;
    else
      break;
  }
  cout << count << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
using namespace std;
struct UnionFind{
    vector<int> data;
    UnionFind(int nb_v) : data(nb_v, -1) {}
    
    bool unionSet(int x, int y){
        x = root(x);
        y = root(y);
        if (x != y){
            if (data[x] > data[y]) swap(x,y);
            data[x] += data[y];
            data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y){
        return root(x) == root(y);    
    }
    int root(int x){
        return data[x] < 0? x: data[x] = root(data[x]);
    }
};

int main(void){cin.tie(0);ios::sync_with_stdio(false);
    
    int nb_v, nb_lines;
    cin >>nb_v
        >>nb_lines;
    UnionFind G(nb_v);
    for(int i=0; i<nb_lines; ++i){
        int query, v1, v2;
        cin >>query
            >>v1
            >>v2;
            
        switch (query){
            case 0:{
                G.unionSet(v1, v2);
                break;
            }
            case 1:{
                cout<<G.findSet(v1, v2)<<endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 3220
#include<bits/stdc++.h>
using namespace std;
int n,m,x,ans,ans1,f[100001],e[100001];
char y[10];
int main(){
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>x>>y;
		if(y[0]+y[1]=='A'+'C'){
			if(!f[x])ans++,f[x]=1,ans1+=e[x];
		}
		else e[x]++;
	}
	printf("%d %d\n",ans,ans1);
	return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		scan.close();
		System.out.println((n%2==0)? (double)1/2:(double)((int)(n/2)+1)/n);
	}
}

Measured memory_bytes: 21844
/*-----lusar98-----*/
#include<bits/stdc++.h>
#define fast() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define mod 1000000007
#define eps 1e-9
#define ff first
#define ss second
#define pb push_back
#define endl "\n"
using namespace std;
int main()
{
    //fast();
    ll n,w;
    cin>>n>>w;
    ll arr[n][2];
    for(ll i=0;i<n;i++)
        cin>>arr[i][0]>>arr[i][1];
    ll dp[n*1000 + 1000];
    for(ll i=0;i<n*1000 + 1000;i++)
        dp[i] = w*10;    
    dp[arr[0][1] ]=arr[0][0];
    dp[0] = 0;
    for(ll i=1;i<n;i++)
    {
        for(ll j =n*1000 ;j>=0;j--)
        {
            if(dp[j]!=-1)
            {
                dp[ j + arr[i][1] ] = min( dp[j] + arr[i][0], dp [j+arr[i][1] ] );
            }
        }
    }
    ll ans=w;
    for(ll j =n*1000 ;j>=0;j--)    
    {
        if(dp[j]<=w)
            {
                cout<<j<<endl;
                break;}
    }    
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const int N=1000005;
int n,a[N],cnt[3],b[3],c[3],pre[N],nxt[N];char s[N];vector<int>V;
inline bool cmp(int x,int y){return cnt[x]<cnt[y];}
inline void del(int x){pre[nxt[x]]=pre[x];nxt[pre[x]]=nxt[x];cnt[a[x]]--;}
int main()
{
	scanf("%s",s+1);n=strlen(s+1);a[0]=a[n+1]=-1;
	for(int i=0;i<=n;i++)pre[i+1]=i,nxt[i]=i+1;
	for(int i=1;i<=n;i++)cnt[a[i]=s[i]-'A']++;
	for(int i=1;i<=n;i++)if(a[i]==a[i-1])del(i);
	c[0]=0;c[1]=1;c[2]=2;sort(c,c+3,cmp);
	b[c[0]]=0;b[c[1]]=1;b[c[2]]=2;V.clear();
	for(int i=nxt[0];i!=n+1;i=nxt[i])if(a[i]==c[2]&&a[pre[i]]!=a[nxt[i]])V.push_back(i);
	for(int i=0;i<V.size()&&cnt[c[2]]>cnt[c[1]];i++)del(V[i]);V.clear();
	for(int i=nxt[0];i!=n+1;i=nxt[i])if(a[i]==c[2]&&a[pre[i]]==c[0]&&a[nxt[i]]==c[0])V.push_back(i);
	for(int i=0;i<V.size()&&cnt[c[2]]>cnt[c[1]];i++)del(V[i]),del(nxt[V[i]]);
	V.clear();for(int i=nxt[0];i!=n+1;i=nxt[i])if(a[i]==c[2]&&a[nxt[i]]==c[1])V.push_back(i);
	for(int i=0;i<V.size()&&cnt[c[1]]>cnt[c[0]];i++)if(a[pre[V[i]]]!=c[0]||a[nxt[nxt[V[i]]]]!=c[0])del(V[i]),del(nxt[V[i]]);
	V.clear();for(int i=nxt[0];i!=n+1;i=nxt[i])if(a[i]==c[2]&&a[pre[i]]==c[1])V.push_back(i);
	for(int i=0;i<V.size()&&cnt[c[1]]>cnt[c[0]];i++)if(a[nxt[V[i]]]!=c[0]||a[pre[pre[V[i]]]]!=c[0])del(V[i]),del(pre[V[i]]);
	if(cnt[0]==cnt[1]&&cnt[0]==cnt[2])for(int i=nxt[0];i!=n+1;i=nxt[i])putchar('A'+a[i]);
	return 0;
}


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

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

    int n;
    cin >> n;

    string prev;
    cin >> prev;
    bool flg = true;
    map<string, int> exists;
    ++exists[prev];

    for(int i = 1; i < n; ++i){
        string next;
        cin >> next;

        if(prev[prev.length()-1] != next[0]) flg = false;
        if(exists[next] > 0) flg = false;

        prev = next;
        ++exists[next];
    }

    cout << (flg? "Yes": "No") << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	double sum = 0;
	for (int i = 1; i <= n; i++) {
		double d = 1.0 / n;
		for (int j = i; j < k; j *= 2) {
			d *= 0.5;
		}
		sum += d;
	}
	printf("%.12f\n", sum);

	return 0;
}

Measured memory_bytes: 256