akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Numerics;


class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
        if (inpt.Length == 3 && inpt.Count(a => a == 5) == 2 && inpt.Count(a => a == 7) == 1)
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }


    }




    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"


7 7 5


";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}

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

int main() {
  int N;
  cin>>N;
  vector<int> B(N-1);
  for(int i=0;i<N-1;i++){
    cin>>B.at(i);
  }
  vector<int> A(N);
  A.at(0)=B.at(0);
  A.at(N-1)=B.at(N-2);
  int ans=A.at(0)+A.at(N-1);
  for(int i=1;i<N-1;i++){
    A.at(i)=min(B.at(i-1),B.at(i));
    ans+=A.at(i);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string A, B;
int main() {
    cin >> A >> B;
    int alen = A.length();
    int blen = B.length();
    if(alen > blen) {
        cout << "GREATER" << endl;
    }else if(alen < blen) {
        cout << "LESS" << endl;
    }else {
        for(int i = 0; i < alen; ++i) {
            if(A.at(i) > B.at(i)) {
                cout << "GREATER" << endl;
                return 0;
            }else if(A.at(i) < B.at(i)) {
                cout << "LESS" << endl;
                return 0;
            }else {

            }
        }
        cout << "EQUAL" << endl;
    }

}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int i;
    scanf("%d", &i);

    int amari = 0;
    amari = i % 10;

    if(amari == 2 || amari == 4 || amari == 5 || amari == 7 || amari == 9)
    {
        printf("hon");
    }

    if(amari == 0 || amari == 1 || amari == 6 || amari == 8)
    {
        printf("pon");
    }

    if(amari == 3)
    {
        printf("bon");
    }

    return 0;

}


Measured memory_bytes: 1704
use proconio::{input};

#[derive(Debug, Clone)]
struct UnionFind {
    vec: Vec<Node>
}

#[derive(Debug, Copy, Clone)]
enum Node {
    Root(u32),
    Vertex(usize),
}

impl UnionFind {
    #[allow(dead_code)]
    fn new(n: usize) -> Self {
        UnionFind{
            vec: vec![Node::Root(1); n]
        }
    }

    #[allow(dead_code)]
    fn root(&self, x: usize) -> usize {
        match self.vec[x] {
            Node::Root(_) => x,
            Node::Vertex(parent) => self.root(parent),
        }
    }

    #[allow(dead_code)]
    fn root_update(&mut self, x: usize) -> usize {
        match self.vec[x] {
            Node::Root(_) => x,
            Node::Vertex(parent) => {
                let root = self.root(parent);
                self.vec[x] = Node::Vertex(root);
                root
            },
        }
    }

    #[allow(dead_code)]
    fn unite(&mut self, x: usize, y: usize) -> u32 {
        let (rx, ry) = (self.root_update(x), self.root_update(y));
        if rx == ry {
            return 0;
        }
        if let (Node::Root(x_root_size), Node::Root(y_root_size)) = (self.vec[rx], self.vec[ry]) {
            self.vec[ry] = Node::Root(x_root_size + y_root_size);
            self.vec[rx] = Node::Vertex(ry);
            return x_root_size + y_root_size;
        } else {
            unreachable!();
        }
    }

    #[allow(dead_code)]
    fn size(&self, x: usize) -> u32 {
        if let Node::Root(s) = self.vec[self.root(x)] {
            return s;
        } else {
            unreachable!();
        }
    }

    #[allow(dead_code)]
    fn max_size(&self) -> u32 {
        let mut answer = 0;
        for i in &self.vec {
            match i {
                Node::Root(size) => {
                    if answer < *size {
                        answer = *size;
                    }
                },
                _ => {},
            }
        }
        return answer;

    }
}
 
fn main() {
    input! {
        n: usize,
        m: usize,
        t: [(usize, usize); m],
    }
 
    let mut uf = UnionFind::new(n);
 
    let mut answer = 1;
    for (a, b) in t {
        let root_size = uf.unite(a-1, b-1);
        if root_size > answer {
            answer = root_size;
        }
    }
    
    println!("{}", answer);
}

Measured memory_bytes: 10740
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.IntStream;

/**
 * 解説通りに実装したソースコード
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			Map<Integer, Integer> map = new HashMap<>();
			int max = IntStream.range(0, n).map(i -> {
				int a = scanner.nextInt();
				map.put(a, map.getOrDefault(a, 0) + 1);
				return a;
			}).max().getAsInt();
			boolean[] dp = new boolean[max + 1];
			map.keySet().stream().forEach(i -> dp[i] = (1 == map.get(i)));
			map.keySet().stream().sorted().forEach(i -> {
				for (int j = i + i; j <= max; j += i) {
					dp[j] = false;
				}
			});
			System.out.println(IntStream.rangeClosed(0, max).filter(i -> dp[i]).count());
		}
	}
}


Measured memory_bytes: 72072
#include <iostream>
#include <algorithm>
#include <string.h>
#include <math.h>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

int main()
{
    string buf;
    cin >> buf;
    size_t pos = buf.rfind("FESTIVAL");
    string fname = buf.substr(0, pos);
    cout << fname << endl;
}


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

int main() {
  string s;
  cin >> s;
  
  int n = s.size();
  int st = -1, go = -1, l = -1, r = -1;
  vector<int> ans(n);
  
  for(int i = 0; i < n; i++){
    if(s.at(i) == 'R'){
      if(st == -1) st = i;
      else if(r != -1){
        go = i - 1;
        
        if(st % 2 == go % 2){
          if(st % 2 == l % 2){
            ans.at(l) = (go - st) / 2 + 1;
            ans.at(r) = (go - st) / 2;
          }
          else{
            ans.at(l) = (go - st) / 2;
            ans.at(r) = (go - st) / 2 + 1;
          }
        }
        else{
          ans.at(l) = (go - st + 1) / 2;
          ans.at(r) = ans.at(l);
        }
        
        st = i;
        go = -1;
        r = -1;
        l = -1;
      }
    }
    else{
      if(r == -1){
        r = i;
        l = i - 1;
      }
    }
  }
  
  go = n - 1;
  if(st % 2 == go % 2){
    if(st % 2 == l % 2){
      ans.at(l) = (go - st) / 2 + 1;
      ans.at(r) = (go - st) / 2;
    }
    else{
      ans.at(l) = (go - st) / 2;
      ans.at(r) = (go - st) / 2 + 1;
    }
  }
  else{
    ans.at(l) = (go - st + 1) / 2;
    ans.at(r) = ans.at(l);
  }

  for(int i = 0; i < n; i++) cout << ans.at(i) << ' ';
  cout << endl;
}

Measured memory_bytes: 1024
S=input()
N=len(S)
f=0
for i in range((N-1)//4):
    if S[i]!=S[(N-3)//2-i]:
        f=-1
        #print(i)
        break
for i in range((N+1)//2,(3*N+1)//4):
    if S[i]!=S[N-1-i]:
        f=-1
        #print(i)
        break
for i in range((N-1)//2):
    if S[i]!=S[N-1-i]:
        f=-1
        #print(i)
        break
if f==-1:
    print("No")
else:
    print("Yes")


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

using namespace std;

typedef long long ll;
typedef pair<ll ,ll> pll;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

const ll mod = 1000000009;
const ll INF = 1e18;//1*10^18

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll powll(ll a,ll n){
  if(n==0)
  {
    return 1;
  }
  return powll(a,n-1)*a;
}

int ReturnDigit(ll num)
{
  string number=to_string(num);
  return number.length();
}

int main() {
  ll i,j,k,l;
  ll n,ans=0;
  cin >>n; 
  // n=200;
  for(i=1; i<=n; i++)
  {
    for(j=1; j<=n; j++)
    {
      for(k=1; k<=n; k++)
      {
        if(i==j || j==k)
        {
          ans+=gcd(i,k);
        }else if(k==i)
        {
          ans+=gcd(k,j);
        }else
        {
          ans+=gcd(gcd(i,j),k); 
        }
      }
    }
  }
  
  // cout<<1.0 * (clock() ) / CLOCKS_PER_SEC<<endl;
  cout<< ans <<endl;
}

Measured memory_bytes: 3604
/*
 © 2020-08-22 12:40:23 Franco1010 All Rights Reserved
*/

#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef long long lli;
typedef pair<lli,lli> ii;
typedef vector<lli> vi;
#define deb(x) cout << #x": " << (x) << endl;
const int cx[4] = {0, 0, 1, -1};
const int cy[4] = {1, -1, 0, 0};
const int N = 1e3 + 5;
const lli INF = 1e18;
char mat[N][N];
lli vis[N][N];
lli h, w;
bool valid(ii pos, ii npos){
  auto [x, y] = npos;
  return 0 <= x and x < h and 0 <= y and y <= w and mat[x][y] == '.' and
        (vis[x][y] > vis[pos.f][pos.s] or vis[x][y] == -1);
}
struct Node{
  ii pos;
  lli dis;
  bool operator < (const Node & n) const {
    return dis > n.dis;
  }
};
void dijkstra(ii pos){
  priority_queue<Node> pq;
  fore(i, 0, N) fore(j, 0, N) vis[i][j] = -1;
  vis[pos.f][pos.s] = 0;
  pq.push({pos, 0});
  while(!pq.empty()){
    auto u = pq.top(); pq.pop();
    if(u.dis > vis[u.pos.f][u.pos.s]) continue;
    fore(i, 0, 4){
      ii npos = {u.pos.f + cx[i], u.pos.s + cy[i]};
      if(valid(u.pos, npos)){
        vis[npos.f][npos.s] = u.dis;
        pq.push({npos, u.dis});
      }
    }
    for(int i = -2; i <= 2; i ++){
      for(int j = -2; j <= 2; j++){
        ii npos = {u.pos.f + i, u.pos.s + j};
        if(valid(u.pos, npos)){
          vis[npos.f][npos.s] = u.dis + 1;
          pq.push({npos, u.dis + 1});
        }
      }
    }
  }
}
int main(){ _
  cin >> h >> w;
  ii ini; cin >> ini.f >> ini.s;
  ii fin; cin >> fin.f >> fin.s;
  ini.f--, ini.s--, fin.f--, fin.s--;
  fore(i, 0, h){
    fore(j, 0, w){
      cin >> mat[i][j];
    }
  }
  dijkstra(ini);
  cout << vis[fin.f][fin.s] << ENDL;
  return 0;
}


Measured memory_bytes: 17936
//include <bits/stdc++.h> 全ヘッダーのinclude
#include <iostream>
#include <cmath>

#define INF 1000001

bool cmpmin(long long *,long long );
bool cmpmax(long long *,long long );

long long h[INF][3]; //足場
long long dp[INF][3]; //結果配列

int main(void){
  int n,i,j,k;
  std::cin >> n;

  for(i=0;i<n;i++){
    for(j=0;j<3;j++){
      std::cin >> h[i][j];
      dp[i][j] = 0;
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<3;j++){
      for(k=0;k<3;k++){
        if(j!=k){
          cmpmax(&dp[i+1][k],dp[i][j]+h[i][k]);
        }
      }
    }
  }

  long long res = 0;
  for(i=0;i<3;i++){
    cmpmax(&res,dp[n][i]);
  }

  std::cout << res << std::endl;
  return 0;
}

bool cmpmin(long long *a,long long b){
  if(*a>b){
    *a = b;
    return true;
  } else {
    return false;
  }
}

bool cmpmax(long long *a,long long b){
  if(*a<b){
    *a = b;
    return true;
  } else {
    return false;
  }
}


Measured memory_bytes: 8448
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  vector<vector<int>> A(H, vector<int>(W));
  deque<tuple<int, int, int, int>> ans;
  for (auto& row : A)
    for (auto& e : row) cin >> e;
  for (int h = 0; h < H; ++h) {
    int first = h % 2 ? W - 1 : 0;
    int last = h % 2 ? 0 : W - 1;
    int step = h % 2 ? -1 : 1;
    for (int w = first; w != last; w += step)
      if (A[h][w] % 2) {
        ++A[h][w + step], --A[h][w];
        ans.emplace_back(h, w + step, h, w);
      }
    if (h != H - 1 && A[h][last] % 2) {
      ++A[h + 1][last], --A[h][last];
      ans.emplace_back(h + 1, last, h, last);
    }
  }
  cout << ans.size() << '\n';
  for (const auto& t : ans) {
    int y1, x1, y2, x2;
    tie(y1, x1, y2, x2) = t;
    ++y1, ++x1, ++y2, ++x2;
    cout << y1 << ' ' << x1 << ' ' << y2 << ' ' << x2 << '\n';
  }
}


