akhauriyash/Code-Regression huggingface dataset:
N,L=map(int,input().split())
if 0<=L:
  count1=0
  for i in range(L+1,L+N):
    count1+=i
  print(count1)
elif L+N-1<=0:
  count2=0
  for j in range(L,L+N-1):
    count2+=j
  print(count2)
else:
  count3=0
  for k in range (L,L+N):
    count3+=k
  print(count3)
  

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<n;++i)
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
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; }
//max=({});
//条件式が真ならwhileの中身を回し続ける
//printf("%d\n", ans);

//pairの入力
//vector<pair<ll, ll>>work(n);
//rep(i, n) {
//	ll a, b;
//	cin >> a >> b;
//	work[i] = make_pair(a, b);
//for(auto p:mp)(mapの探索)
//printf("%.10f\n",なんちゃら)

int g[15][15];
const int INF = 1001001001;
const int dx[4] = { -1,0,1,0 };
const int dy[4] = { 0,-1,0,1 };

//最大公約数
ll gcd(ll x, ll y) {
	return y ? gcd(y, x % y) : x;
}

ll lcm(ll x, ll y) {
	if (x == 0 || y == 0)return 0;
	return (x / gcd(x, y) * y);
}

//素因数分解
vector<pair<ll, int>>factorize(ll n) {
	vector<pair<ll, int>>res;
	for (ll i = 2;i * i <= n;++i) {
		if (n % i)continue;
		res.emplace_back(i, 0);
		while (n % i == 0) {
			n /= i;
			res.back().second++;
		}
	}
	if (n != 1)res.emplace_back(n, 1);
	return res;
}

int bingo[3][3];
int cnt[2][105];
int h, w;
bool flag[110][110];

