akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

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

  vector<ll> x(n);
  for (ll i = 0; i < n; i++) {
    cin >> x[i];
  }

  ll ans = __INT_MAX__;
  for (ll p = 1; p <= 100; p++) {
    ll cnt = 0;
    for (ll i = 0; i < n; i++) {
      cnt += (x[i] - p) * (x[i] - p);
    }
    ans = min(ans, cnt);
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

 class Rectangle {
     private static int a;
     private static int b;

     static void run () {
        readInput();
        printCubic();
    }
     private static void readInput() {
        Scanner sc = new Scanner(System.in);
         a =sc.nextInt();
         b =sc.nextInt();
    }
     private static void printCubic (){
        System.out.println((a * b) + " " + ((a + b) * 2));
    }
}
public class Main {
    public static void main(String[] args) {
        Rectangle.run();
    }
}

Measured memory_bytes: 26300
#include <iostream>
#include <vector>
#include <iomanip>

const double PI = 3.141592653589793;

using namespace std;

int main(void) {
	double r;
	cin >> r;
	cout << fixed << setprecision(6) << r*r*PI << " " << 2*r*PI << endl;

	return 0;
}


Measured memory_bytes: 3280
from collections import defaultdict

def main():
    memo = defaultdict(int)
    N = int(input())
    nums = list(map(int,input().split()))

    for n in nums:
#        print(n)
        if memo[n]:
            return False
        else:
            memo[n] += 1
    return True

if __name__ == '__main__':
    if main():
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 33996
import java.util.Scanner;

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

		int n = sc.nextInt();
		long a = 1, b = 1;
		for (int i = 0; i < n; i++) {
			long x = sc.nextInt();
			long y = sc.nextInt();
			long k = Math.max(b / y, Math.max(1, a / x));
			while (x * k < a || y * k < b) {
				k++;
			}
			a = x * k;
			b = y * k;
		}
		System.out.println((a + b));
	}
}

Measured memory_bytes: 13216
#include<bits/stdc++.h>
using namespace std;
int ans[123456];
const int MX=1e9;
int main()
{
    int n,k,s;
    cin>>n>>k>>s;
    for(int i=0;i<k;i++)  cout<<s<<" ";
    if(s+1<=MX)
    {
     for(int i=k;i<n;i++){
        cout<<s+1<<" ";
        }   
    }
    else
    {
        for(int i=k;i<n;i++){
            cout<<s-1<<" ";
        }  
    }
    return 0;
}

Measured memory_bytes: 1280
import sys;input=lambda:sys.stdin.readline().rstrip();ints=lambda:list(map(int,input().split()))

def main():
    n,k=ints()
    a=ints()
    passed=[]
    flg,p=0,0
    while flg==0:
        if a[p] == 'p':
            flg=1
            s=passed.index(p)
            break
        else:
            passed.append(p)
            pp=p
            p=a[pp]-1
            a[pp]='p'
    l=len(passed)
    print(passed[k]+1) if k<l else print(passed[(k-s)%(l-s)+s]+1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 32380
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long int n,a,b,c,d;
	cin>>n>>a>>b;
	c=b+(a*(n-1));
	d=a+(b*(n-1));
	d=d-c+1;
	
	
	if(d<=0 || a>b)
	{
		cout<<0<<endl;
	}
	else
	{
		cout<<d<<endl;
	}
}

Measured memory_bytes: 3600
import math

n, m = [int(i) for i in input().split(" ")]
pq_max = 0

for p in range(1, int(math.sqrt(m)) + 1):
    if m % p == 0:
        q = m // p
        
        if p >= n and q > pq_max:
            pq_max = q
            
        if q >= n and p > pq_max:
            pq_max = p
        
print(pq_max)

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);

  int a, b, h, m;
  cin >> a >> b >> h >> m;

  double mang, hang, ang, ans;
  mang = m * 360.0 / 60.0;
  hang = h * 360.0 / 12.0;
  hang += m * 360.0 / 720.0;

  mang = mang;
  hang = hang;

  ang = max(mang, hang) - min(mang, hang);
  if (ang > 180) {
    ang = 360 - ang;
  }
  ang = deg_to_rad(ang);

  ans = sqrt((a * a) + (b * b) - (2 * a * b * cos(ang)));

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 4244
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String H = sc.next();
    String W = sc.next();
    while (sc.hasNext()) {
      String c = sc.next();
      System.out.println(c);
      System.out.println(c);
    }
  }
}

Measured memory_bytes: 23508
use std::io::*;
use std::str::FromStr;
use utils::*;

pub fn main() {
    let i = stdin();
    let mut o = Vec::new();
    run(i.lock(), &mut o);
    stdout().write_all(&o).unwrap();
}

