akhauriyash/Code-Regression huggingface dataset:
n = int(input())
h = list(map(int, input().split()))

dp=[0] * n
for i in range(1, n):
  if i - 2 < 0:
    dp[i] = dp[i-1] + abs(h[i] - h[i-1])
  else:
    dp[i] = min(dp[i-2]+abs(h[i] - h[i-2]) ,dp[i-1]+abs(h[i]-h[i-1]) )
  
print(dp[n-1])

Measured memory_bytes: 13928
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std;

int main(){
    int n; cin >> n;
    vector<int> as(n), bs(n), cs(n-1);
    for(int i=0; i<n; ++i){
        cin >> as[i];
        --as[i];
    }
    int ans=0;
    for(int i=0; i<n; ++i){
        int b; cin >> b;
        ans+=b;
    }
    for(int i=0; i<n-1; ++i) cin >> cs[i];
    for(int i=0; i<n-1; ++i){
        if(as[i]+1==as[i+1]) ans+=cs[as[i]];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
typedef int long long ll;
using namespace std;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
    string n;
    cin>>n;
    //reverse(n.begin(),n.end());
   int ans=0;
    int i=0;

    if(n[1]=='0'){
       // cout<<n[0]<<"a"<<endl;
        ans+=10*(n[0]-'0');
        i=2;
    }
    
    for(;i<n.size();i++){
        ans+=(n[i]-'0');
    }
    
    cout<<ans<<endl;
  
    
  
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define endl '\n'
#define int long long
double pi=3.14159265359;

int32_t  main()
{
    IOS; 
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    int mi=h*60+m;
    double tmp=mi;
    mi%=(12*60);
    double a1=360.0*(m/60);
    double b1=360.0*(mi/(12.0*60));
    cout<<fixed<<setprecision(10);
    double ang=min(abs(a1-b1),abs(360.0-abs(a1-b1)));
    ang*=(pi/180);
    cout<<sqrt(a*a+b*b-2*a*b*cos(ang));
}

Measured memory_bytes: 4204
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque
import copy

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

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


def req_count(P, K, W):
    cnt = 0
    for k in range(K):
        p = 0
        while p + W[cnt] <= P:
            p += W[cnt]
            cnt += 1
            if cnt == len(W):
                return cnt
    else:
        return cnt


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, K = il()
    W = [ii() for _ in range(N)]

    left, right = 0, sum(W)
    while right - left != 1:
        middle = (left + right) // 2
        n = req_count(middle, K, W)
        if n >= N:
            right = middle
        else:
            left = middle
    print(right)


if __name__ == '__main__':
    main()



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



int main(){
    ll n,k;
    scanf("%lld",&n);
    scanf("%lld",&k);
    ll result = 0;
    ll min_ary[n+1];
    ll max_ary[n+1];

    min_ary[0] = 0;
    max_ary[0] = n;
    rep1(i,n){
        min_ary[i] = min_ary[i-1] + i;
        max_ary[i] = max_ary[i-1] + n - i;
    }

    for(ll i=k-1;i<=k-1+n+1-k+1-1;i++){
        // printf("%lld\n",max_ary[i] - min_ary[i] + 1);
        result = result + max_ary[i] - min_ary[i] + 1;
    }
    printf("%lld",result % 1000000007);
}

Measured memory_bytes: 6940
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
    /*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}

int main() {    
    ll n,m,k;
    cin >> n >>m >> k;
    vector<ll>a(n),b(m);
    for(int i=0;i<n;i++){
        cin >> a.at(i);
    }
    for(int j=0;j<m;j++){
        cin >> b.at(j);
    }
    vector<ll>ra(n+1,0),rb(m+1,0);
    for(int i=0;i<n;i++){
        ra.at(i+1)=ra.at(i)+a.at(i);
    }
    for(int j=0;j<m;j++){
        rb.at(j+1)=rb.at(j)+b.at(j);
    }
    ll ans = 0;
    for(int i=0;i<=n;i++){
        if(k-ra.at(i)<0)continue;
        ll che = k-ra.at(i)+1;
        ll dd = lower_bound(rb.begin(),rb.end(),che)-rb.begin();
        dd--;
        ans = max(ans,i+dd);
    }
    cout<<ans<<endl;
}
    



Measured memory_bytes: 9500
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,f;cin>>n>>f;
  for(int i=0;i<=n;i++){
  	int j = n-i;
    if((2*i+4*j)==f){cout<<"Yes";return 0;}
  }
      cout<<"No";
}

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

using namespace std;

const int MX = 200002;

template<typename T> void cmax(T &x, const T &y)
{
	if(y > x) x = y;
}

template<typename T> void read(T &x)
{
	x = 0;
	char c = getchar();
	bool f = 0;
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

int deg[MX];
int fst[MX], nxt[MX], v[MX], lnum;
int n, m;

void addeg(int nu, int nv)
{
	nxt[++lnum] = fst[nu];
	fst[nu] = lnum;
	v[lnum] = nv;
	deg[nv]++;
}

void input()
{
	read(n), read(m);
	for(int i=1; i<=m; i++)
	{
		int nu, nv;
		read(nu), read(nv);
		addeg(nu, nv);
		addeg(nv, nu);
	}
}

void out_no()
{
	puts("No");
	exit(0);
}

void out_yes()
{
	puts("Yes");
	exit(0);
}

void check(int x, int y)
{
	queue<int> que;
	static int way[MX];
	memset(way, 0, sizeof(way));
	que.push(x);
	way[x] = 1;
	while(!que.empty())
	{
		int a = que.front();
		que.pop();
		if(a == y) continue;
		for(int i=fst[a]; i; i=nxt[i])
		{
			int b = v[i];
			if(!way[b]) que.push(b);
			way[b] += way[a];
		}
	}
	if(way[y] == 2) out_yes();
	else if(way[y] == 4) out_no();
	else assert(0);
}

void work()
{
	for(int i=1; i<=n; i++) if(deg[i]&1) out_no();
	for(int i=1; i<=n; i++) if(deg[i] >= 6) out_yes();
	vector<int> v4;
	for(int i=1; i<=n; i++) if(deg[i] == 4) v4.push_back(i);
	if(v4.size() <= 1) out_no();
	else if(v4.size() == 2) check(v4[0], v4[1]);
	else out_yes();
}

int main()
{
	input();
	work();
	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n)  for (int i = 0; i < (int) (n); i++)
#define REP1(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x)     (x).begin(), (x).end()
#define SZ(x)      ((int) (x).size())
using ll = long long;

int main() {
  int n;
  cin >> n;
  ll ans = 0;
  REP1(i, n) {
	if (i % 3 && i % 5) {
		ans += i;
	  }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair <ll, ll> l_l;
typedef pair<int, int> i_i;

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

# define EPS (1e-7)
# define INF (1e9)
# define PI (acos(-1))
//const ll mod = 1000000007;

double W, H, x, y;

int main() {
    cin >> W >> H >> x >> y;

    cout << W * H / 2 << " ";
    if (W / 2 == x && H / 2 == y) {
        cout << 1 << endl;
    } else {
        cout << 0 << endl;
    }
    return 0;
}

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

int main(){
 int a,b,k,cnt=0;
 cin>>a>>b>>k;
 for(int i=100;i>=1;i--){
   if(a%i==0 && b%i==0){
     cnt++;
     if(cnt==k){
       cout << i << endl;
       break;
     }
   }
 }
  
 return 0; 

}

Measured memory_bytes: 256
import math
n,p=map(int,input().split())
p_sqrt=int(math.sqrt(p))
ans=1

for i in range(2,p_sqrt+1):
  cnt=0
  while p%i==0:
    p//=i
    cnt+=1
  ans*=i**(cnt//n)

ans*=p**(1//n)
print(ans)

Measured memory_bytes: 64104
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  vector<int> A(3);
  for(auto& a : A) cin >> a;

  boost::sort(A, std::greater<int>());
  ll ans{};
  ans += A[0] - A[1];
  A[1] += ans;
  A[2] += ans;
  assert(A[0] == A[1]);
  assert(A[1] >= A[2]);
  auto diff = A[1] - A[2];
  ans += diff % 2 ? (diff + 1) / 2 + 1 : diff / 2;

  cout << ans << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 256
using System;


    public static class Program
    {
    static void Main()
    {
        var data1 = Console.ReadLine();
        var data2 = data1.Split(' ');
        var a = int.Parse(data2[0]);
        var b = int.Parse(data2[1]);
        var c = int.Parse(data2[2]);
        if (a < b && b < c)
        {
            Console.WriteLine("Yes");
        }
        else 
        {
            Console.WriteLine("No");
        }
       
    }
    }


Measured memory_bytes: 15960
import numpy as np
import scipy as sp
import math

def main():
    # parse
    N, M = parse(get_stdin())
    # compute
    result = compute(N, M)
    # show result
    print(result)

def compute(N, M):
    a = abs(N - M)
    if a >= 2:
        return 0
    elif a == 1:
        return (math.factorial(N) * math.factorial(M)) % (10**9+7)
    else:
        return 2*(math.factorial(N) * math.factorial(M)) % (10**9+7)

def get_stdin():
    return input()

def split_stdin(stdin_val, delimiter = ' '):
    return [x for x in stdin_val.split(delimiter) if x != '']

def parse(stdin_vars):
    vars = split_stdin(stdin_vars)
    return int(vars[0]), int(vars[1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 14312
#include<iostream>
#include<algorithm>
#include<string>
#include<typeinfo>
#include<cstdlib>
using namespace std;
int b[1000][1001];
int main() {
	int w, n;
	int sum = 1;
	while (cin >> w&&w != 0) {
		cin >> n;
		int a[1000][2];
		for (int i = 0; i < n; i++) {
			string h;
			cin >> h;
			h += ",";
			string k = "";
			int l = 0;
			for (int j = 0; j < h.length(); j++) {
				if (h[j] == ',') {
					a[i][l] = atoi(k.c_str());
					k = "";
					l++;
				}
				else
					k += h[j];
			}
		}
		int sum1 = 0, sum2 = 1002;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j <= w; j++) {
				b[i][j] = -1;
				if (j == 0) b[i][j] = 0;
			}
		}
		b[0][a[0][1]] = a[0][0];
		for (int i = 1; i < n; i++) {
			for (int j = 0; j <= w; j++) {
				int l = -1;
				if (j - a[i][1] >= 0) {
					if (b[i - 1][j - a[i][1]] != -1 && b[i - 1][j] != -1)
						l = max(b[i - 1][j], b[i - 1][j - a[i][1]] + a[i][0]);
					else if (b[i - 1][j - a[i][1]] != -1)
						l = b[i - 1][j - a[i][1]] + a[i][0];
					else if (b[i - 1][j] != -1)
						l = b[i - 1][j];
				}
				else if (b[i - 1][j] != -1)
					l = b[i - 1][j];
				b[i][j] = max(l, b[i][j]);
			}
		}
		for (int i = w; i >= 0; i--) {
			if (b[n - 1][i] >= sum1) {
				sum1 = b[n - 1][i];
				sum2 = i;
			}
		}
		cout << "Case " << sum << ":" << endl;
		cout << sum1 << "\n" << sum2 << endl;
		sum++;
	}
}

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

int main(){
	int a,b,c,x;
	cin >> a >> b >> c;
	if(a>b){
		x=a;
		a=b;
		b=x;
	}
	if(b>c){
		x=b;
		b=c;
		c=x;
	}
	if(a>b){
		x=a;
		a=b;
		b=x;
	}
	cout << a << " "<< b << " " << c << endl;

	return 0;
}



Measured memory_bytes: 3108
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<tuple>
#include<ctime>
#include<functional>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p; 
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))

int main(){
    int N,a;
    cin>>N;
    a=N%10;
    if(a==3) p("bon");
    else if(a==0||a==1||a==6||a==8)p("pon");
    else p("hon");

}

Measured memory_bytes: 3624
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

char s[200000];

int main()
{
  int i,j,k,l,ans,b1;
  scanf("%s",s);
  l=strlen(s);
  i=0;j=l-1;
  b1=1;
  ans=0;
  while (i<j)
  {
    if (s[i]==s[j])
    {
      i++;j--;
    }
    else if (s[i]=='x')
    {
      i++;
      ans++;
    }
    else if (s[j]=='x')
    {
      j--;
      ans++;
    }
    else
    {
      b1=0;break;
    }
  }
  if (b1==0) printf("-1\n");
  else printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 384
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
typedef long long ll;
ll n;
int x, m;
const int maxN = 1e5 + 10;
int was[maxN];
int cur[maxN];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("input.txt", "r", stdin);
    memset(was, -1, sizeof was);
    cin >> n;
    cin >> x >> m;
    cur[0] = x;
    int from = -1;
    int to = -1;
    was[x] = 0;
    for (int i = 1; ; i++) {
        cur[i] = (1LL * cur[i - 1] * cur[i - 1]) % m;
        if (was[cur[i]] != -1) {
            from = was[cur[i]];
            to = i - 1;
            break;
        }
        else {
            was[cur[i]] = i;
        }
    }
    ll sum_per = 0;
    for (int i = from; i <= to; i++) sum_per += cur[i];
    // to + tot_cyc * (to - from + 1)
    if (n - 1 <= to) {
        ll all = 0;
        for (int i = 0; i < n; i++) all += cur[i];
        cout << all;
        return 0;
    }
    ll tot_cyc = (n - 1 - to) / (to - from + 1);
    ll ans = (tot_cyc + 1) * sum_per;
    for (int j = 0; j < from; j++) ans += cur[j];
    ll p1 = (tot_cyc + 1) * (to - from + 1) + from;
    for (ll j = 0; j < n - p1; j++) {
        ans += cur[j + from];
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 4236
#include <cstdio>
#include <vector>

struct Node {
  int pos;
  int symbol;
};

bool can(std::vector<int> &lens, int c) {
  std::vector<Node> v;
  int len = 0;
  for (auto new_len : lens) {
    if (new_len <= len) {
      while (!v.empty() && v.back().pos >= new_len) {
        v.pop_back();
      }
      int pos = new_len - 1;
      while (true) {
        if (v.empty() || v.back().pos < pos) {
          if (c == 0) {
            return false;
          }
          v.push_back({pos, 1});
          break;
        }
        if (v.back().symbol < c) {
          v.back().symbol++;
          break;
        }
        if (pos == 0) {
          return false;
        }
        pos--;
        v.pop_back();
      }
    }
    len = new_len;
  }
  return true;
}
int main(void) {
  int n;
  while (scanf("%d", &n) == 1) {
    std::vector<int> lens(n);
    for (auto &x : lens) {
      scanf("%d", &x);
    }
    int l = -1, r = n;
    while (l + 1 < r) {
      int c = (l + r) / 2;
      if (can(lens, c)) {
        r = c;
      } else {
        l = c;
      }
    }
    printf("%d\n", r + 1);
  }
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
typedef long long ll;
const int inf = 1e9;
using namespace std;
const ll mod = 1e9+7;





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

    ll n;
    cin >> n;
    ll a[n];
    for(ll i = 1; i <= n; i++) cin >> a[i];

    ll ans = 0;
    ll s = 0;
    for(int i = 1; i <= n; i++){
        ans += s*a[i];
        s += a[i];
        s %= mod;
        ans %= mod;
    }
    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 5148
import java.util.*;

class Pair {
    int A, B;

    Pair(int A, int B) {
        this.A = A;
        this.B = B;
    }

    int getA() {
        return this.A;
    }

    int getB() {
        return this.B;
    }
}

class MyComparator implements Comparator<Pair>{
	public int compare(Pair Pair1, Pair Pair2) {
		return Pair1.getB() - Pair2.getB();
	}
}

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Pair[] Ps = new Pair[N];
        for(int i = 0; i < N; i++) {
            int A = sc.nextInt();
            int B = sc.nextInt();
            Pair pair = new Pair(A,B);
            Ps[i] = pair;
        }
        Arrays.sort(Ps, new MyComparator());

        long sum = 0;
        boolean cando = true;
        for(int i = 0; i< N; i++) {
            sum += (long)Ps[i].A;
            if(sum > (long)Ps[i].B) {
                cando = false;
                break;
            }
        }
        if(cando) System.out.println("Yes");
        else System.out.println("No");
        sc.close();
    }
}

Measured memory_bytes: 105140
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll ans = n;
    for(ll i = 1; i*i <= n; ++i){
        if(n%i != 0) continue;
        chmin(ans, (i-1) + (n/i - 1));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main() {
  char x;
  cin >> x;
  char y =++x;
  cout << y<< endl;
}
      
 

Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        while(true){
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
            if(m==-1&&f==-1&&r==-1)
                break;
            else if(m==-1 || f==-1){
                System.out.println("F");}
            else if(m+f >= 80){
                System.out.println("A");}
            else if(m+f >= 65){
                System.out.println("B");}
            else if(m+f >= 50){
                System.out.println("C");}
            else if(m+f >= 30){
                if(r >= 50){
                System.out.println("C");
                }
                else{System.out.println("D");
                    }
           }
            else if(m+f < 30){
                System.out.println("F");
                }
        }
        sc.close();
    }
}


Measured memory_bytes: 26416
#include<iostream>
#include<vector>
#include<string>
#include<climits>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<queue>


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

	std::vector<int> aList(n);
	for(int i=0; i<n; i++)
		std::cin>>aList[i];

	std::sort(aList.begin(), aList.end(), [](int x, int y){return x> y;});

	bool isExistPos= false;
	bool isExistNeg= false;

	int changeIdx=n;

	for(int i=1; i<n; i++){
		if(aList[i]>=0)
			isExistPos=true;

		if(aList[i]<0){
			isExistNeg=true;
			changeIdx= i;
			break;
		}
	}

	long long ans= aList[0];

	if(!isExistPos && isExistNeg){
		for(int i= 1; i< n; i++)
			ans-= aList[i];
	}else if(isExistPos && !isExistNeg){
		long long tmp=aList[n-1];
		for(int i= n-2; i>0; i--)
			tmp-=aList[i];

		ans-=tmp;
	}else{
		long long tmp= aList[n-1];
		for(int i=1; i< changeIdx; i++)
			tmp-= aList[i];

		ans-= tmp;

		for(int i=n-2; i>=changeIdx; i--)
			ans-= aList[i];
	}

	std::cout<<ans<<std::endl;


	ans= aList[0];


	if(!isExistPos && isExistNeg){
		for(int i= 1; i< n; i++){
			std::cout<<ans<<" "<<aList[i]<<std::endl;
			ans-= aList[i];
		}

	}else if(isExistPos && !isExistNeg){
		long long tmp=aList[n-1];
		for(int i= n-2; i>0; i--){
			std::cout<<tmp<<" "<<aList[i]<<std::endl;
			tmp-=aList[i];
			
		}

		std::cout<<ans<<" "<<tmp<<std::endl;
		ans-=tmp;
		

	}else{
		long long tmp= aList[n-1];
		for(int i=1; i< changeIdx; i++){
			std::cout<<tmp<<" "<<aList[i]<<std::endl;
			tmp-= aList[i];
			
		}

		std::cout<<ans<<" "<<tmp<<std::endl;
		ans-= tmp;

		for(int i=n-2; i>=changeIdx; i--){
			std::cout<<ans<<" "<<aList[i]<<std::endl;
			ans-= aList[i];
			
		}

		
	}

	

	return 0;
	
}

Measured memory_bytes: 2304
MOD = 10 ** 9 + 7
N = gets.to_i
X = gets.split.map(&:to_i)

counter = Hash.new(0)
min_rank = 1
limit = 1

X.each do |x|
  counter[min_rank] += 1

  if limit <= x
    limit += 2
  else
    min_rank += 1
  end
end

ans = 1
cnt = 0

1.upto(N) do |rank|
  cnt += counter[rank]

  ans *= cnt
  ans %= MOD

  cnt -= 1
end

puts ans


Measured memory_bytes: 22872
using System;
using static System.Console;
using System.Linq;

namespace AC
{
   public class shiokara
   {
      static void Main(string[] args)
      {
          int n = int.Parse(ReadLine());
          int[] a = ReadLine().Split(' ').Select(int.Parse).ToArray();
          for(int i = 0; i < n; i++){
              if(a[i] % 2 == 0){
                  if(a[i] % 3 == 0){

                  }else if(a[i] % 5 == 0){

                  }else{
                      WriteLine("DENIED");
                      return;
                  }
              }
          }
          WriteLine("APPROVED");
      }
   }
}

Measured memory_bytes: 13396
x, n = gets.chomp.split.map(&:to_i)
ary = gets.chomp.split.map(&:to_i)

c_set = (0..101).to_a - ary

ge_num = c_set.find{|i| i >= x}
ge_num_idx = c_set.index{|i| i >= x}
le_num = c_set[0..ge_num_idx].reverse.find{|i| i <= x}

diff1 = x - le_num
diff2 = ge_num - x

ans = diff2 >= diff1 ? le_num : ge_num
puts ans



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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(5e3 + 5);

/////////////////////////////////////////////////////////////
class RollingHash {
 public:
  using hash_type = tuple<ll, ll, ll>;

  string s;

  ll base1;
  ll base2;
  ll base3;

  ll mod1;
  ll mod2;
  ll mod3;

  vector<ll> hash1;
  vector<ll> hash2;
  vector<ll> hash3;

  vector<ll> pow1;
  vector<ll> pow2;
  vector<ll> pow3;

  RollingHash(string s) {
    this->s = s;

    this->base1 = 1009LL;
    this->base2 = 1007LL;
    this->base3 = 1005LL;

    this->mod1 = (ll)(1e9 + 7);
    this->mod2 = (ll)(1e9 + 9);
    this->mod3 = (ll)(999999937);

    init(s);
  }

  void init(const string &s) {
    int n = s.size();

    hash1.assign(n + 1, 0);
    hash2.assign(n + 1, 0);
    hash3.assign(n + 1, 0);

    pow1.assign(n + 1, 1);
    pow2.assign(n + 1, 1);
    pow3.assign(n + 1, 1);

    for (int i = 0; i < n; i++) {
      hash1[i + 1] = (hash1[i] + s[i]) * base1 % mod1;
      hash2[i + 1] = (hash2[i] + s[i]) * base2 % mod2;
      hash3[i + 1] = (hash3[i] + s[i]) * base3 % mod3;

      pow1[i + 1] = pow1[i] * base1 % mod1;
      pow2[i + 1] = pow2[i] * base2 % mod2;
      pow3[i + 1] = pow3[i] * base3 % mod3;
    }
  }

  // 1-indexed, [l, r]
  hash_type get(int l, int r) {
    l -= 1;

    ll t1 = ((hash1[r] - hash1[l] * pow1[r - l]) % mod1 + mod1) % mod1;
    ll t2 = ((hash2[r] - hash2[l] * pow2[r - l]) % mod2 + mod2) % mod2;
    ll t3 = ((hash3[r] - hash3[l] * pow3[r - l]) % mod3 + mod3) % mod3;

    return make_tuple(t1, t2, t3);
  }

  // get hash for whole string
  hash_type get_whole() {
    return get(1, s.size());
  }
};
/////////////////////////////////////////////////////////////

int n;
string s;

bool check(int length, RollingHash &rh) {
  map<RollingHash::hash_type, int> mp;

  for (int i = 0; i < s.size(); ++i) {
    int end_pos = i + length - 1;

    if (end_pos >= s.size()) break;

    int l = i + 1;
    int r = end_pos + 1;

    RollingHash::hash_type hash = rh.get(l, r);

    auto ptr = mp.find(hash);

    if (ptr != mp.end()) {
      if (ptr->second + length - 1 < i) {
        return true;
      }
    } else {
      mp[hash] = i;
    }
  }

  return false;
}

int main(void) {
  // Here your code !
  scanf("%d", &n);

  cin >> s;

  RollingHash rh(s);

  int ok = 0;
  int ng = s.size();

  while (abs(ok - ng) > 1) {
    int next = (ok + ng) / 2;

    if (check(next, rh)) {
      ok = next;
    } else {
      ng = next;
    }
  }

  int ans = ok;

  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 1024
n,m=map(int,input().split())
l=[]
for i in range(m):
    order=list(map(int,input().split()))
    l.append(order)

if n==1:
    for i in range(10):
        if all(str(i)[l[j][0]-1]==str(l[j][1]) for j in range(m)):
            print(i)
            exit()
elif n==2:
    for i in range(10,10**2):
        if all(str(i)[l[j][0]-1]==str(l[j][1]) for j in range(m)):
            print(i)
            exit()
else:
    for i in range(10**2,10**3):
        if all(str(i)[l[j][0]-1]==str(l[j][1]) for j in range(m)):
            print(i)
            exit()
print(-1)

Measured memory_bytes: 9220
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
  int M=1000,N,X,ans=0,sum=0;
  cin>>N>>X;
  int m[N];
  for(int i=0;i<N;i++){
    cin>>m[i];
    sum+=m[i];
    M=min(M,m[i]);
  }
  X-=sum;
  while(X>=0){
    X-=M;
    ans++;
  }
  cout<<ans+N-1<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
using namespace std;
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;

int main() {
  ll a, b; cin >> a >> b;
  ll g = __gcd(a, b);
  if (g == 1) {
    cout << 1 << endl;
    return 0;
  }
  ll cnt = 0;
  for (ll i = 2; i*i <= g; i++) {
    if (g%i == 0) {
      cnt++;
      while (!(g%i)) g /= i;
    }
  }
  if (g != 1) cnt++;
  cout << cnt + 1 << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  
  
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n=sc.nextInt();
    int[] brick = new int[n];
    int ans=0,p=1;
    
    for(int i=0;i<n;i++)brick[i]=sc.nextInt();
    for(int i=0;i<n;i++){
      if(brick[i]==p)p++;
      else ans++;
    }
    if(p==1)ans=-1;
    System.out.println(ans);
  }
}

Measured memory_bytes: 76484
N, A, B = map(int, input().split())
if abs(A - B) % 2 == 0:
    print(abs(A - B) // 2)
else:
    left = A + (B - A - 1) // 2
    right = N - B + 1 + (B - A - 1) // 2
    print(min(right, left))


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(){
    int n;
    cin >> n;
    map<long long, long long> m;
    for(int i = 0; i < n; i++){
        long long a;
        cin >> a;
        m[a]++;
    }
    int ans = 0;
    for(auto x : m){
        if(x.second % 2 == 1){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6528
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)



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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

template<typename... Types>
struct dynarr: std::vector<Types...> {
  using std::vector<Types...>::vector;
  using size_type = typename std::vector<Types...>::size_type;
  auto&& operator[](size_type i) { return this->at(i); }
  auto&& operator[](size_type i) const { return this->at(i); }
};

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

  for(int i = 0;i < n;i++)  {
    string s;
    cin >> s;
    if(s[0] == 'n') {
      x += a;
    }
    if(s[0] == 't') {
      x += b;
    }
    if(s[0] == 'k') {
      x = 0;
    }
    if(x <= 0) {
      x = 0;
    }
  }
  cout << x << endl;
}



Measured memory_bytes: 3184
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
using namespace std;
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

Int dp[110000][110][2];
Int d;
string K;
int main(){
    cin >> K;
    cin >> d;
    int n = K.size();

    dp[0][0][1] = 1;

    for(int i = 1;i <= n;i++){
        for(int j = 0;j < d;j++){
            int digit = K[i-1] - '0';
            for(int k = 0;k < 10;k++){
                dp[i][j][0] += dp[i-1][((j-k)%d+d)%d][0];
                if(k < digit)dp[i][j][0] += dp[i-1][((j-k)%d+d)%d][1];
                dp[i][j][0] %= MOD;
            }
            dp[i][j][1] = dp[i-1][((j-digit)%d+d)%d][1];
        }
    }
    cout << (dp[n][0][0] + dp[n][0][1] + MOD - 1)  % MOD << endl;
    return 0;
}

Measured memory_bytes: 18688
s = input()
K = int(input())
alh = [chr(i) for i in range(97, 97 + 26)]
ans = ""
d = {}
for n,i in enumerate(alh):
    d[i] = (26-n)%26
for i in s[:-1]:
    if K >= d[i]:
        K -=d[i]
        ans += "a"
    else:
        ans += i
ans += chr(97+(ord(s[-1])+K-97)%26)
print(ans)

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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int64_t power_mod(int64_t num, int64_t power){
    int64_t prod = 1;
    num %= MOD;
    while(power > 0){
        if(power&1) prod = prod * num % MOD;
        num = num * num % MOD;
        power >>= 1;
    }
    return prod;
}

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t inv_mod(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

vector<int64_t> fact, fact_inv;

void create_mod_tables(int num){
    fact.assign(num+1, 1);
    fact_inv.assign(num+1, 1);
    for(int i=1; i<=num; i++) fact[i] = fact[i-1] * i % MOD;
    fact_inv[num] = inv_mod(fact[num]);
    for(int i=num; i>0; i--) fact_inv[i-1] = fact_inv[i] * i % MOD;
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int main(){
    int N, M;
    cin >> N >> M;
 
    static int64_t dp[5001][5001];
    for(int j=1; j<=M; j++) dp[0][j] = 1;
    for(int i=1; i<=N; i++){
        int64_t now = 0;
        for(int j=1; j<=M; j++){
            add(dp[i][j], now);
            mul(now, 2);
            add(now, dp[i-1][j]*j);
        }
        for(int j=1; j<=M; j++) add(dp[i][j], (j+1)*dp[i-1][j]);
    }
    cout << dp[N][M] << endl;
    return 0;
}


Measured memory_bytes: 199024
import java.util.Scanner;

public class Main{
	static int gcd(int m, int n) {
		if(m<n)	return gcd(n, m);
		if(n==0)	return m;
		return gcd(n, m%n);
	}
	static int lcm(int m, int n) {
		return m*n/gcd(m, n);
	}
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] a= new int[N+1];
        for(int i=0; i<N; i++) {
        	a[i]=sc.nextInt();
        }
        
        int MAX, MIN, sum=0;
        for(int i=0; i<lcm(N, M); i=i+M) {
        	MAX=0; MIN=110;
        	for(int j=i; j<i+M; j++) {
        		MAX=Math.max(MAX, a[j%N]);
        		MIN=Math.min(MIN, a[j%N]);
        	}
        	sum+=MAX-MIN;
        }
        System.out.println(sum);
	}
}


Measured memory_bytes: 30640
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a;
  cin>>a;
  int b= a/1000;
  int c=a/100-b*10;
  int d=a/10-b*100-c*10;
  int e=a-b*1000-c*100-d*10;
  if(b==c||c==d||d==e){
    cout<<"Bad"<<endl;
  }
  else{
    cout<<"Good"<<endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    ll n;
    cin>>n;
    int x = n%1000;
    if(x==0){
        cout<<"0"<<endl;
    }
    else{
        cout<<1000-x<<endl;
    }


    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
vector<int> g[100010];
int clr[100010];
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n-1;i++){
		int a,b;
		cin>>a>>b;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	memset(clr,-1,sizeof(clr));
	clr[1]=1;clr[n]=2;
	queue<int> q;
	q.push(1);q.push(n);
	while(!q.empty()){
		int x=q.front();
		q.pop();
		for(int i=0;i<g[x].size();i++){
			if(clr[g[x][i]]==-1){
				q.push(g[x][i]);
				clr[g[x][i]]=clr[x];
			}
		}
	}
	int fennec=0,snuke=0;
	for(int i=1;i<=n;i++){
		if(clr[i]==1)fennec++;
		else snuke++;
	}
	if(fennec>snuke)cout<<"Fennec"<<endl;
	else cout<<"Snuke"<<endl;
	return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////

int main(){
    ll n,k;cin>>n>>k;
    ll l=0,r=pow(10,18)+1;
    ll mid;
    ll x;
    ll sum;
    ll c;
    while(r-l>1){
        mid=(r+l)/2;
        x=mid;
        sum=0;
        c=0;
        while(x>0 && c<n){
            sum=sum+x;
            x=x/2;
            c++;
        }
        if(sum<=k){
            l=mid;
        }else{
            r=mid;
        }
        
    }
    cout<<l<<endl;
    
    return 0;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int D;
	cin >> D;
	int c[26];
	int s[D][26];
	int t[D];
	int ok[26];
	rep(i,26) ok[i] = -1;
	rep(i,26) cin >> c[i];
	rep(i,D){
		rep(j,26){
			cin >> s[i][j];
		}
	}
	/*
	rep(i,D){
		cin >> t[i];
		--t[i];
	}
	*/
	int cnt = 0;
	int num;
	rep(i,D){
		int maxi = -INF;
		rep(k,26){
			int ans = 0;
			ans += s[i][k];
			// ok[t[i]] = i;
			rep(j,26){
				if(j == k) continue;
				ans -= c[j] * (i-ok[j]);
			}
			if(maxi < ans){
				maxi = ans;
				num = k;
			}
		}
		cout << num+1 << endl;
		ok[num] = i;
		t[i] = num;
	}
}

Measured memory_bytes: 3764
#include <iostream>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  int H, W, D;
  cin >> H >> W >> D;
  unordered_map<int, pair<int, int>> map;
  rep(i, H) rep(j, W) {
    int A;
    cin >> A;
    map[A] = {i, j};
  }
  vector<int> SUM(H * W + 1, 0);
  for (int i = 1; i <= H * W - D; ++i) {
    int next = i + D;
    int x1, x2, y1, y2;
    tie(x1, y1) = map[i];
    tie(x2, y2) = map[next];
    int cost = abs(x2 - x1) + abs(y2 - y1);
    SUM[next] = SUM[i] + cost;
  }

  int Q;
  cin >> Q;
  rep(i, Q) {
    int L, R;
    cin >> L >> R;
    int answer = SUM[R] - SUM[L];
    cout << answer << endl;
  }
  return 0;
}

