akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
	int n;
  	cin >> n;
  	unsigned long long x;
  	unsigned long long z = 1;
  	bool flag = false;
  	bool zeroflag = false;
  	for (int i = 0; i < n; i++ )
    {
      cin >> x;
      
      if (x == 0) 
      {
        zeroflag = true;
        break;
      }
      if (x <= 1000000000000000000/z)
      {
        z = z*x;
      }
      else 
      {
		flag = true;
      }
    }
  if (!zeroflag) 
  {
    if(!flag) 
    {
  		cout << z << endl;
    }
    else
    {
        cout << -1 << endl;
    }
  }
  else
  {
    cout << 0 << endl;
  }
  
	return 0;
}

Measured memory_bytes: 3112
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
    static final Scanner     sc = new Scanner(System.in);
    static final PrintStream so = System.out;

    public static void main(String[] args) {
        int n = ni();
        int k = ni();
        char[] c = nsToChars();
        c[k-1] = Character.toLowerCase(c[k-1]);
        
        for (int i = 1; i <= n; i++) {
            so.print(c[i-1]);
        }
    }

    private static int ni() {
        return sc.nextInt();
    }

    private static long nl() {
        return sc.nextLong();
    }

    private static String ns() {
        return sc.next();
    }

    private static char[] nsToChars() {
        return sc.next().toCharArray();
    }

    private static int[] nints(int n) {
        return nints(n, 0);
    }

    private static int[] nints(int n, int padding) {
        int[] a = new int[padding + n];
        for (int i = 0; i < n; i++)
            a[padding + i] = ni();
        return a;
    }
}


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

ll gcd(ll a, ll b);
ll lcm(ll a, ll b);

int main()
{
    ll A, B;
    cin >> A >> B;
    cout << lcm(A, B) << endl;
}

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

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


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int int_sort(const void *a, const void *b)
{
    if (*(int *)a < *(int *)b)
    {
        return -1;
    }
    else if (*(int *)a == *(int *)b)
    {
        return 0;
    }
    return 1;
}

int main(int argc, char *argv[])
{
    int i, n, j, temp;
    int N, K;

    scanf("%d", &N);
    scanf("%d", &K);
    int hight[N];
    for (i = 0; i < N; i++)
    {
        scanf("%d", &n);
        hight[i] = n;
    }

    qsort((void *)hight, N, sizeof(hight[0]), int_sort);

    int range[i];
    for (i = 0; i < N - K + 1; i++)
    {
        range[i] = hight[K - 1 + i] - hight[i];
    }
    int min;
    min = range[0];
    for (i = 0; i < N - K + 1; i++)
    {

        if (range[i] < min)
        {
            min = range[i];
        }
    }
    printf("%d\n", min);
    return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=3005;
int n,m,k,a[N][N],dp[N][N][4];
void chmax(int &a,int b){if(a<b)a=b;}
signed main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m>>k;
	for(int i=1;i<=k;i++)
	{
		int x,y,v;
		cin>>x>>y>>v;
		a[x][y]=v;
	}
	dp[1][1][1]=a[1][1];
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			for(int k=0;k<=3;k++)
			{
				chmax(dp[i+1][j][0],dp[i][j][k]);
				chmax(dp[i][j+1][k],dp[i][j][k]);
				chmax(dp[i+1][j][1],dp[i][j][k]+a[i+1][j]);
				if(k<3) chmax(dp[i][j+1][k+1],dp[i][j][k]+a[i][j+1]);
			}
		}
	}
	cout<<max(max(dp[n][m][0],dp[n][m][1]),max(dp[n][m][2],dp[n][m][3]))<<endl;
	return 0;
}

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

#define N 200123
#define mod 1000000007

int main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    if(fopen("input.in", "r")){
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }
    int n, cnt = 1;
    string s;
    cin >> n;
    cin >> s;
    for(int i = 1 ; i < n ; i++){
    	if(s[i] != s[i-1]) cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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

int main()
{
	int a,b,m;
	cin>>a>>b>>m;
	int A[a+1],B[b+1],x[m+1],y[m+1],c[m+1];
	
	for(int i=1; i<=a; i++)
		cin>>A[i];
	
	for(int i=1; i<=b; i++)
		cin>>B[i];
	
	for(int i=1; i<=m; i++)	
		cin>>x[i]>>y[i]>>c[i];
	
	int sum=0,minv=1000000;
	for(int i=1; i<=m; i++)
	{
		sum+=A[x[i]]+B[y[i]]-c[i];
		if(sum<=0)
		{
			cout<<0<< endl;
			return 0;
		}
		if(sum<minv)
			minv=sum;
		
		sum=0;
	}
	
	sort(A+1,A+a+1);
	sort(B+1,B+b+1);
	int sum_2=A[1]+B[1];
	
	if(sum_2<=minv)
		cout<<sum_2<<endl;
	else
		cout<<minv<< endl;
		
	return 0;
}

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

int dp[2222][2222];
int R[2222][2222];
int S,N,M;
int n;
const int INF = (1000000009);

inline bool update(int &a,int b){
  if( a > b ) { a = b; return true; }
  return false;
}

inline void update(int id,int a,int b,int l,int r){
  int j = (a+b)/2;
  if( a>b ) return;
  int mk = 0;
  for(int k=l;k<=min(j-1,r);k++){
    if( update( dp[id][j], dp[id-1][k] + R[j][k] ) )
      mk = k;    
  }
  if( b-a == 0 ) return;
  update(id,a,j-1,l,mk);
  update(id,j+1,b,mk,r);  
}


inline int solve(){
  fill( dp[0],dp[M+1], INF );
  dp[0][0] = 0;
  for(int i=1;i<=min(N,M);i++){
    update(i,i,N,0,N);      
  }
  return dp[min(M,N)][N];
}

int main(){
  cin >> S >> N >> M;
  int X[2222],Y[2222];
  for(int i=0;i<S;i++) cin >> X[i];
  
  for(int i=0;i<N;i++){
    int t,p; cin >> t >> p; p--;
    Y[i] = t-X[p];
  }

  sort( Y,Y+N );

  fill( R[0], R[M+1], INF );
  for(int i=0;i<N;i++){
    int sum = 0;
    for(int j=i;j>-1;j--){
      sum += Y[i] - Y[j];
      R[i+1][j] = sum;
    }
  }

  cout << solve() << endl;
}

Measured memory_bytes: 38048
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,i;
    string s;
    cin>>k;
    cin>>s;
    if(s.length()<=k)
        cout<<s<<endl;
    else
    {
        for(i=0;i<k;i++)
            cout<<s[i];
        cout<<"..."<<endl;
    }
    return 0;
}


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