int main() {
	ll n, k;
	cin >> n >> k;
	ll target = n % k;
	ll ans = min(target, abs(k - target));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, f[200100];

int main() {
    cin >> n;
    for (int i = 1; i < n; i++) {
        int value;
        cin >> value;
        f[value]++;
    }

    for (int i = 1; i <= n; i++)
        cout << f[i] << '\n';
    return 0;
}


Measured memory_bytes: 4376
#include <bits/stdc++.h>
#define rep(i, a, b) for (long long i = (a); i < (b); i++)
#define rep2(r, aa, bb) for (long long r = (aa); r >= (bb); r--)
using namespace std;

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,count=0;
      string s;
      cin>>s;
      for(i=0;i<s.size();i++)
      {
          if(i%2==0)
          {

              if(s[i]=='R' || s[i]=='U' || s[i]=='D')
              {
                 // cout<<s[i];
                  count++;
              }
          }
          else{
            if(s[i]=='L' || s[i]=='U' || s[i]=='D')
                count++;
          }
      }
      //cout<<count<<" "<<s.size();
      if(count==s.size())
      {
          cout<<"Yes";
      }
      else
        cout<<"No";
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

int main()
{
    int m, n;

    cin >> m;
    
    string s, t;
    int ss=0, tt=0;

    for (int j = 0; j < m; ++j) {

        cin >> s >> t;

        n = min(s.size(), t.size());

        for (int i = 0; i < n; ++i) {
            if (s[i] < t[i]) { tt += 3; break; }
            if (s[i] > t[i]) { ss += 3; break; }
        }

        if (s.substr(0, n) == t.substr(0, n)) {
            if (s.size() > t.size()) { ss += 3; }
            if (s.size() < t.size()) { tt += 3; }
        }

        if (s == t) { ss += 1; tt += 1; }

    }

    cout << ss << " " << tt << endl;

}


Measured memory_bytes: 3216
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

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

int main() {
  int n;
  cin >> n;
  map<int, int> ans = prime_factor(n);
  cout << n << ":";
  for (auto a : ans) {
    REP(i, a.second) cout << " " << a.first;
  }
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3084
#include <iostream>
#include <algorithm>
#include <vector>

using lint = long long;
constexpr lint INF = 1LL << 60;

void solve() {
    int n;
    lint k;
    std::cin >> n >> k;

    std::vector<lint> xs(n);
    for (auto& x : xs) std::cin >> x;
    std::sort(xs.begin(), xs.end());

    auto rxs = xs;
    std::sort(rxs.rbegin(), rxs.rend());

    lint ok = INF, ng = -INF;
    // ok以下がk個以上
    while (ok - ng > 1) {
        lint mid = (ok + ng) / 2;

        lint cnt = 0;
        for (int i = 0; i < n; ++i) {
            if (xs[i] >= 0) {
                int iok = n, ing = -1;
                while (iok - ing > 1) {
                    int imid = (iok + ing) / 2;
                    (xs[i] * xs[imid] > mid ? iok : ing) = imid;
                }
                cnt += iok;

            } else {
                int iok = n, ing = -1;
                while (iok - ing > 1) {
                    int imid = (iok + ing) / 2;
                    (xs[i] * rxs[imid] > mid ? iok : ing) = imid;
                }
                cnt += iok;
            }
            if (xs[i] * xs[i] <= mid) --cnt;
        }
        cnt /= 2;
        (cnt >= k ? ok : ng) = mid;
    }

    std::cout << ok << std::endl;
}

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

    solve();

    return 0;
}


Measured memory_bytes: 3456
// Package main provides
//
// File:  main.go
// Author: ymiyamoto
//
// Created on Tue Jan 28 20:51:39 2020
//
package main

import "fmt"

var N, M int

func main() {
	fmt.Scan(&N, &M)
	if N == M {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<iomanip>
#include<string>
using namespace std;
typedef long long ll;
typedef long double ld;
bool judge(string s){
  ll n=s.length();
  for(int i=0;i<n;i++){
    if(s[i]!=s[n-i-1]){
      return false;
    }
  }
  return true;
}
int main(){
  ld L;
  cin>>L;
  L/=3;
  cout<<fixed<<setprecision(10)<<L*L*L<<endl;
}


Measured memory_bytes: 256
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn solve(n: i64) -> u64 {
    if n == 0 {
        return 0;
    }

    let mut ans = 0u64;
    let mut tmp = n;

    if (n > 0 && n%4 == 1) || (n < 0 && (-n)%4 == 3) {
        ans += 1;
        tmp -= 1;
    } else if (n > 0 && n%4 == 3) || (n < 0 && (-n)%4 == 1) {
        ans += 3;
        tmp += 1;
    }

    ans + solve(- tmp / 2) * 2
}

fn main() {
    let n:i64 = read_line().trim().parse().unwrap();
    let m = solve(n);

    let mut ans = String::new();
    let mut tmp = 1;
    while m >= tmp {
        if m & tmp > 0 {
            ans = "1".to_owned() + &ans;
        } else {
            ans = "0".to_owned() + &ans;
        }
        tmp *= 2;
    }

    if ans.is_empty() {
        ans = "0".to_owned();
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
 
int C[1000];
 
int main() {
	LL q, h, s, d, n;
	cin >> q >> h >> s >> d >> n;
	LL min1 = min({ q * 4,h * 2,q * 2 + h,s });
	LL min2 = min(min1*2, d);
	cout << (n / 2)*min2 + (n % 2 == 0 ? 0: min1) << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), sum = 0;
		int x[] = new int[n];
		for(int i = 0; i < n; ++i){
			x[i] = sc.nextInt();
			sum += x[i];
		}
		int min = sum / n;
		double ave = (double) sum / (double) n;
		min = (Math.abs(ave - (double)min) <= Math.abs(ave - (double)(min + 1)) ? min : min + 1);
		int ans = 0;
		for(int i = 0; i < n; ++i){
			ans += (x[i] - min) * (x[i] - min);
		}
		sc.close();
		System.out.println(ans);
	}
}


Measured memory_bytes: 21844
import java.util.Scanner;

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

		String[][] S = new String[H][W];
		for(int i = 0; i < H; i++) {
			S[i] = sc.next().split("");
		}

		int count = 0;
		for(int i = 0; i < H; i++) {
			for(int j = 0; j < W; j++) {
				count = 0;
				if(S[i][j].equals("#")) {
					continue;
				}

				if(j -1 >= 0) {
					if(i -1 >= 0 && S[i-1][j-1].equals("#")) count++;
					if(             S[i  ][j-1].equals("#")) count++;
					if(i +1 <  H && S[i+1][j-1].equals("#")) count++;
				}

				if(i -1 >= 0 && S[i-1][j].equals("#")) count++;
				if(i +1 <  H && S[i+1][j].equals("#")) count++;

				if(j +1 < W) {
					if(i -1 >= 0 && S[i-1][j+1].equals("#")) count++;
					if(             S[i  ][j+1].equals("#")) count++;
					if(i +1 < H  && S[i+1][j+1].equals("#")) count++;
				}

				S[i][j] = ""+count;
			}
		}

		for(int i = 0; i < H; i++) {
			System.out.println(String.join("", S[i]));
		}
	}
}


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

        final long A = Long.parseLong(sc.next());
        final long B = Long.parseLong(sc.next());
        final int K = Integer.parseInt(sc.next());
 
        if (B - A + 1 >= 2 * K) {
            for (int i = 0; i < K; i++) {
                out.println(A + i);
            }
            for (int i = K - 1; i >= 0; i--) {
                out.println(B - i);
            }
        } else {
            for (long i = A; i <= B; i++) {
                out.println(i);
            }
        }
          
        out.flush();
    }
}

Measured memory_bytes: 22224
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(void){
   int X,A,B;
   cin>>X>>A>>B;
   int Q=(X-A)/B;
   int ans=(X-A)-B*Q;
   
   cout<<ans<<endl;
  
}

Measured memory_bytes: 3564
import sys
sys.setrecursionlimit(10000000)
n,m,k=map(int,input().split())
stock=[[] for i in range(n)]
ter=[0]*n
ans=[0]*n
for i in range(m):
    a,b=map(int,input().split())
    stock[a-1].append(b-1)
    stock[b-1].append(a-1)
    ans[a-1]-=1
    ans[b-1]-=1
def dfs(j,k):
    size[k]+=1
    for next_j in stock[j]:
        if ter[next_j]==0:
            ter[next_j]=k
            dfs(next_j,k)
total=0
size=[0]*(n+1)
for i in range(n):
    if ter[i]==0:
        total+=1
        ter[i]=total
        dfs(i,total)

for i in range(n):
    ans[i]+=size[ter[i]]-1
for i in range(k):
    c, d = map(int, input().split())
    if ter[c-1]==ter[d-1]:
        ans[c-1]-=1
        ans[d-1]-=1