fn run<R: BufRead, W: Write>(i: R, o: &mut W) {
    let mut i = CpReader::new(i);
    let n = i.read::<usize>();
    let mut b = i.read_vec::<usize>(n);
    for bi in b.iter_mut() {
        *bi = *bi - 1;
    }
    if let Some(ans) = solve(&mut b) {
        for ai in ans {
            writeln!(o, "{}", ai + 1).unwrap();
        }
    } else {
        writeln!(o, "-1").unwrap();
    }
}
fn solve(b: &mut Vec<usize>) -> Option<Vec<usize>> {
    fn s(b: &mut Vec<usize>, ans: &mut Vec<usize>) -> bool {
        if b.len() == 0 {
            return true;
        }
        let len = b.len();
        for i in 0..len {
            if b[i] > i {
                return false;
            }
        }
        for i in (0..len).rev() {
            if b[i] == i {
                b.remove(i);
                ans.push(i);
                if s(b, ans) {
                    return true;
                }
                ans.pop();
                b.insert(i, i);
            }
        }
        false
    }

    let mut ans = Vec::new();
    if s(b, &mut ans) {
        ans.reverse();
        Some(ans)
    } else {
        None
    }
}

mod utils {
    use super::*;

    pub struct CpReader<R: BufRead> {
        r: R,
        s: String,
    }

    macro_rules! fn_read {
        { $f:ident($($t:ident),*) } => {
            #[allow(dead_code)]
            pub fn $f<$($t: FromStr),*>(&mut self) -> ($($t),*) {
                let i = &mut self.read_line().split(' ');
                ($(read_next::<$t,_>(i)),*)
            }
        };
    }

    impl<R: BufRead> CpReader<R> {
        pub fn new(r: R) -> Self {
            CpReader {
                r: r,
                s: String::new(),
            }
        }
        pub fn read_line(&mut self) -> &str {
            self.s.clear();
            self.r.read_line(&mut self.s).unwrap();
            self.s.trim()
        }

        pub fn read<T: FromStr>(&mut self) -> T {
            self.read_line().parse().ok().unwrap()
        }
        fn_read! { read2(T1, T2) }
        fn_read! { read3(T1, T2, T3) }
        fn_read! { read4(T1, T2, T3, T4) }
        fn_read! { read5(T1, T2, T3, T4, T5) }

        pub fn read_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            self.read_line()
                .split(' ')
                .take(n)
                .map(|x| x.parse().ok().unwrap())
                .collect()
        }
    }
    fn read_next<'a, T: FromStr, I: Iterator<Item = &'a str>>(i: &mut I) -> T {
        i.next().unwrap().parse().ok().unwrap()
    }

}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define erep(i,a,b) for(int i=a;i<=(int)(b);++i)
#define per(i,a,b) for(int i=(a);i>(b);--i)
#define eper(i,a,b) for(int i=(a);i>=b;--i)
#define pb push_back
#define mp make_pair
#define INF 100100100100
#define inf 2001001001
#define MOD 1000000007
#define ALL(x) begin(x),end(x)
#define F first
#define S second
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vii = vector<int>;
using vll = vector<ll>;
using priority_queue_small = priority_queue<int, vector<int>, greater<int> >;
template<class T>using vv = vector<T>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<class T>void show(const vector<T> &a) { for (int i = 0; i < (int)a.size(); ++i) cout << a[i] << (i != (int)a.size()-1 ? " " : "\n"); }
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
int dy[]={0, 1, -1, 0};
int dx[]={1, 0, 0, -1};

ll n, m;
int main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> n >> m;
  if (2 * n >= m) cout << m / 2 << endl;
  else {
    ll ans = n;
    m -= 2 * n;
    ans += m / 4;
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 256
N = int(input())
D, X = list(map(int, input().split()))

count = 0
for i in range(1, N+1):
    A = int(input())
    for j in range(1, D+1):
        if (j - 1) * A + 1 <= D:
            count += 1
        else:
            break

result = count + X

print(result)

Measured memory_bytes: 9148
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int n = 100000;
    vector<int> prime;
    vector<bool> v(n + 1, false);
    for(int i = 2; i <= n; ++i) {
        if (v[i]) continue;
        prime.pb(i);

        for(int j = i; j <= n; j += i) v[j] = true;
    }

    vector<int> k;
    for(auto &e: prime) {
        ll cur = (e + 1) / 2;
        auto it = find(ALL(prime), cur);
        if (it != prime.end()) k.pb(e);
    }

    vector<int> s(n + 2, 0);

    int j = 0;
    REP(i, s.size() - 1) {
        if (j < k.size() && i == k[j]) s[i] += 1, j++;
        s[i + 1] = s[i];
    }

    int q; cin >> q;
    REP(i, q) {
        int l, r; cin >> l >> r;
        print(s[r] - s[l - 1]);
    }
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

//const ll INF = 1e18L + 5;
//const int INF = 1e9 + 5;
//const double pi = 3.14159265358979323846;

void	solve()
{
	double t, x;
	cin >> t >> x;
	
	printf("%0.8f\n", t / x);
}

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

	solve();
}

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

int n,m,q,scc,gp[10005];
bool vis[10005],rvis[10005];
vector<int>G[10005],R[10005],ts;

void dfs(int u) {
	vis[u]=1;
	for (int v:G[u])
		if (!vis[v]) dfs(v);
	ts.pb(u);
}

void rdfs(int u,int k) {
	rvis[u]=1;
	gp[u]=k;
	for (int v:R[u])
		if (!rvis[v]) rdfs(v,k);
}

