akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)

int n,m;

struct e{
    int u;
    int v;
    int k;
    int t;
};
vector<vector<e>> G;
vector<e> es;

vector<int> seen;
bool res;

bool dfs(int i){
    if(seen[i]==0){
        res = true;
        return 0;
    }
    else if(seen[i]==-1){
        seen[i] = 0;
        int u = es[i].v, t = es[i].t;
        t = (t+1)%4;
        for(e ee:G[u]){
            if(ee.t==t){
                dfs(ee.k);
            }
        }
        seen[i] = 1;
    }
    return 0;
}


int main(int argc, char const *argv[]) {
    cin>>n>>m;
    string s;cin>>s;
    G = vector<vector<e>>(n, vector<e>(0));
    seen = vector<int>(2*m, -1);
    res = false;
    es = vector<e>(0);
    for(int i=0;i<m;++i){
        int u,v;cin>>u>>v;
        u--;
        v--;
        e e1;
        e1.u = u;
        e1.v = v;
        e1.k = 2*i;
        int t = 0;
        if(s[u]=='A'&&s[v]=='B')t=1;
        if(s[u]=='B'&&s[v]=='B')t=2;
        if(s[u]=='B'&&s[v]=='A')t=3;
        e1.t = t;
        G[u].push_back(e1);
        es.push_back(e1);
        int tmp = v;
        v = u;
        u = tmp;
        e e2;
        e2.u = u;
        e2.v = v;
        e2.k = 2*i+1;
        t = 0;
        if(s[u]=='A'&&s[v]=='B')t=1;
        if(s[u]=='B'&&s[v]=='B')t=2;
        if(s[u]=='B'&&s[v]=='A')t=3;
        e2.t = t;
        G[u].push_back(e2);
        es.push_back(e2);
    }
    int l = 0;
    for(int i=0;i<2*m;++i){
        if(seen[i]==-1)dfs(i);
    }
    if(res)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 31080
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;



int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	ll x = 100;
	ll n;
	cin >> n;
	int ans = 0;
	while (x < n) {
		x = (ll)(1.01 * x);
		ans++;
	}
	cout << ans;
}


Measured memory_bytes: 3572
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN = 200000;
int a[MAXN + 5], b[MAXN + 5], N;
int c[MAXN + 5], d[MAXN + 5];
int main() {
	scanf("%d", &N);
	for(int i=1;i<=N;i++)
		scanf("%d", &a[i]);
	for(int i=1;i<=N;i++)
		scanf("%d", &b[i]);
	int ans = 0;int p = 0, q = 0;
	for(int i=0;i<=29;i++) {
		q = (1<<i);p |= q;
		for(int j=1;j<=N;j++) {
			c[j] = (a[j] & p);
			d[j] = (b[j] & p);
		}
		sort(d+1, d+N+1);
		for(int j=1;j<=N;j++) {
			int le = lower_bound(d+1, d+N+1, q-c[j]) - d;
			int ri = upper_bound(d+1, d+N+1, p-c[j]) - d - 1;
			if( (ri-le+1) & 1 )
				ans ^= q;
			if( c[j] <= q ) continue;
			le = lower_bound(d+1, d+N+1, 3*q-c[j]) - d;
			if( le > N ) continue;
			ri = N;
			if( (ri-le+1) & 1 )
				ans ^= q;
		}
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a*b/gcd(a,b);}
ll MOD=1000000007;

int main(){
  ll n,k;
  cin>>n>>k;
  ll ans=n%k;
  if(ans*2>k){
    ans=abs(ans-k);
    cout<<ans<<endl;
  }else{
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B: Snake Toy
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 50;

/* typedef */

/* global variables */

int ls[MAX_N];

/* subroutines */

/* main */

int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> ls[i];
  sort(ls, ls + n, greater<int>());

  int sum = 0;
  for (int i = 0; i < k; i++) sum += ls[i];
  printf("%d\n", sum);
  return 0;
}


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

int main() {
  ll a, b, n;
  cin >> a >> b >> n;
  ll x = n;
  if (n >= b-1) x = b-1;
  ll ans = a * (x%b) / b;
  cout << ans << endl;
  return 0;
}


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

int main()
{
    int n,k,a[1010],ans=0;
    scanf("%d %d",&n,&k);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    sort(a+1,a+n+1);
    for(int i=1;i<=k;i++)
        ans+=a[i];
    printf("%d",ans);
}

Measured memory_bytes: 3820
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
using namespace std;
using ll=long long;
#define mod  1000000007

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

  std::vector<int> start(26,-1),goal(26,-1);
  for(int i=0; i<S.size(); i++){
    int a=S[i]-'a';
    int b=T[i]-'a';
    //対応表がすでに存在していて、同じ行き先の場合
    if(start[a]!=-1 || goal[b]!=-1){
      if(start[a]!=b || goal[b]!=a){
        std::cout << "No" << '\n';
        return 0;
      }
    }
    else{
    start[a]=b;
    goal[b]=a;
   }
  }
  std::cout << "Yes" << '\n';
  return 0;
}


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

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define RFOR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define LL long long
#define INF INT_MAX/3

const double EPS = 1e-14;
const double PI  = acos(-1.0);


int main(){
  int h, w;
  scanf("%d %d", &h, &w);

  int v[10][10];
  REP (i, 10) {
    REP (j, 10) {
      scanf("%d", &v[i][j]);
    }
  }

  int a[h][w];
  REP (i, h) {
    REP (j, w) {
      scanf("%d", &a[i][j]);
    }
  }

  REP (i, 10) {
    REP (j, 10) {
      REP (k, 10) {
        v[j][k] = min(v[j][k], v[j][i] + v[i][k]);
      }
    }
  }

  int ans = 0;
  REP (i, h) {
    REP (j, w) {
      if (a[i][j] != -1)
        ans += v[a[i][j]][1];
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	deque<ll> a;
	int q;
	cin>>q;
	for(int i = 0; i < q; i++){
		int b;
		cin>>b;
		if(b==0){
			int d,x;
			cin>>d>>x;
			if(d==0) a.push_front(x);
			else a.push_back(x);
		}else if(b==1){
			int p;
			cin>>p;
			cout<<a[p]<<endl;
		}else{
			int d;
			cin>>d;
			if(d==0) a.pop_front();
			else a.pop_back();
		}
	}

	return 0;
}


Measured memory_bytes: 6208
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
fn main() {
    input!{
        a:chars,
        b:chars,
    }
    if a.len() > b.len(){
        println!("GREATER");
        return;
    }else if a.len() < b.len(){
         println!("LESS");
         return;
    }else{
        for i in 0..a.len(){
            let mut left:usize = a[i] as usize - 48;
            let mut right:usize = b[i] as usize - 48;
            if left > right{
                println!("GREATER");
                return;
            }else if left < right {
                println!("LESS");
                return;
            }
        }
    }
    println!("EQUAL");
}


Measured memory_bytes: 4352
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		String output = "Yes";
		
		String[] W = new String[N];
		
		HashMap<String, Boolean> hmap = new HashMap<String, Boolean>();
		
		for(int i=0; i<N; i++) {
			W[i] = scanner.next();
			
			if(hmap.get(W[i]) != null)
				output = "No";
			hmap.put(W[i], true);
			
			if((i!=0) && (W[i].charAt(0) != (W[i-1].charAt(W[i-1].length()-1))))
				output = "No";
			
		}
		
		System.out.println(output);
		

	}

}


Measured memory_bytes: 22740
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define F first
#define S second
#define db double
#define pb push_back
#define rep(i,a,b)  for(ll i=a;i<=b;i++)
#define all(a) a.begin(),a.end()
using namespace std;

 ll mod=1e9 +7;

ll expo(ll base,ll exponent,ll mod){
    ll ans=1;
    while(exponent!=0){
        if(exponent&1) ans=(1LL*ans*base)%mod;
        base=(1LL*base*base)%mod;
        exponent>>=1;
    }
    return ans%mod;
}
 
vector<bool>  prime(90000002,true);
void Sieve() 
{ 
   
    for (int p=2; p*p<=90000001; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=90000001; i += p) 
                prime[i] = false; 
        } 
    } 
}

