akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use proconio::{input, marker::*};

#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};

#[allow(unused_imports)]
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*).unwrap();
    }
}

fn binary_search<F>(l: usize, r: usize, criterion: F) -> usize
where
    F: Fn(usize) -> bool,
{
    let mut l = l;
    let mut r = r;
    while r - l > 1 {
        let mid = l + (r - l) / 2;
        if criterion(mid) {
            r = mid;
        } else {
            l = mid;
        }
    }
    r
}

fn main() {
    input! {
        n: usize,
        k: usize,
        mut a: [usize; n],
    }

    let crit = |t: usize| {
        let mut sum = 0;
        for &e in &a {
            sum += (e - 1) / t;
        }
        sum <= k
    };

    let t = binary_search(0, 1000000001, crit);
    println!("{}", t);
}


Measured memory_bytes: 5380
module Main (main) where

import qualified Data.ByteString.Char8     as C8

main :: IO ()
main = do
  [s] <- readStrings
  print . showAnswer $ solve s

type Input  = (String)
type Output = String

solve :: Input -> Output
solve = ("2018" ++) . drop 4

showAnswer :: Output -> Answer
showAnswer = String

-- utils
readStrings :: IO [String]
readStrings = map C8.unpack . C8.words <$> C8.getLine

data Answer
  = YesNo Bool
  | YESNO Bool
  | AB Bool
  | Number Int
  | String String
  | Compare Ordering
  | Compare2 Ordering

instance Show Answer where
  show (YesNo b)   = if b then "Yes" else "No"
  show (YESNO b)   = if b then "YES" else "NO"
  show (AB b)      = if b then "A"   else "B"
  show (Number i)  = show i
  show (String s)  = s
  show (Compare o)
    | o == EQ = "="
    | o == LT = "<"
    | o == GT = ">"
  show (Compare2 o)
    | o == EQ = "Balanced"
    | o == LT = "Right"
    | o == GT = "Left"

Measured memory_bytes: 380
n, m = (int(i) for i in input().split())
a = [int(input()) for i in range(m)]

def Fib(n1):
    a1, b1 = 0, 1
    if n1 == 1:
        return a1
    elif n1 == 2:
        return b1
    else:
        for i in range(n1-2):
            a1, b1 = b1, a1 + b1
        return b1

l = []
pre = -1
for x in a:
    if x-pre == 1:
        print(0)
        exit()
    l.append(Fib(x-pre-1 +1))
    pre = x

l.append(Fib(n-pre +1))

res = 1
for x in l:
    res *= x

print(res % 1000000007)

Measured memory_bytes: 49112
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmax(a, b) a = max(a, b);
#define chmin(a, b) a = min(a, b);
using namespace std;
#define int long long
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;

signed main() {
    int r, c, k;
    cin >> r >> c >> k;
    VVI s(r, VI(c));
    rep(_, k) {
        int i, j, v;
        cin >> i >> j >> v;
        i--; j--;
        s[i][j] = v;
    }
    VVVI dp(r, VVI(c, VI(4)));
    dp[0][0][1] = s[0][0];
    rep(i, r) rep(j, c) {
        rep(k, 4) {
            if (j + 1 < c) {
                chmax(dp[i][j+1][k], dp[i][j][k])
                if (k + 1 < 4) chmax(dp[i][j+1][k+1], dp[i][j][k] + s[i][j+1])
            }
            if (i + 1 < r) {
                chmax(dp[i+1][j][0], dp[i][j][k])
                chmax(dp[i+1][j][1], dp[i][j][k] + s[i+1][j])
            }
        }
    }
    ll ans = 0;
    rep(k, 4) chmax(ans, dp[r-1][c-1][k])
    cout << ans << endl;
    
}


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

using namespace std;

int main(){
  string S, T, U;
  int nS, nT;
  
  cin >> S >> T;
  cin >> nS >> nT;
  cin >> U;
  
  if (S == U) --nS;
  if (T == U) --nT;
  
  cout << nS << " " << nT;
}

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

#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif

signed main(){

  int n,c; cin >> n >> c;
  static int d[31][31],t[501][501];
  for(int i = 0; i < c; i++){
    for(int j = 0; j < c; j++){
      cin >> d[i][j];
    }
  }
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      cin >> t[i][j];
      t[i][j]--;
    }
  }

  static int cost[3][31];
  for(int i = 0; i < c; i++){
    for(int j = 0; j < n; j++){
      for(int k = 0; k < n; k++){
        cost[(j+k)%3][i] += d[t[j][k]][i];
      }
    }
  }

  int ans = 1LL << 60;
  for(int i = 0; i < c; i++){
    for(int j = 0; j < c; j++){
      for(int k = 0; k < c; k++){
        if(i == j || j == k || k == i) continue;
        ans = min(ans,cost[0][i]+cost[1][j]+cost[2][k]);
      }
    }
  }
  cout << ans << endl;

  return 0;
}


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

int main() {
  ll n, x; cin >> n >> x;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(),a.end());
  ll ans = 0;
  int i = 0;
  rep(i,n) {
    x -= a[i];
    if (x >= 0) ans++;
  }
  if (x > 0) ans--;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
 
using namespace std;
          
#define endl        "\n"
#define int         long long
#define all(v)      v.begin(),v.end()
#define sz(v)       (int)v.size()
#define pii         pair<int,int>
#define fi          first
#define se          second
#define mod         1e9+7
#define forn(i,a,b) for(int i=a;i<b;i++)
#define deb(x)      cout << #x << ' ' << x << endl
#define clock       cerr << 1000 * (double)clock() / (double)CLOCKS_PER_SEC << "ms" << endl;

const long double pi=acos(0.0)*2.0;

void solve(){
    long double a,b,h,m;
    cin>>a>>b>>h>>m;
    long double angle=abs(6.0*m-0.5*(h*60.0+m));
    angle=min(angle,360.0-angle)*(pi/180.0);
    long double ans=a*a+b*b-2*a*b*cosl(angle);
    cout<<fixed<<setprecision(20)<<sqrtl(ans)<<endl;
}
 
