akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;
template <class T>
inline void read(T &x)
{
    x=0; char c=getchar();  int f=1;
    while(!isdigit(c)){if(c=='-')f=-1; c=getchar();}
    while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
#include <bitset>
const int mod=998244353;
ll Pow(ll x,ll y){ll res=1; while(y){if(y&1) res=res*x%mod; x=x*x%mod,y>>=1;} return res;}
bitset<310> f[310];
int n,m;
void print()
{
	for(int i=0;i<n;++i,puts(""))
	{
		for(int j=0;j<m;++j) printf("%d ",f[i][j]==1);
	}
	puts("");
}
int main()
{
	int x; read(n),read(m);
	for(int i=0;i<n;++i) for(int j=0;j<m;++j) read(x),f[i][j]=x;
	int ans=0;
	for(int i=0;i<m;++i)
	{
		for(int j=0;j<n;++j) if((!f[j][j]||j>=i)&&f[j][i]){if(j!=i)swap(f[i],f[j]); break;}//必须循环到n 
		if(!f[i][i]){ans++; continue;}
		for(int j=0;j<n;++j) if(j!=i&&f[j][i]) f[j]^=f[i];
//		print(); 
	}
//	cout<<ans<<endl;
	printf("%lld",((Pow(2,m+n-1)-Pow(2,ans+n-1))%mod+mod)%mod);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 250
 
int P(int);
int L(int);
int R(int);
 
int main(void){
     
    int i,n,h[MAX];
    scanf("%d",&n);
     
    for(i = 1 ; i <= n ; i++){
        scanf("%d",&h[i]);
    }
     
    for(i = 1 ; i <= n ; i++){
         
        printf("node %d: key = %d, " ,i,h[i]);
         
        if(P(i)!=0){
            printf("parent key = %d, ",h[P(i)]);
        }
         
        if(L(i) != 0 && L(i) <= n){
            printf("left key = %d, ",h[L(i)]);
            if(R(i) != 0 && R(i) <= n){
                printf("right key = %d, ",h[R(i)]);
            }
        }
         
        printf("\n");
    }
    return 0;
}
 
int P(int i){
    return i/2;
}
 
int L(int i){
    return 2*i;
}
 
int R(int i){
    return 2*i+1;
}

Measured memory_bytes: 600
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

int n;
LL a[114514];
bool p[114514];//true=+ false=-

const LL INF = 1e17;

int main(void)
{
	cin >> n;
	for (int i = 0; i < n; ++i)
	{
		if (i != 0)
		{
			char c;
			cin >> c;
			p[i] = (c == '+');
		}
		cin >> a[i];
	}
	p[0] = true;
	LL dp[4], ndp[4];
	dp[0] = 0;
	dp[1] = dp[2] = dp[3] = -INF;
	for (int i = 0; i < n; ++i)
	{
		fill(ndp, ndp + 4, -INF);
		for (int j = 0; j <= 2; ++j)
		{
			int jj = j + (!p[i]);
			bool neg = jj % 2;
			LL val = -114514;
			if (!p[i])
			{
				val = -a[i];
				if (!neg)val = -val;
			}
			else
			{
				val = a[i];
				if (neg)val = -val;
			}
			ndp[jj] = dp[j] + val;
		}
		//括弧を閉じる
		for (int j = 3; j >= 1; --j)
		{
			ndp[j - 1] = max(ndp[j - 1], ndp[j]);
		}
		copy(ndp, ndp + 4, dp);
	}
	cout << dp[0] << endl;
	return 0;
}


Measured memory_bytes: 1152
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};
use std::collections::HashSet;


fn main() {
  let s = read::<String>();
  let mut uniq = HashSet::new();

  for c in s.chars() {
    uniq.insert(c);
  }

  if s.len() == uniq.len() {
    println!("yes")
  } else {
    println!("no")
  }
}


Measured memory_bytes: 4352
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <math.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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; }

//INT_MAX	2,147,483,647 = 2*1.0e9

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

  vector<int> A(N);
  rep(i,N) cin >> A[i];

  deque<int> deq;
  for(int i=0; i <N;i++){
    // A[i]以上の値をもつ下限
    int p = lower_bound(deq.begin(), deq.end(), A[i]) - deq.begin();
    if(p==0) deq.push_front(A[i]);
    else deq[p-1] = A[i];
  }

  cout << deq.size() << endl;

  return 0;
}



Measured memory_bytes: 1024
#!usr/bin/env pypy3
from collections import defaultdict, deque
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate
import sys
import math
import bisect


def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)


def main():
    X, Y, A, B, C = LI()
    p = LI()
    q = LI()
    r = LI()
    p = sorted(p, reverse=True)[:X]
    q = sorted(q, reverse=True)[:Y]
    heapify(p), heapify(q)

    for ri in r:
        if len(p) < X:
            heappush(p, ri)
        elif len(q) < Y:
            heappush(q, ri)
        else:
            ptop = p[0]
            qtop = q[0]
            if min(ptop, qtop, ri) == ri:
                continue
            if ptop <= qtop:
                heappop(p)
                heappush(p, ri)
            else:
                heappop(q)
                heappush(q, ri)

    print(sum(sorted(p, reverse=True)[:X]) +
          sum(sorted(q, reverse=True)[:Y]))


main()


Measured memory_bytes: 108348
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

