akhauriyash/Code-Regression huggingface dataset:
trial = int(input())
for t in range(trial):
    housecnt,elec = (int(n) for n in input().split(" "))
    house = [int(n) for n in input().split(" ")]
    maxlist = []
    for h in range(housecnt-1):
        maxlist.append(house[h+1]-house[h])
    maxlist.sort()
    for p in range(min(housecnt-1,elec-1)):
        maxlist.pop()
    print(sum(maxlist))

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define rep(i , n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
int main (){
    int N;
    string S;
    cin >> N >> S;
    int t = 0;
    for(int i = 1; i < N - 1; i++){
        vector<int> A(26), B(26);
        int j = 0;
        for(; j <= i; j++){
            A[S[j] - 'a']++;
        }
        for(; j < N; j++){
            B[S[j] - 'a']++;
        } 
        int k = 0;
        for(int j = 0; j < 26; j++){
            if(A[j] > 0 && B[j] > 0){
                k++;
            }
        }
        t = max(t, k);
    }
    cout << t << endl;
}

Measured memory_bytes: 3620
import numpy as np
import sys
buf = sys.stdin.buffer
N = int(buf.readline())
L = list(input())

tE = L.count("E")
tW = N-tE
ce,cw = 0,0
ans = 3*(10**5)
for i in range(N):
    if L[i] == "E":
        ce +=1
    elif L[i] == "W":
        cw +=1
    if L[i] == "E":
        ans = min(ans,cw+(tE-ce))
    elif L[i] == "W":
      
        ans = min(ans,cw-1+(tE-ce))
print(ans)

Measured memory_bytes: 17060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;
const double PI = acos(-1);

int main() {
    int a, b, h; cin >> a >> b >> h;
    int area = (a + b) * h / 2;
    cout << area << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
#include <list>
#include <iomanip>
#include <cctype>

using namespace std;

#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979


void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}

Int gcd(Int a, Int b) {
	return b != 0 ? gcd(b, a % b) : a;
}
Int lcm(Int a, Int b) {
	return a * b / gcd(a, b);
}

bool comp(const string a, const string b) {
	return a.length() < b.length();
}

bool integer(double num) {
	return floor(num) == num;
}

string gen(int num) {
	string str="";
	for (int i = 0; i < num; i++) str += ".";
	return str;
}

int main() {
	int n; cin >> n;
	vector<int> a(n);

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	cout << a[a.size() - 1] - a[0];

	cout << endl;
	return 0;
}

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

bool is_sosu(int n){
	if(n==2){
		return true;
	}
	
	for(int i = 2; i < n; i++)
	{
		if(n % i == 0){
			return false;
		}
	}
	return true;
}
int main(){

	int n;
	int max_val = 55555;
	cin >> n;

	vector< int > ans;
	for(int i = 2; i <= max_val; i++)
	{
		if(ans.size() == n) break;
		if(is_sosu(i) && i%5==1){
			ans.push_back(i);
		}
	}
	
	
	for(int i = 0; i < ans.size()-1; i++)
	{
		cout << ans[i] << " ";
	}
	cout << ans[ans.size()-1] << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>

#define INF (1<<29)
#define max_n 10000

using namespace std;

struct node_t{

  node_t *pp,*lp,*rp;
  int id,val,mini,minId,lazy;

  node_t(int id,int v):id(id),val(v){
    pp=lp=rp=NULL; lazy=0; update();
  }
   
  inline void update(){
    mini=val,minId=id;
    if(lp && mini>lp->mini)mini=lp->mini,minId=lp->minId;
    if(rp && mini>=rp->mini)mini=rp->mini,minId=rp->minId;
  }
   
  inline void apply(int v){ lazy+=v, val+=v, mini+=v; }
   
  inline void push(){
    if(lp)lp->apply(lazy);
    if(rp)rp->apply(lazy);
    lazy=0;
  }
 
  bool is_root(){
    return !pp || (pp->lp != this && pp->rp != this);
  }
  
  void rotr(){
    node_t *q=pp,*r=q->pp;
    q->push(),push();
    if((q->lp=rp))rp->pp=q;
    rp=q;q->pp=this;
    if((pp=r)){
      if(r->lp==q)r->lp=this;
      if(r->rp==q)r->rp=this;
    }
    q->update();
  }

  void rotl(){
    node_t *q=pp,*r=q->pp;
    q->push(),push();
    if((q->rp=lp))lp->pp=q;
    lp=q;q->pp=this;
    if((pp=r)){
      if(r->lp==q)r->lp=this;
      if(r->rp==q)r->rp=this;
    }
    q->update();
  }

  void splay(){
    while(!is_root()){
      node_t *q=pp;
      if(q->is_root()){
	if(q->lp==this)rotr();
	else rotl();
      } else {
	node_t *r=q->pp;
	if(r->lp==q){
	  if(q->lp==this){q->rotr();rotr();}
	  else {rotl();rotr();}
	} else {
	  if(q->rp==this){q->rotl();rotl();}
	  else {rotr();rotl();}
	}
      }
    }
    push();
    update();
  }
};

node_t *expose(node_t *x){
  node_t *rp=NULL;
  for(node_t *p=x;p;p=p->pp){
    p->splay();
    p->rp=rp;
    p->update();
    rp=p;
  }
  x->splay();
  //return x;
  return rp;
}

node_t *find_root(node_t *x){
  expose(x);
  while(x->lp)x=x->lp;
  return x;
}

void cut(node_t *c){
  expose(c);
  node_t *p=c->lp;
  c->lp=NULL;
  p->pp=NULL;
  c->val=INF;
}

void link(node_t *c,node_t *p){
  expose(c);
  expose(p);
  c->pp=p;
  p->rp=c;
  c->update();
}

int minId(node_t *x){expose(x); return x->minId;}
void add(node_t *x,int val){ expose(x); x->apply(val); }

node_t *LCA(node_t *x,node_t* y){
  expose(x);
  return expose(y);
}

node_t *node[100001];

int main(void){
  int n;
  cin >> n;
  
  for(int i=0;i<n;i++)node[i]=new node_t(i,0);
  for(int i=0;i<n;i++){
    int k,t;
    cin >> k;
    for(int j=0;j<k;j++){
      cin >> t;
      link(node[t],node[i]);
    }
  }

  int q;
  cin >> q;
  for(int i=0;i<q;i++){
    int u,v;
    cin >> u >> v;
    cout << LCA(node[u],node[v])->id << endl;
  }
  
  return 0;
}

Measured memory_bytes: 8220
N = int(input())
a = map(int,input().split())
dic={}

ans=0
for i in a:
	dic.setdefault(i,0)
	dic[i]+=1
for a,b in dic.items():	
	if b-a>=0:
		ans += b-a
	else:
		ans += b
print(ans)


Measured memory_bytes: 23292
import itertools

n=int(input())

l = list(map(int,input().split()))

count=0

for i in range(len(l)-2):
    for j in range(i+1,len(l)-1):
        for k in range(j+1,len(l)):
            #print(i,j,k)
            a=l[i]
            b=l[j]
            c=l[k]
            if abs(a-b)<c and c<a+b:
                if a!=b and b!=c and c!=a:
                    count+=1

print(count)

Measured memory_bytes: 9200
arr = []
arr.append(int(input()))
arr.append(int(input()))
arr.append(int(input()))
arr.append(int(input()))
arr.append(int(input()))

y = []
for i in range(len(arr)):
    next_time = ((arr[i] + 10) // 10) * 10
    diff = next_time - arr[i]
    if diff == 10:
        y.append([arr[i], 0])
    else:
        y.append([arr[i], diff])

y.sort(key=lambda x: -x[1])

ans = 0
for i in range(len(y)):
    if i == 0:
        ans += y[i][0]
    else:
        ans += y[i][0] + y[i][1]

print(ans)

Measured memory_bytes: 3064
<?php
$n=fgets(STDIN);
$a=fgets(STDIN);
$row = explode(" ", $a);
$counter = 0;
$highest = 0;
for($i=0;$i<$n;$i++){
  if($i===0 or ($highest <= $row[$i])){
    $highest = $row[$i];
    $counter++;
  }else{
  }
}
echo $counter;

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

int n;

char InputEnter(int num, int no) {
    char res;
    if(num == 1) {
        no %= 5;
        if(no == 0) res = '.';
        else if(no == 1) res = ',';
        else if(no == 2) res = '!';
        else if(no == 3) res ='?';
        else res = ' ';
    }else if(num == 2) {
        no %= 3;
        if(no == 0) res = 'a';
        else if(no == 1) res = 'b';
        else res = 'c';
    }else if(num == 3) {
        no %= 3;
        if(no == 0) res = 'd';
        else if(no == 1) res = 'e';
        else res = 'f';
    }else if(num == 4) {
        no %= 3;
        if(no == 0) res = 'g';
        else if(no == 1) res = 'h';
        else res = 'i';
    }else if(num == 5) {
        no %= 3;
        if(no == 0) res = 'j';
        else if(no == 1) res = 'k';
        else res = 'l';
    }else if(num == 6) {
        no %= 3;
        if(no == 0) res = 'm';
        else if(no == 1) res = 'n';
        else res = 'o';
    }else if(num == 7) {
        no %= 4;
        if(no == 0) res = 'p';
        else if(no == 1) res = 'q';
        else if(no == 2) res = 'r';
        else res = 's';
    }else if(num == 8) {
        no %= 3;
        if(no == 0) res = 't';
        else if(no == 1) res = 'u';
        else res = 'v';
    }else if(num == 9) {
        no %= 4;
        if(no == 0) res = 'w';
        else if(no == 1) res = 'x';
        else if(no == 2) res = 'y';
        else res = 'z';
    }
    return res;
}

int main() {
    cin >> n;
    while(n--) {
        string s; cin >> s;
        int slen = s.length();
        vector<char> ans;
        int cc = 0;
        int cno = 0;
        for(int i = 0; i < slen; ++i) {
            int ch = s[i] - '0';
            if(ch == 0) {
                if(cc == 0) continue;
                ans.emplace_back(InputEnter(cno, cc-1));
                cc = 0;
            }else {
                cno = ch;
                cc++;
            }
        }
        for(int i = 0; i < (int)ans.size(); ++i) {
            cout << ans[i];
        }
        cout << endl;
    }
}


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

int main(){
    stack<int> cars;
    int n;
    while(cin >> n){
        if(n == 0){
            cout << cars.top() << endl;
            cars.pop();
        }else{
            cars.push(n);
        }
    }
    
    return 0;
}
    

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const ll MOD = 1000000007;
int main() {
  int N, A, B;
  cin >> N >> A >> B;
  cout << min(A, B) << " " << max(0, A + B - N) << endl;
}

Measured memory_bytes: 3572
#include <stdio.h>
int main(){
    int a,b,c,d;
    scanf("%d%d%d%d",&a,&b,&c,&d);
    int i,cnt=0;
    for(i=0;i<100;i++)
        if(i+0.5>a&&i+0.5<b&&i+0.5>c&&i+0.5<d)
            cnt++;
    printf("%d",cnt);
    
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 100
#define M 100000
int v[N+1],w[N+1],dp[M+1];
signed main(){
	int n,m,i;scanf("%lld%lld",&n,&m);
	for(i=1;i<=n;i++)scanf("%lld%lld",w+i,v+i);
	for(i=1;i<=n;i++)for(int j=m;j>=w[i];j--)
		dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
	printf("%lld\n",dp[m]);
	return 0;
}
/*1
3 8
3 30
4 50
5 60
*/
/*2
5 5
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
*/
/*3
6 15
6 5
5 6
6 4
6 6
3 5
7 2
*/

Measured memory_bytes: 1024
#![allow(
    non_snake_case,
    unused_variables,
    unused_assignments,
    unused_mut,
    dead_code
)]
//use proconio::fastout;
use proconio::input;
//use proconio::marker::*;
//use std::collections::HashSet;
// use std::cmp::*;
//use std::collections::VecDeque;

fn main() {
    input! {
       N:i32,R:i32
    }
    if N >= 10 {
        println!("{}", R);
    } else {
        println!("{}", R + 100 * (10 - N));
    }
}


Measured memory_bytes: 2116
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <cstring>

uint64_t dp[101][100001];

int main() {
  int n, capacity;
  std::cin >> n >> capacity;
  std::vector<int> v(n), w(n);
  for (int i = 0; i < n; ++i) {
    std::cin >> w[i] >> v[i];
  }

  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= capacity; ++j) {
      if (i == 0)
        dp[i][j] = j >= w[i] ? v[i] : 0;
      else if (j >= w[i])
        dp[i][j] = std::max(dp[i - 1][j - w[i]] + v[i],
                            dp[i - 1][j]);
      else
        dp[i][j] = dp[i - 1][j];
    }
  }
  std::cout
    << dp[n - 1][capacity]
    << std::endl;
  return 0;
}

