akhauriyash/Code-Regression huggingface dataset:
x, y, a, b, c = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))

p = sorted(p)
q = sorted(q)
r = sorted(r)
pi = 0
qi = 0
ri = 0
if x < a:
    pi = a-x
if y < b:
    qi = b-y
result = sum(p[pi:a]) + sum(q[qi:b]) + sum(r)
inf = 10**9
p.append(inf)
q.append(inf)
r.append(inf)
ignorea = False
ignoreb = False
while a-pi + b-qi + c-ri > x+y:
    if ignorea:
        result -= q[qi]
        qi+=1
    elif ignoreb:
        result -= p[pi]
        pi+=1
    else:
        if p[pi] > q[qi]:
            if (b-qi+c-ri) == y:
                ignoreb = True
                result -= p[pi]
                pi+=1
                continue
            if q[qi] >= r[ri]:
                result -= r[ri]
                ri+=1
            else:
                result -= q[qi]
                qi+=1
        else:
            if (a-pi+c-ri) == x:
                ignorea = True
                result -= q[qi]
                qi+=1
                continue
            if p[pi] >= r[ri]:
                result -= r[ri]
                ri+=1
            else:
                result -= p[pi]
                pi+=1
print(result)

Measured memory_bytes: 108004
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)

struct potential_Unionfind{
    vector<int> parents;
    vector<int> weights;
    int m;
    potential_Unionfind(int n):parents(n,-1){
        m = n;
        weights.resize(n);
    }

    int find(int x){
        if(parents[x] < 0) return x;
        else{
            int p = find(parents[x]);
            weights[x] += weights[parents[x]];
            return parents[x] = p;
        }
    }

    //weight[y] - weights[x] = wとなるようにuniteする。
    bool unite(int x,int y,int w){
        w += weight(x);
        w -= weight(y);
        x = find(x);
        y = find(y);
        if(x == y) return false;//もうすでに繋がれている頂点ならfalseを返す
        if(parents[x] > parents[y]) {swap(x,y); w = -w;}
        parents[x] += parents[y];
        parents[y] = x;
        weights[y] = w;
        return true;
    }

    bool same(int x,int y){
        return find(x) == find(y);
    }

    //weightsは各頂点から根までの距離
    int weight(int x){
        find(x);
        return weights[x];
    }

    //まずsame(x,y)で繋がっているかわからないと正しい答えは出てこない
    int diff(int x,int y){
         return weight(y) - weight(x);
    }


};

int main(){
    int n,q;
    cin >> n >> q;
    potential_Unionfind uf(n);
    rep(i,q){
        int c;
        cin >> c;
        if(c==0){
            int x,y,z;
            cin >> x >> y >> z;
            uf.unite(x,y,z);
        }else{
            int x,y;
            cin >> x >> y;
            int ans = uf.diff(x,y);
            if(!uf.same(x,y)) cout << '?' << endl;
            else cout << uf.diff(x,y) << endl;
        }
    }
    return 0;

}



Measured memory_bytes: 3600
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)

#ifdef LOCAL  //デバッグ出力
#define dout cout
#define debug() if (true)
#else
#define dout \
  if (false) cout
#define debug() if (false)
#endif

