akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=998244353;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

ll x;
vl a;

int main(){
	cin>>x;
	for(ll i=0;i<=1000;i++){
		a.push_back(i*i*i*i*i);
	}
	int n=1001;
	for(int i=0;i<n;i++) for(int j=0;j<n;j++){
		if(a[i]+a[j]==x){
			cout<<i<<' '<<-j<<endl;
			return 0;
		}
		if(a[i]-a[j]==x){
			cout<<i<<' '<<j<<endl;
			return 0;
		}
	}
}

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

int main() {
    int n;
    cin >> n;
    vector<vector<ll>> robots(n, vector<ll>(3, 0));
    rep(i, n) {
        cin >> robots[i][1] >> robots[i][2];
        robots[i][0] = robots[i][1] + robots[i][2];
    }
    sort(robots.begin(), robots.end());
    // for(auto v : robots){
    //     cout << v[0] << " " << v[1] << " " << v[3] << endl;
    // }
    int ans = 1;
    int right = robots[0][0];
    for (int i = 1; i < n; i++) {
        if (right <= robots[i][1] - robots[i][2]) {
            ans++;
            right = robots[i][0];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 5760
# N, M = gets.chomp.split.map(&:to_i)
# T = gets.chomp.chars
N = gets.chomp.to_i
works = []
N.times do 
  a, b = gets.chomp.split.map(&:to_i)
  works << b * 10_000_000_000 + a
end

works.sort!
# p works.map { |w| [w / 10_000_000_000, w % 10_000_000_000] }

ans = true
consumed = 0
works.each do |w|
  b = w / 10_000_000_000
  a = w % 10_000_000_000

  consumed += a
  # p consumed
  # p b
  if (consumed <= b)
    # ok
  else
    ans = false
    break
  end
end

if ans
  print "Yes\n"
else
  print "No\n"
end

Measured memory_bytes: 12664
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<=(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<si> vsi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<int> qi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 文字変換　
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
// a内でx以上　auto iter = lower_bound(ALL(a), x);
// a内でxより大きい　auto iter = upper_bound(ALL(a), x);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned Euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return Euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int digit_sum(int n) {
  int sum=n%10;
  while(n!=0) {
    n/=10;
    sum+=n%10;
  }
  return sum;
}

vpll PrimeFactorization(ll n) {
  vpll res;
  for (ll i=2; i*i<=n; i++) {
    if(n%i!=0) continue;
    ll ex=0;
    while(n%i==0) {
      ex++;
      n/=i;
    }
    res.push_back(pll(i,ex));
  }
  if(n!=1) res.push_back(pll(n,1));
  return res;
}


int main() {  
  ll n,m;
  cin >> n >> m;
  vll w(n),v(n);
  REP(i,n) cin >> w[i] >> v[i];
  vvll dp(n+1,vll(m+1,0));
  dp[0][0]=0;
  REPD(i,1,n) {
    REPD(j,0,m) {
      if(j-w[i-1]>=0) {
        dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i-1]]+v[i-1]);
      } else {
        dp[i][j]=dp[i-1][j];
      }
    }
  }
  cout << dp[n][m] << endl;
  return 0;
}


Measured memory_bytes: 83096
import sys
input=sys.stdin.readline


def get_candidate(K):
    l = []
    b = 0
    for i in range(30)[::-1]:
        if (K&(1<<i)):
            l.append(b + (1<<i) - 1)
            b += (1<<i)
    return l+[K]


def get_ans(K, l):
    bit = [None]*30
    for i in range(30):
        bit[i] = (K&(1<<i))>>i

    ans = 0
    for i, j in l:
        for k in range(30):
            b = (i&(1<<k))>>k
            if not ((bit[k]==1) or (b==0 and bit[k]==0)):
                break
        else:
            ans += j
    return ans


def solve():
    N, K = map(int, input().split())
    l = [tuple(map(int, input().split())) for _ in range(N)]
    ans = 0
    for k in get_candidate(K):
        ans = max(ans, get_ans(k, l))
    print(ans)


if __name__ == "__main__":
    solve()


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

#define reps(i,j,k) for(int i=(j);i<(k);i++)
#define rep(i,j) reps(i,0,j)
#define sc second
#define fs first
#define pb push_back
using namespace std;

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


int mnx=200005, mny=200005, mxx=-200005, mxy=-200005;
vector<pii> flip(vector<pii> &v, pii p){
	int l = p.fs;
	int r = p.sc;
	vector<pii> ret;
	for(auto q: v){
		int a = q.fs;
		int b = q.sc;
		if( a == b ) continue;
		if( l == r ){
			ret.emplace_back( a, b );
		}else if( r <= a ){
			ret.emplace_back( l, r );
			ret.emplace_back( a, b );
			l = r;
		}else if( b <= l ){
			//ret.emplace_back( l, r );
			ret.emplace_back( a, b );
		}else if( a < l && r < b ){
			ret.emplace_back( a, l );
			ret.emplace_back( r, b );
			l = r;
		}else if( l <= a && r <= b ){
			ret.emplace_back( l, a );
			ret.emplace_back( r, b );
			l = r;
		}else if( l <= a && b <= r ){
			ret.emplace_back( l, a );
			l = b;
		}else if( a < l && l <= b ){
			ret.emplace_back( a, l );
			l = b;
		}
	}
	if( l != r ) ret.emplace_back(l, r);
	return ret;
}