int32_t main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t = 1;
    //cin >> t;
    while (t--) solve();
    return 0;
}

Measured memory_bytes: 4160
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define Graph vector<vector<int>>
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000007;

int main(){
    int N;
    cin >> N;
    map<ll, ll> A;
    ll ans = 0;
    rep(i, N){
        ll a;
        cin >> a;
        A[a]++;
        ans += a;
    }

    int Q;
    cin >> Q;
    
    rep(i, Q){
        ll b, c;
        cin >> b >> c;

        ll tmp = 0;
        if(A.count(b)){
            tmp = A[b];
            A.erase(b);
        }

        A[c] += tmp;

        ans -= tmp * b;
        ans += tmp * c;
        cout << ans << endl;
    }

}

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

int main(){

int a,d;
cin>>a;
  vector<int>b(a),c(a);
d=0;
  for(int i=0;i<a;i++){
cin>>b[i];
  }
    for(int i=0;i<a;i++){
cin>>c[i];
      if(b[i]-c[i]>0){
      d=d+b[i]-c[i];
      }
  }
      cout<<d<<endl;
 


}


Measured memory_bytes: 256
<?php
$a = trim(fgets(STDIN));
$b = trim(fgets(STDIN));
$c = trim(fgets(STDIN));
$d = trim(fgets(STDIN));
$e = trim(fgets(STDIN));
if($a < 0){
  $heat  = abs($a) * $c;
  $heat_time =  $e * $b;
  $time = $heat + $heat_time + $d;
  echo $time.PHP_EOL;
}else{ 
    $heat = $b - $a;
     $time = $heat * $e;
     echo $time.PHP_EOL;
}
?>


Measured memory_bytes: 9212
n = int(input())
data = list(map(int, input().split()))

def insertionsort(a, n):
    for i in range(n):
        v = a[i]
        j = i - 1;
        while (j >= 0 and a[j] > v):
            a[j+1] = a[j]
            j -= 1
        a[j+1] = v
        print(*a)

insertionsort(data, n)

Measured memory_bytes: 8096
#include<bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back
 
typedef long long ll;
 
int main() {
	string s; cin >> s;
	int K; cin >> K;
	int N = s.length();
	vector<string> a;
	rep(l, N) for (int r = l + 1; r <= N && r - l <= 5; r++)
		a.pb(s.substr(l, r - l));
	sort(a.begin(), a.end());
	a.erase(unique(a.begin(), a.end()), a.end());
	cout << a[K - 1] << endl;
}


Measured memory_bytes: 1660
//{
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define SZ(_a) (int)_a.size()
#define ALL(_a) _a.begin(),_a.end()
#define pb push_back
#ifdef brian
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // brian
//}


const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=ll(1e15);

int main()
{
    IOS();
    ll t,x;
    cin>>t>>x;
    cout<<fixed<<setprecision(12)<<t / lf(x)<<endl;
}


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

const int INF = INT_MAX / 2;

int main(){
    int N, M; cin >> N >> M;
    priority_queue<int> que;
    for (int i = 0; i < N; i++)
    {
        int a; cin >> a;
        que.push(a);
    }

    for (int i = 0; i < M; i++)
    {
        int mprice = que.top();
        que.pop();
        mprice /= 2;
        que.push(mprice);
    }
    long ans = 0;
    while(!que.empty()){
        ans += que.top();
        que.pop();
    } 
    cout << ans << endl;
}

Measured memory_bytes: 892
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		 int n = sc.nextInt();
		 int x = sc.nextInt();
		 
		 int[] a= new int[n];
		 int hoge;
		 
		 for(int i=0;i<n;i++) a[i] = sc.nextInt();
		 
		 for(int i=0;i<n;i++) {
			 for(int j=i+1;j<n;j++) {
				 if(a[i]>a[j]) {
					 hoge = a[i];
					 a[i] = a[j];
					 a[j] = hoge;
				 }
			 }
		 }
		 

		int i=0;
		int child=0;
		 while(n>0 && a[i]<=x) {
			 child++;
			 x -= a[i];
			 i++;
			 n--;
		 }
		 if(n==0 && x>0)child--;
		 
		 System.out.println(child);
	}
}


Measured memory_bytes: 23252
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>


using namespace std;


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

    long long a[N+5];

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

    int re[N+5];
    int sum=0;

    for(int i=0;i<N;i++){
        re[i] = 0;
        long long tmp = a[i];
        while(tmp > 0 && tmp % 2 ==0){
            tmp = tmp / 2;
            re[i] = re[i] + 1;
            sum = sum + 1;
        }
    }

    sort(a, a + N);

    long long mina;
    for(int i=0;i<N;i++){
        if(a[i] % 2 == 1){
            mina = a[i];
            break;
        }
    }

    long long tmp2;
    tmp2 = mina;
    int sumb=0;

    while(tmp2 <= 1000000000){
        tmp2 = tmp2 * 3;
        sumb = sumb + 1;
    }

    cout << sum << endl;
    return 0;
}

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

using namespace std;

int main() {
   

   int X, N;
   cin>>X>>N;
   int p[N];
   for (int i=0; i<N; i++){
       cin>>p[i];
   }
   int star=0;
   for (int j=0; j<N; j++){
       if (X==p[j]){
            star=1;
       }
   }
   if (star==0){
       cout<<X;
       return 0;
   }
   int left = X-1, right = X+1;
    
    for (int curr=X-1; true; curr--){
        int flag=0;
        for (int j=0; j<N; j++){
            if(curr==p[j]){
                flag=1;
            }
        }
        if(flag == 0){
            left = curr;
            break;
        }
    }
   for (int curr=X+1; true; curr++){
        int flag=0;
        for (int j=0; j<N; j++){
            if(curr==p[j]){
                flag=1;
            }
        }
        if(flag == 0){
            right = curr;
            break;
        }
    }
    int x=abs(X-left);
    int y=abs(X-right);
    if (x<=y){
        cout<<left;
    }
    else {
        cout<<right;
    }
    
}

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