ll get_val(vector<ll>&ft,ll index)
{
  ll res=0;
  for(;index>=0;index=(index & (index+1))-1)
    res+=ft[index];
  return res;
}

void update(vector<ll>&ft,ll index,ll val)
{
  for(;index<(ll)ft.size();index|=index+1)
    ft[index]+=val;
}

ll bs(ll num,ll a,ll b,ll tot)
{
  ll lo=0,hi=num/a +1;
  ll res=-1;
  while(hi>=lo)
  {
    ll mid=(lo+hi)/2;
    if(mid*a + (tot-mid)*b >=num)
    {
      res=mid;
      hi=mid-1;
    }
    else lo=mid+1;
  }
  return res;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //   #ifndef ONLINE_JUDGE
    // // for getting input from input.txt
    // freopen("input.txt", "r", stdin);
    // // for writing output to output.txt
    // freopen("output.txt", "w", stdout);
    // #endif
    
    // Sieve();
   ll tests=1;
 // cin>>tests;
  // ll t=1;
    while(tests--)
    {
      ll n,a,b,i,j,ans=0;
      cin>>n>>a>>b;
      vector<ll>h(n);
      rep(i,0,n-1) cin>>h[i];
      sort(all(h));
      // reverse(all(h));
      ll hi=1000000000,low=0;
      while(hi>=low )
      {
        ll mid=(low+hi)/2;
        ll cur=0;
        bool flag=true;
        for(i=0;i<n;i++)
        {
          if(h[i]<=mid*b) continue;
          else
          {
            ll tmp=bs(h[i],a,b,mid);
            if(tmp==-1) {flag=false;break;}
            else cur+=tmp;
          }
        }
        if(!flag) {low=mid+1;continue;}
        // cout<<"cur- "<<cur<<" "<<"mid "<<mid<<"\n";
        if(cur<=mid) {ans=mid;hi=mid-1;}
        else low=mid+1;
      }
      // cout<<bs(20,10,4,4)<<"\n";
      cout<<ans;

    }

    return 0;
   }

Measured memory_bytes: 15056
#include <bits/stdc++.h>
using namespace std;
#define FALSE 0
#define TRUE 1