h,a = inm()
print((h+a-1)//a)


Measured memory_bytes: 38460
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using static AtCoderTemplate.MyLibrary;

namespace AtCoderTemplate
{
    class Program
    {
        static void Main (string[] args)
        {
            int N = int.Parse (Console.ReadLine ());
            string S = Console.ReadLine ();

            string[] c = new string[3];
            int ans = 0;
            for (int i = 0; i < 1000; i++)
            {

                if (i < 10)
                {
                    c[0] = c[1] = "0";
                    c[2] = i.ToString ();
                }
                else if (i < 100)
                {
                    c[0] = "0";
                    c[1] = (i / 10).ToString ();
                    c[2] = (i % 10).ToString ();
                }
                else
                {
                    c[0] = (i / 100).ToString ();
                    c[1] = ((i % 100) / 10).ToString ();
                    c[2] = (i % 10).ToString ();
                }

                int j = 0;
                for (int k = 0; k < N; k++)
                {
                    if (S[k].ToString () == c[j]) j++;
                    if (j == 3)
                    {
                        ans++;
                        break;
                    }
                }
            }

            Console.WriteLine (ans);

        }
    }
    class MyLibrary
    {
        public static int GCD (int a, int b)
        {
            if (a % b == 0) return b;
            return GCD (b, a % b);
        }
    }
}

Measured memory_bytes: 40648
while 1:
    n , x =map( int,input().split() )
    count = 0
    if (n,x)==(0,0): break
    for i in range(1,n-1):
        for j in range(i+1,n):
            for k in range(j + 1,n + 1):
                if i + j + k == x:
                    count += 1
    print(count)



Measured memory_bytes: 5600
#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 rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#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(){
  int n;
  cin >> n;
  set<string> se;
  rep(i, n){
    string s;
    cin >> s;
    se.insert(s);
  }
  cout << se.size() << endl;
  return 0;
}

Measured memory_bytes: 19152
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
short ctos(char a) {
	return (int)(a - '0');
}
#define int long long
const long long Inf = 4523372036854775807;
const int inf = 15000000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
int n;
int a[200001];
int dp[200002];
signed main() {
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		dp[i] = -inf;
	}
	int ans = 0;
	for (int i = n; i >= 1; i--) {
		dp[a[i]] = dp[a[i] + 1] + 1;
		if (dp[a[i] + 1] == -inf) dp[a[i]] = 1;
		ans = max(ans, dp[a[i]]);
	}
	cout << n - ans << endl;
}

Measured memory_bytes: 3960
#include <bits/stdc++.h>
using namespace std;
int arr[200];
int main(){
	
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	int n,m;
	cin >> n >> m;
	long long s = 0;
	for(int i = 1;i <= n;i++)cin >> arr[i],s += arr[i];
	long long x = 0;
	sort(arr + 1,arr + 1 + n);
	long long num = arr[n - m + 1] * 4 * m; 
	if(num >= s)cout << "Yes"; else cout << "No";
	return 0;
}

Measured memory_bytes: 256
n = int(input())
xyh = [list(map(int,input().split())) for i in range(n)]

maxh = 0
for x,y,h in xyh:
    maxh = max(maxh,h)
for H in range(maxh,maxh+201):
    for cx in range(101):
        for cy in range(101):
            for x,y,h in xyh:
                if h != max(H-abs(x-cx)-abs(y-cy),0):
                    break
            else:
                print(cx,cy,H)
                quit()


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

int main(){
  string s;
  cin >> s;
  
  int ans = 0;
  if(s.at(0) == 'R'){
    ans = 1;
  }
  for(int i = 1;i < 3;i ++){
    if(s.at(i) == 'R'){
        if(s.at(i-1) == 'R'){
          ans++;
        }
      if(ans == 0){
        ans++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
vector<int> dmg, val;
int cap, n;
long long dp[15000];
long long f(int at)
{
	if(at <= 0)
		return 0;
	if(dp[at] != -1)
		return dp[at];
		
	long long rez = 1e9;
	for(int i = 0;i<n;i++)
	{
		int spell = dmg[i], money = val[i];
		rez = min(rez, f(at - spell) + money);
	}
	return dp[at] = rez;
}
int main()
{
	memset(dp,-1,sizeof(dp));
	cin>>cap>>n;
	for(int i =0;i<n;i++)
	{
		int a, b;
		cin>>a>>b;
		dmg.push_back(a);
		val.push_back(b);
	}
	cout<<f(cap)<<endl;
	return 0;
}

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

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

	vector<int> a(N);
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}

	vector<vector<ll>> dp(N, vector<ll>(N));
	for (int L = N - 1; L >= 0; --L) {
		for (int R = L; R < N; ++R) {
			if (L == R)
				dp[L][R] = a[L];
			else
				dp[L][R] = max(a[L] - dp[L+1][R], a[R] - dp[L][R-1]);
		}
	}
	
	cout << dp[0][N-1] << endl;
}


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

int main(void) {
    int N;
    cin >> N;
    vector< int > A(N + 10);
    for (int i = 2; i <= N; i++) {
        cin >> A[i];
    }
    vector< int > B(N + 10);
    for (int i = 0; i <= N; i++) {
        B[i] = 0;
    }
    for (int i = 2; i <= N; i++) {
        ++B[A[i]];
    }
    for (int i = 1; i <= N; i++) {
        printf("%d\n", B[i]);
    }

    return 0;
}


Measured memory_bytes: 4788
import java.util.ArrayList;
import java.util.Scanner;

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

		ArrayList<Integer> list = new ArrayList<>();

		for (int i = 1; i <= A; i++) {
			if (A % i==0) {
				if (B%i == 0) {
					list.add(i);
				}
			}
		}
		System.out.println(list.get(list.size() -K));
 	}
}


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

using namespace std;