Measured memory_bytes: 5284
from collections import defaultdict

n,m=map(int,input().split())
adj=defaultdict(list)
deg=[0]*(n+1)
for i in range(m):
    x,y=map(int,input().split())
    adj[x].append(y)
    deg[y]+=1

dist=[0]*(n+1)

que=[]
for i in range(1,n+1):
    if deg[i]==0:
        que.append(i)

while que:
    v=que.pop()
    for i in adj[v]:
        deg[i]-=1
        if deg[i]==0:
            que.append(i)
        dist[i]=max(dist[i],dist[v]+1)

print(max(dist))
 


Measured memory_bytes: 68824
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJ
{
  class Program
  {
    public static void Main(string[] args)
    {
      foreach (var x in ReadNumbers())
      {
        var gcd = (decimal)GCD(x[0], x[1]);
        var lcm = ((decimal)x[0] * x[1]) / gcd;
        Console.WriteLine("{0} {1}", gcd, lcm);
      }
    }

    static IEnumerable<int[]> ReadNumbers()
    {
      string line;
      while ((line = Console.ReadLine()) != null)
        yield return line.Split(' ').Select(s => int.Parse(s)).ToArray();
    }

    static int GCD(int a, int b)
    {
      int m, n;
      if (a < b)
      {
        m = b;
        n = a;
      }
      else
      {
        m = a;
        n = b;
      }
      int tmp;
      while (n != 0)
      {
        tmp = n;
        n = m % n;
        m = tmp;
      }
      return m;
    }
  }
}