for i in range(n-1):
    print(ans[i],end=" ")
print(ans[n-1])



Measured memory_bytes: 49768
#include<iostream>
#include<cstdint>
#include<algorithm>
#include<vector>

void divisors(int64_t n, std::vector<int64_t>& res) {
  res.clear();
  for(int64_t i = 1; i*i <= n; ++i) {
    if(n%i == 0) {
      if(i != 1) res.push_back(i);
      if(i*i != n) res.push_back(n/i);
    }
  }
}


bool check(int64_t n, int64_t d) {
//std::cout << "d = " << d << std::endl;
  while(n%d==0) n/=d;
  n%=d;
  return n==1;
}

int main() {
  int64_t N; std::cin >> N;
  std::vector<int64_t> v;
  divisors(N-1, v);
  int ans = v.size();
  divisors(N, v);
  for(auto d: v) if(check(N, d)) ++ans;
  std::cout << ans << std::endl;
  return 0;
}


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

namespace AtCoder_solve
{
    class Program
    {
        public const ulong mod = 1000000007;

        static void Main(string[] args)

        {
            var n = Input();
            var a = Input3();
            double sum = 0;
            var mel = 1;
            double ans = 0;
            
            for(long i = 0; i < n; i++)
            {
                sum +=(double) 1 / a[i];
            }

            ans = 1/ sum;

            Console.WriteLine(ans);
                
                





        }

       
        static public long Input()
        {
            return long.Parse(Console.ReadLine());
        }

        static public string[] Input2()
        {
            return Console.ReadLine().Split();
        }

        static public long[] Input3()
        {
            string[] data = Console.ReadLine().Split();
            long[] res = new long[data.LongLength];
            for(long i = 0; i < data.LongLength; i++)
            {
                res[i] = long.Parse(data[i]);
            }
            return res;
        }
        public static long Choose(long n, long a)
        {
            long x = 1;
            long y = 1;
            for (long i = 0; i < a; i++)
            {
                x *= n - i;
                y *= i + 1;
            }
            return x / y;
        }

        public static long Gcd(long a, long b)
        {
            long x = Math.Max(a, b);
            long y = Math.Min(a, b);
            if (x % y == 0) return y;
            else return Gcd(y, x % y);
        }
    }
}


Measured memory_bytes: 13140
#include<stdio.h>
int main(){
  long long l,r,i=0;
  int mod,mod1,mod2,min=2019;
  scanf("%lld%lld",&l,&r);
  while((l+i)<r && i<2019){
    int j=1;
    while((l+i+j)<=r && i+j<2019){
      mod1=(l+i)%2019;
      mod2=(l+i+j)%2019;
      mod=(mod1*mod2)%2019;
      if(mod<min)
        min=mod;
      j++;
    }
    i++;
  }
  printf("%d\n",min);
  return 0;
}


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

int main() {
  int N, K;
  
  cin >> N;
  cin >> K;
  
  vector<int> x(N);
  for (int i = 0; i < N; i++){
    cin >> x.at(i);
  }
  
  int sum = 0;
  for (int i = 0; i < N; i++){
    if (K - x.at(i) < x.at(i)){
      sum += K - x.at(i);
    } else {
      sum += x.at(i);
    }
  }
  
  cout << 2 * sum << endl;
}

Measured memory_bytes: 256
N, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(N)]
INF = 10 ** 9


def dfs(cur, a, b, c):
    if cur == N:
        return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF
    retNO = dfs(cur + 1, a, b, c)
    retA = dfs(cur + 1, a + l[cur], b, c) + 10
    retB = dfs(cur + 1, a, b + l[cur], c) + 10
    retC = dfs(cur + 1, a, b, c + l[cur]) + 10
    return min(retNO, retA, retB, retC)


print(dfs(0, 0, 0, 0))

Measured memory_bytes: 3064
import bisect
def main():
  X, N = map(int, input().split())
  if N == 0:
    print(X)
    return
  P = set(map(int, input().split()))

  NP = sorted(list(set(range(-1,102)) - P))
  right = bisect.bisect(NP, X)
  left = right - 1
  if abs(X - NP[left]) > abs(X - NP[right]):
    print(NP[right])
  else:
    print(NP[left])

main()


Measured memory_bytes: 9132
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<bitset>
#include<cmath>
#include<queue>
#include<map>
#include<set>

using namespace std;

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

const int N=1e6+5;
int n,vis[N];

int main()
{
	n=read();
	for(int i=1;i<=n-1;++i)
		vis[read()]++;
	for(int i=1;i<=n;++i)
		printf("%d\n",vis[i]);
	return 0;
}

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

const long long mod = 998244353;

long long modpow(long long a, long long b) {
    if (b == 0) return 1;
    return modpow(a * a % mod, b / 2) * (b & 1 ? a : 1) % mod;
}

long long modinv(long long a) {
    return modpow(a, mod - 2);
}

inline long long  inverse(long long  a, long long  m) {
    long long  b = m, u = 1, v = 0;
    while (b) {
        long long  t = a / b;
        swap(a -= t * b, b);
        swap(u -= t * v, v);
    }
    return (u % m + m) % m;
}