const int NMAX = 1000000000;

typedef long long I64;

bool OK( I64 val, I64 N ) {
    return ( val*(val+1)/2 > N );
}

int main()
{
    I64 N, Ans = NMAX;
    cin >> N;
    I64 st = 1, dr = NMAX;
    while( st <= dr ) {
        I64 mid = (st + dr) / 2;
        if( OK(mid, N) ) {
            dr = mid - 1;
            Ans = mid;
        }
        else st = mid + 1;
    }
    I64 mins = ( Ans*(Ans-  1)/2 == N );
    cout << Ans - mins << '\n';
    return 0;
}


Measured memory_bytes: 384
//author: Harsh :)
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
#define F first
#define S second
const ll mod = 1e9 + 7;
const ll INF = 922337203685477;
#define pb push_back
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define fastio ios_base::sync_with_stdio(false); cin.tie(0);
#define maxN 100007
using namespace std;
int main() {
  fastio;
  ll n = 0;
  cin >> n;
  vector<ll>v(n, 0);
  for (ll i = 0; i < n; ++i) {
    cin >> v[i];
  }
  cout << fixed << setprecision(16);
  sort(v.begin(), v.end());
  ld ans = v[0];
  for (ll i = 1; i < n; ++i) ans = (ans + v[i]) / 2.0;
  cout << ans;
}


Measured memory_bytes: 3852
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }



int main(int argc, char const *argv[]) {
  ll n, d, cnt = 0;
  cin >> n >> d;
  vector<ll> x(n),y(n);
  rep(i,n) cin >> x[i] >> y[i];
  rep(i, n) {
    //if (hypot(x[i], y[i]) <= d) cnt++;
    if (x[i] * x[i] + y[i] * y[i] <= d * d) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 6424
N, M = map(int,input().split())
S = "0" * N

for i in range(M):
    s,c = map(int,input().split())
    if s == 1 and c == 0 and N != 1:
        print("-1")
        quit()
    elif S[s-1] == "0" or S[s-1] == str(c):
        S = S[0:s-1] + str(c) + S[s:]
    else:
        print("-1")
        quit()

if S[0] == "0" and N != 1:
    S = "1" + S[1:]

print(S)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int A, B;
      cin >> A >> B;
 
      if ( A+B >= A-B && A+B >= A*B ) {
          cout << A+B << endl;
        }
        else if ( A-B >= A+B && A-B >= A*B ) {
          cout << A-B << endl;
        }
        else {
          cout << A*B << endl;
        }
    }    
 

Measured memory_bytes: 256
solve [] = "YES"
solve s
  | take 5 s == reverse "dream" = solve $ drop 5 s
  | take 7 s == reverse "dreamer" = solve $ drop 7 s
  | take 5 s == reverse "erase" = solve $ drop 5 s
  | take 6 s == reverse "eraser" = solve $ drop 6 s
  | otherwise = "NO"

main = do
  s <- getLine :: IO String
  putStrLn $ solve (reverse s)


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

void fnInput(map<string, int>& rmpScore)
{
  int nBluelSiz;
  cin >> nBluelSiz;

  for (int i = 0; i < nBluelSiz; i++)
  {
    string sBlueStr;
    cin >> sBlueStr;
    rmpScore[sBlueStr]++;
  }

  int nRedSiz;
  cin >> nRedSiz;

  for (int i = 0; i < nRedSiz; i++)
  {
    string sRedStr;
    cin >> sRedStr;
    rmpScore[sRedStr]--;
  }
}

int fnScoreCheck(const map<string, int>& cnrmpScore)
{
  int nMaxScore = 0;
  for (pair<const string, int> PScore : cnrmpScore)
    nMaxScore = max(nMaxScore, PScore.second);

  return nMaxScore;
}

int main()
{
  map<string, int> mpScore;

  fnInput(mpScore);
  cout << fnScoreCheck(mpScore) << endl;

  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 6)

def main():
    N, K = map(int, input().split())
    T = [0] * N
    for _ in range(K):
        d = int(input())
        for a in map(int, input().split()):
            T[a-1] += 1
    print(len([1 for t in T if 0 == t]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 67864
#include <iostream>

using namespace std;

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

    int count = 0;

    for(int x = 0; x <= K; x++) {
        for(int y = 0; y <= K; y++) {
            int z = S - x - y;
            if(z >= 0 && z <= K) count++;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)

# ----------

INF = float("inf")
MOD = 10 ** 9 + 7

N, A, B, C = map(int, input().split())
num = [A, B, C]
S = []
for i in range(N):
    S.append(input().strip())
S.append('AB')

ans = []
for i in range(N):
    s = S[i]
    s1 = s[0]
    s2 = s[1]
    n1 = num["ABC".index(s1)]
    n2 = num["ABC".index(s2)]
    if n1 == n2 == 0:
        print("No")
        exit()
    if n1 == 0:
        num["ABC".index(s1)] += 1
        num["ABC".index(s2)] -= 1
        ans.append(s1)
        continue
    if n2 == 0:
        num["ABC".index(s1)] -= 1
        num["ABC".index(s2)] += 1
        ans.append(s2)
        continue
    if s1 in S[i + 1]:
        num["ABC".index(s1)] += 1
        num["ABC".index(s2)] -= 1
        ans.append(s1)
    else:
        num["ABC".index(s1)] -= 1
        num["ABC".index(s2)] += 1
        ans.append(s2)

print('Yes')
for a in ans:
    print(a)


Measured memory_bytes: 16896
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<string>
#include<map>
#define INF 1000000000
#define all(c) c.begin(),c.end()
#define uni(c) c.erase(unique(all(c)),c.end())
#define pb push_back
using namespace std;
typedef pair<int,int> P;
typedef pair<bool,P> iP;
typedef pair<int,iP> iPi;
int w,h;
int dx[]={1,1,1,1,1,2,2,2,3,-1,-1,-1,-1,-1,-2,-2,-2,-3},dy[]={-2,-1,0,1,2,-1,0,1,0,-2,-1,0,1,2,-1,0,1,0};
int d[62][32][2];
map<P,bool> mp;
//(i,(b,((i,i),(i,i))))
bool inf(P a){
	if(a.second>=0&&a.second<w&&a.first>=0&&a.first<h)
		return true;
	return false;
}

int dij(vector<vector<int> > f,vector<P> v){
	priority_queue<iPi,vector<iPi> , greater<iPi> > que;
	for(int i=0;i<h;i++)
	for(int j=0;j<w;j++)
	for(int z=0;z<2;z++)
		d[i][j][z]=INF;
	for(int i=0;i<v.size();i++){
		que.push(iPi(0,iP(false,v[i])));
		que.push(iPi(0,iP(true,v[i])));
		d[v[i].first][v[i].second][0]=0;
		d[v[i].first][v[i].second][1]=0;
	}
	
	while(!que.empty()){
		iPi p=que.top();
		P pos=p.second.second;
		bool which=p.second.first;
		int nc=p.first;
		que.pop();
		if(d[pos.first][pos.second][which]<nc){
			continue;
		}
		if(mp[pos]){
			return nc;
		}
		d[pos.first][pos.second][which]=nc;
		if(which)
		for(int i=0;i<9;i++){
			int ny=pos.first+dy[i],nx=pos.second+dx[i];
			if(inf(P(ny,nx))&&d[ny][nx][which^1]>nc+f[ny][nx]){
				que.push(iPi(nc+f[ny][nx],iP(which^1,P(ny,nx))));
			}
		}
		else
		for(int i=9;i<18;i++){
			int ny=pos.first+dy[i],nx=pos.second+dx[i];
			if(inf(P(ny,nx))&&d[ny][nx][which^1]>nc+f[ny][nx]){
				que.push(iPi(nc+f[ny][nx],iP(which^1,P(ny,nx))));
			}
		}
	}
	return -1;
}
int main(){
	while(cin>>w>>h,w||h){
		vector<vector<int> > f(h,vector<int>(w));
		vector<P> v(2);
		mp.clear();
		v.clear();
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				char c;
				cin>>c;//f[i][j];
				if(c=='S'){
					v.pb(P(i,j));
					f[i][j]=0;
				}else if(c=='T'){
					mp[P(i,j)]=true;
					f[i][j]=0;
				}else if(c=='X'){
					f[i][j]=INF;
				}else{
					f[i][j]=c-'0';
				}
			}
		}
		sort(all(v));
		cout<<dij(f,v)<<endl;
	}
	return 0;
}

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

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

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

  int p[N];
  rep(i, N) cin >> p[i];

  int cnt = 0;
  rep(i, N) {
    if (p[i] != i + 1) {
      cnt++;
    }
  }

  if (cnt <= 2) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}


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

int main(){
  
  int a, b, c;
  cin >> a >> b >> c;
  
  vector<int> A(3);
  
  A.at(0) = a;
  A.at(1) = b;
  A.at(2) = c;
  
  sort(A.begin(), A.end());
  if ( A.at(0) + A.at(1) == A.at(2) )
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int main() {
    string S;
    cin >> S;
    int res = (int)S.size(); // INF
    for (char c : S) {
        int tmp = 0;
        for (int i = 0; i < S.size();) {
            int j = i;
            while (j < S.size() && !((S[j] == c) ^ (S[i] == c))) ++j;
            if (S[i] != c) chmax(tmp, j-i);
            i = j;
        }
        chmin(res, tmp);
    }
    cout << res << endl;
}

Measured memory_bytes: 256
import numpy as np

S=input()
T=input()

length = len(list(T))
S_length = len(list(S))

max_score = 0
for i in range(len(list(S))-len(list(T))):
    tmp_T = np.array(list(T))
    tmp_S = np.array(list(S))[i:i+len(tmp_T)]
    score = np.zeros(len(tmp_T))
    score[tmp_T==tmp_S]=1
    score = np.sum(score)
    if max_score < score:
        max_score=score

if S_length==length:
    tmp_T = np.array(list(T))
    tmp_S = np.array(list(S))
    score = np.zeros(len(tmp_T))
    score[tmp_T==tmp_S]=1
    max_score = np.sum(score)
print(int(length-max_score))


Measured memory_bytes: 27204
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;

using namespace std;
using Graph = vector<vector<int>>;
Graph G;
const int AMAX = 100000;
/*int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}

int n;
vll a;

ll solve(bool isp)
{
	ll sum = 0ll;
	ll ret = 0ll;

	for (int i = 0; i < n; i++)
	{
		sum += a[i];
		if (isp and sum <= 0)
		{
			ret += -sum + 1;
			sum = 1ll;
		}
		if (not isp and sum >= 0)
		{
			ret += sum + 1;
			sum = -1ll;
		}
		isp ^= 1;
	}
	return ret;
}

*/
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int r, g, b;
	cin >> r >> g >> b;
	int ans = 0;

	ans = r * 100 + g * 10 + b * 1;
	if (ans % 4 == 0) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll a,b,k;
  cin>>a>>b>>k;
  for(int i=0;i<k;i++){
    if(i%2){
      if(b%2)b--;
      a+=b/2;
      b/=2;
    }
    else{
      if(a%2)a--;
      b+=a/2;
      a/=2;
    }
  }
  cout<<a<<' '<<b<<endl;
}

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

int main(){
  int n;
  int maxs,mins,sum;
  while(cin>>n,n){
    sum=0;
    maxs=0;
    mins=2000;
    for(int i=0,tmp;i<n;i++){
      cin>>tmp;
      sum+=tmp;
      maxs=max(maxs,tmp);
      mins=min(mins,tmp);
    }
    sum-=mins;
    sum-=maxs;
    cout<<sum/(n-2)<<endl;
  }
}

Measured memory_bytes: 1156
#include <stdio.h>

int a[1000];

int main(void)
{
	int n, q, i, tmp, b, c, len;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		scanf("%d", a + i);
	}
	scanf("%d", &q);
	while (q--) {
		scanf("%d%d", &b, &c);
		if (c - b <= 1) continue;
		len = c - b;
		for (i = 0; i < (len >> 1); i++) {
			tmp = a[b + i];
			a[b + i] = a[c - 1 - i];
			a[c - 1 - i] = tmp;
		}
	}
	for (i = 0; i < n; i++) {
		printf("%d%c", a[i], " \n"[i + 1 == n]);
	}
	return 0;
}



