akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int main() {
    int a, b;
    cin >> a >> b;
    int ans = 0;
    int tmp = 1;
    while(tmp < b) {
        tmp += a-1;
        ans++;
    }

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

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
//#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
//#include<list>
#include<queue>
#include<deque>
#include<algorithm>
//#include<numeric>
#include<utility>
//#include<memory>
#include<functional>
#include<cassert>
#include<set>
#include<stack>
#include<random>

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, -1, 0, 1};
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;

ll mod_pow(ll x, ll p, ll MOD) {
    ll a = 1;
    while (p) {
        if (p%2) a = a*x%MOD;
        x = x*x%MOD;
        p/=2;
    }
    return a;
}

const int MAXN = 404;
const int MOD = 1e9+7;
int A[MAXN], B[MAXN];
int N, C;

ll memo[MAXN][MAXN];
ll sum[MAXN][MAXN];
ll dp[MAXN][MAXN];

ll dfs(int now, int rest) {
    ll& ret = dp[now][rest];
    if (ret >= 0) return ret;
    if (now == N-1) {
        //return ret = memo[A[now]][rest];
        ret = sum[B[now]+1][rest] - sum[A[now]][rest];
        ret = (ret%MOD+MOD)%MOD;
        return ret;
    }
    ret = 0;
    for (int i = 0; i <= rest; i++) {
        //ll tmp = memo[A[now]][i];
        ll tmp = sum[B[now]+1][i] - sum[A[now]][i];
        tmp = (tmp%MOD+MOD)%MOD;
        tmp *= dfs(now+1, rest-i);
        (ret += tmp%MOD) %= MOD;
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    for (int i = 0; i < MAXN; i++) for (int j = 0; j < MAXN; j++) {
        memo[i][j] = mod_pow(i, j, MOD);
    }
    memset(sum, 0, sizeof(sum));
    for (int i = 0; i < MAXN; i++) {
        for (int j = 1; j < MAXN; j++) {
            sum[j][i] = sum[j-1][i] + memo[j-1][i];
            sum[j][i] %= MOD;
        }
    }
    cin >> N >> C;
    for (int i = 0; i < N; i++)
        cin >> A[i];
    for (int i = 0; i < N; i++)
        cin >> B[i];
    memset(dp, -1, sizeof(dp));
    cout << dfs(0, C) << endl;
    return 0;
}


Measured memory_bytes: 4096
n = int(input(), 10)
live_pos_list = list(map(int, input().split()))


def cost(live_pos, held_pos):
    return (live_pos - held_pos) ** 2

mean_pos = round(sum(live_pos_list) / n)
print(sum(map(lambda live_pos: cost(live_pos, mean_pos), live_pos_list)))


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

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

using namespace std;
using ll = long long;

void solve();

int main(void){
    int N;
    cin >> N;
    int A[N], B[N];
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> B[i];
    ll op = 0;
    rep(i, N){
        if(A[i] >= B[i]) continue;
        int v = B[i] - A[i];
        int temp;
        if (v % 2 == 0){
            temp = v / 2;
        }
        else{
            temp = v / 2 + 1;
        }
        A[i] += (temp << 1);
        op += temp;
    }
    rep(i, N){
        op -= A[i] - B[i];
    }
    if(op >= 0) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

void solve(){}

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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x, n)                                                       \
    for(long long hoge = 0; (hoge) < (n); ++(hoge))                            \
    cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

using ll = long long;
using ull = unsigned long long;
const ll INF = LLONG_MAX / 2;
const ll MOD = 1e9 + 7;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    int N;
    cin >> N;
    int C[N - 1], S[N - 1], F[N - 1];
    for(int i = 0; i < N - 1; i++) {
        cin >> C[i] >> S[i] >> F[i];
    }
    for(int i = 0; i < N; i++) {
        int ans = 0;
        for(int j = i; j < N - 1; j++) {
            if(ans < S[j])
                ans = S[j];
            if(ans % F[j] != 0)
                ans = (ans / F[j] + 1) * F[j];
            ans += C[j];
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int t = sc.nextInt();
		while(t--!=0){
			BigInteger b = sc.nextBigInteger().add(sc.nextBigInteger());
			System.out.println(b.toString().length()>80?"overflow":b.toString());
		}
	}
}

Measured memory_bytes: 18720
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;



int main() {
    

    char s;
    cin >> s;
    cout << (char)(s+1) << endl;



}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vi;

#define pb push_back
const ll mod = 1e9 + 7;

signed main() {
    ll n, k;
    cin >> n >> k;
    vi a(n);
    for (ll i = 0; i < n; ++i) {
        cin >> a[i];
    }
    ll sum = 0;
    sort(a.begin(), a.end());
    for (ll j = 0; j < n - k; ++j) {
        sum += a[j];
    }
    cout << sum << endl;
}

Measured memory_bytes: 1792
#include<stdio.h>

int main(){
   
    int W,H,x,y,r; 
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if(x<r||y<r||(x+r)>W||(y+r)>H){
    printf("No\n");
}  
    else{
    printf("Yes\n");
}
return 0;

}

Measured memory_bytes: 2644
#include <bits/stdc++.h>
using namespace std;
int min(int x,int y)
{
	if (x<y)
	{
		return x;
	}
	else
	{
		return y;
	}
}
int max(int x,int y)
{
	if (x>y)
	{
		return x;
	}
	else
	{
		return y;
	}
}
int main()
{
    ios::sync_with_stdio(0);
    int n,k;
    cin>>n>>k;
    int i,a[n+1];
    a[0]=0;
    for (i=1;i<=n;i++)
    {
    	cin>>a[i];
    }
    int l;
    l=0;
    long long minv=1000000000000000,ans;
    for (i=k;i<=n;i++)
    {
    	ans=0;
    	l++;
    	if (a[l]<0 && a[i]>=0)
    	{
    		ans=a[i]-a[l]+min(0-a[l],a[i]);
    	}
    	else if (a[i]>=0 && a[l]>=0)
    	{
    		ans=fabs(max(a[l],a[i]));
    	}
    	else if (a[i]<0 && a[l]<0)
    	{
    		ans=0-a[l];
    	}
    	if (ans<minv)
    	{
    		minv=ans;
    	}
    }
    cout<<minv<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n;
  cin>>n;
  ll a[n],b[n],c[n];
  rep(i,0,n){
    cin>>a[i];
  }
  rep(i,0,n){
    cin>>b[i];
  }
  rep(i,0,n){
    cin>>c[i];
  }
  sort(a,a+n);
  sort(b,b+n);
  sort(c,c+n);
  int d[n],e[n];
  rep(i,0,n){
    d[i]=upper_bound(b,b+n,a[i])-b;
    e[i]=upper_bound(c,c+n,b[i])-c;
  }
  ll f[n+1];
  f[0]=0;
  rep(i,0,n){
    f[i+1]=f[i]+(n-e[n-1-i]);
  }
  
  ll ans=0;
  rep(i,0,n){
    ans+=f[n-d[i]];
  }
  cout<<ans<<endl;
}

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

long long gcd(long long a, long long b) 
{ 
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
long long findGCD(long long arr[], int n) 
{ 
    long long result = arr[0]; 
    for (long long i = 1; i < n; i++) 
    { 
        result = gcd(arr[i], result); 
  
        if(result == 1) 
        { 
           return 1; 
        } 
    } 
    return result; 
} 
int main()
{
    long long k;
    cin>>k;
    long long i,j,p,sum=0;
    for(i=1;i<=k;i++)
    {
        for(j=1;j<=k;j++)
        {
            for(p=1;p<=k;p++)
            {
                long long arr[3];
                arr[0]=i;
                arr[1]=j;
                arr[2]=p;
                sum+=findGCD(arr, 3);
            }
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

void Input(int*,int*);
int Calc(int*,int*);
void Output(int*,int*,int*);

int main(int argc,char* argv[]){
  int n,count=0;
  int arr[100];

  Input(&n,arr);
  count=Calc(&n,arr);

  Output(&n,&count,arr);

  return 0;
}

void Input(int *pn,int *arr){
  cin>>*pn;
  for(int i=0;i<*pn;i++)
    cin>>*arr++;
}

int Calc(int *pn,int *arr){
  int count=0,now;
  for(int i=0;i<*pn;i++){
    now=i;
    for(int j=i+1;j<*pn;j++){
      if(arr[now]>arr[j])
	now=j;
    }
    if(arr[i]!=arr[now]) count++;
    swap(arr[i],arr[now]);    
  }
  return count;
}

void Output(int *pn,int *pcount,int *arr){

  printf("%d",*arr++);
  for(int i=1;i<*pn;i++)
    printf(" %d",*arr++);
  puts("");

  printf("%d\n",*pcount);
}

Measured memory_bytes: 1148
#include <bits/stdc++.h>
#define int long long
#define range(i,x,y) i=(x);i<(y);i++
#define rep(i,n) for(int i=0,i##_len=n;i<i##_len;i++)
#define all(x) begin(x),end(x)
#define lim(x,r,l) (r<=x&&x<l)
typedef long long ll;
typedef long double ld;
using namespace std;

signed main(){
  int n, a, b; cin >> n >> a >> b;
  int res = 0;
  rep(i,n){
    int x; cin >> x;
    if (x < a || b <= x){
      res ++;
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
    int n;
    cin >> n;
    vi a(n), b(n);
    vi sa(n);
    ll suma=0LL, sumb=0LL;
    rep(i, n) {
        cin >> a[i];
        suma += a[i];
    }
    rep(i, n) {
        cin >> b[i];
        sumb += b[i];
        sa[i] = a[i]-b[i];
    }

    if(sumb > suma) {
        cout << -1 << endl;
        return 0;
    }

    sort(sa.begin(), sa.end());
    if(sa[0] >= 0) {
        cout << 0 << endl;
        return 0;
    }
    deque<int> sad;
    rep(i, n) {
        sad.push_back(sa[i]);
    }
    while(!sad.empty()) {
        
        if(sad.front() + sad.back() > 0) {
            sad.back() = sad.front() + sad.back();
            sad.pop_front();
            if(sad.front() >= 0) {
                sad.pop_back();
                break;
            }
        } else if(sad.front() + sad.back() < 0) {
            sad.front() = sad.front() + sad.back();
            sad.pop_back();
        } else {
            sad.pop_back();
            sad.pop_front();
        }
        
    }

    cout << n-sad.size() << endl;
}

Measured memory_bytes: 1792
// AOJ Volume 0 Problem 0046

#include <stdio.h>

int main(void)
{
    float height;
    float min_height;
    float max_height;

	scanf("%f", &height);
	
	min_height = max_height = height;
    
    while (scanf("%f", &height) != EOF){
		if (height < min_height){
			min_height = height;
		}
		if (height > max_height){
			max_height = height;
		}
    }

	printf("%.1f\n", max_height - min_height);
	
	return (0);
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
using namespace std;
#define N 300000
 
int n,m,x,y,xb,p[N],q[N],dep[N];
bool vis[N];
vector<int> g[N];
 
bool dfs(int u, int fa) {
	int s = 0;
    vis[u] = 1;
    dep[u] = dep[fa] + 1;
	for ( auto v:g[u] ) {
		if ( !vis[v] ) {
			s ^= dfs(v, u);
		} else {
			if ( dep[v] > dep[u] ) {
				p[++xb] = u;
                q[xb] = v;
				s ^= 1;
			}
        }
    }
	if (s) {
        p[++xb] = u;
        q[xb] = fa;
    } else {
        p[++xb] = fa;
        q[xb] = u;
    }
	return s^1;
}

int main() {
	scanf("%d%d", &n, &m);
    //cin >> n >> m;
	for (int i=1; i<=m; ++i) {
		scanf("%d%d", &x, &y);
        //cin >> x >> y;
		g[x].push_back(y);
        g[y].push_back(x);
	}
	if ( !dfs(1,0) ) {
        puts("-1");
        //cout << "-1" << endl;
        return 0;
    }
	for (int i=1; i<=m; ++i) {
        printf("%d %d\n", p[i], q[i]);
        //cout << p[i] << ' ' << q[i] << endl;
    }

	return 0;
}


Measured memory_bytes: 20992
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <iomanip>
#include <bitset>
#include <set>
#include <map>
#include <stdio.h>
#include <numeric>
#include <cstring>

#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i < (n); i++)
#define FOR(i,a,b) for (int i=(a); i < (b); i++)
#define MOD 1000000007 //10^9+7
using namespace std;
using ll = long long;
using PII = pair<int, int>;
const int INF = numeric_limits<int>::max();

// 負の数にも対応した % 演算
long long mod(long long val, long long m) {
    long long res = val % m;
    if (res < 0) res += m;
    return res;
}

//greatest common divisor
long long gcd(ll a, ll b) 
{
    if (a % b == 0) {
        return b;
    } else {
        return gcd(b, a % b);
    }
}

//least common multiple
long long lcm(ll a, ll b)
{
    return a / gcd(a, b) * b ;
}

int main()
{
    string s, t; cin >> s >> t;
    int ans = 0;
    rep(i,3) {
        if (s[i] == t[i])
            ans++;
    }
    cout << ans << endl;
    return 0;
}


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

#define FOR(i, a, b) for(int i = a; i < b; i ++)
#define FORS(i, a, b, c) for(int i = a; i < b; i += c)
#define FORN(i, a, b) for(int i = a; i <= b; i ++)
#define FORD(i, a, b) for(int i = a-1; i >= b; i --)
#define FORE(i, b) for(auto &i:b)
#define REP(i, b) FOR(i, 0, b)
#define REPN(i, b) FORN(i, 0, b)
#define SQ(i) (i*i)
#define ALL(a) a.begin(), a.end()
#define ALLA(a,n) a, a+n
#define SORT(a) sort(ALL(a))
#define SORTA(a, n) sort(ALLA(a, n))
#define REV(a) reverse(ALL(a))
#define REVA(a, n) reverse(ALLA(a, n))
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define IN(a, b) (a.find(b) != a.end())
#define BACK(a) a.back(); a.RB()
#define QBACK(a) a.top(); a.pop()
#define PRINT(a) FORE(i, a) cout << i << " "; cout << endl

#define PB  push_back
#define RB  pop_back
#define RF  pop_front
#define INS insert
#define F   first
#define S   second
#define UM  unordered_map
#define US  unordered_set
#define PQ  priority_queue

#define IO ios_base::sync_with_stdio(false); cin.tie(NULL)

typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<ll,ll> pll;
typedef queue<int> qi;
typedef queue<double> qd;
typedef queue<ll> qll;
typedef US<int> si;
typedef US<double> sd;
typedef US<ll> sll;
typedef vector<vi> mi;
typedef vector<vd> md;
typedef vector<vll> mll;
typedef vector<pi> vpi;
typedef vector<pd> vpd;
typedef vector<pll> vpll;


int main(){
  IO; int K; string s; cin >> K >> s;
  if(s.size() <= K) cout << s;
  else cout << s.substr(0,K) << "...";
}


Measured memory_bytes: 3612
def max(a, b)
  a > b ? a : b
end

N = gets.to_i
a = []
N.times do |i|
  num = gets.to_i
  num.times do |j|
    x, y = gets.split.map(&:to_i)
    a << [i, x-1, y]
  end
end

mask = 0
ans = 0
while mask < 2 ** N
  check = Array.new(N)
  N.times do |i|
    check[i] = mask >> i & 1
  end
  pass = true
  a.each do |i, x, y|
    next if check[i] == 0
    if check[x] == y
      next
    else
      pass = false
      break
    end
  end
  mask += 1

  if pass
    check.compact!
    next if check.empty?
    ans = max(ans, check.inject(:+))
  end
end

p ans

Measured memory_bytes: 3836
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import itertools

n = int(readline())
xy = tuple(map(int,read().split()))

#解説ACです

def check(d):
    eps = 1/(10**10)
    points = []
    for c in itertools.combinations(range(n),2):
        x1,y1 = xy[c[0]*2 : c[0]*2+2]
        x2,y2 = xy[c[1]*2 : c[1]*2+2]

        dif = (x1-x2)**2 + (y1-y2)**2
        if(dif > 4*d**2):
            return False

        h = (d**2 - dif/4)**0.5
        xm,ym = (x1+x2)/2, (y1+y2)/2

        dx,dy = (y1-y2), -1*(x1-x2)
        dxy = (dx**2 + dy**2)**0.5

        points.append( (xm + dx*h/dxy, ym + dy*h/dxy)  )
        points.append( (xm - dx*h/dxy, ym - dy*h/dxy)  )

    for xp,yp in points:
        for i in range(n):
            xi,yi = xy[i*2:i*2+2]
            dif = (xp-xi)**2 + (yp-yi)**2
            if(dif > d**2 + eps):
                break
        else:
            return True

    return False

ok = 1000
ng = 0
for _ in range(50):
    mid = (ok+ng)/2
    if(check(mid)):
        ok = mid
    else:
        ng = mid

print(ok)

Measured memory_bytes: 75992
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  ll x;
  R x;
  if(x==3||x==5||x==7) pr("YES");
  else pr("NO");
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int maxn=200005,maxm=70;
struct datas { int A,B; } cow[maxn]; 
int n,cnt[maxm][maxm];
LL ans,num[maxn];
string S;
int main()
{
	scanf("%d",&n);
	for (int i=1,A,B;i<=n;i++)
	{
		cin>>S;
		int len=S.size(),pos=S.find('.');
		if (pos==string::npos) pos=len-1;
		for (int j=0,J=len+9-(len-pos-1);j<J;j++)
		{
			if (j<len && S[j]!='.') num[i]=num[i]*10+S[j]-48;
			if (j>=len) num[i]*=10;
		}
		//cerr<<">>>>>>"<<num[i]<<endl;
		A=B=0;
		while (!(num[i]&1))
		{
			A++;
			num[i]>>=1;
		}
		while (!(num[i]%5))
		{
			B++;
			num[i]/=5;
		}
		for (int x=max(18-A,0);x<maxm;x++)
			for (int y=max(18-B,0);y<maxm;y++)
				ans+=cnt[x][y];
		cnt[A][B]++;
	}
	printf("%lld\n",ans);
	return 0;
}


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

using namespace std;

int main()
{
	int N;
	int x = 0;
	int max = 0;
	string S;

	cin >> N >> S;

	for (int i = 0; i < N; i++)
	{
		if (S[i] == 'I')
			x++;
		else if (S[i] == 'D')
			x--;

		if (x > max)
			max = x;
	}

	cout << max << endl;

	return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PipedInputStream;
import java.util.*;

public class Main {
    private static final int MOD = (int) Math.pow(10, 9);
    private static final int[][] DIRS = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

    public static void main(String[] args) {
        FastReader sc = new FastReader();
        int a = sc.nextInt();

        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= 9; j++) {
                if (i*j == a) {
                    print("Yes");
                    System.exit(0);
                }
            }
        }
        print("No");
        System.exit(0);
    }

    static  private void print(String s) {
        System.out.println(s);
    }

    static private int log2(int x) {
        return (int)(Math.log(x) / Math.log(2));
    }

    static private long gcd(long m, long n) {
        if (m < n) { return gcd(n, m); }
        if (m % n == 0) { return n; }
        return gcd(n, m%n);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try{
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 21204
x,k,d=map(int,input().split())
b,c=abs(x%d),abs(-x%d)
mi=min(b,c)
if b<=c:
    a=abs(x//d)
else:
    a=abs(-x//d)
if k<a:
    print(min(abs(x-k*d),abs(x+k*d)))
else:
    if a%2==k%2:
        print(mi)
    else:
        print(min(abs(mi-d),abs(mi+d)))


Measured memory_bytes: 9116
a = int(input())
b = int(input())
c = int(input())
x = int(input())
n = 0
for A in range(a+1):
  for B in range(b+1):
    for C in range(c+1):
      if A*500+B*100+C*50 == x:
        n += 1
print(n)

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

using Cd = complex<double>;

inline Cd Circumcenter(Cd a, Cd b, Cd c) {

    //辺
    double eAB = abs(b - a);
    double eBC = abs(c - b);
    double eCA = abs(a - c);

    //角度(余弦定理)
    double aCAB = acos((eCA*eCA + eAB*eAB - eBC*eBC) / (2 * eCA*eAB));
    double aABC = acos((eAB*eAB + eBC*eBC - eCA*eCA) / (2 * eAB*eBC));
    double aBCA = acos((eBC*eBC + eCA*eCA - eAB*eAB) / (2 * eBC*eCA));

    double A = sin(2 * aCAB);
    double B = sin(2 * aABC);
    double C = sin(2 * aBCA);

    //外心の位置ベクトル(ベクトルの面積比の公式)
    Cd ans;
    ans.real((A*a.real() + B*b.real() + C*c.real()) / (A + B + C));
    ans.imag((A*a.imag() + B*b.imag() + C*c.imag()) / (A + B + C));

    return(ans);
}

inline double Circumradius(Cd a, Cd b, Cd c) {

    //辺
    double eAB = abs(b - a);
    double eBC = abs(c - b);
    double eCA = abs(a - c);

    //角度(余弦定理)
    double aCAB = acos((eCA*eCA + eAB*eAB - eBC*eBC) / (2 * eCA*eAB));

    //外接円の半径(正弦定理)
    double R = 0.5*eBC / sin(aCAB);

    return(R);
}




int N;
double eps = 0.0000005;
vector<Cd>z;

bool C1(double rad, Cd cen){
    for (int i = 0; i < N; ++i) {
        double dist = abs(cen - z[i]);
        if (dist > rad+eps) return false;
    }
    return true;
}

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

    double ans = 1000000;
    for (int i = 0; i < N; ++i) {
        for (int j = i+1; j < N; ++j) {
            double rad = abs(z[i] - z[j]) / 2;
            Cd cen = (z[i] + z[j]) / 2.0;
            if (C1(rad, cen)) ans = min(ans, rad);
        }
    }

    for (int i = 0; i < N; ++i) {
        for (int j = i+1; j < N; ++j) {
            for (int k = j+1; k < N; ++k) {
                double rad = Circumradius(z[i], z[j], z[k]);
                Cd cen = Circumcenter(z[i], z[j], z[k]);
                if (C1(rad, cen)) ans = min(ans, rad);
            }
        }
    }
    cout << setprecision(20) << ans << "\n";
    return 0;
}

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

int main (){
  int k;
  string s, ans;
  vector<char>t(0);  
  
  cin >> k >> s;
  
  if ((int)s.length() <= k) ans = s;
  else{

   rep(i, k){
   	t.push_back(s[i]); 
   }
    rep(i,3){
     t.push_back('.');
    }
  }
  rep(i, (int)t.size()){
   ans += t[i] ;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;


template<typename T> void drop(const T &x){cout<<x<<endl;exit(0);}

//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;
  vector< set<int> > G(n);
  for(int i=1;i<n;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    G[a].emplace(b);
    G[b].emplace(a);
  }

  vector<int> ls(n);
  for(int i=0;i<n;i++) ls[i]=G[i].size()==1;

  vector<int> cs(n);
  for(int v=0;v<n;v++)
    for(int u:G[v])
      cs[v]+=ls[u];

  for(int i=0;i<n;i++)
    if(cs[i]>=2) drop("First");

  queue<int> que;
  for(int i=0;i<n;i++)
    if(G[i].size()==2&&cs[i]) que.emplace(i);

  while(!que.empty()){
    int v=que.front();que.pop();
    for(int u:G[v]){
      G[u].erase(v);
      if(G[u].size()==1){
        ls[u]=1;
        int p=*G[u].begin();
        cs[p]+=ls[u];
        if(cs[p]>=2) drop("First");
        if(G[p].size()==2&&cs[p])
          que.emplace(p);
      }
      if(G[u].size()==2&&cs[u])
        que.emplace(u);
    }

    G[v].clear();
  }

  drop("Second");
  return 0;
}


Measured memory_bytes: 15232
#include <iostream>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <limits>
#include <math.h>
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define RREP(i,n) for(ll i=(n)-1; i>=0; --i)
#define SREP(i,s,n) for(ll i=(s), i##_len=(n); i<i##_len; ++i)


using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    if (b == 1) return 1;
    T r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}

bool comp(pair<ll, ll> a, pair<ll, ll> b) {
    return a.second > b.second;
}

struct UnionFind {
    vector<int> par;
    vector<int> rank;
    
    UnionFind(int n = 1) {
        init(n);
    }
    
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
        }
    }
    
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};

#define MOD (1000000007)

int main(int argc, const char * argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    ll N ,K;
    cin >> N >> K;
    vector<ll> A(N), F(N);
    
    REP(i, N) {
        cin >> A[i];
    }
    REP(i, N) {
        cin >> F[i];
    }
    sort(A.begin(), A.end());
    sort(F.begin(), F.end());
    
    ll lb = -1, ub = 1e12;
    while (lb + 1 < ub) {
        ll x = (lb+ub)/2;
        ll k = K;
        REP(i, N) {
            ll T = A[i]*F[N-i-1];
            if (T > x) {
                k -= (T-x+F[N-i-1]-1)/F[N-i-1];
            }
        }
        if (k >= 0) {
            ub = x;
        } else {
            lb = x;
        }
    }
    
    cout << ub << endl;

}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<string> A(N);
	priority_queue<pair<int, string> > qu;
	map<string, int> mp;
	set<string> st;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		st.insert(A[i]);
		//mp[A[i]] = 0;
		//qu.emplace(0, A[i]);
	}

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < i; j++) {
			bool ok = true;
			for (int k = 0; k < min(A[i].size(), A[j].size()); k++) {
				if (A[i][k] != A[j][k]) {
					ok = false;
					break;
				}
			}
			if (ok) {
				if (A[i].size() > A[j].size()) {
					qu.emplace(-((int)A[j].size()), A[i].substr(A[j].size(), A[i].size() - A[j].size()));
				}
				else {
					qu.emplace(-((int)A[i].size()), A[j].substr(A[i].size(), A[j].size() - A[i].size()));
				}
			}
		}

	}
	int INF = 1000000;
	int res = INF;
	while (qu.size() > 0) {
		string a = qu.top().second;
		int b = -qu.top().first;
		qu.pop();
		
		if (mp.find(a) != mp.end())continue;
		//cerr << a << " " << b << endl;
		auto s = st.find(a);
		if (s != st.end()) {
			//cerr << a << " " << b << endl;
			res = min(res, b + (int)a.size());
		}
		else {
			mp[a] = b;

			for (int i = 0; i < N; i++) {
				bool ok = true;
				for (int j = 0; j < min((int)A[i].size(), (int)a.size()); j++) {
					if (A[i][j] != a[j]) {
						ok = false;
						break;
					}
				}
				if (ok) {
					if (A[i].size() > a.size()) {
						qu.emplace(-(b + (int)a.size()), A[i].substr((int)a.size(), (int)A[i].size() - (int)a.size()));
					}
					else {
						qu.emplace(-(b + (int)A[i].size()), a.substr((int)A[i].size(), (int)a.size() - (int)A[i].size()));
					}
				}

			}

		}
	}
	if (res == INF)res = 0;
	cout << res << endl;
}


Measured memory_bytes: 3412
#include <bits/stdc++.h>
using namespace std;
int main(){
  int cnt=0;
  string s,t="",u="",alph="abcdefghijklmnopqrstuvwxyz",alphh="zyxwvutsrqponmlkjihgfedcba";
  cin >> s;
  if(s==alph){
    cout << "abcdefghijklmnopqrstuvwxz" << endl;
    return 0;
  }
  if(s.size()==26&&s==alphh){
    cout << -1 << endl;
    return 0;
  }else if(s.size()==26&&s!=alphh){
    for(int i=s.size()-1;i>=0;i--){
      if(s[i]!=alph[i]){
        cnt++;
        if(cnt==1){
          t+=s[i];
        }else if(cnt==2){
          u+=s[i];
        }
      }
      if(cnt==2){
        for(int j=s.size()-1;j>=0;j--){
          string ss=s.substr(j,s.size()-j);
          sort(ss.begin(),ss.end());
          for(int k=0;k<ss.size();k++){
            if(ss[k]>s[j-1]){
              cout << s.substr(0,j-1) << ss[k] << endl;
              return 0;
            }
          }
        }
      }
    }
  }
  t+=s;
  sort(s.begin(),s.end());
  for(int i=0;i<alph.size();i++){
    if(s[i]!=alph[i]){
      cout << t << alph[i] << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <cstring>
 
typedef long long ll;

#define rep(i,n) for(ll i = 0; i < n; i++)

using namespace std;
 
const ll INF = ll(1e18)+1;
const double PI=3.14159265358979323846;

int dp[1010][1010];

int main(){
  int N;
  cin >> N;
  rep(i,N){
    string x,y;
    cin >> x >> y;

    rep(i,x.size()){
      rep(j,y.size()){
	if(x[i] == y[j])
	  dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]+1);
	else{
	  dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j]);
	  dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j+1]);	  
	}
      }
    }
    cout << dp[x.size()][y.size()] << endl;
    memset(dp, 0, sizeof dp);
  }
}



Measured memory_bytes: 7120
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int start = 0;
        int end = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == 'A') {
                start = i;
                break;
            }
        }
        for (int i = s.length() - 1; i >= 0; i--) {
            if (s.charAt(i) == 'Z') {
                end = i;
                break;
            }
        }
        System.out.println(end - start + 1);
    }
}