using namespace std;
int main() {
  int a, b;
  int ans = 0;
  cin >> a >> b;
  if (a == 1 and b == 2) {
    cout << 3;
  } else if (a == 1 and b == 3) {
    cout << 2;
  } else if (a == 2 and b == 1) {
    cout << 3;
  } else if (a == 2 and b == 3) {
    cout << 1;
  } else if (a == 3 and b == 1) {
    cout << 2;
  } else if (a == 3 and b == 2) {
    cout << 1;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <bitset>  
using namespace std;

//======================================================
#define for1(i,n)  for (int i = 0; i < (int)(n); ++i)
#define for2(i,n)  for (int i = 1; i <=(int)(n); ++i)
#define forr1(i,n)  for (int i = n - 1 ;i <= 0; --i)
#define forr2(i,n)  for (int i = n  ;i < 0; --i)
#define all(v)	   ((v).begin()), ((v).end())
#define allr(v)	   ((v).rbegin()), ((v).rend())
#define clr(v,d)   memset(v, d, sizeof(v))
#define ull        unsigned long long
#define MP(a,b)	   make_pair(a,b)
#define S          second
#define F          first
#define PI         3.14159265359
#define ll         long long
#define sz(v)	   v.size()
#define pb         push_back
#define pp         pop_back
#define bgn        begin
#define N          100000+5
#define	MOD        1e9+7
#define inf        1e18
//======================================================
int dx[] = { 0,  0, 1, -1 ,  1,  -1,  1,  -1 };
int dy[] = { 1, -1, 0,  0 , -1,   1,  1,  -1 };
//======================================================
ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
ll power(ull a, ull b, ull ret = 1LL) {
	while (b--) ret = (ret * a);
	return ret;
}
//======================================================



int weights[100+9];
long long benefit[100+9];
int n , kpWeight;
long long dp[100 + 9][100000 + 9];

long long  knapSack(int index , int reminderWeight)
{
	if (index == n)
		return 0;

	if (dp[index][reminderWeight] != -1)
	{
		return dp[index][reminderWeight];
	}

	long long leave = knapSack(index + 1, reminderWeight);

	long long take = 0;
	if (reminderWeight >= weights[index])
	{
		take = benefit[index] + knapSack(index + 1, reminderWeight - weights[index]);
	}
	return dp[index][reminderWeight] = max(leave, take);
}

int main()
{
	
	cin >> n >> kpWeight;
	for (int i = 0; i < n; i++)
	{
		int a;
		long long b;
		cin >> a >> b;
		weights[i] = a;
		benefit[i] = b;
	}
	for (int i1 = n - 1; i1 >= 0; i1--)
	{
		for (int i2 = 0; i2 <= kpWeight; i2++)
		{
			if (i2 >= weights[i1])
			{
				dp[i1][i2] = max(benefit[i1] + dp[i1 + 1][i2 - weights[i1]], dp[i1 + 1][i2]);

			}
			else
			{
				dp[i1][i2] = dp[i1 + 1][i2];

			}
		}
	}
	cout << dp[0][kpWeight];
}



Measured memory_bytes: 81236
import math

def clock_distance(A, B, H, M):
    theta_H = 2*math.pi*(H+M/60)/12
    theta_M = 2*math.pi*M/60
    theta_D = abs(theta_H - theta_M)
    distance = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(theta_D))
    return distance

A,B,H,M = map(int,input().split())
print(clock_distance(A, B, H, M))

Measured memory_bytes: 9396
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>

int main()
{
  int n, k;
  std::string input, copy;
  std::cin >> n >> k >> input;

  copy = input;
  transform(copy.begin(),copy.end(),copy.begin(),[](unsigned char c)->unsigned char{ return std::tolower(c); });

  input[k-1] = copy[k-1];

  std::cout << input << std::endl;

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  ll n;
  cin >> n;
  ll ans = 1e18;
  for(ll i = 1; i*i <= n; i++){
    if(n % i != 0) continue;
    ll j = n/i;
    ans = min(ans, (i-1)+(j-1));
  }
  cout << ans << endl;
  return 0;
}

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

int main()
{
    int a, z;
    string s;
    cin >> s;

    for (int i = 0; i < s.size(); i++)
    {
        if (s.at(i) == 'A')
        {
            a = i;
            break;
        }
    }

    for (int i = s.size() - 1; i > 0; i--)
    {
        if (s.at(i) == 'Z')
        {
            z = i;
            break;
        }
    }

    cout << z - a + 1 << endl;
}

Measured memory_bytes: 640
import sys,queue,math
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = 10**18
MOD = 10**9 + 7
LI = lambda : [int(x) for x in input().split()]
_LI = lambda : [int(x)-1 for x in input().split()]

N,M = LI()
B = [_LI() for _ in range(M)]

g = [i for i in range(N)]
c = [1 for _ in range(N)]

def root(x):
    if x != g[x]: g[x] = root(g[x])
    return g[x]

def union(x,y):
    rx = root(x)
    ry = root(y)
    if rx != ry:
        if c[ry] > c[rx]: ry,rx = rx,ry
        g[ry] = rx
        c[rx] += c[ry]
        c[ry] = 0

k = []
for i in range(len(B)-1,-1,-1):
    a,b = B[i]
    ra = root(a)
    rb = root(b)
    if ra == rb:
        k.append(0)
    else:
        k.append(c[ra]*c[rb])
        union(ra,rb)

ans = 0
for a in k[::-1]:
    ans += a
    print (ans)

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    string n;
    cin >> n;
    bool ans = false;
    rep(i, n.length()) {
        if (n[i] == '7') {
            ans = true;
        }
    }
    if (ans) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}



Measured memory_bytes: 3624
#include <bits/stdc++.h>
 
//LIFE IS NOT A PROBLEM TO BE SOLVED
 
#define rep(i,a,b) for( int i = (int) a; i < (int) b; i++ )
#define REP(i,a,b) for( int i = (int) a; i <= (int) b; i++ )
#define PER(i,a,b) for( int i = (int) a; i >= (int) b; i-- )
#define F first
#define S second
#define mk make_pair
#define pb push_back
#define debug(a) cout << #a << " = " << a << endl;
#define debug2(a,b) cout << #a << " = " << a << " --- " << #b << " = " << b << endl;
#define debugP(a) cout << a.F << " " << a.S << endl;
#define debugV(v, n) { rep( i, 0, n ) { if(i) printf(" "); printf("%d", v[i]); } printf("\n"); }
#define debugM(mat,n,m) rep( i, 0, n ){ rep( j, 0, m ) { if(j) printf(" "); printf("%d", mat[i][j]); } printf("\n"); }
#define debugMD(mat,n,m) rep( i, 0, n ){ rep( j, 0, m ) { if(j) printf(" "); printf("%.2lf", mat[i][j]); } printf("\n"); }
#define all(s) s.begin(), s.end()
 
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair <double, double> ii;
typedef pair <double, ii> iii;
 
const int MAX = 2e3+3;
const int mod = 1e9+7;
 
ll a[100010], f[100010];
int n, q;

int main(){
	
	scanf("%d", &n);	ll s = 0;
	rep(i, 0, n) scanf("%lld", &a[i]), f[a[i]]++, s+=a[i];

	int b, c;
	scanf("%d", &q);
	while(q--){
		scanf("%d %d", &b, &c);
		s -= (ll)f[b]*b;
		s += (ll)f[b]*c;
		f[c]+=f[b];
		f[b]=0;
		printf("%lld\n", s);
	}
	
	
    return 0;
}

Measured memory_bytes: 5312
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::iter::*;
#[allow(unused_imports)]
use std::*;

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
#[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