int main(){

  vector<int> array(10,0);
  for(int i = 0; i < 10;i++){
    cin >> array[i];
  }

  sort(array.begin(),array.end());

  for(int i = 9; i > 6;i--){
    cout << array[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 3084
input1 = input()
s = str(input1).split(' ')[0]
t = str(input1).split(' ')[1]
input2 = input()
a = int(str(input2).split(' ')[0])
b = int(str(input2).split(' ')[1])
u = str(input())
if s == u:
  a = a - 1
else:
  b = b - 1
print(a, ' ', b)

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

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const int  INF =  1e9;
const ll LINF = 1e18;
const ll MOD = 1e9+7;
const int SIZE = 100;

template<class T>
inline T gcd(T a, T b){return b ? gcd(b, a % b) : a;}

template<class T>
inline T lcm(T a, T b){return a / gcd(a, b) * b;}
 
ll fac[SIZE], inv[SIZE], facinv[SIZE];
void make() {
	fac[0] = fac[1] = 1; inv[1] = 1; facinv[0] = facinv[1] = 1;
	for (ll i = 2; i < SIZE; i++) {
		fac[i] = (fac[i-1] * i) % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		facinv[i] = facinv[i-1] * inv[i] % MOD;
	}
}
ll combi(ll a, ll b) {
	if (a < b) return 0;
	return fac[a] * (facinv[b] * facinv[a-b] % MOD) % MOD;
}

int main() {
	ll n;
	scanf ("%lld", &n);
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	ll ans = 1;
	make();
	for (int i = 0; i < n; i++) {
		ans *= 3;
	}
	ll m = 1;
	for (int i = 0; i < n; i++) {
		m *= (a[i] % 2 == 0) ? 2 : 1;
	}
	printf("%lld\n", ans-m);
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
Int c[26],n,f=1;
string s;
Int dfs(Int l,Int r){
  if(l+1==r){
    return s[l]-'a';
  }
  assert(s[l]=='[');
  assert(s[r-1]==']');
  l++;r--;
  Int o=0;
  for(Int i=l;i<r;i++){
    if(s[i]=='[') o++;
    if(s[i]==']') o--;
    if(o==0&&s[i]=='-'){
      Int x=dfs(l,i);
      Int y=dfs(i+1,r);
      if(c[x]*c[y]||c[x]+c[y]==0){
	f=0;
	return 0;
      }
      if(c[y]) swap(x,y);
      c[x]--;
      return x;
    }
  }
}
signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  cin>>s;
  n=0;
  for(Int i=0;i<(Int)s.size();i++)
    n+=isalpha(s[i]);
  for(Int i=0;i<n;i++){
    char x;
    Int y;
    cin>>x>>y;
    c[x-'a']=y;
  }
  dfs(0,s.size());
  for(Int i=0;i<26;i++) f&=(c[i]==0);
  cout<<(f?"Yes":"No")<<endl;
  return 0;
}



Measured memory_bytes: 3224
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cctype>
#include <string>

using namespace std;

int main(){
  int N, d;
  cin >> N;
  int ans = 1;
  vector<int> vec(N);

  for (int i = 0; i < N; i++){
    cin >> d;
    vec.at(i) = d;
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());

  for (int i = 0; i < N-1; i++){
    if(vec.at(i) > vec.at(i+1)){
      ans++;
    }
  }

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



Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<math.h>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=100000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u];i;i=sq[i].nxt)
#define fir first
#define sec second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define maxd 998244353
#define eps 1e-8
struct node{int to,nxt;}sq[1000200];
int all=0,head[100100];
int n,m,d[100100],dis,a,b;
ll ans=0;
bool vis[100100];
struct pnode{int x,y,id;}p[100100];
bool operator <(pnode p,pnode q) 
{
	return ((p.x<q.x) || ((p.x==q.x) && (p.y<q.y)));
}

int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

void add(int u,int v)
{
	all++;sq[all].to=v;sq[all].nxt=head[u];head[u]=all;
}

void solve(int nowd)
{
	sort(p+1,p+1+n);
	int l=1,r=0,pos=1;
	rep(i,1,n)
	{
		while ((l<n) && ((p[i].x-dis>p[l].x) || ((p[i].x-dis==p[l].x) && (p[i].y-nowd>p[l].y)))) l++;
		while ((r<n) && ((p[i].x-dis>p[r+1].x) || ((p[i].x-dis==p[r+1].x) && (p[i].y+nowd>=p[r+1].y)))) r++;
		d[p[i].id]+=r-l+1;pos=max(pos,l);
		while (pos<=r) 
		{
			add(p[i].id,p[pos].id);add(p[pos].id,p[i].id);
			pos++;
		}
		pos--;
	}
}

void dfs(int u)
{
	ans+=d[u];vis[u]=1;
	go(u,i)
	{
		int v=sq[i].to;
		if (!vis[v]) dfs(v);
	}
}

int main()
{
	n=read();a=read();b=read();
	rep(i,1,n) 
	{
		int x=read(),y=read();
		p[i]=(pnode){x+y,x-y,i};
	}
	dis=max(abs(p[a].x-p[b].x),abs(p[a].y-p[b].y));
	solve(dis);
	rep(i,1,n) swap(p[i].x,p[i].y);
	solve(dis-1);
	dfs(a);
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 9856
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N; cin >> N; 
	int X[110] = {}; 
	for(int i = 0; i < N; i++) cin >> X[i]; 
	int ans = 1145141919; 
	for(int x = 1; x <= 100; x++){
		int power = 0; 
		for(int i = 0; i < N; i++){
			power += (x - X[i]) * (x - X[i]); 
		}
		ans = min(ans, power); 
	}
	cout << ans << endl; 
}

Measured memory_bytes: 256
#include<cstdio>
#include<vector>

using namespace std;

int main(){
	int n, a, b;
	scanf("%d%d%d", &n, &a, &b);
	vector<int> x(n);
	for(int i = 0; i < n; i++){
		scanf("%d", &x[i]);
	}
	int c = b / a;
	long long ans = 0;
	for(int i = 1; i < n; i++){
		int d = x[i] - x[i - 1];
		if(d <= c){
			ans += d * a;
		}else{
			ans += b;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 768
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<math.h>
#define maxn 11000
#define oo 0xfffffff
using namespace std;
int father[maxn], n, m;

struct node
{
    int u, v;
    double w;

} s[maxn*100];///数?大小

struct point
{
    int x, y;
} a[maxn];

double Len(int p, int q)
{
    double d = sqrt((a[p].x-a[q].x)*(a[p].x-a[q].x)+(a[p].y-a[q].y)*(a[p].y-a[q].y));
    return d;
}

int Find(int x)
{
   while(x!=father[x])
     x=father[x];

     return x;
}

int cmp(node p, node q)
{
    return p.w>q.w;
}

double solve()
{
    double ans = 0;

    for(int i=0; i<m; i++)
    {
        int ru = Find(s[i].u);
        int rv = Find(s[i].v);

        if(ru != rv)
        {
            father[ru] = rv;
            ans += s[i].w;
        }

    }

    return ans;
}


int main()
{
    int u, v;

    while(scanf("%d %d",&n, &m)!=EOF)
    {
        double sum = 0;

        for(int i=1; i<=n; i++)
            scanf("%d %d", &a[i].x, &a[i].y);

        for(int i=1; i<=n; i++)
            father[i] = i;

        for(int i=0; i<m; i++)
        {
            scanf("%d %d", &u, &v);
            s[i].u = u;
            s[i].v = v;
            s[i].w = Len(u, v);

            sum += s[i].w;
        }

        sort(s, s+m, cmp);

        double l = solve();

        printf("%.3f\n", sum-l);
    }

    return 0;
}

Measured memory_bytes: 1800
n = int(input())
W = list(str(input()) for _ in range(n))
W_s = set(W)
if len(W) != len(W_s):
    print("No")
    exit()

for i in range(n):
    w = W[i]
    if i == 0:
        end = w[-1]
        continue

    if w[0] == end:
        end = w[-1]
    else:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
	int N;
	long long int power=1;
	cin >> N;

	for (int i = 1; i <= N; i++) {
		power *= i;
		if (power > 1000000007) {
			power %= 1000000007;
		}
	}
	
	cout << power << endl;
}

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

using namespace std;
#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
//rep…「0からn-1まで」の繰り返し
#define rep2(i,s,n) for(long long i=s; i<=(long long)(n);i++)
//rep2…「sからnまで」の繰り返し
#define repr(i,s,n) for(long long i=s;i>=(long long)(n);i--)
//repr…「ｓからnまで」の降順の繰り返し

typedef long long ll;

const int inf = 1e9+7;
const int mod = 1e9+7;

int main(){
    ll n,x,t;
    cin>>n>>x>>t;

    cout<< ((n+x-1)/x)*t<<endl;
}


Measured memory_bytes: 3628
import java.util.Scanner;

class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		double speed;
		int floor;
		
		while(scan.hasNextDouble()){
			speed = scan.nextDouble();
			floor = (int)Math.ceil(((4.9*(speed/9.8)*(speed/9.8))+5)/5);
			
			System.out.println(floor);
		}
	}
}

Measured memory_bytes: 18984
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int a,b,c;
 cin>>a>>b>>c;
 
 if((a*100+b*10+c)%4==0)
 	cout<<"YES"<<endl;
 else
 	cout<<"NO"<<endl;
 
 
 return 0;
 }

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int tmpB = B;
    B = A;
    A = tmpB;
    int tmpC = C;
    C = A;
    A = tmpC;
    System.out.println(Integer.toString(A) + ' ' + Integer.toString(B) + ' '+Integer.toString(C));

  }
}