Measured memory_bytes: 78464
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>

int main(){
    int d, n;
    std::cin>>d>>n;

    int ans = (n < 100 ? n : 101) * pow(10, 2 * d);
    std::cout<<ans<<std::endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
P = [int(a)-1 for a in input().split()]
INV = [0] * N
for i in range(N):
    INV[P[i]] = i

NN = 17
MA = [-1] * ((1<<NN+1)-1)
MI = [N] * ((1<<NN+1)-1)

def update(a, x):
    i = (1<<NN) - 1 + a
    MI[i] = x
    MA[i] = x
    while True:
        i = (i-1) // 2
        MI[i] = min(MI[2*i+1], MI[2*i+2])
        MA[i] = max(MA[2*i+1], MA[2*i+2])
        if i == 0:
            break

def rangemin(a, b):
    l = a + (1<<NN)
    r = b + (1<<NN)
    mi = N
    while l < r:
        if l%2:
            mi = min(mi, MI[l-1])
            l += 1
        if r%2:
            r -= 1
            mi = min(mi, MI[r-1])
        l >>= 1
        r >>= 1
    return mi
def rangemax(a, b):
    l = a + (1<<NN)
    r = b + (1<<NN)
    ma = -1
    while l < r:
        if l%2:
            ma = max(ma, MA[l-1])
            l += 1
        if r%2:
            r -= 1
            ma = max(ma, MA[r-1])
        l >>= 1
        r >>= 1
    return ma
ans = 0
for i in INV[::-1]:
    l1 = rangemax(0, i)
    l2 = rangemax(0, l1)
    r1 = rangemin(i+1, N+1)
    r2 = rangemin(r1+1,N+1)
    pre = ans
    ans += (P[i]+1) * ((i-l1) * (r2-r1) + (l1-l2) * (r1-i))
    update(i, i)

print(ans)

Measured memory_bytes: 94728
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/
const int dx[] = { -1, 0, 1, 0 }, dy[] = { 0, -1, 0, 1 };
//const int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 }, dy[] = { 0, -1, 1, -1, 1, 0, -1, 1 };
bool valid(int x, int y, int h, int w) { return (x >= 0 && y >= 0 && x < h&&y < w); }
int place(int x, int y, int w) { return w*x + y; }

bool dp[8001][16001];


bool check(int x, vi& v)
{
	MS(dp, false);
	dp[0][8000] = true;
	REP(i, v.size())REP(j, 16000)
	{
		if (dp[i][j])
		{
			dp[i + 1][j + v[i]] = true;
			dp[i + 1][j - v[i]] = true;
		}
	}
	return dp[v.size()][8000 + x];
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	string s; int x, y;
	cin >> s >> x >> y;
	vi vx, vy;
	int f = 0;
	int cnt = 0;
	for (auto c : s)
	{
		if (c == 'F') cnt++;
		else
		{
			if (f == 0)
			{
				x -= cnt;
				f = 1;
			}
			else if (f == 1)
			{
				vy.push_back(cnt);
				f = 2;
			}
			else
			{
				vx.push_back(cnt);
				f = 1;
			}
			cnt = 0;
		}
	}
	if (f == 0)
	{
		x -= cnt;
		if (x == 0 && y == 0) cout << "Yes" << endl;
		else cout << "No" << endl;
		return 0;
	}
	if (f == 1) vy.push_back(cnt);
	if(f == 2) vx.push_back(cnt);
	cout << (check(x, vx) && check(y, vy) ? "Yes" : "No") << endl;
	return 0;
}

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

#define pb push_back
#define fst first
#define snd second
#define ALL(s) s.begin(),s.end()
#define fill(a,c) memset(&a, c, sizeof(a))
#define fore(i,x,y) for(ll i=x;i<y;i++)
#define SZ(x) ((int)(x).size())
#define PI 3.1415926535897932384626433832795
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef long long ll;
using namespace std;

int main() {FIN;
    int n,m; cin>>n>>m;
    vector<pair<int,ll>> v;
    fore(i,0,n){
        int a; ll b; cin>>a>>b;
        if(a > m) continue;
        v.pb({a,b});
    }
    sort(ALL(v));
    ll ans = 0;
    int j = 0;
    priority_queue<ll> pq;
    fore(i,1,m+1){
        while(j < SZ(v) && v[j].fst == i){
            pq.push(v[j].snd); j++;
        }
        if(!pq.empty()){
            ans += pq.top(); pq.pop();
        }
    }
    cout<<ans<<"\n";
    return 0;
}



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

signed main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n;
    int64_t k;
    cin >> n >> k;
    vector < int64_t > a(n);
    vector < int > cnt(40, 0);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        for (int j = 0; j < 40; ++j) {
            if (a[i] & (int64_t(1) << int64_t(j)))
                ++cnt[j];
        }
    }
    int64_t x = 0;
    for (int i = 39; i >= 0; --i) {
        if (cnt[i] < (n / 2 + (n & 1)) && x + (int64_t(1) << int64_t(i)) <= k)
            x += (int64_t(1) << int64_t(i));
    }
    int64_t ans = 0;
    for (int i = 0; i < n; ++i)
        ans = ans + (x ^ a[i]);
    cout << ans << '\n';
}


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