fn main() {
    println!("{}", solve(&stdin!()));
}
fn solve(src: &str) -> String {
    input! {
        source = src,
        n:usize,
        a:[usize;n-1],
    }
    let mut employee_map = HashMap::new();
    employee_map.insert(1, 0);
    for (i, ai) in a.iter().enumerate() {
        let i = i + 2;
        employee_map.insert(i, 0);
        *employee_map.get_mut(ai).unwrap() += 1;
    }
    let mut employees = employee_map.iter().collect::<Vec<_>>();
    employees.sort_by_key(|(&k, _)| k);
    employees
        .iter()
        .fold(String::new(), |s, (_, v)| format!("{}{}\n", s, v))
}
test! {
    include_str!("c1_in.txt") => include_str!("c1_out.txt"),
    include_str!("c3_in.txt") => include_str!("c3_out.txt"),
}


Measured memory_bytes: 14408
#include<bits/stdc++.h>
using namespace std;
const int M=1e9+7;
long long mod(long long x){
    return (x%M);
    }
long long add(long long a, long long b){
        return mod(mod(a)+mod(b));
    }
long long mul(long long a, long long b){
        return mod(mod(a)*mod(b));
    }
vector<int> adj[200001];
bool vis[200001];
int maxi=0;

int dfs(int i){
    int ans = 0;
    if(!vis[i]){
        vis[i] = true;
        ans++;
        for(auto v:adj[i]){
            ans += dfs(v);
        }
    }
    return ans;
}

int main()
{  int n,m;
   cin>>n>>m;
   memset(vis,false,sizeof(vis));
    for(int i= 0;i<m;i++) {
        int a,b;
        cin>>a>>b;
        a--;b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    for(int i=0;i<n;i++){
        if(!vis[i]){
            maxi = max(maxi,dfs(i));
        }
    }
    cout<<maxi<<endl;

    return 0;
   
}

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

using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl
#define HYPP(x) hypot(x.first,x.second)

constexpr lli MOD = (lli)1e9 + 7;
constexpr lli LIMIT = 1000000000000000000 * 5;
constexpr int tenfive = 100000;

int main() {
	int H, W, K;
	cin >> H >> W >> K;
	vector<string> m(H);
	for (int i = 0; i < H; i++) {
		cin >> m[i];
	}

	vector<int> Hb(W, -1), He(W);
	for (int i = 0; i < W; i++) {
		int pos = -1;
		for (int j = 0; j < H; j++) {
			if (m[j][i] == '#') {
				if (pos == -1) {
					Hb[i] = j;
				}
				pos = j;
			}
		}
		He[i] = pos;
		if (i != 0) {
			He[i] = max(He[i], He[i - 1]);
		}
	}

	vector<int> Wb(H, -1), We(H);
	for (int i = 0; i < H; i++) {
		int pos = -1;
		for (int j = 0; j < W; j++) {
			if (m[i][j] == '#') {
				if (pos == -1) {
					Wb[i] = j;
				}
				pos = j;
			}
		}
		We[i] = pos;
	}
	for (int i = W - 2; i > -1; i--) {
		He[i] = max(He[i], He[i + 1]);
	}

	vector<vector<int>> ans(H, vector<int>(W, -1));
	for (int y = 0; y < H; y++) {
		for (int x = 0; x < W; x++) {
			if (m[y][x] == '#') {
				int lh = 0, lw = 0, rh = y, rw = x;
				//左端
				for (int i = x - 1; i > -1; i--) {
					if (m[y][i] == '#' || ans[y][i] != -1) {
						lw = i + 1;
						break;;
					}
				}
				//右端
				if (We[y] == x) {
					rw = W - 1;
					for (int i = x + 1; i < W; i++) {
						if (m[y][i] == '#' || ans[y][i] != -1) {
							rw = i - 1;
							break;
						}
					}
				}
				//上端
				for (int i = y - 1; i > -1; i--) {
					if (m[i][x] == '#' || ans[i][x] != -1) {
						lh = i + 1;
						break;;
					}
				}
				//下端
				if (He[x] == y) {
					rh = H - 1;
					for (int i = y + 1; i < H; i++) {
						if (m[i][x] == '#' || ans[i][x] != -1) {
							rh = i - 1;
							break;
						}
					}
				}
				for (int dy = lh; dy <= rh; dy++) {
					for (int dx = lw; dx <= rw; dx++) {
						ans[dy][dx] = K;
					}
				}
				K--;
				//cout << x << y << endl;
				//cout << lh << "," << lw << " : " << rh << "," << rw << endl;
				//for (int i = 0; i < H; i++) {
				//	for (int j = 0; j < W; j++) {
				//		cout << ans[i][j] << " \n"[j == W - 1];
				//	}
				//}
				//cout << endl;
			}
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			cout << ans[i][j] << " \n"[j == W - 1];
		}
	}

	return 0;
}


Measured memory_bytes: 1280
Module Program
    Sub Main(args As String())
        Dim N = Integer.Parse(Console.ReadLine())
        Dim D = Enumerable.Range(0, N).Select(Function(i) Console.ReadLine()).Select(Function(i) i(0) = i(2)).ToList()

        For i As Integer = 2 To N - 1
            If D(i - 2) And D(i - 1) And D(i) Then
                Console.WriteLine("Yes")
                Return
            End If
        Next
        Console.WriteLine("No")
    End Sub
End Module


Measured memory_bytes: 28376
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


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


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  string s;cin>>s;
  ll dp[s.size()+1][2];

  rep(i,s.size()+1) rep(j,2) dp[i][j]=0;
  dp[0][0]=1;
  rep(i,s.size()){
    if(s[i]=='0'){
      dp[i+1][0]+=dp[i][0];
      dp[i+1][0]%=MOD;
      dp[i+1][1]+=dp[i][1]*3;
      dp[i+1][1]%=MOD;
    }else{
      dp[i+1][0]+=dp[i][0]*2;
      dp[i+1][0]%=MOD;
      dp[i+1][1]+=dp[i][0];
      dp[i+1][1]%=MOD;
      dp[i+1][1]+=dp[i][1]*3;
      dp[i+1][1]%=MOD;
    }
  }
  cout<<(dp[s.size()][0]+dp[s.size()][1])%MOD<<endl;
}