vector<long long> fact, inv_fact;
void init_fact(long long n) {
    fact.resize(n);
    fact[0] = 1;
    for (long long i = 1; i < n; i++) {
        fact[i] = i * fact[i - 1] % mod;
    }
    inv_fact.resize(n);
    inv_fact[n - 1] = inverse(fact[n - 1], mod);
    for (long long i = n - 2; i >= 0; i--) {
        inv_fact[i] = (i + 1) * inv_fact[i + 1] % mod;
    }
}

long long nPr(long long n, long long r) {
    if (n < r || n < 0 || r < 0) return 0;
    return fact[n] * inv_fact[n - r] % mod;
}

long long nCr(long long n, long long r) {
    if (n < r || n < 0 || r < 0) return 0;
    return fact[n] * inv_fact[r] % mod * inv_fact[n - r] % mod;
}

long long nHr(long long n, long long r) {
    if (n == 0 && r == 0) return 1;
    return nCr(n + r - 1, r);
}


long long factorial(long long k){
    long long sum = 1;
    for(long long i=1; i<=k; ++i){
        sum *= i;
    }
    return sum;
}

int main(void){
    long long N, A, B, K;
    long long ret;
    cin >> N >> A >> B >> K;
    init_fact(N+1);
    for(long long i=0; i<=K/A; ++i){
        long long j;
        if((K - A*i) % B == 0) j = (K - A*i) / B;
        else continue;

        ret += nCr(N, i) * nCr(N, j);
        ret %= mod;

        // cout << "find:" << i << ' ' << j << endl;
        // i, jをもとに色のパターンを決める
        // long long z = min(i, j);
        // long long x = i-z; long long y = j-z;
        // while(x + y + z <= N && z >= 0){
        //     // cout <<"N:" << N << " 赤:" << x << " 青:" << y << " 緑:" << z << ' ' << endl;
        //     // cout << nCr(N, x+y+z) << ' ' << nCr(x+y+z, y+z) << ' ' << nCr(y+z, y) << endl;
        //     ret += nCr(N, x+y+z) * nCr(x+y+z, x) * nCr(y+z, z);
        //     ret %= 998244353;
        //     x += 1; y += 1;
        //     z -= 1;
        // }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 4992
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};
const MOD : i64 = 1e9 as i64 + 7;

fn main() {
    input!{
      h: usize,
      w: usize,
      k: usize,
    }
    let mut dp = vec![vec![0; w+1]; h+1];
    dp[0][1] = 1;
    for hi in 0..h {
        for wi in 1..w+1 {
            if dp[hi][wi] == 0 { continue; }
            for bit in 0..(1 << w - 1) {
                let mut ok = true;
                for i in 0..w as i64 -2 {
                    if (bit >> i) & 1 == 1 && (bit >> (i+1)) & 1 == 1 { ok = false };
                }
                if ok {
                    if wi < w && 1 << ((wi - 1)) & bit > 0 {
                        dp[hi+1][wi+1] = (dp[hi+1][wi+1] + dp[hi][wi]) % MOD;
                    } else if wi > 1 && (1 << (wi - 2)) & bit > 0 {
                        dp[hi+1][wi-1] = (dp[hi+1][wi-1] + dp[hi][wi]) % MOD;
                    } else {
                        dp[hi+1][wi] = (dp[hi+1][wi] + dp[hi][wi]) % MOD;
                    }
                }
            }
        }
    }
    println!("{}", dp[h][k]);
}


Measured memory_bytes: 4352
import Control.Applicative ((<$>), (<*>), (<*), (*>), (<$))
import Control.Monad
import Data.List

main :: IO ()
main = do
  solve <$> getLine >>= putStrLn

solve :: String -> String
solve s
  | null ci = "No"
  | null fi = "No"
  | head ci < last fi = "Yes"
  | otherwise = "No"
  where
    ci = elemIndices 'C' s
    fi = elemIndices 'F' s


Measured memory_bytes: 508
#define _CRT_SECURE_NO_WARNINGS

#include <vector>
#include <iostream>
#include <string>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <ctime>
#include <queue>
#include <deque>
#include <math.h>
#include <cmath>
#include <stack>
#include <algorithm>
#include <list>
#include <array>
#include <valarray>
#include <unordered_map>
#include <cassert>
#include <random>
#include <cstring>
#include <sstream>

using namespace std;

typedef long long li;
typedef pair<int, int> pii;

#define X first
#define Y second
#define all(a) a.begin(), a.end()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)

double eps = 1e-5;
const int INF = 2e9 + 7;
const li LINF = 9e18 + 7;

bool flag;

bool check(int i) {
	cout << i << endl;

	string s;
	cin >> s;

	if (s == "Vacant")
		exit(0);
	
	if (flag) {
		return (s == "Female" && i % 2 == 0 || s == "Male" && i % 2);
	}
	else {
		return (s == "Female" && i % 2 || s == "Male" && i % 2 == 0);
	}
}

int main() {
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif

	int n;
	cin >> n;

	cout << 0 << endl;

	string s;
	cin >> s;

	if (s == "Vacant")
		return 0;

	flag = (s == "Female");

	int l = 1, r = n - 1;
	while (r - l > 1) {
		int m = (r + l) >> 1;

		if (check(m)) {
			l = m;
		}
		else {
			r = m;
		}
	}

	for (int i = l; i <= r; ++i) {
		check(i);
	}

}

Measured memory_bytes: 852
#include<bits/stdc++.h>
using namespace std;
int n, x, ans;
char a[200005];

int main()
{
	scanf("%s",a+1);
	n = strlen(a+1);
	for(int i=1;i<=n;i++) {
		if(a[i] == 'T') if(x) {x--; ans++;}
		if(a[i] == 'S') x++;
	}
	printf("%d\n",n-2*ans);
}


Measured memory_bytes: 384
#include<stdio.h>
int main()
{
	int a;
	char s[10];
	scanf("%d",&a);
	scanf("%s",&s);
	if(2800<=a && a < 5000)
	{
		if(a >= 3200)
		{
			printf("%s",s);
		}
			else
		{
			printf("red\n");
		}
	}

return 0;
}

Measured memory_bytes: 128
loop do
  n = gets.to_i
  break if n == 0

  points = [[0, 0]]
  directions = [
    [-1, 0],
    [0, 1],
    [1, 0],
    [0, -1]
  ]
  (n-1).times do
    neighbor, d = gets.split.map(&:to_i)
    # p [neighbor, d]
    points << [ points[neighbor][0] + directions[d][0], points[neighbor][1] + directions[d][1] ]
  end

  min_x = points.min_by { |po| po[0] }[0]
  max_x = points.max_by { |po| po[0] }[0]
  min_y = points.min_by { |po| po[1] }[1]
  max_y = points.max_by { |po| po[1] }[1]

  puts "#{max_x - min_x + 1} #{max_y - min_y + 1}"
end

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

namespace ABC_148c
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] input = Array.ConvertAll(Console.ReadLine().Split(' '), long .Parse);
            long res = Math(input[0], input[1]);

            Console.WriteLine(res);
            Console.Read();
        }
        private static long Math(long S,long M)
        {
            if (S < M)
            {
                return Math(M, S);
            }

            long total = 0;
            long s = S;
            long m = M;

            while (M != 0)
            {
                long comp = S % M;
                S = M;
                M = comp;
            }

            total = (s * m) / S;
            return total;
        }
    }
}