Measured memory_bytes: 2048
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		sc.close();
		if(A % 2 == 0 || B % 2 == 0)
			System.out.println("No");
		else
			System.out.println("Yes");
	}
}


Measured memory_bytes: 22356
a = input()
sum = 0
max = 0
for i in a:
    if i is "A":
        sum += 1
    elif i is "T":
        sum += 1
    elif i is "C":
        sum += 1
    elif i is "G":
        sum += 1
    else:
        if sum > max:
            max = sum
        sum = 0
if max == 0 and sum > 0:
    max = sum
if sum > max:
    max = sum
print(max)

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i <= (ll)(n); i++)
#define INF 1000000000000
#define MOD 1000000007
using ll = long long;
using Graph = vector<vector<int>>;

int f(int n){
  if(n%2==0)return n/2;
  else return 3*n+1;
}

int main(){
  int s;
  cin>>s;
  set<int> sd;
  int tmp = s;
  sd.insert(s);
  rep(i,1000000){
    int tmp2 = f(tmp);
    if(sd.count(tmp2)){
      cout<<i+2<<endl;
      return 0;
    }
    sd.insert(tmp2);
    tmp = tmp2;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <sstream>
#include <stdio.h>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <math.h>
#include <utility>
#include <string>
#include <ctype.h>
#include <cstring>
#include <cstdio>
#include <sstream>
using namespace std;

#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define INF 114514810
#define ll long long

int n;
int main()
{
	bool prime[1000005];
	memset(prime, true, 1000005);
	prime[0] = false; prime[1] = false;
	for (int i = 2; i*i < 1000005; i++)
	{
		if (prime[i] == true)
		{
			for (int j = 2; i*j < 1000005; j++)
			{
				prime[i*j] = false;
			}
		}
	}
	while (cin >> n)
	{
		int cnt = 0;
		REP(i, n+1)
		{
			if (prime[i] == true)
			{
				cnt++;
				//cout << i << endl;
			}
		}
		cout << cnt << endl;
	}

	return 0;
}

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

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long N;
    cin >> N;
    vector<long long> A(N+4,0);
    vector<long long> DP(N+4);
    for (long long i = 0; i<N; ++i) cin >> A[i];
    DP[0] = 0;
    DP[1] = abs(A[0]-A[1]);
    if (N==2) cout << DP[1];
    else {
        //DP[2] = min(  abs(A[0]-A[1])  ,  min(  abs(A[0]-A[2]) , abs(A[0]-A[1])+abs(A[1]-A[2]) ) );
        for (long long i = 2,total=0; i<N; ++i) {
            DP[i] = min(abs(A[i]-A[i-1])+DP[i-1],abs(A[i]-A[i-2])+DP[i-2]);
        }
        cout << DP[N-1];
    }
}

Measured memory_bytes: 4728
// #include C/C++ {
#include <bits/stdc++.h>
// }
using namespace std;
// #typedef {
typedef long long int64;
typedef pair <int, int> PII;
typedef pair <int64, int64> PLL;
// }

// #parameter{
#ifdef DEBUG_MODE

#define TYPE decltype
#define RF(filename) {freopen((filename), "r", stdin);}
#define WF(filename) {freopen((filename), "w", stdout);}
#define DF(filename) {freopen((filename), "w", stderr);}
#define eprintf printf

#else

#define TYPE __typeof
#define RF(filename) {;}
#define WF(filename) {;}
#define DF(filename) {;}
#define eprintf(...)
#define fprintf(...)

#endif

// #define {
#define SZ(a) ((int)(a).size())
#define X first
#define Y second
#define MP make_pair
#define L(x) ((x)<<1)
#define R(x) ((x)<<1 | 1)
#define max3(x, y, z) (max(max((x), (y)), (z)))
#define min3(x, y, z) (min(min((x), (y)), (z)))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(it) (it).begin(), (it).end()
#define FILL(__space, __val) memset(__space, __val, sizeof(__space))
#define MOVE(__spaceTo, __spaceFrom) memmove(__spaceTo, __spaceFrom, sizeof(__spaceTo))
#define UNIQUE(__vector) sort(ALL(__vector)), __vector.resize(unique(ALL(__vector)) - __vector.begin())
#define FOR(it, c) for( TYPE((c).begin()) it = (c).begin(); it != (c).end(); it++)
/////////////////////////////////////////////////////////////
const double PI = acos(-1.0);
const double EPS = 1e-6;

#define MAX_N 100005
#define MAX_M 5005
#define MOD (int)(1e9+7)
#define INF ((1 << 30) - 1)
#define BINF ((1LL << 62) - 1LL)
#define NONE -1
#define NIL 0
// }

/////////////////////////////////////////////////////////////
int64 g(int64 x){
	int64 res = 0LL;
	for(int i = 1; i < 62; i++){
		int64 block = 1LL << (i + 1);
		int64 rot = x % block;
		if(rot >= (block >> 1)){
			rot -= block >> 1;
			if((rot & 1) == 0) res += 1LL << i;
		}
	}
	int bk = x % 4;
	if(bk == 1 || bk == 2) res += 1;
	return res;
}
/////////////////////////////////////////////////////////////
int main() {
	RF("input.txt");
	//  WF("output.txt");
	DF("err.txt");

	int64 A, B;
	scanf("%lld %lld", &A, &B);
	if(A > 0) printf("%lld\n", g(B) ^ g(A - 1));
	else printf("%lld\n", g(B));
	return 0;
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
A = list(map(int, input().split()))
Q = int(input())
ans = sum(A)
C = Counter(A)

for i in range(Q):
    b, c = map(int, input().split())
    if C[b] != 0:
        cnt = C[b]
        C[c] += cnt
        C[b] = 0
        ans += (c-b) * cnt
    print(ans)

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

int main() {
	int n; cin >> n;
	vector<string> y(n);
	rep(i, n) {
		string s; cin >> s; sort(s.begin(), s.end());
		y.at(i) = s;
	}
	sort(y.begin(), y.end());
	int64_t a = 0;
	int64_t b = 0;
	string s = "";
	for (string i : y) {
		if (s == i) b++;
		else { s = i; a += b * (b + 1ll) / 2ll; b = 0; }
	}
	a += b * (b + 1ll) / 2ll;
	cout << a << endl;
}

Measured memory_bytes: 5760
#Shift Only
N = int(input())
A = list(map(int,input().split()))
n = 0
judge = 1
for i in range(40):
    if judge == 1:
        for i in range(N):
            if A[i] % 2 == 0:
                A[i] = A[i] // 2
            else:
                judge = 0
        if judge == 1:
            n += 1
    else:
        break
print(n)

Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
    int X,A;
    scanf("%d %d",&X,&A);
    if(0<=X&&X<=9&&0<=A&&A<=9)
    {
        if(X<A)
        {
            printf("0\n");
        }
        else
        {
            printf("10\n");
        }
    }
    return 0;
}

Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.Scanner;

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

		int N = Integer.parseInt(sc.next());

		int[] a = new int[N + 1];
		for (int i = 1; i <= N; i++) {
			a[i] = Integer.parseInt(sc.next());
		}

		sc.close();

		for (int i = N; i >= 2; i--) {
			//i以外のiの約数を探す
//			System.out.println("i:" + i);
			ArrayList<Integer> list = new ArrayList<Integer>();
			list.add(1);
			for (int j = 2; j * j <= i; j++) {
				if (i % j == 0) {
					list.add(j);
					if (j * j != i)
						list.add(i / j);
				}
			}
//			System.out.println(list);
			if (a[i] == 1) {
				for (int j : list) {
					a[j] = 1 - a[j];
				}
			}
		}

//		for(int i = 1;i <= N;i++) {
//			System.out.print(a[i] + " ");
//		}
//		System.out.println();

		int sum = 0;
		for(int i = 1;i <= N;i++) {
			sum += a[i];
		}
		System.out.println(sum);
		for(int i = 1;i <= N;i++) {
			if(a[i] == 1) System.out.print(i + " ");
		}
		System.out.println();

	}
}


