akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)((x).size())
#define mp make_pair

using namespace std;

typedef unsigned long long ull;
typedef pair<int,int> ii;

template<class U,class T>ostream& operator<<(ostream& out, pair<U,T> & P){
    return out << "[" << P.first << ", " << P.second << "]";
}
template<class T>ostream& operator<<(ostream& out, vector<T> & V){
    if(!V.empty())out << "[";
    for(int i = 0; i < sz(V); i++)out << V[i] << (i+1==sz(V)?"]":", ");
    return out;
}

int main(){
    ios_base::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    string A(b,char(a+'0'));
    string B(a,char(b+'0'));
    cout << (A<B?A:B) << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 2000000
#define INFTY (1<<30)
int H,A[MAX+1];
void maxHeapify(int i){
  int l,r,largest;
  l=2*i;
  r=2*i+1;
  if(l<=H && A[l]>A[i])largest=l;
  else largest=i;
  if(r<=H && A[r]>A[largest])largest=r;
  if(largest!=i){
    swap(A[i],A[largest]);
    maxHeapify(largest);
  }
}
int ext(){
  int maxv;
  if(H<1){
    return -INFTY;
  }
  maxv=A[1];
  A[1]=A[H--];
  maxHeapify(1);
  return maxv;
}
void incKey(int i,int key){
  if(key<A[i])return;
  A[i]=key;
  while(i>1&&A[i/2]<A[i]){
    swap(A[i],A[i/2]);
    i=i/2;
  }
}

void ins(int key){
  H++;
  A[H]=-INFTY;
  incKey(H,key);
}

int main(){
  int key;
  char com[10];
  while(1){
    scanf("%s",com);
    if(com[0]=='e' && com[1]=='n')break;
    if(com[0]=='i'){
      scanf("%d",&key);
      ins(key);
    }
    else{printf("%d\n",ext());
  }
  }
  return 0;
}

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

using namespace std;
using ll = long long;

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

  const int inf = 1e9;

  int n;
  cin >> n;
  set<int> s;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    s.insert(a);
  }

  if (s.size() % 2 == 1) {
    cout << s.size() << endl;
  } else {
    cout << s.size() - 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 8120
fun main(args: Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    var l = mutableListOf<Int>()
    for (i in 0 until n){
        var (x, y) = readLine()!!.split(" ").map { it.toInt() }
        if (y <= m) l.add(x)
    }
    var a = if(l.count() == 0) "TLE" else l.min()!!
    println(a)
}

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

#define TYPE(c)   remove_reference_t<decltype(c)>
#define REP(i, n) for(TYPE(n) i = 0; i < n; i++)
#define FOR(v, c) for(TYPE(c.begin()) v = c.begin(); v != c.end(); v++)
#define ALL(c)    c.begin(), c.end()
#define SORT(c)   sort(ALL(c))
#define RSORT(c)  sort(ALL(c), greater<TYPE(c)::value_type>())
#define UNIQUE(c) c.erase(unique(ALL(c)), c.end())

using namespace std;
using ll = long long;

constexpr int MOD  = (int)1e9 + 7;
constexpr int INF  = (int)1e9 + 1;
constexpr ll  LINF = (ll)1e18 + 1;
template<typename T> constexpr bool chmax(T& a, const T& b)
{ if(a < b) { a = b; return true; } else { return false; } }
template<typename T> constexpr bool chmin(T& a, const T& b)
{ if(b < a) { a = b; return true; } else { return false; } }
template<typename S, typename T> ostream& operator<<(ostream &os, const pair<S, T>& p)
{ return os << "(" << p.first << "," << p.second << ")"; }
ostream& operator<<(ostream &os, const string& s)
{ FOR(v, s) os << *v; return os; }
template<typename T> auto operator<<(ostream& os, const T& t)
    -> typename conditional<true, ostream&, decltype(*t.begin())>::type
{ os << "["; FOR(v, t) { if(v != t.begin()) os << ","; os << *v; } os << "]"; return os; }

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

    int X, Y;
    std::cin >> X >> Y;
    auto f = [](int x) {
                 if(x == 1){
                     return 300000;
                 }
                 else if(x == 2) {
                     return 200000;
                 }
                 else if(x == 3) {
                     return 100000;
                 }
                 else {
                     return 0;
                 }
             };
    std::cout << f(X) + f(Y) + ((X == 1 && Y == 1) ? 400000 : 0) << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define inf 10000000000000007
#define all(vec) vec.begin(),vec.end()
#define ggr getchar(); getchar();return 0;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}

int kai(int x) {
	if (x == 1)return 1;
	return kai(x - 1)*x;
}

int mod_pow(int x, int y, int moder) {
	int res = 1;
	while (y > 0) {
		if (y & 1)res = res * x%moder;
		x = x * x%moder;
		y >>= 1;
	}
	return res;
}

int a, b, c, d, e, k;


signed main() {
	cin >> a >> b >> c >> d >> e >> k;
	if (e - a > k)cout << ":(" << endl;
	else cout << "Yay!" << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"os"
	"strconv"
	"bufio"
	"strings"
)

// define
var (
	sc = bufio.NewScanner(os.Stdin)
)

func scanIntLine(len int) []int{
	arr := make([]int, len)
	for i:=0; i<len; i++{
		sc.Scan()
		tmp, err := strconv.Atoi(sc.Text())
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func scanStringLine(len int) []string{
	arr := make([]string, len)
	for i:=0; i<len; i++{
		sc.Scan()
		arr[i] = sc.Text()
	}
	return arr
}

func scanIntSplit(len int) []int{
	arr := make([]int, len)
	sc.Scan()
	for i, v := range strings.Split(sc.Text(), " "){
		tmp, err := strconv.Atoi(v)
		if err == nil{
			arr[i] = tmp
		}
	}
	return arr
}

func main(){
	var n int
	ans := 1
	fmt.Scan(&n)
	for i:=1; i<=n; i++{
		ans *= i
		ans %= 1000000007
	}
	fmt.Println(ans)
}

Measured memory_bytes: 640
a = [list(map(int,input().split())) for _ in range(3)]
N = int(input())
b = [int(input()) for _ in range(N)]


for i in range(len(b)):
  for j in range(3):
    for k in range(3):
      if a[j][k] == b[i]:
        a[j][k] = 0
      
ans = 'No'
for i in range(3):
  if a[i][0]+a[i][1]+a[i][2] == 0:
    ans = 'Yes'
    break
  if a[0][i]+a[1][i]+a[2][i] == 0:
    ans = 'Yes'
    break

if a[0][0]+a[1][1]+a[2][2] == 0 or a[0][2]+a[1][1]+a[2][0] == 0:
    ans = 'Yes'

print(ans)

Measured memory_bytes: 38256
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<vector>
using namespace std;
#define MP make_pair
#define MAX 100005
int n,m;
pair<int,int> req[MAX];
queue<int> q;
int ri;
int ans;
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>req[i].first>>req[i].second;
	}
	sort(req+1,req+1+m);
	for(int i=1;i<=m;i++){
		if(ri<=req[i].first){
			ans++;
			ri=req[i].second;
		}else{
			ri=min(ri,req[i].second);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
def f(i, K):
  if i >= K:
    return 0
  
  upper = 50
  lower = 0

  while(upper - lower > 1):
    middle = int((upper + lower) / 2)
    if i * 2**middle >= K:
      upper = middle
    else:
      lower = middle

  return upper


N, K = map(int, input().split(" "))

ans = 0.0

for i in range(1, N + 1):
  x = f(i, K)
  ans += (1 / N) * (0.5)**x
  # i * 2^x >= Kとなるxが見つかったら
  # 2^x >= K / i
  # x >= log(K / i)
  # i / K >= (1 / 2)^x
  # 1 / 10 
  # ans += (1/2)^x * (1 / N)をするのです

print(ans)



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

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")
}

fn main() {
    let n: u32 = read();
    let m: usize = read();
    let mut l = vec![0;m];
    for _ in 0..n {
        let k: u32 = read();
        for _ in 0..k {
            let a: usize = read();
            l[a-1] += 1;
        }
    }
    let mut cnt = 0;
    for i in l {
        if i == n {
            cnt += 1;
        }
    }
    println!("{}", cnt);

}


Measured memory_bytes: 4352
//↓呪文
#include<iostream>
using namespace std; // 575
class Scanner{public:Scanner(){}int nextInt(){int n;cin >> n;return n;}};
class Out{public:void println(string s){cout<<s<<'\n';}};
class System{public:Out out;};
#define String string
#define public void
#define class main
#define Main ()
#define main(n) 
#define static 
#define void 
#define new 
#define Scanner(n) Scanner()
#define System System()
// ↑呪文

// ここからJava

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt(), b = sc.nextInt(), c = sc.nextInt(), d = sc.nextInt(), e = sc.nextInt(), k = sc.nextInt();
		System.out.println(e - a <= k ? "Yay!" : ":(");
	}
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

Javaっぽく書いてみた()
*/

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> H(N);
  for (int i = 0; i < N; i++)
    cin >> H[i];
  int res = 1;
  for (int i = 1; i < N; i++) {
    bool flag = true;
    for (int j = 0; j < i; j++) {
      if (H[i] < H[j]) flag = false;
    }
    if (flag) res++;
  }
  cout << res << '\n';
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

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

        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());

        Map<Integer, Set<Integer>> map = new HashMap<>();

        for (int i = 0; i < m; i++) {
            int k = Integer.parseInt(sc.next());

            Set<Integer> set = new HashSet<>();

            for (int j = 0; j < k; j++) {
                set.add(Integer.parseInt(sc.next()) - 1);
            }

            map.put(i, set);
        }

        List<Boolean> p = new ArrayList<>();

        for (int i = 0; i < m; i++) {
            p.add(Integer.parseInt(sc.next()) == 1);
        }

        int count = 0;

        for (int i = 0; i < Math.pow(2, n); i++) {
            boolean on = true;

            for (int j = 0; j < m; j++) {
                boolean sw = false;

                for (int k : map.get(j)) {
                    sw = sw ^ ((i & (int) Math.pow(2, k)) != 0);
                }

                if (sw != p.get(j)) on = false;
            }

            if (on) count++;
        }

        System.out.println(count);
    }
}

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