typedef long long ll;

int N;

int main(){
    cin >> N;
    vector<ll> A(N),B(N),C(N);
    for(int i=0; i<N; i++) cin >> A[i];
    for(int i=0; i<N; i++) cin >> B[i];
    for(int i=0; i<N; i++) cin >> C[i];
    
    sort(A.begin(), A.end());
    sort(C.begin(), C.end());
    
    ll cnt=0;
    for(int j=0; j<N; j++){
        ll cnt_i=0, cnt_k=0;
        
        cnt_i = lower_bound(A.begin(),A.end(),B[j]) - A.begin();
        cnt_k = C.end() - upper_bound(C.begin(),C.end(),B[j]);
        
        cnt += cnt_i * cnt_k;
        
    }
    
    cout << cnt << endl;
}


Measured memory_bytes: 2560
#インポート
import sys

#入力用
def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def ISS(): return sys.stdin.readline().rstrip().split()
def IS(): return sys.stdin.readline().rstrip()

A, B = ISI()
for i in range(1, 10000):
    if B == 1:
        print(0)
        break
    else:
        sum = A*i-(i-1)
        if sum >= B:
            print(i)
            break

Measured memory_bytes: 3064
a = int(input())    # 500yen
b = int(input())    # 100yen
c = int(input())    # 50yen
x = int(input())

count = 0

while x >= 0 and a >= 0:
    y = x
    bb = b
    while y >= 0 and bb >= 0:
        if 50 * c >= y:
            count += 1
        y = y - 100
        bb -= 1
    x = x - 500
    a = a - 1

print(count)

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

using namespace std;
const int N = 3000;
double dp[N][N],p[N];
int main(){
	int n;
	cin>>n;
	for(int i=1;i<=n;i++) cin>>p[i];
	dp[0][0]=1;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=i;j++){
			dp[i][j]+=dp[i-1][j-1]*p[i];
			dp[i][j-1]+=dp[i-1][j-1]*(1-p[i]);
		}
	}
	double ans=0;
	for(int i=n/2+1;i<=n;i++){
		ans+=dp[n][i];
	}
	//cout<<dp[3][3]<<endl; 
	printf("%.10lf\n",ans);
	return 0;
}

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

int n;
int main()
{
	std::cin >> n;

	long double ans = 0;
	for (int i = 0; i < n; ++i) {
		long double x;
		std::string u;
		std::cin >> x >> u;

		if (u == "JPY")
			ans += x;
		else
			ans += 380000.0*x;
	}

	std::cout << std::fixed << ans << std::endl;
	return 0;
}


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