ll sum(vector<pii> &v, int x){
	int l = 2000056;
	int r = 2000056;
	if( mnx <= x && x < mxx ){
		l = mny;
		r = mxy;
	}
	ll ret = 0;
	for(auto q: v){
		int a = q.fs;
		int b = q.sc;
		if( a == b ) continue;
		if( l == r ){
			ret += b - a;
		}else if( r <= a ){
			ret += b - a;
		}else if( b <= l ){
			ret += b - a;
		}else if( a < l && r < b ){
			ret += l - a;
			ret += b - r;
		}else if( l <= a && r <= b ){
			ret += b - r;
		}else if( l <= a && b <= r ){
		}else if( a < l && l <= b ){
			ret += l - a;
		}
	}
	return ret;
}

int main(){
	int N;
	while(cin >> N, N){
		vector<pii> v;
		rep(i,N){
			int x, y;
			cin >> x >> y;
			v.emplace_back(x, y);
		}
		mnx=200005, mny=200005, mxx=-200005, mxy=-200005;
		rep(i,4){
			int x, y;
			cin >> x >> y;
			mnx = min(mnx, x);
			mny = min(mny, y);
			mxx = max(mxx, x);
			mxy = max(mxy, y);
//cout << mnx << " " << mxx << endl;
		}
		vector<pair<int,pii>> vv;
		if( v[0].fs != v[1].fs ) v.push_back( v[0] );
		for(int i=0; i<v.size()-1; i+=2){
			if( v[i].fs != v[i+1].fs ) i++;
			int a = v[i].sc;
			int b = v[i+1].sc;
			if( a > b ) swap(a, b);
			vv.emplace_back( v[i].fs, pii(a, b) );
		}
		sort( vv.begin(), vv.end() );
				//cout << "vv:"; for(auto t: vv) cout << "(" << t.sc.fs << "," << t.sc.sc << ") "; cout << endl;
		ll ans = 0, idx=0;
		vector<pii> vp;
		for(ll x=-20000; x<=20000; x++){
			while( idx < vv.size() && vv[idx].fs == x ){
				vp = flip(vp, vv[idx].sc);
				idx++;
				//cout << "flip:"; for(auto t: vp) cout << "(" << t.fs << "," << t.sc << ") "; cout << endl;
//cout << "sum: " << ans << endl;
			}
			ans += sum(vp, x);
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3096
#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

// -----------------------------------------------
// Framework <https://github.com/vain0x/procon>
// -----------------------------------------------

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

const P: i64 = 1_000_000_007;

fn main() {
    // dp[y][x][z][b] :
    // 上から y cm 未満の横棒と、左から x cm 未満の高さ y cm の横棒について、引くか引かないか決まった
    // 高さ y cm において z にいる
    // b = 1 <==> (y, x) の横棒を実際に引いた

    let (H, W, K) = read!(usize, usize, usize);

    let mut dp = vec![vec![vec![vec![0_i64; 2]; W]; W]; H + 1];
    dp[0][0][0][0] = 1;

    for y in 0..H {
        for x in 0..W - 1 {
            for z in 0..W {
                let zz = if z == x {
                    x + 1
                } else if z == x + 1 {
                    x
                } else {
                    z
                };
                dp[y][x + 1][zz][1] += dp[y][x][z][0];
                dp[y][x + 1][zz][1] %= P;

                dp[y][x + 1][z][0] += dp[y][x][z][0];
                dp[y][x + 1][z][0] %= P;
                dp[y][x + 1][z][0] += dp[y][x][z][1];
                dp[y][x + 1][z][0] %= P;
            }
        }

        for z in 0..W {
            dp[y + 1][0][z][0] += dp[y][W - 1][z][0];
            dp[y + 1][0][z][0] %= P;
            dp[y + 1][0][z][0] += dp[y][W - 1][z][1];
            dp[y + 1][0][z][0] %= P;
        }
    }

    // debug!({
    //     for y in 0..H + 1 {
    //         debug!(dp[y])
    //     }
    // });

    println!("{}", dp[H][0][K - 1][0]);
}


Measured memory_bytes: 4352
import sys
import itertools
n,m = map(lambda x: int(x),input().split())
tree = [[]*n for i in range(n)]
l = [int(i) for i in range(n)]
ans_count = 0
for _ in range(m) :
    a,b = map(lambda x: int(x),input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)
for v in itertools.permutations(l) :
    if v[0] != 0 :
        continue
    flag = 1
    for w in range(n-1) :
        if not v[w] in tree[v[w+1]] :
            flag = 0
    if flag == 1 :
        ans_count += 1
print(ans_count)


Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
#define repl(i, l, r) for (int i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
struct UnionFind {
	vector<int> par;
	UnionFind(int N) : par(N, -1) {}
	void init(int N) { par.assign(N, -1); }
	int root(int x) {
		if (par[x] < 0) return x;
		return par[x] = root(par[x]);
	}
	bool issame(int x, int y) { return root(x) == root(y); }
	bool merge(int x, int y) {
		x = root(x), y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}
	int size(int x) { return -par[root(x)]; }
};
template <typename T>
struct Edge {
	int a, b;
	T cost;
	bool operator<(const Edge<T> &o) { return cost < o.cost; }
};
ll kruskal(const int &n, vector<Edge<ll>> &a) {
	sort(a.begin(), a.end());
	UnionFind Tree(n);
	ll res = 0;
	for (auto p : a) {
		if (Tree.issame(p.a, p.b)) continue;
		res += p.cost;
		Tree.merge(p.a, p.b);
	}
	return res;
}
int main() {
	int v, e;
	scanf("%d%d", &v, &e);
	vector<Edge<ll>> a(e);
	for (int i = 0; i < e; i++) scanf("%d%d%lld", &a[i].a, &a[i].b, &a[i].cost);
	ll ans = kruskal(v, a);
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 4396
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;

int main(){
  string a,b;cin>>a>>b;
  double c = sqrt(stoi(a+b));
  if(c==floor(c)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    long long int i, j;
    long long int a, x;
    int ans1 = 0;
    int ans2 = 0;
    scanf("%lld", &x);
    
    
for(i = -1000; i<1000; i++){
  for(j = -1000; j<1000; j++){
    a = i*i*i*i*i - j*j*j*j*j;
    if(a == x){
      ans1 = i;
      ans2 = j;
    }
  }
}



  printf("%d\t%d\n", ans1, ans2);

    return 0;
}

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

using namespace std;
#define EPS (1e-7)
#define INF (1e9)


typedef long long  ll;
#define endl '\n'




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


const int MOD = 1000000007;
const long double PI = (acos(-1));
const int MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];

//////////////////////////////////////////


void COMinit() {
   fac[0] = fac[1] = 1;
   finv[0] = finv[1] = 1;
   inv[1] = 1;
   for (int i = 2; i < MAX; i++){
       fac[i] = fac[i - 1] * i % MOD;
       inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
       finv[i] = finv[i - 1] * inv[i] % MOD;
   }
}

int a, b, c;

void Input() {

    cin >> a >> b >> c;
}



void Solve() {


    if(a+b+c >= 22) cout << "bust" << endl;
    else cout << "win" << endl;


}

int main() {

  cin.tie(0);
  ios::sync_with_stdio(false);
  Input();
  Solve();


  return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int n; cin >> n;
    ll p = 1;
    const int mod = 1e9+7;
    for (int i = 1; i <= n; i++)
    {
        p *= i; p %= mod;
    }
    cout << p << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int N;
    cin >> N;
    vector<int> v(N);
    rep(i, N) cin >> v[i];

    int ans = 1;
    if(N == 1) {
        cout << ans << endl;
        return 0;
    }

    int max = v[0];
    for(int i = 1; i < N; i++) {
        if(max <= v[i]) {
            ans++;
            max = v[i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
def erase(str)
  allowed = "ACGT"
  n = str.length - 1
  for i in 0..(n / 2)
    if !allowed.include?(str[i])
      return "l"
    elsif !allowed.include?(str[n - i])
      return "r"
    end
  end
  return nil
end

# Main Loop
input = STDIN.gets().chomp

while (r = erase(input)) != nil
  if r == "l"
    input.slice!(0)
  elsif r == "r"
    input.chop!
  else
    puts "program bug"
    break
  end
end

puts input.length


Measured memory_bytes: 1788
from collections import deque
n,k=map(int, input().split())

A = deque(map(int, input().split()))
li = []
li2 = [0]*n
li.append(1)

next = 0

t=0
rep = False

for i in range(k):
    if i == k:
        print(next+1)
        exit()

    if li2[next] == 1:
        t = li.index(next+1)
        rep = True
        li.pop()
        break

    li.append(A[next])
    li2[next] = 1
    next = A[next]-1


tmp = (k-t)%len(li[t:])
print(li[tmp+t])

Measured memory_bytes: 94704
#include <bits/stdc++.h>
#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(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
int main(){
	string s;
	cin>>s;
	if(s.size()>=4 && s.substr(0,4)=="YAKI") puts("Yes");
	else puts("No");
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstring>
#include <string>
#include <cstdlib>
#include <cstdio>
using namespace std;
typedef pair<int, int> pii;
typedef long long int ll;
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define RREP(i,x) for(int i=(x);i>=0;i--)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();++i)

int d[4][2]={{1,0},{0,1},{-1,0},{0,-1}};

void dfs(int y, int x, ll c, vector< vector<ll> > &area){
	if(area[y][x] != c) return;
	area[y][x] = 0;
	REP(i, 4){
		dfs(y+d[i][0], x+d[i][1], c, area);
	}
}

int n;
main(){
	while(cin >> n, n){
		set<int> x,y;
		vector<pii> p1, p2;
		REP(i, n){
			int a, b, c, d;
			cin >> a >> b >> c >> d;
			x.insert(a);
			y.insert(b);
			x.insert(c);
			y.insert(d);
			p1.push_back(pii(a, d));
			p2.push_back(pii(c, b));
		}
		map<int, int> xto, yto;
		int i=1;
		FOR(it, x) xto[*it] = ++i;
		i=1;
		FOR(it, y) yto[*it] = ++i;
		vector< vector<ll> > area(yto.size()+5, vector<ll>(xto.size()+5, 0));
		RREP(i, yto.size()+2){
			REP(j, xto.size()+2){
				area[i+1][j+1] = 1;
			}
		}
		REP(i, n){
//			printf("y:%d-%d x:%d-%d\n", yto[p1[i].second], yto[p2[i].second], xto[p1[i].first], xto[p2[i].first]);
			for(int j=yto[p1[i].second];j<yto[p2[i].second];j++)
				for(int k=xto[p1[i].first];k<xto[p2[i].first];k++)
					area[j][k] |= 1LL << (i+1);
		}
/*		RREP(i, yto.size()+4){
			REP(j, xto.size()+4){
				printf("%2llx ", area[i][j]);
			}
			cout << endl;
		}
*/		ll ans=0;
		REP(i, yto.size()+2){
			REP(j, xto.size()+2){
//				cout << i << " " << j << endl;
				if(area[i+1][j+1]){
					dfs(i+1, j+1, area[i+1][j+1], area);
					ans ++;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1812
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
int a[200005];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
		scanf("%d",&a[i]);
	int r=1;
	ll sum0=0,sum1=0,ans=0;
	for(int l=1;l<=n;++l)
	{
		while((sum0^a[r])==(sum1+a[r]) && r<=n)
		{
			sum0^=a[r];
			sum1+=a[r++];
		}
		ans+=r-l;
		//printf("%d %d\n",l,r);
		sum0^=a[l];
		sum1-=a[l];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>

int main(void){
  int price, sale, p = 0, s = 0, i = 0;
  double tmp;
  
  while(scanf("%d,%d", &price, &sale) != EOF){
    p += price*sale;
    s += sale;
    i++;
  }
  tmp = (double)s / i;
  s /= i;
  s = (tmp-s>=0.5) ? s+1 : s;
  printf("%d\n%d\n", p, s);
  return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define N 200100
#define N2 1000010
#define MOD 1000000007
#define int long long int
#define INF 1000000000000000
#define fn(i,n) for(int i=0;i<n;i+=1)
#define rep(i,l,r) for(int i=l;i<=r;i+=1)
int prime[N2]={0};
vector <int> pr;
void sieve(){
    prime[0]=1;prime[1]=1;
    for(int i=2;i<=sqrt(N2);i++){
        if(prime[i]==0)
            {
                for(int j=i*i;j<N2;j+=i){
                    prime[j]=1;
                }
            }
    }
    for(int i=2;i<N2;i++){
        if(!prime[i])
            pr.pb(i);
    }
    return ;
}
double pi=3.141592653589;
int a[N];
signed main() {  
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //sieve();
    int n;cin>>n;
    rep(i,1,n-1){
        int x;cin>>x;
        a[x]+=1;
    }
    rep(i,1,n){
        cout<<a[i]<<endl;
    }
}

Measured memory_bytes: 5152
#include <bits/stdc++.h>
#define LL long long
#define ll k<<1
#define rr k<<1|1
#define lson l, m, ll
#define rson m + 1, r, rr
#define INF 0x3f3f3f3f
using namespace std;
const int N = 100000 + 5;
const int maxn = 1e5;
inline int max(int a, int b)
{
    return a > b ? a : b;
}
inline int min(int a, int b)
{
    return a < b ? a : b;
}
int dp[N][2][2][2];
int a[N];
int main()
{
    ios::sync_with_stdio(false);
    int n, x;
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> x;
        a[i] = x;
        dp[i][x][0][0] = dp[i - 1][!x][0][0] + 1;
        dp[i][x][0][1] = max(dp[i - 1][!x][1][1], dp[i - 1][!x][0][1]) + 1;
        dp[i][!x][1][1] = max(dp[i - 1][x][0][0], dp[i - 1][x][1][1]) + 1;
    }
    int res = 0;
    for (int i = 1; i <= n; i++)
    {
        res = max(res, max(dp[i][a[i]][0][1], dp[i][!a[i]][1][1]));
    }
    cout << res << endl;
    return 0;
}




Measured memory_bytes: 6648
N = int(input())

list = [0]*(10**4)

for x in range(1,100+1):
  for y in range(1,100+1):
    for z in range(1,100+1):
      n = x**2 + y**2 + z**2 + x*y + y*z + z*x
      if(n <= 10**4):
        list[n-1] += 1
      
for i in range(N):
  print(list[i])

Measured memory_bytes: 9432
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	int n, m;
	cin >> n >> m;
	
	vector<int> table(n + 1, 0);
	for(int i = 0; i < m; ++i) {
		int L, R;
		cin >> L >> R;
		
		table[L - 1]++;
		table[R]--;
	}
	
	for(int i = 0; i < n; ++i) {
		table[i + 1] += table[i];
	}
	
	int ans = 0;
	for(int i = 0; i < n; ++i) {
		if( m == table[i] ) ans++;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
long long c(long long n, long long r) {
  if (n == r || r == 0)
    return 1;
  else {
    return c(n - 1, r - 1) + c(n - 1, r);
  }
}

int main(){

      int N,M;cin >> N >> M;
      int ans=0;
      if(N == 1)N=0;
      if(M == 1)M=0;

      if(N == 2 && M == 0){
            cout << 1 << endl;
      }else if(N == 0 && M == 0){
            cout << 0 << endl;
      }else if(N ==0){
            cout << c(M,2) << endl;
      }else if(M == 0){
            cout << c(N,2) << endl;
      }else{
            cout << c(N,2) + c(M,2) << endl;
      }
}


Measured memory_bytes: 256
n = int(input())
p_list = list(map(int, input().split()))

count = 0
diff = p_list[1] - p_list[0]
for idx in range(2, n):
    if (0 < diff):
        if (p_list[idx-1] < p_list[idx]):
            count += 1
    elif (diff == 0):
        if (p_list[idx] != p_list[idx-1]):
            count += 1
    else:
        if (p_list[idx] < p_list[idx-1]):
            count += 1
    
    diff = p_list[idx] - p_list[idx-1]

print(count)


Measured memory_bytes: 3064
n = gets.to_i
p = gets.split
q = gets.split

perm = p.permutation(n).to_a.map { |s| s.join.to_i }.sort
p_i = p.join.to_i
q_i = q.join.to_i
diff = perm.index(p_i) - perm.index(q_i)
puts diff.abs

Measured memory_bytes: 15292
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp(x) fixed << setprecision(x)
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e9;
const ll INF = 1e18;
const ld EPS = 1e-10;

template<ll mod> struct Mod_Int{
    ll x;
    Mod_Int() {}
    Mod_Int(ll y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod){}

    Mod_Int &operator += (const Mod_Int &p) {
        x = (x + p.x) % mod;
        return *this;
    }

    Mod_Int &operator -= (const Mod_Int &p) {
        x = (x + mod - p.x) % mod;
        return *this;
    }

    Mod_Int &operator *= (const Mod_Int &p) {
        x = (x * p.x) % mod;
        return *this;
    }

    Mod_Int &operator /= (const Mod_Int &p) {
        *this *= p.inverse();
        return *this;
    }

    Mod_Int operator -() const {return Mod_Int(-x);}

    Mod_Int operator + (const Mod_Int &p) const {return Mod_Int(*this) += p;}

    Mod_Int operator - (const Mod_Int &p) const {return Mod_Int(*this) -= p;}

    Mod_Int operator * (const Mod_Int &p) const {return Mod_Int(*this) *= p;}

    Mod_Int operator / (const Mod_Int &p) const {return Mod_Int(*this) /= p;}

    bool operator == (const Mod_Int &p) const {return x == p.x;}

    bool operator != (const Mod_Int &p) const {return x != p.x;}

    Mod_Int pow(ll n) const{
        Mod_Int now = *this, ret = 1;
        while(n > 0){
            if(n & 1) ret *= now;
            now *= now, n >>= 1;
        }
        return ret;
    }

    Mod_Int inverse() const{
        return pow(mod-2);
    }
};

using mint = Mod_Int<MOD>;
const int MAX_N = 1e5;
mint fac[MAX_N+1];

void init(){
    fac[0] = 1;
    rep2(i, 1, MAX_N){
        fac[i] = fac[i-1]*mint(i);
    }
}

mint comb(mint n, mint k){
    return fac[n.x]/(fac[n.x-k.x]*fac[k.x]);
}

mint perm(mint n, mint k){
    return fac[n.x]/fac[n.x-k.x];
}

int main(){
    int N, K;
    cin >> N >> K;
    //2組の(1, 2, 3,....., N)を左からペアリングしていく
    //dp[i][j][k]:=左からi個目まで見て、残っているペアがj個あり、合計がkとなる組み合わせの数
    int MAX = N*(N+1)+1;
    mint dp[N+1][N+1][MAX];
    rep(i, N+1) rep(j, N+1) rep(k, MAX) dp[i][j][k] = 0;
    dp[0][0][0] = 1;
    rep(i, N){
        rep(j, N){
            rep(k, MAX){
                if(dp[i][j][k] == 0) continue;
                //i+1同士をペアリングする場合
                dp[i+1][j][k+2*j] += dp[i][j][k];
                //両方のi+1をどちらも別の数とペアリングする場合
                if(j >= 1){
                    dp[i+1][j-1][k+2*(j-1)] += (mint)(j*j)*dp[i][j][k];
                }
                //片方のi+1を別の数とペアリングする場合
                dp[i+1][j][k+2*j] += (mint)(2*j)*dp[i][j][k];
                //どちらのi+1もペアリングしない場合
                dp[i+1][j+1][k+2*(j+1)] += dp[i][j][k];
            }
        }
    }
    cout << dp[N][0][K].x << endl;
}

Measured memory_bytes: 52096
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <cmath>
#include <vector>
#include <ctime>
#include <bitset>
using namespace std;
#define pb push_back
#define sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d%d",&n,&m)
#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define sld(n) scanf("%lld",&n)
#define sldd(n,m) scanf("%lld%lld",&n,&m)
#define slddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define sf(n) scanf("%lf",&n)
#define sff(n,m) scanf("%lf%lf",&n,&m)
#define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define ss(str) scanf("%s",str)
#define ans() printf("%d",ans)
#define ansn() printf("%d\n",ans)
#define anss() printf("%d ",ans)
#define lans() printf("%lld",ans)
#define lanss() printf("%lld ",ans)
#define lansn() printf("%lld\n",ans)
#define fansn() printf("%.10f\n",ans)
#define r0(i,n) for(int i=0;i<(n);++i)
#define r1(i,e) for(int i=1;i<=e;++i)
#define rn(i,e) for(int i=e;i>=1;--i)
#define rsz(i,v) for(int i=0;i<(int)v.size();++i)
#define szz(x) ((int)x.size())
#define mst(abc,bca) memset(abc,bca,sizeof abc)
#define lowbit(a) (a&(-a))
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pli pair<ll,int>
#define mp make_pair
#define lrt rt<<1
#define rrt rt<<1|1
#define X first
#define Y second
#define PI (acos(-1.0))
#define sqr(a) ((a)*(a))
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1000000000+7;
const double eps=1e-9;
const int inf=0x3f3f3f3f;
const ll infl = 10000000000000000;
const int maxn=  100000+10;
const int maxm = 100000+10;

int in(int &ret)
{
    char c;
    int sgn ;
    if(c=getchar(),c==EOF)return -1;
    while(c!='-'&&(c<'0'||c>'9'))c=getchar();
    sgn = (c=='-')?-1:1;
    ret = (c=='-')?0:(c-'0');
    while(c=getchar(),c>='0'&&c<='9')ret = ret*10+(c-'0');
    ret *=sgn;
    return 1;
}


int num[maxn];
int cnt[maxn];

int main()
{
#ifdef LOCAL
    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
#endif // LOCAL

    int n;
    sd(n);
    int ans = 0;
    r1(i,n)sd(num[i]);
    r1(i,n)
    {
        if(i<n&&num[i]==i&&num[i+1]==i+1)
        {
            swap(num[i],num[i+1]);
            i++;++ans;
        }
        else if(num[i]==i)swap(num[i],num[i+1]),++ans;
    }
    ansn();
    return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>

using namespace std;
typedef long long ll;

int main()
{
    int x;
    cin >> x;
    if (x == 0)
    {
        cout << 1 << endl;
    }
    else
    {
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;

const int MAX = 105;
const int INF = 1000000005;
const int white = 0;
const int gray = 1;
const int black = 2;

int n, M[MAX][MAX], color[MAX], d[MAX];

void dijkstra(int s) {
  rep(i, n) {
    color[i] = white;
    d[i] = INF;
  }
  d[s] = 0;
  color[0] = gray;
  while (1) {
    int u = -1;
    int mincost = INF;
    rep(i, n) {
      if (color[i] != black && d[i] < mincost) {
        mincost = d[i];
        u = i;
      }
    }
    if (mincost == INF) break;
    color[u] = black;
    rep(v, n) {
      if (color[v] != black && M[u][v] != INF) {
        if (d[u] + M[u][v] < d[v]) {
          d[v] = d[u] + M[u][v];
          color[v] = gray;
        }
      }
    }
  }
  rep(i, n) {
    cout << i << " " << (d[i] == INF ? -1 : d[i])<< endl;
  }
}

int main() {
  cin >> n;
  rep(i, n) {
    rep(j, n) {
      M[i][j] = INF;
    }
  }
  int u, k, v, c;
  rep(i, n) {
    cin >> u >> k;
    rep(j, k) {
      cin >> v >> c;
      M[u][v] = c;
    }
  }
  dijkstra(0);

  
  return 0;
}


Measured memory_bytes: 3160
s = input()
kisuu = ['R', 'U', 'D']
guusuu = ['L', 'U', 'D']
for i in s[::2]:
    if i in kisuu:
        continue
    else:
        print('No')
        quit()
for j in s[1::2]:
    if j in guusuu:
        continue
    else:
        print('No')
        quit()
print('Yes')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define Rint register int
using namespace std;
const int N = 100003;
int n, m, head[N], to[N << 1], nxt[N << 1];
inline void add(int a, int b){
	static int cnt = 0;
	to[++ cnt] = b; nxt[cnt] = head[a]; head[a] = cnt;
}
int dfn[N], tim;
inline int dfs(int x, int f){
	dfn[x] = ++ tim;
	int v = 0;
	for(Rint i = head[x];i;i = nxt[i]) if(to[i] != f){
		if(!dfn[to[i]]){
			int val = dfs(to[i], x);
			if(val) printf("%d %d\n", x, to[i]);
			else printf("%d %d\n", to[i], x);
			v ^= val;
		} else {
			if(dfn[to[i]] < dfn[x]) continue;
			printf("%d %d\n", x, to[i]);
			v ^= 1;
		}
	}
	return 1 - v;
}
int main(){
	scanf("%d%d", &n, &m);
	if(m & 1){puts("-1"); return 0;}
	for(Rint i = 1;i <= m;i ++){
		int a, b;
		scanf("%d%d", &a, &b);
		add(a, b); add(b, a);
	}
	dfs(1, 0);
}

Measured memory_bytes: 6528
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        for (int x = 1; x <= 10000; x++) {
            int i = scanner.nextInt();
            if (i == 0) {
                break;
            } else {
                System.out.println("Case " + x + ": " + i);
            }
        }
    }
}


Measured memory_bytes: 41564
from collections import deque


class UnionFind:
    def __init__(self, v):
        self.v = v
        self._tree = list(range(v + 1))

    def _root(self, a):
        queue = deque()
        while self._tree[a] != a:
            queue.append(a)
            a = self._tree[a]
        while queue:
            index = queue.popleft()
            self._tree[index] = a
        return a

    def union(self, a, b):
        root_a = self._root(a)
        root_b = self._root(b)
        self._tree[root_b] = root_a

    def find(self, a, b):
        return self._root(a) == self._root(b)


N, M = map(int, input().split(' '))
edges = [tuple(map(int, input().split(' '))) for _ in range(M)]

bridges = 0
for a1, b1 in edges:
    union_find = UnionFind(N)
    for a2, b2 in edges:
        if a1 == a2 and b1 == b2:
            continue
        union_find.union(a2, b2)
    if not union_find.find(a1, b1):
        bridges += 1

print(bridges)


Measured memory_bytes: 3316
def solve(brd, bits)
  if bits == (1<<8) - 1
    brd.map{ |arr| puts arr.map{ |v| v ? '.' : 'Q' }.join }
    return true
  end
  y = (0..7).to_a.index{ |i| bits & (1<<i) == 0 }
  (0..7).each do |x|
    if brd[y][x] && check(y, x, brd)
      brd[y][x] = false
      bits += 1<<y
      return true if solve(brd, bits)
      bits -= 1<<y
      brd[y][x] = true
    end
  end
  false
end

def check(y, x, brd)
  (1..7).each do |i|
    [-1, 1].each do |dy|
      (-1..1).each do |dx|
        ny = y + dy * i
        nx = x + dx * i
        if 0 <= ny && ny < 8 && 0 <= nx && nx < 8
          return false unless brd[ny][nx]
        end
      end
    end
  end
  true
end

brd = 8.times.map{ [true] * 8 }
bit = 0
gets.to_i.times do
  r, c = gets.split.map(&:to_i)
  bit += 1<<r
  brd[r][c] = false
end

solve(brd, bit)

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};


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

  rep(I, k) {
    vector<int> r(n, 1), l(n, 1);

    vector<int> ex(n+1, 0);

    rep(i, n) {
      r[i] -= ex[i];
      if(i < n-1) r[i+1] += r[i];
      ++ex[min(i+a[i]+1, n)];
    }

    reverse(ALL(a));
    ex.assign(n+1, 0);


    rep(i, n) {
      l[i] -= ex[i];
      if(i < n-1) l[i+1] += l[i];
      ++ex[min(i+a[i]+1, n)];
    }

    reverse(ALL(l));

    rep(i, n) {
      a[i] = r[i]+l[i]-1;
    }

    if(*min_element(ALL(a)) == n) {
      line_out(a);
      return 0;
    }
  }
  line_out(a);
}

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

ll cnt[10][10];

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

  ll ans = 0;
  for (ll i = 1; i <= n; ++i) {
    string s = to_string(i);
    ++cnt[s[0]-'0'][s.back()-'0'];
  }
  for (ll i = 1; i <= n; ++i) {
    string s = to_string(i);
    ans += cnt[s.back()-'0'][s[0]-'0'];
  }
  cout << ans << endl;

}


Measured memory_bytes: 3784
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    debug("size %ld: ", arr.size()); \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif


#define INF (1e+9)
int main(void) {
    int num;
    cin >> num;
    vector<int> arr(num);
    cins(arr);
    int cost = INF;
    for(int k = -100; k <= 100; k++) {
        int res = 0;
        for(int val: arr) {
            res += (val - k)*(val-k);
        }
        cost = min(cost, res);
    }
    cout << cost << endl;
    return 0;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
ll dp[100010][3];
int main(){
    int n;cin>>n;
    vector<ll>a(n);
    vector<ll>b(n);
    vector<ll>c(n);
    rep(i,n)cin>>a[i]>>b[i]>>c[i];
    dp[0][0]=a[0],dp[0][1]=b[0],dp[0][2]=c[0];
    REP(i,1,n){
        dp[i][0]=max(dp[i-1][1]+a[i],dp[i-1][2]+a[i]);
        dp[i][1]=max(dp[i-1][2]+b[i],dp[i-1][0]+b[i]);
        dp[i][2]=max(dp[i-1][0]+c[i],dp[i-1][1]+c[i]);
    }
    cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]});
}

Measured memory_bytes: 4992
while True:
  a,b=map(int,raw_input().split())
  if a+b ==0: break
  ans={} ; hoge=[0]*b
  for i in range(a):
    t= map(int,raw_input().split())
    for j in range(b):
      hoge[j] += t[j]
  for i,j in enumerate(hoge):
    ans[i+1] = j
  for k,v in sorted(ans.items(),key = lambda x:x[1],reverse=True):
    print k,
  else: print 

Measured memory_bytes: 4260
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main()
{
	int N;
	cin >> N;
	vector<int> p(100005, 0);
	rep(i, N)
	{
		int tmp;
		cin >> tmp;
		p[tmp]++;
	}
	vector<int> csum(100005, 0);
	int ans = 0;
	rep(i, 100005)
	{
		if (i == 0) csum[i] = 0;
		else csum[i] = csum[i - 1] + p[i];

		if (csum[i] == N / 2) ans++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

#ifdef _DEBUG
#include "../../library/library/debug_template.cpp"
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

struct init {
	init() {
		cin.tie(nullptr); ios::sync_with_stdio(false);
		cout << fixed << setprecision(10);
	}
} init_;

int main() {

	lint N;
	cin >> N;

	vector<lint> cnt(N + 1);
	for (lint i = 1; i <= N; i++) {
		for (lint j = 1; j * i <= N; j++) {
			cnt[i * j]++;
		}
	}

	lint ans = 0;
	for (int i = 1; i <= N; i++) {
		ans += cnt[i] * i;
	}

	cout << ans << "\n";

	return 0;
}



Measured memory_bytes: 81340
#include <iostream>

using namespace std;
typedef long long ll;
ll n, a, b;
ll x[100010];

void solve() {
  ll sum = 0;
  for (int i=1;i<n;i++) {
    sum += min((x[i] - x[i-1]) * a, b);
  }
  cout << sum << endl;
}

int main() {
  cin >> n >> a >> b;
  for (int i=0;i<n;i++) {
    cin >> x[i];
  }
  solve();
}


Measured memory_bytes: 1024
#
# abc126 c
#
import math


def main():
    n, k = map(int, input().split())
    ans = 0
    for i in range(1, n+1):
        s = i
        if 1 <= s <= k-1:
            ans += 1/n * (0.5)**math.ceil(math.log2(k/s))
        else:
            ans += 1/n
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
X,Y=[int(x) for x in input().split()]
#N=int(input())
dic={
    1:300000,
    2:200000,
    3:100000,
    0:0,
    }
if X>3:
    X=0
if Y>3:
    Y=0
if X==1 and Y==1:
    print(dic[1]+dic[1]+400000)
else:
    print(dic[X]+dic[Y])


Measured memory_bytes: 3060
fn read_ls<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main(){
    let lst: Vec<i32> = read_ls();
    let (a, b) = (lst[0], lst[1]); 
    println!("{} {}", a*b, (a+b)*2);
}



Measured memory_bytes: 5032
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) throws ParseException {
		FastScanner sc = new FastScanner();
		int A = sc.nextInt();  
		int B = sc.nextInt();  
		int K = sc.nextInt(); 
		int ans = 0;

		if(A > B) {
			int waru = B;
			while(K != 0) {
				if(A % waru == 0 && B % waru == 0) {
					ans = waru;
					K--;
				}
				waru--;
			}
		}else {
			int waru = A;
			while(K != 0) {
				if(A % waru == 0 && B % waru == 0) {
					ans = waru;
					K--;
				}
				waru--;
			}
		}
		System.out.println(ans);
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 21332
#define rep(i, n) for (int i = 0; i < (n); i++)
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int MOD = 1000000007;
// MAX int 2,147,483,647
// MAX O(n) 10^18

bool isSameDigits(int x) {
    string S = to_string(x);
    bool isSame = false;
    if (S.at(0) == S.at(1) && S.at(1) == S.at(2)) isSame = true;
    return isSame;
}

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

    int ans;
    for (int i = N; i <= 999; i++) {
        if (isSameDigits(i)) {
            ans = i;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3708
#include <iostream>

int gcd(int a, int b){
	if (a < b){
		int temp = a;
		a = b;
		b = temp;
	}
	int r = a % b;
	while (r != 0){
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

int lcm(int a,int b){
	return a / gcd(a, b) * b;
}

int main(){
	int a, b;
	while (std::cin >> a >> b){
		std::cout << gcd(a, b) << " " << lcm(a, b) << "\n";
	}
	return 0;
}


Measured memory_bytes: 3084
eval"N,*D="+`dd`.split*?,
A=[0]*N
m=998244353
f=->a,b{b>0?a**b[0]*f[a,b/2]**2%m:1}
D.map{|d|A[d]+=1}
s=q=1
A.map{|a|s=s*f[q,q=a]%m}
p D[A[0]-1]==0?s:0

Measured memory_bytes: 22616
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, m = inintm()

min_id = 10**5+1
max_id = 0

for _ in range(m):
    l, r = inintm()
    min_id = min(min_id, r)
    max_id = max(max_id, l)

print(max(0, min_id-max_id+1))

Measured memory_bytes: 73836
#include <cstdio>

int main(){
    int n, m;
    static int dict[256];
    char k, v, x;
    while(scanf("%d\n",&n)){
        if(!n) return 0;
        for(int i=0; i<256; i++) dict[i] = i;
        for(int i=0; i<n; i++){
            scanf("%c %c\n",&k,&v);
            dict[(int)k] = (int)v;
        }
        scanf("%d\n",&m);
        for(int i=0; i<m; i++){
            scanf("%c\n",&x);
            printf("%c",dict[(int)x]);
        }
        printf("\n");
    }
}

Measured memory_bytes: 0
def main():
    s = input()

    cnt = s.count('R')
    if cnt != 2:
        print(cnt)
        return

    if s[0] == s[-1] == 'R':
        print(1)
    else:
        print(2)


if __name__ == '__main__':
    main()

# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok


Measured memory_bytes: 9088
#include <algorithm>
#include <cstdio>
#include <queue>

using namespace std;

typedef long long ll;
const int N = 200005;

int n;
ll ans;
int w[N];
priority_queue<int> q;

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; i ++ )
        scanf("%d", w + i);
    sort(w, w + n);
    reverse(w, w + n);
    q.push(w[0]);
    for (int i = 1; i < n; i ++ )
    {
        ans += q.top(), q.pop();
        q.push(w[i]), q.push(w[i]);
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 4520