Measured memory_bytes: 26544
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define deb(x) cerr << "\n" \
                    << #x << "=" << x << "\n";
#define deb2(x, y) cerr << "\n"                   \
                        << #x << "=" << x << "\n" \
                        << #y << "=" << y << "\n";
#define w(x)  \
    int x;    \
    cin >> x; \
    while (x--)
int n, m;
const int N = 1e5 + 2;
vector<vector<int>> v(N);
vector<int> ans(N, -1);
int dis[N];

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        v[a].push_back(b);
        v[b].push_back(a);
    }

    for (int i = 0; i < N; i++)
        dis[i] = INT_MAX;

    queue<pair<int, int>> q;
    q.push({1, 0});
    //  ans[1] = 0;

    while (!q.empty())
    {
        auto cur = q.front();
        q.pop();
        if (ans[cur.first] != -1)
            continue;

        ans[cur.first] = cur.second;

        for (int i : v[cur.first])
            if (ans[i] == -1)
                q.push({i, cur.first});
    }

    for (int i = 2; i <= n; i++)
        if (ans[i] == -1)
        {
            cout << "No";
            return 0;
        }
    cout << "Yes\n";

    for (int i = 2; i <= n; i++)
        cout << ans[i] << "\n";

    return 0;
}

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

typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;