int main(){
    int N;
    cin >> N;
    vector<long int> H(N);

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

    bool check = true;
    for (int i = 0; i < N-1;i++){
        if(H[i] < H[i+1]){
            check = true;
        }else if(H[i] == H[i+1]){
            check = check;
        }else if(H[i] - 1 == H[i+1] && check == true){
            check = false;
        }else{
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 1024
import sys

import bisect

# from collections import Counter, deque, defaultdict
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd

# import itertools

# from operator import attrgetter, itemgetter
# import math

# import numpy as np

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(input())

    ans = ""
    while abs(n) > 1:
        if n % 2 == 0:
            ans += "0"
            n //= 2
            n *= -1
        else:
            ans += "1"
            n //= 2
            n *= -1

    if n == -1:
        ans += "11"
    else:
        ans += str(n)

    ans = ans[::-1]
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _1_1_a
{
    class Program
    {
        static void Main()
        {

            double r = double.Parse(Console.ReadLine());

            double a =r * r * Math.PI;
            double b =2 * r * Math.PI;
            

            Console.WriteLine("{0} {1}",a.ToString("f5"),b.ToString("f5"));

        }
    }
}


Measured memory_bytes: 17948
import scala.io.StdIn

object Main extends App {

  val s = StdIn.readLine.sorted
  if (s.charAt(0) == s.charAt(1) && s.charAt(2) == s.charAt(3) && s.charAt(1) != s.charAt(2)) {
    println("Yes")
  } else {
    println("No")
  }
}


Measured memory_bytes: 25416
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
const int INF = 1e18, MOD = 1e9 + 7;
template<class T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<class T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
signed main() {
    INCANT;
    int w, h, a;
    cin>>w>>h;
    priority_queue<int> q1;
    rep(i, w){
        cin>>a;
        if(a) q1.push(a);
    }
    rep(i, h){
        priority_queue<int> q2;
        cin>>a;
        while(a > 0){
            if(q1.empty()){
                cout<<0<<endl;
                return 0;
            }
            int tmp = q1.top(); q1.pop();
            tmp--, a--;
            if(tmp) q2.push(tmp);
        }
        while( !q2.empty() ){
            q1.push(q2.top()); q2.pop();
        }
    }
    cout<<1<<endl;
}



Measured memory_bytes: 3240
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		
		String[] strArray = br.readLine().split(" ");
		int[] array = new int[n];
		for(int i = 0; i < n; i++){
			array[i] = Integer.parseInt(strArray[i]);
		}
		
		int count = bubbleSor(array, n);
		
		printArray(array);
		System.out.println(count);
		
	}
	
	static int bubbleSor(int[] array, int n){
		int flag = 1;
		int count = 0;
		while(flag == 1){
			flag = 0;
			for(int j = n - 1; j >= 1; j--){
				if(array[j] < array[j - 1]){
					int tmp = array[j];
					array[j]  = array[j - 1];
					array[j - 1] = tmp;
					flag = 1;
					count++;
				}
			}
		}
		
		return count;
	}
	
	static void printArray(int[] array){
		for(int i = 0; i < array.length ;i++){
			System.out.print(array[i]);
			if(i != array.length - 1){
				System.out.print(" ");
			}
		}
		System.out.println();
	}

}

Measured memory_bytes: 24412
#include<iostream>
#include<iomanip>
#include<vector>
typedef unsigned long long ull;
typedef signed long long sll;
using namespace std;

#define INF 0x7FFFFFFFFFFFFFFF
#define BIG_PRIME 1000000007


int main()
{
  ull i,j,N;
  double p;
  cin >> N;
  vector<vector<double>> dp(N+1);
  dp[0].resize(1);
  dp[0][0]=1;
  for(i=1;i<=N;++i)
  {
    dp[i].resize(i+1);
    cin >> p;
    dp[i][0]=(1-p)*dp[i-1][0];
    for(j=1;j<i;++j)
    {
      dp[i][j]=p*dp[i-1][j-1]+(1-p)*dp[i-1][j];
    }
    dp[i][i]=p*dp[i-1][i-1];
  }
  double sum=0;
  for(i=(N+1)/2;i<=N;++i)
  {
    sum+=dp[N][i];
  }
  cout << setprecision(10) << sum;
  return 0;
}

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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair

#define loop(i,a,b) for(int i=(a);i<ull(b);++i)
#define rep(i,n) loop(i,0,n)

const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

bool pairCompare(const std::pair<double, string>& firstElem, const std::pair<double, string>& secondElem) {
    if(firstElem.first != secondElem.first) return firstElem.first > secondElem.first;
    else return firstElem.second < secondElem.second;
}

int main(){
    int n;
    while(cin >> n, n){
        vector<pair<double, string> > ret;
        for(int q=0; q < n; q++){
                string l;
                double p, a, b, c, d, e, f, s, m;
                cin >> l >> p >> a >> b >> c >> d >> e >> f >> s >> m;
                double time = a + b + c + d + e;
                double amount = f;
                for(int i=0; i< m-1; i++){time += d+e; amount += f;}
                double cost = s*amount-p;
                ret.push_back(make_pair(cost/time, l));
        }
        sort(ret.begin(), ret.end(), pairCompare);
        for(int i=0; i< ret.size(); i++) cout << ret[i].second << endl;
        cout << "#" << endl;
    }
}

Measured memory_bytes: 1248
N, M, Q = list(map(int, input().split()))
a = [0]*Q
b = [0]*Q
c = [0]*Q
d = [0]*Q
for i in range(Q):
  a[i], b[i], c[i], d[i] = list(map(int, input().split()))
li = [1]*11
ans = 0

def countup(l, n, m):
  l[n] += 1
  if l[n] > m:
    if n == 0:
      return
    countup(l, n-1, m)
    l[n] = l[n-1]
  return

while(li[0]==1):
  pt = 0
  for i in range(Q):
    if (li[b[i]]-li[a[i]]==c[i]):
      pt += d[i]
  ans = max(ans, pt)
  countup(li, N, M)

print(ans)

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

const int INF = 1 << 30;

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

  int n,k; cin >> n >> k;
  vector<int> a(n),G[n];
  int ans = 0;
  for(int i = 0; i < n; i++){
    cin >> a[i];
    a[i]--;
    if(a[i] == -1) continue;
    G[a[i]].push_back(i);
  }

  vector<int> d(n,INF);
  function< int(int,int) > rec =
  [&](int u,int par){
    if(G[u].empty()) d[u] = 1;
    else {
      for(auto v : G[u]){
        d[u] = min(d[u],rec(v,0) + 1);
      }
    }
    if(par == -1 || d[u] <= k) ans++;
    return d[u];
  };

  for(int i = 0; i < n; i++){
    if(d[i] == INF){
      if(G[i].empty()) ans++;
      else rec(i,-1);
    }
  }
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 17628
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

using P = pair<ll, ll>;

const ll INF = 1LL << 60;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    ll K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, 0, N) {
        cin >> A[i];
    }
    sort(all(A));
    vector<ll> positive, negative, zero;
    rep(i, 0, N) {
        if (A[i] > 0) {
            positive.push_back(A[i]);
        }
        else if (A[i] < 0) {
            negative.push_back(A[i]);
        }
        else {
            zero.push_back(A[i]);
        }
    }
    ll pos_size = (ll)positive.size();
    ll neg_size = (ll)negative.size();
    ll zero_size = (ll)zero.size();
    rep(i, 0, neg_size) {
        negative[i] *= -1;
    }
    reverse(all(negative));
    // ll pos_cnt = pos_size * (pos_size - 1) / 2 + neg_size * (neg_size - 1) / 2;
    ll neg_cnt = pos_size * neg_size;
    ll zero_cnt = zero_size * (zero_size - 1) / 2 + zero_size * (neg_size + pos_size);
    ll now_cnt = neg_cnt;
    if (now_cnt >= K) {
        // K番目の値は負の値
        ll l = 0, r = INF;
        while (r - l > 1) {
            ll mid = (r + l) / 2;
            // mid以上の積となるペアがK個以上あるか
            ll cnt = 0;
            rep(i, 0, pos_size) {
                auto itr = lower_bound(all(negative), (mid + positive[i] - 1) / positive[i]);
                cnt += (ll)(negative.end() - itr);
            }
            if (cnt >= K) {
                l = mid;
            }
            else {
                r = mid;
            }
        }
        cout << -1 * l << endl;
        return 0;
    }
    now_cnt += zero_cnt;
    if (now_cnt >= K) {
        // K番目の値は0
        cout << 0 << endl;
        return 0;
    }
    // K番目の値は正の値
    K -= now_cnt;
    ll l = 0, r = INF;
    while (r - l > 1) {
        ll mid = (r + l) / 2;
        // mid以下の積となるペアがK個以上あるか
        ll cnt = 0;
        rep(i, 0, pos_size) {
            auto itr = upper_bound(positive.begin() + i + 1, positive.end(), mid / positive[i]);
            cnt += (ll)(itr - positive.begin() - i) - 1;
        }
        rep(i, 0, neg_size) {
            auto itr = upper_bound(negative.begin() + i + 1, negative.end(), mid / negative[i]);
            cnt += (ll)(itr - negative.begin() - i) - 1;
        }
        if (cnt >= K) {
            r = mid;
        }
        else {
            l = mid;
        }
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 4468
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
using namespace std;

set<string> G;
string S[200005];

int main(void) {

	int N;
	cin >> N;

	for (int i = 1; i <= N; i++) {
		cin >> S[i];
		G.insert(S[i]);
	}

	int ans = G.size();

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 25452
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int H, W, h, w;
	cin >> H >> W >> h >> w;
	cout << H*W - h*W - H*w + h*w << endl;
}

Measured memory_bytes: 256
import bisect
import math
import sys
from collections import Counter, defaultdict, deque
from copy import copy, deepcopy
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations
from queue import Queue

read = sys.stdin.read
readline = sys.stdin.readline 
readlines = sys.stdin.readlines 

def SI():
    return int(readline())
def MI():
    return map(int, readline().split())
def MLI():
    return map(int, open(0).read().split())

inf = float("inf")
       
    
def check(k, P, W):
    count = 1
    tmp_sum = 0
    for w in W:
        if tmp_sum + w <= P:
            tmp_sum += w
        else:
            tmp_sum = w
            count += 1
    
    if count <= k:
        return True
    else:
        return False

def main():
    n, k, *W = MLI()
    
    lb = max(W)
    ub = sum(W)
    
    while ub - lb > 1:
        P = (lb + ub) // 2
        if check(k, P, W):
            ub = P
        else:
            lb = P
    
    if check(k, lb, W):
        print(lb)
    else:
        print(ub)
    
                
if __name__ == "__main__":
    main() 


Measured memory_bytes: 18064
import java.util.Scanner;

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

        while(true){
            int m =sc.nextInt();
            int f =sc.nextInt();
            int r =sc.nextInt();

            if(m==-1&&f==-1&&r==-1){
                break;
            }

            if(m==-1 || f==-1){
                System.out.println("F");
            }else{
                if(80<=m+f){
                    System.out.println("A");
                }else{
                    if(m+f<80 && 65 <= m+f){
                        System.out.println("B");
                    }else{
                        if(m+f<65 && 50<=m+f){
                            System.out.println("C");
                        }else{
                            if(m+f<50 && 30<=m+f){
                                if(50<=r){
                                    System.out.println("C");
                                }else{
                                    System.out.println("D");
                                }
                            }else{
                                System.out.println("F");
                            }
                        }
                    }
                }
            }
        }

    }
}


