akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>

using namespace std;
using ll = long long;

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

    int N;
    cin >> N;
    cout << (N * (N + 1)) / 2 << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main()
{
long long	int a,b,c,i,d,f,sum;
	scanf("%lld\n",&a);
	c=a+1;
	f=sqrt(a);
	for(i=f;i>=1;i--)
	{
		if(a%i==0){
		d=a/i;
			b=d+i;
			if(b<=c)
			{
				c=b;
				sum=c-2;
			}
	}
	}
	printf("%lld\n",sum);
	return 0;
	}

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

int main() {
  int n;
  cin >> n;
  vector<long> amb(n);
  for (int i = 0; i < n; i++) cin >> amb[i];
  for (int i = 0; i < n; i++) {
    int b;
    cin >> b;
    amb[i] -= b;
  }
  sort(amb.begin(), amb.end());
  int idx = 0, cnt = 0;
  long diff = 0;
  while (idx < n && amb[idx] < 0) {
    diff += (-amb[idx]);
    idx++;
    cnt++;
  }
  idx = n - 1;
  while (idx >= 0 && amb[idx] > 0 && diff > 0) {
    diff -= amb[idx];
    idx--;
    cnt++;
  }
  if (diff <= 0)
    cout << cnt;
  else
    cout << -1;
  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
long long n,a[200003],b[200003],x[200003],y[200003],pw[200003];
const long long base=1100000000,mod=2147483647;
bool check(int i){
	long long vala=(i==0?0:x[i-1])+(x[n-1]-((i==0)?0:x[i-1]*pw[n-i]%mod))*pw[i],valb=y[n-1];
	vala=(vala%mod+mod)%mod;
	return vala==valb;
}
int main(){
	scanf("%lld",&n);
	for(int i=0;i<n;i++)scanf("%lld",a+i);
	for(int i=0;i<n;i++)scanf("%lld",b+i);
	for(int i=0;i<n;i++)x[i]=a[i%n]^a[(i+1)%n];
	for(int i=0;i<n;i++)y[i]=b[i%n]^b[(i+1)%n];
	for(int i=1;i<n;i++)x[i]=(x[i-1]*base+x[i])%mod;
	for(int i=1;i<n;i++)y[i]=(y[i-1]*base+y[i])%mod;
	pw[0]=1;for(int i=1;i<=n;i++)pw[i]=pw[i-1]*base%mod;
	for(int i=0;i<n;i++)
		if(check(i))
			cout<<i<<' '<<(a[i]^b[0])<<endl;
}

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

typedef long long ll;

#define pb push_back
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

ll n, a, x[50] = {}, dp[51][51][2501] = {};

int main() {
  cin >> n >> a;
  rep(i, 0, n) cin >> x[i];
  dp[0][0][0] = 1;

  for(int i = 0;i < n;i++) for(int j = 0;j < i + 1;j++) for(int k = 0;k <= 2500;k++){
    dp[i + 1][j][k] += dp[i][j][k];
    dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
  }

  ll ans = 0;

  rep(i, 1, n + 1) {
    ans += dp[n][i][i * a];
  }

  cout << ans << endl;
}


Measured memory_bytes: 49152
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let k: i32 = read();
    let s: i32 = read();

    let mut ans = 0;

    for x in 0..k+1 {
        for y in 0..k+1 {
            if 0 <= s - x - y && s - x - y <= k {
                ans += 1;
            }
        }
    }

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


Measured memory_bytes: 4352
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

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

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

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

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

fn main() {
    input!{
        n: usize,
        s: [String; n],
        m: usize,
        t: [String; m],
    }
    let mut ans = 0i64;
    for s_ in s.iter() {
        ans = max(
            s.iter().filter(|x| *x == s_).count() as i64
                - t.iter().filter(|x| *x == s_).count() as i64,
            ans,
        );
    }

    println!("{}", ans)
}


Measured memory_bytes: 4352
#include <stdio.h>


int main(void){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a > b){
		printf("a > b\n");
	}else if(a < b){
		printf("a < b\n");
	}else{
		printf("a == b\n");
	}
	return 0;
}



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

int main(){
  char s[3]; cin>>s;
  for(int i=0;i<3;i++){
    if(s[i] == '1'){
      s[i] = '9';
    }else if(s[i] == '9'){
      s[i] = '1';
    }
  }
  cout<<s<<endl;
}

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