Measured memory_bytes: 5120
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string A, B, C;

	cin >> A >> B >> C;

	if (A[A.size() - 1] == B[0] && B[B.size() - 1] == C[0])
	{
		cout << "YES";
	}
	else {
		cout << "NO";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  
  string s;
  string t;
  bool es[26]={};
  bool et[26]={};
  cin>>s;
  cin>>t;
  int n=s.size();
  int m=t.size();
  int index;
  REP(i,n){
    index = s[i]-'a';
    es[index]=true;
  }
  REP(i,m){
    index = t[i]-'a';
    et[index]=true;
  }
  bool flag=true;
  REP(i,26){
    if(!es[i] && et[i]){
      flag = false;
      break;
    }
  }
  if(!flag){
    cout<<-1<<endl;
    return 0;
  }
  
  string temp = s;
  string now = "";
  long long pos;
  long long cnt=0;
  long long offset=0;
  long long ans;
  index=0;
  while(index<m){
    pos=temp.find(t[index]);
    if(pos==-1){
      cnt++;
      temp = s;
      offset = 0;
      continue;
    }else if(pos==temp.size()-1){
      cnt++;
      temp = s;
      offset = 0;
      index++;
    }else{
      if(index==m-1){
        offset += pos+1;
        break;
      }
      temp = temp.substr(pos+1);
      offset += pos+1;
      index++;
    } 
  }
  ans = cnt*(long long)s.size()+offset;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,n) for(int i=0;i<n;i++)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