Measured memory_bytes: 22356
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};


int main(){
    ll n;   cin >> n;
    vector<ll> a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    sort(ALL(a));   sort(ALL(b));
    ll res=0;
    if(n%2){
        res = b[n/2]-a[n/2]+1;
    }else{
        res = b[n/2-1]+b[n/2]-(a[n/2-1]+a[n/2])+1;
    }
    cout << res << endl;

}


Measured memory_bytes: 6432
/**************************************************************************
Coded by: Saba Karimi(_VINTAGE)
Institution: AIT PUNE
***************************************************************************/
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
/***************************************************************************/
signed main()
{   
    fast; 
    int k,x;
    cin>>k>>x;
    vector<int> ans;
    for(int i=x-(k-1);i<=x;i++)
        ans.pb(i);
    for(int i=x+1;i<=x+(k-1);i++)
        ans.pb(i);
    for(int i=0;i<ans.size();i++)
        cout<<ans[i]<<" ";
}   

Measured memory_bytes: 256
import java.util.*;
public class Main {
	static Scanner sc = new Scanner(System.in);
	static int t, n;
	static int[] s, f;
	public static void main(String[] args) {
		while(read()){
			solve();
		}
	}
	
	static boolean read(){
		t = sc.nextInt();
		if(t == 0)return false;
		n = sc.nextInt();
		s = new int[n];
		f = new int[n];
		for(int i = 0; i < n; i++){
			s[i] = sc.nextInt();
			f[i] = sc.nextInt();
		}
		return true;
	}
	
	static void solve(){
		int time = 0;
		for(int i = 0; i < n; i++){
			time += f[i] - s[i];
		}
		System.out.println(time >= t ? "OK" : t-time);
	}

}

Measured memory_bytes: 23604
#include <stdio.h>

int main(void)
{
	char str[10004];
	int joi, ioi, i;
	
	while (scanf("%s", str) != EOF){
		i = joi = ioi = 0;
		while (str[i] != '\0'){
			if (str[i] == 'J' && str[i + 1] == 'O' && str[i + 2] == 'I'){
				joi++;
			}
			else if (str[i] == 'I' && str[i + 1] == 'O' && str[i + 2] == 'I'){
				ioi++;
			}
			i++;
		}
		printf("%d\n%d\n", joi, ioi);
	}
	
	return 0;
}

Measured memory_bytes: 552
#include <iostream>
#include <iomanip>
#include <fstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>