using namespace std;

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

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	int n, k;
	string s;
	cin>>n>>k>>s;
	int r=0;
	while(r<n && s[r]=='1'){
		++r;
	}
	REP(i, k){
		while(r<n && s[r]=='0'){
			++r;
		}
		while(r<n && s[r]=='1'){
			++r;
		}
	}
	if(r==n){
		cout<<n<<'\n';
		return 0;
	}
	int ans=r, l=0;
	while(l<n){
		while(l<n && s[l]=='1'){
			++l;
		}
		while(l<n && s[l]=='0'){
			++l;
		}
		while(r<n && s[r]=='0'){
			++r;
		}
		while(r<n && s[r]=='1'){
			++r;
		}
		CHMAX(ans, r-l);
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll a,b; cin >> a >> b;
    if(a>8 || b>8) puts(":(");
    else puts("Yay!");
}

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

ll H, W, h, w;

int main() {
    scanf("%lld %lld %lld %lld", &H, &W, &h, &w);
    if (h == 1 && w == 1) {
        printf("No\n");
        return 0;
    }
    ll p = 999999999 / (h*w-1), k = -p*(h*w-1)-1;
    ll c = (H/h) * (W/w);
    if (c*k + (H*W-c)*p <= 0) printf("No\n");
    else {
        printf("Yes\n");
        for (ll r = 1; r <= H; r++) {
            for (ll c = 1; c <= W; c++) printf("%lld ", r % h == 0 && c % w == 0 ? k:p);
            printf("\n");
        }
    }
}