#define all(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {

	ll n, W;
	ll ans = 0;
	vector<vector<ll>> w(100);
	ll mw;
	cin >> n >> W;

	rep(i, n) {
		ll a, b; cin >> a >> b;
		if (i == 0)mw = a;
		w[a - mw].push_back(b);
	}

	rep(i, 4) {
		sort(all(w[i]));
		reverse(all(w[i]));
	}

	for (int i = 0; i <= w[0].size(); i++) {
		for (int j = 0; j <= w[1].size(); j++) {
			for (int k = 0; k <= w[2].size(); k++) {
				for (int l = 0; l <= w[3].size(); l++) {
					ll sub = 0;
					if (mw*i + (mw + 1)*j + (mw + 2)*k + (mw + 3)*l <= W) {
						for (int x = 0; x < i; x++) {
							sub += w[0][x];
						}
						for (int x = 0; x < j; x++) {
							sub += w[1][x];
						}
						for (int x = 0; x < k; x++) {
							sub += w[2][x];
						}
						for (int x = 0; x < l; x++) {
							sub += w[3][x];
						}
						ans = max(sub, ans);
					}
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict
N=int(input())
d=defaultdict(lambda: 0)
for _ in range(N):
    s="".join(sorted(list(input())))
    d[s]+=1
ans=0
for _, num in d.items():
    ans+=(num*(num-1))
print(ans//2)


Measured memory_bytes: 62168
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1001001001;

int main()
{
	int n;
	while(scanf("%d", &n), n){
		int x;
		scanf("%d", &x);
		
		int p[30];
		rep(i, n)
			scanf("%d", &p[i]);
		
		bool dp[1000001] = {false};
		dp[0] = true;
		reps(i, 1, x+1){
			rep(j, n)
				dp[i] |= i>=p[j] && dp[i-p[j]];
		}
		
		bool isprime[1000001];
		fill(isprime, isprime+x+1, true);
		isprime[0] = isprime[1] = false;
		reps(i, 2, x){
			if(isprime[i]){
				for(int j=i*2; j<=x; j+=i)
					isprime[j] = false;
			}
		}
		
		int ans = -1;
		for(int i=x+1; i>=0; --i){
			if(dp[i] && isprime[i]){
				ans = i;
				break;
			}
		}
		if(ans == -1)
			puts("NA");
		else
			printf("%d\n", ans);
	}
	
	return 0;
}

Measured memory_bytes: 3000
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <unordered_set>
#include <queue>
#include <deque>
#include <string>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>
#include <stack>
#include <cstdio>
#include <climits>
#include <tuple>
#include <ctime>
#include <cstring>
#define FOR(i,a,n) for (int i = a; i < n; i++)
#define IFOR(i,n,a) for (int i = n; i >= a; i--)
#define mp make_pair
#define full(a) a.begin(), a.end()
#define sz(x) ((int)(x).size())
#define pii pair<int, int>
#define trav(a,x) for (auto& a : x)
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
using namespace std;
const int mod = 998244353;
const int N = 1e5 + 5;



int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    string s, t; cin >> s >> t;
    vector<vector<int>> v(26);
    int n = sz(s);
    FOR(i, 0, n)
    {
        v[s[i] - 'a'].push_back(i);
    }
    ll res = 0;
    int ind = -1, tmp = -1;
    int _size = sz(t);
    FOR(i, 0, _size)
    {
        if (sz(v[t[i] - 'a']) == 0)
        {
            cout << -1;
            return 0;
        }
        auto it = upper_bound(full(v[t[i] - 'a']), ind);
        if (it != v[t[i] - 'a'].end())
        {
            tmp = *it;
            if (ind == -1) res += (tmp + 1);
            else res += (tmp - ind);
            ind = tmp;
        }
        else
        {
            res += (n - ind - 1);
            ind = -1;
            i--;
        }
    }
    cout << res;
    return 0;
}



Measured memory_bytes: 4152
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>

#define STARTUP {(cin.tie(0));\
 (ios::sync_with_stdio(false));}

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define MAX(list) std::max(list)
#define MIN(list) std::min(list)
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

using ll = long long;
using namespace std;
ll mod = 1'000'000'007;

const int INF = 1'050'000'000;

int main() {
    STARTUP;

    string S;
    cin >> S;

    int ans = 0;
    REP(i, 3) {
        if (S[i] == '1')ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
#define MOD 1000000007
#define INF 1000000000
#define mp make_pair
#define pb push_back
#define ss second
#define ff first
#define endl '\n'
#define pl cout<<endl;
#define tc int t;cin>>t;while(t--)
#define get cin>>
#define geta ll a[n];for (int i = 0; i < n; ++i){cin>>a[i];}
#define puta for (int i = 0; i < n; ++i){cout<<a[i];}
#define put cout<<
ll maxi=LLONG_MIN;
ll mini=LLONG_MAX;
void fast() { ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); }
ll mask;
int n;
int a[21][21];
ll dp[21][6000000];
ll match(ll in,ll mask)
{
	 if(in==n)
	 {
	   return __builtin_popcount(mask)==n ;
	 }
	 if(dp[in][mask]!=-1)
	 {
	 return dp[in][mask];
	 } 
	 dp[in][mask]=0;
	 for(ll i=0;i<n;i++)
	 {
	  if(a[in][i]==1&&((mask&(1<<i))==0)) 
	  {
	   dp[in][mask]=( dp[in][mask]%MOD+match(in+1,(mask|(1<<i)))%MOD)%MOD; 
	  }  
	 }
	 return dp[in][mask];
}
int main() 
{
   fast();
   memset(dp,-1,sizeof dp);
   cin>>n;
   for (int i = 0; i < n; ++i)
   {
   	for (int j = 0; j < n ; ++j)
   	{
   		cin>>a[i][j];
   	}
   }
   cout<<match(0,0);
   return 0;
}

Measured memory_bytes: 984704
#include<iostream>
#include<string>
using namespace std;
int main(){
      int n;
      cin>>n;
      long long min=10000000,max=-10000000,s=0;
      for(int i=1;i<=n;i++){
          int a;
          cin>>a;
          s+=a;
          if(max<a)max=a;
          if(min>a)min=a;
      }
      cout<<min<<" "<<max<<" "<<s<<endl;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
ll n, a, b;
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> a >> b;
  if(a > b){
    cout << 0 << endl;
    return 0;
  }
  if(n == 1){
    if(a == b){
      cout << 1 << endl;
    }else{
      cout << 0 << endl;
    }
    return 0;
  }
  cout << (b-a)*(n-2)+1 << endl;
  return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.string;
import std.range;
import std.array;
import std.conv;
import std.complex;
import std.math;
import std.ascii;
import std.bigint;
import std.container;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

const real eps = 1e-10;

void main(){
	auto l = "qwertasdfgzxcvb"d;
	while(true) {
		auto s = readln().chomp();
		if(s == "#") {
			return;
		}
		int ans;
		s.map!(c => !l.find(c).empty).reduce!((a, b) {if(a != b) ++ans; return b;});
		writeln(ans);
	}
}

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

using namespace std;

typedef long long ll;

int main(){
int N,K; cin >> N >> K;
  vector<int> V(N);
  for(int i = 0; i < N; i++){ cin >> V[i];}
   
  int R = min(N,K); ll ans = -1LL << 60;
  for(int a = 0; a <= R; a++){
    for(int b = 0; b <= R - a; b++){
      //このとき、 K- ( a + b) 回捨てることができる
      vector<int> vec;
      for(int i = 0; i < a; i++){
        vec.push_back(V[i]);}
      for(int j = N - 1; j >= N - b; j--){
        vec.push_back(V[j]);}
      ll sum = 0;
      sort(vec.begin(),vec.end());
      for(int i = 0; i < vec.size(); i++){
        if( i < K - ( a + b) && vec[i] < 0){
          continue;}
        sum += vec[i];}
      ans = max(ans,sum);
    }
  }
  
  cout << ans << endl; return 0;}
   

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>

using namespace std;
int main(void)
{
	int n;
	while(scanf("%d",&n))
	{
		if(n == 0) break;
		long long int flag[4001] = {0},shain[4001] = {0},junban[4000] = {0};
		long long int shains,tanka,kosu,j = 0;
		long long int flags = 0;
		for(int i = 0;i < n;i++)
		{
			scanf("%lld%lld%lld",&shains,&tanka,&kosu);
			if(flag[shains] == 0)
			{
				flag[shains] = 1;
				junban[j] = shains;
				shain[shains] = tanka * kosu;
				j++;
			}
			else
			{
				shain[shains] += tanka * kosu;
			}
		}

		for(int i = 0;i < n;i++)
		{
			if(shain[junban[i]] >= 1000000)
			{
				printf("%lld\n",junban[i]);
				flags = 1;
			}
		}
		if(flags == 0) printf("NA\n");
	}
	return 0;
}

Measured memory_bytes: 1140
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll t, n, d;
    string s;
    cin >> t;
    vector<ll> ans;
    while(t--){
    	cin >> n;
    	vector<ll> a(n);
    	for(int i=0;i<n;i++) cin >> a[i];
    	cin >> s;
    	int ok = 0;
    	vector<ll> dp(61, 0);
    	for(int i=n-1;i>=0;i--){
    		if(s[i] == '1'){
                d = INF;
    			for(int j=60;j>=0;j--, d /= 2LL){
    				if(a[i] & d) a[i] ^= dp[j];
    			}
    			if(a[i]) ok = 1;
    		}else{
                d = INF;
    			for(int j=60;j>=0;j--, d /= 2LL){
    				if(a[i] & d) {
    					if(dp[j] & d){
    						a[i] ^= dp[j];
    					}else{
    						dp[j] = a[i];
    						j = -1;
    					}
    				}
    			}
    		}
    	}
    	ans.pb(ok);
    }
    for(auto& i: ans ){
    	cout << i << endl;
    }
    return 0;
}


Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
#include<iomanip>
using namespace std;

int N, M;
long long K;

int mod = 1e9 + 7;

int power(int a, int n){
    if (n == 0) {
        return 1;
    } else if (n % 2 == 0) {
        int b = power(a, n / 2);
        return 1ll * b * b % mod;
    } else {
        return 1ll * a * power(a, n - 1) % mod;
    }
}

int inverse(int a) {
    if (a == 1) {
        return 1;
    }
    return power(a, mod - 2);
}

int main() {
    cin >> N >> M >> K;
    int nmr = 1, dnm1 = 0, dnm2 = 0;
    int tmp = 1;
    for (long long i = 1; i < 1ll * N * M - 1; i++) {
        tmp = 1ll * tmp * i % mod;
        if (i == N * M - 2) nmr = tmp;
        else if (i == K - 2) dnm1 = tmp;
        else if (i == N * M - K) dnm2 = tmp;
    }
    long long ans = 0;
    for (int d = 0; d < M; d++) {
        ans += 1ll * (M - d) * d % mod * N % mod * N % mod;
        ans %= mod;
    }
    for (int d = 0; d < N; d++) {
        ans += 1ll * (N - d) * d % mod * M % mod * M % mod;
        ans %= mod;
    }
    if (1ll * dnm1 * dnm2 > 0) {
        ans *= 1ll * nmr * inverse(dnm1) % mod * inverse(dnm2) % mod;
        ans %= mod;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#define GRAY 2
#define N 101
 
int color[N],d[N],f[N],e[N],count,A[N][N],v[N],B[N][N];

void DFE_Visit(int);
void DFS(int);

main(){
  int n,i,j,v1;

  for(i=0;i<N;i++){ //行列を０で初期化
    for(j=0;j<N;j++){
      A[i][j]=0;
    }
  }
 
  scanf("%d",&n);
   
  for(i=1;i<=n;i++){
    scanf("%d%d",&v[i],&e[i]);
    for(j=1;j<=e[i];j++){
      scanf("%d",&v1);
      B[i][j]=v1; //Bのi行j列に値を容れる
      A[i][v1]=1; //Aにフラグを建てる
    }
  }
  DFS(n);
 
  return 0;
}


void DFS(int n){
  int i,u;
   
  for(i=1;i<=n;i++){ //実質的にcolorを０に初期化
    u=v[i];
    color[u]=0;
  }

    count=0;
   
  for(i=1;i<=n;i++){ //実質的にi回DFEを呼び出し、かつプリント
    u=v[i];
    if(color[u]==0)DFE_Visit(u);
    printf("%d %d %d\n",u,d[u],f[u]);
  }
}


void DFE_Visit(int u){
  int v,i;
   
  color[u]=GRAY; //未確定で初期化
  d[u]=++count;
 
  for(i=1;i<=e[u];i++){ //Bの値を順番に呼び出して再帰することによってd[u]の値を決定する
    v=B[u][i];
    if(color[v]==0)DFE_Visit(v);
  }
  color[u]=1;
  f[u]=++count; //再帰の特徴から、逆順に入る
}

Measured memory_bytes: 676
#include<bits/stdc++.h>
using namespace std;
 
#define fi              first
#define se              second
#define ll             long long
#define pb              push_back
#define mp              make_pair
#define pll             pair<ll,ll>
#define vll              vector<int>
#define mll             map<ll,ll>
#define pqg             priority_queue<ll>
#define pqs             priority_queue<ll,vll,greater<ll> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define md             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            ll x; cin>>x; while(x--)
 
#define IJ \
    freopen("input.txt", "r", stdin); 
#define OJ \
    freopen("output.txt", "w", stdout);
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
int main()
{
    //IJ; OJ; 
    FIO;
    int a,a1;
    cin>>a;
      a1=a%10;
      if(a1==2 || a1==4 || a1==5 || a1==7 || a1==9)
        cout<<"hon";
      else if(a1==0 || a1==1 || a1==6 || a1==8)
        cout<<"pon";
      else if(a1==3)
        cout<<"bon";
    return 0;
} 

Measured memory_bytes: 3636
def valid?(a, b, c)
  x = b + c - a
  y = c + a - b
  z = a + b - c
  (x >= 0 && y >= 0 && z >= 0) || (x >= 1 && y >= -1 && z >= -1)
end

def calc(rear, front, west, east, north, south, best)
  path = ''
  loop do
    a = rear + front
    b = west + east
    c = north + south

    return path if a + b + c == 0

    if east > 0 && valid?(b - 1, c, a)
      rear, front, west, east = east - 1, west, rear, front
      y = 'E'
    elsif north > 0 && valid?(c - 1, a, b)
      rear, front, north, south = north - 1, south, front, rear
      y = 'N'
    elsif south > 0 && valid?(c - 1, a, b)
      rear, front, north, south = south - 1, north, rear, front
      y = 'S'
    elsif west > 0 && valid?(b - 1, c, a)
      rear, front, west, east = west - 1, east, front, rear
      y = 'W'
    else
      throw 'error'
    end
    
    if best
      x = best[path.size]
      return best if x < y
      best = nil if x > y
    end
    path << y  
  end
end

def find(target)
  best = nil
  target.permutation(6).to_a.uniq.each do |rear, front, west, east, north, south|
    a = rear + front
    b = west + east
    c = north + south
    if valid?(a, b, c)
      best = calc(rear, front, west, east, north, south, best)
    end
  end
  best
end

loop do
  target = STDIN.gets.split.map!(&:to_i)
  break if target.max == 0
  p, q = STDIN.gets.split.map!(&:to_i)
  result = find(target)
  puts result ? result[p-1...q] : 'impossible'
end

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

int main() {
    int n, y;
    cin >> n >> y;
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= n - i; ++j) {
            int k = n - i - j;
            if (10000 * i + 5000 * j + 1000 * k == y) {
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " "  << -1 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f(i,n) for(int i=0;i<n;++i)
#define pie 3.141592653589793238462643383279
#define mod 1e9+7
signed main(){
	string s;
	int ans=0,cnt=0;
	cin>>s;
	f(i,s.size()){
		if(s[i]-'0'==i%2) cnt++;
	}
	ans=cnt;
	cnt=0;
	f(i,s.size()){
		if(s[i]-'0'!=i%2) cnt++;
	}
	cout<<min(ans,cnt)<<endl;
}


Measured memory_bytes: 512
n=int(input())
h=list(map(int, input().split()))
v=h[0]
for i in range(n-1):
    if h[i]<h[i+1]:
        v=h[i+1]
    if h[i]-h[i+1]>=2:
        print('No')
        exit()
    if v-h[i+1]>=2:
        print('No')
        exit()
print('Yes')

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

#define mian main
#define maxn 500010
#define fo(i,a,b) for(register int (i)=(a);(i)<=(b);++(i))
#define rd read()

int read() {
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9') {
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9') {
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}
long long a,b,c;
int mian() {
    a=read();b=read();c=read();
    if(c<a+b)puts("No");
    else if((c-a-b)*(c-a-b)<=4*a*b)puts("No");
    else puts("Yes");
    return 0;

}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
const int MAX=1e5+5;
int dp[MAX][3], arr[MAX][3];

int recur(int i, int k) 
{
    if(i == n) 
        return 0;

    if(dp[i][k]!=-1) 
        return dp[i][k];

    if(k==0) 
        return dp[i][k] = max(arr[i][1] + recur(i+1, 1), arr[i][2] + recur(i+1, 2));
    else if(k==1) 
        return dp[i][k] = max(arr[i][0] + recur(i+1, 0), arr[i][2] + recur(i+1, 2));
    else 
        return dp[i][k] = max(arr[i][0]+recur(i+1, 0), arr[i][1] + recur(i+1, 1));
}

int main() 
{
    cin >> n;
    memset(dp, -1, sizeof(dp));

    for(int i=0;i<n;i++) 
        cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
    
    cout << max(recur(0, 0), max(recur(0, 1), recur(0, 2)));
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;


int main() {
    ll k, a, b;
    cin >> k >> a >> b;
    if(a >= k)cout << 1 << endl;
    else{
        if(a <= b)cout << -1 << endl;
        else {
            cout << (k-a+a-b-1)/(a-b) * 2 + 1<< endl;
        }
    }
}   

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


int main () {
  int A, B, C;
  cin >> A >> B >> C;
  vector<int> vec = {A, B, C};
  sort(vec.begin(), vec.end());
  cout << vec.at(2) * 10 + vec.at(1) + vec.at(0) << endl;
}

Measured memory_bytes: 3688
//#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }

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

int X, Y;
int a[2010];
int n, z, w;
int dp[2010][2];

int func(int x, int y) {
  if(dp[x][y] != -1) return dp[x][y];

  int ret = y==0?0:INF;
  FOR(i, x+1, n+2) {
    int tmp = x==1?z:a[x-2];
    int now = i==n+1?abs(tmp-a[i-2]):func(i, !y);
    if(y) chmin(ret, now);
    else chmax(ret, now);
  }
  return dp[x][y] = ret;
}

signed main(void)
{
  cin >> n >> w >> z;
  REP(i, n) cin >> a[i];

  memset(dp, -1, sizeof(dp));
  cout << func(1, 0) << endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;

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

    double res = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));

    printf("%0.4lf\n", res);
}



Measured memory_bytes: 3200
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;


namespace StartFinish
{
 
    class Program
    {
        static void Main(string[] args)
        {
            int[,] building1 = new int[3, 10];
            int[,] building2 = new int[3, 10];
            int[,] building3 = new int[3, 10];
            int[,] building4 = new int[3, 10];
            Const(ref building1);
            Const(ref building2);
            Const(ref building3);
            Const(ref building4);
            int n = int.Parse(Console.ReadLine());
            string[] str;
            //b?£?f???r?????????v???
            for(int i = 0; i < n; i++)
            {
                str = Console.ReadLine().Split(' ').ToArray();
                if (str[0] == "1")
                {
                    building1[int.Parse(str[1]) - 1, int.Parse(str[2]) - 1] += int.Parse(str[3]);
                }
                if (str[0] == "2")
                {
                    building2[int.Parse(str[1]) - 1, int.Parse(str[2]) - 1] += int.Parse(str[3]);
                }
                if (str[0] == "3")
                {
                    building3[int.Parse(str[1]) - 1, int.Parse(str[2]) - 1] += int.Parse(str[3]);
                }
                if (str[0] == "4")
                {
                    building4[int.Parse(str[1]) - 1, int.Parse(str[2]) - 1] += int.Parse(str[3]);
                }
            }

            Show(building1);
            Console.WriteLine("####################");
            Show(building2);
            Console.WriteLine("####################");
            Show(building3);
            Console.WriteLine("####################");
            Show(building4);
            //Console.WriteLine();

        }
        static void Const(ref int[,] building)
        {
            for (int i = 0; i < 3; i++)
            {
                for(int j = 0; j < 10; j++)
                {
                    building[i, j] = 0;
                }
            }

        }
        static void Show(int[,] building)
        {
            for(int i = 0; i < 3; i++)
            {
                for(int j = 0; j < 10; j++)
                {
                    if (j != 9)
                    {
                        Console.Write(" {0}", building[i, j]);
                    }
                    else
                    {
                        Console.WriteLine(" {0}",building[i, 9]);
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 9544
package main

import (
	"fmt"
	"strconv"
)

func topbottom(x int) (int, int) {
	str := strconv.Itoa(x)
	top, _ := strconv.Atoi(string(str[0]))
	bottom, _ := strconv.Atoi(string(str[len(str)-1]))
	return top, bottom
}
func main() {
	var n int
	fmt.Scan(&n)

	result := 0
	c := [10][10]int{}
	for k := 1; k <= n; k++ {
		top, bottom := topbottom(k)
		c[top][bottom]++
	}
	for i := 0; i <= 9; i++ {
		for j := 0; j <= 9; j++ {
			result += c[i][j] * c[j][i]
		}
	}
	fmt.Println(result)

}


Measured memory_bytes: 3712
L = list(map(int, input().split()))

def gcd(x, y):
    r = x % y
    if r == 0:
        return y
    return gcd(y, r)

def count_between(x, a, b):
    c = x
    l = (a * b) // gcd(a, b)
    c = c - x // a - x // b + x // l
    return c


print(count_between(L[1], L[2], L[3]) - count_between(L[0] - 1, L[2], L[3]))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long 
using namespace std;
const int N=2e5+10;
int n,top;
int a[N],b[N],c[N],pre[N],suf[N],stk[N];
long double ans;
void init(){
	int mx=0,ps=-1;
	for(int i=1;i<=n;i++) if(a[i]>mx) mx=a[i],ps=i;
	rotate(a+1,a+ps,a+n+1);
	rotate(b+1,b+ps,b+n+1);
	a[++n]=a[1],b[n]=b[1];
	for(int i=3;i<=n;i++) c[i]=2*(b[i-1]+c[i-1])-c[i-2],a[i]-=c[i];
}
long double slope(int tp1,int tp2){ 
	return 1.0*(a[tp2]-a[tp1])/(tp2-tp1); 
}
bool pd(int tp1,int tp2,int tp3){ 
	return slope(tp1,tp2)<=slope(tp2,tp3); 
}
void solve(){
	for(int i=1;i<=n;i++){
		while(top>1 && pd(stk[top-1],stk[top],i)) --top;
		stk[++top]=i;
	}
	stk[top+1]=n+1;
	for(int i=1;i<=top;i++) for(int j=stk[i];j<stk[i+1];j++) pre[j]=stk[i];
	for(int i=1;i<=top;i++) for(int j=stk[i-1]+1;j<=stk[i];j++) suf[j]=stk[i];
	for(int i=1;i<n;i++){
		if(pre[i]!=suf[i]) ans+=1.0*(a[suf[i]]*(i-pre[i])+a[pre[i]]*(suf[i]-i))/(suf[i]-pre[i]);
		else ans+=1.0*a[i];
	}
	for(int i=1;i<n;i++) ans+=c[i];
}
signed main(){
	scanf("%lld",&n);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	for(int i=1;i<=n;i++) scanf("%lld",&b[i]);
	init();
	solve();
	printf("%.12Lf",1.0*ans/(n-1));
} 


Measured memory_bytes: 13120
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
constexpr ll Mod = 998244353;
constexpr ll mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
const double PI = acos(-1);
template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
/*-------------------------------------------*/

bool winner(vector<int> v) {
    int odd = 0, even = 0;
    for(auto &&x : v)
        (x & 1 ? odd : even)++;
    if(even & 1) return 1;
    if(odd >= 2) return 0;
    int G = 0;
    for(auto &&x : v) {
        if(x == 1) return 0;
        if(x & 1) x--;
        G = gcd(G, x);
    }
    for(auto &&x : v)
        x /= G;
    return !winner(v);
}

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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    cout << (winner(a) ? "First" : "Second") << "\n";

    return 0;
}

Measured memory_bytes: 12892
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long k = sc.nextLong();

		long ans = n % k;
		if (ans == 0) {
			System.out.println(ans);
		} else {
			long a2 = Math.abs(ans - k);

			if (a2 > n) {
				System.out.println(n);
			} else {
				System.out.println(a2);
			}
		}

		sc.close();
	}

}

Measured memory_bytes: 23508
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cinttypes>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

set<char> PopulateAll() {
  set<char> all;
  for (char ch = 'a'; ch <= 'z'; ++ch) {
    all.insert(ch);
  }
  return all;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  string S;
  cin >> S;
  
  if (S.size() < 26) {
    auto all = PopulateAll();
    for (char ch : S) {
      all.erase(ch);
    }
    
    S += *all.begin();
    cout << S << '\n';
    return 0;
  }
  
  for (int i = S.size() - 1; i >= 0; --i) {
    string prefix = S.substr(0, i);
    auto all = PopulateAll();
    for (char ch : prefix) {
      all.erase(ch);
    }
    
    auto it = all.upper_bound(S[i]);
    if (it != all.end()) {
      prefix += *it;
      cout << prefix << '\n';
      return 0;
    }
  }
  
  if (S == "zyxwvutsrqponmlkjihgfedcba") {
    cout << -1 << '\n';
    return 0;
  }
  
  assert(false);
  
  return 0;
}


Measured memory_bytes: 256
def main()->None:
    N, C, K = map(int, input().split())
    range_N = range(N)
    T = [int(input()) for i in range_N] # バスの出発時刻
    T = sorted(T)
    
    bus = 0
    passenger = 0
    start = 0

    for i in range_N:
        if passenger == 0:
            start = T[i] + K
            passenger = 1

        elif passenger == C:
            bus += 1
            start = T[i] + K
            passenger = 1

        else:
            if T[i] > start:
                bus += 1
                start = T[i] + K
                passenger = 1

            else:
                passenger += 1
    print(bus+1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 8280
#include <bits/stdc++.h>
#define pb push_back
#define pll pair <ll, ll>
#define mp make_pair
#define pyshnapyshnakaa ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define x first
#define y second
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define plll pair <pair <ll, ll>, ll>
#define pllll pair <pair <ll, ll>, pair <ll, ll> >
#define psl pair <string, ll>
#define all(a) a.begin(), a.end()

typedef long long ll;

typedef long double ld;

using namespace std;

ll n, m, k, t;

const ll maxn = 6e3 + 100;
const ll shift = 2e3;

ll mod;

inline ll step(ll a, ll x) {
    if (x == 0) {
        return 1;
    }
    if (x % 2 == 1) {
        return step(a, x - 1) * a % mod;
    }
    ll t = step(a, x / 2);
    return t * t % mod;
}

inline ll del(ll a, ll b) {
    return a * step(b, mod - 2) % mod;
}

ll D[maxn][2 * maxn + 200]; /// s, 1 - 2

ll F[maxn];

ll R[maxn];

int main() {
    ll q, w, e, a, b, d;
    cin >> n >> mod;
    n *= 3;
    for (q = 1; q <= n; q++) {
        R[q] = del(1, q);
    }
    F[0] = 1;
    for (q = 1; q < maxn; q++) {
        F[q] = (F[q - 1] * q) % mod;
    }
    D[0][shift] = F[n];
    for (q = 0; q < n; q++) {
        for (w = 0; w < maxn * 2 + 100; w++) {
            for (e = 1; e <= 3; e++) {
                ll nw = w;
                if (e == 1) {
                    nw = nw + 1;
                }
                if (e == 2) {
                    nw = nw - 1;
                }
                if (q + e > maxn || nw > 3 * maxn || q + e < 0 || nw < 0) {
                    continue;
                }
                // D[q + e][nw] += del(D[q][w], q + e);
                D[q + e][nw] += D[q][w] * R[q + e] % mod;
                D[q + e][nw] %= mod;
            }
        }
    }
    ll ans = 0;
    for (q = 0; q < 2 * maxn + 200; q++) {
        if (q - shift >= 0) {
            ans += D[n][q];
            ans %= mod;
        }
    }
    cout << ans;
    return 0;
}


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

int main(){
	int n, in;
	cin >> n;
	ll sum = 0;
	vector<ll> s(n);
	rep(i, n){
		cin >> in;
		sum += in;
		s[i] = sum;
	}
	ll mi = 2000000000000000;
	rep(i, n-1){
		if(mi > abs(s[n-1] - s[i]*2)) mi = abs(s[n-1] - s[i]*2);
	}
	cout << mi << endl;
	return 0;
}

Measured memory_bytes: 1792