#define _GLIBCXX_DEBUG
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t w,h,x,y;
    cin >> w >> h >> x >> y;
    double area = h * w / 2.0;
    bool isCenter =
          (h%2==0) && (h/2==y)
        &&(w%2==0) && (w/2==x);
    cout << area << " " <<  isCenter << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define maxc 10010
struct ss{
    int x,y,h;
}s[maxc];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>s[i].x>>s[i].y>>s[i].h;
    int H,k;
    int x2,y2;
    int f=0;
    int maxh=0;
    int p=0;
    while(s[p++].h==0){}
    for(int x1=0;x1<=100;x1++){
        for(int y1=0;y1<=100;y1++){
                k=s[p].h+abs(s[p].x-x1)+abs(s[p].y-y1);
                f=0;
            for(int i=0;i<n;i++){
                H=max(k-abs(s[i].x-x1)-abs(s[i].y-y1),0);
                if(H!=s[i].h){
                    f=1;
                    break;
                }
            }
            if(f==0&&k>maxh){
                x2=x1;
                y2=y1;
                maxh=k;
                cout<<x2<<" "<<y2<<" "<<maxh<<endl;
                return 0;
            }
        }
    }

    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)
static const int dx[4] = { 0, 1, 0, -1 };
static const int dy[4] = { 1, 0, -1, 0 };
static const char dir[4] = { 'u', 'r', 'd', 'l' };
static const ll INF = 1 << 21;
static const ll MOD = 1e9 + 7;
static const int MAX_N = 1e5;
int N, M;
struct edge {
    int to,
        d;
};
vector<vector<edge>> g;
vector<int> x,used;

void dfs(int i, int d)
{
    used[i] = 1;
    x[i] = d;
    for (auto e : g[i]) {
        if (used[e.to]) {
            if (x[e.to] != x[i] + e.d) {
                puts("No");
                exit(0);
            }
        } else {
            dfs(e.to, d + e.d);
        }
    }
}

signed main()
{
    cin >> N >> M;
    g.resize(N);
    rep(i, M)
    {
        int l, r, d;
        cin >> l >> r >> d;
        --l, --r;
        g[l].emplace_back(edge{ r, d });
        g[r].emplace_back(edge{ l, -d });
    }
    used.resize(N), x.resize(N);
    rep(i, N)
    {
        if (!used[i]) {
            dfs(i, 0);
        }
    }
    puts("Yes");
    return 0;
}

Measured memory_bytes: 12416
#include<iostream>
#include<functional>
#include<utility>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>

using namespace std;
const auto MOD = 1000000007;
const int INF = 1e9;
const long long LINF = 1e18;
#define rep(i,n) for(int i = 0; i < (n);i++)
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef vector<int> VI;
typedef vector<long long> VLL;


int n, m,a,b,c;
string s,t;

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

Measured memory_bytes: 256
let s = read_line ()
let t = read_line ()

let tenki s t = 
  let rec tenki_iter i ret = 
    if i = 3 then ret
    else if s.[i] = t.[i] then tenki_iter (i+1) (ret+1)
    else tenki_iter (i+1) ret
  in tenki_iter 0 0;;


Printf.printf "%d\n" (tenki s t)

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
int n;
int p[60], q[60];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n;
    rep(i,0,n){
        cin>>p[i];
        q[i]=p[i];
    }
    sort(q,q+n);
    int cnt=0;
    rep(i,0,n){
        if(p[i]!=q[i]) cnt++;
    }
    cout <<(cnt<=2?"YES":"NO")<<"\n";
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
#define maxn 18

using namespace std;

int n, m;
int a[maxn][maxn];
int x, y, z;
int g[1 << maxn];
int f[1 << maxn][maxn];
int sum;

vector<int> v;

inline void Max(int &x, int y){
	x = max(x, y);
}

int main(){
	scanf("%d%d", &n, &m);
	while(m--){
		scanf("%d%d%d", &x, &y, &z);
		--x, --y;
		a[x][y] = a[y][x] = z;
		sum += z;
	}
	for(int i = 0;i < (1 << n);i++){
		v.clear();
		for(int j = 0;j < n;j++){
			if(i & (1 << j)) v.push_back(j);
		}
		for(int j = 1;j < v.size();j++){
			for(int k = 0;k < j;k++){
				g[i] += a[v[j]][v[k]];//debug:没写v 我弱智 
			}
		}
	}
	memset(f, -0x3f, sizeof(f));
	f[1][0] = 0;
	for(int i = 0;i < (1 << n) - 1;i++){
		for(int j = 0;j < n;j++){
			if(!(i & (1 << j))) continue;
			for(int k = 0;k < n;k++){
				if(!(i & (1 << k)) && a[j][k]){
					Max(f[i | (1 << k)][k], f[i][j] + a[j][k]);
				}
			}
			int x = i ^ ((1 << n) - 1);
			for(int k = x;k;k = (k - 1) & x){
				Max(f[i | k][j], f[i][j] + g[(1 << j) | k]);
			}
		}	
	}
	int ans = 0;
	for(int i = 0;i < (1 << n);i++) ans = max(ans, f[i][n - 1]);
	printf("%d", sum - ans);
}

Measured memory_bytes: 22364
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

const int MOD=1e9+7;