Measured memory_bytes: 2944
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <string>
#include <string.h>
#include <math.h>
#include <iomanip>
#include <stdio.h>
using namespace std;

#define int64 long long
#define pii pair <int64, int64>
#define fr first
#define sc second
#define heap priority_queue
struct piii{
    int64 fr, sc, th;
    bool operator < (const piii &b){
        if (fr != b.fr) return fr < b.fr;
        if (sc != b.sc) return sc < b.sc;
        return th < b.th;
    }
};
///////////////////////////////////////////////
///////////////////////////////////////////////

int n, res;
vector <int> a[18];
bool dd[18];

bool check(){
    for (int i = 1; i <= n; i++)
    if (dd[i]){
        for (int j = 0; j < a[i].size(); j += 2)
            if (dd[a[i][j]] != a[i][j + 1]) return 0;
    }
    return 1;
}

void thu(int pos, int cur){
    if (pos > n){
        if (check())
            res = max(res, cur);
        return;
    }
    thu(pos + 1, cur);
    dd[pos] = true;
    thu(pos + 1, cur + 1);
    dd[pos] = false;
}

int main(){
    cout << setprecision(2) << fixed;
    ios::sync_with_stdio(false), cin.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> n;
    int tmp;
    for (int i = 1; i <= n; i++){
        cin >> tmp;
        a[i].resize(tmp * 2);
        for (int j = 0; j < tmp * 2; j++) cin >> a[i][j];
    }
    thu(1, 0);
    cout << res;
    return 0;
}


Measured memory_bytes: 256
// Last Change:               11/29/2018 22:43:38.
#include <algorithm>
#include <array>
#include <cmath>
#include <iostream>
#include <list>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N, K, x[100000];
  int pNum = 0, nNum = 0;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    cin >> x[i];
    if (x[i] > 0) {
      pNum++;
    } else if (x[i] == 0) {
      N--;
      i--;
      K--;
    }
  }
  nNum = N - pNum;

  int left, right, tmp;
  if (nNum >= K) {
    left = nNum - K;
    right = nNum - 1;
    tmp = abs(x[left]);
  } else {
    left = 0;
    right = K - 1;
    tmp = abs(x[left]) + abs(x[right]) + min(abs(x[left]), x[right]);
  }

  while (left < nNum && right < N) {
    tmp = min(tmp,
              abs(x[left]) + abs(x[right]) + min(abs(x[left]), abs(x[right])));
    right++;
    left++;
  }
  if (right < N) {
    tmp = min(tmp, abs(x[right]));
  }

  cout << tmp << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define ALL(x) (x).begin(),(x).end()
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8

string S;
string s[9];
int K;

void hantei(int i,int k,int j){
  if(k==K || j==K+1 || i+j>S.size()){
  }
  else if(S.substr(i,j)<=s[k] || s[k].size()==0){
    if(S.substr(i,j)!=s[k]){
      for(int l=4;l>=k+1;l--){
        s[l]=s[l-1];
        }
      s[k]=S.substr(i,j);
    }
    hantei(i,k+1,j+1);
  }
  else{
    hantei(i,k+1,j);
  }
}

int main() {
  cin >> S >> K;
  rep(i,S.size()){
    hantei(i,0,1);
  }
  cout << s[K-1] << endl;
}