Measured memory_bytes: 65256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    string s;
    cin >> s;
    
    set<char> st;
    for (ll i = 0; i < s.length(); i++) {
        st.insert(s[i]);
    }
    
    if(st.size() == 1) {
        cout << 0 << endl;
        return 0;
    }


    ll ans = 100, cnt;
    for (auto key = st.begin(); key != st.end(); key++) {
        string str = s;
        bool flag = true;
        cnt = 1;

        while (flag) {
            string vacant;
            flag = false;
            for (ll i = 0; i < str.length()-1; i++) {
                if (str[i] == *key || str[i+1] == *key) {
                    vacant += *key;
                } else {
                    vacant += str[i];
                    flag = true;
                }
            }
            if (flag) {
                str = vacant;
                cnt ++;
            }
        }

        ans = min(ans, cnt);
    }


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

Measured memory_bytes: 256
/*
    Author: aksayushx
*/
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mod 1000000007
using namespace std;
typedef long long ll;
typedef long double ld;

/*
void compute()
{
	fac[0]=1;
	for(ll i=1;i<=10000;i++)
	fac[i]=(i*fac[i-1])%mod;
}
ll power(ll x, ll y)  
{  
    ll res = 1; 
    x = x % mod;
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % mod;  
        y = y>>1; 
        x = (x*x) % mod;  
    }  
    return res;  
} 
ll modInverse(ll n) 
{ 
    return power(n, mod-2); 
}
ll nCr(ll n,ll r) 
{ 
    if (r == 0) 
        return 1; 
    return (fac[n] * modInverse(fac[r]) % mod * modInverse(fac[n - r]) % mod) % mod; 
}*/ 