Measured memory_bytes: 27448
#include <stdio.h>
#define N 1000005
#define max(a,b) ((a)>(b)?(a):(b))
int n, a[N], left[N], right[N];
int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", a + i);
	for (int i = 1; i <= n; i++)
		left[i] = max(left[i - 1], a[i]);
	for (int i = n; i >= 1; i--)
		right[i] = max(right[i + 1], a[i]);
	for (int i = 1; i <= n; i++)
		printf("%d\n", max(left[i - 1], right[i + 1]));
	return 0;
}

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

#define int long long
#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x.size())
const int MOD=1e9+7;
int powmod(int a,int l, int md){a%=md; int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
int binpow(int a,int l){int res=1;while(l){if(l&1)res=res*a;l/=2;a=a*a;}return res;}
int invmod(int a, int md){return powmod(a,md-2,md);}
typedef long long ll; typedef unsigned long long ull; typedef long double ld;
typedef vector<int> vi; typedef pair<int, int> ii; typedef vector< ii > vii;
#define pb push_back
int __set(int b, int i) {return b|(1LL<<i);} //set ith bit
int __unset(int b, int i) {return b&(~(1UL<<i));}
int __check(int b, int i) {return b&(1LL<<i);} //returns 0 if ith bit is 0
int mulmod(int a, int b, int md) {return (((a%md)*(b%md))%md+md)%md;}
int addmod(int a, int b, int md) {return ((a%md+b%md)%md+md)%md;}
int submod(int a, int b, int md) {return (((a%md-b%md)%md)+md)%md;}
int divmod(int a, int b, int md) {return mulmod(a, powmod(b, md-2, md), md);} //if md is prime;
const ll inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);



signed main(void) {
	IOS;
	string s; cin>>s;
	if(s[2]==s[3] && s[4]==s[5]) {
		cout<<"Yes"<<endl;
	} else
		cout<<"No"<<endl;
	return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod= int(1e9)+7;
using P = pair<ll,ll>;
using ld=long double;

int main(){
   ll n;cin >>n;
   ll a=2;
   ll g=__gcd(a,n);
   ll lcm=a*n/g;
   cout <<lcm<<endl;
   return 0;
}

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

int main() {
  int n,m; cin >> n >> m;
  Graph G(n+1);
  int a,b;
  REP(i,m) {
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  vector<int> dist(n+1, 0);
  dist[1] = 0;
  queue<int> q;
  q.push(1);
  while(!q.empty()) {
    int t = q.front(); q.pop();
    if (dist[t] > 1) continue;

    for (int x : G[t]) {
      if (dist[x]) continue;
      if (x == n) { cout << "POSSIBLE" << endl; return 0; }
      dist[x] = dist[t]+1;
      q.push(x);
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}

Measured memory_bytes: 13168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
int n;
int p[N];
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> p[i];
	}
	int ans = 1, cur_min = p[0];
	for (int i = 1; i < n; i++) {
		if (p[i] <= cur_min) {
			cur_min = p[i];
			ans++;
		}
	}
	cout << ans;
	return 0;
}

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

int main() 
{
	long long int n;
	cin>>n;
	long long int a[n];
	for(long long int i=0;i<n;i++)
	    cin>>a[i];
	long long int ans=0;
	long long int maxi=0;
	for(long long int i=0;i<n;i++)
	{
	    maxi=max(maxi,a[i]);
	    ans+=maxi-a[i];
	}
	cout<<ans<<endl;
}


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

int main() {
	int n,m,ans[200010];
	for(int i=0;i<200009;i++){
		ans[i]=0;
	}
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int a,b;
		cin>>a>>b;
		if(a==1||b==1){
			ans[a]++;
			ans[b]++;
		}
		else if(a==n||b==n){
			ans[a]++;
			ans[b]++;
		}
	}
	for(int i=2;i<=n-1;i++){
		if(ans[i]>=2){
			cout<< "POSSIBLE"<<endl;
			return 0;
		}
	}
	cout <<"IMPOSSIBLE"<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>



int main(void){
int card[4][14]={0},n,i;
scanf("%d",&n);

for (i=0;i<n;i++){
    char mark;
    int kari;
    scanf(" %c %d",&mark, &kari);
    if (mark == 'S') card[0][kari] = 1;
    if (mark == 'H') card[1][kari] = 1;
    if (mark == 'C') card[2][kari] = 1;
    if (mark == 'D') card[3][kari] = 1;
}
for(i=0;i<4;i++){
    int j;
    for(j=1;j<14;j++){
      if (card[i][j]==0)
      {
          if(i==0) printf("S %d\n",j);
          if(i==1) printf("H %d\n",j);
          if(i==2) printf("C %d\n",j);
          if(i==3) printf("D %d\n",j);
      }
    }
}
return 0;
}




Measured memory_bytes: 2100
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod=MOD):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))