Measured memory_bytes: 256
/*     !ya khoda!     */
#include <bits/stdc++.h>

#define ll long long
#define ld long double

#define pp push
#define po pop()
#define pb push_back
#define pf push_front
#define pob pop_back()
#define pof pop_front()
#define I insert
#define E erase

#define F first
#define S second

#define mkp make_pair
#define pll pair<ll,ll>
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define all(a) a.begin(),a.end()

#define coutghat(x)      cout<<tolower(x);
#define coutashar(x,d)   cout<<fixed<<setprecision(x)<<(ld)d
#define IOS ios_base::sync_with_stdio(false) , cin.tie(0);

#define LB(x) ((x) & -(x))
#define BIT(a , b) (((a)>>(b)) & 1)
//#define poow(a,b,M)   b?(poow((a*a)%M,b/2)%M * (b&1?a))%M:1 ;
/*==========================================================================*/
using namespace std;
ll poow(ll x,ll n,ll Mod=1e9+7) { return (n==0?1:poow(x*x%Mod,n/2)*(n&1?x:1)%Mod); }
//#pragma optimize O3
// 107,109, 211,223, 307, 401,409, 503,509, 601,607, 701,709, 809, 907, 1009
/*==========================================================================*/
const int N=2e5+10  , M=1e4+10  , SQ=320 , LG=23 , base=2;
const int mod=1e9+7 , MOD=1e9+9;
const ll  INF=1e9   , inf=1e18 , super_inf=~0ull/4;
ll n,m,a[N]  ,  cnt[16]  ,  dp[1<<16],val[1<<16]  ,  x,k;
vector<ll>vec;
/*==========================================================================*/
int main()
{
    IOS;
    cin>>n;
	for(int i=1;i<n;i++)
	{   ll v,u,w;
        cin>>v>>u>>w;
		a[v]^=w  ,  a[u]^=w;
	}
	for(int i=0;i<n;i++)   cnt[a[i]]++;


	x=cnt[0]  ,  cnt[0]=0;
	for(int i=0;i<n;i++)
	{
		if(cnt[a[i]]%2)   vec.pb(a[i]);
		x+=cnt[a[i]]/2;
		cnt[a[i]]=0;
	}

	m=vec.size() , k=(1<<m);
	for(int i=0;i<k;i++)
		for(int j=0;j<m;j++)
			if(i>>j&1)
				val[i]^=vec[j];

	for(int i=1;i<k;i++)
	{   dp[i]=1;
		if(val[i]!=0)   continue;
		for(int j=i;j>0;j=(j-1)&i)
			if(!val[j])
				dp[i]=max(dp[i],dp[j]+dp[i^j]);
	}

	cout<<n-(dp[k-1]+x);
	return 0;
}


Measured memory_bytes: 1536
from math import sqrt

while True:
    D, E = map(int, raw_input().split())

    if D == 0 and E == 0:
        break

    d = 0xdeadbeaf
    for i in range(D+1):
        x, y = i, D-i
        d = min(abs(sqrt(x**2 + y**2) - E), d)

    print d



Measured memory_bytes: 4716
// F - Fork in the Road
#include <bits/stdc++.h>

using namespace std;

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false); cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<vector<int> > g(n);
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		g[u].push_back(v);
	}

	double ans = 1e18;
	for (int k = 0; k < n; k++) {
		vector<double> dp(n);
		dp[n - 1] = 0;
		for (int u = n - 2; u >= 0; u--) {
			int c = g[u].size();
			double sum = 0, mx = 0;
			for (int i = 0; i < g[u].size(); i++) {
				sum += dp[g[u][i]];
				mx = max(mx, dp[g[u][i]]);
			}
			if (u == k && c >= 2) {
				c--;
				sum -= mx;
			}
			dp[u] = sum / c + 1.0;
		}
		ans = min(ans, dp[0]);
	}

	cout << fixed << setprecision(15) << ans << endl;

	return 0;
}


Measured memory_bytes: 1408
// Created by sahim on 7/3/2020.
#include"bits/stdc++.h"
using namespace std ;
#define ll unsigned long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

template <class ...Args>
auto &log(const Args &...args) {return ((cerr << " " << args), ...) << '\n';}
#define watch(...)  cerr << "[ "#__VA_ARGS__" ] = "; log(__VA_ARGS__) << '\n'
//C++17
template<typename... Args>
void read(Args&... args){((cin >> args), ...);}
template<typename... Args>
void write(Args... args){((cout << args << " "), ...);}

const int mod = 1e9 +7 ;



int main() {
    IOS
    int n ;
    cin >>  n ;
    map< string ,int > mp ;
    string s ;
    for (int i = 0; i <n ; ++i) {
        cin>> s;
        mp[s]++;
    }
    int l = mp.size();
    cout << "AC x " << mp["AC"]<< '\n' ;

    cout << "WA x " << mp["WA"]<< '\n' ;

    cout << "TLE x " << mp["TLE"]<< '\n' ;

    cout << "RE x " << mp["RE"]<< '\n' ;

}




Measured memory_bytes: 3668
<?php   
    $sum=0;
    fscanf(STDIN,"%d",$K);

    for($i=1;$i<=$K;$i++){
        
        for($j=1;$j<=$K;$j++){
            $ij = gmp_gcd($i, $j);
          
            for($k=1;$k<=$K;$k++){
                if($k==1){
                    $sum++;
                    continue;
                }
                $gcd = gmp_gcd($ij,$k);
                $sum += $gcd;
            }
        }
    }

    echo $sum."\n";


Measured memory_bytes: 16428
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;

#define int long long

#define rep(i, n) for (signed i = 0; i < signed(n); i++)
#define REP(i, s, n) for (signed i = signed(s); i < signed(n); i++)
#define rrep(i, n) for (signed i = signed(s) - 1; i >= 0; i--)