Measured memory_bytes: 2000
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  ll N,M,K;
  cin >> N >> M >> K;
  ll A[N];
  ll B[M];
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < M; i++) {
    cin >> B[i];
  }
  ll Ar[N+1];
  ll Br[M+1];
  Ar[0] = 0;
  Br[0] = 0;
  for (int i = 0; i < N; i++) {
    Ar[i+1] = Ar[i] + A[i];
  }
  for (int i = 0; i < M; i++) {
    Br[i+1] = Br[i] + B[i];
  }
  int ans = 0;
  for (int i = 0; i <= N; i++) {
    if (Ar[i] <= K) {
      int a = lower_bound(Br,Br+(M+1),K - Ar[i] + 1) - Br;
      ans = max(ans,a - 1 + i);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 9832
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
typedef pair<int, int> pii;
signed main() {
  int n, m;
  cin >> n >> m;

  vector<pii> req(m);
  for (int i = 0; i < m; i++) {
    int ai, bi;
    cin >> ai >> bi;
    req[i] = {ai, bi};
  }
  sort(req.begin(), req.end());

  int result = 0;
  int end = -1;
  for (int i = 0; i < m; i++) {
    if (end <= req[i].first) {
      result++;
      end = n + 2;
    }
    end = min(end, req[i].second);
  }

  cout << result << "\n";
}


Measured memory_bytes: 1920
s = str(input())
t = str(input())
s_t_len = len(s)
count = 0
for i in range(s_t_len):
  if s[i] != t[i]:
    s_replace = s.replace(s[i], t[i], 1)
    count += 1
  else:
    pass
print(count)

Measured memory_bytes: 9584
#include <cstdio>
typedef long long ll;
inline ll rd(){
    ll x=0,p=1;
    char a=getchar();
    while((a<48||a>57)&&a!='-')a=getchar();
    if(a=='-')p=-p,a=getchar();
    while(a>47&&a<58)x=(x<<1)+(x<<3)+(a&15),a=getchar();
    return x*p;
}
inline ll min(ll a,ll b){return a<b?a:b;}
inline ll max(ll a,ll b){return a>b?a:b;}
ll n,a,b,ta,tb;
ll ans;
int main(){
	n=rd(),a=rd(),b=rd();
	ans=n+n;
	if((a&1)==(b&1))return printf("%lld\n",(b-a)/2),0;
	ta=a,tb=b;
	ans=min(b-1,n-a);
	ll p=0;
	p+=n-b+1;b=n;
	a+=p;
	p+=(b-a)/2;
	ans=min(ans,p);
	a=ta,b=tb;
	p=0;
	p+=a;a=1;
	b-=p;
	p+=(b-a)/2;
	ans=min(ans,p);
	printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define SORT(x) sort(x.begin(),x.end(),greater<ll>())
#define ALL(x) x.begin(),x.end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, m, n) for(int i = m; i >= n; i--)
#define INF 1000000000000000003 //1000000007
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;


void Main(){

  int X,t;
  cin>>X>>t;

  cout<< max(0,(X-t))<<"\n";

}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


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

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

    ll n;
    cin >> n;
    
    ll ans = 0;
    for(int i=1; i<=n-1; i++){
        ans += i;
    }
    
    cout << ans << endl;

    return 0;
}

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

def main():
    N = int(input())
    H = [int(h) for h in input().split()]
    
    MaxMove = [0] * (N+1)
    
    for i in range(N-1):
        if H[i+1]<=H[i]:
            MaxMove[i+1] = MaxMove[i] + 1
        else:
            MaxMove[i+1] = 0
    print(max(MaxMove))
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 59632
#include <bits/stdc++.h>
#include <cmath>
#include <stdio.h>

using namespace std;

int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

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


int main() {
  int A,B,C;
  cin>>A>>B>>C;
  if(A==B&&B==C&&C==A) cout<<1<<endl;
  else if(A!=B&&B!=C&&C!=A) cout<<3<<endl;
  else cout<<2<<endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <map>
typedef long long ll;
using namespace std;

int main(void){
    ll N,K;cin>>N>>K;
    map<ll, ll> mp;
    for (ll i = 0; i < N; i++) {
        ll a,b;cin>>a>>b;
        if (mp.find(a) != mp.end()) mp[a] += b;
        else mp[a] = b;
    }

    // 結果出力
    ll cur = 0;
    for (map<ll, ll>::iterator it = mp.begin(); it != mp.end(); ++it) {
        cur += it->second;
        if (cur >= K) { 
           cout <<it->first << endl;
           return 0;
        }
    }
    return 0;
}

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


int main() {
  ll n;
  cin >> n;
  vector<P> v(n);
  rep(i,n){
    ll a1,b1;
    cin>>a1>>b1;
    v[i]=make_pair(b1,a1);
  }
  sort(v.begin(),v.end());
  ll t=0;
  rep(i,n){
    t+=v[i].second;
    if (t>v[i].first){
      cout<<"No";
      return 0;
    }
  }
  cout<<"Yes";
}


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

#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
#define CININIT cin.tie(0),ios::sync_with_stdio(false)
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }

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

constexpr ll mod = 1e9+7;

const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
int H,W;
vector<vector<int>> maze;
int sx,sy,gx,gy;

bool in(int x,int y,int h,int w){
    if(x<0||y<0||x>=h||y>=w) return false;
    else return true;
}

int dfs(int x,int y,int cost){
//    auto tab = maze;
//    tab[x][y]=4;
//    cout << "--------------------------------------------------" << endl;
//    for(int i=0;i<H;i++){
//        for(int j=0;j<W;j++) cout << tab[i][j] << " ";
//        cout << endl;
//    }
    if(cost>9) return -1;

    rep(i,4){
        for(int j=1;x+dx[i]*j>=0 and x+dx[i]*j<H and y+dy[i]*j>=0 and y+dy[i]*j<W;j++){
            int nx=x+dx[i]*j,ny=y+dy[i]*j;
            if(maze[nx][ny]==1) break;
            if(nx==gx and ny==gy){
//                cout << "return : " << cost + 1 << endl;
                return cost + 1;
            }
        }
    }

    int ret = -1;
    rep(i,4){
        if(in(x+dx[i],y+dy[i],H,W) and maze[x+dx[i]][y+dy[i]]==1) continue;
        for(int j=1;x+dx[i]*j>=0 and x+dx[i]*j<H and y+dy[i]*j>=0 and y+dy[i]*j<W;j++){
            int nx=x+dx[i]*j,ny=y+dy[i]*j;
            if(maze[nx][ny]==1){
                maze[nx][ny]=0;
                int tmp=dfs(x+dx[i]*(j-1),y+dy[i]*(j-1),cost+1);
                maze[nx][ny]=1;
                if(tmp>=0){
                    if(ret==-1) ret = tmp;
                    else ret = min(ret,tmp);
                }
                break;
            }
        }
    }
 //   if(ret==-1) cout << "error" << endl;
    return ret;
}

void solve(){
    vvi tmp;
    swap(maze,tmp);
    maze = vvi(H,vi(W));
    rep(i,H) rep(j,W){
        cin>>maze[i][j];
        if(maze[i][j]==2){
            sx=i;
            sy=j;
        }
        if(maze[i][j]==3){
            gx=i;
            gy=j;
        }
    }

    int ans = dfs(sx,sy,0);
    cout << ans << endl;
}

int main(){
    while(cin>>W>>H){
        if(H==0 and W==0) break;
        solve();
    }
}

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    Int n, k;
    cin >> n >> k;
    vector<Int> a, b;
    for (Int i = 0; i < n; i++) {
        Int x;
        cin >> x;
        if (x < 0) {
            a.push_back(x);
        } else {
            b.push_back(x);
        }
    }
    for (Int i = 0; i < (Int)a.size(); i++) {
        a[i] = -a[i];
    }
    a.push_back(0);
    b.push_back(0);
    sort(all(a));
    sort(all(b));
    Int mi = INF;
    for (Int i = 0; i < (Int)a.size(); i++) {
        if (k < i) break;
        if (k - i >= (Int)b.size()) continue;
        Int t = a[i] + b[k - i];
        if (not(i == 0 or k - i == 0)) {
            t += min(a[i], b[k - i]);
        }
        mi = min(mi, t);
    }
    dump(mi);
    return 0;
}

Measured memory_bytes: 1656
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1E9
#define EPS 1E-9
#define MOD (ll)(1E9+7)
#define PI 3.1415926535897932384

template <class T>ostream &operator<<(std::ostream &o, const vector<T> &v)
{
	rep(i, v.size()) {
		o << (i > 0 ? " " : "") << v[i];
	}
	return o;
}
int n,t=0;
vvi a;
vi d;
vi f;

void Depth(int pos) {
	if (d[pos] == 0) {
		d[pos] = ++t;
	}
	rep(i, n) {
		if (a[pos][i] == 1&&d[i]==0) {
			Depth(i);
		}
	}
	if (f[pos] == 0) {
		f[pos] = ++t;
	}
}


int main() {
	cin >> n;
	a.resize(n, vi(n, 0));
	d.resize(n, 0);
	f.resize(n, 0);
	rep(i, n) {
		int num,m;
		cin >>num >>m;
		rep(i, m) {
			int tmp;
			cin >> tmp;
			a[num - 1][tmp - 1] = 1;
		}
	}
	Depth(0);
	rep(i, n) {
		if (d[i] == 0) {
			Depth(i);
		}
	}
	rep(i, n) {
		cout << i + 1 << " " << d[i] << " " << f[i] << endl;
	}
}



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

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var p = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var q = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

        var a = 0;
        var b = 0;

        foreach(var item in GetPermutation(Enumerable.Range(1, n))){
            if (IsBigger<int>(p, item.ToArray()) == false) a++;
            if (IsBigger<int>(q, item.ToArray()) == false) b++;
        }

        Console.WriteLine(Math.Abs(a - b));
    }

    static bool IsBigger<T>(T[] a, T[] b) where T : IComparable<T>
    {
        if (a.Length != b.Length) return false;

        var length = a.Length;
        for (int i = 0; i < length; i++)
        {
            if (a[i].CompareTo(b[i]) == 0) continue;

            if (a[i].CompareTo(b[i]) > 0) return true;
            else return false;
        }

        return false;
    }

    public static IEnumerable<T[]> GetPermutation<T>(IEnumerable<T> collection)
    {
        // 未確定要素が一個のみ
        if(collection.Count() == 1)
        {
            yield return new T[] { collection.First() };
        }

        foreach(var item in collection)
        {
            var selected = new T[] { item };
            var unused = collection.Except(selected);

            // 確定した要素以外の前通りを再帰で取り出す
            foreach(var num in GetPermutation(unused))
            {
                yield return selected.Concat(num).ToArray();
            }
        }
    }
}