int main() {
	cin>>n>>m;
	for (int i=0;i<m;i++) {
		int u,v; cin>>u>>v;
		G[u].pb(v);
		R[v].pb(u);
	}
	for (int i=0;i<n;i++)
		if (!vis[i]) dfs(i);
	for (auto it=ts.rbegin();it!=ts.rend();it++)
		if (!rvis[*it]) rdfs(*it,scc++);
	cin>>q;
	for (int i=0;i<q;i++) {
		int u,v; cin>>u>>v;
		cout<<(gp[u]==gp[v])<<'\n';
	}
}


Measured memory_bytes: 4820
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include <ctime>
#include<list>
#include <numeric>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
	~debug() { cerr << endl; }
	template<class c> typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) {
		cerr << boolalpha << i; return *this;
	}

	template<class c, int=0> typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) {
		return *this << range(begin(i), end(i));
	}

sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c&) { ris; }
#endif
};
#define watch(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(int i = 0; i < n; i++)
#define FORAB(i, a, b) for(int i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))
#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int128 LLL;
typedef long long LLL;

typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII > VP;
typedef vector<PLL > VPL;
typedef vector<double> VD;
typedef long double ld;

const double PI = acos(-1.);

void solve(int ks) {
	string s;
	cin >> s;
	int len = s.size();
	int cnt = 0;
	for (int i = 0; i < len; i++) {
		if (s.at(i) == 'o') cnt++;
	}
	cnt += 15 - len;
	if (cnt >= 8) printf("YES\n");
	else printf("NO\n");
}