Measured memory_bytes: 26200
from collections import defaultdict

N = int(input())
L = defaultdict(lambda: 0)
R = defaultdict(lambda: 0)
for i, val in enumerate(map(int, input().split())):
  L[i - val] += 1
  R[i + val] += 1
  
cnt = 0
for key, val in L.items():
  if key > 0:
    cnt += L[key] * R[key]
print(cnt)

Measured memory_bytes: 61472
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i, n) for (int i = 0; i < n; i++)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
int dxx[8] = { 1, 1, 1, 0, 0, -1, -1, -1 }, dyy[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main() {
    int A, B, m;
    cin >> A >> B >> m;
    int a[A], b[B], x[m], y[m], c[m];
    int ans = 0, sum = inf;
    rep (i, A) {
        cin >> a[i];
        sum = min (sum, a[i]);
    }
    ans += sum;
    sum = inf;
    rep (i, B) {
        cin >> b[i];
        sum = min (sum, b[i]);
    }
    ans += sum;
    sum = inf;
    rep (i, m) {
        cin >> x[i] >> y[i] >> c[i];
        sum = min (sum, a[x[i] - 1] + b[y[i] - 1] - c[i]);
    }
    ans = min (ans, sum);
    cout << ans << "\n";
}


Measured memory_bytes: 2176
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <map>
#include <numeric>
#define bogo_sort std::sort
#define bozo_sort std::stable_sort
#define alles(obj) obj.begin(), obj.end()
#define elif else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo std::cout <<
#define read std::cin >>
#define endl std::endl
#define fin << '\n'
#define bash push_back
#define makePair std::make_pair
#define _ << ' ' <<
// type-define
#define Stack std::stack
#define Queue std::queue
#define Set std::set
#define PQueue std::priority_queue
#define Vector std::vector
#define Pair std::pair
#define Map std::map
#define Greater std::greater
using String = std::string;
using llong = long long;
using boolean = bool;
using Pii = Pair<int, int>;
using Vi = Vector<int>;
using Vii = Vector<Pii>;
// utils
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    llong power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    llong power ( llong x, llong n ) { return power( x, n, 1000000007 ); }
    llong gcd ( llong x, llong y ) { return x % y ? gcd( y, x % y ) : y; }
    llong lcm ( llong x, llong y ) { return ( x / gcd(x, y) * y ); }
    llong abs ( llong n ) { return ( n < 0 ) ? -n : n; }
    boolean isMovable ( int x, int y, int w, int h ) { 
        return ( x >= 0 && y >= 0 && x < w && y < h ); }
}