Measured memory_bytes: 22236
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

#define eps (1e-10)
struct Point{
    double x,y;
    Point(){}
    Point(double x,double y):x(x),y(y){}
    Point operator+(Point p) {return Point(x+p.x,y+p.y);}
    Point operator-(Point p) {return Point(x-p.x,y-p.y);}
    Point operator*(Point p) {return Point(x*p.x-y*p.y,x*p.y+y*p.x);}
    Point operator*(double k){return Point(x*k,y*k);}
    double norm(){return x*x+y*y;}
    double abs(){return sqrt(norm());}
    bool operator == (const Point &p) const{return fabs(x-p.x)<eps && fabs(y-p.y)<eps;}
    double arg(){return atan2(y,x);}
    double dot(Point p){return x*p.x+y*p.y;}
    double det(Point p){return x*p.y-y*p.x;}
};
bool cmp_x(const Point& p,const Point& q){
  if(p.x!=q.x) return p.x<q.x;
  return p.y<q.y;
}
struct Circle{
    double r;
    Point p;
    Circle(){}
    Circle(Point p,double r):p(p),r(r){}
};
bool isIntersectCC(Circle c1,Circle c2){
    return (c1.p-c2.p).abs()<=c1.r+c2.r+eps;
}
pair<Point,Point> CrossPointsCC(Circle c1,Circle c2){
    assert(isIntersectCC(c1,c2));
    double d=(c1.p-c2.p).abs();
    double k=acos((d*d+c1.r*c1.r-c2.r*c2.r)/(c1.r*d*2));
    return make_pair(c1.p+(c2.p-c1.p)*Point(cos(k),sin(k))*(c1.r/d),c1.p+(c2.p-c1.p)*Point(cos(-k),sin(-k))*(c1.r/d));
}
Point p[301];
int main(){
    int n;
    double x,y;
    while(cin>>n,n){
        rep(i,n){
            cin>>x>>y;
            p[i]=Point(x,y);
        }
        int mx=1;
        rep(i,n)FOR(j,i+1,n){
            if((p[i]-p[j]).abs()>2) continue;
            pair<Point,Point> pp=CrossPointsCC(Circle(p[i],1.0),Circle(p[j],1.0));
            int cnt=0,cnt2=0;
            rep(k,n){
                if((pp.first-p[k]).abs()<=1.0+eps) ++cnt;
                if((pp.second-p[k]).abs()<=1.0+eps) ++cnt2;
            }
            mx=max(mx,max(cnt,cnt2));
        }
        cout<<mx<<endl;
    }
    return 0;
}