int PP(vector<int> v) {
  int N = v.size();
  int pos = 1;
  while(prev_permutation(v.begin(), v.end())) {
    pos += 1;
  }
  return pos;
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N), B(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  for (int i = 0; i < N; i++) {
    cin >> B.at(i);
  }
  
  int a = PP(A);
  int b = PP(B);
  
  cout << max(a-b, b-a) << endl;
}

Measured memory_bytes: 256
//this library has many things needed for arrays, the asterisc means we get everything is inside, the dot says where is is inside, you need the ; to tell the line has ended, like in C
import java.util.*;

//the name of the main function has to be the same name of the program
//what public class mean in java: it means that other function scan also access the class. What happens if we dont make it public? Well, it stil works, but it will be visivle to code only in the same package
public class Main {
	//this is a method, it tells that it will execute the things that are inside, it takes string as args when we execute the program, it is optional. What if instead we use int? It does not work, it has to be String[] args
	public static void main(String[] args){
		//it is a class of the .util that is used to take input from the user. Why it is used as class?
		Scanner sc = new Scanner(System.in);
		// get a integer
		//nextInt is a method, it will take text and turn it into an integer. It is looking for space or line break? Yes, if it is a line break or a space it treats it the same way. How to consider it is different?
		int N = sc.nextInt();
       	int A = 0;
      	int base = 2;
		// get two integers separated with half-width break
		for (int i = 0; i <= N; i++){
       		if(Math.pow(base,i)<=N){
            	A = (int)Math.pow(base,i);
            }
          	else{
              break;
            }
            	
        }
		// output
		//prints a new line. It looks like it has to be repeated all the time System.out.println
		//so you can tell println to print an int because it is overloaded, it means it has all the methods and it will find the one that can print what you pass to it, while in c++ you have to tell what you are printing
		System.out.println(A);
	}
}