void aksayushx()
{
	int n;
	cin>>n;
	vector<ld> p(n);
	for(int i=0;i<n;i++) cin>>p[i];
	vector<vector<ld>> dp(n,vector<ld>(n+1,0.0));
	dp[0][1]=p[0];
	dp[0][0]=1.0-p[0];
	for(int i=1;i<n;i++)
	{
		for(int j=0;j<=i+1;j++)
		{
		    dp[i][j]=dp[i-1][j]*(1.0-p[i]);
		    if(j-1>=0)
			dp[i][j]+=dp[i-1][j-1]*p[i];
			
		}
	}
	ld ans=0.0;
	int m=n/2+1;
	for(int i=m;i<=n;i++)
	ans+=dp[n-1][i];
	//cout<<dp[n-2][1]<<'\n';
	cout<<setprecision(20)<<ans;

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test=1;
    //cin>>test;
    while(test--)
        aksayushx();
    return 0;
}


Measured memory_bytes: 144364
#include <cstdio>
#include <set>
using namespace std;
#define R for(i=0;i<n;++i)
int a[1<<17],b[1<<17],e=1e7,f=-1e7,g=1e7,h=-1e7,n,c,d,j=-1e7,k=-1e7,i;
int main(){
	scanf("%d",&n);
	R{
		scanf("%d %d",&c,&d);
		a[i] = c+d;
		b[i] = c-d;
		e = min(e,a[i]);
		f = max(f,a[i]);
		g = min(g,b[i]);
		h = max(h,b[i]);
	}
	R{
		j = max(j,min(max(a[i]-e,b[i]-g),max(f-a[i],h-b[i])));
		k = max(k,min(max(a[i]-e,h-b[i]),max(f-a[i],b[i]-g)));
	}
	printf("%d\n",min(j,k));
}

Measured memory_bytes: 1816
#include<cstdio>
#include<complex>
#include<cmath>
using namespace std;
typedef complex<double> xy;