Measured memory_bytes: 3580
<?php
$n = trim(fgets(STDIN));
for ($i=0; $i<$n; $i++) {
  $input = trim(fgets(STDIN));
  $data = explode(" ", $input);
  $data = array_map(function($v) { return $v*$v; }, $data);
  sort($data);

  if (($data[0] + $data[1]) == $data[2]) {
    echo "YES\n";
  } else {
    echo "NO\n";
  }
}

Measured memory_bytes: 15060
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int N = 500005;

struct pI {
      int x, y;
};

LL detI(pI& a, pI& b, pI& c) {
      return a.x * 1LL * b.y + b.x * 1LL * c.y + c.x * 1LL * a.y - a.x * 1LL * c.y - b.x * 1LL * a.y - c.x * 1LL * b.y;
}

int ccwI(pI& a, pI& b, pI& c) {
      LL d = detI(a, b, c);
      return (d > 0) ? 1 : ((d < 0) ? -1 : 0);
}

double od (double a, double b, double c, double d) {
            return sqrt( (a-c) * 1LL * (a-c) + (b-d) * 1LL * (b-d));
}


bool obliczOkrag (pI a, pI b, pI c, double& x, double& y, double& r) {
            if (ccwI(a,b,c)==0) return false;
            double ma,mb;
            if (a.x==b.x) swap(b,c);
            if (b.x==c.x) swap(a,b);
            ma = ((b.y - a.y)*1.0) / (b.x - a.x);
            mb = ((c.y - b.y)*1.0) / (c.x - b.x);
            x = (ma * mb * (a.y-c.y) + mb * (a.x+b.x) - ma * (b.x+c.x)) / (2*(mb-ma));
            y = (-1/ma) * (x-(a.x+b.x)/2.0) + (a.y+b.y)/2.0;
            r = od (a.x,a.y,x,y);    
            return true;
}

double minR, x, y, r;
int n, i, j, l;
pI tab[55];
const double eps = 1e-8;

void check() {
	int ok = 1;
	for (int k=0;k<n;k++) if (od(tab[k].x, tab[k].y, x, y) > r + eps) ok = 0;
	if (ok) minR = min(minR, r);
}