int main(){
  ll n;
  cin>>n;
  
  ll dp[n+1][5][5][5];
  
  rep(i,n+1){
    rep(j,5){
      rep(k,5){
        rep(l,5){
          if(i==3) dp[i][j][k][l]=1;
          else dp[i][j][k][l]=0;
        }
      }
    }
  }
  dp[3][1][3][2]=0;
  dp[3][3][1][2]=0;
  dp[3][1][2][3]=0;
  
  for(int i=3;i<n;i++){
    for(int j=1;j<=4;j++){
      for(int k=1;k<=4;k++){
        for(int l=1;l<=4;l++){
          for(int m=1;m<=4;m++){
            if(k==3 && l==1 && m==2) continue;
            if(k==1 && l==2 && m==3) continue;
            if(j==1 && l==3 && m==2) continue;
            if(j==1 && k==3 && m==2) continue;
            if(k==1 && l==3 && m==2) continue;
            dp[i+1][k][l][m]=(dp[i+1][k][l][m]+dp[i][j][k][l])%MOD;
          }
        }
      }
    }
  }
  
  ll ans=0;
  for(int j=1;j<=4;j++){
    for(int k=1;k<=4;k++){
      for(int l=1;l<=4;l++) ans=(ans+dp[n][j][k][l])%MOD;
    }
  }

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

Measured memory_bytes: 3664
#include<stdio.h>
int main()
{
	int H,A,quotient;
	scanf("%d%d",&H,&A);
	quotient = H/A;
	if(quotient*A == H)
	{
		printf("%d\n",quotient);
	}
	else
	printf("%d\n",quotient+1);
	return 0;
}

Measured memory_bytes: 128
N = int(input().strip())
A = list(map(int, input().strip().split(' ')))

def hoge(n):
  result = 0
  while True:
    if n%2 == 0:
      result += 1
      n = n//2
    else:
      break
  return result

print(min([hoge(a) for a in A]))

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

string ans = "";
int sy, sx, ty, tx;

int main() {
   cin >> sx >> sy >> tx >> ty;

   int dy = abs(sy - ty), dx = abs(sx - tx);
   // Path1
   ans += string(dy, 'U') + string(dx, 'R');
   // Path2
   ans += string(dy, 'D') + string(dx, 'L');
   // Path3
   ans += 'L' + string(dy+1, 'U') + string(dx+1, 'R') + 'D';
   // Path4
   ans += 'R' + string(dy+1, 'D') + string(dx+1, 'L') + 'U';

   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
  static boolean n,s,w,e;
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);

    char[] carr = scan.next().toCharArray();
    for(char c : carr) {
      if(c=='N') n = true;
      if(c=='S') s = true;
      if(c=='W') w = true;
      if(c=='E') e = true;
    }

    System.out.println((!(n^s)&&!(w^e))?"Yes":"No");
  }
}


Measured memory_bytes: 9940
def resolve():
    N = int(input())
    city = []
    for i in range(N):
        s, p = input().split()
        city.append([s, int(p), i+1])
    city.sort(key = lambda city : (city[0], -city[1]))
    for j in range(N):
        print(city[j][2])
resolve()

Measured memory_bytes: 9016
/*********************
*  Author: xuziyuan  * 
*********************/
 
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <LL,LL>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair
 
using namespace std;
 
LL n,m,x,y,re[60],ans=0;
vector <pii> g[60];
vector <LL> pass;
bool ok;
 
void dfs(LL pos,LL to,LL no)
{
  if(pos==to)
  {
    ok=true;
    return;
  }
  rep(i,g[pos].size())
  {
    if(g[pos][i].fi==no) continue;
    pass.pb(g[pos][i].se);
    dfs(g[pos][i].fi,to,pos);
    if(ok) return;
    pass.pop_back();
  }
}
 
int main()
{
  cin>>n;
  rep(i,n-1)
  {
    cin>>x>>y;
    g[x].pb(mpr(y,i));
    g[y].pb(mpr(x,i));
  }
  cin>>m;
  rep(i,m)
  {
    cin>>x>>y;
    ok=false;
    dfs(x,y,0);
    rep(j,pass.size()) re[i]|=(LL)pow(2,pass[j]);
    pass.clear();
  }
  repn(i,(1<<m)-1)
  {
    LL num=__builtin_popcount(i),now=0;
    rep(j,m)
    {
      if((i&(1<<j))==0) continue;
      now|=re[j];
    }
    LL now1=0;
    while(now>0)
    {
      now1+=now%2;
      now/=2;
    }
    LL res=(LL)pow(2,n-1-now1);
    if(num%2==1) ans+=res;
    else ans-=res;
  }
  cout<<(LL)pow(2,n-1)-ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<utility>
using namespace std;
#define P pair<int, int>
#define PP pair<int, P>
int main () {
  string s, t;
  cin >> s >> t;
  int ss = s.size();
  int ts = t.size();
  vector<vector<PP>>dp(ss + 1, vector<PP>(ts + 1));
  for (int i = 0; i <= ss; i ++) {
    for (int j = 0; j <= ts; j ++) {
      dp[i][0] = make_pair(0, make_pair(-1, -1));
    }
  }
  //dp[i][j] = sをi番目まで、tをj番目まで処理したときの大きさ、最後の文字
  for (int i = 1; i <= ss; i ++) {
    for (int j = 1; j <= ts; j ++) {
      if (s[i - 1] == t[j - 1]) {
        dp[i][j].first = dp[i - 1][j - 1].first + 1;
        dp[i][j].second = make_pair(i - 1, j - 1);
      }
      else {
        if (dp[i - 1][j].first > dp[i][j - 1].first) dp[i][j] = dp[i - 1][j];
        else dp[i][j] = dp[i][j - 1];
      }
    }
  }
  vector<char>ans(dp[ss][ts].first);
  int ku = dp[ss][ts].second.first;
  int ma = dp[ss][ts].second.second;
  for (int i = 0; i < dp[ss][ts].first; i ++) {
    int j = dp[ss][ts].first - i - 1;
    ans[j] = s[ku];
    int t = dp[ku][ma].second.first;
    ma = dp[ku][ma].second.second;
    ku = t;
  }
  for (int i = 0; i < dp[ss][ts].first; i ++) cout << ans[i];
  cout << endl;
}



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

ifstream in ("test.in" );
ofstream out("test.out");

const int DIM = 2e5 + 5;
const int INF = 0x3f3f3f3f;

long long arr[DIM];

int main(void)
{
    ios::sync_with_stdio(false);
    cin.tie(); cout.tie();
    
    int n;
    cin >> n;
    
    for (int i = 1; i <= n; ++i)
        cin >> arr[i];
    
    long long ans = 0;
    while (true) {
        if (*max_element(arr + 1, arr + n + 1) < n)
            break;
    
        long long cnt = 0;
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= n; ++j) {
                if (i == j)
                    continue;
                
                arr[j] += arr[i] / n;
            }
            
            ans += arr[i] / n; arr[i] %= n;
        }
    }
    
    cout << ans << endl;
    return 0;
}


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