######################################################

N,A=ilint()
A=[A[i]-(i+1) for i in range(N)]
A.sort()
k=A[N//2]
ans=0
for a in A:
    ans+=abs(a-k)
print(ans)

Measured memory_bytes: 113368
N = gets.to_i
A, B, C = (0..2).map{gets.split.map(&:to_i).sort}
x = B.map{|b|(s = C.bsearch_index{|c|b<c}) ? N-s : 0}
(2..N).each{|i|x[-i] += x[-i+1]}
p A.map{|a|(s = B.bsearch_index{|b|a<b}) ? x[s] : 0}.inject:+

Measured memory_bytes: 25192
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,m;
int cnt[30];
int main(){
  scanf("%d%d",&n,&m);
  int N=n*m;
  char ch;
  for(int i=1;i<=N;++i){
    while(ch=getchar(),ch>'z'||ch<'a');
    cnt[ch-'a']++;
  }
  if(n%2==0&&m%2==0){
    bool flag=true;
    for(int i=0;i<26;++i)if(cnt[i]%4!=0)flag=false;
    printf("%s\n",flag?"Yes":"No");
  }else if(n%2==0||m%2==0){
    if(m%2==0)swap(n,m);
    //n even m odd
    //    4*((m-1)*n/4),2*(n/2)
    bool flag=true;
    for(int i=0;i<26;++i){
      if(cnt[i]&1)flag=false;
    }
    //    2*((m-1)*n/4),1*(n/2)
    for(int i=0;i<26;++i)cnt[i]/=2;
    int cnt2=0,cnt1=0;
    for(int i=0;i<26;++i)cnt2+=cnt[i]/2,cnt1+=cnt[i]&1;
    if(cnt1>n/2||(cnt1&1)!=((n/2)&1))flag=false;
    printf("%s\n",flag?"Yes":"No");
  }else{
    //n odd m odd
    // 4*[(n-1)*(m-1)/4] 2*[(n-1)/2 +(m-1)/2] 1*1
    int cnt1=0;
    for(int i=0;i<26;++i){
      if(cnt[i]&1)cnt1++;
    }
    bool flag=true;
    if(cnt1!=1){
      flag=false;
    }else{
      for(int i=0;i<26;++i){
	cnt[i]/=2;
      }//2*[(n-1)*(m-1)/4] 1*[(n-1)/2 +(m-1)/2]
      cnt1=0;
      for(int i=0;i<26;++i){
	if(cnt[i]&1)cnt1++;
      }
      if(cnt1>(n-1)/2+(m-1)/2||((cnt1&1)!=(((n-1)/2 +(m-1)/2)&1)))flag=false;
    }
    printf("%s\n",flag?"Yes":"No");
  }
  return 0;
}


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

int main(){
    int a,b;
    cin>>a>>b;
    cout<<max(0,a-2*b)<<endl;
    
    return 0;
}


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

int main() {
  int n, a, b;
  cin >> n >> a >> b;

  int ans_max = min(a, b);
  int ans_min = max(a + b - n, 0);

  cout << ans_max << " " << ans_min << endl;
  return 0;
}

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

#define int             long long
#define FOR( i, m, n )  for( int (i) = (m); (i) < (n); (i)++ )
#define REP( i, n )     FOR( i, 0, n )
#define REPR( i, m )    for( int (i) = (m); (i) >= 0; (i)-- )
#define REPONE( i, n )  FOR( i, 1, n + 1 )
#define ALL( a )        (a).begin(), (a).end()
#define MP              make_pair

typedef pair<int, int> P;

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( a > b ) { a = b; return 1; } return 0; }