#define int long long

namespace Rlyeh {

    int dp[100100][4];
    int data[100100][4];
    int n;

    int dfs(int pos, int prev) {
        if ( pos == n ) return 0;
        if ( ~dp[pos][prev] ) return dp[pos][prev];
        int rec = 0;
        for ( int i = 0; i < 3; i++ ) {
            if ( prev == i ) continue;
            rec = std::max(rec, dfs(pos+1, i)+data[pos][i]);
        }
        return dp[pos][prev] = rec;
    }

    signed call_of_Cthulhu( signed datum ) {

        read n;

        for ( int i = 0; i < n; i++ ) {
            for ( int j = 0; j < 3; j++ ) {
                read data[i][j];
            }
        }

        memset(dp, -1, sizeof(dp));

        int rec = 0;
        for ( int i = 0; i < 3; i++ ) {
            rec = std::max(rec, dfs(0, i));
        }

        echo rec fin;

        return 0;
    }
}

signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); int main_result = Rlyeh::call_of_Cthulhu(114514); return 0;}


Measured memory_bytes: 12800
N = int(input())
K = int(input())

ans = 10**18
for state in range(1 << N):
    now = 1
    for d in range(N):
        if (state & (1 << d)) == 0:
            now *= 2
        else:
            now += K
    ans = min(ans, now)
print(ans)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false); 
    int N, ans = 0;
    cin >> N;
    vector<int> L(2*N);
    for (auto& l:L) {
        cin >> l;
    }
    sort(L.begin(), L.end());
    for (int i = 0; i<N; i++) {
        ans += L[i*2];
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [0]*13
for i in map(int, input().split()):
    a[i] += 1

ans = 0
if not (any(i>2 for i in a) or a[0] or a[12]>1):
    s = [[0]]
    for i in range(1, 13):
        nxt = []
        if a[i] == 0:
            nxt = s
        elif a[i] == 1:
            for si in s:
                nxt.append(si+[i])
                nxt.append(si+[24-i])
        else:
            for si in s:
                nxt.append(si+[i, 24-i])
        s = nxt
    for si in s:
        si.sort()
        tmp = float("Inf")
        for i in range(len(si)):
            k = abs(si[i]-si[i-1])
            k = min(k, 24-k)
            tmp = min(tmp, k)
        ans = max(ans, tmp)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n,m,q;
vvi a;

int main(){
	cin>>n>>m>>q;
	a=vvi(n+1,vi(n+1));
	for(int i=0;i<m;i++){
		int l,r;
		cin>>l>>r;
		a[l][r]++;
	}
	for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) a[i][j]+=a[i-1][j]+a[i][j-1]-a[i-1][j-1];
	for(int i=0;i<q;i++){
		int L,R;
		cin>>L>>R;
		L--;
		cout<<a[R][R]-a[L][R]-a[R][L]+a[L][L]<<endl;
	}
}

Measured memory_bytes: 1920
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define f first
#define s second
#define int long long
int a[222222];
signed main(){
	ic(x) ic(y)
	int ans=0;
	if(x<4)ans+=(4-x)*100000;
	if(y<4)ans+=(4-y)*100000;
	if(x==1&&y==1)ans+=400000;
	c(ans)
}	

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <cstring>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
static const int INF = 1000010000;
static const int MOD = 100000;

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue

//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
	int u, v;
	ll cost;
};

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

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;

const int N=100005;

int n,cnt,last[N],f[N],g[N];
struct edge{int to,next;}e[N*2];