int N;
viii F;
vii P;

int solve(void) {
	int max_p = (int)-2e9;
	int max_n = (1 << 10) - 1;
	for (int m = 1; m <= max_n; ++m) {
		int price = 0;
		int am = m & 0b0000011111;
		int pm = (m >> 5);
		for (int i = 0; i < N; ++i) {
			int cnt = 0;
			for (int j = 0; j < 5; ++j) {
				int bit = (1 << j);
				if (F[i][j][0] == 1 && (am & bit) != 0)
					++cnt;
				if (F[i][j][1] == 1 && (pm & bit) != 0)
					++cnt;
			}
			price += P[i][cnt];
		}
		max_p = max(price, max_p);
	}
	return max_p;
}

int main(void) {
	cin >> N;

	F.resize(N, vii(5, vi(2, 0)));
	P.resize(N, vi(11, 0));
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < 5; ++j) {
			for (int k = 0; k < 2; ++k)
				cin >> F[i][j][k];
		}
	}
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j <= 10; ++j)
			cin >> P[i][j];
	}

	int ans = solve();

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
def fibonacci(n):
    if n == 0 or n == 1:
        F[n] = 1
        return F[n]
    if F[n] is not None:
        return F[n]
    F[n] = fibonacci(n - 1) + fibonacci(n - 2)
    return F[n]