const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    int N; cin >> N;
    for( int i = 0; ; i++ ){
        if( i * i > N ){
            cout << ( i - 1 ) * ( i - 1 ) << endl;
            break;
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  int A[N];
  
  int sum = 0;
  for ( int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
  }
  
  int average = sum/N;
  int var1 = 0;
  int var2 = 0;
  int var3 = 0;
  
  for (int i = 0; i < N; i++ ){
    var1 += (A[i]-average) * (A[i]-average);
    var2 += (A[i]-average-1) * (A[i]-average-1);
    var3 += (A[i]-average+1) * (A[i]-average+1);
  }
  
  cout << min({var1, var2, var3}) << endl;
}

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

vector<int> to[100005];
vector<bool> visited;
void dfs(int i){
    visited[i] = true;
    for(int k : to[i]){
        if(visited[k])continue;
        dfs(k);
    }
}

int main()
{
    // input
    int n,m;
    cin >> n >> m;
    vector<int> hint(n);
    rep(i,m){
        int x,y,z;
        cin >> x >> y >> z;
        x--;y--;
        to[x].emplace_back(y);
        to[y].emplace_back(x);
    }

    // solve
    visited.resize(n);
    int ans=0;
    rep(i,n){
        if(visited[i])continue;
        dfs(i);
        ans++;
    }


    // output
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9216
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    int[] children;

    void solve() {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int N = S.length();
        char[] LR = S.toCharArray();
        children = new int[N];
        Arrays.fill(children, 0);

        int start = 0; // RLブロックの左端
        int end = 0; // RLブロックの右端
        for (int i = 0; i <= N - 2; i++) {
            if (LR[i] == 'R' && LR[i + 1] == 'L') {
                for (int j = i + 1; j <= N - 1; j++) {
                    if (j == N - 1) {
                        end = j;
                        //start = i;
                        break;
                    }
                    if (LR[j] == 'R') {
                        end = j - 1;
                        // i = end;
                        break;
                    }
                }
                countChildren(i, start, end); // i は R の場所。
                i = end;
                start = end + 1;
                end = start; // 不要だが、start > end の状態は不自然なので、ここで是正しておく。
            }
        }

        for (int i = 0; i < N; i++) {
            System.out.print(children[i] + " ");
        }

    }
    void countChildren(int rPos, int start, int end) {
        int lPos = rPos + 1;
        int rPosChildrenNum = (rPos - start) / 2 + (end - rPos) / 2 + 1;
        int lPosChildrenNum = (lPos - start) / 2 + (end - lPos) / 2 + 1;
        children[rPos] = rPosChildrenNum;
        children[lPos] = lPosChildrenNum;
    }

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



Measured memory_bytes: 43228
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String[] in = s.nextLine().split(" ");
        int a = Integer.parseInt(in[0]);
        int b = Integer.parseInt(in[1]);
        if(a <= 8 && b <= 8) {
            System.out.println("Yay!");
        }else{
            System.out.println(":(");
        }
    }
}

Measured memory_bytes: 23892
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#define int long long
using namespace std;

int n, x;
int a[100];

signed main() {
	cin >> n >> x;
	int i;
	
	for (i = 0; i < n; i++) cin >> a[i];
	sort(a, a + n);
	for (i = 0; i < n; i++) {
		if (x >= a[i]) x -= a[i];
		else break;
	}
	if (i == n && x > 0) i--;
	cout << i << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
inline void add(int &x, int v) {
  x += v;
  if (x>=MOD)x-=MOD;
}

int N;
int F[5001];
vector<int> G[5000];

vector<int> dp[5000][2];
void dfs(int x, int p) {
  dp[x][0] = {0, 1};
  dp[x][1] = {0, 0};
  for (int t : G[x]) if (t != p) {
    dfs(t, x);
    vector<vector<int> > ret(2);
    ret[0] = vector<int>(dp[x][0].size()+dp[t][0].size()-1, 0);
    ret[1] = vector<int>(dp[x][0].size()+dp[t][0].size()-1, 0);
    rep(i, dp[x][0].size()) rep(k1, 2) {
      rep(j, dp[t][0].size()) rep(k2, 2) {
        int s = (1LL*dp[x][k1][i]*dp[t][k2][j])%MOD;
        add(ret[k1^k2^1][i], (1LL*F[j]*s)%MOD);
        add(ret[k1^k2][i+j], s);
      }
    }
    swap(dp[x][0], ret[0]);
    swap(dp[x][1], ret[1]);
  }
  //cout<<"dp["<<x<<"]={";for(int i : dp[x])cout<<i<<",";cout<<"}\n";
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  F[0] = 1;
  for (int i=2; i<=5000; i++) F[i] = (1LL*(i-1)*F[i-2])%MOD;

  cin >> N;
  rep(i, N-1) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    G[x].pb(y);
    G[y].pb(x);
  }
  dfs(0, -1);
  int s = 0;
  rep(i, dp[0][0].size()) {
    int e = (dp[0][0][i]+(MOD-dp[0][1][i]))%MOD;
    add(s, (1LL*e*F[i])%MOD);
  }
  cout << s << "\n";
  return 0;
}


Measured memory_bytes: 70144
use std::io;