int read()
{
	int x=0,f=1;char ch=getchar();
	while (ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

void addedge(int u,int v)
{
	e[++cnt].to=v;e[cnt].next=last[u];last[u]=cnt;
	e[++cnt].to=u;e[cnt].next=last[v];last[v]=cnt;
}

void dp(int x,int fa)
{
	int mx=-n;
	for (int i=last[x];i;i=e[i].next)
	{
		if (e[i].to==fa) continue;
		dp(e[i].to,x);
		g[x]+=max(g[e[i].to],f[e[i].to]);
		mx=max(mx,g[e[i].to]-f[e[i].to]);
	}
	if (mx>=0) f[x]=g[x]+1;
	else if (mx>-n) f[x]=g[x]+mx+1;
}

int main()
{
	n=read();
	for (int i=1;i<n;i++)
	{
		int x=read(),y=read();
		addedge(x,y);
	}
	dp(1,0);
	if (max(f[1],g[1])==n/2&&!(n&1)) puts("Second");
	else puts("First");
	return 0;
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
#define EPS (1e-10)
#define equal(x,y)  (fabs(x-y)<EPS)
enum Status{
	COUNTER_CLOCKWISE=1,CLOCKWISE=-1,ONLINE_BACK=2,ONLINE_FRONT=-2,ON_SEGMENT=0
};
struct Point{
	double x,y;
	Point(double _x,double _y): x(_x),y(_y){ }
	Point operator+(const Point & p){
		return Point(x+p.x,y+p.y);
	}
	Point operator-(const Point & p){
		return Point(x-p.x,y-p.y);
	}
	Point operator*(double k){
		return Point(k*x,k*y);
	}
};
typedef Point Vector;
double dot(const Vector &v1,const Vector & v2 ){
	return v1.x*v2.x+v1.y*v2.y;
}
double cross(const Vector &v1,const Vector & v2){
	return v1.x*v2.y-v1.y*v2.x;
}
double norm(const Vector & v){
	return dot(v,v);
}
double abs(const Vector & v){
	return sqrt(norm(v));
}
int ccw( Point p1, Point p2,  Point p3){
	Vector v1=p2-p1,v2=p3-p1;
	if(cross(v1,v2)<-EPS) return CLOCKWISE;
	if(cross(v1,v2)>EPS) return COUNTER_CLOCKWISE;
	if(dot(v1,v2)<-EPS) return ONLINE_BACK;
	if(norm(v1)<norm(v2)) return ONLINE_FRONT;
	return ON_SEGMENT;
}
bool intersect(Point p1,Point p2,Point p3,Point p4){
	return (ccw(p1,p2,p3)*ccw(p1,p2,p4)<=0&&
				ccw(p3,p4,p1)*ccw(p3,p4,p2)<=0);
}
int main(){
	double x[4],y[4];
	int q;
	cin>>q;
	for(int i=0;i<q;i++){
		cin>>x[0]>>y[0]>>x[1]>>y[1];
		cin>>x[2]>>y[2]>>x[3]>>y[3];
		cout<< intersect(Point(x[0],y[0]),Point(x[1],y[1]),Point(x[2],y[2]),Point (x[3],y[3])) <<endl;
	}
	return 0;
}


Measured memory_bytes: 3232
import java.util.Scanner;public class Main {public static void main(String[] args){Scanner in= new Scanner(System.in);int a=0,b=0,temp1,temp2,j;while((j=in.nextInt())!=0){a=0;b=0;for(int i=0;i<j;i++){temp1=in.nextInt();temp2=in.nextInt();if(temp1>temp2){a+=temp1+temp2;}else if(temp1==temp2){a+=temp1;b+=temp2;}else{b+=temp1+temp2;}}System.out.printf("%d %d\n",a,b);}}}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define all(obj) (obj).begin(),(obj).end() 
#define dump(x)  cout << #x << " = " << (x) << endl;
typedef long long lint;
using namespace std;
int main(){
	int a,b,c,d,e,k;
	cin>>a>>b>>c>>d>>e>>k;
	cout<<(k<e-a?":(":"Yay!")<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <bitset>
#include <string>
#include <array>
#include <random>
#include <chrono>
#include <algorithm>
#include <unordered_map>
std::vector<std::vector<int>> connection;
std::vector<int> p;
void calc(int node, int add, int parent){
	p[node] += add;
	for(int i=0;i<connection[node].size();i++){
		if(connection[node][i] != parent){
			calc(connection[node][i], p[node], node);
		}
	}
}
int main(void){
	std::string s, t;
	std::cin >> s >> t;
	std::vector<std::vector<int>> pos(26);
	for(int i=0;i<s.size();i++){
		pos[s[i] - 'a'].push_back(i);
	}
	int64_t x = 0;
	for(int i=0;i<t.size();i++){
		int c = t[i] - 'a';
		if(pos[c].size() == 0){
			//無理
			std::cout << -1 << std::endl;
			return 0;
		}
		//1周
		int bestscore = pos[c][0] - x % s.size() + s.size();
		//1周しない
		int start = 0;
		for(int j=0;j<pos[c].size();j+=1000){
			if(x%s.size()>pos[c][j]){
				start = j;
			}
			else{
				break;
			}
		}
		for(int j=start;j<pos[c].size();j+=100){
			if(x%s.size()>pos[c][j]){
				start = j;
			}
			else{
				break;
			}
		}
		for(int i=start;i<pos[c].size();i++){
			if(x%s.size() <= pos[c][i]){
				bestscore = pos[c][i] - x % s.size();
				break;
			}
		}
		x += bestscore+1;
		if(bestscore == s.size() * 10){
			//無理
			std::cout << -1 << std::endl;
			return 0;
		}
	}
	std::cout << x << std::endl;
}

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

const int M = 1000000007;

vector<int> grp, val;
vector<vector<int>> lis;
void init(int n) {
    grp.resize(n);
    val.resize(n, 0);
    lis.resize(n);
    for (int i = 0; i < n; ++i) {
        grp[i] = i;
        lis[i].push_back(i);
    }
}
void merge(int p, int q, int w) {
    if (grp[p] == grp[q]) return;
    if (lis[grp[p]].size() < lis[grp[q]].size()) {
        merge(q, p, -w);
        return;
    }
    int d = w + val[p] - val[q];
    int g = grp[q];
    for (int i : lis[g]) {
        grp[i] = grp[p];
        val[i] += d;
        lis[grp[p]].emplace_back(i);
    }
    lis[g].clear();
}

int main() {
    while (1) {
        int n, m;
        cin >> n >> m;
        if (!n) return 0;
        init(n);
        for (int i = 0; i < m; ++i) {
            char c;
            cin >> c;
            if (c == '!') {
                int p, q, w;
                cin >> p >> q >> w;
                merge(p - 1, q - 1, w);
            }
            else {
                int p, q;
                cin >> p >> q;
                --p;
                --q;
                if (grp[p] != grp[q])
                    puts("UNKNOWN");
                else
                    printf("%d\n", val[q] - val[p]);
            }
        }
        for (int i = 0; i < n; ++i)
            lis[i].clear();
    }
}

Measured memory_bytes: 10444
N,M=map(int,input().split())
AB=[[0,0] for i in range(N)]
for i in range(N):
    AB[i][0],AB[i][1]=map(int,input().split())
AB.sort(key=lambda x:x[0])
ans=0
number=0
i=0
while number<M:
    if number+AB[i][1]<M:
        ans+=AB[i][0]*AB[i][1]
        number+=AB[i][1]
    else:
        break
    i+=1
ans+=(M-number)*AB[i][0]
print(ans)


Measured memory_bytes: 21156
def main():
    from builtins import int, map, list, print
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = sys.stdin.readline
    input_list = (lambda: input().rstrip().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    a,b = input_list()
    t = int(a+b)
    root = t**0.5
    print('YNeos'[root%1!=0::2])

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <stack>

using namespace std;

class Node {
public:
	vector<int> rels;
	int id, len, pos, ts1, ts2;
	Node();
	int next();
};

Node::Node() {
	pos = ts1 = ts2 = 0;
}

int Node::next() {
	if (pos >= len) return -1;
	int next = rels[pos];
	pos++;
	return next;
}


void dfs(int idx, Node **graph, stack<int> *stack, int *time) {
	stack->push(idx);
	graph[idx]->ts1 = ++(*time);
	while (stack->size() > 0) {
		int u = stack->top();
		int v = graph[u]->next();
		if (v != -1) {
			if (graph[v]->ts1 == 0) {
				graph[v]->ts1 = ++(*time);
				stack->push(v);
			}
		}
		else {
			graph[u]->ts2 = ++(*time);
			stack->pop();
		}
	}
}

int main() {
	int n, val, time;
	Node *graph[100];
	stack<int> stack;

	cin >> n;
	
	for (int i = 0; i < n; i++) {
		graph[i] = new Node();
		cin >> graph[i]->id;
		cin >> graph[i]->len;
		for (int j = 0; j < graph[i]->len; j++) {
			cin >> val;
			graph[i]->rels.push_back(val-1);
		}
	}

	time = 0;
	for (int i = 0; i < n; i++) {
		if (graph[i]->ts1 == 0)
			dfs(i, graph, &stack, &time);
	}


	for (int i = 0; i < n; i++) {
		cout << graph[i]->id << " " << graph[i]->ts1 << " " << graph[i]->ts2 << endl;
	}

	for (int i = 0; i < n; i++)
		delete(graph[i]);


	return 0;	
}



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

bool f[8];

void cB(int b[8][8], int i, int j, int d) {
	int k;

	for (k = 0; k < 8; k++) {
		b[i][k] += d;
		b[k][j] += d;
		if (j - i + k > -1 && j - i + k < 8)
			b[k][j - i + k] += d;
		if (j + i - k > -1 && j + i - k < 8)
			b[k][j + i - k] += d;
	}
}

void setQ(int a[8], int b[8][8], int i) {
	int j;

	if (i == 8) {
		for (int i2 = 0; i2 < 8; i2++) {
			for (int j2 = 0; j2 < 8; j2++) {
				if (a[i2] == j2)
					cout << "Q";
				else
					cout << ".";
			}
			cout << endl;
		}
		return;
	}

	for (j = 0; j < 8; j++) {
		if (b[i][j] == 0) {
			a[i] = j;
			cB(b, i, j, 1);
			int t = 1;
			while (f[i + t])
				t++;
			setQ(a, b, i + t);
			cB(b, i, j, -1);
		}
	}
}

int main()
{
	int k, r, c;
	int a[8];
	int b[8][8];

	memset(b, 0, sizeof(b));
	memset(f, 0, sizeof(f));

	cin >> k;

	for (int i = 0; i < k; i++) {
		cin >> r >> c;
		a[r] = c;
		f[r] = 1;
		cB(b, r, c, 1);
	}

	int t = 0;
	while (f[t])
		t++;
	setQ(a, b, t);

	return 0;
}


Measured memory_bytes: 3120
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    Long W = sc.nextLong(); 
    Long H = sc.nextLong(); 
    Long x = sc.nextLong(); 
    Long y = sc.nextLong(); 
    int b = 0;
    if((double)W/2.0==(double)x && (double)H/2.0==(double)y){
      b = 1;
    }
    double ans = (double)(W*H)/2.0;

    System.out.println(ans+" "+b);    
  
  }
}




Measured memory_bytes: 21844
s = int(input())
if s == 1 or s == 2:
    print(4)
else:
    res = 1
    while True:
        if s == 4:
            break
        else:
            if s % 2 == 0:
                s = s // 2
            else:
                s = 3 * s + 1
            res += 1

    print(res+3)

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

using namespace std;

int main(){
	long long x,ans = 0;

	cin >> x;

	ans = x / 11;
	ans *= 2;
	x %= 11;
	
	if(x > 6)ans += 2;
	else if(x > 0) ans += 1;
	
	cout << ans <<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
   int i,n,a=0,b;
   scanf("%d",&n); //120
   b=n;
   for(i=0;i<10;i++){
      a+=n%10;
      n=n/10;
   }
   if(b%a==0){
      printf("Yes\n");
   } 
   else
      printf("No\n");
   return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main()
{
    double x1, y1, x2, y2;

    cin >> x1 >> y1 >> x2 >> y2;

    cout << fixed << setprecision(8) << sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) << endl;

    return 0;
}

Measured memory_bytes: 1284
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}

int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    ll n;cin>>n;
    string s;cin>>s;
    ll dp[n][n];
    memset(dp,0,sizeof dp);
    rep(i,0,n){
        dp[0][i]=1;
    }
    rep(i,0,n-1){
        ll sum[n];
        sum[0]=dp[i][0];
        rep(j,1,n)sum[j]=(sum[j-1]+dp[i][j])%mod;
        if(s[i]=='>'){
            rep(j,0,n-i-1)dp[i+1][j]=sum[j];
        }
        else{
            rep(j,0,n-i-1)dp[i+1][j]=(sum[n-1]-sum[j]+mod)%mod;
            
        }
    }
    cout<<dp[n-1][0]<<endl;
   // rep(i,0,n){
       // rep(j,0,n)cout<<dp[i][j]<<" ";
       // cout<<endl;
  //  }
}


Measured memory_bytes: 70656
//

#include <iostream>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <vector>
#include <numeric>
#include<string>

using namespace std;

#define ll long long
#define rep(cnt,a,n) for(ll cnt=a;cnt<n+a;cnt++) //aから始めてn回ループ
#define vector2(type,name,a,b) vector<vector<type>> name(a, vector<type>(b))
#define PI 3.141592653589793



int main() {
    char alp;
    cin >> alp;
    if (alp >= 'A' && alp <= 'Z') {
        cout << "A" << endl;
    }
    else {
        cout << "a" << endl;
    }

    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

int N, K;
double t[100120];

int main() {
  while (cin >> N >> K) {
    memset(t, 0, sizeof(t));
    for (int i = K; i >= 1; i--) {
      if (i >= K) {
	t[i] = 1.0;
      } else if (i*2 >= K) {
	t[i] = 0.5;
      } else {
	t[i] = t[i*2] / 2;
      }
    }
    double sum = 0.0;
    for (int i = 1; i <= N; ++i) {
      if (i >= K) {
	sum += 1.0;
      } else {
	sum += t[i];
      }
    }
    printf("%.012f\n", sum / N);
  }
}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
"""
Created on Sun Aug 26 11:25:55 2018

@author: maezawa
"""

n, m = list(map(int, input().split()))
a = []
b = []
for i in range(n):
    a.append(input())
for i in range(m):
    b.append(input())

yesno = 0
for x in range(n-m+1):
    for y in range(n-m+1):
        flag = 0
        i = 0
        while a[x+i][y:y+m] == b[i]:
            #print((x,y), i, a[x+i][y:y+m], b[i])
            i += 1
            if i == m:
                flag = 1
                break
        if flag == 1:
            yesno = 1
            break
    if yesno == 1:
        break
    
if yesno == 1:
    print('Yes')
else:
    print('No')    

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define fi first
#define se second
long long mo = 1000000007;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
typedef pair<ll,Pll> PlP;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;
using namespace atcoder;

struct S{
    ll zero, one, inverse;
};

struct F{
    bool a;
};

S op(S a, S b) {
    return S{a.zero + b.zero, a.one + b.one, a.inverse + b.inverse + (a.one*b.zero)};
}

S e() {
    return S{0LL,0LL,0LL};
}

S mapping(F f, S x){
    if(!(f.a)) return x;
    return S{x.one, x.zero, x.one*x.zero-x.inverse};
}

F composition(F f, F g){
    return F{((f.a && !(g.a)) || ((!f.a)&&g.a))};
}

F id(){
    return F{false};
}

int main(){
    ll N,Q;
    cin >> N >> Q;
    vector<S> A(N);
    ll a;
    rep(i,N){
        cin >> a;
        if(a == 0){
            A[i] = S{1LL,0LL,0LL};
        }else{
            A[i] = S{0LL,1LL,0LL};
        }
    }
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(A);
    vector<int> T(Q), L(Q), R(Q);
    rep(i,Q){
        cin >> T[i] >> L[i] >> R[i];
        L[i]--;
    }
    rep(i,Q){
        if(T[i] == 1){
            seg.apply(L[i], R[i], F{true});
        }else{
            cout << seg.prod(L[i], R[i]).inverse << endl;
        }
    }
}

Measured memory_bytes: 22836
import sys
from itertools import combinations

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    _ = int(rl())
    L = list(map(int, rl().split()))
    L.sort()
    ans = 0
    for li, lj, lk in combinations(L, 3):
        ans += li < lj < lk < li + lj
    print(ans)


if __name__ == '__main__':
    solve()


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

using namespace std;

struct Dice
{
  int x, y;
  int l, r, f, b, d, u;

  void RollF()
  {
    --y;
    int buff = d;
    d = f;
    f = u;
    u = b;
    b = buff;
  }

  void RollB()
  {
    ++y;
    int buff = d;
    d = b;
    b = u;
    u = f;
    f = buff;
  }

  void RollL()
  {
    --x;
    int buff = d;
    d = l;
    l = u;
    u = r;
    r = buff;
  }

  void RollR()
  {
    ++x;
    int buff = d;
    d = r;
    r = u;
    u = l;
    l = buff;
  }
};


int main()
{
  Dice dice;
  cin >> dice.u;
  cin >> dice.f;
  cin >> dice.l;
  cin >> dice.r;
  cin >> dice.b;
  cin >> dice.d;

  string S;
  cin >> S;
  for(char &c : S) {
    if(c == 'S') dice.RollF();
    else if(c == 'N') dice.RollB();
    else if(c == 'W') dice.RollR();
    else dice.RollL();
  }

  cout << dice.u << endl;
}

Measured memory_bytes: 3144
#include <vector> // vectorを使うためにインクルードする
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;

string change(string s,int t){
	int sit = s.size();
	string news;
	for(int i=0;i<sit-1;i++){
		if(i == sit-1){

			if(s[i]==t){
				news.push_back(t);
			}
			else{news.push_back(s[i]);}
		}
		else{
		if(s[i]==t|s[i+1]==t){
			news.push_back(t);
		}
		else{news.push_back(s[i]);}
	}
}
	return news;
}


int coun(string s,int t,int c){
	int sit = s.size();
	int p =0;
  for(int i=0;i<sit;i++){
		if(s[i]!=t)break;
		if(i==sit-1)p=1;
	}
	if(p==1)return c;
	else{
		string tpp;
		tpp=change(s,t);
		s = tpp;
		c++;
		return coun(s,t,c);
	}
}


int main() {
	string s;
	cin >> s;
	int se = s.size();
  if(se==1)  cout << 0 <<endl;
  else{

	set<int> st;
	for(int i=1;i<se;i++){
		st.insert(s[i]);
	}
	int setn = st.size();
	int ans = 1000000000;
	auto itr = st.begin();
	for(int i =0;i<setn;i++){
		int c = coun(s,*itr,0);
		if(c<ans){
			ans = c;
		}
		++itr;
	}
  cout << ans <<endl;
}
	return 0;
	}


Measured memory_bytes: 256