int main(){
    int A, B, C;
    // int N;
    // vector<int>     vA(100010, 0);
    // map<int64_t, int>   mP;
    int res;

    cin >> A >> B >> C;
    // for (int i=0; i<N; i++){
    //     int Ai;
    //     cin >> Ai;
    //     vA.at(Ai)++;
    //     AiMax = max(AiMax, Ai);
    // }

    res = max(C - A + B, 0);
    // for (int i=0; i<N; i++){
        // res = max(res, count3);
    // }

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <sstream>
#include <string.h>
using namespace std;

int main()
{
int a,b;
cin>>a>>b;
int c=a-b;
if (c<=0)
cout<<"0";
else
cout<<c;
system ("pause");
return 0;
}

Measured memory_bytes: 504
p = [True for i in range(1000001)]
p[0] = False
p[1] = False
for i in range(2,500000):
  for j in range(2, 1000000//i + 1):
    p[i * j] = False

while True:
  n = int(input())
  if n == 0:
     break
  cnt = 0
  for i in range(1, n//2 + 1):
    if (p[i] and p[n-i]):
      cnt += 1
  print(cnt)


Measured memory_bytes: 13516
N, M = map(int, input().split())

def bf(links, n, st=1):
    inf = float('inf')
    dj = [-inf] * (n + 1)
    dj[st] = 0
    for _ in range(N):
        updated = False
        for link in links:
            fn, tn, lc = link
            if dj[fn] + lc > dj[tn]:
                dj[tn] = dj[fn] + lc
                updated = True
        if not updated: break
    else:
        negative = [False] * (n + 1)
        for _ in range(N):
            for link in links:
                fn, tn, lc = link
                negative[tn] |= negative[fn]
                if dj[fn] + lc > dj[tn]:
                    dj[tn] = dj[fn] + lc
                    negative[tn] = True
        if negative[N]: return inf
    return dj[-1]

links = []
for _ in range(M):
    links.append([int(x) for x in input().split()])

print(bf(links, N, 1))

Measured memory_bytes: 3444
#include <vector>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<n;i++)
#define SORT(c) sort((c).begin(),(c).end())

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

  int n;
  cin >> n;

  vector<int> upper(n), lower(n);

  REP(i, n) {
    cin >> upper[i];
  }
  REP(i, n) {
    cin >> lower[i];
  }

  int ans = -1;

  REP(i, n) {
    int tmpSum = 0;
    for(int j=0;j<=i;j++) {
      tmpSum += upper[j];
      // cout << "[" << i << "]" << upper[j] << endl;
    }
    for(int j=i;j<n;j++) {
      tmpSum += lower[j];
      // cout << "[" << i << "]" << lower[j] << endl;
    }
    ans = max(tmpSum, ans);
  }

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


Measured memory_bytes: 256
use proconio::{input, fastout};
use std::collections::HashSet;

#[fastout]
fn main() {
    input! {
        x: isize,
        n: usize,
        ps: [isize; n]
    }

    let mut set = HashSet::new();
    for p in ps {
        set.insert(p);
    }

    let mut min = 101;
    let mut ans = 101;
    for i in 0..=101 {
        if set.contains(&i) {
            continue;
        }
        let sub = (i-x).abs();
        if sub < min {
            ans = i;
            min = sub;
        }
    }

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

Measured memory_bytes: 2216
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
int r;
cin >> r;
if(r<1200) {
  cout << "ABC" << endl;
} else if(1200<=r&&r<2800) {
  cout << "ARC" << endl;
} else {
  cout << "AGC" << endl;
}
return 0;
}


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

int main()
{
	
	ll arr[6];
	ll i;
	ll flag=0;
	for(i=1; i<=5; i++)
	{
		cin>>arr[i];
		if(arr[i]==0)
			flag=i;
	}
	cout<<flag;
	return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace::std;
#define int long long

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sax(x) cout << "!!!!!!!!!!! " << #x << " = " << x << '\n'
#define inf (sizeof(int) == 4 ? (int)1E9 : (int)1E18)
#define one(x) x.insert(x.begin(), 0);
#define TCT template <class T>
#define TCT12 template <class T1, class T2>
#define IS istream
#define OS ostream
#define OP operator

//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less_equal<int>,rb_tree_tag,
//tree_order_statistics_node_update> imsi;

TCT IS& OP>>(IS &I, vector<T>& v) {for (T &e: v) I >> e; return I;}
TCT OS& OP<<(OS &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; /*O << '\n';*/ return O;}
TCT OS& OP<<(OS &O, const unordered_set<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const set<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const unordered_multiset<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, const multiset<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT IS& OP>>(IS &I, deque<T>& v) {for (T &e: v) I >> e; return I;}
TCT OS& OP<<(OS &O, const deque<T>& v) {for (const T &e: v) O << e << ' '; return O;}
TCT OS& OP<<(OS &O, priority_queue<T> v) {while (!v.empty()) {O << v.top() << ' '; v.pop();} return O;}
TCT OS& OP<<(OS &O, stack<T> v) {while (!v.empty()) {O << v.top() << '\n'; v.pop();} return O;}
TCT OS& OP<<(OS &O, queue<T> v) {while (!v.empty()) {O << v.front() << ' '; v.pop();} return O;}
TCT12 IS& OP>>(IS &I, pair<T1,T2>& p) {return I >> p.first >> p.second;}
TCT12 OS& OP<<(OS &O, const pair<T1,T2>& p) {return O << '(' << p.first << ' ' << p.second << ')';}
TCT12 OS& OP<<(OS &O, const unordered_map<T1,T2>& v) {for (const auto &e: v) O << e << ' '; return O;}
TCT12 OS& OP<<(OS &O, const map<T1,T2>& v) {for (const auto &e: v) O << e << ' '; return O;}
typedef pair<int,int> pii;
typedef vector<int> vi;




void _main() {
        int n; cin >> n;
        vector<int> a(n); cin >> a; one(a);
        vector<int> b(n); cin >> b; one(b);
        vector<int> c(n - 1); cin >> c; one(c);

        int ans = 0;
        for (int i = 1; i <= n; i++) {
                ans += b[a[i]];
                if (i > 1 && a[i] - 1 == a[i - 1]) ans += c[a[i] - 1];
        }

        cout << ans;
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 256
#include<algorithm>/*{{{*/
#include<cctype>
#include<cassert>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<vector>
using namespace std;
typedef long long lld;
typedef long double lf;
typedef unsigned long long uld;
typedef pair<int,int> pii;
#define fi first
#define se second
#define pb push_back
#define mk make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define ROF(i,a,b) for(int i=(a);i>=(b);--i)
namespace RA{
    int r(int p){return 1ll*rand()*rand()%p;}
    int r(int L,int R){return r(R-L+1)+L;}
}/*}}}*/
/******************heading******************/
const int N=3050*2;

int n;
char s[N];
string a[N];
int la;

bool del_a(string &s){
    for(string::iterator it=s.begin();it!=s.end();it++){
        if(*it=='a')return s.erase(it),1;
    }
    return 0;
}
bool del_b(string &s){
    for(string::iterator it=s.begin();it!=s.end();it++){
        if(*it=='b')return s.erase(it),1;
    }
    return 0;
}
string calc(string s){
    //cout<<"calc "<<s<<endl;
    if(s[0]=='a'){
        string res="";
        int las_b=-1;
        int pos_a=-1,pos_b=-1;
        while(pos_b<(int)s.size()){
            ++pos_b;
            while(pos_b<(int)s.size()&&s[pos_b]=='a')++pos_b;
            ++pos_a;
            while(pos_a<(int)s.size()&&s[pos_a]=='b')++pos_a;
            if(pos_b==s.size())break;
            //printf("%d %d\n",pos_a,pos_b);
            if(pos_a>las_b)res+="ab", las_b=pos_b;
        }
        return res;
    }else {
        string res=s;
        while(s!=""){
            del_a(s);
            del_b(s);
            res=max(res,s);
        }
        //cout<<"res="<<res<<endl;
        return res;
    }
}
int main(){
    scanf("%d",&n);
    scanf("%s",s+1);
    int ca=0,cb=0;
    string t="";
    FOR(i,1,n*2){
        if(s[i]=='a')ca++;
        else cb++;
        t.pb(s[i]);
        if(ca==cb)a[++la]=calc(t),t="";
    }
    assert(t=="");
    string ans="";
    ROF(i,la,1)ans=max(ans,a[i]+ans);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 512
def f(a):
 q=a[:n];s=sum(q);heapify(q);yield s
 for e in a[n:2*n]:s+=e-heappushpop(q,e);yield s
from heapq import*;r=reversed;n,*a=map(int,open(0).read().split());print(max(map(sum,zip(f(a),r(list(f([-e for e in r(a)])))))))

Measured memory_bytes: 36308
# include <iostream>
# include <cmath>
# include <algorithm>
# include <stdio.h>
# include <cstdint>
# include <cstring>
# include <string>
# include <cstdlib>
# include <vector>
# include <bitset>
# include <map>
# include <queue>
# include <ctime>
# include <stack>
# include <set>
# include <list>
# include <random>
# include <deque>
# include <functional>
# include <iomanip>
# include <sstream>
# include <fstream>
# include <complex>
# include <numeric>
# include <immintrin.h>
# include <cassert>
# include <array>
# include <tuple>
# include <unordered_set>
# include <unordered_map>
using namespace std;
const long long md = 1e9 + 21;

string s;
int n;
long long p[500005], h[500005];
vector<int> v[500005];

inline int get(int l, int r) {
    long long res = h[r] - h[l - 1];
    if (res < 0) res += md;
    res *= p[n - l];
    res %= md;
    return res;
}

bool check(int l, int r) {
    int len = r - l + 1;
    if (len == 1) return false;
    for (int i = 0; i < (int)v[len].size(); ++i)
        if (get(l, r - v[len][i]) == get(l + v[len][i], r)) return true;
    return false;
}

int main(int argc, const char * argv[]) {
#ifdef __APPLE__
    freopen("/Users/danya.smelskiy/Documents/Danya/Resources/input.txt","r",stdin);
#endif
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> s;
    n = (int)s.size();
    s = "#" + s;
    p[0] = 31;
    for (int i = 1; i <= n; ++i) {
        p[i] = (p[i - 1] * 43) % md;
        h[i] = (h[i - 1] + (s[i] - 'a' + 1) * p[i]) % md;
    }
    for (int i = 1; i <= n; ++i)
        for (int j = i + i; j <= n; j += i)
            v[j].push_back(i);
    if (!check(1, n)) {
        cout << "1\n1\n";
        return 0;
    }
    int ans = 0;
    for (int i = 1; i < n; ++i)
        if (!check(1, i) && !check(i + 1, n)) ++ans;
    if (ans == 0) {
        cout << n << '\n' << 1 << '\n';
        return 0;
    }
    cout << 2 << '\n' << ans << '\n';
    return 0;
}



Measured memory_bytes: 64304
#include<bits/stdc++.h>
using namespace std;
int GCD[205][205];
inline int gcd(int a, int b)
{
	int r;
	while (b > 0)
	{
		r = a % b;
		a = b;
		b = r;
	}
	return a;
}
int main()
{
	int n;
	long long ans = 0;
	cin >> n;
	for (int i = 1; i <= n; i++)
		for (int j = i; j <= n; j++)
			GCD[i][j] = GCD[j][i] = gcd(i, j);
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			for (int k = 1; k <= n; k++)
			{
				ans += (long long)GCD[GCD[i][j]][k];
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  ll ans = 1, mod = 998244353;
  int count[3] = {}, count2[3] = {};
  for (char c : s) {
    int v = (c == 'R')*2+(c == 'G')*1+(c == 'B')*0;
    if (count2[v]) {
      (ans *= count2[v]--) %= mod;
    } else if (count[(v+1)%3]) {
      (ans *= count[(v+1)%3]--) %= mod;
      count2[(v+2)%3]++;
    } else if (count[(v+2)%3]) {
      (ans *= count[(v+2)%3]--) %= mod;
      count2[(v+1)%3]++;
    } else {
      count[v]++;
    }
  }
  for (int i = 1; i <= n; i++)
    (ans *= i) %= mod;
  for (int i : {0,1,2}) {
    assert(count[i] == 0);
    assert(count2[i] == 0);
  }
  cout << ans << endl;
}


Measured memory_bytes: 720
#include <iostream>
#include <vector>
#include <cstdio>

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

#define PB push_back

using namespace std;

struct Node {
	vector<int> edges_to;
	vector<int> edges_cost;

	bool done;
	int cost;
};

int main() {
	while (true) {
		int n, k;
		Node nodes[100];
		cin >> n >> k;
		if (n == 0 && k == 0) break;
		REP(i, k) {
			int a, b, c, d;
			scanf("%d %d %d", &a, &b, &c);
			b--; c--;
			if (a == 1) {
				scanf("%d", &d);
				nodes[b].edges_to.PB(c);
				nodes[b].edges_cost.PB(d);
				nodes[c].edges_to.PB(b);
				nodes[c].edges_cost.PB(d);
			} else {
				REP(i, n) {
					nodes[i].done = false;
					nodes[i].cost = -1;
				}
				nodes[b].cost = 0;
				while (true) {
					int doneNodeNum = -1;
					REP(i, n) {
						if (nodes[i].done || nodes[i].cost < 0) continue;
						if (doneNodeNum == -1 || nodes[i].cost < nodes[doneNodeNum].cost)
							doneNodeNum = i;
					}
					if (doneNodeNum == -1) break;

					Node *doneNode = &nodes[doneNodeNum];
					doneNode->done = true;
					REP(i, int(doneNode->edges_to.size())) {
						int to = doneNode->edges_to[i];

						int cost = doneNode->cost + doneNode->edges_cost[i];
						if (nodes[to].cost < 0 || nodes[to].cost > cost) nodes[to].cost = cost;
					}
				}

				printf("%d\n", nodes[c].cost);
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1284
def bfs(H, W, h, w, maze):
    if maze[h][w] == '#':
        return 0
    visited = []
    distance = []
    for i in range(H):
        visited.append([False] * W)
        distance.append([0] * W)
    visited[h][w] = True
    position = [[h, w]]
    current = 0
    while len(position) > 0:
        h, w = iter(position.pop(0))
        current = distance[h][w]
        if h - 1 >= 0 and maze[h-1][w] == '.' and not(visited[h-1][w]):
            distance[h-1][w] = current + 1
            visited[h-1][w] = True
            position.append([h-1, w])
        if h + 1 < H and maze[h+1][w] == '.' and not(visited[h+1][w]):
            distance[h+1][w] = current + 1
            visited[h+1][w] = True
            position.append([h+1, w])
        if w - 1 >= 0 and maze[h][w-1] == '.' and not(visited[h][w-1]):
            distance[h][w-1] = current + 1
            visited[h][w-1] = True
            position.append([h, w-1])
        if w + 1 < W and maze[h][w+1] == '.' and not(visited[h][w+1]):
            distance[h][w+1] = current + 1
            visited[h][w+1] = True
            position.append([h, w+1])
    return current


H, W = map(int, input().split())
maze = []
for i in range(H):
    maze.append(input())
M = 0
for h in range(H):
    for w in range(W):
        d = bfs(H, W, h, w, maze)
        if d > M:
            M = d
print(M)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 1010101010101010;
const int INF = 1010101010;
const int dx[] = {-1,0,1,0,-1,-1,1,1};
const int dy[] = {0,-1,0,1,1,-1,1,-1};
bool seen[100][100];
int w,h;
bool c[100][100];

int main(){
  while(true){
    cin>>w>>h;
    if(w==0) return 0;
    int cnt=0;
    rep(i,h)rep(j,w) seen[j][i]=false;
    rep(i,h)rep(j,w) cin>>c[j][i];
    int num=0;
    /*rep(i,h){
      rep(j,w) cout<<c[j][i];
      cout<<endl;
    }*/
    rep(i,h){
      rep(j,w){
        stack<int> q;
        if(c[j][i]==0||seen[j][i]) continue;
        q.push(i*w+j);
        while(!q.empty()){
          int x=q.top()%w,y=q.top()/w;
          q.pop();
          if(c[x][y]==0||seen[x][y]) continue;
          //cout<<x<<' '<<y<<endl;
          rep(d,8){
            if(y+dy[d]<0||y+dy[d]>=h||x+dx[d]<0||x+dx[d]>=w) continue;
            if(c[x+dx[d]][y+dy[d]]==0||seen[x+dx[d]][y+dy[d]]) continue;
            q.push((x+dx[d])+(y+dy[d])*w);
          }
          seen[x][y]=true;
        }
        num++;
        //cout<<i<<' '<<j<<endl;
      }
    }
    cout<<num<<endl;
  }
}



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

int main(){
  int i,j,k,D,G,mask,sum;
  cin >> D >> G;
  int p[D],c[D],ans=1e9;
  for(i=0;i<D;i++){
    cin >> p[i] >> c[i];
  }
  //ここまで入力
  for(mask=0;mask<(1<<D);mask++){
    int s = 0, num = 0, rest_max = -1;
    for(i=0;i<D;i++){
      if(mask >> i & 1){//maskのiビット目が立っている時問題セットiをすべて解く
        s += 100*(i+1)*p[i]+c[i];
        num += p[i];//問題数の更新
      }else{
        rest_max = i;//解かない問題の最大点数
      }
    }
    if(s<G){
      int s1 = 100 * (rest_max+1); //解いていない問題セットの最大点数
      int need = (G-s+s1-1)/s1; //中途半端に解くのに必要な問題数
      if(need>=p[rest_max]){//needが解いてない問題セットの問題数以上の時は次
        continue;
      }
      num+=need;
    }
    ans = min(ans,num);//更新
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define pi (acos(-1))
#define ull  unsigned long long
#define ld long double
///freopen("input.txt","r",stdin);
///freopen("output.txt","w",stdout);
#define M 100000
ll LCM(ll a, ll b)
{
    ll g = __gcd(a,b);
    return (a*b)/g ;
}
string numtostr(ll n)
{
    ostringstream str1 ;
    str1 << n ;
    return str1.str();
}
ll strtonum(string s)
{
    ll x ;
    stringstream str1(s);
    str1 >> x ;
    return x ;
}
string s;
int l,i;
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>s;
    l=s.length();
    for(i=0;i<l;++i)
    {
        if(s[i]=='?')
            cout<<'D';
        else
            cout<<s[i];
    }
    cout<<'\n';
    return 0;
}


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

using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

int main(){

  int h,w;cin>>h>>w;
  deque<string>d[h+10];
  rep(i,0,h){
    string s;cin>>s;
    d[i].push_front("#");
    d[i].push_back(s);
    d[i].push_back("#");
  }
  rep(i,0,w+2)cout<<"#";
  cout<<endl;
  rep(i,0,h){
    rep(j,0,d[i].size()){
      cout<<d[i][j];
    }
    cout<<endl;
  }
  rep(i,0,w+2)cout<<"#";
  cout<<endl;



  return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <math.h>
#include <complex>
using namespace std;

int a[100005];
int pre_gcd[100005];
int post_gcd[100005];

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

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    pre_gcd[0] = a[0];
    for (int i = 1; i < n; i++) {
        pre_gcd[i] = gcd(a[i], pre_gcd[i-1]);
    }
    post_gcd[n-1] = a[n-1];
    for (int i = n-2; i >= 0; i--) {
        post_gcd[i] = gcd(a[i], post_gcd[i+1]);
    }
    int ans = 0;
    ans = max(ans, post_gcd[1]);
    for (int i = 1; i < n-1; i++) {
        ans = max(ans, gcd(pre_gcd[i-1], post_gcd[i+1]));
    }
    ans = max(ans, pre_gcd[n-2]);
    printf("%d\n", ans);
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
     
int main() {
	int A,B,C;
  	cin >> A >> B >> C;
  	if ((A==B&&B!=C)||(A==C&&C!=B)||(B==C&&B!=A)){
    cout << "Yes";
    }else{
    cout << "No" << endl;
    }
}

Measured memory_bytes: 256
from collections import deque

INF = int(1e9 + 7)


def bfs(g, s, t):
    q = deque()
    q.append((s, 0))
    d = [] * 100000
    for _ in range(100000):
        d.append([INF, INF, INF])
    d[s][0] = 0
    while q:
        v_c, l = q.popleft()
        nl = (l + 1) % 3
        for vt in g[v_c]:
            if d[vt][nl] != INF:
                continue
            d[vt][nl] = d[v_c][l] + 1
            if vt == t and nl == 0:
                return d[vt][nl] // 3
            q.append((vt, nl))
    return -1


n, m = map(int, input().split())
graph = [] * n
for i in range(n):
    graph.append([])
for i in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    graph[u].append(v)
s, t = map(int, input().split())
print(bfs(graph, s - 1, t - 1))


Measured memory_bytes: 70884
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL gcd(LL a, LL b)
{
	if (a < b) std::swap(a, b);
	LL r = a % b;
	while (r != 0)
	{
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

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

LL mypow(LL x, LL y)
{
	LL res = 1;
	rep(i, y) res *= x;
	return res;
}

int main()
{
	std::string str;
	in >> str;

	LL p1 = -1, p2 = -1, p3 = -1;
	rep(i, str.size())
	{
		if (str[i] == '(') p1 = i;
		if (str[i] == ')') p2 = i;
		if (str[i] == '.') p3 = i;
	}

	LL k1 = 0, k2 = 0, m1 = 1, m2 = 1;
	if (p1 != -1)
	{
		LL w1 = p1 - 1;
		std::string temp;
		rep(i, p1) temp += str[i];
		if (temp.size() > 1)
		{
			k1 = std::stold(temp)*mypow(10, temp.size());
			m1 = mypow(10, temp.size());
			if (k1 > 0)
			{
				LL num1 = gcd(k1, m1);
				k1 /= num1; m1 /= num1;
			}
		}

		LL w2 = p2 - p1 - 1;
		k2 = std::stoi(str.substr(p1 + 1, w2));
		m2 = mypow(10, w2) - 1;
		if (p2 - 2 > p3 + w2) m2 *= mypow(10, ((p2 - 2) - (p3 + w2)));
		LL num2 = gcd(k2, m2);
		k2 /= num2; m2 /= num2;
	}
	else
	{
		std::string temp;
		rep(i, str.size()) temp += str[i];
		k1 = std::stold(temp)*mypow(10, temp.size());
		m1 = mypow(10, temp.size());
		if (k1 > 0)
		{
			LL num1 = gcd(k1, m1);
			k1 /= num1; m1 /= num1;
		}
	}

	LL m = m1 * m2, k = k1 * m2 + k2 * m1;
	LL num = gcd(k, m);
	m /= num; k /= num;

	out << k << "/" << m << std::endl;
	return 0;
}



Measured memory_bytes: 3304
/// wa ^3^

#pragma GCC optimize("O3")

#include<bits/stdc++.h>
                           
#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
 
using namespace std;
 
using ll = long long;
using pii = pair<int, int>;                                   

const int MOD = 1e9 + 7;
const int INF32 = 1e9 + 1e2;

template<typename T> istream 
&operator>>(istream &a, vector<T> &v) { 
for (auto& x : v) a >> x; return a; }

void stndrtn() {
#ifdef accepted
    freopen(".in", "r", stdin);
#endif        
}

const bool flag = 0;

void maincode() {
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    for (int i = 0; i < n; ++i, cout << "\n") {
        for (int j = 0; j < m; ++j) {
            cout << ((i >= b && j >= a) | (i < b && j < a));
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr), stndrtn();
    int ts = 1;
    if (flag) 
        cin >> ts;
    while (ts--)
        maincode(); 
    return 0;
}



Measured memory_bytes: 1280
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll x, y;
	cin >> x >> y;

	if (x == y) {
		cout << -1 << endl;
	} else {
		for (int i = 1; i < y; i++) {
			if ((i*x % y) != 0) {
				cout << i*x << endl;
				return 0;
			}
		}
		cout << -1 << endl;
	}
	return 0;
	
}





Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public class ABC
{
    //          long[] sp = Console.ReadLine().Split().Select(long .Parse).ToArray();
    //          int[] sp = Console.ReadLine().Split().Select(int.Parse).ToArray();
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int largest = 0;
        int second_largest = 0;
        int[] A = new int[n];

        for (int i = 0; i < n; i++)
        {
            A[i] = int.Parse(Console.ReadLine());
            if (largest < A[i])
            {
                second_largest = largest;
                largest = A[i];

            }
            else if (second_largest < A[i])
            {
                second_largest = A[i];

            }



        }
        for (int i = 0; i < n; i++)
        {
            if (A[i] == largest)
            {
                Console.WriteLine(second_largest);
            }
            else
            {
                Console.WriteLine(largest);
            }
        }



    }




}



Measured memory_bytes: 17108
#include <bits/stdc++.h>
#define x first
#define y second
#define pb push_back

using namespace std;

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

const int MAXN = 2e5 + 10;

ll r, d;

int main(){
	ios_base::sync_with_stdio(false), cin.tie(0);
	
	ll cx;
	cin >> r >> d >> cx;
	for(int i=1; i<=10; i++){
		cx = r * cx - d;
		cout << cx << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>

using namespace std;


int main(){
    int n;
    double total=0.0,tempx;
    char b[10];
    scanf("%d",&n);
    while(n--){
        scanf("%lf %s",&tempx,b);
        if(b[0]=='J')
            total+=tempx;
        else
            total+=(tempx*380000);
    }
    printf("%lf",total);
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll          long long
#define all(a)      (a).begin(),(a).end()
#define pb          push_back
#define INF         10000000000000000
using namespace std;
ll i,j,k,n,x,mid,sum1=0,sum2=0,ans,l[300005],r[300005];
vector<ll> v(300005);
int main()
{
    cin>>n;
	for(i=0;i<3*n;i++){
		cin>>v[i];
	}
	priority_queue<int> pq; //max_heap for first half
	priority_queue<int,vector<int>,greater<int> > pq2; //min_heap for second half
	ll csum=0;
	for(i=0;i<3*n;i++){
		pq2.push(v[i]);
		csum+=v[i];
		if(pq2.size()>n){
			csum-=pq2.top();pq2.pop();
		}
		if(pq2.size()==n)l[i]=csum;else l[i]=-INF; //maximum  possible sumof n numbers till ith index so, 
	}											//if i<n or pq2.size<n set it to -inf cause it is not favourable
	csum=0;
	for(int i=3*n-1;i>=0;i--){
		pq.push(v[i]);
		csum+=v[i];
		if(pq.size()>n){
			csum-=pq.top();pq.pop();
		}
		if(pq.size()==n) r[i]=csum;else r[i]=INF;//minimum  possible sumof n numbers till ith index from back so, 
	}											//if i<2*n or pq2.size<n set it to inf cause it is not favourable
	ll ans=-INF;
	for(i=n-1;i<2*n;i++){
		ans=max(ans,l[i]-r[i+1]); //checking at where the partition would be for maximum ans
							      // u can also loop from n to 2*n because l[i]is -inf before n and r[i]is inf after 2*n
	}
	cout<<ans<<endl;
 
    return 0;
}


Measured memory_bytes: 8184
#include<cstdio>
#include<algorithm>

using namespace std;

typedef long long ll;

double abs1(double a){
   if(a<0.0) return -a;
   return a;
}

int main(){
   ll n, a[100000];
   scanf("%lld", &n);
   for(ll i = 0; i < n; i++) scanf("%lld",&a[i]);
   sort(a, a + n);
   ll ans1 = a[n-1];
   ll ans2 = 100000000000;
   for(ll i = 0; i < n - 1; i++) if(abs1((double)ans2-(double)ans1/2)>abs1((double)a[i]-(double)ans1/2)) ans2 = a[i];
   printf("%lld %lld\n", ans1, ans2);
}

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

int main() {
    string s;
    cin>>s;
    int temp=0,ans=0;
    rep(i,s.size()){
        if(s[i]=='A' or s[i]=='C' or s[i]=='T' or s[i]=='G'){
            temp++;
        }else if(ans<temp){
            ans=temp;
            temp = 0;
        }
    }
    cout << max(ans,temp) <<endl;
}

Measured memory_bytes: 256
#!/usr/bin/python
# -*- coding: UTF-8 -*-

import sys


def get_ints():
    return map(int, sys.stdin.readline().strip().split())


def input():
    return sys.stdin.readline().strip()


def _main():
    n, length = get_ints()
    s_list = [""] * n
    for i in range(n):
        s_list[i] = input()
    s = sorted(s_list)
    print("".join(s))


if __name__ == "__main__":
    _main()


Measured memory_bytes: 8960
"use strict";

var main = function main(input) {
  var args = input.split('\n');
  var N = args[0];
  var Aup = args[1].split(' ');
  var Adown = args[2].split(' ');
  var AupSum = [];
  var AdownSum = [];
  var upSum = 0;
  var downSum = 0;

  for (var i = 0; i < N; i++) {
    upSum += parseInt(Aup[i], 10);
    downSum += parseInt(Adown[N - i - 1], 10);
    AupSum.push(upSum);
    AdownSum.push(downSum);
  }

  var max = -1;

  for (var _i = 0; _i < N; _i++) {
    if (max < AupSum[_i] + AdownSum[N - _i - 1]) {
      max = AupSum[_i] + AdownSum[N - _i - 1];
    }
  }

  console.log(max);
};

main(require('fs').readFileSync('/dev/stdin', 'utf-8'));

Measured memory_bytes: 7372
import math
def dot(a, b):
  return a.real * b.real + a.imag * b.imag

def projection(p0,p1,p2):
  a=p1-p0
  b=p2-p0
  pro = a * dot(a, b) / (abs(a) ** 2)
  t=p0+pro
  return t

def get_cross_point(p0,p1,p2):
  pro=projection(p0,p1,p2)
  e  =(p1-p0)/abs(p1-p0)
  base = (r**2 - abs(pro-p2)**2)**0.5
  if (pro-e*base).real == (pro+e*base).real:
    if (pro-e*base).imag < (pro+e*base).imag:
      ans1=pro-e*base
      ans2=pro+e*base
    else:
      ans1=pro+e*base
      ans2=pro-e*base
  elif (pro-e*base).real < (pro+e*base).real:
    ans1=pro-e*base
    ans2=pro+e*base
  else:
    ans1=pro+e*base
    ans2=pro-e*base
  return ans1.real, ans1.imag,ans2.real,ans2.imag

cx, cy, r = map(int, input().split())
p2=complex(cx,cy)
q = int(input())
for _ in range(q):
  x0,y0,x1,y1=map(int,input().split())
  p0=complex(x0,y0)
  p1=complex(x1,y1)
  print("{:.8f} {:.8f} {:.8f} {:.8f}".format(*get_cross_point(p0,p1,p2)))





Measured memory_bytes: 5740
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;

#define MAX (ll(1e6)+7)
#define MOD (ll(1e9)+7)
#define INF (ll(1e18)+7)

#define elif else if
#define def inline auto
#define for1(a,b) for(ll a=0;a<(b);++a)
#define array_size(a) ll(sizeof(a)/sizeof(a[0]))
#define ios_boost cin.tie(0);ios::sync_with_stdio(false)
#define digit(a) to_string(a).length()
#define lcm(a,b) a*b/gcd(a,b)
char N='\n',S=' ';
def gcd(ll a,ll b){ll c;while(a){c=a;a=b%a;b=c;}return b;}

ll check[100+100];
int main(){
	ios_boost;
	ll N,K,X=-1;
	cin>>N>>K;
	ll a[N];
	for1(i,N){
		cin>>a[i];
		if(a[i]==0){
			i--;
			N--;
			K--;
		}
		elif(X==-1 && a[i]>0){
			X=i;
		}
	}
	if(X==-1)X=N;
	ll ans=INF;
	for(ll i=0;i<K-1;++i){
		ll s=0;
		if(X+(i-K+1)<0 || X+i>=N)continue;
		s+=abs(a[X+i]);
		s+=abs(a[X+i]-a[X+(i-K+1)]);
		ans=min(ans,s);
	}
	for(ll i=-1;i>=-K+1;--i){
		ll s=0;
		if(X+(i+K-1)>=N || X+i<0)continue;
		s+=abs(a[X+i]);
		s+=abs(a[X+i]-a[X+(i+K-1)]);
		ans=min(ans,s);
	}
	if(X+K-1<N)ans=min(ans,abs(a[X+K-1]));
	if(X-K>=0)ans=min(ans,abs(a[X-K]));

	if(ans>2*abs(a[N-1])+2*abs(a[0]))ans=0;

	cout<<ans<<"\n";
}

//for compilation: g++ -o _ _.cpp -std=c++14 (or 17)
//
//for fastening: g++ -O2 -o _ _.cpp -std=c++14 (or 17)
//for fastening: g++ -O3 -mtune=native -march=native -o _ _.cpp -std=c++14 (or 17)


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

#define pb push_back

const int N = 2e3 + 100 ;
vector <int> g[N] ;
int d[N] , vis[N] ;
int ans[N] ;
int c ;


int main () {
	int n , x , y ;
	cin >> n >> x >> y ;
	for (int i = 1 ; i < n ; ++i) {
		g[i].pb(i+1) ;
		g[i+1].pb(i) ;
	}
	g[x].pb(y) ;
	g[y].pb(x) ;
	queue <int> q ;
	for (int i = 1 ; i <= n ; ++i) {
		q.push(i) ;
		d[i] = 0 ;
		vis[i] = ++c ;
		while (q.size()) {
			int u = q.front() ;
			q.pop() ;
			for (int &j : g[u]) {
				if (vis[j] < c) {
					vis[j] = c ;
					q.push(j) ;
					d[j] = d[u] + 1 ;
					++ans[d[j]] ;
				}
			}
		}
	}
	for (int i = 1 ; i < n ; ++i) {
		cout << ans[i]/2 << '\n' ;
	}
	return 0 ;
}

Measured memory_bytes: 384
n = int(input())
ban = []
for i in range(n):
    ban.append(input())
def hantei(data):
    for i in range(1,n):
        for k in range(i):
            if data[i][k] != data[k][i]:
                return(0)
    return(1)
ans = 0
for _ in range(n):
    tmp = ban[_:] + ban[:_]
    ans += hantei(tmp)
print(ans * n)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
const int MOD =1000000007;
#define INF INT_MAX
unsigned long long  a[100010];
int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int N;
    cin>>N;

    for(int i=0;i<N;i++)
    {
        cin>>a[i];
    }
    sort(a,a+N);
    if(N%2==0)
    {
        for(int i=0;i<N;i+=2)
        {
            if(a[i]==a[i+1]&&a[i]==i+1)
            {

            }
            else
            {
                cout <<0<<endl;
                return 0;
            }
        }
        unsigned long long ans=1;
        for(int i=1;i<=N/2;i++)
        {
            ans<<=1;
            ans=ans%MOD;
        }
        cout <<ans <<endl;
    }
    else
    {
        if(a[0]==0)
        {

        }
        else
        {
             cout <<0<<endl;
            return 0;
        }
        for(int i=1;i<=N/2;i+=2)
        {
            if(a[i]==a[i+1]&&a[i]==i+1)
            {

            }
            else
            {
                cout <<0<<endl;
                return 0;
            }
        }
        unsigned long long ans=1;
        for(int i=1;i<=N/2;i++)
        {
            ans<<=1;
            ans=ans%MOD;
        }
        cout <<ans <<endl;
    }
    return 0;
}


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


int main(void){
    int N;
    cin>>N;
    set<string> v;
    for(int i=0;i<N;i++){
      string s;
      cin>>s;
      v.insert(s);
    }
    cout<<v.size()<<endl;
    return 0;
}




Measured memory_bytes: 19204
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    string S, T;
    cin >> S >> T;
    int N,M;
    N=S.size();
    M=T.size();

    int pnt=-1;
    for(int i=N-M; i>=0; i--){
        bool flag=true;
        for(int j=0; j<M; j++){
            if(S[i+j]=='?'){
                continue;
            }else if(S[i+j]!=T[j]){
                flag=false;
                break;
            }
        }
        if(flag){
            pnt=i;
            break;
        }
    }
    if(pnt==-1){
        cout << "UNRESTORABLE" << endl;
    }else{
        for(int i=0; i<N; i++){
            if(S[i]=='?'){
                S[i]='a';
            }
        }
        for(int i=0; i<M; i++){
            S[pnt+i]=T[i];
        }
        cout << S << endl;
    }
}

Measured memory_bytes: 3552
#include<iostream>
using namespace std;
int main(void){
	int i,a[3],tmp,b,c;
	for(i=0;i<3;i++)cin>>a[i];
	for(b=0;b<3;b++){
		for(c=b+1;c<3;c++){
			if(a[b]>a[c]){
			tmp=a[b];
			a[b]=a[c];
			a[c]=tmp;
			}
		}
	}
	cout<<a[0]<<" "<<a[1]<<" "<<a[2]<<endl;
	return 0;
}

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

int solve(int n, int s, int l) {
	if (n == 0) {
		if (s == 0) return 1;
		else return 0;
	}
	int res = 0, h = min(l, 9);
	for (int i = h + 1; i < 10; i++) {
		res += solve(n - 1, s - i, i);
	}
	return res;
}

int main() {
	int n, s;
	while (cin >> n >> s) {
		if (n == 0 && s == 0) break;
		cout << solve(n, s, -1) << endl;
	}
	return 0;
}

Measured memory_bytes: 2980