int main() {
	xy p1, p2, q, r;

	while (~scanf("%lf,%lf,%lf,%lf,%lf,%lf",
		&p1.real(), &p1.imag(),
		&p2.real(), &p2.imag(),
		&q.real(), &q.imag()))
	{
		double t; //argment
		t = arg((q - p1)) - arg((p2 - p1));
		xy T(cos(-t*2), sin(-t*2));
		r = p1 + (q - p1) * T;
		printf("%.6f %.6f\n", real(r), imag(r));
	}
	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()




int main(){
    int a,b,ans=0;
    cin>>a>>b;
    for(int i=a; i<=b; ++i){
        if(i/10000==i%10 && (i/1000)%10==(i/10)%10){
            //cout<<i<<endl;
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>

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

int n, ans = 0;
int main() {
    cin>>n;
    int a[n] = {0};
    rep (i, n)
        cin >> a[i];
    while (true) {
        rep (i, n) {
            if (a[i]%2 != 0) {
                cout << ans << endl;
                return 0;
            }
        }
        rep (i, n) {
            a[i] = a[i] / 2;
        }
        ans++;
    }
}


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

#define NMAX 40
#define ABMAX 10
const int inf = 1000000;

int a[NMAX], b[NMAX], c[NMAX];
int dp[NMAX + 1][NMAX*ABMAX + 1][NMAX*ABMAX + 1];

int main() {
	int n, ma, mb;
	cin >> n >> ma >> mb;

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

	for (int i = 0; i <= n; i++) {
		for (int ca = 0; ca <= NMAX*ABMAX; ca++) {
			for (int cb = 0; cb <= NMAX*ABMAX; cb++) {
				dp[i][ca][cb] = inf;
			}
		}
	}


	dp[0][0][0] = 0;
	for (int i = 0; i < n; ++i) {
		for (int ca = 0; ca <= NMAX*ABMAX; ca++) {
			 for (int cb = 0; cb <= NMAX*ABMAX; cb++) {
				if (dp[i][ca][cb] == inf) continue;
				dp[i + 1][ca][cb] = min(dp[i + 1][ca][cb], dp[i][ca][cb]);
				dp[i + 1][ca + a[i]][cb + b[i]] = min(dp[i + 1][ca + a[i]][cb + b[i]], dp[i][ca][cb] + c[i]);
			}
		}
	}

	int ans = inf;
	for (int ca = 1; ca <= NMAX*ABMAX; ca++) {
		for (int cb = 1; cb <= NMAX*ABMAX; cb++) {
			if (ca*mb == cb*ma) ans = min(ans, dp[n][ca][cb]);
		}
	}

	if (ans == inf) ans = -1;
	cout << ans << endl;

	return 0;
}

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

using namespace std;

int main(){
	int n;
	int d[1000];
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&d[i]);
	}
	sort(d,d+n);
	int now=1;
	int last=d[0];

	for(int i=1;i<n;i++){
		if(d[i]!=last){
			now++;
			last=d[i];
		}else{
			continue;
		}
	}
	printf("%d\n",now);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define ll long long
#define double long double
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define ALL(V) ((V).begin(),(V).end())
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
using namespace std;

int main(){
  ll N,L,t=1;
  cin>>N>>L;
  ll A[N];
  REP(i,N) cin>>A[i];
  
  bool CAN=false;
  REP(i,N-1){
    if(A[i]+A[i+1]>=L){
      CAN=true;
      t=i+1;
    }
  }
  
  if(CAN){
    cout<<"Possible"<<endl;
    for(int i=1; i<=N-2; ++i){
      if(i<=t-1) cout<<i<<endl;
      else cout<<N+t-1-i<<endl;
    }
    cout<<t<<endl;
  }
  else cout<<"Impossible"<<endl;
  return 0;
}

Measured memory_bytes: 1536
# coding: utf-8

import sys
import math
import collections
import itertools
from functools import lru_cache
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")

H, W = LI()
S = RS(H)

L = [[0] * W for _ in range(H)]
R = [[0] * W for _ in range(H)]
U = [[0] * W for _ in range(H)]
D = [[0] * W for _ in range(H)]

for i in range(H):
    lf = 0
    rf = 0
    for j in range(W):
        if S[i][j] == ".":
            lf += 1
            L[i][j] = lf
        else:
            lf = 0

        if S[i][W-1-j] == ".":
            rf += 1
            R[i][W-1-j] = rf
        else:
            rf = 0

for i in range(W):
    uf = 0
    df = 0
    for j in range(H):
        if S[j][i] == ".":
            df += 1
            D[j][i] = df
        else:
            df = 0

        if S[H-1-j][i] == ".":
            uf += 1
            U[H-1-j][i] = uf
        else:
            uf = 0

ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            ans = max(ans, U[i][j]+D[i][j]+L[i][j]+R[i][j]-3)

print(ans)


Measured memory_bytes: 177032
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
int main(){
	int h,w,n;
	cin>>h>>w>>n;
	int a[n];
	rep(i,n) cin>>a[i];
	int ans[h][w];
	int c=0,index=0,len=0;
	rep(i,h)rep(j,w){
		ans[i][j]=c+1;
		a[c]--;
		if(a[c]==0) c++;
	}
	rep(i,h){
		if (i%2==0) reverse(ans[i],ans[i]+w);
		rep(j,w) cout<<ans[i][j]<<((j==w-1)?"":" ");
		cout<<endl;
	}
	return 0;
}


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

using namespace std;

#define fio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define int long long
#define mp make_pair
#define ff first
#define ss second
#define pii pair<int,int>
#define INF LLONG_MAX
#define EPS 1e-9
#define all(v) (v).begin(),(v).end()
#define sq(x) ((x)*(x))
#define foreach(it, v) for(auto it=(v).begin(); it != (v).end(); ++it)
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)


#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)

template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
 
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}
 
typedef long double dbl;
bool codejam = 0;

const int MOD = 1000*1000*1000 + 7;
const int NMAX = 1000*1000 + 11;

int arr[305];
int n;
string s,str;
char ch;
vector<int> v;
double p[303][303][303];
double ev[303][303][303];
int cnt[4];

void solve()
{
    cin>>n;

    for(int i=0;i<n;i++){
        cin>>arr[i];
        cnt[arr[i]]++;
    }

    p[cnt[1]][cnt[2]][cnt[3]] = 1;

    for(int c = n; c >= 0; c--){
        for(int b = n; b >= 0; b--){
            for(int a = n; a >= 0; a--){
                if(a+b+c > n) continue;
                if(a + b + c == 0) continue;

                double x = (1.0*(n - (a+b+c)))/n;
                double p_waste = (x/(1-x)) + 1;
                double p_go;

                ev[a][b][c] += p[a][b][c]*p_waste;

                if(c > 0){
                    p_go = (double)(c)/(a+b+c);
                    p[a][b+1][c-1] += p[a][b][c]*p_go;
                    ev[a][b+1][c-1] += ev[a][b][c]*p_go;
                }
                if(b > 0){
                    p_go = (double)(b)/(a+b+c);
                    p[a+1][b-1][c] += p[a][b][c]*p_go;
                    ev[a+1][b-1][c] += ev[a][b][c]*p_go;
                }
                if(a > 0){
                    p_go = (double)(a)/(a+b+c);
                    p[a-1][b][c] += p[a][b][c]*p_go;
                    ev[a-1][b][c] += ev[a][b][c]*p_go;
                }

            }
        }
    }
    cout<<fixed<<setprecision(12)<<ev[0][0][0]<<"\n";
}

int32_t main(){ fio;
    int t = 1;
    int cs = 1;
    // cin>>t;
    while(t--){
        if(codejam){
            cout<<"Case #"<<cs<<": ";
        }
        cs++;
        solve();
        cout<<"\n";
    }
}

Measured memory_bytes: 434432
n, x = map(int, input().split())
A = [0] + list(map(int, input().split()))
c = 0
for i in range(n):
  m = A[i] + A[i+1]
  if m > x:
    A[i+1] = x - A[i]
    c += m - x
print(c)

Measured memory_bytes: 14132
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <bitset>
#include <iomanip>

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

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

    vector<int> s(N+1, 0);
    vector<int> x(N+1, 0);
    for (int i = 1; i <= N; i++) {
        int a; cin >> a;
        x[i] = x[i-1] ^ a;
        s[i] = s[i-1] + a;
    }

    ll count = 0;
    int right = 1;
    for (int left = 1; left <= N; left++) {
        int tmp_right = right;
        while (tmp_right <= N) {
            if (s[tmp_right] - s[left-1] == (x[tmp_right] ^ x[left-1])) {
                tmp_right += 1;
            } else {
                break;
            }
        }
        right = tmp_right - 1;
        count += right - left + 1;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int n,m,c,b[25],a[25],cnt;
int main()
{
    cin>>n>>m>>c;
    for(int i=1;i<=m;i++)cin>>b[i];
    for(int i=1;i<=n;i++){
        int tot=0;
        for(int j=1;j<=m;j++){
            cin>>a[j];
            tot+=a[j]*b[j];
        }
        tot+=c;
        if(tot>0)cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 256