int main(void){
    int n;
    cin>>n;
    vector<int> a(n);
    for (int i = 0; i < n; ++i)cin>>a[i];
    for (int i = 1; i < n; ++i) {
        int v = a[i];
        int j = i - 1;
        for (int k = 0; k < n-1; ++k) {
            cout << a[k]<<" ";
        }
        cout << a[n-1]<<endl;
        while (j >= 0 && a[j] > v) {
            a[j + 1] = a[j];
            a[j] = v;
            --j;
        }
    }
    for (int k = 0; k < n-1; ++k) {
        cout << a[k]<<" ";
    }
    cout << a[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)

using namespace std;
using p = pair<long long, int>;
#define INF 100000000

int main(){
    int n,m;
    long long x;
	cin >> n >> m >> x;
	
	vector<int> c(n);
	vector<vector<int> > a(n,vector<int>(m));
    long long ans = INF;
    rep(i,n){
    	cin >> c[i];
    	rep(j,m){
    		cin >> a[i][j];
    	}
    }
    
    for (int bit = 0; bit < (1<<n); ++bit) {
    	vector<int> s;
    	for(int i = 0; i < n; i++){
    		if (bit & (1 << i)) {
    			s.push_back(i);
        	}
        }
        
        bool can = true;
        rep(i,m){
        long long dream = 0;
        	for(int v: s){
        		dream+=a[v][i];
        	}
        	if(dream < x) can = false;
        }
        if(can){
        	
         	long long k = 0;
        	for(int v: s){
        		k+=c[v];
        	} 
        	ans = min(ans,k);
        }
    }
    if(ans == INF)
	cout << -1 << endl;
	else
	cout << ans << endl;
    return 0;
		
}

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

#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;

int main() {
    int64_t n, t;
    cin >> n >> t;

    vector<int64_t> a(n);
    int64_t m = 1L << 30, g = 0;
    for (auto&& aa : a) {
        cin >> aa;
        m = min(m, aa);
        g = max(g, aa - m);
    }

    m = 1L << 30;
    int64_t ans = 0;
    for (auto aa : a) {
        m = min(m, aa);

        if (aa - m == g) {
            ++ans;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 1024
//============================================================================
// Name        : AOJ.cpp
// Author      : Akari Fujii
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cctype>
#include <string>
#include<algorithm>

using namespace std;
typedef long long ll;
int main(){

	string s;

	cin>>s;

	if(s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I'){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}


	return 0;



}


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

using namespace std;
using ll = long long;
using ld = long double;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) ((x).begin()), ((x).end())

#define READ(x) (cin >> (x))
#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))
#define WRITE_YESNO(x) (WRITE_N((x) ? "Yes" : "No"))

#define PRECISE_COUT std::cout << std::setprecision(15) << std::fixed

bool xor_logic(bool x, bool y) { return (x && y) || (!x && !y); }

#define DIVIDER 1000000007

ll solve(vector<ll> &A) {
  ll sum_mod = 0;
  for (auto &&x : A) {
    sum_mod = (sum_mod + x) % DIVIDER;
  }

  ll retv = 0;
  for (auto &&x : A) {
    sum_mod = (sum_mod + DIVIDER - x) % DIVIDER;
    retv = (retv + x * sum_mod) % DIVIDER;
  }

  return retv;
}

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N;
  cin >> N;

  std::vector<ll> A(N, 0);
  for (size_t i = 0; i < N; i++) {
    cin >> A[i];
  }

  // main procedure
  ll ans = solve(A);

  // output
  cout << ans << endl;

  return 0;
}

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

using namespace std;

typedef long long ll;
// typedef pair<ll, ll> P;
typedef pair<int, int> 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()

int N, M;
vector<P> G[100000];
vector<bool> visit(100000, false);
vector<int> x(100000, 0);
bool ok = true;

void dfs(int cur)
{
  visit[cur] = true;
  REP(i, G[cur].size())
  {
    int to = G[cur][i].first;
    int w = G[cur][i].second;
    if (visit[to]) // 訪問済みの場合
      ok = ok && (x[to] == x[cur] + w);
    else // そうでない場合
    {
      x[to] = x[cur] + w;
      dfs(to);
    }
  }
}

int main()
{
  cin >> N >> M;
  REP(i, M)
  {
    int L, R, D;
    cin >> L >> R >> D;
    L--, R--;
    G[L].push_back(P(R, D));
    G[R].push_back(P(L, -D));
  }
  REP(i, N)
  {
    if (visit[i])
      continue;
    dfs(i);
  }
  cout << (ok ? "Yes" : "No") << endl;
  return 0;
}

Measured memory_bytes: 12032
n = int(input())
a = [0 for i in range(13)]
for i in map(int, input().split()):
    a[i // 400] += 1
ans = 0
add = 0
for i in range(8):
    if a[i]:
        ans += 1
for i in range(8,13):
    if a[i]:
        add += a[i]
if ans == 0:
    print(1, add)
else:
    print(ans, ans+add)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
long long sum[200005],res=1e18;
void get(int l,int r,long long &x,long long &y)
{
	long long res=1e18;
	int lef=l,rig=r-1;
	while (lef<=rig)
	{
		int m=lef+rig>>1;
		long long a=sum[m]-sum[l-1];
		long long b=sum[r]-sum[m];
		if (abs(a-b)<res)
		{
			res=abs(a-b);
			x=a;y=b;
		}
		if (a<=b) lef=m+1;
		else rig=m-1;
	}
}
int main()
{
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		sum[i]=x+sum[i-1];
	}
	for (int i=2;i<=n-2;i++)
	{
		long long a,b,c,d;
		get(1,i,a,b);
		get(i+1,n,c,d);
		res=min(res,max({a,b,c,d})-min({a,b,c,d}));
	}
	cout<<res<<endl;
	return 0;
}

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

bool checkStorable(const int (&nums)[10]);

int main()
{
    int n;
    int nums[10];
    
    cin >> n;
    for(int i=0; i<n; i++)
    {
       for(int j=0; j<10; j++)
        {
            cin >> nums[j];
        }
        if(checkStorable(nums))
        {
            cout << "YES" << endl;
        }
        else
        {
            cout << "NO" << endl;
        }
    }
    return 0;
}

bool checkStorable(const int (&nums)[10])
{
    int prev_value_left = 0;
    int prev_value_right = 0;
    bool is_storable = true;
    
    for(int i=0; i<10; i++)
    {
        if(nums[i] > prev_value_left)
        {
            prev_value_left = nums[i];
        }
        else
        {
            if(nums[i] > prev_value_right)
            {
                prev_value_right = nums[i];
            }
            else
            {
                is_storable = false;
                break;
            }
        }
    }
    return is_storable;
}


Measured memory_bytes: 3088
#include <iostream>
#include <vector>
#include<map>
#include<string>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<typeinfo>
using namespace std;


int main() {
	string s;
	cin >> s;
	vector<string> a(s.size());
	
	long long int sum=0;
	for (int bit = 0; bit < (1 << s.size()-1);bit++) {
		for (int i = 0; i < s.size(); i++) {
			a[i] = s[i];
		}
		for (int i = 0; i < s.size()-1; i++) {
			if (bit & (1 << i)&&i<s.size()-1) {
				a[i + 1] = a[i] + a[i + 1];
				a[i] = '0';
			}

		}
		for (int i = 0; i < s.size(); i++) {
			istringstream is(a[i]);
			long long int x;
			is >> x;
			sum += x;
		}
		
	}
	cout << sum;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int a,b,x;
  scanf("%d%d",&a,&b);
  x=a+b;
  if((a+b)%2==0){
    printf("%d",(a+b)/2);
  }
  else{
    printf("%d",(a+b)/2+1);
  }
}

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (n - 1); i > (a - 1); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define Unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) (((n) * ((n) + 1)) / 2)
#define updiv(a, b) ((a + b - 1) / b)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[] = {1, 0, -1, 0, 1, -1, 1, -1};
int dy[] = {0, 1, 0, -1, 1, 1, 1, -1, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main(void) {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  string s;
  cin >> s;
  int r = 0, b = 0, g = 0;
  rep(i, 0, n) {
    if (s[i] == 'R') ++r;
    if (s[i] == 'G') ++g;
    if (s[i] == 'B') ++b;
  }
  int cnt = 0;
  rep(i, 0, n) {
    rep(j, i, n) {
      int wa = abs(j - i) * 2;
      wa += i;
      if (wa < n && s[i] != s[j] && s[i] != s[wa] && s[j] != s[wa]) ++cnt;
    }
  }
  cout << r * g * b - cnt << '\n';
  return 0;
}

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

int main() {
    long long X;
    cin >> X;
    long long ans = 0;
    for (int b = 1; b < 100; b++) {
        for (int p = 2; p < 100; p++) {
            if (pow(b, p) <= X) {
                ans = max(ans, (long long)pow(b, p));
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::endl;
using std::string;

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

  if (a >= 10 || b >= 10){
    cout << -1 << endl;
  }
  else{
    cout << a * b << endl;
  }

  return 0;
}


Measured memory_bytes: 256
# coding:utf-8

import sys
# from collections import Counter, defaultdict

INF = float('inf')
MOD = 10 ** 9 + 7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()


a, b = LI()
print(a + b if b % a == 0 else b - a)

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

namespace ABC130A
{
    class Program
    {
        static void Main(string[] args)
        {
            var XA = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int X = XA[0];
            int A = XA[1];
            Console.WriteLine(X < A ? "0" : "10");
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include<numeric>
using namespace std;
using P = pair<int, int>;
#define rep(i,n) for(int i=0; i<(n);i++)
typedef long long ll;


int main(){
    ll r, d, x; cin >> r>>d>>x;
    ll ans = r*x-d;
    rep(i,10){
        cout << ans << endl;
        ans = r*ans-d;
    }
    return 0;
}


Measured memory_bytes: 888
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        m : usize,
    }

    if n >= 13 {
        println!("{}", m);
    } else if n >= 6 {
        println!("{}", m / 2);
    } else {
        println!("0");
    }
}


Measured memory_bytes: 2140
s = input()

check = 0

if s == 'a':
    print('vowel')
    check = check + 1

if s == 'i':
    print('vowel')
    check = check + 1

if s == 'u':
    print('vowel')
    check = check + 1

if s == 'e':
    print('vowel')
    check = check + 1

if s == 'o':
    print('vowel')
    check = check + 1

if check == 0:
    print('consonant')


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

int main(){
  ll N,M,S;
  cin >> N >> M >> S;
  int amax = 2501;
  if (S >= amax) S = amax;
  vector< vector< tuple<ll,int, int> > > G(N);
  REP(i,M) {
    int u,v,a,b;
    cin >> u >> v >> a >> b;
    u--; v--;
    G[u].emplace_back( b, v, a);
    G[v].emplace_back( b, u, a);
  }
  vector<int> C(N);
  vector<ll> D(N);
  REP(i,N)  cin >> C[i] >> D[i];

  vector< vector<ll> > ti(N, vector<ll>(amax+2, 1LL << 62));
  priority_queue< tuple< ll, int, int >, vector< tuple< ll, int, int > > , greater< tuple< ll, int, int > > > q;
  q.push( {0, 0, S} );
  ti[0][S] = 0;
  while( !q.empty() ) {
    ll t; int v, co;
    tie(t,v,co) = q.top(); q.pop();
//    cout << t << " " << v << " " << co << endl;
    // 両替
    if ( co < amax ) {
      int vco = min(co + C[v], amax);
      if ( ti[v][co] + D[v] < ti[v][vco] ) {
        ti[v][vco] = ti[v][co] + D[v];
        q.emplace( ti[v][vco], v, vco );
//      cout << "  add " << ti[v][co+C[v]] << " " << v << " " << vco << endl;
      }
    }
    for ( auto nv : G[v] ) {
      ll nvt; int nvpos, nvco;
      tie(nvt, nvpos, nvco) = nv;
      // 移動
      if ( co >= nvco ) {
        if ( ti[v][co] + nvt < ti[nvpos][co-nvco] ) {
          ti[nvpos][co-nvco] = ti[v][co] + nvt;
          q.emplace( ti[nvpos][co-nvco], nvpos, co-nvco );
//        cout << "  add " << ti[nvpos][co-nvco] << " " << nvpos << " " << co-nvco << endl;
        }
      }
    }
  }
  for (int i=1; i<N; i++ ) {
    ll ans = 1LL << 62;
    REP(j, amax) {
      ans = min(ans, ti[i][j]);
    }
    cout << ans << endl;
  }

}


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

// for loop
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)

// abbreviati
#define PB(v) push_back(v)
#define MP(A,B) make_pair(A,B)
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

using ll = long long;
using P = pair<int,int>;
using itn = int;

// constant
const int INF = 1<<30;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007;
const long double PI =(acos(-1));

/***Snippet***************************************************
ifelse, isprime, torad, todeg, lcm, bfs,chmin,chmax
**************************************************************/

// adjacency list
vector<int> to[100005];

// Graph
using Graph = vector<vector<int>>;

// Grid
int H,W;
vector<vector<int>> field;

// 4方向への移動ベクトル
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,m; cin >> n >> m;
    int L=0;
    int R=INF;
    int l=0,r=0;
    rep(i,0,m){
        cin >> l >> r;
        L=max(L,l);
        R=min(R,r);
    }
    if(L<=R) cout << R-(L-1) ENDL;
    else cout << 0 ENDL;
    
    return 0;
}

Measured memory_bytes: 5908
import sys
import math
import collections
import bisect
import copy
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def main():
    n, m = ns()
    p = na1()

    uf = UnionFind(n)

    for _ in range(m):
        x, y = ns()
        uf.union(x - 1, y - 1)

    ans = 0
    for i, pi in enumerate(p):
        if uf.same(i, pi):
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 20740
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
 
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
 
/*------------------------------------------------------------------*/
 
int main(){
    ll n; cin >> n;
    vector<ll> a(n);
    ll sum = 0;
    rep(i, n){
        cin >> a[i];
        sum += a[i] - 1;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
h,w=map(int,input().split())
s=[]
for i in range(h):
    s.append(list(input()))

#for i in s:
#    print(i)

for i in range(h):
    for j in range(w):
        if(s[i][j]=='#'):
            continue
        c=0
        for di in range(-1,2):
            if(i+di<0 or i+di>=h):
                continue
            for dj in range(-1,2):
                if(j+dj<0 or j+dj>=w):
                    continue
                if(s[i+di][j+dj]=='#'):
                    c+=1
        s[i][j]=c

for i in s:
    i=map(str,i)
    si="".join(i)
    print(si)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
long long B = 1717171;
int main(){
        string t,p;
        cin>>t>>p;
        long long hash[t.size()+1];
        long long pow[t.size()+1];
        hash[0]=0;
        pow[0]=1;
        for(int i=0;i<t.size();i++){
                hash[i+1] = hash[i]*B + t[i];
                pow[i+1] = pow[i]*B;
        }
        long long base=0, ans=0;
        for(int i=0;i<p.size();i++) base = base*B+p[i];

        for(int i=0;i+p.size()<=t.size();i++){
                int left=i, right=i+p.size()-1;
                if(hash[right+1]-hash[left]*pow[right-left+1]==base) printf("%d\n", i);
        }
        return 0;
}


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

char bomb[8][8];

void printData(int i){
  cout << "Data " << i+1 << ':' << endl;
}

void dfs(int x,int y){
  bomb[y][x] = '0';

  for(int i = x-3 ; i <= x+3 ; i++){
    if((0 <= i && i <= 7)&&bomb[y][i]=='1') dfs(i,y);
  }
  for(int j = y-3 ; j <= y+3 ; j++){
    if((0 <= j && j <= 7)&&bomb[j][x]=='1') dfs(x,j);
  }
}

int main(){
  int n,x,y;
  string str;
  
  cin >> n;
  for(int i = 0 ; i < n ; i++){
    string tmp = "";
    for(int j = 0 ; j < 8 ; j++){
      cin >> str;
      tmp += str;
    }

    int t = 0;
    for(int j = 0 ; j < 8 ; j++)
      for(int k = 0 ; k < 8 ; k++)
	bomb[j][k] = tmp[t++];

    cin >> x >> y;

    printData(i);
    dfs(x-1,y-1);

    for(int j = 0 ; j < 8 ; j++){
      for(int k = 0 ; k < 8 ; k++){
	cout << bomb[j][k];
      }
      cout << endl;
    }

  }

  return 0;
}

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

int main()
{

    char in[120];
    pair<pair<string,int>,int>p[110];
    int a;
    scanf("%d", &a);
    for(int i = 0;i<a;i++)
    {
        int t;
        scanf("%s%d", in, &t);
        string tmp = in;
        p[i] = make_pair(make_pair(in,-t),i);

    }
    sort(p,p+a);
    for(int i = 0;i<a;i++)
    printf("%d\n", p[i].second+1);
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(100000)

def islands ( x, y):
    s[y][x] = '0'
    for dx, dy in ((1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1)):
        xx,yy = x+dx , y+dy
        if 0<=xx<w and 0<=yy<h and s[yy][xx]=='1':
            islands(xx,yy)
            
while True:
    w, h = map(int, input().split())
    count = 0

    if w==0 and h==0:
        break
    
    s = [[i for i in input().split()] for _ in range(h)]


    for i in range (w):
        for j in range(h):
            if s[j][i] == '1':
                islands( i, j)
                count += 1

    print(count)



Measured memory_bytes: 7976
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long int ll;

int main(){
    int n; cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    vector<int> b(n);
    for(int i=n-1;i>=0;i--){
        int c=0;
        for(int j=2*(i+1);j<=n;j+=(i+1)){
            if(b[j-1])c++;
        }
        if(c%2!=a[i])b[i]=1;
    }
    vector<int> ans;
    for(int i=0;i<n;i++){
        if(b[i])ans.push_back(i+1);
    }
    cout << ans.size() << endl;
    for(int i=0;i<ans.size();i++){
        cout << ans[i] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

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

    int Cx, Cy, H;
    bool F;
    for(Cx = 0; Cx <= 100; Cx++){
        for(Cy = 0; Cy <= 100; Cy++){
            for(int i = 0; i < N; i++){
                if(h[i] > 0){
                    H = abs(x[i]-Cx) + abs(y[i]-Cy) + h[i];
                    break;
                }
            }

            F = true;
            for(int i = 0; i < N; i++){
                if(max(H-abs(x[i]-Cx)-abs(y[i]-Cy), 0) != h[i]){
                    F = false;
                    break;
                }
            }

            if(F == true){
                break;
            }
        }
        if(F == true){
            break;
        }
    }

    cout << Cx << " " << Cy << " " << H << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#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 pi acos(-1.0)
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(){
	int n, m;
	cin >> n >> m;
	VI used(n+1), ans, e(m);

	REP(i,m) cin >> e[i];

	FORR(i,m-1,0){
		int x = e[i];
		if (!used[x]){
			ans.push_back(x);
			used[x] = 1;
		}
	}

	REP(i,ans.size()) cout << ans[i] << endl;
	FOR(i,1,n) if(!used[i]) cout << i << endl;

    return 0;
}

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

int main(){
    ll a,b,k;
    cin >> a >> b >> k;
    if (a<=k && a+b>=k)
    {
        cout << "YES" << endl;
    }else
    {
        cout << "NO" << endl;
    }
}

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

using namespace std;

long long p[200005], v[200005], z[200005];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	long long n, br = 1;
	cin >> n;
	for(long long i = 0; i < n; ++i) cin >> p[i];
	for(long long i = 0; i < n; ++i){
		if(br == p[i]) ++br;
//		++v[p[i]];
//		if(v[p[i]] == p[i]) z[p[i]] = i + 1;
	}
/*	for(long long i = n; i > 0; --i){
		if(z[i] and z[i] - i <= n - i){
			cout << n - i;
			return 0;
		}
	}*/
/*	for(long long i = 1; i <= n; ++i){
		if(!v[i]){
			if(i > 1) cout << n - i + 1;
			else cout << -1;
			return 0;
		}
	}*/
//	cout << -1;
    --br;
    if(!br) cout << -1;
    else cout << n - br;

	return 0;
}



Measured memory_bytes: 2944
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		// ?????????????????\???
		Scanner sc = new Scanner(System.in);
		String input = sc.nextLine();

		// ??\?????????????????????char????????????
		char [] sentence = input.toCharArray();

		// ??§??????????°??????????????°????????????§???????????????
		for(int cnt=0; cnt< sentence.length; cnt++){

			if (Character.isUpperCase(sentence[cnt])){

				sentence[cnt] = Character.toLowerCase(sentence[cnt]);

			}else{

				sentence[cnt]=Character.toUpperCase(sentence[cnt]);

			}
		}

		sc.close();

		// ??????
		String output = String.valueOf(sentence);
		System.out.println(output);

	}
}

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

using namespace std;
using ll = long long;
const ll mod = 1000000007;


int main()
{
    string a, b, c;
    cin >> a >> b >> c;
    cout << (a.back() == b.front() && b.back() == c.front() ? "YES" : "NO") << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<cstdio>
#include<iomanip>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int INF = 1e9 + 7;
int N;
vector<ll>v;//nが条件を満たす場合vに入れるkは桁数
void dfs(ll n, ll k) {
	if (k > 1e9)return;
	int f[10] = {}, t = n;
	while (t) {
		f[t % 10]++;
		t /= 10;
	}
	if (f[3] && f[5] && f[7])v.push_back(n);
	dfs(n + 3 * k, k * 10);
	dfs(n + 5 * k, k * 10);
	dfs(n + 7 * k, k * 10);
}
int main() {
	int N;
	cin >> N;
	dfs(0, 1);
	sort(v.begin(), v.end());
	ll i = 0;
	int ans = 0;
	for (; i < v.size(); ++i) {
		if (v[i] > N)break;
		ans++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>

int main(void){
	int w, h, n, i;
	int x[1000], y[1000];
	int now=0;
	long ans=0;

	scanf(" %d %d %d", &w, &h, &n);
	for(i=0; i<n; i++) scanf(" %d %d", &x[i], &y[i]);
	
	int nx=x[0], ny=y[0];
	
	while(now<n-1){
		if(x[now+1] > nx && y[now+1] > ny){
			while(x[now+1] != nx && y[now+1] != ny){
				++nx;
				++ny;
				++ans;
			}
			
			if(x[now+1] == nx){
				while(y[now+1] != ny) {
					++ny;
					++ans;
				}
			}
			else if(y[now+1] == ny){
				while(x[now+1] != nx) {
					++nx;
					++ans;
				}
			}	
		}
		else if(x[now+1] < nx && y[now+1] < ny){
			while(x[now+1] != nx && y[now+1] != ny){
				--nx;
				--ny;
				++ans;
			}
			
			if(x[now+1] == nx){
				while(y[now+1] != ny) {
					--ny;
					++ans;
				}
			}
			else if(y[now+1] == ny){
				while(x[now+1] != nx) {
					--nx;
					++ans;
				}
			}	
		}
		else{
			ans += fabs(nx-x[now+1]) + fabs(ny-y[now+1]);
			nx = x[now+1];
			ny = y[now+1];
		}
	
		now++;
		//printf("%d %d, %ld\n", nx, ny, ans);
	}
	
	printf("%ld\n", ans);

	return 0;
}

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

#define pfin(a) printf("%d\n",a);
#define pfln(a) printf("%lld\n",a);
#define pfis(a) printf("%d ",a);
#define pfls(a) printf("%lld ",a);
#define sfi(a) scanf("%d",&a);
#define sfl(a) scanf("%lld",&a);
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define f(i,a,b) for(int i=a;i<b;i++)
#define mem(dp,a) memset(dp,a,sizeof dp);
#define pb(a) push_back(a);
#define mp(a,b) make_pair(a,b)
#define ll long long

const ll mod=1e9+7;

int main()
{
  	ll n,w;
    sfl(n)
    sfl(w)

    ll weight[n+1];
    ll value[n+1];

    ll maxi=0;

    f(i,1,n+1)
    {
        sfl(weight[i])
        sfl(value[i])
        maxi+=value[i];
    }

    ll dp[n+1][maxi+1];

    f(i,1,maxi+1)
        dp[0][i]=LLONG_MAX;
    f(i,0,n+1)
        dp[i][0]=0;

    f(i,1,n+1)
    {
        f(j,1,maxi+1)
        {
            dp[i][j]=dp[i-1][j];
            if((j-value[i]>=0)&&(dp[i-1][j-value[i]]!=LLONG_MAX))
            {
                dp[i][j]=min(dp[i][j],(dp[i-1][j-value[i]]+weight[i]));
            }
        }
    }

    ll ans=0;

    f(i,1,maxi+1)
    {
        if(dp[n][i]<=w)
            ans=i;
    }

    // f(i,0,n+1)
    // {
    //     f(j,0,maxi+1)
    //         pfls(dp[i][j])
    //     printf("\n");
    // }

    pfln(ans)

    return 0;
}

Measured memory_bytes: 79104
#include <bitset>
#include <iostream>

int main(int argc, char *argv[]) {
  long a, b;
  std::cin >> a >> b;
  std::bitset<32> abs(a), bbs(b);
  std::cout << (abs & bbs) << std::endl
            << (abs | bbs) << std::endl
            << (abs ^ bbs) << std::endl;
}



Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'

ll n,total_capacity;
vector<pair<ll,ll>> arr;
ll ans=0;
vector<vector<ll>> dp(105,vector<ll>(1e5+5,-1));

ll recurse(ll pos,ll capacity_left)
{
    if(dp[pos][capacity_left]!=-1) return dp[pos][capacity_left];
    
    if(pos==n || capacity_left==0) return 0;
    
    ll tmp1 = LLONG_MIN, tmp2 = LLONG_MIN;
    
    if(arr[pos].first > capacity_left) tmp1 = recurse(pos+1,capacity_left);
    
    else
    {
        tmp1 = recurse(pos+1,capacity_left);
        tmp2 = arr[pos].second + recurse(pos+1,capacity_left-arr[pos].first);
    }
    
    dp[pos][capacity_left] = max(tmp1,tmp2);
    
    return max(tmp1,tmp2);
}

int main()
{
    cin>>n>>total_capacity;
    
    for(ll i=0;i<n;i++)
    {
        ll w,v;
        cin>>w>>v;
        arr.push_back({w,v});
    }
    
    cout<<recurse(0,total_capacity)<<endl;
}

Measured memory_bytes: 86172
N = int(input())
S_n = [ ]
for i in range(N):
    S_n.append(input())

if N ==1:
    print(1)
else:
    count=1
    S_n.sort()
    prize= S_n.pop()
    for i in range(N-1):
        neprize = S_n.pop()
        if prize != neprize:
            count +=1
            prize = neprize
    print(count)
    

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

#define mp make_pair
#define sz(x) (int)((x).size())
#define all(x) (x).begin(),(x).end()
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define eb emplace_back

typedef pair< int, int > pii;
typedef pair< long long, long long > pll;
typedef long long ll;
typedef unsigned long long ull;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vll;
typedef vector< vll > vvll;
typedef vector< pii > vpii;
typedef vector< vpii > vvpii;
typedef vector< pll > vpll;
typedef long double ld;
typedef vector< ld > vld;
typedef unsigned int uint;
 
template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    const bool operator<(const M& o) const {return v < o.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
 
using Mint = ModInt<(int)1e9 + 7>;
 
int main() { 
    #ifdef BLAT
        freopen("stdin", "r", stdin);
        freopen("stderr", "w", stderr);
    #endif
 
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(12);
    srand(time(NULL));
    
    ll a;
    cin >> a;

    int b = 0;

    char c;
    cin >> c;

    b = c - '0';
    cin >> c;

    cin >> c;

    b = 10*b + c - '0';
    cin >> c;
    b = 10*b + c - '0';

    cout << a*b/100;
    return 0;
}

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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

int main() {
  ll n;
  cin >> n;

  map<string, ll> m;
  for (ll i = 0; i < n; ++i) {
    string s;
    cin >> s;
    m[s]++;
  }

  cout << "AC x " << m["AC"] << endl;
  cout << "WA x " << m["WA"] << endl;
  cout << "TLE x " << m["TLE"] << endl;
  cout << "RE x " << m["RE"] << endl;

  return 0;
}


Measured memory_bytes: 3600
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    s = input()
    ans = []
    for i in range(len(s)):
        if s[i] == 'B':
            if ans:
                ans.pop()
        else:
            ans.append(s[i])
    ans = "".join(ans)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 9008
n = $stdin.readline.to_i
s = 0

if n == 0
  puts "0"
  exit
end

res = []
i = 0
while n - s != 0
  if i % 2 == 0
    d = (n - s).abs & (1 << i)
    s += d
    res.unshift((d >> i) & 1)
  else
    d = (n - s).abs & (1 << i)
    n += d
    res.unshift((d >> i) & 1)
  end
  i += 1
end
puts res.join("")

Measured memory_bytes: 14336
#include <bits/stdc++.h>
#define N 400010
#define int long long
#define mod 998244353
using namespace std;

inline int qpow(int bas,int pw)
{
	int ret=1; for(;pw;pw>>=1,bas=1ll*bas*bas%mod)
		if(pw&1) ret=1ll*ret*bas%mod; return ret;
}
int n,a,b,k,fac[N+10],inv[N+10],sum;
inline int C(int n,int m)
{
	return fac[n]*inv[n-m]%mod*inv[m]%mod;
}
inline void Add(int &x,int y)
{
	x+=y; if(x>=mod) x-=mod;
	if(x<0) x+=mod;
}
signed main()
{
	fac[0]=1; for(int i=1;i<=N;i++)
		fac[i]=1ll*fac[i-1]*i%mod;
	inv[N]=qpow(fac[N],mod-2);
	for(int i=N-1;i>=0;i--)
		inv[i]=1ll*inv[i+1]*(i+1)%mod;
	cin >> n >> a >> b >> k;
	for(int i=0;i<=n;i++)
	{
		int t=k-a*i; if(t<0) continue;
		if(t%b==0&&t/b<=n)
			Add(sum,1ll*C(n,i)*C(n,t/b)%mod);
	}
	cout << sum << endl;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vll vector<ll>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb  push_back
#define ppb pop_back
#define mp  make_pair
#define SIZE 100003
vector<pll> graph[SIZE];
ll color[SIZE];
unordered_map<ll,ll> m;
bool visited[SIZE];


ll maxc=0;
void DFS(ll u,ll e){
	visited[u]=true;
	ll c=1;
	for(auto node:graph[u]){
		if(!visited[node.first]){
			if(c==color[e]){
				c++;
			}
			// cout<<e<<" "<<c<<endl;
			color[node.second]=c;
			maxc=max(maxc,c);
			c++;
			DFS(node.first,node.second);
		}
	}
}


int main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	// #endif
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	ll N;
	cin>>N;
	for(ll i=0;i<N-1;++i){
		ll u,v;
		cin>>u>>v;
		graph[u].pb(mp(v,i+1));
		graph[v].pb(mp(u,i+1));
	}
	DFS(1,0);
	cout<<maxc<<endl;
	for(ll i=1;i<=N-1;++i){
		cout<<color[i]<<endl;
	}
}

Measured memory_bytes: 8960
import sys
from collections import deque

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

H, W = map(int, readline().split())
S = [list(input()) for i in range(H)]


def bfs(grid, start):
    distance = [[0] * W for _ in range(H)]
    queue = deque([start])
    visited = [[False] * W for _ in range(H)]
    while queue:
        x, y = queue.popleft()
        if visited[x][y]:
            continue
        visited[x][y] = True

        for i, j in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = y + j, x + i
            if 0 <= new_y < W and 0 <= new_x < H:
                if grid[new_x][new_y] == '.' and not visited[new_x][new_y]:
                    distance[new_x][new_y] = distance[x][y] + 1
                    queue.append((new_x, new_y))
    return distance


answer = 0
limit = H - 1 + W - 1
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue

        cnt = 0
        for dx, dy in ([1, 0], [-1, 0], [0, 1], [0, -1]):
            new_y, new_x = dy + j, dx + i
            if 0 <= new_y < W and 0 <= new_x < H:
                if S[new_x][new_y] == '.':
                    cnt += 1

        if cnt > 2:
            continue

        tmp = max(map(max, bfs(S, (i, j))))
        if tmp > answer:
            answer = tmp
        if answer == limit:
            print(answer)
            exit()

print(answer)


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

using namespace std;

int solve(int num, int sum, int n, int s) {

  int scnt = 0;
  if(n) for(int i = num + 1; i < 10; ++i) scnt += solve(i, sum + i, n - 1, s);
  else return (sum == s) ? 1 : 0;
  return scnt;

}

int main() {

  int n, s;

  while(cin >> n >> s) {
    if(n == 0 && s == 0) break;
    cout << solve(-1, 0, n, s) << endl;
  }

}

Measured memory_bytes: 1160
N, C, K = map(int, input().split())
T = []
for i in range(N):
    T.append(int(input()))

T.sort()
i = 0
start = 0
ans = 0
limit = C
for i in range(N - 1):
    # 定員余裕あり、時刻余裕ありの場合は乗車させる（定員から一人引く）
    if T[start] + K >= T[i + 1] and limit > 1 :
        limit -= 1
    # 定員余裕あり、時刻NGの場合は出発させる。
    elif T[start] + K < T[i + 1] and limit > 1:
        ans += 1
        limit = C
        start = i + 1
    # 定員余裕なしの場合は出発させる。
    elif limit == 1:
        ans += 1
        limit = C
        start = i + 1
# 最後の人のために出発させる（定員余裕あり、時刻余裕ありの場合は同乗者あり）
ans += 1
print(ans)

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

using namespace std;



int main()
{
	int n;
	cin>>n;
	while(n!=0)
	{
	vector< pair<int,int> > a;
	rep(i,n)
	{
		int z,x,c;
		cin>>z>>x>>c;
		a.push_back(pair<int,int>(x+c,z));
	}
	
	sort(a.begin(),a.end());
	
		cout<<a[a.size()-1].second<<" "<<a[a.size()-1].first<<endl;
		cin>>n;
	}
}

Measured memory_bytes: 1328
#include <stdio.h>
int main(){
  int a,b,c,x,i,j,k,cnt=0;
  scanf("%d %d %d %d",&a,&b,&c,&x);
  for(i=0;i<=a;i++)
    for(j=0;j<=b;j++)
      for(k=0;k<=c;k++){
        if((i*500+j*100+k*50)==x)
          cnt++;
      }
  printf("%d\n",cnt);
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		int count =0;
		for(int i=0;i<=2;i++) {
			if(s.charAt(i)=='o') {
				count++;
			}
		}
		System.out.println(700+count*100);

	}

}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define int long long
#define f(i,l,n) for(ll i=l;i<n;i++) 
#define E "\n"
#define bp __builtin_popcount

 ll n,m;
 const int M=1e3+5;
ll Ans=1e15;
vector<ll> a(M),b(M);
vector<ll> c[M];
int dp[M][5000];


int solve(int indx,int mask)
{
  //cout<<indx<<" "<<mask<<E;
    if(indx>=m) return (bp(mask)>=n)?0:1e15;
    if(bp(mask)==n) return 0;


    int &ans=dp[indx][mask];
    if(ans!=-1) return ans;

    ans=1e15;
    ans=solve(indx+1,mask);
    f(i,0,b[indx])  mask=mask|(1<<c[indx][i]-1);
    ans=min(ans,a[indx]+solve(indx+1,mask));
 //   cout<<indx<<" "<<mask<<" "<<ans<<E;

    return ans;


}


int32_t main()
{

   

    cin >> n >> m;

    f(i,0,m)
    {
      cin >> a[i] >> b[i];
      f(j,0,b[i])
      {
        ll x;
        cin >> x;
        c[i].push_back(x);
      }
    }

    

    

    f(i,0,m+1) f(j,0,5000) dp[i][j]=-1;

    Ans=solve(0,0);

    (Ans>=1e15)?cout<<"-1":cout<<Ans;


     return 0;
}

Measured memory_bytes: 42788
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;
const double PI = 3.14159265358979323846;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\n"

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> p(N);
	for (int i = 0; i < N; ++i) {
		cin >> p[i];
	}

	sort(p.begin(), p.end());

	int sum = 0;
	for (int i = 0; i < K; ++i) {
		sum += p[i];
	}

	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 3624