n = int(input())
F = [None]*(n + 1)
print(fibonacci(n))

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

using namespace std;

int answer, n, m;
long long int high[111111];

set<int> adj[111111];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		cin >> high[i];
	}

	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		adj[a].insert(b);
		adj[b].insert(a);
	}

	for (int i = 1; i <= n; i++) {
		int flag = 1;
		for (auto e : adj[i]) {
			if (high[i] <= high[e]) flag = 0;
		}
		if (flag) answer++;
	}

	cout << answer;
	return 0;
}

Measured memory_bytes: 18948
#include <iostream>
#include <set>
#include <string>
#include <vector>

using std::set;
using std::string;
using std::vector;

vector<int> solve(int N, const string &S, const vector<vector<string>> &queries)
{
	set<int> sets[26];
	for (int i = 0; i < S.size(); ++i)
	{
		sets[S[i] - 'a'].insert(i);
	}
	string T = S;
	vector<int> ans;
	for (const auto &query : queries)
	{
		if (query[0] == "1")
		{
			int i = std::stoi(query[1]) - 1;
			char c = query[2][0];
			sets[T[i] - 'a'].erase(i);
			T[i] = c;
			sets[T[i] - 'a'].insert(i);
		}
		else if (query[0] == "2")
		{
			int l = std::stoi(query[1]) - 1;
			int r = std::stoi(query[2]) - 1;
			int count = 0;
			for (int i = 0; i < 26; ++i)
			{
				auto it = sets[i].lower_bound(l);
				if (it != sets[i].end() && *it <= r) { ++count; }
			}
			ans.push_back(count);
		}
	}
	return ans;
}