Measured memory_bytes: 6036
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>
#include <type_traits>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

using LL = long long;

//------------------------------------------
//------------------------------------------


int main() {

    int N;
    cin >> N;

    vector<double> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];

    double b = 0;
    for (int i = 0; i < N; i++) b += 1.0 / A[i];

    cout << fixed << setprecision(20) << 1/ b << endl;

}
























Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

n = int(readline())
lst1 = []
for i in range(n):
    lst1.append(int(readline()))

ans = 0
lst2 = []
for i in lst1:
    i -= 2
    if i >= 0:
        ans += (i+1)//2
    if i == -2:
        lst2.append(0)
    elif even(i):
        lst2.append(2)
    else:
        lst2.append(1)

now = 0
while now < n:
    if now == 0:
        if lst2[now] == 2:
            ans += 1
            lst2[now] = 0
        now += 1
        continue
    if lst2[now-1] == 1 and lst2[now] == 2:
        ans += 1
        lst2[now] = 1
        now += 1
        continue

    if lst2[now-1] == 1 and lst2[now] == 1:
        ans += 1
        lst2[now] = 0
        now += 1
        continue
    
    if lst2[now] == 2:
        ans += 1
        lst2[now] = 0
        now += 1
        continue
    now += 1

print(ans)

Measured memory_bytes: 48864
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n,m;
  cin>>n>>m;
  vector<int> l(m);
  vector<int> r(m);
  for(int i=0;i<m;i++){
    cin>>l[i]>>r[i];
  }
  sort(l.begin(),l.end());
  sort(r.begin(),r.end());
  int ans=r[0]-l[m-1]+1;
  if(ans>0){
    cout<<ans<<endl;
  }else{
    cout<<0<<endl;
  }
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,a) for(int i=0;i<int(a);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
using ll = long long;
using itn = int;
using namespace std;
using Graph = vector<vector<int>>;
static const long double GRATIO=(long double)(1+sqrt(5))/2;
ll GCD(ll a, ll b){
    return b ? GCD(b, a%b) : a;
}
ll LCM(ll a, ll b){
    return a/GCD(a,b)*b;
}
int main(){
    ll N,L;
    cin>>N>>L;
    vector<ll> a(N);
    rep(i,N) cin>>a[i];
    int cnt=0;
    int b=0;
    rep(i,N-1){
        if(a[i]+a[i+1]<L) cnt++;
        else b=i; 
    }
    if(cnt>=N-1){
        cout<<"Impossible"<<endl;
        return 0;
    }else{
        cout<<"Possible"<<endl;
    }
    rep(i,N-1){
        if(i==b) break;
        cout<<i+1<<endl;
    }
    for(int i=N-2; i>=0; i--){
        if(i==b) break;
        cout<<i+1<<endl;
    }
    cout<<b+1<<endl;
}

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

using u64 = std::uint64_t;
constexpr u64 inf = std::numeric_limits<u64>::max();

#define REP(i, n) for (u64 i = 0; i < (n); ++i)

namespace io {
  constexpr int is = 1 << 17;
  char ib[is], *ip = ib + is, it;
  inline char getc() {
    if (ip == ib + is) { read(STDIN_FILENO, ib, is); ip = ib; }
    return *ip++;
  }
  inline u64 scan() {
    u64 r = 0;
    if (ip + 16 > ib + is) while ((it = getc()) & 16) r = r * 10 + it - '0';
    else while ((it = *ip++) & 16) r = r * 10 + it - '0';
    return r;
  }
  constexpr int os = 1 << 17;
  char ob[os], *op = ob, ot;
  inline void putc(const char c) {
    *op++ = c;
    if (op == ob + os) { write(STDOUT_FILENO, ob, os); op = ob; }
  }
  /* x shoud be greater than or equal to zero */
  inline void print(u64 x) {
    char d[20];
    int i = 0;
    while (true) {
      d[i] = x % 10 + 48;
      x /= 10;
      ++i;
      if (x <= 0) break;
    }
    while (i--) {
      putc(d[i]);
    }
  }
  inline void flush() {
    write(STDOUT_FILENO, ob, op - ob);
  }
}

using P = pair<u64, u64>;

u64 collect(const vector<vector<u64>> &G, const vector<u64> &H, u64 u, u64 v, u64 p) {
  if (u == v) return 0;
  for (auto e : G[u]) {
    u64 t = H[e] ^ u;
    if (t == p) continue;
    u64 s = collect(G, H, t, v, u);
    if (s != inf) {
      return s | (1ULL << e);
    }
  }
  return inf;
}

signed main() {
  u64 n = io::scan();
  auto G = vector<vector<u64>>(n);
  auto H = vector<u64>(n);
  REP(i, n - 1) {
    u64 a = io::scan() - 1;
    u64 b = io::scan() - 1;
    G[a].push_back(i);
    G[b].push_back(i);
    H[i] = a ^ b;
  }
  u64 m = io::scan();
  auto mask = vector<u64>(1ULL << m);
  auto parity = vector<u64>(1ULL << m);
  REP(j, m) {
    u64 u = io::scan() - 1;
    u64 v = io::scan() - 1;
    mask[1ULL << j] = collect(G, H, u, v, -1);
    parity[1ULL << j] = 1;
  }
  u64 ans = 1ULL << (n - 1);
  for (u64 s = 1; s < (1ULL << m); ++s) {
    u64 d = s & -s;
    mask[s] = mask[s ^ d] | mask[d];
    parity[s] = parity[s ^ d] ^ parity[d];
    if (parity[s]) {
      ans -= 1ULL << (n - 1 - __builtin_popcountll(mask[s]));
    } else {
      ans += 1ULL << (n - 1 - __builtin_popcountll(mask[s]));
    }
  }
  io::print(ans);
  io::flush();
}


Measured memory_bytes: 16640
import java.io.*;
import java.util.*;

/**
 * Created by Ayushi on 31 May 2020.
 * Problem:
 * Round:
 */

public class Main {
    public static void main(String[] args) throws IOException {
        StringTokenizer st;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        st = new StringTokenizer(br.readLine(), " ");
        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        br.close();
        System.out.println(n*m);
    }
}


Measured memory_bytes: 32448
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  
  cin >> a >> b;
  
  if ((a%2 == 0) || (b%2 == 0)) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256