int main()
{
#ifdef LOCAL
	double start_time = clock();
	freopen("C:\\Home\\ContestCodes\\sample.in", "r", stdin);
	//	freopen("out.out", "w", stdout);
#endif


	if (0) {
		int T;
		scanf("%d", &T);
		//AIN(T, 1, 25);
		for (int ks = 1; ks <= T; ks++) solve(ks);
	}
	else {
		solve(0);
	}

#ifdef LOCAL
	double end_time = clock();
	fprintf(stderr, "Time = %lf\n", (end_time - start_time) / CLOCKS_PER_SEC);
#endif

	return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
lrList = [list(map(int, input().split())) for _ in range(M)]

l, r = 0, float("inf")
for lr in lrList:
    l, r = max(lr[0], l), min(lr[1], r)

ans = max(min(r, N) - l + 1, 0)
print(ans)


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

int main() {

    int n; cin >> n;
    int left = 1000000;
    int right = -1;
    for (int i = 0; i < n; i++) {
        int a; cin >> a;
        left = min(left, a);
        right = max(right, a);
    }
    
    cout << right - left << endl;
    return 0;
}

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

int n;
int a[100005];

int main()
{
    int flag = 1;
    scanf("%d",&n);
    for(int i = 0; i < n; i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i = n-1; i > 0; i--)
    {
        if(a[i] < a[i-1])
        {
            a[i-1]--;
            if(a[i-1]>a[i])
                flag = 0;
        }
    }
    if(flag)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


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

using namespace std;
using ll =long long;
typedef pair<int,int> P;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//Write From this Line

int main()
{
	string s;
	cin >> s;
	cout << s.substr(0,3) << endl;

}


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

int main() 
{
    int N;
    cin >> N;

    int *X = new int[N];
    int sum_X = 0;
    for(int i=0; i<N; i++)
    {
        cin >> X[i];
        sum_X += X[i];
    }

    int P[2];
    P[0] = (int)floor(sum_X / N);
    P[1] = P[0] + 1;

    int min[2] = {0, 0};
    
    for(int t=0; t<2; t++)
    {
        for(int i=0; i<N; i++)
        {
            min[t] += (X[i] - P[t]) * (X[i] - P[t]);
        }
    }

    if(min[0] < min[1])
    {
        cout << min[0] << endl;
    }
    else
    {
        cout << min[1] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
// https://atcoder.jp/contests/abc051/tasks/abc051_b

#include <iostream>
using namespace std;

int main()
{
    int K, S;
    cin >> K >> S;

    int res = 0;
    for (int p = 0; p <= K; ++p)
    {
        for (int q = 0; q <= K; ++q)
        {
            int r = S - p - q;
            if ((0 <= r) && (r <= K))
                ++res;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int judge=0;
  char s[3];
  
  scanf("%s",s);

  if(s[0]=='a'){
    if(s[1]=='b'){
      if(s[2]=='c')
        judge=1;
    }else if(s[1]=='c'){
      if(s[2]=='b')
        judge=1;
    }
  }else if(s[0]=='b'){
    if(s[1]=='a'){
      if(s[2]=='c')
        judge=1;
    }else if(s[1]=='c'){
      if(s[2]=='a')
        judge=1;
    }
  }else if(s[0]=='c'){
    if(s[1]=='b'){
      if(s[2]=='a')
        judge=1;
    }else if(s[1]=='a'){
      if(s[2]=='b')
        judge=1;
    }
  }
  if(judge==0)
    puts("No");
  else if(judge==1)
    puts("Yes");
  return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#define ll long long
using namespace std;
ll b[100005];
int main()
{
    int n;
    scanf("%d",&n);
    
    ll a[100005],i;
    
    for(i=0; i<n; i++)
        scanf("%lld",&a[i]);
    for(i=0;i<100005;i++)
        b[i]=0;
    if(n>=1e5)
        a[-2]=0;
    if(a[0]!=0)
            printf("0\n");
    else
    {
        ll ans=1;
        for(i=0;i<n;i++)
            b[a[i]]++;
        for(i=1;i<n;i++)
        {
            ans*=b[a[i]-1];
            ans%=998244353;
        }

        printf("%lld\n",ans);
    }
    return 0;
}


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

using namespace std;
using ll = long long;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<ll> P(N + 1);
  for (int i = 1; i <= N; i++) {
    cin >> P[i];
    P[i] += P[i - 1];
  }
  ll ans = P[N];
  int l = 1, r = 3;
  for (int i = 2; i <= N - 2; i++) {
    while (l < i && abs(P[i] - 2 * P[l]) > abs(P[i] - 2 * P[l + 1]))
      l++;
    while (r < N &&
           abs(P[N] - 2 * P[r] + P[i]) > abs(P[N] - 2 * P[r + 1] + P[i]))
      r++;
    ll minn =
        min({abs(P[i] - P[l]), abs(P[l]), abs(P[N] - P[r]), abs(P[r] - P[i])});
    ll maxn =
        max({abs(P[i] - P[l]), abs(P[l]), abs(P[N] - P[r]), abs(P[r] - P[i])});
    ans = min(ans, maxn - minn);
  }
  cout << ans << '\n';
  return 0;
}


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

using namespace std;

const int INF = 1e9;
int dp[510][10010];

int main(void) {
  int m, n;
  cin >> m >> n;

  vector<int> p(m), c(n), e(n);
  for (int i = 0; i < m; i++) {
    cin >> p[i];
  }
  for (int i = 0; i < n; i++) {
    cin >> c[i] >> e[i];
  }

  sort(p.begin(), p.end(), greater<int>());
  for (int i = 1; i < m; i++) {
    p[i] += p[i - 1];
  }

  fill(dp[0], dp[510], INF);
  dp[0][0] = 0;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= m; j++) {
      if (j - c[i] < 0) {
        dp[i + 1][j] = min(dp[i][j], e[i]);
      } else {
        dp[i + 1][j] = min(dp[i][j], dp[i][j - c[i]] + e[i]);
      }
    }
  }

  int ans = 0;
  for (int i = 0; i < m; i++) {
    ans = max(ans, p[i] - dp[n][i + 1]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 23096
#include <stdio.h>
#include <string.h>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define FOR(i,m,n) for(i=m;i<n;i++)

int main(void)
{
	int a,b,c,i;
	scanf("%d %d",&a,&b);
	printf("%d",(a*3+b)/2);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
struct S{
	string s;
	int id,p;
}a[105];
bool cmp(S s1,S s2){
	if(s1.s<s2.s) return 1;
	else if(s1.s>s2.s) return 0;
	else return s1.p>s2.p;
}
int n;
int main()
{
	//freopen("in.txt","r",stdin);
	scanf(" %d",&n);
	for(int i=0;i<n;i++){
		cin>>a[i].s>>a[i].p;
		a[i].id=i+1;
	}
	sort(a,a+n,cmp);
	for(int i=0;i<n;i++)
		printf("%d\n",a[i].id);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define INF 1e9
typedef long long ll;
using namespace std;

int main() {
    int a,b; cin >> a >> b;
    vector<string> s(a);
    rep(i,a){
        cin >> s[i];
    }
    rep(i,a){
        cout << s[i] << endl;
        cout << s[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <string>
#include <algorithm>
#include <functional>
#include <utility>
#include <vector>
#include <map>
#include <list>
#include <set>

using namespace std;

typedef long long ll;
#define rep(i, s, n) for(int i=(s); i<(int)(n); i++)
#define endl "\n"

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

    int a;
    string s;

    cin >> a >> s;

    if(a >= 3200){
        cout << s << endl;
    }else if(a < 3200){
        cout << "red" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<queue>
#include<stack>
#include<iomanip>
#include<cstring>
#include<string>
#include<set>

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

using namespace std;
using ll = long long int;

const ll INF = 1<<30;
const ll LINF = 1LL<<60;
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(void) {
    int x; cin >> x;
    REP(i, 360) {
        if (((i + 1) * x) % 360 == 0) {
            cout << i + 1 << endl;
            exit(0);
        }
    }
}

Measured memory_bytes: 3588
N, X, Y = map(int, input().split())

DP = [[abs(i - j) for i in range(N)] for j in range(N)]

DP[X - 1][Y - 1] = 1
DP[Y - 1][X - 1] = 1

# que = deque()
# que.append((X - 1, Y - 1))
# while que:
#     tmp = que.popleft()
#     x, y = tmp[0], tmp[1]

x = X - 1
y = Y - 1
for i in range(N - 1):
    for j in range(i + 1, N):
        DP[i][j] = min(DP[i][j], DP[i][x] + DP[y][j] + 1, DP[i][y] + DP[x][j] + 1)

lst = [0] * N
for i in range(N - 1):
    # tmp = list(ans[i,:])
    # print (tmp)
    for j in range(i + 1, N):
        lst[DP[i][j]] += 1
    
print (*lst[1:], sep = '\n')



Measured memory_bytes: 78300
/*
      author : nishi5451
      created: 11.08.2020 01:00:46
*/

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


int main(){
    int n; 
    cin >> n;
    if(n/100 == n%10) cout <<" Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3616
#!/usr/bin/env python3

import itertools


def compute(n, m_a, m_b, a, b, c):
    max_a, max_b, max_c = max(a), max(b), max(c)
    inf = n * max_c * 2
    dp = [[[inf for _ in range(n * max_b + 1)]
          for _ in range(n * max_a + 1)] for _ in range(n + 1)]
    dp[0][0][0] = 0
    g = itertools.product(range(n), range(n * max_a + 1), range(n * max_b + 1))
    for i, wa, wb in g:
        if dp[i][wa][wb] == inf:
            continue
        dp[i + 1][wa][wb] = min(dp[i + 1][wa][wb], dp[i][wa][wb])
        dp[i + 1][wa + a[i]][wb + b[i]] = min(dp[i + 1][wa + a[i]][wb + b[i]],
                                              dp[i][wa][wb] + c[i])
    h = itertools.product(range(1, n * max_a + 1), range(1, n * max_b + 1))
    ans = min((dp[n][wa][wb] for wa, wb in h if wa * m_b == wb * m_a),
              default=inf)
    return ans if ans != inf else -1


def main():
    n, m_a, m_b = (int(x) for x in input().split())
    a, b, c = ([int(i) for i in r] for r in
               zip(*(input().split() for _ in range(n))))
    print(compute(n, m_a, m_b, a, b, c))


if __name__ == '__main__':
    main()


Measured memory_bytes: 60148
#include<bits/stdc++.h> 
using namespace std;
long long x, s;
long long q(long long l){
	if(l==1) return 101;
	else{
		return q(l-1)*1.01;
	}
}
int main(){
	scanf("%lld", &s);
	for(int i=1; i<=4000; i++){
		if(q(i)>=s){
			x=i;
			break;
		}
	}
	printf("%lld", x);
	return 0;
}

Measured memory_bytes: 3816
import math
import copy
import sys
import fractions
# import numpy as np
# import statistics
import decimal
import heapq
import collections
import itertools


# from operator import mul

# sys.setrecursionlimit(100001)


# input = sys.stdin.readline
# sys.setrecursionlimit(10**6)

# ===FUNCTION===

def getInputIntList():
    outputDataList = []
    inputData = input().split()
    outputDataList = [int(n) for n in inputData]

    return outputDataList

def getSomeInputInt(n):
    outputDataList = []
    for i in range(n):
        inputData = int(input())
        outputDataList.append(inputData)

    return outputDataList


def getSomeInputListInt(n):
    inputDataList = []
    outputDataList = []
    for i in range(n):
        inputData = input().split()
        inputDataList = [int(n) for n in inputData]
        outputDataList.append(inputDataList)

    return outputDataList


# ===CODE===

n = int(input())
obj = getSomeInputListInt(n)

data = [[] for _ in range(8)]
for x in range(8):
    for y in range(8):
        flg = True
        for o in obj:
            tmpx = o[0]-x
            tmpy = o[1]-y
            if tmpx == 0 or tmpy == 0 or abs(tmpx) == abs(tmpy):
                flg = False
                break

        if flg:
            data[x].append([x,y])



def checker(a, b_list):
    flg = True
    for b in b_list:
        tmpx = b[0] - a[0]
        tmpy = b[1] - a[1]
        if tmpx == 0 or tmpy == 0 or abs(tmpx) == abs(tmpy):
            flg = False
            break

    return flg

def printer(l):
    for x in range(8):
        for y in range(8):
            if [x,y] in l:
                print("Q", end="")
            else:
                print(".", end="")
        print("")


def search(cnt, candidate):
    if cnt == 8:
        printer(candidate)
        exit(0)
    if len(data[cnt]) == 0:
        search(cnt+1, candidate)


    for d in data[cnt]:
        if checker(d, candidate):
            tmp = copy.deepcopy(candidate)
            tmp.append(d)
            search(cnt+1, tmp)


search(0, obj)


Measured memory_bytes: 6900
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = (a);i < (n);i++)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main(){
    string s,t;
    cin >> s >> t;
    
    s += s;
    
    rep(i,0,s.size()){
        rep(j,0,t.size()){
            if(s[i+j] != t[j]){
                break;   
            }
            else if(j == t.size()-1){
                cout << "Yes" << endl;
              	return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3236
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
using namespace __gnu_pbds;
using namespace std;
typedef tree<
    pair<int, int>,
    null_type,
    less_equal<pair<int, int>>,
    rb_tree_tag,
    tree_order_statistics_node_update>
    ordered_set;
#define int long long
#define double long double
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define lb(v, z) lower_bound(all(v), z)
#define ub(v, z) upper_bound(all(v), z)
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define rdp(i, a, b) for (int i = (a); i >= (b); i--)
#define rlt(i, a, b) for (int i = (a); i < (b); i++)
#define cns(z) cout << (z) << ' '
#define cnl(z) cout << (z) << '\n'
#define M1 1000000007
#define M2 998244353
#define MAXN 300005
#define INF (1ll << 60)
#define endl "\n"
#define garr(ip)       \
    for (auto &x : ip) \
        cin >> x;
#define parr(ip)          \
    for (auto &x : ip)    \
        cout << x << " "; \
    cout << endl;
#define nl cout << endl
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vp;

void solve(int testCaseNumber = 1)
{
    int n;
    cin >> n;
    string ans;
    while (n > 0)
    {
        n--;
        ans += 'a' + n % 26;
        n /= 26;
    }
    reverse(all(ans));
    cnl(ans);
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 10*9+7

int main(){
  string s; cin >> s;
  for(int i=0;i<s.size();i++){
    if(s[i]=='7'){
      cout<< "Yes" <<endl;
      return 0;
    }
  }
  cout<< "No" <<endl;
}


Measured memory_bytes: 3604
#pragma region
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define rep2(i, m, n) for (int i = m; i < n; i++)
#define all(v) v.begin(), v.end
#define INF 1e9
#define EPS 1e-10
using namespace std;
typedef long long ll;
#pragma endregion

int main()
{
    int K,N,m;
    cin >> K >> N;
    vector<int> A(N);

    rep(i, N){
        cin >> A.at(i);
    }

    rep(i, N - 1){
        m = max(A.at(i + 1) - A.at(i), m);
    }
    m = max((K - A.at(N - 1)) + A.at(0), m);

    cout << K - m << endl;
}



Measured memory_bytes: 1024
fun main(arg: Array<String>) {
    val N = nextInt()
    val A = listOfLong()
    val M = mutableMapOf<Long, Int>()
    A.sortedDescending().forEach { a ->
        val c = M.getOrElse(a, { 0 })
        M[a] = c + 1
    }
    val M2 = M.filter { it.value >= 2 }.toList()
    var ans = 0L
    if (M2.size == 1 && M2[0].second >= 4) ans = M2[0].first * M2[0].first
    if (M2.size >= 2) {
        ans = if (M2[0].second >= 4) M2[0].first * M2[0].first
                else M2[0].first * M2[1].first
    }
    println(ans)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfLong() = listOfString().map { java.lang.Long.parseLong(it) }


Measured memory_bytes: 60104
#include <iostream>

void swap(int *x, int *y)
{
	int temp = *x;
	*x = *y;
	*y = temp;
}

int main()
{
	int a, b, c;
	std::cin >> a >> b >> c;
	if (a > b) {
		swap(&a, &b);
	}
	if (b > c) {
		swap(&b, &c);
	}
	if (a > b) {
		swap(&a, &b);
	}
	std::cout << a << " " << b << " " << c << std::endl;
	return 0;
}

Measured memory_bytes: 1164
#include <cstdio>
#include <iostream>
#include <vector>

using namespace std;

typedef long long    ll;
typedef long double  ld;

#define rep(i, n)      for (int i = 0; i < (int)(n); ++i)
#define rep3(i, m, n)  for (int i = (m); i < (int)(n); ++i)
#define rrep(i, n)     for (int i = (int)(n)-1; i >= 0; --i)
#define rrep3(i, m, n) for (int i = (int)(n)-1; i >= (m); --i)

#define endl '\n'
#define INF  0x7f7f7f7f7f7f7f7f
#define INFi 0x7f7f7f7f


ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll solve(int N, const vector<ll> & a) {
  ll ret=0;
  for (int i=0; i<a.size(); i+=2)
    if (a[i] % 2 == 1) ret++;
  return ret;
}

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

  int N;
  cin >> N;
  vector<ll> a(N);
  rep (i, N) {
    cin >> a[i];
  }

  auto ans = solve(N, a);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3140
unittest
{
	assert( [ "1 3 2" ].parse.expand.solve == "Yes" );
	assert( [ "6 5 4" ].parse.expand.solve == "No" );
	assert( [ "2 2 2" ].parse.expand.solve == "Yes" );
}



import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto abc = input.front.split.to!( long[] );
	return tuple( abc[ 0 ], abc[ 1 ], abc[ 2 ] );
}

auto solve( long a, long b, long c )
{
	return ( a <= c && c <= b ) ? "Yes" : "No";
}


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

string s,t;
int ans=0;

int main()
{
	cin>>s>>t;
	
	for (int i=0 ; i<s.length() ; i++)
	{
		if (t[i]!=s[i]) ans++;
	}
	
	printf("%d\n",ans);
	
	return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  char C[H][W];
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> C[i][j];
      cout << C[i][j] << flush;
    }
    cout << endl;
    for (int j = 0; j < W; j++) {
      cout << C[i][j] << flush;
    }
    cout << endl;
  }
}

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

#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())
#define endl "\n"

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
void initialize( void );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;
template <typename T, typename K> struct P {
	T a; K b;
};
typedef struct {
	vector <int> to;
	int cost;
} edge;

const int MAX = 1e5+10;
int main( void ){
	// initialize();
	int N, Q;
	cin >> N;
	vector<int> vec(MAX, 0);
	rep(i,0,N){
		int input; cin >> input;
		vec[input]++;
	}
	ll sum = 0;
	rep(i,0,MAX){
		sum += i*vec[i];
	}
	cin >> Q;
	rep(i,0,Q){
		int b, c; cin >> b >> c;
		int d = vec[b];
		vec[b] = 0;
		vec[c] += d;
		sum += (c-b)*d;
		cout << sum << endl;
	}


}

template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}
void initialize( void ){
	cout << fixed << setprecision( 10 );
}


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair

int main() {
  ll n, t;
  cin >> n >> t;
  vl x(n);
  rep (i, n) {
    cin >> x[i];
  }
  vl sum(n + 1);
  rep (i, n) sum[i + 1] = sum[i] + x[i];
  ll res = INF * 8;
  rep1 (k, n) {
    ll ans = 0;
    ll i = n - 1;
    ll cnt = 0;
    while (i >= 0) {
      ll add = sum[i + 1] - sum[max(i - k + 1, 0LL)];
      if (cnt == 0) add *= 5;
      else add *= (2*cnt + 3);
      ans += add;
      if (ans > INF / 2) break;
      assert(ans >= 0);
      cnt++;
      i -= k;
    }
    chmin(res, ans + n*t + k*t);
  }
  cout << res << endl;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <cstdio>
using namespace std;
using ll = long long;

const int nax = 1e5 + 5;
vector<int> edges[nax];

const int mod = 1e9 + 7;
int mul(int a, int b) {
	return (ll) a * b % mod;
}

// returns a pair {black, white}
pair<int,int> dfs(int a, int parent) {
	int all_white = 1; // means: my vertex can be painted black
	int sth_is_black = 0;
	for(int b : edges[a]) {
		if(b != parent) {
			pair<int,int> p = dfs(b, a);
			// p.first is the number of ways to color the subtree
			// such that 'b' is black
			int memo_all_white = all_white;
			all_white = mul(all_white, p.second);
			sth_is_black = (mul(memo_all_white, p.first)
				+ mul(sth_is_black, p.first + p.second)) % mod;
		}
	}
	return make_pair(all_white, (all_white + sth_is_black) % mod);
}

int main() {
	int n;
	scanf("%d", &n);
	for(int i = 0; i < n - 1; ++i) {
		int a, b;
		scanf("%d%d", &a, &b);
		edges[a].push_back(b);
		edges[b].push_back(a);
	}
	pair<int,int> p = dfs(1, -1); //from 1 to endless
	int answer = (p.first + p.second) % mod;
	printf("%d\n", answer);
	return 0;
}

Measured memory_bytes: 16052
#include<stdio.h>
int main(){
    int H[10000], W[10000];
    int length;
    int i=0, j, k;
    do{
        scanf("%d %d", &H[i], &W[i]);
        i += 1;
    }while(H[i-1]!=0 || W[i-1]!=0);
    length = i;
    for(i=0; i<length-1; i++){
        for(j=0; j<H[i]; j++){
            for(k=0; k<W[i]; k++){
                if((j+k)%2 == 0){
                    printf("#");
                }else{
                    printf(".");
                }
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}

Measured memory_bytes: 2700
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


def Dijkstra(g, s):
    prev = {}
    q = []
    d = defaultdict(lambda: INF)
    d[s] = 0
    heapq.heappush(q, (d[s], s))

    while q:
        c, u = heapq.heappop(q)
        if d[u] < c:
            continue
        for v, w in g[u].items():
            alt = w + c
            if d[v] > alt:
                d[v] = alt
                prev[v] = u
                heapq.heappush(q, (alt, v))
    return d

@mt
def slv(N, LRC):
    g = defaultdict(dict)

    LRC.sort(key=lambda x: x[2], reverse=True )
    for l, r, c in LRC:
        g[l][r] = c
    
    for i in range(2, N+1):
        g[i][i-1] = 0

    
    d = Dijkstra(g, 1)

    return -1 if d[N] == INF else d[N]


def main():
    N, M = read_int_n()
    LRC = [read_int_n() for _ in range(M)]
    print(slv(N, LRC))

if __name__ == '__main__':
    main()


Measured memory_bytes: 97632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int R = 1, N = 0, K = 0;
  cin >> N >> K;

  for (int i = 0; i < N; i++) {
    if (R <= K)
      R += R;
    else
      R += K;
  }

  cout << R << endl;
}

Measured memory_bytes: 256
m1, d1 = list(map(int, input().split()))
m2, d2 = list(map(int, input().split()))

c = 0

if m1 == 1 and d1 == 31 and m2 == 2 and d2 == 1:
    print(1)
    c = 1
if m1 == 2 and d1 == 28 and m2 == 3 and d2 == 1:
    print(1)
    c = 1
if m1 == 3 and d1 == 31 and m2 == 4 and d2 == 1:
    print(1)
    c = 1
if m1 == 4 and d1 == 30 and m2 == 5 and d2 == 1:
    print(1)
    c = 1
if m1 == 5 and d1 == 31 and m2 == 6 and d2 == 1:
    print(1)
    c = 1
if m1 == 6 and d1 == 30 and m2 == 7 and d2 == 1:
    print(1)
    c = 1
if m1 == 7 and d1 == 31 and m2 == 8 and d2 == 1:
    print(1)
    c = 1
if m1 == 8 and d1 == 31 and m2 == 9 and d2 == 1:
    print(1)
    c = 1
if m1 == 9 and d1 == 30 and m2 == 10 and d2 == 1:
    print(1)
    c = 1
if m1 == 10 and d1 == 31 and m2 == 11 and d2 == 1:
    print(1)
    c = 1
if m1 == 11 and d1 == 30 and m2 == 12 and d2 == 1:
    print(1)
    c = 1
if m1 == 12 and d1 == 31 and m2 == 1 and d2 == 1:
    print(1)
    c = 1
if c == 0:
    print(0)


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

typedef pair<int,int> P;
typedef pair<P, int> Pc;

int main() {
    int N;
    while (cin >> N, N) {
        vector<Pc> pc;
        for (int i = 0; i < N; i++) {
            int a = 0, b = 0, c;
            char s;
            cin >> s;
            c = (N-i) * 1000 + s;
            for (int j = 0; j < N - 1; j++) {
                int t; cin >> t;
                if (t == 0) a++;
                if (t == 2) b++;
            }

            pc.push_back(Pc(P(a, b), c));
        }

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

        for (int i = 0; i < N; i++)
            cout << (char)(pc[N-1-i].second  % 1000)<< endl;
    }

    return 0;
}

Measured memory_bytes: 3052
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

ll Pow(ll A, ll B, ll mod){
  if (B == 0) return 1;
  else{
    if (B % 2 == 0){
      return Pow(A * A % mod, B / 2, mod) % mod;
    }else{
      return A * Pow(A * A % mod, B / 2, mod) % mod;
    }
  }
}

ll nCr(ll N, ll R, ll mod){
  ll ans = 1; R = min(R, N - R);
  for (ll i = 1; i <= R; i++){
    ans *= N - i + 1; ans %= mod;
    ans *= Pow(i, mod - 2, mod); ans %= mod;
  }
  return ans;
}

int main(){
  int N; cin >> N;
  string S[N];
  for (int i = 0; i < N; i++) cin >> S[i];
  sort(S, S + N);

  int cnt = 1;
  vector < pair<int, string> > ans;
  for (int i = 1; i < N; i++){
    if (S[i] == S[i - 1]){
      cnt++;
    }else{
      ans.push_back(make_pair(cnt, S[i - 1]));
      cnt = 1;
    }
  }
  ans.push_back(make_pair(cnt, S[N - 1]));
  sort(ans.begin(), ans.end());

  vector <string> Ans;
  Ans.push_back(ans[ans.size() - 1].second);

  for (int i = ans.size() - 2; i >= 0; i--){
    if (ans[i].first == ans[ans.size() - 1].first){
      Ans.push_back(ans[i].second);
    }
  }

  sort(Ans.begin(), Ans.end());
  for (int i = 0; i < Ans.size(); i++){
    cout << Ans[i] << endl;
  }
  
  return 0;
}


Measured memory_bytes: 21232
from sys import stdin
input = stdin.readline

N = int(input())
A = list(map(int, input().split()))


def p(N):
    for i in range(len(N)):
        if i == len(N) - 1:
            print(N[i])
        else:
            print(N[i], end=" ")


p(A)

for i in range(1, N):
    s = A[i]
    j = i - 1

    while j >= 0 and A[j] > s:
        A[j + 1] = A[j]
        j -= 1

    A[j + 1] = s

    p(A)



Measured memory_bytes: 5984
//Author : Sukarna Paul

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/trie_policy.hpp>
#include<ext/pb_ds/detail/standard_policies.hpp>
#define pi acos(-1)
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#define MAX 300005
#define INF 0x3f3f3f3f
template <class T> inline T bigmod(T p,T e,T M){ll ret = 1LL;for(; e > 0LL; e >>= 1LL){if(e & 1LL) ret = (ret * p) % M;p = (p * p) % M;}return (T)ret;}
template <class T> inline T modinverse(T a,T M){return bigmod(a,M-2,M);}   // M is prime}

using namespace std;
using namespace __gnu_pbds;

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update>pref_trie;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;


int main(){
    IOS
    //freopen("output.txt","w",stdout);

    int n;
    cin>>n;
    int m;
    cin>>m;
    ll sum = 0;
    for(int i=0;i<m;i++){
        ll a;
        cin>>a;
        sum+=a;
    }
    if(n-sum>=0)cout<<n-sum<<"\n";
    else cout<<-1<<"\n";
}


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

 
int main() {
   int a;
   string s;
   cin>>a>>s;
   if(a>=3200)cout<<s<<endl;
   else cout<<"red"<<endl;
}

Measured memory_bytes: 256