int main(){
	unsigned short n, m;
	cin >> n >> m;
	vector<unsigned short> a(m), b(m);
	for (int i = 0; i < m; ++i){
		cin >> a.at(i) >> b.at(i);
	}

	for (int i = 1; i <= n; ++i){
		unsigned short out = 0;
		for (int k = 0; k < m; ++k){
			out += (a.at(k) == i ? 1 : (b.at(k) == i ? 1 : 0));
		}

		cout << out << endl;
	}
}

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


int N;
vector<int> P;


void input() {
    cin >> N;
    P = vector<int>(N);
    rep(i, N) cin >> P[i];
}


int main() {
    input();
    int ans = 0;
    int mn = 1e6;
    rep(i, N) {
        if (P[i] < mn) {
            ans++;
            mn = P[i];
        }
    }
    cout << ans << endl;
}


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

int main() {
	vector<int> vec(3);
	int ans = 0;
	for (int i = 0; i < 3; i++) {
		cin >> vec.at(i);
	}
	sort(vec.begin(), vec.end());
	for (int i = 0; i < 2; i++) {
		ans += vec.at(i);
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    
    for(int i = 1; i <= 1000; i++){
        int c = floor(i * 0.08),d = floor(i * 0.1);
        if(c == a && d == b){
        cout << i << endl;
        return 0;
        }

    }
    cout << -1 << endl;
}

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

int main()
{
	long long int i, j, k, l, m, sum,A,B,N;
	int flag = 0;
	sum = 0;
	cin >> N;
	if (N == 10 || N == 100 || N == 1000 || N == 10000 || N == 100000) {
		cout << "10" << endl;
	}
	else {
		while (N > 0) {
			sum += N % 10;
			N /= 10;
		}
		cout << sum << endl;
	}

    return 0;
}



Measured memory_bytes: 256
N = int(input())
S = input().rstrip()
cnt1, cnt2 = 0, 0
for s in S:
    if s == "(":
        cnt1 += 1
    if s == ")" and cnt1 >= 1:
        cnt1 -= 1
for s in reversed(S):
    if s == ")":
        cnt2 += 1
    if s == "(" and cnt2 >= 1:
        cnt2 -= 1
print("("*cnt2 + S + ")"*cnt1)

Measured memory_bytes: 61688
def f():
    s,t=input(),input()
    n,m=len(s),len(t)
    table=[[]for i in  range(26)]
    d={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}

    for j in range(n):
        table[d[s[j]]].append(j)
    now=0
    ind=0
    if set(list(t))-set(list(s)):print(-1);exit()
    from bisect import bisect_left as bl
    for p in t:
        if ind>table[d[p]][-1]:now+=1;ind=0
        ind=table[d[p]][bl(table[d[p]],ind)]+1

    print(now*n+ind)
if __name__ == "__main__":
    f()

Measured memory_bytes: 8416
#include<iostream>
#include<cstdio>
const int N=1e5+5;
typedef long long ll;
const ll mod=1e9+7;
int n,num[26];char s[N];
int main() {
    scanf("%d%s",&n,s+1);
    for(int i=1;i<=n;i++) num[s[i]-'a']++;
    ll ans=1;
    for(int i=0;i<26;i++) ans=ans*(num[i]+1)%mod;
    ans=(ans+mod-1)%mod;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
int main() {
	double a,b,c,d,e,f;
	double x,y;
	while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=EOF) {
		y=(a*f-c*d)/(a*e-b*d);
		x=(-b*y+c)/a;
		printf("%.3lf %.3lf\n",x,y);
	}
}

Measured memory_bytes: 1080
x = {}
("a".."z").each{|i| x[i]=0}

while line=gets
  line.chars {|c|
    c=c.downcase
    if x[c]
      x[c] +=1
    else
      x[c]=1
    end
  }
end

("a".."z").each{|c|
  puts "#{c} : #{x[c]}"
}



Measured memory_bytes: 6868
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
const ll inf = 1e18+5;
const ll maxn = 2*100000+5;
ll d, a, n, ans;
pi monster[maxn];
deque<pi> window;
ll fw[maxn];
void upd(ll p, ll v){
	for (ll i = p; i <= n; i+=(i&(-i)))fw[i] += v;
}
ll qry(ll p){
	ll res = 0;
	for (ll i= p; i > 0; i-=(i&(-i)))res+=fw[i];
	return res;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> n >> d >> a;
	ll r = 2*d;
	for (ll i = 1; i <= n; i++)cin >> monster[i].F >> monster[i].S; //pos then health
	sort(monster+1, monster+n+1);
	for (ll i = 1; i <= n; i++){
		upd(i, monster[i].S);
		upd(i+1, -monster[i].S);
	}
	for (ll i= 1; i<= n; i++){//for each monster we consider it being the start of the window
		if (i == 1){ //put all the necessary stuff in the deque
			ll cur = i;
			ll fron = i;
			while (((monster[cur].F-monster[fron].F)<= r)&& cur <= n){
				window.pb(mp(cur, monster[cur].S)); //window stores pair<index, health points>
				cur++;
			}
		}else { //move on to i being the front
			pi backpair = window.back();
			ll cur = backpair.F;
			cur++;
			ll fron = i;
			window.pop_front();
			while (monster[cur].F-monster[fron].F <= r && cur  <= n){
				window.pb(mp(cur, monster[cur].S));
				cur++;
			}
		}
		//so now i have a deque with all the things that will be affected when i drop a bomb at fron
		//we use a RUPQ fenwick
		ll fhealth = qry(i);
		if (fhealth <= 0)continue;
		pi backpair = window.back();
		ll endr = backpair.F;
		//~ while (fhealth > 0){ //too slow, can calc directly
			//~ upd(i, -a);upd(endr+1, a);
			//~ fhealth -= a;
			//~ cout << i <<  ' ' << endr<< '\n';
			//~ ans++;
		//~ }
		ll bombs = 0;
		if (fhealth%a == 0)bombs = fhealth/a;
		else bombs = fhealth/a + 1;
		upd(i, -(bombs*a)); upd(endr+1, (bombs*a));
		ans += bombs;
	}
	cout << ans;
}


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

int main() {
  int N;
  string S;
  
  cin >> N >> S;
  
  for(int i = 0; i < S.size(); i++){
    cout << char((S.at(i) - 'A' + N) % 26 + 'A') ;
  }
  cout << endl;
 
}
 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
ll sieve[1000001]={0},i,j;
ll power(ll p, ll k)
{
ll a=1;
while(k)
{
if(k&1)
a=(a*p);
p=(p*p);
k>>=1;
}
return a;
}
using namespace std;
set<ll> s;
  ll countDivisors(ll n) 
{ 
    ll cnt = 0; 
    for (ll i = 1; i <= sqrt(n); i++) { 
        if (n % i == 0) { 
            if (n / i == i) 
                cnt++; 
  
            else 
                cnt = cnt + 2; 
        } 
    } 
    return cnt; 
} 
void primeFactors(ll n)  
{  
    for (ll i = 1; i <= sqrt(n); i++) { 
        if (n % i == 0) { 
            if (n / i == i) 
            {
              
                if(i>=2)
                s.insert(i);
			}
  
            else 
            {
            
            if(i>=2)
               s.insert(i);
               if(n/i>=2)
               s.insert(n/i);
			}
        } 
    }   
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 int tc=1;
//cin>>tc;
ll cas=1;
 while(tc--)
 {
	string s;
	cin>>s;
	if(s[2]==s[3] && s[4]==s[5])
	cout<<"Yes";
	else
	cout<<"No";
 cout<<"\n"; 
 } 
}


Measured memory_bytes: 256
# set
n = gets.chomp.to_i
p_arr = gets.chomp.split(" ").map(&:to_i)
min = p_arr[0]
count = 0

# main
0.upto(n - 1) do |i|
  if p_arr[i] > min then
    next   
  else
    min = p_arr[i]
    count += 1
  end
end

print ("#{count}\n")

Measured memory_bytes: 18564
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MOD = 1e9+7, N = 1e5+5;
int n,w[N],send[N];
vector<int> adj[N];
void ans(bool solves){
    if(solves)
        puts("YES");
    else
        puts("NO");
    exit(0);
}
int root = 0;
void dfs(int u, int p){
    int sum = 0;
    if(adj[u].size() == 1){
        send[u] = w[u];
        return;
    }
    int cur_send = 0, cur_keep = 0, max_send = 0, total = 0;
    for(int v : adj[u]){
        if(v == p)
            continue;
        dfs(v,u);
        cur_send += send[v];
        total += send[v];
        max_send = max(max_send,send[v]);
    }
    while(cur_send > w[u]){
        cur_send -= 2;
        cur_keep += 1;
        w[u] -= 1;
    }
    if(w[u] < cur_send || w[u] < 0)
        ans(0);
    send[u] = cur_send;
    int max_keep = total-max_send;
    if(cur_keep > max_keep)
        ans(0);
    if(u == root && send[root] != 0)
        ans(0);
}
int main(){
    cin >> n;
    for(int i = 1; i <= n; ++i)
        scanf("%d",&w[i]);
    for(int i = 0; i < n-1; ++i){
        int a,b;
        scanf("%d %d",&a,&b);
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    if(n == 2)
        ans(w[1]==w[2]);
    root = 1;
    while(adj[root].size() < 2)
        ++root;
    dfs(root,0);
    ans(1);
} 


Measured memory_bytes: 13184
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
 
using namespace std;
using lint=long long;
 
int main(){
	int n; cin>>n;
	vector<lint> a(n),b(n);
	rep(i,n) cin>>a[i];
	rep(i,n) cin>>b[i];
 
	vector<lint> b2[30];
	rep(i,30){
		b2[i]=b;
		rep(j,n) b2[i][j]&=(1<<(i+1))-1;
		sort(b2[i].begin(),b2[i].end());
	}
 
	int ans=0;
	rep(i,30){
		lint cnt=0;
		rep(j,n){
			lint a2=a[j]&((1LL<<(i+1))-1);
			cnt+=lower_bound(b2[i].begin(),b2[i].end(),(1LL<<(i+1))-a2)
				-lower_bound(b2[i].begin(),b2[i].end(),(1LL<<i)-a2);
			cnt+=lower_bound(b2[i].begin(),b2[i].end(),(1LL<<(i+2))-a2)
				-lower_bound(b2[i].begin(),b2[i].end(),(1LL<<(i+1))+(1LL<<i)-a2);
		}
		if(cnt%2==1) ans|=1<<i;
	}
	cout<<ans<<endl;
 
	return 0;
}

Measured memory_bytes: 52352
#include <bits/stdc++.h>
#include <string>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <bitset>

//#include <boost/multiprecision/cpp_dec_float.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;
//// 任意長整数型
//using Bint = mp::cpp_int;
//// 仮数部が1024ビットの浮動小数点数型(TLEしたら小さくする)
//using Real = mp::number<mp::cpp_dec_float<1024>>;
//
typedef long long ll;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef pair<int,int> P;

const int MOD = 1000000007;



int main(int argc, const char * argv[]) {
    string S;
    string T;
    
    cin >> S >> T;
    
    for(ll i=0;i<S.size();i++){
        if(S[i]!=T[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    
    
    return 0;
}



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

int main() {
  int n,A=0,B=0,C=0,a,b,c; cin >> n;
  for (int i=0; i<n; i++) {
    cin >> a >> b >> c;
    a+=max(B,C); b+=max(A, C); c+= max(A,B);
    A=a; B=b; C=c;
  }
  cout << max(A, max(B,C)) << endl;
}




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

const long MOD=998244353;
const long INF=100000000000000000;
int main(){
    long N;
    cin>>N;
    vector<bool> dp(N+1);
    dp.at(0)=true;
    for(int i=1;i<=N;i++) dp.at(i)=((i>=4 && dp.at(i-4))||(i>=7 && dp.at(i-7)));
    if(dp.at(N)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256