macro_rules! get {
    ($t: ty) => {
        {
            let mut x = String::new();
            io::stdin().read_line(&mut x).ok();
            x = x.trim_right().to_owned();
            x.parse::<$t>().unwrap()
        }
    };
    ($($t: ty), *) => {
        {
            let mut x = String::new();
            io::stdin().read_line(&mut x).ok();
            x = x.trim_right().to_owned();
            let mut inter = x.split_whitespace();
            (
                $(inter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
}

macro_rules! insert_vec {
    ($t: ty) => {
        {
            let mut x = String::new();
            io::stdin().read_line(&mut x).ok();
            x = x.trim_right().to_owned();
            x.split_whitespace().map(|x| x.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

macro_rules! word_chars_vec {
    () => {
        {
            let mut x = String::new();
            io::stdin().read_line(&mut x).ok();
            x = x.trim_right().to_owned();
            x.chars().collect::<Vec<_>>()
        }        
    };
}

macro_rules! two_vec {
    ($t: ty; $e: expr) => {
        {
            (0..$e).map(|_| insert_vec!($t)).collect::<Vec<_>>()
        }
    };
}


fn main () {
    let (n, x) = get!(usize, usize);
    let l_vec = insert_vec!(usize);
    let mut ans = 0;
    let mut l = 0;

    for i in 0..n{
        l = l + l_vec[i];
        if l <= x {
            ans += 1;
        };
    }
    println!("{}", ans + 1);

}


Measured memory_bytes: 4352
n = int,input()
t, a = map(int,input().split())
dic_oA = {}
dic_lA = {}
H = list(map(int,input().split()))
kome = 0

for i in H:
    T = t -i*6/1000
    kome += 1        
    if T >= a:
        dic_oA[kome] = T
    else:
        dic_lA[kome] = T

if len(dic_oA) == 0:
    print(max(dic_lA,key=dic_lA.get))
elif len(dic_lA) == 0:
    print(min(dic_oA,key=dic_oA.get))
else:
    sa_o = min(dic_oA.values())- a
    sa_l = a - max(dic_lA.values())
    if sa_o > sa_l:
        print(max(dic_lA,key=dic_lA.get))
    else:
        print(min(dic_oA,key=dic_oA.get))





Measured memory_bytes: 3188
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


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

    ll N, K;
    cin >> N >> K;
    ll ans = 0LL;
//    rep(a,1,N+1){
//    ll a = N;
//        rep(b,1,N+1){
//            if(b <= K) continue;
//            ans += a / b;
//            if(a % b >= K) ans++;
//        }
//    }
    for (ll b = 1; b <= N; b++) {
        if (b <= K) {
            continue;
        }
        ans += N / b * (b - K);
//        if (N % b != 0)
//        ans += max(((N + 1) % b) - K, 0ll);
        if (N % b != 0) {
            if (K == 0) {
                ans += (N % b);

            } else {
                ans += max(N % b - K + 1LL,0LL);
            }
        }
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 888
package main
 
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)
 
var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  var line, buffer []byte
  var isPrefix bool = true
  var err error
  for isPrefix {
    line, isPrefix, err = reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
  }
  return string(buffer)
}
func NextInt() int {
  var n int
  n, _ = strconv.Atoi(NextLine())
  return n
}
func NextIntVec() []int {
  L := strings.Split(NextLine(), " ")
  N := make([]int, len(L))
  for i := range N {
    N[i], _ = strconv.Atoi(L[i])
  }
  return N
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func Output() {
  _ = writer.Flush()
}

func main() {
  ABX := NextIntVec()
  B := ABX[1] / ABX[2]
  A := (ABX[0] - 1) / ABX[2]
  if ABX[0] == 0 { A = -1 }
  Write(B - A)
  Output()
}

Measured memory_bytes: 640
from sys import stdin
input = stdin.buffer.readline

def main():
    n, m = map(int, input().split())
    
    ab = [0] * m
    for ind in range(m):
        i, j = map(int, input().split())
        ab[ind] = (i-1, j-1)
    
    ab.sort()

    ans = 1
    right = ab[0][1]
    for ind in range(1, m):
        # ab[ind] ∩ a[ind-1] = Φ
        if right <= ab[ind][0]:
            ans += 1
            right = ab[ind][1]

        # ab[ind] ⊆ ab[ind-1]
        elif ab[ind][1] < right:
                right = ab[ind][1]
        
        # else:
            # pass
    
    print(ans)

main()

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

int main(){
    long A, B, Q;
    cin >> A >> B >> Q;
    deque<long> s(A), t(B), x(Q);
    for(auto& i : s)cin >> i;
    for(auto& i : t)cin >> i;
    for(auto& i : x)cin >> i;
    s.push_front(numeric_limits<long>::min() / 5);
    t.push_front(numeric_limits<long>::min() / 5);
    s.push_back(numeric_limits<long>::max() / 5);
    t.push_back(numeric_limits<long>::max() / 5);
    for(auto i : x){
        long sl = *lower_bound(s.begin(), s.end(), i), ss = *(lower_bound(s.begin(), s.end(), i) - 1);
        long tl = *lower_bound(t.begin(), t.end(), i), ts = *(lower_bound(t.begin(), t.end(), i) - 1);
        cout << min({abs(i - sl) + abs(sl - tl), abs(i - sl) + abs(sl - ts), abs(i - ss) + abs(ss - tl), abs(i - ss) + abs(ss - ts), abs(i - tl) + abs(tl - sl), abs(i - tl) + abs(tl - ss), abs(i - ts) + abs(ts - sl), abs(i - ts) + abs(ts - ss)}) << endl;
    }
    return 0;
}

Measured memory_bytes: 3712