Measured memory_bytes: 23760
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    while(cin >> n, n){
        int w, h;
        cin >> w >> h;
        vector<vector<int>> v(h+1, vector<int>(w+1, 0));
        for (int i = 0; i < n; ++i) {
            int x, y;
            cin >> x >> y;
            v[y][x]++;
        }
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j <= w; ++j) {
                v[i+1][j] += v[i][j];
            }
        }
        for (int i = 0; i <= h; ++i) {
            for (int j = 0; j < w; ++j) {
                v[i][j+1] += v[i][j];
            }
        }
        int s, t;
        cin >> t >> s;
        int ans = 0;
        for (int i = 0; i <= h-s; ++i) {
            for (int j = 0; j <= w-t; ++j) {
                ans = max(ans, v[i+s][j+t]-v[i][j+t]-v[i+s][j]+v[i][j]);
            }
        }
        cout << ans << "\n";
    }
    return 0;
}



Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int cnt=0;
	int n;
	cin>>n;
	string s;
	queue <string> ab;
	queue <string> a;
	queue <string> b;
	queue <string> c;
 	for(int i=0; i<n; i++)
	{
		cin>>s;
		int len = (int)s.size();
		if(s[0] == 'B' && s[len-1] == 'A') ab.push(s);
		else if(s[0] == 'B') b.push(s);
		else if(s[len-1] == 'A') a.push(s);
		else c.push(s);
	}
	string ss;
	if(!ab.empty() && !a.empty())
	{
		ss=ss+a.front();
		a.pop();
	}
	while(!ab.empty())
	{
		ss=ss+ab.front();
		ab.pop();		
	}
//	cout<<ss<<endl;
	if(!b.empty()  && (int)ss.size() != 0)
	{
		ss=ss+b.front();
		b.pop();
	}
//	cout<<ss<<endl;
	while(!b.empty() && !a.empty())
	{
		ss=ss+a.front()+b.front();
		b.pop();
		a.pop();
	}
	while(!b.empty())
	{
		ss=ss+b.front();
		b.pop();
	}
	while(!a.empty())
	{
		ss=ss+a.front();
		a.pop();
	}
	while(!c.empty())
	{
		ss=ss+c.front();
		c.pop();
	}