int main() {
scanf("%d", &n);
for (i=0;i<n;i++) scanf("%d %d", &tab[i].x, &tab[i].y);
minR = INF;
for (i=0;i<n;i++) for (j=i+1;j<n;j++) {
	x = (tab[i].x + tab[j].x) / 2.0;
	y = (tab[i].y + tab[j].y) / 2.0;
	r = od(tab[i].x, tab[i].y, x, y);
	check();
}
for (i=0;i<n;i++) for (j=i+1;j<n;j++) for (l=j+1;l<n;l++) {
	if (obliczOkrag(tab[i], tab[j], tab[l], x, y, r)) check();
}
printf("%.10lf\n", minR);
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> inline T bis(T ok, T ng, function<bool(T)> f, T eps = 1) { while (abs(ok - ng) > eps) { T mi = (ok + ng) / 2; (f(mi) ? ok : ng) = mi; } return ok; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
#pragma endregion

void solve() {
  multiset<int, greater<int>> se;
  se.insert(-1);
  int n;
  cin >> n;
  int m = exp(2, n);
  rep(i, m) {
    int s;
    cin >> s;
    se.insert(s);
  }
  multiset<int, greater<int>> te;
  {
    auto it = se.lower_bound(2e9);
    te.insert(*it);
    se.erase(it);
  }
  rep(i, n) {
    vi32 lst;
    each(t, te) lst.push_back(t);
    each(l, lst) {
      auto it = se.upper_bound(l);
      int val = *it;
      if (val == -1) no();
      se.erase(it);
      te.insert(val);
    }
  }
  yes();
}


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

struct TCard{
	int Number;
	char Mark;
    bool operator<(const TCard &Y) const;
	bool operator<=(const TCard &Y) const;
    bool operator==(const TCard &Y) const;	
};

bool TCard::operator<(const TCard &Y) const
{
	return Number < Y.Number;
}
bool TCard::operator<=(const TCard &Y) const
{
	return Number <= Y.Number;
}
bool TCard::operator==(const TCard &Y) const
{
	return Mark == Y.Mark;
}

int Partition(vector<TCard>& A, int p, int r)
{
	int i = p-1;
	for(int j = p; j < r; j++){
		if(A[j] <= A[r]){
			i++;
			swap(A[i], A[j]);
		}
	}
	swap(A[i+1], A[r]);
	return i+1;
}

void QuickSort(vector<TCard>& A, int p, int r)
{
	if(p < r){
		int q = Partition(A, p, r);
		QuickSort(A, p, q-1);
		QuickSort(A, q+1, r);
	}
}

int main()
{
	int n;
	cin >> n;
	vector<TCard> A(n);
	for(int i = 0; i < n; i++){
		cin >> A[i].Mark >> A[i].Number;
	}
	vector<TCard> B = A;
	std::stable_sort(B.begin(), B.end());
	QuickSort(A, 0, n-1);
	if(A == B){
		cout << "Stable" << endl;
	}else{
		cout << "Not stable" << endl;
	}
	for(int i = 0; i < n; i++){
		cout << A[i].Mark << ' ' << A[i].Number << endl;
	}
	return 0;
}

Measured memory_bytes: 4580
#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;

int main(){
    int N;
    cin >> N;
    map<int, int> mp;
    rep(i, N-1){
        int a; cin >> a;
        mp[a]++;
    }
    rep2(i, 1, N) cout << mp[i] << endl;
}

Measured memory_bytes: 12976
#!/usr/bin/env python

if __name__ == '__main__':
    while True:
        n = int(raw_input())
        if n == 0:
            break

        s = map(float, raw_input().split())
        m = sum(s)/len(s)
        print (sum(map(lambda x : (x-m)**2, s))/len(s))**0.5



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

#[fastout]
fn main() {
    input! {n: usize, d: [usize; n]};
    let mut sum = 0;

    for i in 0..n - 1 {
        for j in i + 1..n {
            sum += d[i] * d[j];
        }
    }

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


Measured memory_bytes: 2196
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
using namespace std;

vector<string> number;
int L;

bool comp_asc(const char& ch1, const char& ch2){
  return (ch1 < ch2);
}

bool comp_des(const char& ch1, const char& ch2){
  return (ch1 > ch2);
}

int findj(string num){
  vector<string>::iterator it;
  int k = 0;
  for(it = number.begin(); it != number.end(); it++){
    if(*it == num) return k;
    k++;
  }
  return 0;
}

void padding(string& num){
  while(num.size() < L){
    num.insert(num.begin(), '0');
  }
}

int main(void){
  string num;
  int i = 0;
  while(cin >> num >> L, L){
    padding(num);
    number.push_back(num);
    while(true){
      sort(num.begin(), num.end(), comp_des);
      int nb = int(atof(num.c_str()));
      sort(num.begin(), num.end(), comp_asc);
      int ns = int(atof(num.c_str()));
      num = to_string(nb - ns);
      
      padding(num);
      i++;

      if(find(number.begin(), number.end(), num) != number.end()){
        int j = findj(num);
        cout << j << " " << int(atof(num.c_str())) << " " << i - j << endl;
        break;
      }
      
      number.push_back(num);
    }
    number.clear();
    i = 0;
  }
  return 0;
}

Measured memory_bytes: 1284
def main():
    n = int(input())
    a = []
    for _ in range(n):
        a.append(int(input()))

    sorted_a = sorted(a, reverse=True)
    one = sorted_a[0]
    two = sorted_a[1]

    for i in range(n):
        if one == a[i]:
            print(two)
        else:
            print(one)

main()

Measured memory_bytes: 14112
object Main{

def main(args: Array[String]): Unit = {
  val arr1 = io.StdIn.readLine().split(' ')
  val L = arr1(0).toLong
  val R = arr1(1).toLong
  
  val given = 2019 // = 1 x 3 x 673
  val pf1 = 3
  val pf2 = 673
  val res = R - L
  
  if(res >= pf2 - 1){
    println("0")
  }else{
    var min = 2018
    (L until R).foreach{
      i =>
      (i + 1L to R).foreach{
        j => 
      val k = (i * j) % 2019L
      if(min > k) min = k.toInt
      }
    }
    println(min)
  }
}
}

Measured memory_bytes: 29724
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define fi first
#define sec second
#define pr priority_queue
#define ump  unordered_map
#define prg priority_queue<ll, vec<ll> ,greater<ll> >
#define pb  push_back;
//parent finding
ll find(vector<ll> &v, ll n)
{
  if (v[n] == n)
    return n;
  return v[n] = find(v, v[n]);
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, sum = 0;
  cin >> n;
  vector<ll> vec(n);
  for (ll i = 0; i < n; i++)
    cin >> vec[i];
  ll maxy = vec[0];
  for (ll i = 1; i < n; i++)
  {
    maxy = max(maxy, vec[i]);
    if (maxy > vec[i])
      sum += maxy - vec[i];
  }
  cout << sum << "\n";
  return 0;
}

Measured memory_bytes: 4760
from collections import deque
def main():
    N, u, v = [int(i) for i in input().split()]
    u -= 1
    v -= 1
    graph = [[] for _ in range(N)]
    for i in range(N-1):
        a,b = [int(i) for i in input().split()]
        a -= 1
        b -= 1
        graph[a].append(b)
        graph[b].append(a)
    atree, aparents, adistances = maketree(v, graph, N)
    ttree, tparents, tdistances = maketree(u, graph, N)
    res = 0
    # print(adistances)
    # print(tdistances)
    for i in range(N):
        a = adistances[i]
        t = tdistances[i]
        if(a > t):
            res = max(res, a - 1)
    print(res)

def maketree(v, graph, N):
    tree = [[] for _ in range(N)]
    parents = [-1] * N
    distances = [0]*N
    
    stack = deque([(v, -1, 0)])
    while len(stack) > 0:
        current, parent, distance = stack.pop()
        distances[current] = distance
        parents[current] = parent
        for n in graph[current]:
            if parent == n:
                continue
            stack.append((n, current, distance+1))
            tree[current].append(n)
    return tree, parents, distances
    
main()

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

using namespace std;

#define abs abs_
inline int abs(int x){return x<0?-x:x;} 
inline bool chk(int n){if(n<=2)return false;for(int d=2;d*d<=n;d++)if(n%d==0)return false;return true;}

const int N=233,M=23333,inf=1e9;

int S,T,h[N],nxt[M],to[M],flow[M],cnt=1,qu[N],ql,qr,d[N];
void addedge(int u,int v,int c){
	to[++cnt]=v,nxt[cnt]=h[u],h[u]=cnt,flow[cnt]=c;
	to[++cnt]=u,nxt[cnt]=h[v],h[v]=cnt,flow[cnt]=0;
}
bool bfs(){
	for(int i=S;i<=T;i++)d[i]=-1;
	d[S]=0,qu[ql=qr=1]=S;
	while(ql<=qr){
		int u=qu[ql++];
		for(int i=h[u],v;i;i=nxt[i])if(d[v=to[i]]==-1&&flow[i])d[v]=d[u]+1,qu[++qr]=v;
		if(d[T]!=-1)break;
	}
	return d[T]!=-1;
}
int dfs(int u,int mf){
	if(u==T)return mf;
	int r=0,p;
	for(int i=h[u],v;i;i=nxt[i])if(d[v=to[i]]==d[u]+1&&flow[i])
		p=dfs(v,min(mf,flow[i])),flow[i]-=p,flow[i^1]+=p,r+=p,mf-=p; 
	return r;
}
int dinic(){
	int r=0;
	while(bfs())r+=dfs(S,inf);
	return r;
}

int n,m1,m2,odd[N],even[N];
set<int> dat;

int main(){
	scanf("%d",&n);
	for(int i=1,x;i<=n;i++){
		scanf("%d",&x);
		if(dat.count(x))dat.erase(x);else dat.insert(x);
		x++;
		if(dat.count(x))dat.erase(x);else dat.insert(x);
	}
	for(int x:dat)if(x&1)odd[++m1]=x;else even[++m2]=x;
	T=m1+m2+1;
	for(int i=1;i<=m1;i++)addedge(S,i,1);
	for(int i=1;i<=m2;i++)addedge(i+m1,T,1);
	for(int i=1;i<=m1;i++)for(int j=1;j<=m2;j++)
		if(chk(abs(odd[i]-even[j])))addedge(i,j+m1,1);
	int mch=dinic(),ans=m1+m2-mch+((m1-mch)&1); 
	printf("%d\n",ans); 
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#define REP(i, n) for(LL i = 0;i < n;i++)
#define REPR(i, n) for(LL i = n;i >= 0;i--)
#define FOR(i, m, n) for(LL i = m;i < n;i++)
#define FORR(i, m, n) for(LL i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
//typedef LL int;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
    int n, m;
    cin >> n >> m;
    cout << --n * --m << endl;   
}


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

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

	int			n;
	int			max;
	int			second_max;
	cin >> n;
	vector<int>	A(n);
	vector<int>	B(n);

	rep(i, n)
		cin >> A.at(i);
	B = A;
	sort(B.begin(), B.end(), greater<>());
	max = B.at(0);
	second_max = B.at(1);
	rep(i, n)
	{
		if (A.at(i) != max)
			cout << max << "\n";
		else
			cout << second_max << "\n";
	}
}


Measured memory_bytes: 3200