int main(int argc, char *argv[])
{
	int N;
	std::cin >> N;

	string S;
	std::cin >> S;

	int Q;
	std::cin >> Q;

	vector<vector<string>> queries(Q);
	for (int i = 0; i < Q; ++i)
	{
		queries[i].resize(3);
		std::cin >> queries[i][0] >> queries[i][1] >> queries[i][2];
	}

	for (int ans : solve(N, S, queries))
	{
		std::cout << ans << std::endl;
	}

	return 0;
}


Measured memory_bytes: 28804
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import Data.Foldable (foldMap)
import Data.List.Split
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
 
readInt = read :: String -> Int
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
applyBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
applyBin op f g x = op (f x) $ g x
applyUni :: (a -> b -> c) -> (a -> b) -> a -> c
applyUni op f x = op x $ f x
applyTuple :: (a -> b, a -> c) -> a -> (b, c)
applyTuple (f,g) a = (f a, g a)
-- end of templete

main = unwords . filter (inRange (3,6) . length) . wordsBy (flip elem " .,") <$> getLine >>= putStrLn

Measured memory_bytes: 3808
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
# define rep(i,n) for(int i=0;i<n;i++)
void solve(){
    int n;
    cin>>n;
    lli a[n];
    
    lli mod =1e9+7;
    lli b[n];
    rep(i,n){
        cin>>a[i];
    }
    b[0]=a[0];
    for(int i=1;i<n;i++){
        b[i] = (a[i]+b[i-1])%mod;
    }
    lli ans = 0;
    for(int i=0;i<n;i++){

            lli x =b[n-1]-b[i];
            if(x<0)
                x+=mod;
            ans+=(a[i]*x);
            ans%=mod;
        
    }
    cout<<ans<<endl;
    


}
int main()
{
    int t;
    //cin>>t;
    
    t=1;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 6720
#include<stdio.h>
int main(void)
{
int a,b,c,d;
scanf("%d",&a);
scanf("%d",&b);
scanf("%d",&c);
if(!(a==b)){
	if(!(a==c)){
	d=a;
}}
if(!(b==a)){
	if(!(b==c)){
	d=b;
}}
if(!(c==a)){
	if(!(c==b)){
	d=c;
}}
printf("%d\n",d);
}

Measured memory_bytes: 128
require 'set'

N, M, P = gets.split.map(&:to_i)
abc_list = M.times.map do
  a, b, c = gets.split.map(&:to_i)
  [a - 1, b - 1, -(c - P)]
end
graph = Array.new(N) { [] }
abc_list.each do |(a, b, c)|
  graph[a].push([b, c])
end
reverse_graph = Array.new(N) { [] }
abc_list.each do |(a, b, c)|
  reverse_graph[b].push([a, c])
end

INF = 1 << 60

def reachable(graph, s)
  visit = Set.new
  visit.add(s)
  queue = [s]
  while !queue.empty?
    u = queue.shift
    graph[u].each.with_index do |(v, _)|
      next if visit.include?(v)
      visit.add(v)
      queue.push(v)
    end
  end
  visit
end

def bellman_ford(edge_list, s, max_count)
  d = Array.new(N, INF)
  d[s] = 0
  c = 0
  loop do
    is_update = false
    edge_list.each do |(u, v, c)|
      if d[u] != INF && d[u] + c < d[v]
        d[v] = d[u] + c
        is_update = true
      end
    end
    return d if !is_update
    c += 1
    return nil if c == max_count
  end
end

reachable_from_0 = reachable(graph, 0)
reachable_to_n = reachable(reverse_graph, N - 1)
v_set = Set.new
N.times do |v|
  v_set.add(v) if reachable_from_0.include?(v) && reachable_to_n.include?(v)
end
edge_list = abc_list.select do |(a, b, _)|
  v_set.include?(a) && v_set.include?(b)
end
ans = bellman_ford(edge_list, 0, v_set.size)
puts(ans == nil ? '-1' : [-(ans[N - 1]), 0].max)


Measured memory_bytes: 5500
#include<bits/stdc++.h>
using namespace std;
const int N=100;
int main()
{
    int n,cnt=0,a[N];
    scanf("%d",&n);
    if(n==0){
        return 0*printf("0\n");
    }
    while(n){
        if(n&1){
            a[cnt++]=1;
            n=(n-1)/(-2);
        }else{
            a[cnt++]=0;
            n=n/(-2);
        }
    }
    for(int i=cnt-1;i>=0;i--){
        printf("%d",a[i]);
    }
    return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<queue>
#include<stdio.h>
#include<string>
#include<string.h>
#define INF 2147483647
#define MP make_pair
using namespace std;
typedef pair<int,string> PAIR;
string start(int N){
	string st[9];
	st[0]="0";st[1]="1";st[2]="12";st[3]="123";st[4]="1234";
	st[5]="12345";st[6]="123456";st[7]="1234567";st[8]="12345678";
	return st[N];
}
int fact(int N){
	return (N==0)?1:N*fact(N-1);
}
string swapnumber(const string input,int a,int b){
	char str[9];
	char *pa,*pb;
	string before(input);
	strcpy(str,before.c_str());
	pa=strchr(str,'0'+a);pb=strchr(str,'0'+b);
	*pa='0'+b;*pb='0'+a;
	return str;
	//p=before.find(sa,0);pb=before.find(sb,0);
	
}
int main(void){
  int N;
  int c[8][8];
  map<string,int> node;//数列、コスト
  map<string,int>::iterator itr;
	priority_queue<PAIR,vector<PAIR>,greater<PAIR> > edge;//コスト,数列
  int ans=0;
  scanf("%d",&N);
  for(int i=0;i<N;i++){
    for(int j=0;j<N;j++){
    	scanf("%d",&c[i][j]);
    }
  }

  string startstr=start(N);
  node.insert(MP(start(N),0));
  for(int i=0;i<N;i++){
    for(int j=i+1;j<N;j++){
    	edge.push( MP(c[i][j],swapnumber(startstr,i+1,j+1)) );
    }
  }
  while(1){
	  pair<int,string> buf;
	  if(node.size()==fact(N)){
	  	break;
	  }
 	  while(1){
  		buf=edge.top();
	  	edge.pop();
  		if(node.count(buf.second)){//既に確定してたら
  			continue;
	  	}else{//初めてだったら
	  		break;
	  	}
	  }
	  node.insert(map<string,int>::value_type(buf.second,buf.first));
	  for(int i=0;i<N;i++){
    	for(int j=i+1;j<N;j++){
   			edge.push( MP( buf.first+c[i][j],swapnumber(buf.second,i+1,j+1) ) );
   		}
 	 	}
  }
	for (itr = node.begin(); itr != node.end(); itr++){
		if((itr->second)>ans){
			ans=itr->second;
		}
	}
	printf("%d\n",ans);
	
  return 0;
}

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

using namespace std;

#define lli long long int
#define pb  push_back
#define mp  make_pair

vector <lli> vv;

int main(){
    lli k,x;
    cin >> k >> x;

    x = x-k+1;
    k = 2*k-1;

    for(lli i=0; i<k; i++){
        cout << x << " ";
        x++;
    }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int MOD = (int)1e9 + 7;
const double PI = 3.14159265358979323846;

int main(void) {
  int n;
  cin >> n;
  //   vector<int> a(n + 1);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    // cin >> a[i];
    int a;
    cin >> a;
    if (i % 2 == 1 && a % 2 == 1) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
#include "bits/stdc++.h"
using namespace std;
int main(){
  int n;
  string s;
  string ans = "";
  string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
  cin >> n;
  cin >> s;
  for(int i = 0;i < s.length();i++){
    string tmp = ABC.substr(ABC.find(s.substr(i,1)) + n, 1);
    ans = ans + tmp;
    //cout << "TMP: " << tmp << " ANS: " << ans << endl;
  }
  //string tmp = ABC.find(s.substr(0,1);
  cout << ans;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
    int64_t sosuu = 1000000007;

    int k;
    string S;

    cin >> k >> S;

    int s = S.size();

    vector<int64_t> beki26;
    beki26.push_back(1);
    for(int i = 1 ; i <= k ; i++){
        beki26.push_back((beki26.at(i - 1) * 26) % sosuu);
    }

    vector<int64_t> beki25;
    beki25.push_back(1);
    for(int i = 1 ; i <= k ; i++){
        beki25.push_back((beki25.at(i - 1) * 25) % sosuu);
    }

    combination c(s + k);

    mint result = 0;
    for(int i = 0 ; i <= k ; i++){
        mint temp = beki26.at(k - i);
        temp *= beki25.at(i);
        temp *= c(i+s-1, s-1);
        result += temp;
    }

    cout << result << endl;
    

}

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

int main(){
  ll n;
  cin>>n;
  ll sum=0;
  ll k;
  for(int i=1;i<=n;i++){
    sum+=i;
    if(sum<n)continue;
    k=i;
    break;
  }
  for(int i=1;i<=k;i++){
    if(i==sum-n)continue;
    cout<<i<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
M = 10 ** 9 + 7

x, y = map(int, input().split())

r = 0
if (x + y) % 3 == 0:
  a, b = (2 * y - x) // 3, (2 * x - y ) // 3
  if a >= 0 <= b:
    f = [1]
    for i in range(1, a + b + 1):
      f.append(f[-1] * i % M)
    r = f[a + b] * pow(f[a] * f[b], M - 2, M) % M
print(r)


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

int main() {
    ll a, b, c;
    cin >> a >> b >> c;
    int d = a%b;
    if(d==c) { cout << "YES" << endl; return 0;}
    int i = 2;
    bool ok = false;
    while(1){
        int e = (a*i)%b;
        if(e==c) {ok = true; break;}
        if(e==d) break;
        ++i;
    }

    if(ok) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

int main() {
  string s;
  cin >> s;

  if(s.at(2) == s.at(3) && s.at(4) == s.at(5)){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256