//	cout<<ss<<endl;
	for(int i=0;i<(int)ss.size()-2;i++)
	{
		if(ss[i] == 'A' && ss[i+1] == 'B') cnt++;
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 1120
#include<bits/stdc++.h>
using namespace std;
int n, a[200009];
vector<std::pair<int, int> > K;

bool check(int d)
{
	K.clear();
	K.push_back(std::make_pair(0, 0));
	for (int i = 1; i <= n; ++i)
		if (a[i] <= a[i - 1])
		{
			while (K.back().first > a[i]) K.pop_back();
			for (int j = a[i]; ; --j)
			{
				if (j < 1) return false;
				int t = 1;
				if (K.back().first == j) t = 1 + K.back().second, K.pop_back();
				if (t < d)
				{
					K.push_back(make_pair(j, t));
					break;
				}
			}
		}
	return true;
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	int l = 1, r = n;
	while (l < r)
	{
		int mid = (l + r) / 2;
		if (check(mid)) r = mid;
		else l = mid + 1;
	}
	printf("%d\n", l);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    string s;
    cin>>s;
    if(s[2]==s[3]&&s[4]==s[5])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

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

using namespace std;

using ll = long long;

constexpr ll MOD = 1000000007;

#ifndef ONLINE_JUDGE
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " (" << x.first << " : " << x.second << ")" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "["; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "]"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "(" << obj.first << ", " << obj.second << ")"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print_sim_py(void) {cout << endl;}
template <class Head> void print_sim_py(Head&& head) {cout << head;print_sim_py();}
template <class Head, class... Tail> void print_sim_py(Head&& head, Tail&&... tail) {cout << head << " ";print_sim_py(forward<Tail>(tail)...);}

#define print(...) print_sim_py(__VA_ARGS__);
#else
#define print(...);
#endif

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

    ll x,y;
    
    cin >> x >> y;

    ll a,b;

    for(a=0; a<=50; a++){
        for(b=0; b<=25; b++){
            if(2*a+4*b==y && a+b==x){
                cout << "Yes\n";
                return 0;
            }
        }
    }

    cout << "No\n";

    return 0;
}

Measured memory_bytes: 3648
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
#include <iomanip>
//#include <vector>
//#include <string>
//#include <algorithm>
//#include <functional>
#include <cmath>

using namespace std;

int main(){

	double a, b, c, d, h, C, S, L;

	cin >> a >> b >> C;

	h = b * sin(C * M_PI / 180);
	d = b * cos(C * M_PI / 180);
	c = sqrt(pow(a - d, 2) + pow(h, 2));
	S = a * h / 2;
	L = a + b + c;

	printf("%.6f\n%.6f\n%.6f\n", S, L, h);


	return 0;
}

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

typedef pair<int, int> P;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin, (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

int main() {
  ll H;
  ll sum = 0;
  ll cnt = 1;
  cin >> H;
  while (H != 0) {
    H /= 2;
    sum += cnt;
    cnt *= 2;
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
from collections import OrderedDict
while True:
    n = int(input())
    if n == 0:
        break    
    dic = OrderedDict()
    for i in range(n):
        line = input().split()
        key = line[0]
        sales = int(line[1]) * int(line[2])
        if key in dic:
            dic[key] += sales
        else:
            dic[key] = sales
    res = [k for k in dic if dic[k] >= 1000000]
    if len(res) == 0:
        print("NA")
    else:
        [print(k) for k in res]

Measured memory_bytes: 8324
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		int[] array1 = new int[n];
		int[] array2 = new int[n];
		for(int i=0;i<n;i++) {
			array1[i] = sc.nextInt();
			array2[i] = sc.nextInt();
		}
		sc.close();

		boolean flag = false;
		int ans = 0;
		for(int i=0;i<n;i++) {
			int d1 = array1[i];
			int d2 = array2[i];
			if(d1==d2) {
				flag = true;
				ans = ans + 1;
			}else {
				flag = false;
				ans = 0;
			}

			if(ans==3) {
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");



	}
}


Measured memory_bytes: 36096
N, K = map(int, input().split())
from collections import defaultdict
D = defaultdict(int)
for _ in range(N):
    a, b = map(int, input().split())
    D[a] += b
for k,v in sorted(D.items(), key=lambda x:x[0]):
    K -= v
    if K <= 0:
        print(k)
        exit()

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
// typedef __int128 int128_t;
// typedef unsigned __int128 uint128_t;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<char, int> pci;
typedef tuple<int, int, int> ti3;
typedef tuple<ll, ll, ll> tl3;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;

#define ff          first
#define ss          second

#define pb(x)       push_back(x)
#define ppb()       pop_back()
#define pf(x)       push_front(x)
#define ppf()       pop_front()
#define mp(x,y)     make_pair(x, y)
#define all(v)     begin(v),end(v)
#define gcd(x, y)   __gcd(x, y)

// pbds and ordered set
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <class T, class cmp = less<T> >
// using ordered_set = tree<T, null_type, cmp, rb_tree_tag, tree_order_statistics_node_update>;

// for fast I/O
#define endl '\n'
#define FASTIO() ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

const int N = 2e5;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0);
const ll INF = INT_MAX-1;

int main() {
  FASTIO();

  int h1, m1, h2, m2, k;
  cin >> h1 >> m1 >> h2 >> m2 >> k;

  int st = h1 * 60 + m1;
  int en = h2 * 60 + m2;

  int ans = en - st - k;

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



Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define SUM(v) accumulate(v.begin(),v.end(),lli(0))
#define rev(n,d) for(int i=n;i>=d;i--)
#define FOR0(n) for(int i=0;i<n;i++)
#define FOR(a,n) for(int i=a;i<n;i++)
#define FORQ(a,n) for(int i=a;i<=n;i++)
#define inf 1000000009
#define inff 0x3f3f3f3f
#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define mem(ar,x) memset(ar,x,sizeof ar)
#define present(container, element) (container.find(element) != container.end())
#define max3(a,b,c) return (lli(a)>lli(b)?(lli(a)>lli(c)?a:c):(lli(b)>lli(c)?b:c))
#define max4(a,b,c,d) return (max3(a,b,c)>lli(d)?(max3(a,b,c)):d)
#define min3(a,b,c) return (lli(a)<lli(b)?(lli(a)<lli(c)?a:c):(lli(b)<lli(c)?b:c))
#define min4(a,b,c,d) return (max3(a,b,c)<lli(d)?(max3(a,b,c)):d)
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<int,pii>ppii;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<pii>vpii;
const int N=100005;
int dr8[]={0,0,1,-1,1,1,-1,-1};
int dc8[]={1,-1,0,0,-1,1,-1,1};
int dr4[]={0,1,-1,0};
int dc4[]={1,0,0,-1};
int main(){
	fast
	int n;
	cin>>n;
	int an=0,x;
	FORQ(1,n){
		cin>>x;
		if(i%2&&x%2) an++;
	}
	cout<<an;
}



Measured memory_bytes: 3660
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
    int n;
    while(scanf("%d",&n)==1)
    {
        if(n>999)
            printf("ABD\n");
        else
            printf("ABC\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n)     for(int i = 0;i < n;i++)
#define REPR(i, n)    for(int i = n;i >= 0;i--)
#define FOR(i, m, n)  for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.begin(), v.end(),greater<int>());
#define ALL(X) (X).begin(),(X).end()
#define INF 99999999
#define M_PI 3.14159265358979323846
#define MOD 1000000007

#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 0};
int dy[]={0, 1, 0, -1, 0};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
const int NIL = -1;
static mt19937 _g(time(nullptr));
 
std::string pad(int num){ char buffer[4]; std::snprintf(buffer, sizeof(buffer), "%03d", num); return buffer;}
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) os << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }


int N,M;
int S,T;
map<int,vector<int> > toList;

void input(){
  #ifdef __LOCAL
      fs::path p = __FILE__;
      fs::path input,output;
      input = output = p.parent_path();
      input += string("/input/") + string(p.stem()) + string(".txt");
      output += string("/output/") + string(p.stem()) + string(".txt");
      freopen(input.c_str(), "r", stdin);
      freopen(output.c_str(), "w", stdout);
  #endif

  fast_io();
  cin >> N >> M;
  for (int i = 0;i < M;i++)
  {
    int a,b;
    cin >> a >> b;
    a--;b--;
    toList[a].push_back(b);
  }
  cin >> S >> T;
  S--;
  T--;
}

int solve(){
  vector<vector<bool>> visited(N,vector<bool>(3,false));
  queue<pii> q;
  q.push({S,0});
  visited[S][0]=true;;
  int now,dist,next_dist;
  while(!q.empty()){
    tie(now,dist) = q.front();
    q.pop();
    for(auto next:toList[now]){
      next_dist = dist+1;
      if(next==T && next_dist%3==0) {cout << next_dist/3 << endl; return 0;}
      if(visited[next][next_dist%3]) continue;
      visited[next][next_dist%3]=true;
      q.push({next,next_dist});
    }

  }
  cout << -1 << endl;
  return 0;
}

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


Measured memory_bytes: 18304
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>

using namespace std;

//using
using VI = vector<int>;
using VVI = vector<VI>;
using VS = vector<string>;
using PII = pair<int, int>;
using LL = long long;

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  for(int i=0;i<(n);i++)

//constant
const int INF = 1 << 29;
const double EPS = 1e-10;
const double PI = acos(-1.0);

//debug
#define dump(x)  cout << #x << " = " << (x) << endl;

int main() {
    int A, B, C, X, Y;
    int ans = 0;
    cin >> A >> B >> C >> X >> Y;
    if (X < Y) {
        ans += C*X*2;
        ans += B*(Y-X);
    }else {
        ans += C*Y*2;
        ans += A*(X-Y);
    }
    ans = min(ans, X*A+Y*B);
    ans = min(ans, max(X, Y)*C*2);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(s) cout << s << endl;
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
   int a,b,c,d; cin>>a>>b>>c>>d;
   cout << (a + b == c + d ? "Balanced" : (a + b > c + d ? "Left" : "Right")) << endl;
}


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

int main() {
    string s;
    cin >> s;

    int T;
    cin >> T;
    while (T--) {
        string Q;
        int a, b;
        cin >> Q >> a >> b;

        if (Q == "replace") {
            string t;
            cin >> t;

            for (int i = a; i <= b; ++i)
                s[i] = t[i - a];
        }

        else if (Q == "reverse") {
            reverse(s.begin() + a, s.begin() + b + 1);
        }

        else {
            for (int i = a; i <= b; ++i)
                cout << s[i];
            cout << endl;
        }
    }

    return 0;
}


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

int main () {
  string s;
  cin >> s;
  vector<char> p1(s.size());
  vector<char> p2(s.size());
  for (int i = 0; i < s.size(); i++) {
    if (i%2 == 0){
      p1.at(i) = '0';
      p2.at(i) = '1';
    }
    else {
      p2.at(i) = '0';
      p1.at(i) = '1';
    }
  }   
  int diff1 = 0;
  int diff2 = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) != p1.at(i)) diff1++;
    if (s.at(i) != p2.at(i)) diff2++;
  }
  cout << min(diff1,diff2) << endl;
}

Measured memory_bytes: 512
x, num_of_nums = map(int, input().split(' '))

if num_of_nums == 0:
    print(x)
    exit()
    
nums = set(map(int, input().split(' ')))

diff = 0

while True:
    n1 = x - diff
    n2 = x + diff

    if n1 not in nums:
        print(n1)
        break
    
    if n2 not in nums:
        print(n2)
        break
    
    diff += 1

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

const int MAX_N = 16;
int N;
int A[MAX_N][MAX_N][2];
int cur[MAX_N];

void solve()
{
	int ans = 0;
	for(int f=0;f<(1<<N);++f){
		memset(cur,-1,sizeof(cur));
		bool ok = true;
		for(int i=0;i<N;++i)if(f>>i&1){
			for(int j=1;j<=A[i][0][0];++j){
				if(A[i][j][1]){
				    if(!(f>>(A[i][j][0]-1)&1)){
				        ok=false;
				        goto out;
				    }
					if(cur[A[i][j][0]] == 0){
						ok=false;
						goto out;
					}
					cur[A[i][j][0]] = 1;
				}else{
					if(f>>(A[i][j][0]-1)&1){
						ok=false;
						goto out;
					}
				}
			}
		}
		out:
		if(ok){
			ans=max(ans, __builtin_popcount(f));
		}
	}
	cout<<ans<<'\n';
}

int main()
{
	cin >> N;
	for(int i=0;i<N;++i){
		cin >> A[i][0][0];
		for(int j=1;j<=A[i][0][0];++j){
			cin >> A[i][j][0] >> A[i][j][1];
		}
	}
	solve();
	return 0;
}

Measured memory_bytes: 3628
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
s=0
for i in range(n-1):
  if (a[i+1]-a[i])==1:
    s+=c[a[i]-1]
print(s+sum(b))

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

int main(){
  int i,j,cnt=0;
  int n,k;
  string s;
  cin>>n;
  cin>>s;
  cin>>k;
  char c[n];
  for(i=0;i<n;i++){
    if(s[i]!=s[k-1])c[i]='*';
    else c[i]=s[i];
  }
  for(i=0;i<n;i++)cout<<c[i];
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
long long b[110000];
long long gz[550];
double eps=1e-9;
int main(){
	int a;
	while(scanf("%d",&a),a){
		long double A=1;
		int sz=0;
		for(int i=0;i<(a+1)*a/2;i++){
			scanf("%lld",b+i);
			if(b[i]%2==0){
				A*=pow(b[i],1.0/a);
				gz[sz++]=b[i];
			}else A*=pow(b[i],-1.0/a/(a-1));
		}
		long long gs=(long long)(A+0.5);
		printf("%lld\n",gs);
		std::sort(gz,gz+a);
		for(int i=0;i<a;i++){
			if(i)printf(" ");
			printf("%lld",gz[i]/gs);
		}
		printf("\n");
	}
}

Measured memory_bytes: 1424
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 X = sc.nextInt();
		sc.close();
		
		int nyannyan = X - A;
		if(nyannyan < 0 || B < nyannyan)
			System.out.println("NO");
		else
			System.out.println("YES");
	}
}