#define all(c) begin(c), end(c)
template<typename T>bool maxup(T& a, const T&& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool maxup(T& a, const T& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool minup(T& a, const T&& b) { if (a > b) { a = b; return true; }; }
template<typename T>bool minup(T& a, const T& b) { if (a > b) { a = b; return true; }; }

#define X first
#define Y second

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }


void calc() {
	int N; cin >> N;
	V v(N);
	int cnt = 1;
	rep(i, N) {
		int a; cin >> a;
		v[i] = a % 2;
		if (a % 2 == 0) cnt *= 2;
	}
	cout << (int)(pow(3, N) - cnt) << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	calc();
#ifdef _MSC_VER
	system("pause");
#endif
}

Measured memory_bytes: 256
#pragma region RegionDefs
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define reps(i,l,r) for(int i=(l),i##_len=(r);i<i##_len;++i)
#define all(x) begin(x),end(x)
using namespace std;
typedef long long ll;
const ll INF = 1e9;
template<class T=ll> using V = vector<T>;
template<class T=ll> using PQ = priority_queue<T>;
template<class T=ll> using PQG = priority_queue<T, V<T>, greater<T>>;
const ll MOD = 1000000007LL;
void in() {}
template<class Head, class... Tail>
void in(Head&& head, Tail&&... tail)
{
    cin >> head;
    in(move(tail)...);
}
#define IN(...) ll __VA_ARGS__; in(__VA_ARGS__)
#define INS(T, ...) T __VA_ARGS__; in(__VA_ARGS__)
#define VIN(T, v, n) V<T> v(n); for(auto& _elem:v)cin>>_elem
template<class T>bool chmax(T &a, const T &b) {if (a<b) {a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) {if (a>b) {a=b; return 1;} return 0;}
#define y0 y__0
#define y1 y__1
#define j0 j__0
#define j1 j__1
#define YN(e) cout << ((e) ? "YES" : "NO") << endl
#define yn(e) cout << ((e) ? "Yes" : "No") << endl
#pragma endregion RegionDefs

#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;

void solve()
{
    IN(n);
    VIN(ll, v, n);
    sort(all(v));
    if (v[0] == 0) {
        cout << 0 << endl;
        return;
    }
    mp::cpp_int s = 1;
    rep(i, n) {
        s *= v[i];
        if (s > 1000000000000000000LL) {
            cout << -1 << endl;
            return;
        }
    }
    cout << s << endl;
}

int main()
{
    cin.tie(0); cout.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(numeric_limits<double>::max_digits10);

    solve();

    return 0;
}

Measured memory_bytes: 4044
function Main(input) {

	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
    
    let x = parseInt(input[0].split(" ")[0]);
    let n = parseInt(input[0].split(" ")[1]);
    
    if (n == 0) {
        console.log(x);
        return;
    }
    
    let p_n = input[1].split(" ").map(Number);
    
    let buf = 10000;
    
    for (let i = 0; ; i++) {
        
        let tmp = buf;
        
        if (p_n.indexOf(x + i) == -1) buf = x + i;
        
        if (p_n.indexOf(x - i) == -1) buf = x - i;
        
        if (tmp != buf) break;
        
    }
    
    console.log(buf);
    
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29644
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define All(x) (x).begin(),(x).end()
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> VI;
typedef pair<int,int> PII;
const double PI=acos(-1.0);
const double eps=1e-6;
const long long mod=998244353;
const int inf=0x7fffffff;
const int maxn=100005;
ll qpow(ll x,ll y,ll Mod) {ll ans=1,base=x%Mod; while(y){if(y&1)ans=(ans*base)%Mod;base=(base*base)%Mod;y>>=1;} return ans;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
// fast read
template<class T> void read(T &x) {
	x=0;int f=0;char ch=getchar();
	while(ch<'0'||ch>'9'){f|=(ch=='-');ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	x=f?-x:x;
	return;
}

int n,s,a[maxn];
ll dp[3005][3005];
int main(){
	//freopen("test.in","r",stdin);
	read(n),read(s);
	rep(i,1,n) read(a[i]);
	// ll inv2=qpow(2,mod-2,mod);
	dp[0][0]=1;
	rep(i,1,n){
		rep(j,0,s){
			dp[i][j]=(dp[i][j]+dp[i-1][j]*2)%mod;
			if(j>=a[i]) dp[i][j]=(dp[i][j]+dp[i-1][j-a[i]])%mod;
		}
	}
	printf("%lld\n",dp[n][s]%mod);
	return 0;
}

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

using ll = long long;
//print(fixed << setprecision(10));
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repk(i,n,k) for(int i = k; i < (n); i++)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl
double PI = acos(-1.0);
int INF = 1e9;
ll LINF = 1e18;
ll MOD = 1e9+7;


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

    int n;
    cin >> n;
    ll sum=0;
    vector<ll> a(n+1);
    rep(i,n+1){
        cin >> a[i];
        sum += a[i];
    }

    ll root = 1;
    ll mp = 1;
    ll ans = 0;
    rep(d,n+1){
        sum -= a[d];
        if(a[d] > mp){
            ans = -1;
            break;
        }
        if(d==0) if(a[d]>0 && n>0){
            ans = -1;
            break;
        }
        if(d==n){
            if(a[d]<root || a[d]>root*2) ans = -1;
            else ans += a[d];
        }
        else{
            if(a[d] > root*2){
                ans = -1;
                break;
            }
            if(d!=0) root = min(mp-a[d], min(sum,root*2-a[d]));
            if(root<1){
                ans = -1;
                break;
            }
            ans += root + a[d];
        }
        mp = min(mp*2,100000000+sum);
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 3972
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>

using namespace std;

typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define Fst first
#define Snd second
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)
#define repv(t,it,v) for(vector<t>::iterator it = v.begin() ; it != v.end() ; ++it)

typedef long long LL;

int N;
int a[100010];
int b[100010];
LL f[100010];
const LL mod = 1e9 + 7;

int main(){
	scanf("%d" , &N);
	repp(i,0,N){
		scanf("%d" , a + i);
	}
	repp(i,0,N){
		scanf("%d" , b + i);
	}
	sort(a,a+N);
	sort(b,b+N);
	f[0] = 1;
	repp(i,0,N){
		f[i+1] = f[i] * i % mod;
	}
	LL ans = 1;
	repp(i,0,N){
		int z = 1;
		int x = i;
		if(a[i] < b[i]){
			while(z > 0 && i < N-1){
				if(a[i+1] < b[x]){
					++z;
					++i;
					(ans *= z) %= mod;
				} else {
					--z;
					++x;
				}
			}
		} else {
			while(z > 0 && i < N-1){
				if(b[i+1] < a[x]){
					++z;
					++i;
					(ans *= z) %= mod;
				} else {
					--z;
					++x;
				}
			}
		}
	}
	printf("%lld\n" , ans);
	return 0;
}


Measured memory_bytes: 1664
from collections import deque
N, M = map(int, raw_input().split())
A = {}
for i in xrange(M):
    L, R, D = map(int, raw_input().split())
    if not L in A:
        A[L]=[]
    A[L].append((R,D))
    if not R in A:
        A[R]=[]
    A[R].append((L,-D))
K = set(A.keys())
x = {}
ans = "Yes"
while len(K)>0:
    i = list(K)[0]
    K.remove(i)
    x[i] = 0
    q = deque([i])
    while len(q)>0:
        j = q.pop()
        for u,v in A[j]:
            if u in x and x[u]!=x[j]+v:
                ans="No"
            x[u]=x[j]+v
            if u in K:
                K.remove(u)
                q.append(u)
print ans

Measured memory_bytes: 81452
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long ll;
#define int long long
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;

int N,M;
int A[31][31];
int K[31];
int num[31];
int ans=0;

signed main(){
	cin>>N>>M;
	REP(i,N){
		cin>>K[i];
		REP(j,K[i]){
			cin>>A[i][j];
		}
	}
	REP(i,N){
		REP(j,K[i]){
			REP(k,M){
				if(A[i][j]==k+1){
					num[k]++;
				}
			}
		}
	}
	REP(i,M){
		if(num[i]==N){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n; cin>>n;
	int t, x, y, pt, px, py;
	pt = px = py = 0;
	for(int i = 0; i < n; i++){
		cin>>t>>x>>y;
		int dist = abs(px - x) + abs(py - y);
		int tmd = t - pt;
		if(dist > tmd || (dist^tmd)%2 != 0){
			cout<<"No"<<endl;
			exit(0);
		}
		pt = t; px = x; py = y;
	}
	cout<<"Yes"<<endl;

	return 0;
}

Measured memory_bytes: 256
<?php
while (true) {
$rep_words = [];
$string = [];
$rep_count = trim(fgets(STDIN));
if (0 == $rep_count) break;
for ($i = 0; $i < $rep_count; $i++) {
    list($before, $after) = explode(' ', trim(fgets(STDIN)));
    $rep_words[] = array('before' => $before, 'after' => $after);
}

$string_count = trim(fgets(STDIN));
for ($i = 0; $i < $string_count; $i++) {
    $string[] = trim(fgets(STDIN));
}

$done = array_fill(0, count($string), false);
foreach ($rep_words as $rep) {
    for ($i = 0; $i < count($done); $i++) {
        if ($done[$i] == true) continue;
        if ($string[$i] == $rep['before']) {
            $string[$i] = $rep['after'];
            $done[$i] = true;
        }
    }
}

echo implode($string) . PHP_EOL;
}


Measured memory_bytes: 46312
#include <bits/stdc++.h>
using namespace std;
struct BB{
    long f,s;
};
bool cmp(BB left,BB right){
    if(left.s == right.s)return left.f > right.f;
    return left.s > right.s;
}
int main(){
    int n,m;
    scanf("%d %d",&n,&m);
    multiset<long>A;
    for(int i = 0; i < n; i++){
        long x;scanf("%ld",&x);
        A.insert(x);
    }
    BB B[m+5];
    for(int i = 0; i < m; i++){
        scanf("%ld %ld",&B[i].f,&B[i].s);
    }
    sort(B,B+m,cmp);

    for(int i = 0; i < m; i++){
        long first = B[i].f;
        long second = B[i].s;
        if(*A.begin() >= second)break;
        for(int j = 0; j < first; j++){
            if(*A.begin() >= second) break;
            A.erase(A.begin());
            A.insert(second);
        }
    }

    long long ans = 0;
    for(long t : A){
        ans += t;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6528
import sys
def input():
	return sys.stdin.readline().strip()

A, B, C, X, Y = list(map(int, input().split()))

if 2*C < A and 2*C < B:
	print(max(X, Y)*2*C)
	#print(1)
elif 2*C < A and 2*C >= B:
	if X >= Y:
		print(max(X, Y) * 2 * C)
		#print(2)
	else:
		print(X*2*C + (Y - X)*B)
		#print(3)
elif 2*C >= A and 2*C < B:
	if X <= Y:
		print(max(X, Y) * 2 * C)
		#print(4)
	else:
		print(Y*2*C + (X - Y)*A)
		#print(5)
elif 2*C < A + B and X <= Y:
	print(2*C*X + (Y - X)*B)
	#print(6)
elif 2*C < A + B and X >= Y:
	print(2 * C * Y + (X - Y) * A)
	#print(7)
else:
	print(A*X + B*Y)
	#print(8)

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

//#pragma GCC optimize("O3")
//#pragma GCC target("sse4")

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ITER(it, a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

#define SZ(a) (int)((a).size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = (LL)INF * INF;

const int MAX = 100 * 1000 + 7;

bool cmp(const PII& a, const PII& b)
{
	return a.first + a.second > b.first + b.second;
}

PII p[MAX];

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//freopen("In.txt", "r", stdin);
	int n;
	cin >> n;
	FOR(i, 0, n)
		cin >> p[i].first >> p[i].second;
	sort(p, p + n, cmp);
	LL ans = 0;
	FOR(i, 0, n)
		ans += (i & 1 ? -p[i].second : p[i].first);
	cout << ans;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <climits>
#include <vector>

using ull = unsigned long long;
using ll = long long;

int main()
{
    uint64_t n;
    std::cin >> n;
    std::vector<ll> r(n);
    for (int i = 0; i < n; ++i)
    {
        std::cin >> r[i];
    }

    ll r_min = LONG_MAX;
    ll profit_max = LONG_MIN;
    for (int i = 1; i < n; ++i)
    {
        r_min = std::min(r_min, r[i - 1]);
        profit_max = std::max(profit_max, r[i] - r_min);
    }

    std::cout << profit_max << std::endl;
    return 0;
}


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

using namespace std;

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

  int a, b;
  cin >> a >> b;
  int res = 0;
  for (int i = a; i <= b; ++i) {
    ostringstream oss;
    oss << i;
    string tmp = oss.str();
    if (tmp[0] == tmp[4] && tmp[1] == tmp[3]) 
      ++res;
  }
  cout << res << endl;

  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)

void chmax(ll& a, ll b) { a = max(a, b); }
void chmin(ll& a, ll b) { a = min(a, b); }

using P = pair<int, int>;

int main() {
    int n,t; cin >> n >> t;
    vector<P> ba;
    rep(i, n) {
        int a,b;
        cin >> a >> b;
        ba.push_back(make_pair(b,a));
    }
    //sort(ba.rbegin(), ba.rend());
    vector<vector<int>> dp1(n+1, vector<int>(t, 0));
    vector<vector<int>> dp2(n+1, vector<int>(t, 0));

    vector<int> ans1(n,0);
    vector<int> ans2(n,0);
    rep(i, n) {
        rep(j, t) {
            if(j >= ba[i].second) {
                if(i > 0) dp1[i][j] = max(dp1[i-1][j-ba[i].second] + ba[i].first, dp1[i-1][j]);
                else dp1[i][j] = ba[i].first;
            } else {
                if(i > 0) dp1[i][j] = dp1[i-1][j];
            }
            ans1[i] = max(ans1[i], dp1[i][j]);
        }
    }

    for(int i=n-1; i >= 0; i--) {
        rep(j, t) {
            if(j >= ba[i].second) {
                dp2[i][j] = max(dp2[i+1][j-ba[i].second] + ba[i].first, dp2[i+1][j]);
            } else {
                dp2[i][j] = dp2[i+1][j];
            }
            ans2[i] = max(ans2[i], dp2[i][j]);
        }
    }

    int ans = 0;
    rep(i, n) {
        int tmpans = 0;
        rep(j, t) {
            if(i == 0) {
                tmpans = max(tmpans, dp2[i + 1][j]);
            } else if(i == n-1) {
                tmpans = max(tmpans, dp1[i - 1][j]);
            } else {
                tmpans = max(tmpans, dp1[i - 1][j] + dp2[i + 1][t - 1 - j]);
            }
        }
        ans = max(ans, tmpans+ba[i].first);
    }

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


/**
3 1000
2 40
500 20
500 12


5 900
200 1
100 2
1000 3
900 4
900 5
**/

Measured memory_bytes: 70912
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Toi junbi = new Junbi3();
		junbi.solve();
	}
}

interface Toi{
	public void solve();
}

class Junbi1 implements Toi{
	public void solve(){
		for (int i = 1; i <= 9; i++) {
			for (int j = 1; j <= 9; j++) {
				System.out.println(i + "x" + j + "=" + i * j);
			}
		}
	}
}

class Junbi2 implements Toi{
	public void solve(){
		Scanner sc = new Scanner(System.in);
		int[] array = new int[10];
		for (int i = 0; i < array.length; i++) {
			array[i] = sc.nextInt();
		}
		Arrays.sort(array);
		for (int i = 0; i < 3; i++) {
			System.out.println(array[array.length - (i + 1)]);
		}
	}
}

class Junbi3 implements Toi{
	public void solve(){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 0; i < n; i++) {
			int[] array = new int[3];
			for (int j = 0; j < 3; j++) {
				array[j] = sc.nextInt();
			}
			Arrays.sort(array);
			double num = Math.sqrt(Math.pow((double)array[0], 2.) + Math.pow((double)array[1], 2.));
			if(Math.abs(num - (double)array[2]) < 1E-8){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
		}
	}
}


Measured memory_bytes: 33940
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define PI 3.1415926535897932384626433
#define mod 1000000007
 
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
 
int lcm(int a, int b) { return a * b / gcd(a, b); }
 
int main(){
    int k, t;
    cin >> k >> t;
    int a[t];
    for (int i = 0; i < t; i++){
        cin >> a[i];
    }
    sort(a, a + t, greater<int>());
    cout << max(a[0] - 1 - (k - a[0]), 0) << endl;
    return 0;
}

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

int main() {
    string s,ans="";
    cin>>s;
    for(int i=0;i<s.length();i++)
    {
       ans+=s[i];
       /*for(int j=0;j<ans.length()-1;j++)
       {
           if(ans[j]==s[i])
           {
               ans ="";
               break;
           }
       }*/
       if(ans.length()==3)
        break;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3600