Measured memory_bytes: 23124
#include <iostream>
#include <vector>
#include<algorithm>
#define ff(i,m,n) for(int i=m;i<n;i++)
#define i64 int64_t
using namespace std;

int main() {
	int a;
	cin >> a;
	if (a % 2 != 0) {
		cout << "No" << endl;
		return 0;
	}
	string b;
	cin >> b;
	ff(i, 0, a / 2) {
		if (b[i] != b[i + (a / 2)]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main() {
  int N, K;
  cin >> N >> K;
  ll x[N];
  for (int i = 0; i < N; i++) cin >> x[i];
  ll ans = 10000000000;

  if (K == 1) {
    for (int i = 0; i < N; i++) ans = min(ans, x[i]);
    cout << ans << endl;
    return 0;
  }

  if (N == 1) {
    cout << x[0] << endl;
    return 0;
  }

  for (int i = 0; i < N; i++) {
    if (i + K > N) break;
    ll sum, l = x[i], r = x[i + K - 1];
    sum = min(abs(l) + abs(r - l), abs(r) + abs(r - l));
    ans = min(sum, ans);
  }

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

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <cmath>

typedef long long ll;

#define debug(x) cerr << #x << ": " << x << "\n";
#define rep(i,n) for(int i=0; i<n; i++)

using namespace std;

int main(){
  ll a;
  long double b;
  cin >> a >> b;
  cout << ll(a*b) << endl;
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
int main(){
    string S;
    cin >> S;
    vector<int> sa = suffix_array(S);
    vector<int> lcp = lcp_array(S, sa);
    long long N = (long long)S.size();
    cout << N * (N + 1) / 2 - accumulate(lcp.begin(), lcp.end(), 0LL) << endl;
}

Measured memory_bytes: 15600
n,a,b,c,d,e=[int(input()) for i in range(6)]
A=[a,b,c,d,e]
if n<=min(A):
  print(5)
else:
  if n%min(A)==0:
    ans=n//min(A)+4
  else:
    ans=n//min(A)+5
  print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    ll A[100010];
    cin >> N;
    rep(i,0,N) cin >> A[i];
    ll cnt = 0;
    rep(i,0,N){
        if(A[i] % 2 == 1) cnt++;
    }
    if(cnt % 2 == 0){
        print("YES");
    }else{
        print("NO");
    }

}

Measured memory_bytes: 1024
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
def main():
    s = tuple(input())
    r = 0
    s_len = len(s)
    for i1 in range(s_len):
        for i2 in range(i1 + 1, s_len + 1):
            if all([c in ('A', 'T', 'C', 'G') for c in s[i1:i2]]):
                r = max(r, i2 - i1)
    print(r)

if __name__ == '__main__':
    main()

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

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

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

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

int main(){
  int N, Q; cin >> N >> Q;
  vector <int> graph[N];
  for (int i = 0; i < N - 1; i++){
    int A, B; cin >> A >> B;
    A--; B--;
    graph[A].push_back(B);
    graph[B].push_back(A);
  }
  
  vector <ll> ans(N);
  for (int i = 0; i < Q; i++){
    int P; ll X; cin >> P >> X;
    P--; ans[P] += X;
  }
  
  vector <bool> visited(N);
  queue <int> que; que.push(0); visited[0] = true;

  while (!que.empty()){
    int Q = que.front(); que.pop();

    for (int i = 0; i < graph[Q].size(); i++){
      int next = graph[Q][i];
      if (visited[next] == false){
        visited[next] = true;
        ans[next] += ans[Q];
        que.push(next);
      }
    }
  }
  
  for (int i = 0; i < N; i++){
    cout << ans[i];
    if (i == N - 1) cout << endl;
    else cout << " ";
  }
  

  return 0;
}


Measured memory_bytes: 16372
#include <iostream>
#include <string>
using namespace std;
 
 
int main(){
  int n, n1, n2, n3, n4;
  
  cin>> n;
  
  n1=n/1000;
  n2=(n/100)%10;
  n3=(n/10)%10;
  n4=n%10;
  
  if(n1==n2 || n2==n3 || n3==n4) cout<< "Bad" << endl;
  else cout<< "Good" << endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
#define code                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(0);
// #define int long long
#define MM(a, b) memset(a, b, sizeof(a))
const ll MOD = 1000000007;
using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1)
{
	cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args)
{
	const char *comma = strchr(names + 1, ',');
	cout.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}


struct ds
{
	/* data */
	int a,b,c;
};

bool comp(ds x,ds y){
	if(x.a==y.a){
		return x.b<y.b;
	}
	return x.a<y.a;
}

int32_t main()
{
	code;
	pair<string,int> s;
	cin>>s.first;
	pair<string,int> t;
	cin>>t.first;
	cin>>s.second>>t.second;
	string u; cin>>u;
	if(u==s.first){
		cout<<s.second-1<<" "<<t.second<<endl;
	}
	else{
		cout<<s.second<<" "<<t.second-1<<endl;
	}
	
	
	
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#define shosu(x) fixed<<setprecision(x)
using namespace std;

int n,ans=0;
vector<int> num;

int main(){
	cin>>n;
	for(int i=0;i<2*n;i++){
		int tmp;
		cin>>tmp;
		num.push_back(tmp);
	}
	sort(num.begin(),num.end());
	for(int i=0;i<2*n;i+=2){
		ans+=num[i];
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
from math import ceil
h, n = map(int, input().split())
data = []
for i in range(n):
    a, b = map(int, input().split())
    data.append([a, b])

max_a = max(a for a, b in data)
dp = [0] * (h + max_a)
for i in range(h + max_a):
    dp[i] = min(dp[i - a] + b for a, b in data)

print(min(dp[h - 1: ])) 


Measured memory_bytes: 9480
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<P,int> PP;
struct data{
	short v[3];
	data(){}
};

short dx[5]={0,1,-1,0,0};
short dy[5]={0,0,0,1,-1};

int n,w,h;
short fie[14][14];
short sx[3],sy[3];
short gx[3],gy[3];
int num[14][14];
short dp[150][150][150];
int to[150][5];
short move[3]={5,25,125};

int solve(){
	queue<data> que;
	data st;
	for(int i=0;i<3;i++){
		if(i<n){
			st.v[i]=num[sy[i]][sx[i]];
		}else{
			st.v[i]=0;
		}
	}
	memset(dp,-1,sizeof(dp));
	que.push(st);
	dp[st.v[0]][st.v[1]][st.v[2]]=0;
	while(que.size()){
		data d=que.front();
		que.pop();
		for(int i=1;i<move[n-1];i++){
			if(false){
				bye:
				i++;
				if(i==move[n-1])break;
			}
			data nd=d;
			int pi=i;
			for(int j=0;j<n;j++){
				nd.v[j]=to[d.v[j]][pi%5];
				if(nd.v[j]==-1){
					goto bye;
				}
				pi/=5;
			}
			for(int j=0;j<n;j++){
				for(int k=j+1;k<n;k++){
					if(d.v[j]==nd.v[k] && d.v[k]==nd.v[j]){
						goto bye;
					}
					if(nd.v[j]==nd.v[k]){
						goto bye;
					}
				}
			}
			if(dp[nd.v[0]][nd.v[1]][nd.v[2]]==-1){
				bool goal=true;
				for(int j=0;j<n;j++){
					if(nd.v[j]!=num[gy[j]][gx[j]])goal=false;
				}
				if(goal){
					return dp[d.v[0]][d.v[1]][d.v[2]]+1;
				}
				dp[nd.v[0]][nd.v[1]][nd.v[2]]=dp[d.v[0]][d.v[1]][d.v[2]]+1;
				que.push(nd);
			}
		}
	}
}

int main(void){
	while(1){
		scanf("%d%d%d%*c",&w,&h,&n);
		if(w==0 && h==0 && n==0)break;
		memset(fie,0,sizeof(fie));
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				char str;
				scanf("%c",&str);
				if(i==0 || j==0 || i==h-1 || j==w-1)continue;
				if(str=='#'){
					fie[i-1][j-1]=-1;
				}
				if(str>='A' && str<='C'){
					sx[(str-'A')]=j-1;
					sy[(str-'A')]=i-1;
				}
				if(str>='a' && str<='c'){
					gx[(str-'a')]=j-1;
					gy[(str-'a')]=i-1;
				}
			}
			scanf("%*c");
		}
		w-=2;
		h-=2;
		int all=0;
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(fie[i][j]==0){
					num[i][j]=all++;
				}
			}
		}
		memset(to,-1,sizeof(to));
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(fie[i][j]==0){
					for(int k=0;k<5;k++){
						int nx=j+dx[k],ny=i+dy[k];
						if(nx<0 || nx>=w || ny<0 || ny>=h)to[num[i][j]][k]=-1;
						else{
							if(fie[ny][nx]==-1){
								to[num[i][j]][k]=-1;
							}else{
								to[num[i][j]][k]=num[ny][nx];
							}
						}
					}
				}
			}
		}
		printf("%d\n",solve());
	}
	return 0;
}

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


int main() {

    int N; cin >> N;
    vector<int> v(N);
    for (int i = 0; i < N; ++i) {
        cin >> v.at(i);
    }
    int ans = 0;
    for (int i = 0; i < N-1; ++i) {
        for (int j = i+1; j < N; ++j) {
            ans += v.at(i) * v.at(j);
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
from math import gcd

class SegTree():
    def segfunc(self, x, y):
        return gcd(x, y)

    def __init__(self, ide, init_val):
        n = len(init_val)
        self.ide_ele = ide
        self.num = 2**(n-1).bit_length()
        self.seg = [self.ide_ele] * 2 * self.num
        for i in range(n):
            self.seg[i+self.num-1] = init_val[i]    
        for i in range(self.num-2,-1,-1):
            self.seg[i] = self.segfunc(self.seg[2*i+1],self.seg[2*i+2]) 
    def update(self, idx, val):
        idx += self.num-1
        self.seg[idx] = val
        while idx:
            idx = (idx-1)//2
            self.seg[idx] = self.segfunc(self.seg[idx*2+1], self.seg[idx*2+2])
    def query(self, begin, end):
        if end <= begin:
            return self.ide_ele
        begin += self.num-1
        end += self.num-2
        res = self.ide_ele
        while begin + 1 < end:
            if begin&1 == 0:
                res = self.segfunc(res, self.seg[begin])
            if end&1 == 1:
                res = self.segfunc(res, self.seg[end])
                end -= 1
            begin = begin//2
            end = (end-1)//2
        if begin == end:
            res = self.segfunc(res, self.seg[begin])
        else:
            res = self.segfunc(self.segfunc(res, self.seg[begin]), self.seg[end])
        return res

def main():
    n = int(input())
    a = list(map(int, input().split()))
    seg = SegTree(0, a)
    ans = 1
    for i in range(n):
        ans = max(ans, gcd(seg.query(0, i), seg.query(i+1, n)))
    print(ans)

if __name__ == "__main__":
    main()

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

using namespace std;

int A, B, C;
int X;
int solve(){
int ans = 0;
for(int i = 0; i <= A; ++i){
for(int j = 0; j <= B; ++j){
for(int k = 0; k <= C; ++k){
int tmp = i * 500 + j * 100 + k * 50;
if(tmp == X) ans++;
}
}
}
return ans;
}
int main()
{

   scanf("%d%d%d%d", &A, &B, &C, &X);
int ans = solve();
printf("%d\n", ans);

    /*
    int n,a=0,b=0,sum=0;
    scanf("%d",&n);
    int x[2][n];
    for(int i=0;i<2;i++)
    {
        for(int j=0;j<n;j++)
            scanf("%d",&x[i][j]);
    }
    while(x[a+1][b]<=x[a][b+1]&&b<n)
    {
        cout<<" b = "<<b<<"  "<<x[a][b+1]<<"  ??  "<<x[a+1][b]<<endl;
        sum+=x[a][b];
        cout<<sum<<endl;
        b++;
    }
    sum+=x[a][b];
    cout<<sum<<endl;
    for(int i=b;i<n;i++)
    {
        cout<<"b = "<<i<<"  "<<x[1][i]<<endl;
        sum+=x[1][i];
    }


    printf("%d",sum);
    */
    return 0;
}


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

int main(){
int N,ima,now;
  cin >> N;
int a[N];
  for(int i = 0;i < N;i++){
  cin >> a[i];
  }

ima = 1;
int cnt = 0;  
  for(int i = 0;i < N;i++){
    if(ima == 2){
    cout << cnt << endl;
      break;
    }
    
  else if(a[ima - 1] == 0){
    cout << -1 << endl;
    break;
  }  
    else{
      now = ima;
      ima = a[ima - 1];
      a[now - 1] = 0;
      cnt++;
    }
  
  }
  
  return 0;
}

Measured memory_bytes: 768
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

ll check(ll a, ll b, ll digit){
  ll div = pow(2,digit);
  ll cnt = 0;
  if(div - (a%div) + a <= b){
    if(a%(2*div) >= div) cnt += (div-(a%div))%2;
    if(b%(2*div) >= div) cnt += (b%div+1)%2;
    cnt %= 2;
  }else{
    if(a%(2*div) >= div) cnt += (b-a+1)%2;
  }
  return cnt;
}


int main(){
  ll a,b;
  cin >> a >> b;
  ll digit = 0;
  ll memo = b;
  while(memo > 0){
    memo /= 2;
    digit++;
  }
  ll ans = 0;
  if(a%2==0){
    if(((b-a+1)/2)%2 != 0) ans++;
  }else{
    if(((b-a+1+1)/2)%2 != 0) ans++;
  }
  memo = 2;
  for(int i = 1; i < digit; i++){
    ans += check(a,b,i)*memo;
    memo *= 2;
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B;
  int TapNumber = 1;
  int PlugNumber = A;
  
  //if (B == 1) cout << 0 << endl;
  //else if (A >= B) cout << 1 << endl;
  //else {

  while (PlugNumber < B) {
    PlugNumber += A - 1;
    TapNumber++;
  }
    
  if (B == 1) cout << 0 << endl;
  else cout << TapNumber << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  string table[256],man[256];
  int n,m;
  bool b=true;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>table[i];
  }
  cin>>m;
  for(int i=0;i<m;i++){
    cin>>man[i];
    for(int j=0;j<n;j++){
      if(man[i]==table[j] && b){
	cout<<"Opened"<<" "<<"by"<<" "<<table[j]<<endl;
	b=false;
	break;
      }else if(man[i]==table[j] && !b){
	cout<<"Closed"<<" "<<"by"<<" "<<table[j]<<endl;
	b=true;
	break;
      }
      if(j==n-1) cout<<"Unknown"<<" "<<man[i]<<endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3208
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		long H = sc.nextInt();
		long W = sc.nextInt();

		sc.close();

		if (H == 1 || W == 1) {
			out.println(1);
			return;
		}

		out.println((H * W + 1) / 2);

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}
}


Measured memory_bytes: 23764